playback: Check type when setting "connection-speed" on unknown elements
authorThibault Saunier <thibault.saunier@collabora.com>
Thu, 10 May 2012 17:15:26 +0000 (13:15 -0400)
committerThibault Saunier <thibault.saunier@collabora.com>
Thu, 10 May 2012 17:21:04 +0000 (13:21 -0400)
Clamp the values if needed

gst/playback/gstdecodebin2.c
gst/playback/gsturidecodebin.c

index 512a6cb..357a87a 100644 (file)
@@ -1974,13 +1974,43 @@ connect_pad (GstDecodeBin * dbin, GstElement * src, GstDecodePad * dpad,
 
     /* Set connection-speed property if needed */
     if (chain->demuxer == TRUE) {
-      if (g_object_class_find_property (G_OBJECT_GET_CLASS (element),
-              "connection-speed")) {
-        GST_DEBUG_OBJECT (dbin,
-            "setting connection-speed=%d to demuxer element",
-            dbin->connection_speed / 1000);
-        g_object_set (element, "connection-speed",
-            dbin->connection_speed / 1000, NULL);
+      GParamSpec *pspec;
+
+      if ((pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (element),
+                  "connection-speed"))) {
+        guint64 speed = dbin->connection_speed / 1000;
+        gboolean wrong_type = FALSE;
+
+        if (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_UINT) {
+          GParamSpecUInt *pspecuint = G_PARAM_SPEC_UINT (pspec);
+
+          speed = CLAMP (speed, pspecuint->minimum, pspecuint->maximum);
+        } else if (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_INT) {
+          GParamSpecInt *pspecint = G_PARAM_SPEC_INT (pspec);
+
+          speed = CLAMP (speed, pspecint->minimum, pspecint->maximum);
+        } else if (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_UINT64) {
+          GParamSpecUInt64 *pspecuint = G_PARAM_SPEC_UINT64 (pspec);
+
+          speed = CLAMP (speed, pspecuint->minimum, pspecuint->maximum);
+        } else if (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_INT64) {
+          GParamSpecInt64 *pspecint = G_PARAM_SPEC_INT (pspec);
+
+          speed = CLAMP (speed, pspecint->minimum, pspecint->maximum);
+        } else {
+          GST_WARNING_OBJECT (dbin,
+              "The connection speed property %i of type %s"
+              " is not usefull not setting it", speed,
+              g_type_name (G_PARAM_SPEC_TYPE (pspec)));
+          wrong_type = TRUE;
+        }
+
+        if (wrong_type == FALSE) {
+          GST_DEBUG_OBJECT (dbin, "setting connection-speed=%d to demuxer"
+              " element", speed);
+
+          g_object_set (element, "connection-speed", speed, NULL);
+        }
       }
     }
 
index a68e7c1..17f274a 100644 (file)
@@ -1246,17 +1246,37 @@ gen_source_element (GstURIDecodeBin * decoder)
 
   pspec = g_object_class_find_property (source_class, "connection-speed");
   if (pspec != NULL) {
-    if (G_PARAM_SPEC_VALUE_TYPE (pspec) == G_TYPE_UINT64 ||
-        G_PARAM_SPEC_VALUE_TYPE (pspec) == G_TYPE_INT64) {
-      GST_DEBUG_OBJECT (decoder,
-          "setting connection-speed=%" G_GUINT64_FORMAT " on source element %s",
-          decoder->connection_speed / 1000, G_OBJECT_TYPE_NAME (source));
+    guint64 speed = decoder->connection_speed / 1000;
+    gboolean wrong_type = FALSE;
+
+    if (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_UINT) {
+      GParamSpecUInt *pspecuint = G_PARAM_SPEC_UINT (pspec);
+
+      speed = CLAMP (speed, pspecuint->minimum, pspecuint->maximum);
+    } else if (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_INT) {
+      GParamSpecInt *pspecint = G_PARAM_SPEC_INT (pspec);
+
+      speed = CLAMP (speed, pspecint->minimum, pspecint->maximum);
+    } else if (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_UINT64) {
+      GParamSpecUInt64 *pspecuint = G_PARAM_SPEC_UINT64 (pspec);
+
+      speed = CLAMP (speed, pspecuint->minimum, pspecuint->maximum);
+    } else if (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_INT64) {
+      GParamSpecInt64 *pspecint = G_PARAM_SPEC_INT64 (pspec);
 
-      g_object_set (source, "connection-speed",
-          decoder->connection_speed / 1000, NULL);
+      speed = CLAMP (speed, pspecint->minimum, pspecint->maximum);
     } else {
-      g_warning ("connection-speed property of '%s' is not a 64-bit int type",
-          G_OBJECT_TYPE_NAME (source));
+      GST_WARNING_OBJECT (decoder, "The connection speed property %i of type %s"
+          " is not usefull not setting it", speed,
+          g_type_name (G_PARAM_SPEC_TYPE (pspec)));
+      wrong_type = TRUE;
+    }
+
+    if (wrong_type == FALSE) {
+      g_object_set (source, "connection-speed", speed, NULL);
+
+      GST_DEBUG_OBJECT (decoder,
+          "setting connection-speed=%d to source element", speed);
     }
   }