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
This commit is contained in:
Debarshi Ray 2011-05-28 22:04:34 +05:30 committed by Sebastian Dröge
parent eeb4d19992
commit 17ff8a73d8
6 changed files with 52 additions and 61 deletions

View file

@ -204,9 +204,9 @@ gst_matroska_demux_finalize (GObject * object)
demux->common.src = NULL; demux->common.src = NULL;
} }
if (demux->global_tags) { if (demux->common.global_tags) {
gst_tag_list_free (demux->global_tags); gst_tag_list_free (demux->common.global_tags);
demux->global_tags = NULL; demux->common.global_tags = NULL;
} }
g_object_unref (demux->common.adapter); g_object_unref (demux->common.adapter);
@ -260,7 +260,7 @@ gst_matroska_demux_init (GstMatroskaDemux * demux,
demux->writing_app = NULL; demux->writing_app = NULL;
demux->muxing_app = NULL; demux->muxing_app = NULL;
demux->common.index = NULL; demux->common.index = NULL;
demux->global_tags = NULL; demux->common.global_tags = NULL;
demux->common.adapter = gst_adapter_new (); demux->common.adapter = gst_adapter_new ();
@ -450,10 +450,10 @@ gst_matroska_demux_reset (GstElement * element)
} }
demux->common.element_index_writer_id = -1; demux->common.element_index_writer_id = -1;
if (demux->global_tags) { if (demux->common.global_tags) {
gst_tag_list_free (demux->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) { if (demux->common.cached_buffer) {
gst_buffer_unref (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; 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, /* returns FALSE if there are no pads to deliver event to,
* otherwise TRUE (whatever the outcome of event sending), * otherwise TRUE (whatever the outcome of event sending),
* takes ownership of the passed event! */ * 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)) { if (G_UNLIKELY (is_newsegment && demux->common.global_tags != NULL)) {
gst_tag_list_add (demux->global_tags, GST_TAG_MERGE_REPLACE, gst_tag_list_add (demux->common.global_tags, GST_TAG_MERGE_REPLACE,
GST_TAG_CONTAINER_FORMAT, "Matroska", NULL); GST_TAG_CONTAINER_FORMAT, "Matroska", NULL);
GST_DEBUG_OBJECT (demux, "Sending global_tags %p : %" GST_PTR_FORMAT, GST_DEBUG_OBJECT (demux, "Sending global_tags %p : %" GST_PTR_FORMAT,
demux->global_tags, demux->global_tags); demux->common.global_tags, demux->common.global_tags);
gst_element_found_tags (GST_ELEMENT (demux), demux->global_tags); gst_element_found_tags (GST_ELEMENT (demux), demux->common.global_tags);
demux->global_tags = NULL; demux->common.global_tags = NULL;
} }
gst_event_unref (event); gst_event_unref (event);
@ -2569,7 +2552,8 @@ gst_matroska_demux_parse_info (GstMatroskaDemux * demux, GstEbmlRead * ebml)
taglist = gst_tag_list_new (); taglist = gst_tag_list_new ();
gst_tag_list_add (taglist, GST_TAG_MERGE_APPEND, GST_TAG_TITLE, text, gst_tag_list_add (taglist, GST_TAG_MERGE_APPEND, GST_TAG_TITLE, text,
NULL); 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); g_free (text);
break; break;
} }
@ -2828,7 +2812,8 @@ gst_matroska_demux_parse_metadata (GstMatroskaDemux * demux, GstEbmlRead * ebml)
DEBUG_ELEMENT_STOP (demux, ebml, "Tags", ret); 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; return ret;
} }
@ -3023,7 +3008,8 @@ gst_matroska_demux_parse_attachments (GstMatroskaDemux * demux,
if (gst_structure_n_fields (GST_STRUCTURE (taglist)) > 0) { if (gst_structure_n_fields (GST_STRUCTURE (taglist)) > 0) {
GST_DEBUG_OBJECT (demux, "Storing attachment tags"); 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 { } else {
GST_DEBUG_OBJECT (demux, "No valid attachments found"); GST_DEBUG_OBJECT (demux, "No valid attachments found");
gst_tag_list_free (taglist); gst_tag_list_free (taglist);

View file

@ -83,7 +83,6 @@ typedef struct _GstMatroskaDemux {
GstEvent *close_segment; GstEvent *close_segment;
GstEvent *new_segment; GstEvent *new_segment;
GstTagList *global_tags;
/* some state saving */ /* some state saving */
GstClockTime cluster_time; GstClockTime cluster_time;

View file

@ -166,9 +166,9 @@ gst_matroska_parse_finalize (GObject * object)
parse->common.src = NULL; parse->common.src = NULL;
} }
if (parse->global_tags) { if (parse->common.global_tags) {
gst_tag_list_free (parse->global_tags); gst_tag_list_free (parse->common.global_tags);
parse->global_tags = NULL; parse->common.global_tags = NULL;
} }
g_object_unref (parse->common.adapter); g_object_unref (parse->common.adapter);
@ -229,7 +229,7 @@ gst_matroska_parse_init (GstMatroskaParse * parse,
parse->writing_app = NULL; parse->writing_app = NULL;
parse->muxing_app = NULL; parse->muxing_app = NULL;
parse->common.index = NULL; parse->common.index = NULL;
parse->global_tags = NULL; parse->common.global_tags = NULL;
parse->common.adapter = gst_adapter_new (); parse->common.adapter = gst_adapter_new ();
@ -373,10 +373,10 @@ gst_matroska_parse_reset (GstElement * element)
} }
parse->common.element_index_writer_id = -1; parse->common.element_index_writer_id = -1;
if (parse->global_tags) { if (parse->common.global_tags) {
gst_tag_list_free (parse->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) { if (parse->common.cached_buffer) {
gst_buffer_unref (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; 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, /* returns FALSE if there are no pads to deliver event to,
* otherwise TRUE (whatever the outcome of event sending), * otherwise TRUE (whatever the outcome of event sending),
* takes ownership of the passed event! */ * takes ownership of the passed event! */
@ -1870,7 +1853,8 @@ gst_matroska_parse_parse_info (GstMatroskaParse * parse, GstEbmlRead * ebml)
taglist = gst_tag_list_new (); taglist = gst_tag_list_new ();
gst_tag_list_add (taglist, GST_TAG_MERGE_APPEND, GST_TAG_TITLE, text, gst_tag_list_add (taglist, GST_TAG_MERGE_APPEND, GST_TAG_TITLE, text,
NULL); 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); g_free (text);
break; break;
} }
@ -2128,7 +2112,8 @@ gst_matroska_parse_parse_metadata (GstMatroskaParse * parse, GstEbmlRead * ebml)
DEBUG_ELEMENT_STOP (parse, ebml, "Tags", ret); 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; return ret;
} }
@ -2323,7 +2308,8 @@ gst_matroska_parse_parse_attachments (GstMatroskaParse * parse,
if (gst_structure_n_fields (GST_STRUCTURE (taglist)) > 0) { if (gst_structure_n_fields (GST_STRUCTURE (taglist)) > 0) {
GST_DEBUG_OBJECT (parse, "Storing attachment tags"); 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 { } else {
GST_DEBUG_OBJECT (parse, "No valid attachments found"); GST_DEBUG_OBJECT (parse, "No valid attachments found");
gst_tag_list_free (taglist); gst_tag_list_free (taglist);

View file

@ -85,7 +85,6 @@ typedef struct _GstMatroskaParse {
GstEvent *close_segment; GstEvent *close_segment;
GstEvent *new_segment; GstEvent *new_segment;
GstTagList *global_tags;
/* some state saving */ /* some state saving */
GstClockTime cluster_time; GstClockTime cluster_time;

View file

@ -416,6 +416,23 @@ gst_matroska_read_common_encoding_order_unique (GArray * encodings, guint64
return TRUE; 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 gint64
gst_matroska_read_common_get_length (GstMatroskaReadCommon * common) gst_matroska_read_common_get_length (GstMatroskaReadCommon * common)
{ {

View file

@ -64,6 +64,8 @@ typedef struct _GstMatroskaReadCommon {
/* timescale in the file */ /* timescale in the file */
guint64 time_scale; guint64 time_scale;
GstTagList *global_tags;
/* pull mode caching */ /* pull mode caching */
GstBuffer *cached_buffer; 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 ( GstMatroskaIndex * gst_matroska_read_common_do_index_seek (
GstMatroskaReadCommon * common, GstMatroskaTrackContext * track, gint64 GstMatroskaReadCommon * common, GstMatroskaTrackContext * track, gint64
seek_pos, GArray ** _index, gint * _entry_index); 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); gint64 gst_matroska_read_common_get_length (GstMatroskaReadCommon * common);
GstFlowReturn gst_matroska_read_common_parse_index (GstMatroskaReadCommon * GstFlowReturn gst_matroska_read_common_parse_index (GstMatroskaReadCommon *
common, GstEbmlRead * ebml); common, GstEbmlRead * ebml);