validate: Add a way to pass a MediaDescriptor around monitors
authorThibault Saunier <thibault.saunier@collabora.com>
Mon, 15 Sep 2014 15:22:52 +0000 (17:22 +0200)
committerMathieu Duponchelle <mathieu.duponchelle@opencreed.com>
Tue, 21 Oct 2014 18:14:05 +0000 (20:14 +0200)
And add an option in gst-validate so that the user can define what
media descriptor file to use.

https://bugzilla.gnome.org/show_bug.cgi?id=736138

validate/gst/validate/gst-validate-bin-monitor.c
validate/gst/validate/gst-validate-element-monitor.c
validate/gst/validate/gst-validate-monitor.c
validate/gst/validate/gst-validate-monitor.h
validate/tools/gst-validate.c

index 34bbc64..e508aa7 100644 (file)
@@ -65,6 +65,22 @@ _validate_bin_element_added (GstBin * bin, GstElement * pad,
     GstValidateBinMonitor * monitor);
 
 static void
+gst_validate_bin_set_media_descriptor (GstValidateMonitor * monitor,
+    GstMediaDescriptor * media_descriptor)
+{
+  GList *tmp;
+
+  GST_VALIDATE_MONITOR_LOCK (monitor);
+  for (tmp = GST_VALIDATE_BIN_MONITOR_CAST (monitor)->element_monitors; tmp;
+      tmp = tmp->next)
+    gst_validate_monitor_set_media_descriptor (tmp->data, media_descriptor);
+  GST_VALIDATE_MONITOR_UNLOCK (monitor);
+
+  GST_VALIDATE_MONITOR_CLASS (parent_class)->set_media_descriptor (monitor,
+      media_descriptor);
+}
+
+static void
 gst_validate_bin_monitor_set_property (GObject * object, guint prop_id,
     const GValue * value, GParamSpec * pspec)
 {
@@ -143,6 +159,8 @@ gst_validate_bin_monitor_class_init (GstValidateBinMonitorClass * klass)
           FALSE, G_PARAM_READABLE));
 
   validatemonitor_class->setup = gst_validate_bin_monitor_setup;
+  validatemonitor_class->set_media_descriptor =
+      gst_validate_bin_set_media_descriptor;
 }
 
 static void
index 34caedd..9d3c282 100644 (file)
@@ -55,6 +55,49 @@ _validate_element_pad_added (GstElement * element, GstPad * pad,
     GstValidateElementMonitor * monitor);
 
 static void
+gst_validate_element_set_media_descriptor (GstValidateMonitor * monitor,
+    GstMediaDescriptor * media_descriptor)
+{
+  gboolean done;
+  GstPad *pad;
+  GstValidateMonitor *pmonitor;
+  GstIterator *iterator;
+
+  iterator =
+      gst_element_iterate_pads (GST_ELEMENT (GST_VALIDATE_MONITOR_GET_OBJECT
+          (monitor)));
+  done = FALSE;
+  while (!done) {
+    GValue value = { 0, };
+
+    switch (gst_iterator_next (iterator, &value)) {
+      case GST_ITERATOR_OK:
+
+        pad = g_value_get_object (&value);
+
+        pmonitor = g_object_get_data ((GObject *) pad, "validate-monitor");
+        if (pmonitor)
+          gst_validate_monitor_set_media_descriptor (pmonitor,
+              media_descriptor);
+        g_value_reset (&value);
+        break;
+      case GST_ITERATOR_RESYNC:
+        /* TODO how to handle this? */
+        gst_iterator_resync (iterator);
+        break;
+      case GST_ITERATOR_ERROR:
+        done = TRUE;
+        break;
+      case GST_ITERATOR_DONE:
+        done = TRUE;
+        break;
+    }
+  }
+  gst_iterator_free (iterator);
+}
+
+
+static void
 gst_validate_element_monitor_dispose (GObject * object)
 {
   GstValidateElementMonitor *monitor =
@@ -83,6 +126,8 @@ gst_validate_element_monitor_class_init (GstValidateElementMonitorClass * klass)
 
   monitor_klass->setup = gst_validate_element_monitor_do_setup;
   monitor_klass->get_element = gst_validate_element_monitor_get_element;
+  monitor_klass->set_media_descriptor =
+      gst_validate_element_set_media_descriptor;
 }
 
 static void
index 984bb80..2be465d 100644 (file)
@@ -99,6 +99,9 @@ gst_validate_monitor_dispose (GObject * object)
     g_object_weak_unref (G_OBJECT (monitor->target),
         (GWeakNotify) _target_freed_cb, monitor);
 
+  if (monitor->media_descriptor)
+    gst_object_unref (monitor->media_descriptor);
+
   G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
@@ -151,6 +154,13 @@ gst_validate_monitor_constructor (GType type, guint n_construct_params,
       (type,
           n_construct_params,
           construct_params));
+
+  if (monitor->parent) {
+    gst_validate_monitor_set_media_descriptor (monitor,
+        monitor->parent->media_descriptor);
+  }
+
+
   gst_validate_monitor_setup (monitor);
   return (GObject *) monitor;
 }
@@ -360,3 +370,22 @@ gst_validate_monitor_get_property (GObject * object, guint prop_id,
       break;
   }
 }
+
+void
+gst_validate_monitor_set_media_descriptor (GstValidateMonitor * monitor,
+    GstMediaDescriptor * media_descriptor)
+{
+  GstValidateMonitorClass *klass = GST_VALIDATE_MONITOR_GET_CLASS (monitor);
+
+  GST_DEBUG_OBJECT (monitor->target, "Set media desc: %" GST_PTR_FORMAT,
+      media_descriptor);
+  if (monitor->media_descriptor)
+    gst_object_unref (monitor->media_descriptor);
+
+  if (media_descriptor)
+    gst_object_ref (media_descriptor);
+
+  monitor->media_descriptor = media_descriptor;
+  if (klass->set_media_descriptor)
+    klass->set_media_descriptor (monitor, media_descriptor);
+}
index eb0e67f..fd46d8d 100644 (file)
@@ -32,6 +32,7 @@ typedef struct _GstValidateMonitorClass GstValidateMonitorClass;
 #include <gst/validate/gst-validate-reporter.h>
 #include <gst/validate/gst-validate-runner.h>
 #include <gst/validate/gst-validate-override.h>
+#include <gst/validate/media-descriptor-parser.h>
 
 G_BEGIN_DECLS
 
@@ -90,6 +91,7 @@ struct _GstValidateMonitor {
 
   GMutex        overrides_mutex;
   GQueue        overrides;
+  GstMediaDescriptor *media_descriptor;
 
   GstValidateReportingLevel level;
 
@@ -108,6 +110,8 @@ struct _GstValidateMonitorClass {
 
   gboolean (* setup) (GstValidateMonitor * monitor);
   GstElement *(* get_element) (GstValidateMonitor * monitor);
+  void (*set_media_descriptor) (GstValidateMonitor * monitor,
+          GstMediaDescriptor * media_descriptor);
 };
 
 /* normal GObject stuff */
@@ -118,7 +122,8 @@ void            gst_validate_monitor_attach_override  (GstValidateMonitor * moni
 
 GstElement *    gst_validate_monitor_get_element (GstValidateMonitor * monitor);
 const gchar *   gst_validate_monitor_get_element_name (GstValidateMonitor * monitor);
-
+void gst_validate_monitor_set_media_descriptor (GstValidateMonitor * monitor,
+                                                GstMediaDescriptor *media_descriptor);
 G_END_DECLS
 
 #endif /* __GST_VALIDATE_MONITOR_H__ */
index 1a9782a..7bad0be 100644 (file)
@@ -33,6 +33,7 @@
 #include <gst/validate/validate.h>
 #include <gst/validate/gst-validate-scenario.h>
 #include <gst/validate/gst-validate-utils.h>
+#include <gst/validate/media-descriptor-parser.h>
 
 #ifdef G_OS_UNIX
 #include <glib-unix.h>
@@ -365,7 +366,7 @@ int
 main (int argc, gchar ** argv)
 {
   GError *err = NULL;
-  const gchar *scenario = NULL, *configs = NULL;
+  const gchar *scenario = NULL, *configs = NULL, *media_info = NULL;
   gboolean list_scenarios = FALSE, monitor_handles_state,
       inspect_action_type = FALSE;
   GstStateChangeReturn sret;
@@ -393,10 +394,14 @@ main (int argc, gchar ** argv)
           " if no parameter passed, it will list all avalaible action types"
           " otherwize will print the full description of the wanted types",
         NULL},
+    {"set-media-info", '\0', 0, G_OPTION_ARG_STRING, &media_info,
+          "Set a media_info XML file descriptor to share information about the"
+          " media file that will be reproduced.",
+        NULL},
     {"set-configs", '\0', 0, G_OPTION_ARG_STRING, &configs,
           "Let you set a config scenario, the scenario needs to be set as 'config"
           "' you can specify a list of scenario separated by ':'"
-          " it will override the GST_VALIDATE_SCENARIO environment variable,",
+          " it will override the GST_VALIDATE_SCENARIO environment variable.",
         NULL},
     {NULL}
   };
@@ -505,6 +510,23 @@ main (int argc, gchar ** argv)
       runner, NULL);
   gst_validate_reporter_set_handle_g_logs (GST_VALIDATE_REPORTER (monitor));
 
+  if (media_info) {
+    GError *err = NULL;
+    GstMediaDescriptorParser *parser = gst_media_descriptor_parser_new (runner,
+        media_info, &err);
+
+    if (parser == NULL) {
+      GST_ERROR ("Could not use %s as a media-info file (error: %s)",
+          media_info, err ? err->message : "Unknown error");
+
+      exit (1);
+    }
+
+    gst_validate_monitor_set_media_descriptor (monitor,
+        GST_MEDIA_DESCRIPTOR (parser));
+    gst_object_unref (parser);
+  }
+
   mainloop = g_main_loop_new (NULL, FALSE);
   bus = gst_element_get_bus (pipeline);
   gst_bus_add_signal_watch (bus);