From: Debarshi Ray Date: Mon, 6 Jun 2011 09:17:27 +0000 (+0530) Subject: matroska: refactor code common to matroskademux and matroskaparse X-Git-Tag: 1.19.3~509^2~7136^2~491 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=05778b85d59acbb8c90f0d9926ad19918dd5a426;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}_parse_attachments https://bugzilla.gnome.org/show_bug.cgi?id=650877 --- diff --git a/gst/matroska/matroska-demux.c b/gst/matroska/matroska-demux.c index 0d08a1c..30767bf 100644 --- a/gst/matroska/matroska-demux.c +++ b/gst/matroska/matroska-demux.c @@ -400,7 +400,7 @@ gst_matroska_demux_reset (GstElement * element) demux->common.index_parsed = FALSE; demux->tracks_parsed = FALSE; demux->common.segmentinfo_parsed = FALSE; - demux->attachments_parsed = FALSE; + demux->common.attachments_parsed = FALSE; g_list_foreach (demux->common.tags_parsed, (GFunc) gst_matroska_demux_free_parsed_el, NULL); @@ -2258,55 +2258,6 @@ gst_matroska_demux_parse_tracks (GstMatroskaDemux * demux, GstEbmlRead * ebml) } static GstFlowReturn -gst_matroska_demux_parse_attachments (GstMatroskaDemux * demux, - GstEbmlRead * ebml) -{ - guint32 id; - GstFlowReturn ret = GST_FLOW_OK; - GstTagList *taglist; - - DEBUG_ELEMENT_START (demux, ebml, "Attachments"); - - if ((ret = gst_ebml_read_master (ebml, &id)) != GST_FLOW_OK) { - DEBUG_ELEMENT_STOP (demux, ebml, "Attachments", 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_ATTACHEDFILE: - ret = gst_matroska_read_common_parse_attached_file (&demux->common, - ebml, taglist); - break; - - default: - ret = gst_matroska_read_common_parse_skip (&demux->common, ebml, - "Attachments", id); - break; - } - } - DEBUG_ELEMENT_STOP (demux, ebml, "Attachments", ret); - - if (gst_structure_n_fields (GST_STRUCTURE (taglist)) > 0) { - GST_DEBUG_OBJECT (demux, "Storing attachment tags"); - gst_matroska_read_common_found_global_tag (&demux->common, - GST_ELEMENT_CAST (demux), taglist); - } else { - GST_DEBUG_OBJECT (demux, "No valid attachments found"); - gst_tag_list_free (taglist); - } - - demux->attachments_parsed = TRUE; - - return ret; -} - -static GstFlowReturn gst_matroska_demux_parse_chapters (GstMatroskaDemux * demux, GstEbmlRead * ebml) { guint32 id; @@ -4207,9 +4158,10 @@ gst_matroska_demux_parse_id (GstMatroskaDemux * demux, guint32 id, DEBUG_ELEMENT_STOP (demux, &ebml, "SimpleBlock", ret); break; case GST_MATROSKA_ID_ATTACHMENTS: - if (!demux->attachments_parsed) { + if (!demux->common.attachments_parsed) { GST_READ_CHECK (gst_matroska_demux_take (demux, read, &ebml)); - ret = gst_matroska_demux_parse_attachments (demux, &ebml); + ret = gst_matroska_read_common_parse_attachments (&demux->common, + GST_ELEMENT_CAST (demux), &ebml); } else { GST_READ_CHECK (gst_matroska_demux_flush (demux, read)); } diff --git a/gst/matroska/matroska-demux.h b/gst/matroska/matroska-demux.h index 8980918..c9ab2fc 100644 --- a/gst/matroska/matroska-demux.h +++ b/gst/matroska/matroska-demux.h @@ -63,7 +63,6 @@ typedef struct _GstMatroskaDemux { /* did we parse cues/tracks/segmentinfo already? */ gboolean tracks_parsed; - gboolean attachments_parsed; GList *seek_parsed; /* cluster positions (optional) */ diff --git a/gst/matroska/matroska-parse.c b/gst/matroska/matroska-parse.c index 7534ed0..20e1248 100644 --- a/gst/matroska/matroska-parse.c +++ b/gst/matroska/matroska-parse.c @@ -323,7 +323,7 @@ gst_matroska_parse_reset (GstElement * element) parse->common.index_parsed = FALSE; parse->tracks_parsed = FALSE; parse->common.segmentinfo_parsed = FALSE; - parse->attachments_parsed = FALSE; + parse->common.attachments_parsed = FALSE; g_list_foreach (parse->common.tags_parsed, (GFunc) gst_matroska_parse_free_parsed_el, NULL); @@ -1558,55 +1558,6 @@ gst_matroska_parse_parse_tracks (GstMatroskaParse * parse, GstEbmlRead * ebml) } static GstFlowReturn -gst_matroska_parse_parse_attachments (GstMatroskaParse * parse, - GstEbmlRead * ebml) -{ - guint32 id; - GstFlowReturn ret = GST_FLOW_OK; - GstTagList *taglist; - - DEBUG_ELEMENT_START (parse, ebml, "Attachments"); - - if ((ret = gst_ebml_read_master (ebml, &id)) != GST_FLOW_OK) { - DEBUG_ELEMENT_STOP (parse, ebml, "Attachments", 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_ATTACHEDFILE: - ret = gst_matroska_read_common_parse_attached_file (&parse->common, - ebml, taglist); - break; - - default: - ret = gst_matroska_read_common_parse_skip (&parse->common, ebml, - "Attachments", id); - break; - } - } - DEBUG_ELEMENT_STOP (parse, ebml, "Attachments", ret); - - if (gst_structure_n_fields (GST_STRUCTURE (taglist)) > 0) { - GST_DEBUG_OBJECT (parse, "Storing attachment tags"); - gst_matroska_read_common_found_global_tag (&parse->common, - GST_ELEMENT_CAST (parse), taglist); - } else { - GST_DEBUG_OBJECT (parse, "No valid attachments found"); - gst_tag_list_free (taglist); - } - - parse->attachments_parsed = TRUE; - - return ret; -} - -static GstFlowReturn gst_matroska_parse_parse_chapters (GstMatroskaParse * parse, GstEbmlRead * ebml) { guint32 id; @@ -2821,8 +2772,9 @@ gst_matroska_parse_parse_id (GstMatroskaParse * parse, guint32 id, break; case GST_MATROSKA_ID_ATTACHMENTS: GST_READ_CHECK (gst_matroska_parse_take (parse, read, &ebml)); - if (!parse->attachments_parsed) { - ret = gst_matroska_parse_parse_attachments (parse, &ebml); + if (!parse->common.attachments_parsed) { + ret = gst_matroska_read_common_parse_attachments (&parse->common, + GST_ELEMENT_CAST (parse), &ebml); } gst_matroska_parse_output (parse, ebml.buf, FALSE); break; diff --git a/gst/matroska/matroska-parse.h b/gst/matroska/matroska-parse.h index db62a8a..a447e77 100644 --- a/gst/matroska/matroska-parse.h +++ b/gst/matroska/matroska-parse.h @@ -68,7 +68,6 @@ typedef struct _GstMatroskaParse { /* did we parse cues/tracks/segmentinfo already? */ gboolean tracks_parsed; - gboolean attachments_parsed; GList *seek_parsed; /* keeping track of playback position */ diff --git a/gst/matroska/matroska-read-common.c b/gst/matroska/matroska-read-common.c index bbe3e74..abf9e06 100644 --- a/gst/matroska/matroska-read-common.c +++ b/gst/matroska/matroska-read-common.c @@ -487,7 +487,7 @@ gst_matroska_read_common_parse_skip (GstMatroskaReadCommon * common, return gst_ebml_read_skip (ebml); } -GstFlowReturn +static GstFlowReturn gst_matroska_read_common_parse_attached_file (GstMatroskaReadCommon * common, GstEbmlRead * ebml, GstTagList * taglist) { @@ -643,6 +643,54 @@ gst_matroska_read_common_parse_attached_file (GstMatroskaReadCommon * common, } GstFlowReturn +gst_matroska_read_common_parse_attachments (GstMatroskaReadCommon * common, + GstElement * el, GstEbmlRead * ebml) +{ + guint32 id; + GstFlowReturn ret = GST_FLOW_OK; + GstTagList *taglist; + + DEBUG_ELEMENT_START (common, ebml, "Attachments"); + + if ((ret = gst_ebml_read_master (ebml, &id)) != GST_FLOW_OK) { + DEBUG_ELEMENT_STOP (common, ebml, "Attachments", 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_ATTACHEDFILE: + ret = gst_matroska_read_common_parse_attached_file (common, ebml, + taglist); + break; + + default: + ret = gst_matroska_read_common_parse_skip (common, ebml, + "Attachments", id); + break; + } + } + DEBUG_ELEMENT_STOP (common, ebml, "Attachments", ret); + + if (gst_structure_n_fields (GST_STRUCTURE (taglist)) > 0) { + GST_DEBUG_OBJECT (common, "Storing attachment tags"); + gst_matroska_read_common_found_global_tag (common, el, taglist); + } else { + GST_DEBUG_OBJECT (common, "No valid attachments found"); + gst_tag_list_free (taglist); + } + + common->attachments_parsed = TRUE; + + return ret; +} + +GstFlowReturn gst_matroska_read_common_parse_header (GstMatroskaReadCommon * common, GstEbmlRead * ebml) { diff --git a/gst/matroska/matroska-read-common.h b/gst/matroska/matroska-read-common.h index 4fb489c..ef1e19f 100644 --- a/gst/matroska/matroska-read-common.h +++ b/gst/matroska/matroska-read-common.h @@ -60,6 +60,7 @@ typedef struct _GstMatroskaReadCommon { /* did we parse cues/tracks/segmentinfo already? */ gboolean index_parsed; gboolean segmentinfo_parsed; + gboolean attachments_parsed; GList *tags_parsed; /* start-of-segment */ @@ -103,8 +104,8 @@ GstFlowReturn gst_matroska_read_common_parse_index (GstMatroskaReadCommon * common, GstEbmlRead * ebml); GstFlowReturn gst_matroska_read_common_parse_info (GstMatroskaReadCommon * common, GstElement * el, GstEbmlRead * ebml); -GstFlowReturn gst_matroska_read_common_parse_attached_file ( - GstMatroskaReadCommon * common, GstEbmlRead * ebml, GstTagList * taglist); +GstFlowReturn gst_matroska_read_common_parse_attachments ( + GstMatroskaReadCommon * common, GstElement * el, GstEbmlRead * ebml); GstFlowReturn gst_matroska_read_common_parse_header (GstMatroskaReadCommon * common, GstEbmlRead * ebml); GstFlowReturn gst_matroska_read_common_parse_metadata (GstMatroskaReadCommon *