matroskademux: Use pbutils for H.264 profile/level extraction
authorArun Raghavan <arun.raghavan@collabora.co.uk>
Fri, 30 Apr 2010 15:30:31 +0000 (21:00 +0530)
committerTim-Philipp Müller <tim.muller@collabora.co.uk>
Fri, 1 Oct 2010 15:58:46 +0000 (16:58 +0100)
The functions used to extract this data have been moved to gstpbutils to
facilitate reuse.

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

gst/matroska/Makefile.am
gst/matroska/matroska-demux.c
gst/matroska/matroska.c

index 8612a2d..96777bd 100644 (file)
@@ -29,6 +29,7 @@ libgstmatroska_la_LIBADD = \
        -lgstriff-@GST_MAJORMINOR@ \
        -lgstaudio-@GST_MAJORMINOR@ \
        -lgsttag-@GST_MAJORMINOR@ \
+       -lgstpbutils-@GST_MAJORMINOR@ \
        $(GST_BASE_LIBS) \
        $(GST_LIBS) \
        $(ZLIB_LIBS) \
index 1ba5750..6d42056 100644 (file)
@@ -70,6 +70,8 @@
 #include <bzlib.h>
 #endif
 
+#include <gst/pbutils/pbutils.h>
+
 #include "lzo.h"
 
 #include "matroska-demux.h"
@@ -6259,94 +6261,6 @@ gst_matroska_demux_sink_activate_pull (GstPad * sinkpad, gboolean active)
   return TRUE;
 }
 
-/*
- * XXX: This code is duplicated in gst/qtdemux/qtdemux.c. Please replicate any
- * changes you make over there as well.
- */
-static gchar *
-avc_profile_idc_to_string (guint profile_idc, guint constraint_set_flags)
-{
-  const gchar *profile = NULL;
-  gint csf1, csf3;
-
-  csf1 = (constraint_set_flags & 0x40) >> 6;
-  csf3 = (constraint_set_flags & 0x10) >> 4;
-
-  switch (profile_idc) {
-    case 66:
-      if (csf1)
-        profile = "constrained-baseline";
-      else
-        profile = "baseline";
-      break;
-    case 77:
-      profile = "main";
-      break;
-    case 88:
-      profile = "extended";
-      break;
-    case 100:
-      profile = "high";
-      break;
-    case 110:
-      if (csf3)
-        profile = "high-10-intra";
-      else
-        profile = "high-10";
-      break;
-    case 122:
-      if (csf3)
-        profile = "high-4:2:2-intra";
-      else
-        profile = "high-4:2:2";
-      break;
-    case 244:
-      if (csf3)
-        profile = "high-4:4:4-intra";
-      else
-        profile = "high-4:4:4";
-      break;
-    case 44:
-      profile = "cavlc-4:4:4-intra";
-      break;
-    default:
-      return NULL;
-  }
-
-  return g_strdup (profile);
-}
-
-static gchar *
-avc_level_idc_to_string (guint level_idc, guint constraint_set_flags)
-{
-  gint csf3;
-
-  csf3 = (constraint_set_flags & 0x10) >> 4;
-
-  if (level_idc == 11 && csf3)
-    return g_strdup ("1b");
-  else if (level_idc % 10 == 0)
-    return g_strdup_printf ("%u", level_idc / 10);
-  else
-    return g_strdup_printf ("%u.%u", level_idc / 10, level_idc % 10);
-}
-
-static void
-avc_get_profile_and_level_string (const guint8 * avc_data, gint size,
-    gchar ** profile, gchar ** level)
-{
-  if (size >= 2)
-    /* First byte is the version, second is the profile indication,
-     * and third is the 5 contraint_set_flags and 3 reserved bits */
-    *profile = avc_profile_idc_to_string (GST_READ_UINT8 (avc_data + 1),
-        GST_READ_UINT8 (avc_data + 2));
-
-  if (size >= 4)
-    /* Fourth byte is the level indication */
-    *level = avc_level_idc_to_string (GST_READ_UINT8 (avc_data + 3),
-        GST_READ_UINT8 (avc_data + 2));
-}
-
 static GstCaps *
 gst_matroska_demux_video_caps (GstMatroskaTrackVideoContext *
     videocontext, const gchar * codec_id, guint8 * data, guint size,
@@ -6509,17 +6423,12 @@ gst_matroska_demux_video_caps (GstMatroskaTrackVideoContext *
     caps = gst_caps_new_simple ("video/x-h264", NULL);
     if (data) {
       GstBuffer *priv = gst_buffer_new_and_alloc (size);
-      gchar *profile = NULL, *level = NULL;
 
-      avc_get_profile_and_level_string (data, size, &profile, &level);
-      if (profile) {
-        gst_caps_set_simple (caps, "profile", G_TYPE_STRING, profile, NULL);
-        g_free (profile);
-      }
-      if (level) {
-        gst_caps_set_simple (caps, "level", G_TYPE_STRING, level, NULL);
-        g_free (level);
-      }
+      /* First byte is the version, second is the profile indication, and third
+       * is the 5 contraint_set_flags and 3 reserved bits. Fourth byte is the
+       * level indication. */
+      gst_codec_utils_h264_caps_set_level_and_profile (caps, data + 1,
+          size - 1);
 
       memcpy (GST_BUFFER_DATA (priv), data, size);
       gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, priv, NULL);
index 503e24d..fd6c873 100644 (file)
 #include "matroska-ids.h"
 #include "webm-mux.h"
 
+#include <gst/pbutils/pbutils.h>
+
 static gboolean
 plugin_init (GstPlugin * plugin)
 {
   gboolean ret;
 
+  gst_pb_utils_init ();
+
   gst_matroska_register_tags ();
 
   ret = gst_matroska_demux_plugin_init (plugin);