Advertisement
Guest User

Untitled

a guest
Jul 5th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import sys, os
  3. import pygtk, gtk, gobject
  4.  
  5. import pygst
  6. pygst.require("0.10")
  7. import gst
  8.  
  9. gtk.gdk.threads_init()
  10.  
  11. class Emisor:
  12.  
  13.     def __init__(self, port, location, host):
  14.         self.pipeline = None
  15.         self.location=location
  16.         self.port=port
  17.         self.host=host
  18.  
  19.         #gst-launch filesrc location=/home/gaston/1.mp3 ! ffdemux_mp3 ! udpsink port=6969 host=192.168.2.102
  20.  
  21.         self.pipeline = gst.Pipeline("player")
  22.         source = gst.element_factory_make("filesrc", "source") # origen
  23.         source.set_property('location', self.location)
  24.         codec = gst.element_factory_make("mp3parse", "codec")
  25.         udpsink = gst.element_factory_make("udpsink", "udpsink") # salida
  26.         udpsink.set_property('port', self.port)
  27.         udpsink.set_property('host', self.host)
  28.    
  29.         self.pipeline.add(source, codec, udpsink) # armar el pipeline
  30.         gst.element_link_many(source, codec, udpsink) # entubar los elementos
  31.  
  32.         # Es necesario conectar el controlador de sincronización de mensajes al sink en el
  33.         # momento adecuado para no tener una nueva ventana temporal.
  34.  
  35.         bus = self.pipeline.get_bus()
  36.         bus.enable_sync_message_emission()
  37.             bus.add_signal_watch()     
  38.         bus.connect("sync-message::element", self.on_sync_message)
  39.             bus.connect("message", self.on_message)
  40.             self.pipeline.set_state(gst.STATE_PLAYING) # comenzar ejecución
  41.  
  42.         def on_message(self, bus, message):
  43.             if message.type == gst.MESSAGE_ERROR:
  44.                     err, debug = message.parse_error()
  45.                     print "ERROR ON_MESSAGE: ", err, debug
  46.  
  47.     def on_sync_message(self, bus, message):
  48.             if message.structure is None:
  49.                     return
  50.             if message.structure.get_name() == 'prepare-xwindow-id':
  51.         # Todo esto es necesario para que se sincronice con el servidor X antes de dar la
  52.                 # X id al lavabo sink
  53.                     gtk.gdk.threads_enter()
  54.                     gtk.gdk.display_get_default().sync()
  55.                     #self.video_widget.set_sink(message.src)
  56.                     message.src.set_property("force-aspect-ratio", True)
  57.                     gtk.gdk.threads_leave()
  58.  
  59. Emisor()
  60. gtk.gdk.threads_init()
  61. gtk.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement