2 __all__ = ('AVTransport', )
7 from brisa.core import log
8 from brisa.upnp.device import Service, ServiceController
9 from zukebox_renderer.services.gst_renderer import GSTRenderer
11 service_name = 'AVTransport'
12 service_type = 'urn:schemas-upnp-org:service:AVTransport:1'
15 class AVTransport(Service):
17 def __init__(self, xml_path):
18 Service.__init__(self, service_name, service_type, '',
19 os.path.join(xml_path, 'render-transport-scpd.xml'),
23 return self.control_controller.get_player()
26 class AVTransportControl(ServiceController):
29 ServiceController.__init__(self, service_type)
30 self.av_transport_uri = ''
31 self.number_of_tracks = 0
33 self.gst_player = GSTRenderer()
36 self.transport_state = 'NO_MEDIA_PRESENT'
37 self.transport_status= 'OK'
38 self.transport_speed = 1
40 def soap_SetAVTransportURI(self, *args, **kwargs):
41 """Specifies the URI of resource.
43 This action specifies the URI of the resource to be controlled
44 by the specified AVTransport instance. It is RECOMMENDED that the
45 AVTransport service checks the MIME-type of the specified resource
46 when executing this action"""
48 instance_id = kwargs['InstanceID']
49 current_uri = kwargs['CurrentURI']
50 current_uri_metadata = kwargs['CurrentURIMetaData']
52 self.av_transport_uri = current_uri
53 self.number_of_tracks = 1
54 self.gst_player.av_uri = current_uri
55 self.transport_state = 'STOPPED'
57 log.info('SetAVTransportURI()')
59 return {'SetAVTransportURI': {}}
61 def soap_GetMediaInfo(self, *args, **kwargs):
62 """Return information of current Media.
64 This action returns information associated with the current
65 media of the specified instance; it has no effect on state."""
67 log.info('GetMediaInfo()')
69 return {'GetMediaInfoResponse':
70 {'NrTracks': str(self.number_of_tracks),
71 'MediaDuration': str(self.gst_player.query_duration()[0]),
72 'CurrentURI': self.av_transport_uri,
73 'CurrentURIMetaData': '',
74 'NextURI': '', 'NextURIMetaData': '',
75 'PlayMedium': 'NETWORK',
79 def soap_GetMediaInfo_Ext(self, *args, **kwargs):
80 """Return information of current Media and CurrentType argment.
82 This action returns information associated with the current
83 media of the specified instance; it has no effect on state.The
84 information returned is identical to the information returned
85 by the GetMediaInfo() action, except for the additionally
86 returned CurrentType argument """
88 log.info('GetMediaInfo_Ext()')
90 return {'GetMediaInfo_ExtResponse': {'CurrentType': 'TRACK_UNAWARE',
91 'NrTracks': str(self.number_of_tracks),
92 'MediaDuration': str(self.gst_player.query_duration()[0]),
93 'CurrentURI': self.av_transport_uri,
94 'CurrentURIMetaData': '',
95 'NextURI': '', 'NextURIMetaData': '',
96 'PlayMedium': 'NETWORK',
100 def soap_GetTransportInfo(self, *args, **kwargs):
101 """Return informations os current Transport state.
103 This action returns information associated with the current
104 transport state of the specified instance; it has no effect on
107 self.transport_state = self.gst_player.get_state()
109 return {'GetTransportInfoResponse': {'CurrentTransportState':
110 self.transport_state,
111 'CurrentTransportStatus':
112 self.transport_status,
114 str(self.transport_speed)}}
116 def soap_GetPositionInfo(self, *args, **kwargs):
117 """Return information of the Transporte of the specified instante.
119 This action returns information associated with the current
120 position of the transport of the specified instance; it has no
123 dur = self.gst_player.query_duration()
124 pos = self.gst_player.query_position()
135 if dur[1] > 2147483646:
136 abs_pos = pos[1]*2147483646/dur[1]
142 return {'GetPositionInfoResponse': {'Track': '1',
144 '"'+str(duration)+'"',
147 self.av_transport_uri,
148 'RelTime': '"'+str(pos[0])+'"',
149 'AbsTime': '"'+str(pos[0])+'"',
151 'AbsCount': abs_pos}}
153 def soap_GetDeviceCapabilities(self, *args, **kwargs):
154 """Return information on device capabilities.
156 This action returns information on device capabilities of
157 the specified instance, such as the supported playback and
158 recording formats, and the supported quality levels for
159 recording. This action has no effect on state."""
161 log.info('GetDeviceCapabilities()')
163 return {'GetDeviceCapabilitiesResponse': {'PlayMedia': 'NONE',
164 'RecMedia': 'NOT_IMPLEMENTED',
165 'ReqQualityMode': 'NOT_IMPLEMENTED'}}
167 def soap_GetTransportSettings(self, *args, **kwargs):
168 """Return information on various settings of instance.
170 This action returns information on various settings of the
171 specified instance, such as the current play mode and the
172 current recording quality mode. This action has no effect on
175 log.info('GetTransportSettings()')
177 return {'GetTransportSettingsResponse': {'PlayMode': 'DIRECT_1',
178 'ReqQualityMode': 'NOT_IMPLEMENTED'}}
180 def soap_Stop(self, *args, **kwargs):
181 """Stop progression of current resource.
183 This action stops the progression of the current resource that
184 is associated with the specified instance."""
187 self.transport_state = 'TRANSITIONING'
188 self.gst_player.stop()
189 self.transport_state = 'STOPPED'
191 return {'StopResponse': {}}
193 def soap_Play(self, *args, **kwargs):
194 """Play the resource of instance.
196 This action starts playing the resource of the specified
197 instance, at the specified speed, starting at the current
198 position, according to the current play mode."""
201 log.debug('Playing uri: %r', self.gst_player.av_uri)
202 self.transport_state = 'TRANSITIONING'
204 self.gst_player.play()
206 self.transport_state = 'PLAYING'
208 return {'PlayResponse': {}}
210 def soap_Pause(self, *args, **kwargs):
211 """Pause the resouce of instance.
213 This action starts playing the resource of the specified
214 instance, at the specified speed, starting at the current
215 position, according to the current play mode."""
219 self.transport_state = 'TRANSITIONING'
221 self.gst_player.pause()
223 self.transport_state = 'PAUSED_PLAYBACK'
225 return {'PauseResponse': {}}
227 def soap_Seek(self, *args, **kwargs):
228 """Seek through the resource controlled.
230 This action starts seeking through the resource controlled
231 by the specified instance - as fast as possible - to the position,
232 specified in the Target argument."""
234 (instance_id, unit, target) = args
236 self.gst_player.seek(unit, target)
240 return {'SeekResponse': {}}
242 def soap_Next(self, *args, **kwargs):
243 """Advance to the next track.
245 This is a convenient action to advance to the next track. This
246 action is functionally equivalent to Seek(TRACK_NR, CurrentTrackNr+1).
247 This action does not cycle back to the first track."""
251 def soap_Previous(self, *args, **kwargs):
252 """Advance to the previous track.
254 This is a convenient action to advance to the previous track. This
255 action is functionally equivalent to Seek(TRACK_NR, CurrentTrackNr-1).
256 This action does not cycle back to the last track."""
258 log.info('Previous()')
260 def get_player(self):
261 return self.gst_player