From 13ed50b8f2670018daf6d3726a4f777d00944869 Mon Sep 17 00:00:00 2001 From: Fabrizio Gennari Date: Thu, 20 Apr 2006 16:33:55 +0000 Subject: gst/avi/gstavidemux.c: Fix index creation when we have to scan the file to create an index. There may be other types ... Original commit message from CVS: Patch by: Fabrizio Gennari * gst/avi/gstavidemux.c: (gst_avi_demux_peek_tag), (gst_avi_demux_next_data_buffer), (gst_avi_demux_stream_scan): Fix index creation when we have to scan the file to create an index. There may be other types of RIFF 'LIST' chunks than 'movi' and we need to skip them properly as well or we'll end up reading garbage (#336889). Some other cosmetic changes. --- ChangeLog | 11 +++++ gst/avi/gstavidemux.c | 116 ++++++++++++++++++++++++-------------------------- 2 files changed, 67 insertions(+), 60 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8ec2d8d1..26b48d64 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2006-04-20 Tim-Philipp Müller + + Patch by: Fabrizio Gennari + + * gst/avi/gstavidemux.c: (gst_avi_demux_peek_tag), + (gst_avi_demux_next_data_buffer), (gst_avi_demux_stream_scan): + Fix index creation when we have to scan the file to create + an index. There may be other types of RIFF 'LIST' chunks than + 'movi' and we need to skip them properly as well or we'll end up + reading garbage (#336889). Some other cosmetic changes. + 2006-04-20 Tim-Philipp Müller * ext/flac/gstflacdec.c: (gst_flac_dec_loop), diff --git a/gst/avi/gstavidemux.c b/gst/avi/gstavidemux.c index ff2f237f..c91f8145 100644 --- a/gst/avi/gstavidemux.c +++ b/gst/avi/gstavidemux.c @@ -1605,9 +1605,10 @@ gst_avi_demux_peek_tag (GstAviDemux * avi, guint64 offset, guint32 * tag, *size = GST_READ_UINT32_LE (GST_BUFFER_DATA (buf) + 4); gst_buffer_unref (buf); - GST_LOG_OBJECT (avi, - "Tag[%" GST_FOURCC_FORMAT "] (size:%d) %lld -- %lld", - GST_FOURCC_ARGS (*tag), *size, offset, offset + (guint64) * size); + GST_LOG_OBJECT (avi, "Tag[%" GST_FOURCC_FORMAT "] (size:%d) %" + G_GINT64_FORMAT " -- %" G_GINT64_FORMAT, GST_FOURCC_ARGS (*tag), + *size, offset + 8, offset + 8 + (gint64) * size); + beach: return res; } @@ -1631,9 +1632,7 @@ gst_avi_demux_next_data_buffer (GstAviDemux * avi, guint64 * offset, if ((res = gst_avi_demux_peek_tag (avi, off, tag, &siz)) != GST_FLOW_OK) break; if (*tag == GST_RIFF_TAG_LIST) - off += 8; - else if (*tag == GST_RIFF_LIST_movi) - off += 4; + off += 12; else { *offset = off + 8; *size = siz; @@ -1663,7 +1662,6 @@ gst_avi_demux_stream_scan (GstAviDemux * avi, guint64 length; gint64 tmplength; guint32 tag; - GstPad *peer; GList *list = NULL; guint index_size = 0; @@ -1674,12 +1672,10 @@ gst_avi_demux_stream_scan (GstAviDemux * avi, GST_LOG_OBJECT (avi, "Creating index %s existing index", (*index) ? "with" : "without"); - if (!(peer = gst_pad_get_peer (avi->sinkpad))) - return FALSE; - if (!(gst_pad_query_duration (peer, &format, &tmplength))) + if (!gst_pad_query_peer_duration (avi->sinkpad, &format, &tmplength)) return FALSE; + length = tmplength; - gst_object_unref (peer); if (*index) { entry = g_list_last (*index)->data; @@ -1706,59 +1702,59 @@ gst_avi_demux_stream_scan (GstAviDemux * avi, &size)) != GST_FLOW_OK) break; stream_nr = CHUNKID_TO_STREAMNR (tag); - if (stream_nr < 0 || stream_nr >= avi->num_streams) - continue; - stream = &avi->stream[stream_nr]; - - /* pre-allocate */ - if (index_size % 1024 == 0) { - entries = g_new (gst_avi_index_entry, 1024); - *alloc_list = g_list_prepend (*alloc_list, entries); - } - entry = &entries[index_size % 1024]; + if (stream_nr >= 0 && stream_nr < avi->num_streams) { + stream = &avi->stream[stream_nr]; - entry->index_nr = index_size++; - entry->stream_nr = stream_nr; - entry->flags = GST_RIFF_IF_KEYFRAME; - entry->offset = pos - avi->index_offset; - entry->size = size; - - /* timestamps */ - if (stream->strh->samplesize && stream->strh->type == GST_RIFF_FCC_auds) { - format = GST_FORMAT_TIME; - /* constant rate stream */ - gst_avi_demux_src_convert (stream->pad, GST_FORMAT_BYTES, - stream->total_bytes, &format, &tmpts); - entry->ts = tmpts; - gst_avi_demux_src_convert (stream->pad, GST_FORMAT_BYTES, - stream->total_bytes + entry->size, &format, &tmpdur); - entry->dur = tmpdur; - } else { - format = GST_FORMAT_TIME; - /* VBR stream */ - gst_avi_demux_src_convert (stream->pad, GST_FORMAT_DEFAULT, - stream->total_frames, &format, &tmpts); - entry->ts = tmpts; - gst_avi_demux_src_convert (stream->pad, GST_FORMAT_DEFAULT, - stream->total_frames + 1, &format, &tmpdur); - entry->dur = tmpdur; + /* pre-allocate */ + if (index_size % 1024 == 0) { + entries = g_new (gst_avi_index_entry, 1024); + *alloc_list = g_list_prepend (*alloc_list, entries); + } + entry = &entries[index_size % 1024]; + + entry->index_nr = index_size++; + entry->stream_nr = stream_nr; + entry->flags = GST_RIFF_IF_KEYFRAME; + entry->offset = pos - avi->index_offset; + entry->size = size; + + /* timestamps */ + if (stream->strh->samplesize && stream->strh->type == GST_RIFF_FCC_auds) { + format = GST_FORMAT_TIME; + /* constant rate stream */ + gst_avi_demux_src_convert (stream->pad, GST_FORMAT_BYTES, + stream->total_bytes, &format, &tmpts); + entry->ts = tmpts; + gst_avi_demux_src_convert (stream->pad, GST_FORMAT_BYTES, + stream->total_bytes + entry->size, &format, &tmpdur); + entry->dur = tmpdur; + } else { + format = GST_FORMAT_TIME; + /* VBR stream */ + gst_avi_demux_src_convert (stream->pad, GST_FORMAT_DEFAULT, + stream->total_frames, &format, &tmpts); + entry->ts = tmpts; + gst_avi_demux_src_convert (stream->pad, GST_FORMAT_DEFAULT, + stream->total_frames + 1, &format, &tmpdur); + entry->dur = tmpdur; + } + entry->dur -= entry->ts; + + /* stream position */ + entry->bytes_before = stream->total_bytes; + stream->total_bytes += entry->size; + entry->frames_before = stream->total_frames; + stream->total_frames++; + + list = g_list_prepend (list, entry); + GST_DEBUG_OBJECT (avi, "Added index entry %d (in stream: %d), offset %" + G_GUINT64_FORMAT ", time %" GST_TIME_FORMAT " for stream %d", + index_size - 1, entry->frames_before, entry->offset, + GST_TIME_ARGS (entry->ts), entry->stream_nr); } - entry->dur -= entry->ts; - - /* stream position */ - entry->bytes_before = stream->total_bytes; - stream->total_bytes += entry->size; - entry->frames_before = stream->total_frames; - stream->total_frames++; - - list = g_list_prepend (list, entry); - GST_DEBUG_OBJECT (avi, "Added index entry %d (in stream: %d), offset %" - G_GUINT64_FORMAT ", time %" GST_TIME_FORMAT " for stream %d", - index_size - 1, entry->frames_before, entry->offset, - GST_TIME_ARGS (entry->ts), entry->stream_nr); /* update position */ - pos += ((size + 1) & ~1); + pos += GST_ROUND_UP_2 (size); if (pos > length) { GST_WARNING_OBJECT (avi, "Stopping index lookup since we are further than EOF"); -- cgit