From: Debarshi Ray Date: Fri, 27 May 2011 14:58:19 +0000 (+0530) Subject: matroska: refactor code common to matroskademux and matroskaparse X-Git-Tag: 1.19.3~509^2~7136^2~512 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0aa35a6bcc3705d2168fa0bad450c5ef11608e97;p=platform%2Fupstream%2Fgstreamer.git matroska: refactor code common to matroskademux and matroskaparse Move the following function to matroska-read-common.[ch] from matroska-demux.c and matroska-parse.c: - gst_matroska_{demux,parse}_decode_data https://bugzilla.gnome.org/show_bug.cgi?id=650877 --- diff --git a/gst/matroska/matroska-demux.c b/gst/matroska/matroska-demux.c index 6386cc5..97ae2bb 100644 --- a/gst/matroska/matroska-demux.c +++ b/gst/matroska/matroska-demux.c @@ -461,68 +461,6 @@ gst_matroska_demux_reset (GstElement * element) } } -static gboolean -gst_matroska_decode_data (GArray * encodings, guint8 ** data_out, - guint * size_out, GstMatroskaTrackEncodingScope scope, gboolean free) -{ - guint8 *data; - guint size; - gboolean ret = TRUE; - gint i; - - g_return_val_if_fail (encodings != NULL, FALSE); - g_return_val_if_fail (data_out != NULL && *data_out != NULL, FALSE); - g_return_val_if_fail (size_out != NULL, FALSE); - - data = *data_out; - size = *size_out; - - for (i = 0; i < encodings->len; i++) { - GstMatroskaTrackEncoding *enc = - &g_array_index (encodings, GstMatroskaTrackEncoding, i); - guint8 *new_data = NULL; - guint new_size = 0; - - if ((enc->scope & scope) == 0) - continue; - - /* Encryption not supported yet */ - if (enc->type != 0) { - ret = FALSE; - break; - } - - new_data = data; - new_size = size; - - ret = - gst_matroska_decompress_data (enc, &new_data, &new_size, - enc->comp_algo); - - if (!ret) - break; - - if ((data == *data_out && free) || (data != *data_out)) - g_free (data); - - data = new_data; - size = new_size; - } - - if (!ret) { - if ((data == *data_out && free) || (data != *data_out)) - g_free (data); - - *data_out = NULL; - *size_out = 0; - } else { - *data_out = data; - *size_out = size; - } - - return ret; -} - static GstBuffer * gst_matroska_decode_buffer (GstMatroskaTrackContext * context, GstBuffer * buf) { diff --git a/gst/matroska/matroska-parse.c b/gst/matroska/matroska-parse.c index f89e97c..96ded4d 100644 --- a/gst/matroska/matroska-parse.c +++ b/gst/matroska/matroska-parse.c @@ -385,68 +385,6 @@ gst_matroska_parse_reset (GstElement * element) } static gboolean -gst_matroska_decode_data (GArray * encodings, guint8 ** data_out, - guint * size_out, GstMatroskaTrackEncodingScope scope, gboolean free) -{ - guint8 *data; - guint size; - gboolean ret = TRUE; - gint i; - - g_return_val_if_fail (encodings != NULL, FALSE); - g_return_val_if_fail (data_out != NULL && *data_out != NULL, FALSE); - g_return_val_if_fail (size_out != NULL, FALSE); - - data = *data_out; - size = *size_out; - - for (i = 0; i < encodings->len; i++) { - GstMatroskaTrackEncoding *enc = - &g_array_index (encodings, GstMatroskaTrackEncoding, i); - guint8 *new_data = NULL; - guint new_size = 0; - - if ((enc->scope & scope) == 0) - continue; - - /* Encryption not supported yet */ - if (enc->type != 0) { - ret = FALSE; - break; - } - - new_data = data; - new_size = size; - - ret = - gst_matroska_decompress_data (enc, &new_data, &new_size, - enc->comp_algo); - - if (!ret) - break; - - if ((data == *data_out && free) || (data != *data_out)) - g_free (data); - - data = new_data; - size = new_size; - } - - if (!ret) { - if ((data == *data_out && free) || (data != *data_out)) - g_free (data); - - *data_out = NULL; - *size_out = 0; - } else { - *data_out = data; - *size_out = size; - } - - return ret; -} - -static gboolean gst_matroska_parse_tracknumber_unique (GstMatroskaParse * parse, guint64 num) { gint i; diff --git a/gst/matroska/matroska-read-common.c b/gst/matroska/matroska-read-common.c index 6b0f44b..cacc180 100644 --- a/gst/matroska/matroska-read-common.c +++ b/gst/matroska/matroska-read-common.c @@ -52,50 +52,7 @@ GST_DEBUG_CATEGORY_STATIC (matroskareadcommon_debug); GST_DEBUG_OBJECT (common, "Parsing " element " element " \ " finished with '%s'", gst_flow_get_name (ret)) -GstFlowReturn -gst_matroska_decode_content_encodings (GArray * encodings) -{ - gint i; - - if (encodings == NULL) - return GST_FLOW_OK; - - for (i = 0; i < encodings->len; i++) { - GstMatroskaTrackEncoding *enc = - &g_array_index (encodings, GstMatroskaTrackEncoding, i); - guint8 *data = NULL; - guint size; - - if ((enc->scope & GST_MATROSKA_TRACK_ENCODING_SCOPE_NEXT_CONTENT_ENCODING) - == 0) - continue; - - /* Encryption not supported yet */ - if (enc->type != 0) - return GST_FLOW_ERROR; - - if (i + 1 >= encodings->len) - return GST_FLOW_ERROR; - - if (enc->comp_settings_length == 0) - continue; - - data = enc->comp_settings; - size = enc->comp_settings_length; - - if (!gst_matroska_decompress_data (enc, &data, &size, enc->comp_algo)) - return GST_FLOW_ERROR; - - g_free (enc->comp_settings); - - enc->comp_settings = data; - enc->comp_settings_length = size; - } - - return GST_FLOW_OK; -} - -gboolean +static gboolean gst_matroska_decompress_data (GstMatroskaTrackEncoding * enc, guint8 ** data_out, guint * size_out, GstMatroskaTrackCompressionAlgorithm algo) @@ -265,6 +222,111 @@ out: return ret; } +GstFlowReturn +gst_matroska_decode_content_encodings (GArray * encodings) +{ + gint i; + + if (encodings == NULL) + return GST_FLOW_OK; + + for (i = 0; i < encodings->len; i++) { + GstMatroskaTrackEncoding *enc = + &g_array_index (encodings, GstMatroskaTrackEncoding, i); + guint8 *data = NULL; + guint size; + + if ((enc->scope & GST_MATROSKA_TRACK_ENCODING_SCOPE_NEXT_CONTENT_ENCODING) + == 0) + continue; + + /* Encryption not supported yet */ + if (enc->type != 0) + return GST_FLOW_ERROR; + + if (i + 1 >= encodings->len) + return GST_FLOW_ERROR; + + if (enc->comp_settings_length == 0) + continue; + + data = enc->comp_settings; + size = enc->comp_settings_length; + + if (!gst_matroska_decompress_data (enc, &data, &size, enc->comp_algo)) + return GST_FLOW_ERROR; + + g_free (enc->comp_settings); + + enc->comp_settings = data; + enc->comp_settings_length = size; + } + + return GST_FLOW_OK; +} + +gboolean +gst_matroska_decode_data (GArray * encodings, guint8 ** data_out, + guint * size_out, GstMatroskaTrackEncodingScope scope, gboolean free) +{ + guint8 *data; + guint size; + gboolean ret = TRUE; + gint i; + + g_return_val_if_fail (encodings != NULL, FALSE); + g_return_val_if_fail (data_out != NULL && *data_out != NULL, FALSE); + g_return_val_if_fail (size_out != NULL, FALSE); + + data = *data_out; + size = *size_out; + + for (i = 0; i < encodings->len; i++) { + GstMatroskaTrackEncoding *enc = + &g_array_index (encodings, GstMatroskaTrackEncoding, i); + guint8 *new_data = NULL; + guint new_size = 0; + + if ((enc->scope & scope) == 0) + continue; + + /* Encryption not supported yet */ + if (enc->type != 0) { + ret = FALSE; + break; + } + + new_data = data; + new_size = size; + + ret = + gst_matroska_decompress_data (enc, &new_data, &new_size, + enc->comp_algo); + + if (!ret) + break; + + if ((data == *data_out && free) || (data != *data_out)) + g_free (data); + + data = new_data; + size = new_size; + } + + if (!ret) { + if ((data == *data_out && free) || (data != *data_out)) + g_free (data); + + *data_out = NULL; + *size_out = 0; + } else { + *data_out = data; + *size_out = size; + } + + return ret; +} + static gint gst_matroska_index_compare (GstMatroskaIndex * i1, GstMatroskaIndex * i2) { diff --git a/gst/matroska/matroska-read-common.h b/gst/matroska/matroska-read-common.h index 5f7cb97..92396c8 100644 --- a/gst/matroska/matroska-read-common.h +++ b/gst/matroska/matroska-read-common.h @@ -75,9 +75,8 @@ typedef struct _GstMatroskaReadCommon { } GstMatroskaReadCommon; GstFlowReturn gst_matroska_decode_content_encodings (GArray * encodings); -gboolean gst_matroska_decompress_data (GstMatroskaTrackEncoding * enc, - guint8 ** data_out, guint * size_out, - GstMatroskaTrackCompressionAlgorithm algo); +gboolean gst_matroska_decode_data (GArray * encodings, guint8 ** data_out, + guint * size_out, GstMatroskaTrackEncodingScope scope, gboolean free); gint64 gst_matroska_read_common_get_length (GstMatroskaReadCommon * common); GstFlowReturn gst_matroska_read_common_parse_index (GstMatroskaReadCommon * common, GstEbmlRead * ebml);