Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys, os
- import pygtk, gtk, gobject
- import pygst
- pygst.require("0.10")
- import gst
- gtk.gdk.threads_init()
- class Emisor:
- def __init__(self, port, location, host):
- self.pipeline = None
- self.location=location
- self.port=port
- self.host=host
- #gst-launch filesrc location=/home/gaston/1.mp3 ! ffdemux_mp3 ! udpsink port=6969 host=192.168.2.102
- self.pipeline = gst.Pipeline("player")
- source = gst.element_factory_make("filesrc", "source") # origen
- source.set_property('location', self.location)
- codec = gst.element_factory_make("mp3parse", "codec")
- udpsink = gst.element_factory_make("udpsink", "udpsink") # salida
- udpsink.set_property('port', self.port)
- udpsink.set_property('host', self.host)
- self.pipeline.add(source, codec, udpsink) # armar el pipeline
- gst.element_link_many(source, codec, udpsink) # entubar los elementos
- # Es necesario conectar el controlador de sincronización de mensajes al sink en el
- # momento adecuado para no tener una nueva ventana temporal.
- bus = self.pipeline.get_bus()
- bus.enable_sync_message_emission()
- bus.add_signal_watch()
- bus.connect("sync-message::element", self.on_sync_message)
- bus.connect("message", self.on_message)
- self.pipeline.set_state(gst.STATE_PLAYING) # comenzar ejecución
- def on_message(self, bus, message):
- if message.type == gst.MESSAGE_ERROR:
- err, debug = message.parse_error()
- print "ERROR ON_MESSAGE: ", err, debug
- def on_sync_message(self, bus, message):
- if message.structure is None:
- return
- if message.structure.get_name() == 'prepare-xwindow-id':
- # Todo esto es necesario para que se sincronice con el servidor X antes de dar la
- # X id al lavabo sink
- gtk.gdk.threads_enter()
- gtk.gdk.display_get_default().sync()
- #self.video_widget.set_sink(message.src)
- message.src.set_property("force-aspect-ratio", True)
- gtk.gdk.threads_leave()
- Emisor()
- gtk.gdk.threads_init()
- gtk.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement