Commit 13ed50b8 authored by Fabrizio Gennari's avatar Fabrizio Gennari Committed by Tim-Philipp Müller

gst/avi/gstavidemux.c: Fix index creation when we have to scan the file to...

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  <fabrizio dot ge at tiscali dot it>
* 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.
parent 37d04ac0
2006-04-20 Tim-Philipp Müller <tim at centricular dot net>
Patch by: Fabrizio Gennari <fabrizio dot ge at tiscali dot it>
* 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 <tim at centricular dot net> 2006-04-20 Tim-Philipp Müller <tim at centricular dot net>
* ext/flac/gstflacdec.c: (gst_flac_dec_loop), * ext/flac/gstflacdec.c: (gst_flac_dec_loop),
......
...@@ -1605,9 +1605,10 @@ gst_avi_demux_peek_tag (GstAviDemux * avi, guint64 offset, guint32 * tag, ...@@ -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); *size = GST_READ_UINT32_LE (GST_BUFFER_DATA (buf) + 4);
gst_buffer_unref (buf); gst_buffer_unref (buf);
GST_LOG_OBJECT (avi, GST_LOG_OBJECT (avi, "Tag[%" GST_FOURCC_FORMAT "] (size:%d) %"
"Tag[%" GST_FOURCC_FORMAT "] (size:%d) %lld -- %lld", G_GINT64_FORMAT " -- %" G_GINT64_FORMAT, GST_FOURCC_ARGS (*tag),
GST_FOURCC_ARGS (*tag), *size, offset, offset + (guint64) * size); *size, offset + 8, offset + 8 + (gint64) * size);
beach: beach:
return res; return res;
} }
...@@ -1631,9 +1632,7 @@ gst_avi_demux_next_data_buffer (GstAviDemux * avi, guint64 * offset, ...@@ -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) if ((res = gst_avi_demux_peek_tag (avi, off, tag, &siz)) != GST_FLOW_OK)
break; break;
if (*tag == GST_RIFF_TAG_LIST) if (*tag == GST_RIFF_TAG_LIST)
off += 8; off += 12;
else if (*tag == GST_RIFF_LIST_movi)
off += 4;
else { else {
*offset = off + 8; *offset = off + 8;
*size = siz; *size = siz;
...@@ -1663,7 +1662,6 @@ gst_avi_demux_stream_scan (GstAviDemux * avi, ...@@ -1663,7 +1662,6 @@ gst_avi_demux_stream_scan (GstAviDemux * avi,
guint64 length; guint64 length;
gint64 tmplength; gint64 tmplength;
guint32 tag; guint32 tag;
GstPad *peer;
GList *list = NULL; GList *list = NULL;
guint index_size = 0; guint index_size = 0;
...@@ -1674,12 +1672,10 @@ gst_avi_demux_stream_scan (GstAviDemux * avi, ...@@ -1674,12 +1672,10 @@ gst_avi_demux_stream_scan (GstAviDemux * avi,
GST_LOG_OBJECT (avi, "Creating index %s existing index", GST_LOG_OBJECT (avi, "Creating index %s existing index",
(*index) ? "with" : "without"); (*index) ? "with" : "without");
if (!(peer = gst_pad_get_peer (avi->sinkpad))) if (!gst_pad_query_peer_duration (avi->sinkpad, &format, &tmplength))
return FALSE;
if (!(gst_pad_query_duration (peer, &format, &tmplength)))
return FALSE; return FALSE;
length = tmplength; length = tmplength;
gst_object_unref (peer);
if (*index) { if (*index) {
entry = g_list_last (*index)->data; entry = g_list_last (*index)->data;
...@@ -1706,59 +1702,59 @@ gst_avi_demux_stream_scan (GstAviDemux * avi, ...@@ -1706,59 +1702,59 @@ gst_avi_demux_stream_scan (GstAviDemux * avi,
&size)) != GST_FLOW_OK) &size)) != GST_FLOW_OK)
break; break;
stream_nr = CHUNKID_TO_STREAMNR (tag); stream_nr = CHUNKID_TO_STREAMNR (tag);
if (stream_nr < 0 || stream_nr >= avi->num_streams) if (stream_nr >= 0 && stream_nr < avi->num_streams) {
continue; stream = &avi->stream[stream_nr];
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];
entry->index_nr = index_size++; /* pre-allocate */
entry->stream_nr = stream_nr; if (index_size % 1024 == 0) {
entry->flags = GST_RIFF_IF_KEYFRAME; entries = g_new (gst_avi_index_entry, 1024);
entry->offset = pos - avi->index_offset; *alloc_list = g_list_prepend (*alloc_list, entries);
entry->size = size; }
entry = &entries[index_size % 1024];
/* timestamps */
if (stream->strh->samplesize && stream->strh->type == GST_RIFF_FCC_auds) { entry->index_nr = index_size++;
format = GST_FORMAT_TIME; entry->stream_nr = stream_nr;
/* constant rate stream */ entry->flags = GST_RIFF_IF_KEYFRAME;
gst_avi_demux_src_convert (stream->pad, GST_FORMAT_BYTES, entry->offset = pos - avi->index_offset;
stream->total_bytes, &format, &tmpts); entry->size = size;
entry->ts = tmpts;
gst_avi_demux_src_convert (stream->pad, GST_FORMAT_BYTES, /* timestamps */
stream->total_bytes + entry->size, &format, &tmpdur); if (stream->strh->samplesize && stream->strh->type == GST_RIFF_FCC_auds) {
entry->dur = tmpdur; format = GST_FORMAT_TIME;
} else { /* constant rate stream */
format = GST_FORMAT_TIME; gst_avi_demux_src_convert (stream->pad, GST_FORMAT_BYTES,
/* VBR stream */ stream->total_bytes, &format, &tmpts);
gst_avi_demux_src_convert (stream->pad, GST_FORMAT_DEFAULT, entry->ts = tmpts;
stream->total_frames, &format, &tmpts); gst_avi_demux_src_convert (stream->pad, GST_FORMAT_BYTES,
entry->ts = tmpts; stream->total_bytes + entry->size, &format, &tmpdur);
gst_avi_demux_src_convert (stream->pad, GST_FORMAT_DEFAULT, entry->dur = tmpdur;
stream->total_frames + 1, &format, &tmpdur); } else {
entry->dur = tmpdur; 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 */ /* update position */
pos += ((size + 1) & ~1); pos += GST_ROUND_UP_2 (size);
if (pos > length) { if (pos > length) {
GST_WARNING_OBJECT (avi, GST_WARNING_OBJECT (avi,
"Stopping index lookup since we are further than EOF"); "Stopping index lookup since we are further than EOF");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment