Package elisa :: Package plugins :: Package bad :: Package dvd :: Module dvd_player
[hide private]
[frames] | no frames]

Source Code for Module elisa.plugins.bad.dvd.dvd_player

  1  # -*- Mode: Python -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3  import pygtk 
  4  pygtk.require('2.0') 
  5   
  6  import gobject 
  7  gobject.threads_init() 
  8   
  9  import pygst 
 10  pygst.require('0.10') 
 11   
 12  import gst 
 13  import gst.interfaces 
 14  from elisa.core.utils import classinit, signal 
 15  from elisa.core.media_uri import MediaUri 
 16   
 17  from fluendo_dvd.PipePlayer import * 
 18   
 19  DVD_ACTION_BUTTON_ACTIVATE = "Return" 
 20  DVD_ACTION_BUTTON_LEFT = "Left"; 
 21  DVD_ACTION_BUTTON_RIGHT = "Right"  
 22  DVD_ACTION_BUTTON_UP = "Up" 
 23  DVD_ACTION_BUTTON_DOWN = "Down" 
 24  DVD_ACTION_MENU_TITLE = "t" 
 25  DVD_ACTION_MENU_ANGLE = "a" 
 26  DVD_ACTION_MENU_PTT = "p" 
 27  DVD_ACTION_MENU_ROOT_OR_RESUME = "m" 
 28  DVD_ACTION_SEARCH_PREV_PG = "comma" 
 29  DVD_ACTION_SEARCH_NEXT_PG = "period" 
 30  DVD_ACTION_BUTTON_ANGLE_NEXT = "plus" 
 31  DVD_ACTION_BUTTON_ANGLE_PREV = "minus" 
 32  DVD_R = "r" 
 33   
 34   
 35  # A class with a sink pad for connecting an incoming audio stream. 
36 -class ElisaDVDPlayer:
37 38 # Allows property fget/fset/fdel/doc overriding 39 __metaclass__ = classinit.ClassInitMeta 40 __classinit__ = classinit.build_properties 41 42 in_menu = signal.Signal('in_menu', bool) 43
44 - def __init__(self, gpl=0):
45 # 46 self._dvd_player = DVDPlayer(gpl=gpl) 47 self._imagesink = None 48 self.timeout = 250 * gst.MSECOND 49 self._is_menu = False 50 bus = self._dvd_player.pipeline.get_bus() 51 bus.connect('message', self.on_message)
52
53 - def is_menu__get(self):
54 return self._is_menu
55
56 - def fire_action(self, action):
57 state = self.get_state() 58 #FIXME have read error if I'm asking menu where state is READY !! 59 if state[1] == gst.STATE_READY and action == DVD_ACTION_MENU_ROOT_OR_RESUME: 60 return 61 62 if self._imagesink: 63 if self._imagesink: 64 s = gst.structure_from_string( "application/x-gst-navigation,event=key-release,key=%s" % action ) 65 event = gst.event_new_navigation(s) 66 self._imagesink.send_event(event)
67
68 - def video_sink__get(self):
69 """ Video sink access 70 71 If we're using playbin, return the value of the 'video-sink' 72 property. Either find the element in the pipeline named 73 'video-sink' 74 75 @rtype: L{gst.BaseSink} 76 """ 77 78 return self._dvd_player.vsink
79
80 - def video_sink__set(self, sink):
81 """ Video sink setter 82 83 @type sink: L{gst.BaseSink} 84 """ 85 self._dvd_player.vdecoder.unlink(self._dvd_player.vsink) 86 self._dvd_player.pipeline.remove(self._dvd_player.vsink) 87 88 self._imagesink = sink.get_by_name('pgm_sink') 89 self._dvd_player.vsink = sink 90 self._dvd_player.pipeline.add(sink) 91 self._dvd_player.vdecoder.link(sink)
92 93
94 - def get_volume_element(self):
95 vlm = self._dvd_player.pipeline.get_by_name('vlm') 96 return vlm
97
98 - def volume__get(self):
99 """The volume of the audio stream""" 100 volume = 0 101 vlm = self.get_volume_element() 102 if vlm: 103 volume = vlm.get_property('volume') 104 return volume
105
106 - def volume__set(self, volume):
107 vlm = self.get_volume_element() 108 if vlm: 109 vlm.set_property('volume', volume)
110
111 - def on_message(self, bus, message):
112 if message.structure is None: 113 return 114 """ 115 if message.structure.get_name() == 'prepare-xwindow-id': 116 message.src.set_property('force-aspect-ratio', True) 117 """ 118 if message.type == gst.MESSAGE_ELEMENT and message.structure.get_name() == 'application/x-gst-dvd': 119 self._is_menu = message.structure['in-menu'] 120 self.in_menu.emit(self._is_menu)
121
122 - def load_uri(self, uri):
123 freezefile = None 124 125 if isinstance(uri, MediaUri) and uri.scheme != 'dvd': 126 path = uri.path 127 else: 128 path = None 129 130 self._dvd_player.reader.set_location (path, freezefile)
131 132
133 - def gst_duration__get(self):
134 """ 135 Returns the duration of the currently playing context 136 137 @rtype: gst.FORMAT_TIME 138 """ 139 if self._dvd_player.pipeline.get_state(self.timeout)[1] not in (gst.STATE_PLAYING, gst.STATE_PAUSED): 140 return gst.CLOCK_TIME_NONE 141 142 try: 143 duration, format = self._dvd_player.pipeline.query_duration(gst.FORMAT_TIME) 144 except: 145 # FIXME: is this enough ? 146 duration = gst.CLOCK_TIME_NONE 147 148 return duration
149
150 - def duration__get(self):
151 """ 152 Returns the duration of the currently playing context 153 154 @rtype: long in nanoseconds, 155 """ 156 duration = self.gst_duration 157 if duration == gst.CLOCK_TIME_NONE: 158 duration = 0 159 160 return duration
161
162 - def gst_position__get(self):
163 """ 164 Returns the position of the currently playing context 165 166 @rtype: gst.FORMAT_TIME 167 """ 168 169 if self._dvd_player.pipeline.get_state(self.timeout)[1] not in (gst.STATE_PLAYING, gst.STATE_PAUSED): 170 return gst.CLOCK_TIME_NONE 171 172 try: 173 position, format = self._dvd_player.pipeline.query_position(gst.FORMAT_TIME) 174 except: 175 # FIXME: is this enough ? 176 position = gst.CLOCK_TIME_NONE 177 178 return position
179 180
181 - def position__get(self):
182 """ 183 Returns the position of the currently playing context 184 185 @rtype: long in nanoseconds, 186 """ 187 position = self.gst_position 188 if position == gst.CLOCK_TIME_NONE: 189 position = 0 190 191 return position
192
193 - def seek_to_location(self, location):
194 """ 195 @param location: time to seek to, in nanoseconds 196 """ 197 res = self._dvd_player.seek(location)
198
199 - def pause(self):
200 self._dvd_player.pause()
201
202 - def play(self):
203 self._dvd_player.play()
204
205 - def stop(self):
206 self._dvd_player.stop()
207
208 - def get_state(self, timeout=1):
209 return self._dvd_player.pipeline.get_state(timeout=timeout)
210
211 - def is_playing(self):
212 return self._dvd_player
213