set property value from a string

Gary Metalle Gary.Metalle at rvl.co.uk
Thu Jul 23 11:51:50 UTC 2020


Hi Matt


Yes thanks for that, it seems to work fine. I actually used gst_util_set_value_from_string() which is a close relative.


I am having trouble checking whether the converted value is within bounds though, g_param_value_validate() always seems to return FALSE. I can live without checking for the moment, but if anyone spots anything obvious, let me know:


GValue prop_value = G_VALUE_INIT;

GParamSpec *realParamSpec;

realParamSpec = g_object_class_find_property(G_OBJECT_GET_CLASS("x264enc), "bitrate");
if (realParamSpec) {
g_value_init(&prop_value, G_PARAM_SPEC_VALUE_TYPE(realParamSpec));

gst_util_set_value_from_string(&prop_value, "500");

if (g_param_value_validate(realParamSpec, &prop_value)) {
                            // this is good
                        } else {
                            // not within bounds
                        }
    } else // property doesn't exist



________________________________
From: Matthew Waters <ystreet00 at gmail.com>
Sent: 23 July 2020 11:04
To: Discussion of the development of and with GStreamer; Gary Metalle
Subject: Re: set property value from a string

gst_parse_launch() uses gst_util_set_object_arg(): https://gstreamer.freedesktop.org/documentation/gstreamer/gstutils.html?gi-language=c#gst_util_set_object_arg

On 23/7/20 8:00 pm, Gary Metalle wrote:

Is there a way to set a property value from a given string, i.e convert from G_STRING to whatever type is required for that property?


I have a string such as the following:


"byte-stream=TRUE rc-lookahead=0 tune=zerolatency speed-preset=ultrafast sync-lookahead=0"


That I split up into name/value pairs and then need to set each property.


I first use g_object_class_find_property() to find out if the named property exists and this is ok and it returns a GParamSpec which tells me the type of the property.


I've tried using g_value_transform() but this only seems to be able to cope with simple stuff like converting a double to an int etc. Is there no simple way to convert say a string of "TRUE" to a gboolean?

I have also tried g_param_convert() but didn't get anywhere with that either.


Someone must be doing it somehow because if you pass a pipeline string to gst_parse_launch() then it has to cope with this. It would be easy to custom write something for "TRUE"/"FALSE" to gboolean but not so for the enum types and the x264enc plugin has quite a few of those.


On a positive note I think g_param_value_validate() works when you want to check that a given value is within the range for the defined property, but it implies you've converted it to the correct type first.



_______________________________________________
gstreamer-devel mailing list
gstreamer-devel at lists.freedesktop.org<mailto:gstreamer-devel at lists.freedesktop.org>
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20200723/c3775e61/attachment-0001.htm>


More information about the gstreamer-devel mailing list