All pastes #277724 Raw Edit

Miscellany

public python v1 · immutable
·published 2006-12-13 14:57 UTC
rendered paste body
#!/usr/bin/env pythonimport sysimport pygstpygst.require('0.10')import gstimport gobjectgobject.threads_init()# 1 create a pipeline# 2 set it to playing# 3 wait for pipeline to go to playing# 4 get the pipeline clock and the base_time# 5 create a NetTimeProvider using the clock and port# 6 inform clients of port and base_timeclass MasterPipeline:    def __init__(self, uri, port):        self.port = int(port)        self.uri = uri                # 1 create a pipeline        self.pipeline = gst.element_factory_make("playbin")        self.pipeline.set_property("uri", 'file://' + self.uri)        # connect a method to the bus messages        self.bus = self.pipeline.get_bus()        self.bus.add_signal_watch()        self.bus.connect('message', self._busMessageCb)        # create a mainloop to do event-based programming        self.mainloop = gobject.MainLoop()    def run(self):        # 2 set pipeline to playing        if self.pipeline.set_state(gst.STATE_PLAYING) == gst.STATE_CHANGE_FAILURE:            print "Couldn't set the pipeline to PLAYING"        self.mainloop.run()    def _busMessageCb(self, bus, message):        if message.type == gst.MESSAGE_STATE_CHANGED:            if message.src == self.pipeline:                previous, current, pending = message.parse_state_changed()                if previous == gst.STATE_PAUSED and current == gst.STATE_PLAYING and pending == gst.STATE_VOID_PENDING:                    # The pipeline is now playing                    # get the clock                    clock = self.pipeline.get_clock()                    # get the base_time                    base_time = self.pipeline.get_base_time()                    # Create the NetTimeProvider                    provider = gst.NetTimeProvider(clock, None, self.port)                    # inform clients of port and base_time                    print ("Start slave as: python ./play-slave.py %s [IP] %d %d"                           % (self.uri, self.port, base_time))        elif message.type in [gst.MESSAGE_ERROR, gst.MESSAGE_EOS]:            # if we have finished playing or there is an error, we exit the mainloop            self.mainloop.quit()if __name__ == '__main__':    uri, port = sys.argv[1:]    pipeline = MasterPipeline(uri, port)    pipeline.run()