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}_parse_metadata

https://bugzilla.gnome.org/show_bug.cgi?id=650877
This commit is contained in:
Debarshi Ray 2011-06-05 10:15:23 +05:30 committed by Sebastian Dröge
parent 493e197588
commit 2d282a6c79
6 changed files with 78 additions and 144 deletions

View file

@ -404,10 +404,10 @@ gst_matroska_demux_reset (GstElement * element)
demux->segmentinfo_parsed = FALSE; demux->segmentinfo_parsed = FALSE;
demux->attachments_parsed = FALSE; demux->attachments_parsed = FALSE;
g_list_foreach (demux->tags_parsed, g_list_foreach (demux->common.tags_parsed,
(GFunc) gst_matroska_demux_free_parsed_el, NULL); (GFunc) gst_matroska_demux_free_parsed_el, NULL);
g_list_free (demux->tags_parsed); g_list_free (demux->common.tags_parsed);
demux->tags_parsed = NULL; demux->common.tags_parsed = NULL;
g_list_foreach (demux->seek_parsed, g_list_foreach (demux->seek_parsed,
(GFunc) gst_matroska_demux_free_parsed_el, NULL); (GFunc) gst_matroska_demux_free_parsed_el, NULL);
@ -2387,71 +2387,6 @@ gst_matroska_demux_parse_info (GstMatroskaDemux * demux, GstEbmlRead * ebml)
return ret; return ret;
} }
static GstFlowReturn
gst_matroska_demux_parse_metadata (GstMatroskaDemux * demux, GstEbmlRead * ebml)
{
GstTagList *taglist;
GstFlowReturn ret = GST_FLOW_OK;
guint32 id;
GList *l;
guint64 curpos;
curpos = gst_ebml_read_get_pos (ebml);
/* Make sure we don't parse a tags element twice and
* post it's tags twice */
curpos = gst_ebml_read_get_pos (ebml);
for (l = demux->tags_parsed; l; l = l->next) {
guint64 *pos = l->data;
if (*pos == curpos) {
GST_DEBUG_OBJECT (demux, "Skipping already parsed Tags at offset %"
G_GUINT64_FORMAT, curpos);
return GST_FLOW_OK;
}
}
demux->tags_parsed =
g_list_prepend (demux->tags_parsed, g_slice_new (guint64));
*((guint64 *) demux->tags_parsed->data) = curpos;
/* fall-through */
if ((ret = gst_ebml_read_master (ebml, &id)) != GST_FLOW_OK) {
DEBUG_ELEMENT_STOP (demux, ebml, "Tags", ret);
return ret;
}
taglist = gst_tag_list_new ();
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_TAG:
ret = gst_matroska_read_common_parse_metadata_id_tag (&demux->common,
ebml, &taglist);
break;
default:
ret = gst_matroska_read_common_parse_skip (&demux->common, ebml,
"Tags", id);
break;
/* FIXME: Use to limit the tags to specific pads */
case GST_MATROSKA_ID_TARGETS:
ret = gst_ebml_read_skip (ebml);
break;
}
}
DEBUG_ELEMENT_STOP (demux, ebml, "Tags", ret);
gst_matroska_read_common_found_global_tag (&demux->common,
GST_ELEMENT_CAST (demux), taglist);
return ret;
}
static GstFlowReturn static GstFlowReturn
gst_matroska_demux_parse_attached_file (GstMatroskaDemux * demux, gst_matroska_demux_parse_attached_file (GstMatroskaDemux * demux,
GstEbmlRead * ebml, GstTagList * taglist) GstEbmlRead * ebml, GstTagList * taglist)
@ -4556,7 +4491,8 @@ gst_matroska_demux_parse_id (GstMatroskaDemux * demux, guint32 id,
break; break;
case GST_MATROSKA_ID_TAGS: case GST_MATROSKA_ID_TAGS:
GST_READ_CHECK (gst_matroska_demux_take (demux, read, &ebml)); GST_READ_CHECK (gst_matroska_demux_take (demux, read, &ebml));
ret = gst_matroska_demux_parse_metadata (demux, &ebml); ret = gst_matroska_read_common_parse_metadata (&demux->common,
GST_ELEMENT_CAST (demux), &ebml);
break; break;
case GST_MATROSKA_ID_CHAPTERS: case GST_MATROSKA_ID_CHAPTERS:
GST_READ_CHECK (gst_matroska_demux_take (demux, read, &ebml)); GST_READ_CHECK (gst_matroska_demux_take (demux, read, &ebml));

View file

@ -70,7 +70,6 @@ typedef struct _GstMatroskaDemux {
gboolean tracks_parsed; gboolean tracks_parsed;
gboolean segmentinfo_parsed; gboolean segmentinfo_parsed;
gboolean attachments_parsed; gboolean attachments_parsed;
GList *tags_parsed;
GList *seek_parsed; GList *seek_parsed;
/* cluster positions (optional) */ /* cluster positions (optional) */

View file

@ -327,10 +327,10 @@ gst_matroska_parse_reset (GstElement * element)
parse->segmentinfo_parsed = FALSE; parse->segmentinfo_parsed = FALSE;
parse->attachments_parsed = FALSE; parse->attachments_parsed = FALSE;
g_list_foreach (parse->tags_parsed, g_list_foreach (parse->common.tags_parsed,
(GFunc) gst_matroska_parse_free_parsed_el, NULL); (GFunc) gst_matroska_parse_free_parsed_el, NULL);
g_list_free (parse->tags_parsed); g_list_free (parse->common.tags_parsed);
parse->tags_parsed = NULL; parse->common.tags_parsed = NULL;
g_list_foreach (parse->seek_parsed, g_list_foreach (parse->seek_parsed,
(GFunc) gst_matroska_parse_free_parsed_el, NULL); (GFunc) gst_matroska_parse_free_parsed_el, NULL);
@ -1689,71 +1689,6 @@ gst_matroska_parse_parse_info (GstMatroskaParse * parse, GstEbmlRead * ebml)
return ret; return ret;
} }
static GstFlowReturn
gst_matroska_parse_parse_metadata (GstMatroskaParse * parse, GstEbmlRead * ebml)
{
GstTagList *taglist;
GstFlowReturn ret = GST_FLOW_OK;
guint32 id;
GList *l;
guint64 curpos;
curpos = gst_ebml_read_get_pos (ebml);
/* Make sure we don't parse a tags element twice and
* post it's tags twice */
curpos = gst_ebml_read_get_pos (ebml);
for (l = parse->tags_parsed; l; l = l->next) {
guint64 *pos = l->data;
if (*pos == curpos) {
GST_DEBUG_OBJECT (parse, "Skipping already parsed Tags at offset %"
G_GUINT64_FORMAT, curpos);
return GST_FLOW_OK;
}
}
parse->tags_parsed =
g_list_prepend (parse->tags_parsed, g_slice_new (guint64));
*((guint64 *) parse->tags_parsed->data) = curpos;
/* fall-through */
if ((ret = gst_ebml_read_master (ebml, &id)) != GST_FLOW_OK) {
DEBUG_ELEMENT_STOP (parse, ebml, "Tags", ret);
return ret;
}
taglist = gst_tag_list_new ();
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_TAG:
ret = gst_matroska_read_common_parse_metadata_id_tag (&parse->common,
ebml, &taglist);
break;
default:
ret = gst_matroska_read_common_parse_skip (&parse->common, ebml,
"Tags", id);
break;
/* FIXME: Use to limit the tags to specific pads */
case GST_MATROSKA_ID_TARGETS:
ret = gst_ebml_read_skip (ebml);
break;
}
}
DEBUG_ELEMENT_STOP (parse, ebml, "Tags", ret);
gst_matroska_read_common_found_global_tag (&parse->common,
GST_ELEMENT_CAST (parse), taglist);
return ret;
}
static GstFlowReturn static GstFlowReturn
gst_matroska_parse_parse_attached_file (GstMatroskaParse * parse, gst_matroska_parse_parse_attached_file (GstMatroskaParse * parse,
GstEbmlRead * ebml, GstTagList * taglist) GstEbmlRead * ebml, GstTagList * taglist)
@ -3176,7 +3111,8 @@ gst_matroska_parse_parse_id (GstMatroskaParse * parse, guint32 id,
break; break;
case GST_MATROSKA_ID_TAGS: case GST_MATROSKA_ID_TAGS:
GST_READ_CHECK (gst_matroska_parse_take (parse, read, &ebml)); GST_READ_CHECK (gst_matroska_parse_take (parse, read, &ebml));
ret = gst_matroska_parse_parse_metadata (parse, &ebml); ret = gst_matroska_read_common_parse_metadata (&parse->common,
GST_ELEMENT_CAST (parse), &ebml);
gst_matroska_parse_output (parse, ebml.buf, FALSE); gst_matroska_parse_output (parse, ebml.buf, FALSE);
break; break;
case GST_MATROSKA_ID_CHAPTERS: case GST_MATROSKA_ID_CHAPTERS:

View file

@ -75,7 +75,6 @@ typedef struct _GstMatroskaParse {
gboolean tracks_parsed; gboolean tracks_parsed;
gboolean segmentinfo_parsed; gboolean segmentinfo_parsed;
gboolean attachments_parsed; gboolean attachments_parsed;
GList *tags_parsed;
GList *seek_parsed; GList *seek_parsed;
/* keeping track of playback position */ /* keeping track of playback position */

View file

@ -1076,7 +1076,7 @@ gst_matroska_read_common_parse_metadata_id_simple_tag (GstMatroskaReadCommon *
return ret; return ret;
} }
GstFlowReturn static GstFlowReturn
gst_matroska_read_common_parse_metadata_id_tag (GstMatroskaReadCommon * common, gst_matroska_read_common_parse_metadata_id_tag (GstMatroskaReadCommon * common,
GstEbmlRead * ebml, GstTagList ** p_taglist) GstEbmlRead * ebml, GstTagList ** p_taglist)
{ {
@ -1113,6 +1113,70 @@ gst_matroska_read_common_parse_metadata_id_tag (GstMatroskaReadCommon * common,
return ret; return ret;
} }
GstFlowReturn
gst_matroska_read_common_parse_metadata (GstMatroskaReadCommon * common,
GstElement * el, GstEbmlRead * ebml)
{
GstTagList *taglist;
GstFlowReturn ret = GST_FLOW_OK;
guint32 id;
GList *l;
guint64 curpos;
curpos = gst_ebml_read_get_pos (ebml);
/* Make sure we don't parse a tags element twice and
* post it's tags twice */
curpos = gst_ebml_read_get_pos (ebml);
for (l = common->tags_parsed; l; l = l->next) {
guint64 *pos = l->data;
if (*pos == curpos) {
GST_DEBUG_OBJECT (common, "Skipping already parsed Tags at offset %"
G_GUINT64_FORMAT, curpos);
return GST_FLOW_OK;
}
}
common->tags_parsed =
g_list_prepend (common->tags_parsed, g_slice_new (guint64));
*((guint64 *) common->tags_parsed->data) = curpos;
/* fall-through */
if ((ret = gst_ebml_read_master (ebml, &id)) != GST_FLOW_OK) {
DEBUG_ELEMENT_STOP (common, ebml, "Tags", ret);
return ret;
}
taglist = gst_tag_list_new ();
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_TAG:
ret = gst_matroska_read_common_parse_metadata_id_tag (common, ebml,
&taglist);
break;
default:
ret = gst_matroska_read_common_parse_skip (common, ebml, "Tags", id);
break;
/* FIXME: Use to limit the tags to specific pads */
case GST_MATROSKA_ID_TARGETS:
ret = gst_ebml_read_skip (ebml);
break;
}
}
DEBUG_ELEMENT_STOP (common, ebml, "Tags", ret);
gst_matroska_read_common_found_global_tag (common, el, taglist);
return ret;
}
static const guint8 * static const guint8 *
gst_matroska_read_common_peek_adapter (GstMatroskaReadCommon * common, guint gst_matroska_read_common_peek_adapter (GstMatroskaReadCommon * common, guint
peek) peek)

View file

@ -54,6 +54,7 @@ typedef struct _GstMatroskaReadCommon {
/* did we parse cues/tracks/segmentinfo already? */ /* did we parse cues/tracks/segmentinfo already? */
gboolean index_parsed; gboolean index_parsed;
GList *tags_parsed;
/* start-of-segment */ /* start-of-segment */
guint64 ebml_segment_start; guint64 ebml_segment_start;
@ -93,9 +94,8 @@ GstFlowReturn gst_matroska_read_common_parse_index (GstMatroskaReadCommon *
common, GstEbmlRead * ebml); common, GstEbmlRead * ebml);
GstFlowReturn gst_matroska_read_common_parse_header (GstMatroskaReadCommon * GstFlowReturn gst_matroska_read_common_parse_header (GstMatroskaReadCommon *
common, GstEbmlRead * ebml); common, GstEbmlRead * ebml);
GstFlowReturn gst_matroska_read_common_parse_metadata_id_tag ( GstFlowReturn gst_matroska_read_common_parse_metadata (GstMatroskaReadCommon *
GstMatroskaReadCommon * common, GstEbmlRead * ebml, GstTagList ** common, GstElement * el, GstEbmlRead * ebml);
p_taglist);
GstFlowReturn gst_matroska_read_common_parse_skip (GstMatroskaReadCommon * GstFlowReturn gst_matroska_read_common_parse_skip (GstMatroskaReadCommon *
common, GstEbmlRead * ebml, const gchar * parent_name, guint id); common, GstEbmlRead * ebml, const gchar * parent_name, guint id);
GstFlowReturn gst_matroska_read_common_peek_bytes (GstMatroskaReadCommon * GstFlowReturn gst_matroska_read_common_peek_bytes (GstMatroskaReadCommon *