Tuesday, June 18, 2013

Porting gstreamer.py and test_common_gstreamer.py

To make a port for the audio test  i'll have to port gstreamer.py, feedcomponent.py and check.py , because audiotest.py imports them.
(gst.* is replaced with Gst.* everywhere)
1. I'll start off with gstreamer.py which is a set of  gstreamer helpers:

  import gst

#is replaced with

  import gi
  gi.require_version('Gst', '1.0')
  from gi.repository import Gst

2. In function element_factory_has_property:


    e = gst.element_factory_make(element_factory)

#is replaced with

    e = Gst.element_factory.make(element_factory)

3. In function element_factory_has_property_value:

    e = gst.element_factory_make(element_factory)

#is replaced with (same as the one before)

    e = Gst.element_factory.make(element_factory)

4, In function element_factory_exists:

    registry = gst.registry_get_default()
#is replaced with
    registry = Gst.registry_get()

5. In function get_plugin_version:

    plugin = gst.registry_get_default().find_plugin(plugin_name)
#is replaced with
    plugin = Gst.registry_get().find_plugin(plugin_name)
6. In function get_state_change:

    table = {(gst.STATE_NULL, gst.STATE_READY):
             gst.STATE_CHANGE_NULL_TO_READY,
             (gst.STATE_READY, gst.STATE_PAUSED):
             gst.STATE_CHANGE_READY_TO_PAUSED,
             (gst.STATE_PAUSED, gst.STATE_PLAYING):
             gst.STATE_CHANGE_PAUSED_TO_PLAYING,
             (gst.STATE_PLAYING, gst.STATE_PAUSED):
             gst.STATE_CHANGE_PLAYING_TO_PAUSED,
             (gst.STATE_PAUSED, gst.STATE_READY):
             gst.STATE_CHANGE_PAUSED_TO_READY,
             (gst.STATE_READY, gst.STATE_NULL):
             gst.STATE_CHANGE_READY_TO_NULL}

#is replaced with

table = {(Gst.STATE.NULL, Gst.STATE.READY):
             Gst.STATE.CHANGE_NULL_TO_READY,
             (Gst.STATE.READY, Gst.STATE.PAUSED):
             Gst.STATE.CHANGE_READY_TO_PAUSED,
             (Gst.STATE.PAUSED, Gst.STATE.PLAYING):
             Gst.STATE.CHANGE_PAUSED_TO_PLAYING,
             (Gst.STATE.PLAYING, Gst.STATE.PAUSED):
             Gst.STATE.CHANGE_PLAYING_TO_PAUSED,
             (Gst.STATE.PAUSED, Gst.STATE.READY):
             Gst.STATE.CHANGE_PAUSED_TO_READY,
             (Gst.STATE.READY, Gst.STATE.NULL):
             Gst.STATE.CHANGE_READY_TO_NULL}

7. In function have_error:

        changes = [gst.STATE_CHANGE_NULL_TO_READY,
                   gst.STATE_CHANGE_READY_TO_PAUSED,
                   gst.STATE_CHANGE_PAUSED_TO_PLAYING]

        extras = ((gst.STATE_PAUSED, gst.STATE_CHANGE_PLAYING_TO_PAUSED),
                  (gst.STATE_READY, gst.STATE_CHANGE_PAUSED_TO_READY),
                  (gst.STATE_NULL, gst.STATE_CHANGE_READY_TO_NULL))

#is replaced with

        changes = [Gst.STATE.CHANGE_NULL_TO_READY,
                   Gst.STATE.CHANGE_READY_TO_PAUSED,
                   Gst.STATE.CHANGE_PAUSED_TO_PLAYING]

        extras = ((Gst.STATE.PAUSED, Gst.STATE.CHANGE_PLAYING_TO_PAUSED),
                  (Gst.STATE.READY, Gst.STATE.CHANGE_PAUSED_TO_READY),
                  (Gst.STATE.NULL, Gst.STATE.CHANGE_READY_TO_NULL))

Now i'll have to port the unit test for the gstreamer module, test_common_gstreamer:

1.

  import gst

#is replaced with

  import gi
  gi.require_version('Gst', '1.0')
  from gi.repository import Gst

2. In class Caps, function testCaps:


caps = gst.caps_from_string(
            'video/x-raw-yuv,width=10,framerate=5.0;video/x-raw-rgb,'
            'width=15,framerate=10.0')
        self.assertEquals(gstreamer.caps_repr(caps),
            'video/x-raw-yuv, width=(int)10, '
                          'framerate=(double)5; video/x-raw-rgb, '
                          'width=(int)15, framerate=(double)10')



#is replaced with


    def testCaps(self):

        caps = Gst.caps_from_string(
            'video/x-raw-yuv,width=10,framerate=5.0;video/x-raw-rgb,'
            'width=15,framerate=10.0')
        self.assertEquals(gstreamer.caps_repr(caps),
            'video/x-raw-yuv, width=(int)10, '
                          'framerate=(double)5; video/x-raw-rgb, '
                          'width=(int)15, framerate=(double)10')


3. In class FakeComponent, function run_it_a_little_while:


    p.set_state(gst.STATE_PLAYING)
    m = p.get_bus().poll(gst.MESSAGE_EOS, -1)
    p.set_state(gst.STATE_NULL)


#is replaced with

    p.set_state(Gst.STATE.PLAYING)
    m = p.get_bus().poll(Gst.MESSAGE_EOS, -1)
    p.set_state(Gst.STATE.NULL)




After the porting i tried to run the test using Trial and i got:


[ERROR]
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/twisted/trial/runner.py", line 660, in loadByNames
    things.append(self.findByName(name))
  File "/usr/lib/python2.7/dist-packages/twisted/trial/runner.py", line 470, in findByName
    return reflect.namedAny(name)
  File "/usr/lib/python2.7/dist-packages/twisted/python/reflect.py", line 464, in namedAny
    topLevelPackage = _importAndCheckStack(trialname)
  File "/flumotion/flumotion/test/test_common_gstreamer.py", line 18, in <module>
    import gi
  File "/usr/lib/python2.7/dist-packages/gi/__init__.py", line 23, in <module>
    from ._gi import _API, Repository
exceptions.ImportError: could not import gobject (error was: ImportError('When using gi.repository you must not import static modules like "gobject". Please change all occurrences of "import gobject" to "from gi.repository import GObject".',))

flumotion.test.test_common_gstreamer

Even tho i've changed all occurrences of "import gobject" to "from gi.repository import GObject"


3 comments :

  1. Have you tried from gi.repository import GObject, Gst

    ReplyDelete
  2. You don't need to document exactly every change you make - just the broad strokes and the problems you run into. A lot of the above is just search and replace, no?

    ReplyDelete
  3. True. I'll keep that in mind.

    ReplyDelete