matroska: refactor code common to matroskademux and matroskaparse

Move the following functions to matroska-read-common.[ch] from
matroska-demux.c and matroska-parse.c:
    - gst_matroska_{demux,parse}_get_seek_track
    - gst_matroska_{demux,parse}_reset_streams

https://bugzilla.gnome.org/show_bug.cgi?id=650877
This commit is contained in:
Debarshi Ray 2011-05-30 10:40:08 +05:30 committed by Sebastian Dröge
parent 17ff8a73d8
commit bc7d61abca
4 changed files with 63 additions and 104 deletions

View file

@ -1514,55 +1514,6 @@ gst_matroska_demux_element_send_event (GstElement * element, GstEvent * event)
return res;
}
/* determine track to seek in */
static GstMatroskaTrackContext *
gst_matroska_demux_get_seek_track (GstMatroskaDemux * demux,
GstMatroskaTrackContext * track)
{
gint i;
if (track && track->type == GST_MATROSKA_TRACK_TYPE_VIDEO)
return track;
for (i = 0; i < demux->common.src->len; i++) {
GstMatroskaTrackContext *stream;
stream = g_ptr_array_index (demux->common.src, i);
if (stream->type == GST_MATROSKA_TRACK_TYPE_VIDEO && stream->index_table)
track = stream;
}
return track;
}
/* call with object lock held */
static void
gst_matroska_demux_reset_streams (GstMatroskaDemux * demux, GstClockTime time,
gboolean full)
{
gint i;
GST_DEBUG_OBJECT (demux, "resetting stream state");
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);
context->pos = time;
context->set_discont = TRUE;
context->eos = FALSE;
context->from_time = GST_CLOCK_TIME_NONE;
if (full)
context->last_flow = GST_FLOW_OK;
if (context->type == GST_MATROSKA_TRACK_TYPE_VIDEO) {
GstMatroskaTrackVideoContext *videocontext =
(GstMatroskaTrackVideoContext *) context;
/* demux object lock held by caller */
videocontext->earliest_time = GST_CLOCK_TIME_NONE;
}
}
}
static gboolean
gst_matroska_demux_move_to_entry (GstMatroskaDemux * demux,
GstMatroskaIndex * entry, gboolean reset)
@ -1580,7 +1531,7 @@ gst_matroska_demux_move_to_entry (GstMatroskaDemux * demux,
entry->block, GST_TIME_ARGS (entry->time));
/* update the time */
gst_matroska_demux_reset_streams (demux, entry->time, TRUE);
gst_matroska_read_common_reset_streams (&demux->common, entry->time, TRUE);
demux->segment.last_stop = entry->time;
demux->seek_block = entry->block;
demux->seek_first = TRUE;
@ -1945,7 +1896,7 @@ gst_matroska_demux_handle_seek_event (GstMatroskaDemux * demux,
/* check sanity before we start flushing and all that */
GST_OBJECT_LOCK (demux);
track = gst_matroska_demux_get_seek_track (demux, track);
track = gst_matroska_read_common_get_seek_track (&demux->common, track);
if ((entry = gst_matroska_read_common_do_index_seek (&demux->common, track,
seeksegment.last_stop, &demux->seek_index, &demux->seek_entry)) ==
NULL) {
@ -5200,7 +5151,8 @@ gst_matroska_demux_chain (GstPad * pad, GstBuffer * buffer)
GST_DEBUG_OBJECT (demux, "got DISCONT");
gst_adapter_clear (demux->common.adapter);
GST_OBJECT_LOCK (demux);
gst_matroska_demux_reset_streams (demux, GST_CLOCK_TIME_NONE, FALSE);
gst_matroska_read_common_reset_streams (&demux->common,
GST_CLOCK_TIME_NONE, FALSE);
GST_OBJECT_UNLOCK (demux);
}
@ -5312,7 +5264,8 @@ gst_matroska_demux_handle_sink_event (GstPad * pad, GstEvent * event)
{
gst_adapter_clear (demux->common.adapter);
GST_OBJECT_LOCK (demux);
gst_matroska_demux_reset_streams (demux, GST_CLOCK_TIME_NONE, TRUE);
gst_matroska_read_common_reset_streams (&demux->common,
GST_CLOCK_TIME_NONE, TRUE);
demux->segment.last_stop = GST_CLOCK_TIME_NONE;
demux->cluster_time = GST_CLOCK_TIME_NONE;
demux->cluster_offset = 0;

View file

@ -1234,54 +1234,6 @@ gst_matroska_parse_element_send_event (GstElement * element, GstEvent * event)
return res;
}
/* determine track to seek in */
static GstMatroskaTrackContext *
gst_matroska_parse_get_seek_track (GstMatroskaParse * parse,
GstMatroskaTrackContext * track)
{
gint i;
if (track && track->type == GST_MATROSKA_TRACK_TYPE_VIDEO)
return track;
for (i = 0; i < parse->common.src->len; i++) {
GstMatroskaTrackContext *stream;
stream = g_ptr_array_index (parse->common.src, i);
if (stream->type == GST_MATROSKA_TRACK_TYPE_VIDEO && stream->index_table)
track = stream;
}
return track;
}
static void
gst_matroska_parse_reset_streams (GstMatroskaParse * parse, GstClockTime time,
gboolean full)
{
gint i;
GST_DEBUG_OBJECT (parse, "resetting stream state");
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);
context->pos = time;
context->set_discont = TRUE;
context->eos = FALSE;
context->from_time = GST_CLOCK_TIME_NONE;
if (full)
context->last_flow = GST_FLOW_OK;
if (context->type == GST_MATROSKA_TRACK_TYPE_VIDEO) {
GstMatroskaTrackVideoContext *videocontext =
(GstMatroskaTrackVideoContext *) context;
/* parse object lock held by caller */
videocontext->earliest_time = GST_CLOCK_TIME_NONE;
}
}
}
/* searches for a cluster start from @pos,
* return GST_FLOW_OK and cluster position in @pos if found */
static GstFlowReturn
@ -1389,7 +1341,7 @@ gst_matroska_parse_handle_seek_event (GstMatroskaParse * parse,
if (pad)
track = gst_pad_get_element_private (pad);
track = gst_matroska_parse_get_seek_track (parse, track);
track = gst_matroska_read_common_get_seek_track (&parse->common, track);
gst_event_parse_seek (event, &rate, &format, &flags, &cur_type, &cur,
&stop_type, &stop);
@ -3824,7 +3776,8 @@ gst_matroska_parse_chain (GstPad * pad, GstBuffer * buffer)
GST_DEBUG_OBJECT (parse, "got DISCONT");
gst_adapter_clear (parse->common.adapter);
GST_OBJECT_LOCK (parse);
gst_matroska_parse_reset_streams (parse, GST_CLOCK_TIME_NONE, FALSE);
gst_matroska_read_common_reset_streams (&parse->common,
GST_CLOCK_TIME_NONE, FALSE);
GST_OBJECT_UNLOCK (parse);
}
@ -3934,7 +3887,8 @@ gst_matroska_parse_handle_sink_event (GstPad * pad, GstEvent * event)
{
gst_adapter_clear (parse->common.adapter);
GST_OBJECT_LOCK (parse);
gst_matroska_parse_reset_streams (parse, GST_CLOCK_TIME_NONE, TRUE);
gst_matroska_read_common_reset_streams (&parse->common,
GST_CLOCK_TIME_NONE, TRUE);
GST_OBJECT_UNLOCK (parse);
parse->segment.last_stop = GST_CLOCK_TIME_NONE;
parse->cluster_time = GST_CLOCK_TIME_NONE;

View file

@ -446,6 +446,27 @@ gst_matroska_read_common_get_length (GstMatroskaReadCommon * common)
return end;
}
/* determine track to seek in */
GstMatroskaTrackContext *
gst_matroska_read_common_get_seek_track (GstMatroskaReadCommon * common,
GstMatroskaTrackContext * track)
{
gint i;
if (track && track->type == GST_MATROSKA_TRACK_TYPE_VIDEO)
return track;
for (i = 0; i < common->src->len; i++) {
GstMatroskaTrackContext *stream;
stream = g_ptr_array_index (common->src, i);
if (stream->type == GST_MATROSKA_TRACK_TYPE_VIDEO && stream->index_table)
track = stream;
}
return track;
}
/* skip unknown or alike element */
GstFlowReturn
gst_matroska_read_common_parse_skip (GstMatroskaReadCommon * common,
@ -1102,6 +1123,33 @@ gst_matroska_read_common_read_track_encodings (GstMatroskaReadCommon * common,
return gst_matroska_decode_content_encodings (context->encodings);
}
/* call with object lock held */
void
gst_matroska_read_common_reset_streams (GstMatroskaReadCommon * common,
GstClockTime time, gboolean full)
{
gint i;
GST_DEBUG_OBJECT (common, "resetting stream state");
g_assert (common->src->len == common->num_streams);
for (i = 0; i < common->src->len; i++) {
GstMatroskaTrackContext *context = g_ptr_array_index (common->src, i);
context->pos = time;
context->set_discont = TRUE;
context->eos = FALSE;
context->from_time = GST_CLOCK_TIME_NONE;
if (full)
context->last_flow = GST_FLOW_OK;
if (context->type == GST_MATROSKA_TRACK_TYPE_VIDEO) {
GstMatroskaTrackVideoContext *videocontext =
(GstMatroskaTrackVideoContext *) context;
/* demux object lock held by caller */
videocontext->earliest_time = GST_CLOCK_TIME_NONE;
}
}
}
gboolean
gst_matroska_read_common_tracknumber_unique (GstMatroskaReadCommon * common,
guint64 num)

View file

@ -87,6 +87,8 @@ GstMatroskaIndex * gst_matroska_read_common_do_index_seek (
void gst_matroska_read_common_found_global_tag (GstMatroskaReadCommon * common,
GstElement * el, GstTagList * taglist);
gint64 gst_matroska_read_common_get_length (GstMatroskaReadCommon * common);
GstMatroskaTrackContext * gst_matroska_read_common_get_seek_track (
GstMatroskaReadCommon * common, GstMatroskaTrackContext * track);
GstFlowReturn gst_matroska_read_common_parse_index (GstMatroskaReadCommon *
common, GstEbmlRead * ebml);
GstFlowReturn gst_matroska_read_common_parse_skip (GstMatroskaReadCommon *
@ -104,6 +106,8 @@ gint gst_matroska_read_common_stream_from_num (GstMatroskaReadCommon * common,
GstFlowReturn gst_matroska_read_common_read_track_encodings (
GstMatroskaReadCommon * common, GstEbmlRead * ebml,
GstMatroskaTrackContext * context);
void gst_matroska_read_common_reset_streams (GstMatroskaReadCommon * common,
GstClockTime time, gboolean full);
gboolean gst_matroska_read_common_tracknumber_unique (GstMatroskaReadCommon *
common, guint64 num);