mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-02 12:32:29 +00:00
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
This commit is contained in:
parent
b437744b70
commit
0aa35a6bcc
4 changed files with 108 additions and 171 deletions
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -384,68 +384,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)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue