From: Debarshi Ray Date: Sat, 28 May 2011 16:34:34 +0000 (+0530) Subject: matroska: refactor code common to matroskademux and matroskaparse X-Git-Tag: 1.19.3~509^2~7136^2~509 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=17ff8a73d81ccb75b91e2db3d13fb7fbf4acc789;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}_found_global_tag https://bugzilla.gnome.org/show_bug.cgi?id=650877 --- diff --git a/gst/matroska/matroska-demux.c b/gst/matroska/matroska-demux.c index cb5d3d1..33a37a6 100644 --- a/gst/matroska/matroska-demux.c +++ b/gst/matroska/matroska-demux.c @@ -204,9 +204,9 @@ gst_matroska_demux_finalize (GObject * object) demux->common.src = NULL; } - if (demux->global_tags) { - gst_tag_list_free (demux->global_tags); - demux->global_tags = NULL; + if (demux->common.global_tags) { + gst_tag_list_free (demux->common.global_tags); + demux->common.global_tags = NULL; } g_object_unref (demux->common.adapter); @@ -260,7 +260,7 @@ gst_matroska_demux_init (GstMatroskaDemux * demux, demux->writing_app = NULL; demux->muxing_app = NULL; demux->common.index = NULL; - demux->global_tags = NULL; + demux->common.global_tags = NULL; demux->common.adapter = gst_adapter_new (); @@ -450,10 +450,10 @@ gst_matroska_demux_reset (GstElement * element) } demux->common.element_index_writer_id = -1; - if (demux->global_tags) { - gst_tag_list_free (demux->global_tags); + if (demux->common.global_tags) { + gst_tag_list_free (demux->common.global_tags); } - demux->global_tags = gst_tag_list_new (); + demux->common.global_tags = gst_tag_list_new (); if (demux->common.cached_buffer) { gst_buffer_unref (demux->common.cached_buffer); @@ -1445,23 +1445,6 @@ gst_matroska_demux_handle_src_query (GstPad * pad, GstQuery * query) return ret; } -/* takes ownership of taglist */ -static void -gst_matroska_demux_found_global_tag (GstMatroskaDemux * demux, - GstTagList * taglist) -{ - if (demux->global_tags) { - /* nothing sent yet, add to cache */ - gst_tag_list_insert (demux->global_tags, taglist, GST_TAG_MERGE_APPEND); - gst_tag_list_free (taglist); - } else { - /* hm, already sent, no need to cache and wait anymore */ - GST_DEBUG_OBJECT (demux, "Sending late global tags %" GST_PTR_FORMAT, - taglist); - gst_element_found_tags (GST_ELEMENT (demux), taglist); - } -} - /* returns FALSE if there are no pads to deliver event to, * otherwise TRUE (whatever the outcome of event sending), * takes ownership of the passed event! */ @@ -1499,13 +1482,13 @@ gst_matroska_demux_send_event (GstMatroskaDemux * demux, GstEvent * event) } } - if (G_UNLIKELY (is_newsegment && demux->global_tags != NULL)) { - gst_tag_list_add (demux->global_tags, GST_TAG_MERGE_REPLACE, + if (G_UNLIKELY (is_newsegment && demux->common.global_tags != NULL)) { + gst_tag_list_add (demux->common.global_tags, GST_TAG_MERGE_REPLACE, GST_TAG_CONTAINER_FORMAT, "Matroska", NULL); GST_DEBUG_OBJECT (demux, "Sending global_tags %p : %" GST_PTR_FORMAT, - demux->global_tags, demux->global_tags); - gst_element_found_tags (GST_ELEMENT (demux), demux->global_tags); - demux->global_tags = NULL; + demux->common.global_tags, demux->common.global_tags); + gst_element_found_tags (GST_ELEMENT (demux), demux->common.global_tags); + demux->common.global_tags = NULL; } gst_event_unref (event); @@ -2569,7 +2552,8 @@ gst_matroska_demux_parse_info (GstMatroskaDemux * demux, GstEbmlRead * ebml) taglist = gst_tag_list_new (); gst_tag_list_add (taglist, GST_TAG_MERGE_APPEND, GST_TAG_TITLE, text, NULL); - gst_matroska_demux_found_global_tag (demux, taglist); + gst_matroska_read_common_found_global_tag (&demux->common, + GST_ELEMENT_CAST (demux), taglist); g_free (text); break; } @@ -2828,7 +2812,8 @@ gst_matroska_demux_parse_metadata (GstMatroskaDemux * demux, GstEbmlRead * ebml) DEBUG_ELEMENT_STOP (demux, ebml, "Tags", ret); - gst_matroska_demux_found_global_tag (demux, taglist); + gst_matroska_read_common_found_global_tag (&demux->common, + GST_ELEMENT_CAST (demux), taglist); return ret; } @@ -3023,7 +3008,8 @@ gst_matroska_demux_parse_attachments (GstMatroskaDemux * demux, if (gst_structure_n_fields (GST_STRUCTURE (taglist)) > 0) { GST_DEBUG_OBJECT (demux, "Storing attachment tags"); - gst_matroska_demux_found_global_tag (demux, taglist); + 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); diff --git a/gst/matroska/matroska-demux.h b/gst/matroska/matroska-demux.h index a234a40..109f301 100644 --- a/gst/matroska/matroska-demux.h +++ b/gst/matroska/matroska-demux.h @@ -83,7 +83,6 @@ typedef struct _GstMatroskaDemux { GstEvent *close_segment; GstEvent *new_segment; - GstTagList *global_tags; /* some state saving */ GstClockTime cluster_time; diff --git a/gst/matroska/matroska-parse.c b/gst/matroska/matroska-parse.c index 04ccd71..92e97c8 100644 --- a/gst/matroska/matroska-parse.c +++ b/gst/matroska/matroska-parse.c @@ -166,9 +166,9 @@ gst_matroska_parse_finalize (GObject * object) parse->common.src = NULL; } - if (parse->global_tags) { - gst_tag_list_free (parse->global_tags); - parse->global_tags = NULL; + if (parse->common.global_tags) { + gst_tag_list_free (parse->common.global_tags); + parse->common.global_tags = NULL; } g_object_unref (parse->common.adapter); @@ -229,7 +229,7 @@ gst_matroska_parse_init (GstMatroskaParse * parse, parse->writing_app = NULL; parse->muxing_app = NULL; parse->common.index = NULL; - parse->global_tags = NULL; + parse->common.global_tags = NULL; parse->common.adapter = gst_adapter_new (); @@ -373,10 +373,10 @@ gst_matroska_parse_reset (GstElement * element) } parse->common.element_index_writer_id = -1; - if (parse->global_tags) { - gst_tag_list_free (parse->global_tags); + if (parse->common.global_tags) { + gst_tag_list_free (parse->common.global_tags); } - parse->global_tags = gst_tag_list_new (); + parse->common.global_tags = gst_tag_list_new (); if (parse->common.cached_buffer) { gst_buffer_unref (parse->common.cached_buffer); @@ -1197,23 +1197,6 @@ gst_matroska_parse_handle_src_query (GstPad * pad, GstQuery * query) return ret; } -/* takes ownership of taglist */ -static void -gst_matroska_parse_found_global_tag (GstMatroskaParse * parse, - GstTagList * taglist) -{ - if (parse->global_tags) { - /* nothing sent yet, add to cache */ - gst_tag_list_insert (parse->global_tags, taglist, GST_TAG_MERGE_APPEND); - gst_tag_list_free (taglist); - } else { - /* hm, already sent, no need to cache and wait anymore */ - GST_DEBUG_OBJECT (parse, "Sending late global tags %" GST_PTR_FORMAT, - taglist); - gst_element_found_tags (GST_ELEMENT (parse), taglist); - } -} - /* returns FALSE if there are no pads to deliver event to, * otherwise TRUE (whatever the outcome of event sending), * takes ownership of the passed event! */ @@ -1870,7 +1853,8 @@ gst_matroska_parse_parse_info (GstMatroskaParse * parse, GstEbmlRead * ebml) taglist = gst_tag_list_new (); gst_tag_list_add (taglist, GST_TAG_MERGE_APPEND, GST_TAG_TITLE, text, NULL); - gst_matroska_parse_found_global_tag (parse, taglist); + gst_matroska_read_common_found_global_tag (&parse->common, + GST_ELEMENT_CAST (parse), taglist); g_free (text); break; } @@ -2128,7 +2112,8 @@ gst_matroska_parse_parse_metadata (GstMatroskaParse * parse, GstEbmlRead * ebml) DEBUG_ELEMENT_STOP (parse, ebml, "Tags", ret); - gst_matroska_parse_found_global_tag (parse, taglist); + gst_matroska_read_common_found_global_tag (&parse->common, + GST_ELEMENT_CAST (parse), taglist); return ret; } @@ -2323,7 +2308,8 @@ gst_matroska_parse_parse_attachments (GstMatroskaParse * parse, if (gst_structure_n_fields (GST_STRUCTURE (taglist)) > 0) { GST_DEBUG_OBJECT (parse, "Storing attachment tags"); - gst_matroska_parse_found_global_tag (parse, taglist); + 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); diff --git a/gst/matroska/matroska-parse.h b/gst/matroska/matroska-parse.h index 1772920..14c9129 100644 --- a/gst/matroska/matroska-parse.h +++ b/gst/matroska/matroska-parse.h @@ -85,7 +85,6 @@ typedef struct _GstMatroskaParse { GstEvent *close_segment; GstEvent *new_segment; - GstTagList *global_tags; /* some state saving */ GstClockTime cluster_time; diff --git a/gst/matroska/matroska-read-common.c b/gst/matroska/matroska-read-common.c index 6ee04bd..a8f041b 100644 --- a/gst/matroska/matroska-read-common.c +++ b/gst/matroska/matroska-read-common.c @@ -416,6 +416,23 @@ gst_matroska_read_common_encoding_order_unique (GArray * encodings, guint64 return TRUE; } +/* takes ownership of taglist */ +void +gst_matroska_read_common_found_global_tag (GstMatroskaReadCommon * common, + GstElement * el, GstTagList * taglist) +{ + if (common->global_tags) { + /* nothing sent yet, add to cache */ + gst_tag_list_insert (common->global_tags, taglist, GST_TAG_MERGE_APPEND); + gst_tag_list_free (taglist); + } else { + /* hm, already sent, no need to cache and wait anymore */ + GST_DEBUG_OBJECT (common, "Sending late global tags %" GST_PTR_FORMAT, + taglist); + gst_element_found_tags (el, taglist); + } +} + gint64 gst_matroska_read_common_get_length (GstMatroskaReadCommon * common) { diff --git a/gst/matroska/matroska-read-common.h b/gst/matroska/matroska-read-common.h index 8b49b7c..7c48879 100644 --- a/gst/matroska/matroska-read-common.h +++ b/gst/matroska/matroska-read-common.h @@ -64,6 +64,8 @@ typedef struct _GstMatroskaReadCommon { /* timescale in the file */ guint64 time_scale; + GstTagList *global_tags; + /* pull mode caching */ GstBuffer *cached_buffer; @@ -82,6 +84,8 @@ gint gst_matroska_index_seek_find (GstMatroskaIndex * i1, GstClockTime * time, GstMatroskaIndex * gst_matroska_read_common_do_index_seek ( GstMatroskaReadCommon * common, GstMatroskaTrackContext * track, gint64 seek_pos, GArray ** _index, gint * _entry_index); +void gst_matroska_read_common_found_global_tag (GstMatroskaReadCommon * common, + GstElement * el, GstTagList * taglist); gint64 gst_matroska_read_common_get_length (GstMatroskaReadCommon * common); GstFlowReturn gst_matroska_read_common_parse_index (GstMatroskaReadCommon * common, GstEbmlRead * ebml);