[1.1.1] MediaTransporterGst: refactor using gst_util_set_object_arg() 78/313278/5
authorSeungbae Shin <seungbae.shin@samsung.com>
Fri, 21 Jun 2024 08:13:39 +0000 (17:13 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Mon, 5 Aug 2024 06:13:44 +0000 (15:13 +0900)
Change-Id: I0fc990551eb5c0ec9c88534a3ecdf6af1599d3be

include/MediaTransporterGst.h
src/MediaTransporterGst.cpp

index 7cbecfd2e717099630d1b8bd26068ecb6abc75cb..16a564f610e76fc2fc147d35ec41c66700bbe4e9 100644 (file)
@@ -97,7 +97,7 @@ bool _setGhostpadTarget(GstPad* ghost_pad, GstElement* target_element, bool isSr
 GstPad* _getGhostPadFromBin(GstBin* bin, const std::string& name, bool isSrcPad);
 unsigned int _getUnoccupiedSourceId(GHashTable* slots);
 
-void _setElementProperties(GstElement* element, std::vector<std::string> key_value_pairs);
+void _setElementProperties(GstElement* element, const std::vector<std::string>& key_value_pairs);
 void _applyStreamInfo(GstElement* element, std::string streamInfo);
 void _addElementsToBin(GstBin* bin, GstElements elements);
 void _removeElementsFromBin(GstBin* bin, GstElements& elements);
index eb240595d0c7e12d39970b5f7369784724b0dea6..cd160c137f78dade19752d1e72676ab8a93a1f42 100644 (file)
@@ -225,79 +225,35 @@ void gst::_linkElements(GstElements& elements)
        LOG_DEBUG("%zu elements are linked", elements.size());
 }
 
-static void __parse_type_and_set_value(GType type, GstElement* element, gchar** key_value_pair)
+void gst::_setElementProperties(GstElement* element, const std::vector<std::string>& key_value_pairs)
 {
        RET_IF(!element, "element is NULL");
-       RET_IF(!key_value_pair, "key_value_pairs is NULL");
-       RET_IF(!key_value_pair[0], "key is NULL");
-       RET_IF(!key_value_pair[1], "value is NULL");
 
-       switch (type) {
-       case G_TYPE_STRING:
-               g_object_set(G_OBJECT(element), key_value_pair[0], key_value_pair[1], NULL);
-               break;
-       case G_TYPE_INT:
-       case G_TYPE_INT64:
-       case G_TYPE_ENUM: {
-               gint64 value = g_ascii_strtoll(static_cast<const gchar*>(key_value_pair[1]), NULL, 10);
-               g_object_set(G_OBJECT(element), key_value_pair[0], value, NULL);
-               break;
-       }
-       case G_TYPE_UINT:
-       case G_TYPE_UINT64: {
-               guint64 value = g_ascii_strtoll(static_cast<const gchar*>(key_value_pair[1]), NULL, 10);
-               g_object_set(G_OBJECT(element), key_value_pair[0], value, NULL);
-               break;
-       }
-       case G_TYPE_BOOLEAN: {
-               gboolean value = FALSE;
-               static const gchar* true_names[] = {
-                 "1", "yes", "on", "true", "TRUE", NULL
-               };
-
-               if (g_strv_contains (true_names, static_cast<const gchar*>(key_value_pair[1])))
-                 value = TRUE;
-
-               g_object_set(G_OBJECT(element), key_value_pair[0], value, NULL);
-               break;
-       }
-       case G_TYPE_FLOAT:
-       case G_TYPE_DOUBLE: {
-               gdouble value = g_ascii_strtod(static_cast<const gchar*>(key_value_pair[1]), NULL);
-               g_object_set(G_OBJECT(element), key_value_pair[0], value, NULL);
-               break;
-       }
-       default:
-               LOG_DEBUG("not supported type(0x%x) exactly, but try it with int64 type", (unsigned int)type); /* e.g.) custom enum type falls through here */
-               gint64 value = g_ascii_strtoll(static_cast<const gchar*>(key_value_pair[1]), NULL, 10);
-               g_object_set(G_OBJECT(element), key_value_pair[0], value, NULL);
-               break;
-       }
+       for (const auto& kv : key_value_pairs) {
+               LOGI("kv: [%s]", kv.c_str());
 
-       LOG_DEBUG("element[%s] property[%s] value[type:0x%x, %s]", GST_ELEMENT_NAME(element), key_value_pair[0], (unsigned int)type, key_value_pair[1]);
-}
+               GStrv key_value_pair = g_strsplit(kv.c_str(), "=", 2);
 
-void gst::_setElementProperties(GstElement* element, std::vector<std::string> key_value_pairs)
-{
-       RET_IF(!element, "element is NULL");
+               if (!key_value_pair) {
+                       LOG_ERROR("invalid string [%s] to split", kv.c_str());
+                       continue;
+               }
 
-       for (auto& kv : key_value_pairs) {
-               // FIXME: remove g_strsplit later
-               gchar** key_value_pair = g_strsplit(kv.c_str(), "=", 2);
+               if (g_strv_length(key_value_pair) != 2) {
+                       LOG_ERROR("splitted string doesn't contains key/value");
+                       g_strfreev(key_value_pair);
+                       continue;
+               }
 
-               if (!g_strcmp0(key_value_pair[0], "") ||
-                       !g_strcmp0(key_value_pair[1], "")) {
+               if (strlen(key_value_pair[0]) == 0 ||
+                       strlen(key_value_pair[1]) == 0) {
                        LOG_ERROR("invalid key_value_pair, key[%s], value[%s]",
                                        key_value_pair[0], key_value_pair[1]);
                        g_strfreev(key_value_pair);
                        continue;
                }
 
-               GParamSpec* param_spec = g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(element)), g_strstrip(key_value_pair[0]));;
-               if (param_spec)
-                       __parse_type_and_set_value(param_spec->value_type, element, key_value_pair);
-               else
-                       LOG_ERROR("element[%s] does not have this property[%s]", GST_ELEMENT_NAME(element), key_value_pair[0]);
+               gst_util_set_object_arg(reinterpret_cast<GObject*>(element), g_strstrip(key_value_pair[0]), key_value_pair[1]);
 
                g_strfreev(key_value_pair);
        }