Package screenlets :: Package plugins :: Module Gstreamer
[hide private]
[frames] | no frames]

Source Code for Module screenlets.plugins.Gstreamer

  1  # This program is free software: you can redistribute it and/or modify 
  2  # it under the terms of the GNU General Public License as published by 
  3  # the Free Software Foundation, either version 3 of the License, or 
  4  # (at your option) any later version. 
  5  #  
  6  # This program is distributed in the hope that it will be useful, 
  7  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
  8  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  9  # GNU General Public License for more details. 
 10  #  
 11  # You should have received a copy of the GNU General Public License 
 12  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 13   
 14  import pygtk, gtk, gobject 
 15  import pygst 
 16  pygst.require("0.10") 
 17  import gst 
 18   
19 -class gstreamer(object):
20
21 - def __init__(self):
22 self.player = gst.element_factory_make("playbin", "player") 23 fakesink = gst.element_factory_make('fakesink', "my-fakesink") 24 self.player.set_property("video-sink", fakesink) 25 bus = self.player.get_bus() 26 bus.add_signal_watch() 27 bus.connect('message', self.on_message) 28 29 self.player = gst.Pipeline("player") 30 source = gst.element_factory_make("filesrc", "file-source") 31 self.player.add(source) 32 demuxer = gst.element_factory_make("oggdemux", "demuxer") 33 self.player.add(demuxer) 34 demuxer.connect("pad-added", self.demuxer_callback) 35 self.audio_decoder = gst.element_factory_make("vorbisdec", "vorbis-decoder") 36 self.player.add(self.audio_decoder) 37 audioconv = gst.element_factory_make("audioconvert", "converter") 38 self.player.add(audioconv) 39 audiosink = gst.element_factory_make("autoaudiosink", "audio-output") 40 self.player.add(audiosink) 41 42 gst.element_link_many(source, demuxer) 43 gst.element_link_many(self.audio_decoder, audioconv, audiosink) 44 45 bus = self.player.get_bus() 46 bus.add_signal_watch() 47 bus.connect("message", self.on_message)
48 49
50 - def demuxer_callback(self, demuxer, pad):
51 adec_pad = self.audio_decoder.get_pad("sink") 52 pad.link(adec_pad)
53 54
55 - def start(self):
56 try: 57 self.player.set_property('uri', ta) 58 self.player.set_state(gst.STATE_PLAYING) 59 except Exception, ex: 60 print 'unable to connect'
61
62 - def stop(self):
63 64 self.player.set_state(gst.STATE_NULL)
65
66 - def on_message(self, bus, message):
67 t = message.type 68 if t == gst.MESSAGE_EOS: 69 self.player.set_state(gst.STATE_NULL) 70 71 elif t == gst.MESSAGE_ERROR: 72 err, debug = message.parse_error() 73 print "Error: %s" % err, debug 74 self.player.set_state(gst.STATE_NULL)
75
76 - def rewind_callback(self, w):
77 pos_int = self.player.query_position(self.time_format, None)[0] 78 seek_ns = pos_int - (10 * 1000000000) 79 self.player.seek_simple(self.time_format, gst.SEEK_FLAG_FLUSH, seek_ns)
80
81 - def forward_callback(self, w):
82 pos_int = self.player.query_position(self.time_format, None)[0] 83 seek_ns = pos_int + (10 * 1000000000) 84 self.player.seek_simple(self.time_format, gst.SEEK_FLAG_FLUSH, seek_ns)
85
86 - def convert_ns(self, time_int):
87 time_int = time_int / 1000000000 88 time_str = "" 89 if time_int >= 3600: 90 _hours = time_int / 3600 91 time_int = time_int - (_hours * 3600) 92 time_str = str(_hours) + ":" 93 if time_int >= 600: 94 _mins = time_int / 60 95 time_int = time_int - (_mins * 60) 96 time_str = time_str + str(_mins) + ":" 97 elif time_int >= 60: 98 _mins = time_int / 60 99 time_int = time_int - (_mins * 60) 100 time_str = time_str + "0" + str(_mins) + ":" 101 else: 102 time_str = time_str + "00:" 103 if time_int > 9: 104 time_str = time_str + str(time_int) 105 else: 106 time_str = time_str + "0" + str(time_int) 107 108 return time_str
109