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
This commit is contained in:
Debarshi Ray 2011-06-06 14:47:27 +05:30 committed by Sebastian Dröge
parent d8a8326d7c
commit 05778b85d5
6 changed files with 60 additions and 109 deletions

View file

@ -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);
@ -2257,55 +2257,6 @@ gst_matroska_demux_parse_tracks (GstMatroskaDemux * demux, GstEbmlRead * ebml)
return ret;
}
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)
{
@ -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));
}

View file

@ -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) */

View file

@ -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);
@ -1557,55 +1557,6 @@ gst_matroska_parse_parse_tracks (GstMatroskaParse * parse, GstEbmlRead * ebml)
return ret;
}
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)
{
@ -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;

View file

@ -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 */

View file

@ -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)
{
@ -642,6 +642,54 @@ gst_matroska_read_common_parse_attached_file (GstMatroskaReadCommon * common,
return ret;
}
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)

View file

@ -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 *