将PyGST应用程序移植到GStreamer1.0 + PyGI

时间:2013-08-10 19:35:47

标签: python gstreamer

我有一个基于gstreamer和dbus http://sourceforge.net/p/autoradiobc/code/210/tree/trunk/autoradio/autoplayer/player_gstreamer1.py的python音频播放器。它适用于pygst,我希望将它移植到gstreamer 1。 在此之后如何https://wiki.ubuntu.com/Novacut/GStreamer1.0它将起作用,但是:

File "/home/pat1/svn/autoradio/autoradio/autoplayer/player.py", line 826, in position
except(Gst.QueryError):
File "/usr/lib64/python2.7/site-packages/gi/module.py", line 316, in __getattr__
return getattr(self._introspection_module, name)
File "/usr/lib64/python2.7/site-packages/gi/module.py", line 135, in __getattr__
self.__name__, name))
AttributeError: 'gi.repository.Gst' object has no attribute 'QueryError'

这是代码的这一部分:

try:
  pos_int = self.player.query_position(Gst.Format.TIME, None)[0]
except(Gst.QueryError):
  logging.warning( "Gst.QueryError in query_position" )
  return None

在我得到之后绕过这个问题:

if ret == Gst.State.CHANGE_FAILURE:
AttributeError: type object 'GstState' has no attribute 'CHANGE_FAILURE'

在这部分代码中:

ret = self.player.set_state(Gst.State.READY)
if ret == Gst.State.CHANGE_FAILURE:
  logging.error( "Unable to set the pipeline to the READY state.")

也绕过了这个问题,我得到了:

File "/home/pat1/svn/autoradio/autoradio/autoplayer/player.py", line 659, in on_message_state_changed
(Gst.element_state_get_name(old_state),
File "/usr/lib64/python2.7/site-packages/gi/module.py", line 316, in __getattr__
return getattr(self._introspection_module, name)
File "/usr/lib64/python2.7/site-packages/gi/module.py", line 135, in __getattr__
self.__name__, name))
AttributeError: 'gi.repository.Gst' object has no attribute 'element_state_get_name'

在这部分代码中:

    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)))

注释掉玩家将要工作的element_state_get_name ....

如何在不绕过损坏的代码的情况下迁移到gstreamer 1的完整代码?

1 个答案:

答案 0 :(得分:2)

我无法找到有关QueryError

的第一个问题的解决方案

但是:

if ret == Gst.State.CHANGE_FAILURE:

成为:

if ret == Gst.StateChangeReturn.FAILURE:

Gst.element_state_get_name(old_state)

成为:

Gst.Element.state_get_name(old_state)

      self.player.set_new_stream_time(0L)

成为:

      self.player.set_start_time(0L)

     event = Gst.event_new_seek(1.0, Gst.Format.TIME,
             Gst.SeekFlags.FLUSH|Gst.SeekFlags.ACCURATE,
             Gst.SEEK_TYPE_SET, tnano, Gst.SEEK_TYPE_NONE, 0)

成为:

     event = Gst.Event.new_seek(1.0, Gst.Format.TIME,
             Gst.SeekFlags.FLUSH|Gst.SeekFlags.ACCURATE,
             Gst.SeekType.SET, tnano, Gst.SeekType.NONE, 0)

    pos_int = self.player.query_duration(Gst.Format.TIME, None)[0]

成为:

    pos_int = self.player.query_duration(Gst.Format.TIME)[1]