Exemple #1
0
    def on_message_state_changed(self, bus, message):

        t = message.type
        logging.debug("Message type %s received; source %s" %
                      (t, type(message.src)))

        if isinstance(message.src, gst.Pipeline):
            old_state, new_state, pending_state = message.parse_state_changed()

            # gst.STATE_NULL	    the NULL state or initial state of an element
            # gst.STATE_PAUSED    the element is PAUSED
            # gst.STATE_PLAYING   the element is PLAYING
            # gst.STATE_READY	    the element is ready to go to PAUSED
            # gst.STATE_VOID_PENDING    no pending state

            if pending_state == gst.STATE_VOID_PENDING:

                logging.debug(
                    "Pipeline state changed from %s to %s. Pendig: %s" %
                    (gst.element_state_get_name(old_state),
                     gst.element_state_get_name(new_state),
                     gst.element_state_get_name(pending_state)))

                if new_state == gst.STATE_READY:
                    self.playmode = "Stopped"
                    self.statuschanged = True
                elif new_state == gst.STATE_PAUSED:
                    self.playmode = "Paused"
                    self.statuschanged = True
                elif new_state == gst.STATE_PLAYING:
                    self.playmode = "Playing"
                    self.statuschanged = True
Exemple #2
0
    def on_bus_message(self, bus, message):
        if message.src != self.pipeline:
            log.error("Got bus message which is not ours")
            return
        if message.type == gst.MESSAGE_STATE_CHANGED:
            ret, state, pending = message.parse_state_changed()
            self.stop_audio_alert_button.set_sensitive(state==gst.STATE_PLAYING)
            self.playing = (state==gst.STATE_PLAYING)
#            if state == gst.STATE_PLAYING:
#                self.playing = True
#                self.stop_audio_alert_button.set_sensitive(True)
#            else:
#                self.stop_audio_alert_button.set_sensitive(False)
            log.debug("GST_MESSAGE_STATE_CHANGED. Returned: %s  Current: %s  "
                      "Pending: %s", gst.element_state_get_name(ret),
                      gst.element_state_get_name(state),
                      gst.element_state_get_name(pending))
#            print gst.element_state_get_name(state)

        elif message.src == self.pipeline and message.type == gst.MESSAGE_EOS:
            log.debug("GOT EOS!!!!")
            self.pipeline.seek_simple(gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH, 0)
        elif message.type == gst.MESSAGE_ERROR:
            log.debug("Got ERROR: %s", message.parse_error())
        else:
            log.debug("%s\nonBusMessage: %s  Type: %s\n", self.__class__.__name__,
                      message.structure, message.type)
        return True
def handle_message(data, msg):
    if message.type == gst.MESSAGE_ERROR:
        err, debug = message.parse_error()
        print >> sys.stderr, "Error received from element %s: %s"% (message.src.get_name(), err)
        print >> sys.stderr, "Debugging information: %s"% debug
        data["terminate"] = True
    elif message.type == gst.MESSAGE_EOS:
        print "End-Of-Stream reached."
        data["terminate"] = True
    elif message.type == gst.MESSAGE_DURATION:
        # The duration has changed, mark the current one as invalid
        data["duration"] = gst.CLOCK_TIME_NONE
    elif message.type == gst.MESSAGE_STATE_CHANGED:
        if message.src == data["playbin2"]:
            old_state, new_state, pending_state = message.parse_state_changed()
            print ("Pipeline state changed from %s to %s."% 
                   (gst.element_state_get_name(old_state), gst.element_state_get_name (new_state)))
            data["playing"] = (new_state == gst.STATE_PLAYING)
            if data["playing"]:
                query = gst.query_new_seeking(gst.FORMAT_TIME)
                if data["playbin2"].query(query):
                    (aux, data["seek_enabled"], start, end) = query.parse_seeking()
                    if data["seek_enabled"]:
                        print "Seeking is ENABLED from %s to %s"%(convert_ns(start), convert_ns(end))
                    else:
                        print "Seeking is DISABLED for this stream."
                else:
                    print >> sys.stderr, "Seeking query failed."

                                      
                
            
    else:
        print >> sys.stderr, "Unexpected message received."
Exemple #4
0
  def on_message_state_changed(self, bus, message):

    t = message.type
    logging.debug("Message type %s received; source %s" % (t,type(message.src))) 
    
    if isinstance(message.src, gst.Pipeline):
      old_state, new_state, pending_state = message.parse_state_changed()

      # gst.STATE_NULL	    the NULL state or initial state of an element
      # gst.STATE_PAUSED    the element is PAUSED
      # gst.STATE_PLAYING   the element is PLAYING
      # gst.STATE_READY	    the element is ready to go to PAUSED
      # gst.STATE_VOID_PENDING    no pending state

      if pending_state == gst.STATE_VOID_PENDING:

        logging.debug("Pipeline state changed from %s to %s. Pendig: %s"%
                     (gst.element_state_get_name(old_state),
                      gst.element_state_get_name (new_state),
                      gst.element_state_get_name (pending_state)))
        
        if new_state == gst.STATE_READY :
          self.playmode = "Stopped"
          self.statuschanged = True
        elif new_state == gst.STATE_PAUSED:
          self.playmode = "Paused"
          self.statuschanged = True
        elif new_state == gst.STATE_PLAYING :
          self.playmode = "Playing"
          self.statuschanged = True
Exemple #5
0
def handle_message(data, msg):
    if message.type == gst.MESSAGE_ERROR:
        err, debug = message.parse_error()
        print >> sys.stderr, "Error received from element %s: %s" % (
            message.src.get_name(), err)
        print >> sys.stderr, "Debugging information: %s" % debug
        data["terminate"] = True
    elif message.type == gst.MESSAGE_EOS:
        print "End-Of-Stream reached."
        data["terminate"] = True
    elif message.type == gst.MESSAGE_DURATION:
        # The duration has changed, mark the current one as invalid
        data["duration"] = gst.CLOCK_TIME_NONE
    elif message.type == gst.MESSAGE_STATE_CHANGED:
        if message.src == data["playbin2"]:
            old_state, new_state, pending_state = message.parse_state_changed()
            print("Pipeline state changed from %s to %s." %
                  (gst.element_state_get_name(old_state),
                   gst.element_state_get_name(new_state)))
            data["playing"] = (new_state == gst.STATE_PLAYING)
            if data["playing"]:
                query = gst.query_new_seeking(gst.FORMAT_TIME)
                if data["playbin2"].query(query):
                    (aux, data["seek_enabled"], start,
                     end) = query.parse_seeking()
                    if data["seek_enabled"]:
                        print "Seeking is ENABLED from %s to %s" % (
                            convert_ns(start), convert_ns(end))
                    else:
                        print "Seeking is DISABLED for this stream."
                else:
                    print >> sys.stderr, "Seeking query failed."

    else:
        print >> sys.stderr, "Unexpected message received."
Exemple #6
0
 def state_changed():
     if src == self.pipeline:
         old, new, pending = message.parse_state_changed()
         self._change_monitor.state_changed(old, new)
         dump_filename = "%s.%s_%s" % (self.name,
                                       gst.element_state_get_name(old),
                                       gst.element_state_get_name(new))
         self.dump_gstreamer_debug_dot_file(dump_filename, True)
Exemple #7
0
 def state_changed():
     if src == self.pipeline:
         old, new, pending = message.parse_state_changed()
         self._change_monitor.state_changed(old, new)
         dump_filename = "%s.%s_%s" % (self.name,
             gst.element_state_get_name(old),
             gst.element_state_get_name(new))
         self.dump_gstreamer_debug_dot_file(dump_filename, True)
Exemple #8
0
	def addVideoPlayback(self, source):
		# Create the bin for these elements to be created in
		player = gst.Bin("vidPlayer_%d" % self.selChan)

		# Create the elements
		plsource = gst.element_factory_make('filesrc')
		pldec = gst.element_factory_make('decodebin')
		pltee = gst.element_factory_make("tee")
		plqueue1 = gst.element_factory_make("queue")
		plqueue2 = gst.element_factory_make("queue")
		plqueue3 = gst.element_factory_make("queue")
		plcolorspace1 = gst.element_factory_make("ffmpegcolorspace")
		plcolorspace2 = gst.element_factory_make("ffmpegcolorspace")
		plcolorspace3 = gst.element_factory_make("ffmpegcolorspace")

		plaudioconvert = gst.element_factory_make("audioconvert")
		plaudiosink = gst.element_factory_make("autoaudiosink")

		# Add the elements to the bin
		player.add(plsource, pldec, pltee, plqueue1, plqueue2, plqueue3,
							plaudioconvert, plaudiosink, plcolorspace1,
							plcolorspace2, plcolorspace3)

		# Link the elements together
		plsource.link(pldec)

		gst.element_link_many(pltee, plqueue1, plcolorspace1)
		gst.element_link_many(pltee, plqueue2, plcolorspace2)
		gst.element_link_many(pltee, plqueue3, plcolorspace3)

		# Video decoding needs to be dynamically linked at runtime - it is only then it know what type
		# of media it needs to decode. To do this you specify a 'new-decoded-pad' and the callback for when
		# this happens.
		self.vpad = pltee.get_pad('sink')
		self.apad = plaudioconvert.get_pad('sink')
		pldec.connect('new-decoded-pad', self.on_new_decoded_pad)

		# Set the location of the video to play
		plsource.set_property('location', source)

		# This creates the 'ghost pads' for vidPlayer bin. This allows to connect the bin to other elements
		binsink1 = gst.GhostPad("src_1", plcolorspace1.get_pad("src"))
		binsink2 = gst.GhostPad("src_2", plcolorspace2.get_pad("src"))
		binsink3 = gst.GhostPad("src_3", plcolorspace3.get_pad("src"))
		player.add_pad(binsink1)
		player.add_pad(binsink2)
		player.add_pad(binsink3)

		# For now I'm connecting to a fakesink (black hole!) as I can't manage to get it to 
		# connect to the videosink correctly
		plfakesink1 = gst.element_factory_make("fakesink")

		# Set the bin to playing
		player.set_state(gst.STATE_PLAYING)
		plfakesink1.set_state(gst.STATE_PLAYING)
		gst.element_state_get_name(gst.STATE_PLAYING)

		self.connectChannel(self.selChan, player, self.videoSinks[self.selChan - 1])
def state_changed_cb(bus, msg, data):
    old_state, new_state, pending_state = msg.parse_state_changed()
    if msg.src == data["playbin2"]:
        data["state"] = new_state;
        print "State set to %s"% gst.element_state_get_name(new_state)
        if old_state == gst.STATE_READY and new_state == gst.STATE_PAUSED:
            # For extra responsiveness, we refresh the GUI as soon as we reach the PAUSED state
            refresh_ui (data)
Exemple #10
0
def get_props(path):
    props = {}
    player = gst.parse_launch("filesrc name=source ! decodebin name=decoder ! queue ! fakesink decoder. ! queue ! fakesink")
    player.get_by_name("source").set_property("location", path)
    try:
        player.set_state(gst.STATE_PAUSED)
        while gst.element_state_get_name(player.get_state()[1]) != "PAUSED":
            time.sleep(0.01)
        for i in player.get_by_name("decoder").src_pads():
            structure_name = i.get_caps()[0].get_name()
            if structure_name.startswith("video") and len(str(i.get_caps()[0]["width"])) < 6:
                props['framerate'] = "{0:.2f}".format(i.get_caps()[0]["framerate"].__float__())
                props['pixel-aspect-ratio'] = i.get_caps()[0]["pixel-aspect-ratio"].__float__()
                props['resolution'] = (i.get_caps()[0]["width"], i.get_caps()[0]["height"])
                props['aspect-ratio'] = float(i.get_caps()[0]["width"]) / i.get_caps()[0]["height"] * i.get_caps()[0]["pixel-aspect-ratio"].__float__()
                break
    except:
        props = None
    finally:
        player.set_state(gst.STATE_NULL)
        return props
Exemple #11
0
 def get_state_string(self):
     '''Return a string representation of the pipeline state'''
     real_state = self.get_state()
     #real_state is a tuple, we want the second value here.
     string_state = gst.element_state_get_name(real_state[1])
     return string_state
while True:
    message = bus.timed_pop_filtered(35 * gst.SECOND, gst.MESSAGE_ANY)
    if not message:
        print "DO IT !!", pipeline.get_clock().get_time()
        print q.get_property("current-level-buffers"), q.get_property(
            "current-level-bytes"), q.get_property("current-level-time")
        #event = gst.event_new_eos()
        #sink.send_event(event)
    elif message.type == gst.MESSAGE_ERROR:
        err, debug = message.parse_error()
        print "Error received from element %s: %s" % (message.src.get_name(),
                                                      err)
        print "Debugging information: %s" % debug
        break
    elif message.type == gst.MESSAGE_EOS:
        print " - gst.MESSAGE_EOS: End-Of-Stream reached."
        break
    elif message.type == gst.MESSAGE_STATE_CHANGED:
        old_state, new_state, pending_state = message.parse_state_changed()
        print(" - gst.MESSAGE_STATE_CHANGED: %s state changed from %s to %s." %
              (message.src.get_name(), gst.element_state_get_name(old_state),
               gst.element_state_get_name(new_state)))
    elif message.type == gst.MESSAGE_ELEMENT:
        print " - gst.MESSAGE_ELEMENT: src %s ." % message.src.get_name()
    else:
        print "Unexpected message (%s) received." % message.type

# Free resources
pipeline.set_state(gst.STATE_NULL)
# Wait until error, EOS or State Change
bus = pipeline.get_bus()
while True:
    message = bus.timed_pop_filtered(
        gst.CLOCK_TIME_NONE,
        gst.MESSAGE_STATE_CHANGED | gst.MESSAGE_ERROR | gst.MESSAGE_EOS)
    if message.type == gst.MESSAGE_ERROR:
        err, debug = message.parse_error()
        print >> sys.stderr, "Error received from element %s: %s" % (
            message.src.get_name(), err)
        print >> sys.stderr, "Debugging information: %s" % debug
        break
    elif message.type == gst.MESSAGE_EOS:
        print "End-Of-Stream reached."
        break
    elif message.type == gst.MESSAGE_STATE_CHANGED:
        if isinstance(message.src, gst.Pipeline):
            old_state, new_state, pending_state = message.parse_state_changed()
            print("Pipeline state changed from %s to %s." %
                  (gst.element_state_get_name(old_state),
                   gst.element_state_get_name(new_state)))
            # Print the current capabilities of the sink element
            print_pad_capabilities(sink, "sink")
    else:
        # We should not reach here because we only asked for ERRORs, EOS and STATE_CHANGED
        print >> sys.stderr, "Unexpected message received."

# Free resources
pipeline.set_state(gst.STATE_NULL)
#Start playing
ret = data.pipeline.set_state(gst.STATE_PLAYING)
if (ret == gst.STATE_CHANGE_FAILURE):
    print >> sys.stderr, "Unable to set the pipeline to the playing state."
    exit(-1)

# Listen to the bus
bus = data.pipeline.get_bus()
while True:
    msg = bus.timed_pop_filtered(gst.CLOCK_TIME_NONE, 
                                    gst.MESSAGE_STATE_CHANGED | gst.MESSAGE_ERROR | gst.MESSAGE_EOS)
    if (msg.type == gst.MESSAGE_ERROR):
        err, debug = msg.parse_error()
        print >> sys.stderr, "Error received from element {0}: {1}\n".format(msg.src, err)
        print >> sys.stderr, "Debugging information {0}".format(debug)
    elif (msg.type == gst.MESSAGE_EOS):
        print "End-Of-Stream reached."
        break
    elif (msg.type == gst.MESSAGE_STATE_CHANGED):
        # We are only interested in state-changed messages from the pipeline
        if ( isinstance(msg.src, gst.Pipeline) ):
            old_state, new_state, pending_state = msg.parse_state_changed()
                
            print "Pipeline state changed from {0} to {1}".format(
                gst.element_state_get_name(old_state), gst.element_state_get_name(new_state))
    else:
        print >> sys.stderr, "Unexpected message received"

pipeline.set_state(gst.STATE_NULL)
Exemple #15
0
  def on_message(self, bus, message):
    try:
      if threading.currentThread() != mainloop_thread :
        err_resp("on_message is not run main thread -%s" % threading.currentThread())
      mtype= message.type
      if mtype== gst.MESSAGE_EOS:
        uri = self.player.get_property("uri")
        self.player.set_state(gst.STATE_NULL)
        resp("STOP")
        resp("EOS", uri)
      elif mtype== gst.MESSAGE_TAG:
        srctype = "-"
        if message.src:
          # video-bitrate or audio-bitrate? (fix-me ad hoc!)
          klass = message.src.get_factory().get_klass().lower()
          # print "srcname=", message.src.get_name(), " klass=",klass # debug
          if "audio" in klass: srctype = "A"
          elif "video" in klass: srctype = "V"
        tags = message.parse_tag()
        for k in tags.keys():
          v = tags[k]
          if isinstance(v, (basestring, int, float, long, bool, gst.Date)):
            resp("TAG", srctype, "%s=%s" % (k, v))
          else:
            # if _isdebug: # image test
            #  if k == "image" and isinstance(v, gst.Buffer): self.test_image(v)
            resp("TAG", srctype, "%s=%s" % (k, type(v)))
      elif mtype == gst.MESSAGE_STATE_CHANGED:
        (o_state, n_state, pending) = message.parse_state_changed()
        (old, new, ps) = ( gst.element_state_get_name(o_state),
                           gst.element_state_get_name(n_state),
                           gst.element_state_get_name(pending))
        # _puts("State changed %s => %s pending:%s",old, new, ps)
        # _puts("audio-sink %s", self.player.get_property("audio-sink"))
        if not self.asink_org:
          # Set original audiosink
          asink = self.player.get_property("audio-sink")
          if asink and (asink != self.recsink):
            _puts("Set original asink to %s", asink)
            self.asink_org = asink
        elif (o_state == gst.STATE_READY) and (n_state == gst.STATE_PAUSED):
          # Report audiosink negotiated capacities
          self.report_caps(self.asink_org)

        if self.requests:
          self.response_by_state(o_state, n_state)

      elif mtype== gst.MESSAGE_WARNING:
        err, debug = message.parse_warning()
        if _isdebug: wrn_resp("%s - %s" % (err, debug))
        else: wrn_resp(err)
      elif mtype== gst.MESSAGE_ERROR:
        self.player.set_state(gst.STATE_NULL)
        err, debug = message.parse_error()
        if _isdebug: err_resp("%s - %s" % (err, debug))
        else: err_resp(err)
        self.stop()
        resp("STOP")
      else:
        _puts("On message: Unsupported message type %s", mtype)
        _puts("  src %s", message.src)
        struct = message.structure
        if struct is not None:
          _puts("  structure:")
          for k in struct.keys():
            _puts("    key=%s value=%s", k , struct[k])
    except Exception , exc:
      err_resp("on_message - %s" % exc)
Exemple #16
0
    elif not os.path.isdir(dirpath):
      raise IOError("Fail to create a directory `%s'" % dirpath)

    if not os.path.exists(fname):
      return fname
    (base, ext) = os.path.splitext(fname)
    for n in xrange(1, sys.maxint):
      name = "".join((base, ("-%d" % n), ext))
      _puts("FileTempl#nextfile name=%s",name)
      if not os.path.exists(name): return name
    raise IOError("Fail to create recording file")

(_LOADING, _LOADED, _PLAYING, _PLAYED, _STOPPING, _STOPPED,
 _PAUSING, _PAUSED ) = range(1, 9)

_STATE_TAB = dict((gst.element_state_get_name(state), state)
                  for state in (gst.STATE_NULL, gst.STATE_READY, gst.STATE_PAUSED,
                                gst.STATE_PLAYING, gst.STATE_VOID_PENDING))
state2str = gst.element_state_get_name
def str2state(skey):
  return _STATE_TAB.get(skey.upper())

_STATE_CHANGE_TAB = {gst.STATE_CHANGE_SUCCESS:"SUCCESS",
                     gst.STATE_CHANGE_ASYNC:"ASYNC",
                     gst.STATE_CHANGE_FAILURE:"FAILURE",
                     gst.STATE_CHANGE_NO_PREROLL:"PREROLL"}
def state_change2str(v):
  return _STATE_CHANGE_TAB.get(v, "UNKNOWN")
  
class CLIPlayer(object):
Exemple #17
0
 def get_state_string(self):
     '''Return a string representation of the pipeline state'''
     real_state = self.get_state()
     #real_state is a tuple, we want the second value here.
     string_state = gst.element_state_get_name(real_state[1])
     return string_state
bus = pipeline.get_bus()
bus.add_signal_watch()

while True:
    message = bus.timed_pop_filtered(35 * gst.SECOND, gst.MESSAGE_ANY)
    if not message:
        print "DO IT !!", pipeline.get_clock().get_time()
        print q.get_property("current-level-buffers"), q.get_property("current-level-bytes"), q.get_property("current-level-time")
        #event = gst.event_new_eos()
        #sink.send_event(event)
    elif message.type == gst.MESSAGE_ERROR:
        err, debug = message.parse_error()
        print "Error received from element %s: %s"% (message.src.get_name(), err)
        print "Debugging information: %s"% debug
        break
    elif message.type == gst.MESSAGE_EOS:
        print " - gst.MESSAGE_EOS: End-Of-Stream reached."
        break
    elif message.type == gst.MESSAGE_STATE_CHANGED:
        old_state, new_state, pending_state = message.parse_state_changed()
        print (" - gst.MESSAGE_STATE_CHANGED: %s state changed from %s to %s."% 
               (message.src.get_name(), gst.element_state_get_name(old_state), gst.element_state_get_name (new_state)))
    elif message.type == gst.MESSAGE_ELEMENT:
        print " - gst.MESSAGE_ELEMENT: src %s ."% message.src.get_name()
    else:
        print "Unexpected message (%s) received." % message.type


# Free resources
pipeline.set_state(gst.STATE_NULL)
Exemple #19
0
	def closeEvent(self, event):
		self.pipeM.pipeline.set_state(gst.STATE_NULL)
		gst.element_state_get_name(gst.STATE_NULL)