1

I am using Gstreamer 1.0 with Python bindings. Below is the pipeline I am trying to build considering Opengl plugins :

gltestsrc -> gltransformation -> glimagesink

I am trying to modify the properties of element 'gltransformation' dynamically based on the values received from external hardware device. Here is the link, for a similar question but it did not help me much in my usecase. Below is the snipped of the python script :

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

#global variables 
#the values of a,b,c get updated for certain events dynamically based on external hardware 
a = 0 
b= 0 
c = 0 


source = Gst.ElementFactory.make("gltestsrc", "source") 
gltrnsfrm = Gst.ElementFactory.make("gltransformation","gltrnsfrm") 
sink = Gst.ElementFactory.make("glimagesink", "sink") 

# create the empty pipeline 
pipeline = Gst.Pipeline.new("test-pipeline") 

if not pipeline or not source or not gltrnsfrm or not sink: 
    print("ERROR: Not all elements could be created") 
    sys.exit(1) 

# build the pipeline 
pipeline.add(source,gltrnsfrm,sink) 

if not source.link(gltrnsfrm): 
    print("ERROR: Could not link source to gltrsnfrm") 
    sys.exit(1) 

if not gltrnsfrm.link(sink): 
   print("ERROR: Could not link gltrsnfrm  to sink") 
   sys.exit(1) 

# modify the gltransformation's properties 
gltrnsfrm.set_property("rotation-z",a) 
gltrnsfrm.set_property("rotation-x",b) 
gltrnsfrm.set_property("rotation-y",c) 

#dynamic controller
cs = GstController.InterpolationControlSource()
cs.set_property('mode', GstController.InterpolationMode.LINEAR)
cb= Gstcontorller.DirectControlBinding.new(gltrnsfrm,"rotation-x",cs)
gltrnsfrm.add_control_binding(cb)

#modify the values
cs.set(0*Gst.SECOND,b)  #use updated values of b
cs.set(1*Gst.SECOND,b)

The above example shows only modification of 1 element property, however, I have other properties as well to be modified based on the values of a,b & c.

Executing the above script gives me the following error:

GStreamer-CRITICAL : gst_object_add_control_binding: assertion 'binding->pspec' failed. 

I think I have to set certain more attributes in python to get this working. Does anyone have a hand on this issue?

EDIT: After the suggestions from Hugh Fisher, I tried to trace back to the source of the file. Here is a snippet from the original code :

GST_INFO_OBJECT (object, "trying to put property '%s' under control",
  binding->name);

/* check if the object has a property of that name */
if ((pspec =
      g_object_class_find_property (G_OBJECT_GET_CLASS (object),
          binding->name))) {
GST_DEBUG_OBJECT (object, "  psec->flags : 0x%08x", pspec->flags);

/* check if this param is witable && controlable && !construct-only */
if ((pspec->flags & (G_PARAM_WRITABLE | GST_PARAM_CONTROLLABLE |
            G_PARAM_CONSTRUCT_ONLY)) ==
    (G_PARAM_WRITABLE | GST_PARAM_CONTROLLABLE)) {
  binding->pspec = pspec;
} else {
  GST_WARNING_OBJECT (object,
      "property '%s' on class '%s' needs to "
      "be writeable, controlable and not construct_only", binding->name,
      G_OBJECT_TYPE_NAME (object));
}
} else {
GST_WARNING_OBJECT (object, "class '%s' has no property '%s'",
    G_OBJECT_TYPE_NAME (object), binding->name);
}

gst_object_unref (object);

And this is the log file for my script :

0:00:00.174410648 [336m 8309[00m       0xd1b750 [37mTRACE  [00m [00;01;31;44m     GST_REFCOUNTING gstobject.c:207:gst_object_init:<GstObject@0x10b0020>[00m 0x10b0020 new
0:00:00.174697421 [336m 8309[00m       0xd1b750 [37mTRACE  [00m [00;01;31;44m     GST_REFCOUNTING gstobject.c:207:gst_object_init:<GstObject@0x10b20f0>[00m 0x10b20f0 new
0:00:00.174716708 [336m 8309[00m       0xd1b750 [36mINFO   [00m [00m   gstcontrolbinding gstcontrolbinding.c:144:gst_control_binding_constructor:<gltrnsfrm>[00m trying to put property 'rotation-x' under control
0:00:00.174723927 [336m 8309[00m       0xd1b750 [37mDEBUG  [00m [00m   gstcontrolbinding gstcontrolbinding.c:150:gst_control_binding_constructor:<gltrnsfrm>[00m   psec->flags : 0x000000e3
0:00:00.174729088 [336m 8309[00m       0xd1b750 [33;01mWARN   [00m [00m   gstcontrolbinding gstcontrolbinding.c:161:gst_control_binding_constructor:<gltrnsfrm>[00m property 'rotation-x' on class 'GstGLTransformation' needs to be writeable, controlable and not construct_only
0:00:00.174733951 [336m 8309[00m       0xd1b750 [37mTRACE  [00m [00;01;31;44m     GST_REFCOUNTING gstobject.c:264:gst_object_unref:<gltrnsfrm>[00m 0x10a60e0 unref 4->3

(python3:8309): GStreamer-CRITICAL **: 10:37:00.609: gst_object_add_control_binding: assertion 'binding->pspec' failed

As per the man page of 'gltransformation', the properties rotation-x/y/z, are writable and readable. Also here is a link, of an application that takes input from GUI and changes the rotation-x/y/z for 'gltransformation'. I have no clue, why here in my case this is an issue.

  #gst-inspect-1.0 gltransformation
  translation-x       : Translates the video at the X-Axis, in universal [0-1] coordinate.
                        flags: readable, writable
                        Float. Range:   -3,402823e+38 -    3,402823e+38 Default:               0 
  translation-y       : Translates the video at the Y-Axis, in universal [0-1] coordinate.
                        flags: readable, writable
                        Float. Range:   -3,402823e+38 -    3,402823e+38 Default:               0 
  translation-z       : Translates the video at the Z-Axis, in universal [0-1] coordinate.
                        flags: readable, writable
                        Float. Range:   -3,402823e+38 -    3,402823e+38 Default:               0 
  rotation-x          : Rotates the video around the X-Axis in degrees.
                        flags: readable, writable
                        Float. Range:   -3,402823e+38 -    3,402823e+38 Default:               0 
  rotation-y          : Rotates the video around the Y-Axis in degrees.
                        flags: readable, writable
                        Float. Range:   -3,402823e+38 -    3,402823e+38 Default:               0 
  rotation-z          : Rotates the video around the Z-Axis in degrees.
                        flags: readable, writable
                        Float. Range:   -3,402823e+38 -    3,402823e+38 Default:               0 

Edit 2: updated the code, with a workaround for issue:

class Thread(object):
def __init__(self):
    thread = threading.Thread(target=self.get)
    self.gltrnsfrm = Gst.ElementFactory.make("gltransformation","gltrnsfrm")
    thread.start()

def get(self):
   try:

        global a,b,c
        while True:
            self.gltrnsfrm.set_property("rotation-z",a)
            self.gltrnsfrm.set_property("rotation-x",b)
            self.gltrnsfrm.set_property("rotation-y",c)
            #time.sleep(0.01)
    except KeyboardInterrupt:
        pass

The rest of the code is the same(with minor adaptation to use the threads) as described before in the post. However, the following code was ommited :

#dynamic controller
cs = GstController.InterpolationControlSource()
cs.set_property('mode', GstController.InterpolationMode.LINEAR)
cb= Gstcontorller.DirectControlBinding.new(gltrnsfrm,"rotation-x",cs)
gltrnsfrm.add_control_binding(cb)

#modify the values
cs.set(0*Gst.SECOND,b)  #use updated values of b
cs.set(1*Gst.SECOND,b)
gst
  • 1,251
  • 1
  • 14
  • 32
  • My guess is that the control binding object, your cb, is expecting to find a GParamSpec for the 'mode' property of your cs object and/or GParamSpecs for the rotation-x/y/z properties of your gltrnsfrm object. Most likely cs mode because the error message refers to the binding object pspec. Hope this helps. – Hugh Fisher Aug 07 '18 at 00:05
  • @HughFisher : Added more debug info that displays information on the binding object. Can you suggest me what could be done here? – gst Aug 07 '18 at 09:43

1 Answers1

0

The problem here is that the gltransformation properties are not controllable. i.e. they don't have the GST_PARAM_CONTROLLABLE flag on property creation in the code.

You can either add controllability to gltransformation by proposing a patch upstream or not relying on controllable properties.

ystreet00
  • 240
  • 1
  • 4
  • Is it possible to use 'g_object_class_install_property' in the python-script and modify the property ? Or is there another way to set the rotation-x/y/z dynamically? – gst Aug 07 '18 at 12:17
  • 2
    No, `g_object_class_install_property` is intended for subclasses. You don't have to use control bindings to set a property dynamically. You can simply keep calling `set_property` as many times as you like. – ystreet00 Aug 07 '18 at 12:23
  • @ysteet00 in my case, I want to get updated values(atleast every 100ms) as long as the video is playing. The next step is to use a live video, instead of 'gltestsrc' – gst Aug 07 '18 at 12:34
  • Then you can do that however you like using whatever method you like. whether that's async/await, glib mainloop, running an extra python thread, etc. – ystreet00 Aug 08 '18 at 05:11
  • I followed your suggestion to keep calling `set_property`, and it worked. However, the rendering of the video is choppy- the previous frames are seen in addition to current frames. Any suggestions, on how to filter this out, and obtain a smooth black background, except for the current frame? Here are the images [rotation-y](https://i.imgur.com/m8NM141.png) , [rotation-y](https://i.imgur.com/gJY30xY.png) and [rotation-z](https://i.imgur.com/NbuqkO4.png) – gst Aug 08 '18 at 08:16
  • That looks like no-one's `glClear()`ing from the previous frame somewhere. Can you post your updated code? Perhaps on a bug [here](https://bugzilla.gnome.org/enter_bug.cgi?product=GStreamer&component=gst-plugins-base) – ystreet00 Aug 10 '18 at 10:24
  • @ysteet00 : updated the code. I replaced the `gltestsrc` with `v4l2src`, and it works fine with a smooth video. I can raise a bug once, you confirm that I am not doing anything wrong in the above code :) – gst Aug 10 '18 at 11:11
  • This was an issue in GStreamer that has since been fixed thanks to this question :). Change is [here](https://cgit.freedesktop.org/gstreamer/gst-plugins-base/commit/?id=91bc6f63f67f19426aca638452f507c8b9928499). Your code looks good – ystreet00 Aug 10 '18 at 12:48
  • Also created an enhancement to introduce dynamic control for rotation properties [here](https://bugzilla.gnome.org/show_bug.cgi?id=796960) . – gst Aug 14 '18 at 12:06