tools: catch and print missing-plugin messages in gst-launch
authorTim-Philipp Müller <tim.muller@collabora.co.uk>
Fri, 27 May 2011 14:14:32 +0000 (15:14 +0100)
committerTim-Philipp Müller <tim.muller@collabora.co.uk>
Fri, 27 May 2011 14:17:32 +0000 (15:17 +0100)
So that users get some feedback if they're using a pipeline
like  src ! decodebin2 ! sink  and are missing an element.

tools/gst-launch.c

index 2b0d862..ea99b8f 100644 (file)
@@ -403,6 +403,24 @@ print_index_stats (GPtrArray * index_stats)
   }
 }
 
+/* Kids, use the functions from libgstpbutils in gst-plugins-base in your
+ * own code (we can't do that here because it would introduce a circular
+ * dependency) */
+static gboolean
+gst_is_missing_plugin_message (GstMessage * msg)
+{
+  if (GST_MESSAGE_TYPE (msg) != GST_MESSAGE_ELEMENT || msg->structure == NULL)
+    return FALSE;
+
+  return gst_structure_has_name (msg->structure, "missing-plugin");
+}
+
+static const gchar *
+gst_missing_plugin_message_get_description (GstMessage * msg)
+{
+  return gst_structure_get_string (msg->structure, "name");
+}
+
 static void
 print_error_message (GstMessage * msg)
 {
@@ -821,6 +839,16 @@ event_loop (GstElement * pipeline, gboolean blocking, GstState target_state)
           res = ELR_INTERRUPT;
           goto exit;
         }
+        break;
+      }
+      case GST_MESSAGE_ELEMENT:{
+        if (gst_is_missing_plugin_message (message)) {
+          const gchar *desc;
+
+          desc = gst_missing_plugin_message_get_description (message);
+          PRINT (_("Missing element: %s\n"), desc ? desc : "(no description)");
+        }
+        break;
       }
       default:
         /* just be quiet by default */