<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none"><!-- p { margin-top: 0px; margin-bottom: 0px; }--></style>
</head>
<body dir="ltr" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Just for completeness I sussed out the problem with validating a property value...<br>
</p>
<p><br>
</p>
<p>The return value from <span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);"><strong>g_param_value_validate</strong></span><strong style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">()</strong>​
 returns TRUE if it had to modify the value in order to keep the value within the bounds for the property and FALSE if the value you passed in was already good.<br>
</p>
<p><br>
</p>
<p>I think it's slightly confusing that a call to a function called <strong style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px;">g_param_value_validate</strong>​ returns a FALSE value when it is given a valid parameter to validate, but
 never mind, once you understand how it works, it's easy.<br>
</p>
<p><br>
</p>
<p>I ignore the return value if it's FALSE and print out a whinge warning if TRUE that the property value has been set to a different (but valid) value compared to the requested value which was invalid.<br>
</p>
<p><br>
</p>
<p>Gary.<br>
</p>
<div dir="ltr" style="font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> gstreamer-devel <gstreamer-devel-bounces@lists.freedesktop.org> on behalf of Gary Metalle <Gary.Metalle@rvl.co.uk><br>
<b>Sent:</b> 23 July 2020 12:51<br>
<b>To:</b> Discussion of the development of and with GStreamer<br>
<b>Subject:</b> Re: set property value from a string</font>
<div> </div>
</div>
<div>
<p>Hi Matt<br>
</p>
<p><br>
</p>
<p>Yes thanks for that, it seems to work fine. I actually used <strong>gst_util_set_value_from_string()</strong> which is a close relative.<br>
</p>
<p><br>
</p>
<p>I am having trouble checking whether the converted value is within bounds though,
<span style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:16px; background-color:rgb(255,255,255)">
<strong>g_param_value_validate</strong></span><strong>()</strong> always seems to return FALSE. I can live without checking for the moment, but if anyone spots anything obvious, let me know:<br>
</p>
<p><span style="font-size:12pt; white-space:pre"><br>
</span></p>
<p><span style="font-size:12pt; white-space:pre"></span><span style="font-size:12pt">GValue prop_value = G_VALUE_INIT;</span><br>
</p>
<div>
<div><span style="white-space:pre"></span>GParamSpec *realParamSpec;<br>
</div>
<div><br>
</div>
<span style="white-space:pre"></span>realParamSpec = g_object_class_find_property(G_OBJECT_GET_CLASS("x264enc), "bitrate");</div>
<div><span style="white-space:pre"></span>if (realParamSpec) {<br>
</div>
<div>
<div>
<div><span style="white-space:pre"></span>g_value_init(&prop_value, G_PARAM_SPEC_VALUE_TYPE(realParamSpec));<br>
</div>
<div><br>
</div>
<span style="white-space:pre"></span>gst_util_set_value_from_string(&prop_value, "500");</div>
<div><br>
</div>
<div><span style="white-space:pre"></span>if (g_param_value_validate(realParamSpec, &prop_value)) {</div>
<div>                            // this is good<br>
                        } else {<br>
</div>
<div>                            // not within bounds<br>
</div>
<div>                        }<br>
</div>
<div>    } else // property doesn't exist<br>
</div>
<div><br>
</div>
</div>
<p><br>
</p>
<div style="color:rgb(33,33,33)">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Matthew Waters <ystreet00@gmail.com><br>
<b>Sent:</b> 23 July 2020 11:04<br>
<b>To:</b> Discussion of the development of and with GStreamer; Gary Metalle<br>
<b>Subject:</b> Re: set property value from a string</font>
<div> </div>
</div>
<div>
<div class="moz-cite-prefix">gst_parse_launch() uses gst_util_set_object_arg(): <a href="https://gstreamer.freedesktop.org/documentation/gstreamer/gstutils.html?gi-language=c#gst_util_set_object_arg">
https://gstreamer.freedesktop.org/documentation/gstreamer/gstutils.html?gi-language=c#gst_util_set_object_arg</a><br>
<br>
On 23/7/20 8:00 pm, Gary Metalle wrote:<br>
</div>
<blockquote type="cite"><style type="text/css" style="">
<!--
p
        {margin-top:0px;
        margin-bottom:0px}
-->
</style>
<p>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?<br>
</p>
<p><br>
</p>
<p>I have a string such as the following:<br>
</p>
<p><br>
</p>
<p>"byte-stream=TRUE rc-lookahead=0 tune=zerolatency speed-preset=ultrafast sync-lookahead=0"<br>
</p>
<p><br>
</p>
<p>That I split up into name/value pairs and then need to set each property.<br>
</p>
<p><br>
</p>
<p>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.<br>
</p>
<p><br>
</p>
<p>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?<br>
</p>
<p>I have also tried g_param_convert() but didn't get anywhere with that either.<br>
</p>
<p><br>
</p>
<p>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.<br>
</p>
<p><br>
</p>
<p>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.<br>
</p>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre">_______________________________________________
gstreamer-devel mailing list
<a class="moz-txt-link-abbreviated" href="mailto:gstreamer-devel@lists.freedesktop.org">gstreamer-devel@lists.freedesktop.org</a>
<a class="moz-txt-link-freetext" href="https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel">https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel</a>
</pre>
</blockquote>
<br>
</div>
</div>
</div>
</div>
</body>
</html>