encoding-profile: add a function to create a profile from a discoverer info
authorVincent Penquerc'h <vincent.penquerch@collabora.co.uk>
Fri, 18 Feb 2011 11:48:37 +0000 (11:48 +0000)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Mon, 3 Oct 2011 09:51:23 +0000 (11:51 +0200)
Only A/V streams are added at the moment, there does not seem to be
a similar way to add other streams (eg, subtitles).

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

docs/libs/gst-plugins-base-libs-sections.txt
gst-libs/gst/pbutils/encoding-profile.c
gst-libs/gst/pbutils/encoding-profile.h
win32/common/libgstpbutils.def

index 4e998e4..fe52a0c 100644 (file)
@@ -2114,6 +2114,7 @@ GstEncodingProfile
 gst_encoding_profile_unref
 gst_encoding_profile_ref
 gst_encoding_profile_find
+gst_encoding_profile_from_discoverer
 gst_encoding_profile_get_name
 gst_encoding_profile_get_description
 gst_encoding_profile_get_format
index eaa7507..65af1b1 100644 (file)
@@ -964,3 +964,73 @@ gst_encoding_profile_deserialize_valfunc (GValue * value, const gchar * s)
 
   return FALSE;
 }
+
+/**
+ * gst_encoding_profile_from_discoverer:
+ * @info: (transfer none): The #GstDiscovererInfo to read from
+ *
+ * Creates a #GstEncodingProfile matching the formats from the given
+ * #GstEncodingProfile. Streams other than audio or video (eg,
+ * subtitles), are currently ignored.
+ *
+ * Returns: (transfer full): The new #GstEncodingProfile or %NULL.
+ *
+ * Since: 0.10.36
+ */
+GstEncodingProfile *
+gst_encoding_profile_from_discoverer (GstDiscovererInfo * info)
+{
+  GstEncodingContainerProfile *profile;
+  GstDiscovererStreamInfo *sinfo;
+  GList *streams, *stream;
+  GstCaps *caps = NULL;
+
+  if (!info || gst_discoverer_info_get_result (info) != GST_DISCOVERER_OK)
+    return NULL;
+
+  sinfo = gst_discoverer_info_get_stream_info (info);
+  if (!sinfo)
+    return NULL;
+
+  caps = gst_discoverer_stream_info_get_caps (sinfo);
+  GST_LOG ("Container: %" GST_PTR_FORMAT "\n", caps);
+  profile =
+      gst_encoding_container_profile_new ("auto-generated",
+      "Automatically generated from GstDiscovererInfo", caps, NULL);
+  gst_caps_unref (caps);
+  if (!profile) {
+    GST_ERROR ("Failed to create container profile from caps %" GST_PTR_FORMAT,
+        caps);
+    return NULL;
+  }
+
+  streams =
+      gst_discoverer_container_info_get_streams (GST_DISCOVERER_CONTAINER_INFO
+      (sinfo));
+  for (stream = streams; stream; stream = stream->next) {
+    GstEncodingProfile *sprofile = NULL;
+    sinfo = (GstDiscovererStreamInfo *) stream->data;
+    caps = gst_discoverer_stream_info_get_caps (sinfo);
+    GST_LOG ("Stream: %" GST_PTR_FORMAT "\n", caps);
+    if (GST_IS_DISCOVERER_AUDIO_INFO (sinfo)) {
+      sprofile =
+          (GstEncodingProfile *) gst_encoding_audio_profile_new (caps, NULL,
+          NULL, 0);
+    } else if (GST_IS_DISCOVERER_VIDEO_INFO (sinfo)) {
+      sprofile =
+          (GstEncodingProfile *) gst_encoding_video_profile_new (caps, NULL,
+          NULL, 0);
+    } else {
+      /* subtitles or other ? ignore for now */
+    }
+    if (sprofile)
+      gst_encoding_container_profile_add_profile (profile, sprofile);
+    else
+      GST_ERROR ("Failed to create stream profile from caps %" GST_PTR_FORMAT,
+          caps);
+    gst_caps_unref (caps);
+  }
+  gst_discoverer_stream_info_list_free (streams);
+
+  return (GstEncodingProfile *) profile;
+}
index 86becca..826db52 100644 (file)
@@ -26,6 +26,7 @@
 G_BEGIN_DECLS
 
 #include <gst/pbutils/pbutils-enumtypes.h>
+#include <gst/pbutils/gstdiscoverer.h>
 
 /**
  * GstEncodingProfile:
@@ -182,6 +183,9 @@ void     gst_encoding_video_profile_set_pass              (GstEncodingVideoProfi
                                                           guint pass);
 void     gst_encoding_video_profile_set_variableframerate (GstEncodingVideoProfile *prof,
                                                           gboolean variableframerate);
+
+GstEncodingProfile * gst_encoding_profile_from_discoverer (GstDiscovererInfo *info);
+
 G_END_DECLS
 
 #endif /* __GST_PROFILE_H__ */
index 3fa74d4..0e2fcf9 100644 (file)
@@ -73,6 +73,7 @@ EXPORTS
        gst_encoding_list_all_targets
        gst_encoding_list_available_categories
        gst_encoding_profile_find
+       gst_encoding_profile_from_discoverer
        gst_encoding_profile_get_description
        gst_encoding_profile_get_format
        gst_encoding_profile_get_input_caps