Bug 874305 - Support older versions of gstreamer r=alessandro.d
authorEdwin Flores <eflores@mozilla.com>
Tue, 11 Jun 2013 14:13:09 +1200
changeset 146097 de789c0f4b9aedc478d94a430e9cfc01977a835c
parent 146096 63e57ae2f15c950662dd7f84284ce29e1983c6e2
child 146098 1b59b25f6464218410d3c133f93a771892794fb4
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersalessandro
bugs874305
milestone24.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 874305 - Support older versions of gstreamer r=alessandro.d
content/media/gstreamer/GStreamerFormatHelper.cpp
content/media/gstreamer/GStreamerFunctionList.h
--- a/content/media/gstreamer/GStreamerFormatHelper.cpp
+++ b/content/media/gstreamer/GStreamerFormatHelper.cpp
@@ -158,34 +158,83 @@ GstCaps* GStreamerFormatHelper::ConvertF
     GstCaps* tmp = gst_caps_from_string(capsString);
     /* appends and frees tmp */
     gst_caps_append(caps, tmp);
   }
 
   return caps;
 }
 
+static gboolean FactoryFilter(GstPluginFeature *aFeature, gpointer)
+{
+  if (!GST_IS_ELEMENT_FACTORY(aFeature)) {
+    return FALSE;
+  }
+
+  // TODO _get_klass doesn't exist in 1.0
+  const gchar *className =
+    gst_element_factory_get_klass(GST_ELEMENT_FACTORY_CAST(aFeature));
+
+  if (!strstr(className, "Decoder") && !strstr(className, "Demux")) {
+    return FALSE;
+  }
+
+  return gst_plugin_feature_get_rank(aFeature) >= GST_RANK_MARGINAL;
+}
+
+/**
+ * Returns true if any |aFactory| caps intersect with |aCaps|
+ */
+static bool SupportsCaps(GstElementFactory *aFactory, GstCaps *aCaps)
+{
+  for (const GList *iter = gst_element_factory_get_static_pad_templates(aFactory); iter; iter = iter->next) {
+    GstStaticPadTemplate *templ = static_cast<GstStaticPadTemplate *>(iter->data);
+
+    if (templ->direction == GST_PAD_SRC) {
+      continue;
+    }
+
+    GstCaps *caps = gst_static_caps_get(&templ->static_caps);
+    if (!caps) {
+      continue;
+    }
+
+    if (gst_caps_can_intersect(gst_static_caps_get(&templ->static_caps), aCaps)) {
+      return true;
+    }
+  }
+
+  return false;
+}
+
 bool GStreamerFormatHelper::HaveElementsToProcessCaps(GstCaps* aCaps) {
   NS_ASSERTION(sLoadOK, "GStreamer library not linked");
 
   GList* factories = GetFactories();
 
-  GList* list;
   /* here aCaps contains [containerCaps, [codecCaps1, [codecCaps2, ...]]] so process
    * caps structures individually as we want one element for _each_
    * structure */
   for (unsigned int i = 0; i < gst_caps_get_size(aCaps); i++) {
     GstStructure* s = gst_caps_get_structure(aCaps, i);
     GstCaps* caps = gst_caps_new_full(gst_structure_copy(s), nullptr);
-    list = gst_element_factory_list_filter (factories, caps, GST_PAD_SINK, FALSE);
-    gst_caps_unref(caps);
-    if (!list) {
+
+    bool found = false;
+    for (GList *elem = factories; elem; elem = elem->next) {
+      if (SupportsCaps(GST_ELEMENT_FACTORY_CAST(elem->data), caps)) {
+        found = true;
+        break;
+      }
+    }
+
+    if (!found) {
       return false;
     }
-    g_list_free(list);
+
+    gst_caps_unref(caps);
   }
 
   return true;
 }
 
 bool GStreamerFormatHelper::CanHandleContainerCaps(GstCaps* aCaps)
 {
   NS_ASSERTION(sLoadOK, "GStreamer library not linked");
@@ -201,18 +250,18 @@ bool GStreamerFormatHelper::CanHandleCod
 }
 
 GList* GStreamerFormatHelper::GetFactories() {
   NS_ASSERTION(sLoadOK, "GStreamer library not linked");
 
   uint32_t cookie = gst_default_registry_get_feature_list_cookie ();
   if (cookie != mCookie) {
     g_list_free(mFactories);
-    mFactories = gst_element_factory_list_get_elements
-        (GST_ELEMENT_FACTORY_TYPE_DEMUXER | GST_ELEMENT_FACTORY_TYPE_DECODER,
-         GST_RANK_MARGINAL);
+    mFactories =
+      gst_default_registry_feature_filter((GstPluginFeatureFilter)FactoryFilter,
+                                          false, nullptr);
     mCookie = cookie;
   }
 
   return mFactories;
 }
 
 } // namespace mozilla
--- a/content/media/gstreamer/GStreamerFunctionList.h
+++ b/content/media/gstreamer/GStreamerFunctionList.h
@@ -17,35 +17,33 @@ GST_FUNC(LIBGSTAPP, gst_app_src_get_type
 GST_FUNC(LIBGSTAPP, gst_app_src_push_buffer)
 GST_FUNC(LIBGSTAPP, gst_app_src_set_callbacks)
 GST_FUNC(LIBGSTAPP, gst_app_src_set_size)
 GST_FUNC(LIBGSTAPP, gst_app_src_set_stream_type)
 GST_FUNC(LIBGSTREAMER, gst_bin_get_by_name)
 GST_FUNC(LIBGSTREAMER, gst_bin_get_type)
 GST_FUNC(LIBGSTREAMER, gst_bin_iterate_recurse)
 GST_FUNC(LIBGSTREAMER, gst_buffer_copy_metadata)
-GST_FUNC(LIBGSTREAMER, gst_buffer_get_qdata)
 GST_FUNC(LIBGSTREAMER, gst_buffer_get_type)
 GST_FUNC(LIBGSTREAMER, gst_buffer_new)
 GST_FUNC(LIBGSTREAMER, gst_buffer_new_and_alloc)
-GST_FUNC(LIBGSTREAMER, gst_buffer_set_qdata)
 GST_FUNC(LIBGSTREAMER, gst_bus_timed_pop_filtered)
 GST_FUNC(LIBGSTREAMER, gst_caps_append)
 GST_FUNC(LIBGSTREAMER, gst_caps_can_intersect)
 GST_FUNC(LIBGSTREAMER, gst_caps_from_string)
 GST_FUNC(LIBGSTREAMER, gst_caps_get_size)
 GST_FUNC(LIBGSTREAMER, gst_caps_get_structure)
 GST_FUNC(LIBGSTREAMER, gst_caps_new_any)
 GST_FUNC(LIBGSTREAMER, gst_caps_new_empty)
 GST_FUNC(LIBGSTREAMER, gst_caps_new_full)
 GST_FUNC(LIBGSTREAMER, gst_caps_new_simple)
 GST_FUNC(LIBGSTREAMER, gst_caps_unref)
 GST_FUNC(LIBGSTREAMER, gst_element_factory_get_klass)
-GST_FUNC(LIBGSTREAMER, gst_element_factory_list_filter)
-GST_FUNC(LIBGSTREAMER, gst_element_factory_list_get_elements)
+GST_FUNC(LIBGSTREAMER, gst_element_factory_get_static_pad_templates)
+GST_FUNC(LIBGSTREAMER, gst_element_factory_get_type)
 GST_FUNC(LIBGSTREAMER, gst_element_factory_make)
 GST_FUNC(LIBGSTREAMER, gst_element_get_factory)
 GST_FUNC(LIBGSTREAMER, gst_element_get_pad)
 GST_FUNC(LIBGSTREAMER, gst_element_get_type)
 GST_FUNC(LIBGSTREAMER, gst_element_query_convert)
 GST_FUNC(LIBGSTREAMER, gst_element_query_duration)
 GST_FUNC(LIBGSTREAMER, gst_element_seek_simple)
 GST_FUNC(LIBGSTREAMER, gst_element_set_state)
@@ -65,27 +63,29 @@ GST_FUNC(LIBGSTREAMER, gst_pad_add_event
 GST_FUNC(LIBGSTREAMER, gst_pad_alloc_buffer)
 GST_FUNC(LIBGSTREAMER, gst_pad_get_element_private)
 GST_FUNC(LIBGSTREAMER, gst_pad_get_negotiated_caps)
 GST_FUNC(LIBGSTREAMER, gst_pad_set_bufferalloc_function)
 GST_FUNC(LIBGSTREAMER, gst_pad_set_element_private)
 GST_FUNC(LIBGSTREAMER, gst_parse_bin_from_description)
 GST_FUNC(LIBGSTREAMER, gst_pipeline_get_bus)
 GST_FUNC(LIBGSTREAMER, gst_pipeline_get_type)
+GST_FUNC(LIBGSTREAMER, gst_plugin_feature_get_rank)
+GST_FUNC(LIBGSTREAMER, gst_registry_feature_filter)
 GST_FUNC(LIBGSTREAMER, gst_registry_get_default)
 GST_FUNC(LIBGSTREAMER, gst_registry_get_feature_list_cookie)
 GST_FUNC(LIBGSTREAMER, gst_segment_init)
 GST_FUNC(LIBGSTREAMER, gst_segment_set_newsegment)
 GST_FUNC(LIBGSTREAMER, gst_segment_to_stream_time)
+GST_FUNC(LIBGSTREAMER, gst_static_caps_get)
 GST_FUNC(LIBGSTREAMER, gst_structure_copy)
 GST_FUNC(LIBGSTREAMER, gst_structure_get_fraction)
 GST_FUNC(LIBGSTREAMER, gst_structure_get_int)
 GST_FUNC(LIBGSTREAMER, gst_structure_get_value)
 GST_FUNC(LIBGSTREAMER, gst_structure_new)
-GST_FUNC(LIBGSTREAMER, gst_structure_take_value)
 GST_FUNC(LIBGSTREAMER, gst_util_uint64_scale)
 GST_FUNC(LIBGSTVIDEO, gst_video_format_get_component_height)
 GST_FUNC(LIBGSTVIDEO, gst_video_format_get_component_offset)
 GST_FUNC(LIBGSTVIDEO, gst_video_format_get_component_width)
 GST_FUNC(LIBGSTVIDEO, gst_video_format_get_row_stride)
 GST_FUNC(LIBGSTVIDEO, gst_video_format_parse_caps)
 
 /*