matroska: refactor code common to matroskademux and matroskaparse
authorDebarshi Ray <rishi@gnu.org>
Thu, 26 May 2011 18:05:52 +0000 (23:35 +0530)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Fri, 27 May 2011 07:10:17 +0000 (09:10 +0200)
Move the following functions to matroska-read-common.[ch] from
matroska-demux.c and matroska-parse.c:
    - gst_matroska_{demux,parse}_encoding_cmp
    - gst_matroska_{demux,parse}_read_track_encodings

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

gst/matroska/matroska-demux.c
gst/matroska/matroska-parse.c
gst/matroska/matroska-read-common.c
gst/matroska/matroska-read-common.h

index 3de7172..05cdf63 100644 (file)
@@ -474,18 +474,6 @@ gst_matroska_demux_get_length (GstMatroskaDemux * demux)
   return end;
 }
 
-static gint
-gst_matroska_demux_encoding_cmp (GstMatroskaTrackEncoding * a,
-    GstMatroskaTrackEncoding * b)
-{
-  if (b->order > a->order)
-    return 1;
-  else if (b->order < a->order)
-    return -1;
-  else
-    return 0;
-}
-
 static gboolean
 gst_matroska_decode_data (GArray * encodings, guint8 ** data_out,
     guint * size_out, GstMatroskaTrackEncodingScope scope, gboolean free)
@@ -582,51 +570,6 @@ gst_matroska_decode_buffer (GstMatroskaTrackContext * context, GstBuffer * buf)
   }
 }
 
-static GstFlowReturn
-gst_matroska_demux_read_track_encodings (GstMatroskaDemux * demux,
-    GstEbmlRead * ebml, GstMatroskaTrackContext * context)
-{
-  GstFlowReturn ret;
-  guint32 id;
-
-  DEBUG_ELEMENT_START (demux, ebml, "ContentEncodings");
-
-  if ((ret = gst_ebml_read_master (ebml, &id)) != GST_FLOW_OK) {
-    DEBUG_ELEMENT_STOP (demux, ebml, "ContentEncodings", ret);
-    return ret;
-  }
-
-  context->encodings =
-      g_array_sized_new (FALSE, FALSE, sizeof (GstMatroskaTrackEncoding), 1);
-
-  while (ret == GST_FLOW_OK && gst_ebml_read_has_remaining (ebml, 1, TRUE)) {
-    if ((ret = gst_ebml_peek_id (ebml, &id)) != GST_FLOW_OK)
-      break;
-
-    switch (id) {
-      case GST_MATROSKA_ID_CONTENTENCODING:
-        ret = gst_matroska_read_common_read_track_encoding (&demux->common,
-            ebml, context);
-        break;
-      default:
-        GST_WARNING_OBJECT (demux,
-            "Unknown ContentEncodings subelement 0x%x - ignoring", id);
-        ret = gst_ebml_read_skip (ebml);
-        break;
-    }
-  }
-
-  DEBUG_ELEMENT_STOP (demux, ebml, "ContentEncodings", ret);
-  if (ret != GST_FLOW_OK && ret != GST_FLOW_UNEXPECTED)
-    return ret;
-
-  /* Sort encodings according to their order */
-  g_array_sort (context->encodings,
-      (GCompareFunc) gst_matroska_demux_encoding_cmp);
-
-  return gst_matroska_decode_content_encodings (context->encodings);
-}
-
 static gboolean
 gst_matroska_demux_tracknumber_unique (GstMatroskaDemux * demux, guint64 num)
 {
@@ -1257,7 +1200,8 @@ gst_matroska_demux_add_stream (GstMatroskaDemux * demux, GstEbmlRead * ebml)
       }
 
       case GST_MATROSKA_ID_CONTENTENCODINGS:{
-        ret = gst_matroska_demux_read_track_encodings (demux, ebml, context);
+        ret = gst_matroska_read_common_read_track_encodings (&demux->common,
+            ebml, context);
         break;
       }
 
index 091992d..9b55550 100644 (file)
@@ -397,18 +397,6 @@ gst_matroska_parse_get_length (GstMatroskaParse * parse)
   return end;
 }
 
-static gint
-gst_matroska_parse_encoding_cmp (GstMatroskaTrackEncoding * a,
-    GstMatroskaTrackEncoding * b)
-{
-  if (b->order > a->order)
-    return 1;
-  else if (b->order < a->order)
-    return -1;
-  else
-    return 0;
-}
-
 static gboolean
 gst_matroska_decode_data (GArray * encodings, guint8 ** data_out,
     guint * size_out, GstMatroskaTrackEncodingScope scope, gboolean free)
@@ -471,51 +459,6 @@ gst_matroska_decode_data (GArray * encodings, guint8 ** data_out,
   return ret;
 }
 
-static GstFlowReturn
-gst_matroska_parse_read_track_encodings (GstMatroskaParse * parse,
-    GstEbmlRead * ebml, GstMatroskaTrackContext * context)
-{
-  GstFlowReturn ret;
-  guint32 id;
-
-  DEBUG_ELEMENT_START (parse, ebml, "ContentEncodings");
-
-  if ((ret = gst_ebml_read_master (ebml, &id)) != GST_FLOW_OK) {
-    DEBUG_ELEMENT_STOP (parse, ebml, "ContentEncodings", ret);
-    return ret;
-  }
-
-  context->encodings =
-      g_array_sized_new (FALSE, FALSE, sizeof (GstMatroskaTrackEncoding), 1);
-
-  while (ret == GST_FLOW_OK && gst_ebml_read_has_remaining (ebml, 1, TRUE)) {
-    if ((ret = gst_ebml_peek_id (ebml, &id)) != GST_FLOW_OK)
-      break;
-
-    switch (id) {
-      case GST_MATROSKA_ID_CONTENTENCODING:
-        ret = gst_matroska_read_common_read_track_encoding (&parse->common,
-            ebml, context);
-        break;
-      default:
-        GST_WARNING_OBJECT (parse,
-            "Unknown ContentEncodings subelement 0x%x - ignoring", id);
-        ret = gst_ebml_read_skip (ebml);
-        break;
-    }
-  }
-
-  DEBUG_ELEMENT_STOP (parse, ebml, "ContentEncodings", ret);
-  if (ret != GST_FLOW_OK && ret != GST_FLOW_UNEXPECTED)
-    return ret;
-
-  /* Sort encodings according to their order */
-  g_array_sort (context->encodings,
-      (GCompareFunc) gst_matroska_parse_encoding_cmp);
-
-  return gst_matroska_decode_content_encodings (context->encodings);
-}
-
 static gboolean
 gst_matroska_parse_tracknumber_unique (GstMatroskaParse * parse, guint64 num)
 {
@@ -1139,7 +1082,8 @@ gst_matroska_parse_add_stream (GstMatroskaParse * parse, GstEbmlRead * ebml)
       }
 
       case GST_MATROSKA_ID_CONTENTENCODINGS:{
-        ret = gst_matroska_parse_read_track_encodings (parse, ebml, context);
+        ret = gst_matroska_read_common_read_track_encodings (&parse->common,
+            ebml, context);
         break;
       }
 
index 28df40b..178aa36 100644 (file)
@@ -280,6 +280,18 @@ gst_matroska_index_compare (GstMatroskaIndex * i1, GstMatroskaIndex * i2)
     return 0;
 }
 
+static gint
+gst_matroska_read_common_encoding_cmp (GstMatroskaTrackEncoding * a,
+    GstMatroskaTrackEncoding * b)
+{
+  if (b->order > a->order)
+    return 1;
+  else if (b->order < a->order)
+    return -1;
+  else
+    return 0;
+}
+
 static gboolean
 gst_matroska_read_common_encoding_order_unique (GArray * encodings, guint64
     order)
@@ -744,7 +756,7 @@ gst_matroska_read_common_peek_id_length_push (GstMatroskaReadCommon * common,
       el, common->offset);
 }
 
-GstFlowReturn
+static GstFlowReturn
 gst_matroska_read_common_read_track_encoding (GstMatroskaReadCommon * common,
     GstEbmlRead * ebml, GstMatroskaTrackContext * context)
 {
@@ -906,3 +918,48 @@ gst_matroska_read_common_read_track_encoding (GstMatroskaReadCommon * common,
 
   return ret;
 }
+
+GstFlowReturn
+gst_matroska_read_common_read_track_encodings (GstMatroskaReadCommon * common,
+    GstEbmlRead * ebml, GstMatroskaTrackContext * context)
+{
+  GstFlowReturn ret;
+  guint32 id;
+
+  DEBUG_ELEMENT_START (common, ebml, "ContentEncodings");
+
+  if ((ret = gst_ebml_read_master (ebml, &id)) != GST_FLOW_OK) {
+    DEBUG_ELEMENT_STOP (common, ebml, "ContentEncodings", ret);
+    return ret;
+  }
+
+  context->encodings =
+      g_array_sized_new (FALSE, FALSE, sizeof (GstMatroskaTrackEncoding), 1);
+
+  while (ret == GST_FLOW_OK && gst_ebml_read_has_remaining (ebml, 1, TRUE)) {
+    if ((ret = gst_ebml_peek_id (ebml, &id)) != GST_FLOW_OK)
+      break;
+
+    switch (id) {
+      case GST_MATROSKA_ID_CONTENTENCODING:
+        ret = gst_matroska_read_common_read_track_encoding (common, ebml,
+            context);
+        break;
+      default:
+        GST_WARNING_OBJECT (common,
+            "Unknown ContentEncodings subelement 0x%x - ignoring", id);
+        ret = gst_ebml_read_skip (ebml);
+        break;
+    }
+  }
+
+  DEBUG_ELEMENT_STOP (common, ebml, "ContentEncodings", ret);
+  if (ret != GST_FLOW_OK && ret != GST_FLOW_UNEXPECTED)
+    return ret;
+
+  /* Sort encodings according to their order */
+  g_array_sort (context->encodings,
+      (GCompareFunc) gst_matroska_read_common_encoding_cmp);
+
+  return gst_matroska_decode_content_encodings (context->encodings);
+}
index daa3793..cf5416f 100644 (file)
@@ -92,7 +92,7 @@ GstFlowReturn gst_matroska_read_common_peek_id_length_push (GstMatroskaReadCommo
     _needed);
 gint gst_matroska_read_common_stream_from_num (GstMatroskaReadCommon * common,
     guint track_num);
-GstFlowReturn gst_matroska_read_common_read_track_encoding (
+GstFlowReturn gst_matroska_read_common_read_track_encodings (
     GstMatroskaReadCommon * common, GstEbmlRead * ebml,
     GstMatroskaTrackContext * context);