summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gst/matroska/matroska-demux.c153
-rw-r--r--gst/matroska/matroska-ids.c35
-rw-r--r--gst/matroska/matroska-ids.h1
-rw-r--r--gst/matroska/matroska-parse.c131
-rw-r--r--gst/matroska/matroska-read-common.c118
-rw-r--r--gst/matroska/matroska-read-common.h5
6 files changed, 171 insertions, 272 deletions
diff --git a/gst/matroska/matroska-demux.c b/gst/matroska/matroska-demux.c
index 90424fb56..010a2216c 100644
--- a/gst/matroska/matroska-demux.c
+++ b/gst/matroska/matroska-demux.c
@@ -189,18 +189,7 @@ gst_matroska_demux_finalize (GObject * object)
{
GstMatroskaDemux *demux = GST_MATROSKA_DEMUX (object);
- if (demux->common.src) {
- g_ptr_array_free (demux->common.src, TRUE);
- demux->common.src = NULL;
- }
-
- if (demux->common.global_tags) {
- gst_tag_list_unref (demux->common.global_tags);
- demux->common.global_tags = NULL;
- }
-
- g_object_unref (demux->common.adapter);
-
+ gst_matroska_read_common_finalize (&demux->common);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@@ -267,15 +256,8 @@ gst_matroska_demux_init (GstMatroskaDemux * demux)
GST_DEBUG_FUNCPTR (gst_matroska_demux_handle_sink_event));
gst_element_add_pad (GST_ELEMENT (demux), demux->common.sinkpad);
- /* initial stream no. */
- demux->common.src = NULL;
-
- demux->common.writing_app = NULL;
- demux->common.muxing_app = NULL;
- demux->common.index = NULL;
- demux->common.global_tags = NULL;
-
- demux->common.adapter = gst_adapter_new ();
+ /* init defaults for common read context */
+ gst_matroska_read_common_init (&demux->common);
/* property defaults */
demux->max_gap_time = DEFAULT_MAX_GAP_TIME;
@@ -286,41 +268,6 @@ gst_matroska_demux_init (GstMatroskaDemux * demux)
gst_matroska_demux_reset (GST_ELEMENT (demux));
}
-static void
-gst_matroska_track_free (GstMatroskaTrackContext * track)
-{
- g_free (track->codec_id);
- g_free (track->codec_name);
- g_free (track->name);
- g_free (track->language);
- g_free (track->codec_priv);
- g_free (track->codec_state);
-
- if (track->encodings != NULL) {
- int i;
-
- for (i = 0; i < track->encodings->len; ++i) {
- GstMatroskaTrackEncoding *enc = &g_array_index (track->encodings,
- GstMatroskaTrackEncoding,
- i);
-
- g_free (enc->comp_settings);
- }
- g_array_free (track->encodings, TRUE);
- }
-
- if (track->pending_tags)
- gst_tag_list_unref (track->pending_tags);
-
- if (track->index_table)
- g_array_free (track->index_table, TRUE);
-
- if (track->stream_headers)
- gst_buffer_list_unref (track->stream_headers);
-
- g_free (track);
-}
-
/*
* Returns the aggregated GstFlowReturn.
*/
@@ -360,40 +307,14 @@ done:
}
static void
-gst_matroska_demux_free_parsed_el (gpointer mem, gpointer user_data)
-{
- g_slice_free (guint64, mem);
-}
-
-static void
gst_matroska_demux_reset (GstElement * element)
{
GstMatroskaDemux *demux = GST_MATROSKA_DEMUX (element);
- guint i;
GST_DEBUG_OBJECT (demux, "Resetting state");
- /* reset input */
- demux->common.state = GST_MATROSKA_READ_STATE_START;
+ gst_matroska_read_common_reset (GST_ELEMENT (demux), &demux->common);
- /* clean up existing streams */
- if (demux->common.src) {
- g_assert (demux->common.src->len == demux->common.num_streams);
- for (i = 0; i < demux->common.src->len; i++) {
- GstMatroskaTrackContext *context = g_ptr_array_index (demux->common.src,
- i);
-
- if (context->pad != NULL)
- gst_element_remove_pad (GST_ELEMENT (demux), context->pad);
-
- gst_caps_replace (&context->caps, NULL);
- gst_matroska_track_free (context);
- }
- g_ptr_array_free (demux->common.src, TRUE);
- }
- demux->common.src = g_ptr_array_new ();
-
- demux->common.num_streams = 0;
demux->num_a_streams = 0;
demux->num_t_streams = 0;
demux->num_v_streams = 0;
@@ -401,55 +322,23 @@ gst_matroska_demux_reset (GstElement * element)
demux->have_group_id = FALSE;
demux->group_id = G_MAXUINT;
- /* reset media info */
- g_free (demux->common.writing_app);
- demux->common.writing_app = NULL;
- g_free (demux->common.muxing_app);
- demux->common.muxing_app = NULL;
-
- /* reset stream type */
- demux->common.is_webm = FALSE;
- demux->common.has_video = FALSE;
-
- /* reset indexes */
- if (demux->common.index) {
- g_array_free (demux->common.index, TRUE);
- demux->common.index = NULL;
- }
+ demux->clock = NULL;
+ demux->tracks_parsed = FALSE;
if (demux->clusters) {
g_array_free (demux->clusters, TRUE);
demux->clusters = NULL;
}
- /* reset timers */
- demux->clock = NULL;
- demux->common.time_scale = 1000000;
- demux->common.created = G_MININT64;
-
- demux->common.index_parsed = FALSE;
- demux->tracks_parsed = FALSE;
- demux->common.segmentinfo_parsed = FALSE;
- demux->common.attachments_parsed = FALSE;
- demux->common.chapters_parsed = FALSE;
-
- g_list_foreach (demux->common.tags_parsed,
- (GFunc) gst_matroska_demux_free_parsed_el, NULL);
- g_list_free (demux->common.tags_parsed);
- demux->common.tags_parsed = NULL;
-
g_list_foreach (demux->seek_parsed,
- (GFunc) gst_matroska_demux_free_parsed_el, NULL);
+ (GFunc) gst_matroska_read_common_free_parsed_el, NULL);
g_list_free (demux->seek_parsed);
demux->seek_parsed = NULL;
- gst_segment_init (&demux->common.segment, GST_FORMAT_TIME);
demux->last_stop_end = GST_CLOCK_TIME_NONE;
demux->seek_block = 0;
demux->stream_start_time = GST_CLOCK_TIME_NONE;
demux->to_time = GST_CLOCK_TIME_NONE;
-
- demux->common.offset = 0;
demux->cluster_time = GST_CLOCK_TIME_NONE;
demux->cluster_offset = 0;
demux->next_cluster_offset = 0;
@@ -472,34 +361,6 @@ gst_matroska_demux_reset (GstElement * element)
gst_event_unref (demux->new_segment);
demux->new_segment = NULL;
}
-#if 0
- if (demux->common.element_index) {
- gst_object_unref (demux->common.element_index);
- demux->common.element_index = NULL;
- }
- demux->common.element_index_writer_id = -1;
-#endif
-
- if (demux->common.global_tags) {
- gst_tag_list_unref (demux->common.global_tags);
- }
- demux->common.global_tags = gst_tag_list_new_empty ();
- gst_tag_list_set_scope (demux->common.global_tags, GST_TAG_SCOPE_GLOBAL);
-
- if (demux->common.cached_buffer) {
- if (demux->common.cached_data) {
- gst_buffer_unmap (demux->common.cached_buffer, &demux->common.cached_map);
- demux->common.cached_data = NULL;
- }
- gst_buffer_unref (demux->common.cached_buffer);
- demux->common.cached_buffer = NULL;
- }
-
- /* free chapters TOC if any */
- if (demux->common.toc) {
- gst_toc_unref (demux->common.toc);
- demux->common.toc = NULL;
- }
demux->invalid_duration = FALSE;
}
diff --git a/gst/matroska/matroska-ids.c b/gst/matroska/matroska-ids.c
index da8f82bda..60ebd0eb2 100644
--- a/gst/matroska/matroska-ids.c
+++ b/gst/matroska/matroska-ids.c
@@ -266,3 +266,38 @@ gst_matroska_parse_flac_stream_headers (gpointer codec_data,
}
return list;
}
+
+void
+gst_matroska_track_free (GstMatroskaTrackContext * track)
+{
+ g_free (track->codec_id);
+ g_free (track->codec_name);
+ g_free (track->name);
+ g_free (track->language);
+ g_free (track->codec_priv);
+ g_free (track->codec_state);
+
+ if (track->encodings != NULL) {
+ int i;
+
+ for (i = 0; i < track->encodings->len; ++i) {
+ GstMatroskaTrackEncoding *enc = &g_array_index (track->encodings,
+ GstMatroskaTrackEncoding,
+ i);
+
+ g_free (enc->comp_settings);
+ }
+ g_array_free (track->encodings, TRUE);
+ }
+
+ if (track->pending_tags)
+ gst_tag_list_unref (track->pending_tags);
+
+ if (track->index_table)
+ g_array_free (track->index_table, TRUE);
+
+ if (track->stream_headers)
+ gst_buffer_list_unref (track->stream_headers);
+
+ g_free (track);
+}
diff --git a/gst/matroska/matroska-ids.h b/gst/matroska/matroska-ids.h
index 8d8862312..dbb642d11 100644
--- a/gst/matroska/matroska-ids.h
+++ b/gst/matroska/matroska-ids.h
@@ -642,5 +642,6 @@ GstBufferList * gst_matroska_parse_speex_stream_headers (gpointer codec_data,
GstBufferList * gst_matroska_parse_flac_stream_headers (gpointer codec_data,
gsize codec_data_size);
+void gst_matroska_track_free (GstMatroskaTrackContext * track);
#endif /* __GST_MATROSKA_IDS_H__ */
diff --git a/gst/matroska/matroska-parse.c b/gst/matroska/matroska-parse.c
index 480d5c189..2c49bf3a3 100644
--- a/gst/matroska/matroska-parse.c
+++ b/gst/matroska/matroska-parse.c
@@ -147,18 +147,7 @@ gst_matroska_parse_finalize (GObject * object)
{
GstMatroskaParse *parse = GST_MATROSKA_PARSE (object);
- if (parse->common.src) {
- g_ptr_array_free (parse->common.src, TRUE);
- parse->common.src = NULL;
- }
-
- if (parse->common.global_tags) {
- gst_tag_list_unref (parse->common.global_tags);
- parse->common.global_tags = NULL;
- }
-
- g_object_unref (parse->common.adapter);
-
+ gst_matroska_read_common_finalize (&parse->common);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@@ -218,15 +207,8 @@ gst_matroska_parse_init (GstMatroskaParse * parse)
gst_element_add_pad (GST_ELEMENT (parse), parse->srcpad);
- /* initial stream no. */
- parse->common.src = NULL;
-
- parse->common.writing_app = NULL;
- parse->common.muxing_app = NULL;
- parse->common.index = NULL;
- parse->common.global_tags = NULL;
-
- parse->common.adapter = gst_adapter_new ();
+ /* init defaults for common read context */
+ gst_matroska_read_common_init (&parse->common);
GST_OBJECT_FLAG_SET (parse, GST_ELEMENT_FLAG_INDEXABLE);
@@ -235,114 +217,28 @@ gst_matroska_parse_init (GstMatroskaParse * parse)
}
static void
-gst_matroska_track_free (GstMatroskaTrackContext * track)
-{
- g_free (track->codec_id);
- g_free (track->codec_name);
- g_free (track->name);
- g_free (track->language);
- g_free (track->codec_priv);
- g_free (track->codec_state);
-
- if (track->encodings != NULL) {
- int i;
-
- for (i = 0; i < track->encodings->len; ++i) {
- GstMatroskaTrackEncoding *enc = &g_array_index (track->encodings,
- GstMatroskaTrackEncoding,
- i);
-
- g_free (enc->comp_settings);
- }
- g_array_free (track->encodings, TRUE);
- }
-
- if (track->pending_tags)
- gst_tag_list_unref (track->pending_tags);
-
- if (track->index_table)
- g_array_free (track->index_table, TRUE);
-
- g_free (track);
-}
-
-static void
-gst_matroska_parse_free_parsed_el (gpointer mem, gpointer user_data)
-{
- g_slice_free (guint64, mem);
-}
-
-static void
gst_matroska_parse_reset (GstElement * element)
{
GstMatroskaParse *parse = GST_MATROSKA_PARSE (element);
- guint i;
GST_DEBUG_OBJECT (parse, "Resetting state");
- /* reset input */
- parse->common.state = GST_MATROSKA_READ_STATE_START;
+ gst_matroska_read_common_reset (GST_ELEMENT (parse), &parse->common);
- /* clean up existing streams */
- if (parse->common.src) {
- g_assert (parse->common.src->len == parse->common.num_streams);
- for (i = 0; i < parse->common.src->len; i++) {
- GstMatroskaTrackContext *context = g_ptr_array_index (parse->common.src,
- i);
-
- gst_caps_replace (&context->caps, NULL);
- gst_matroska_track_free (context);
- }
- g_ptr_array_free (parse->common.src, TRUE);
- }
- parse->common.src = g_ptr_array_new ();
-
- parse->common.num_streams = 0;
parse->num_a_streams = 0;
parse->num_t_streams = 0;
parse->num_v_streams = 0;
- /* reset media info */
- g_free (parse->common.writing_app);
- parse->common.writing_app = NULL;
- g_free (parse->common.muxing_app);
- parse->common.muxing_app = NULL;
-
- /* reset stream type */
- parse->common.is_webm = FALSE;
- parse->common.has_video = FALSE;
-
- /* reset indexes */
- if (parse->common.index) {
- g_array_free (parse->common.index, TRUE);
- parse->common.index = NULL;
- }
-
- /* reset timers */
parse->clock = NULL;
- parse->common.time_scale = 1000000;
- parse->common.created = G_MININT64;
-
- parse->common.index_parsed = FALSE;
parse->tracks_parsed = FALSE;
- parse->common.segmentinfo_parsed = FALSE;
- parse->common.attachments_parsed = FALSE;
-
- g_list_foreach (parse->common.tags_parsed,
- (GFunc) gst_matroska_parse_free_parsed_el, NULL);
- g_list_free (parse->common.tags_parsed);
- parse->common.tags_parsed = NULL;
g_list_foreach (parse->seek_parsed,
- (GFunc) gst_matroska_parse_free_parsed_el, NULL);
+ (GFunc) gst_matroska_read_common_free_parsed_el, NULL);
g_list_free (parse->seek_parsed);
parse->seek_parsed = NULL;
- gst_segment_init (&parse->common.segment, GST_FORMAT_TIME);
parse->last_stop_end = GST_CLOCK_TIME_NONE;
parse->seek_block = 0;
-
- parse->common.offset = 0;
parse->cluster_time = GST_CLOCK_TIME_NONE;
parse->cluster_offset = 0;
parse->next_cluster_offset = 0;
@@ -367,23 +263,6 @@ gst_matroska_parse_reset (GstElement * element)
gst_event_unref (parse->new_segment);
parse->new_segment = NULL;
}
-#if 0
- if (parse->common.element_index) {
- gst_object_unref (parse->common.element_index);
- parse->common.element_index = NULL;
- }
- parse->common.element_index_writer_id = -1;
-#endif
-
- if (parse->common.global_tags) {
- gst_tag_list_unref (parse->common.global_tags);
- }
- parse->common.global_tags = gst_tag_list_new_empty ();
-
- if (parse->common.cached_buffer) {
- gst_buffer_unref (parse->common.cached_buffer);
- parse->common.cached_buffer = NULL;
- }
if (parse->streamheader != NULL) {
gst_buffer_unref (parse->streamheader);
diff --git a/gst/matroska/matroska-read-common.c b/gst/matroska/matroska-read-common.c
index 8a54a09cc..fd10924ba 100644
--- a/gst/matroska/matroska-read-common.c
+++ b/gst/matroska/matroska-read-common.c
@@ -44,6 +44,7 @@
#include "ebml-read.h"
#include "matroska-read-common.h"
+#include "matroska-ids.h"
GST_DEBUG_CATEGORY (matroskareadcommon_debug);
#define GST_CAT_DEFAULT matroskareadcommon_debug
@@ -2823,6 +2824,123 @@ gst_matroska_read_common_read_track_encodings (GstMatroskaReadCommon * common,
return gst_matroska_decode_content_encodings (context->encodings);
}
+void
+gst_matroska_read_common_free_parsed_el (gpointer mem, gpointer user_data)
+{
+ g_slice_free (guint64, mem);
+}
+
+void
+gst_matroska_read_common_init (GstMatroskaReadCommon * ctx)
+{
+ ctx->src = NULL;
+ ctx->writing_app = NULL;
+ ctx->muxing_app = NULL;
+ ctx->index = NULL;
+ ctx->global_tags = NULL;
+ ctx->adapter = gst_adapter_new ();
+}
+
+void
+gst_matroska_read_common_finalize (GstMatroskaReadCommon * ctx)
+{
+ if (ctx->src) {
+ g_ptr_array_free (ctx->src, TRUE);
+ ctx->src = NULL;
+ }
+
+ if (ctx->global_tags) {
+ gst_tag_list_unref (ctx->global_tags);
+ ctx->global_tags = NULL;
+ }
+
+ g_object_unref (ctx->adapter);
+}
+
+void
+gst_matroska_read_common_reset (GstElement * element,
+ GstMatroskaReadCommon * ctx)
+{
+ guint i;
+
+ GST_LOG_OBJECT (ctx, "resetting read context");
+
+ /* reset input */
+ ctx->state = GST_MATROSKA_READ_STATE_START;
+
+ /* clean up existing streams if any */
+ if (ctx->src) {
+ g_assert (ctx->src->len == ctx->num_streams);
+ for (i = 0; i < ctx->src->len; i++) {
+ GstMatroskaTrackContext *context = g_ptr_array_index (ctx->src, i);
+
+ if (context->pad != NULL)
+ gst_element_remove_pad (element, context->pad);
+
+ gst_caps_replace (&context->caps, NULL);
+ gst_matroska_track_free (context);
+ }
+ g_ptr_array_free (ctx->src, TRUE);
+ }
+ ctx->src = g_ptr_array_new ();
+ ctx->num_streams = 0;
+
+ /* reset media info */
+ g_free (ctx->writing_app);
+ ctx->writing_app = NULL;
+ g_free (ctx->muxing_app);
+ ctx->muxing_app = NULL;
+
+ /* reset stream type */
+ ctx->is_webm = FALSE;
+ ctx->has_video = FALSE;
+
+ /* reset indexes */
+ if (ctx->index) {
+ g_array_free (ctx->index, TRUE);
+ ctx->index = NULL;
+ }
+
+ /* reset timers */
+ ctx->time_scale = 1000000;
+ ctx->created = G_MININT64;
+
+ /* cues/tracks/segmentinfo */
+ ctx->index_parsed = FALSE;
+ ctx->segmentinfo_parsed = FALSE;
+ ctx->attachments_parsed = FALSE;
+ ctx->chapters_parsed = FALSE;
+
+ /* tags */
+ g_list_foreach (ctx->tags_parsed,
+ (GFunc) gst_matroska_read_common_free_parsed_el, NULL);
+ g_list_free (ctx->tags_parsed);
+ ctx->tags_parsed = NULL;
+ if (ctx->global_tags) {
+ gst_tag_list_unref (ctx->global_tags);
+ }
+ ctx->global_tags = gst_tag_list_new_empty ();
+ gst_tag_list_set_scope (ctx->global_tags, GST_TAG_SCOPE_GLOBAL);
+
+ gst_segment_init (&ctx->segment, GST_FORMAT_TIME);
+ ctx->offset = 0;
+
+ if (ctx->cached_buffer) {
+ if (ctx->cached_data) {
+ gst_buffer_unmap (ctx->cached_buffer, &ctx->cached_map);
+ ctx->cached_data = NULL;
+ }
+ gst_buffer_unref (ctx->cached_buffer);
+ ctx->cached_buffer = NULL;
+ }
+
+ /* free chapters TOC if any */
+ if (ctx->toc) {
+ gst_toc_unref (ctx->toc);
+ ctx->toc = NULL;
+ }
+}
+
/* call with object lock held */
void
gst_matroska_read_common_reset_streams (GstMatroskaReadCommon * common,
diff --git a/gst/matroska/matroska-read-common.h b/gst/matroska/matroska-read-common.h
index 148cd1fa6..be0329648 100644
--- a/gst/matroska/matroska-read-common.h
+++ b/gst/matroska/matroska-read-common.h
@@ -144,6 +144,11 @@ GstFlowReturn gst_matroska_read_common_read_track_encodings (
GstMatroskaTrackContext * context);
void gst_matroska_read_common_reset_streams (GstMatroskaReadCommon * common,
GstClockTime time, gboolean full);
+void gst_matroska_read_common_free_parsed_el (gpointer mem, gpointer user_data);
+void gst_matroska_read_common_init (GstMatroskaReadCommon * ctx);
+void gst_matroska_read_common_finalize (GstMatroskaReadCommon * ctx);
+void gst_matroska_read_common_reset (GstElement * element,
+ GstMatroskaReadCommon * ctx);
gboolean gst_matroska_read_common_tracknumber_unique (GstMatroskaReadCommon *
common, guint64 num);