mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-07-27 00:38:21 +00:00
qtdemux: move error code out of normal flow
This commit is contained in:
parent
4b2b7067b6
commit
3b643817be
|
@ -777,17 +777,23 @@ gst_qtdemux_find_index_linear (GstQTDemux * qtdemux, QtDemuxStream * str,
|
||||||
result++;
|
result++;
|
||||||
while (index < str->n_samples - 1) {
|
while (index < str->n_samples - 1) {
|
||||||
if (index + 1 > str->stbl_index
|
if (index + 1 > str->stbl_index
|
||||||
&& !qtdemux_parse_samples (qtdemux, str, index + 1)) {
|
&& !qtdemux_parse_samples (qtdemux, str, index + 1))
|
||||||
GST_LOG_OBJECT (qtdemux, "Parsing of index %u failed!", index + 1);
|
goto parse_failed;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (media_time < result->timestamp)
|
if (media_time < result->timestamp)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
result++;
|
result++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return index;
|
return index;
|
||||||
|
|
||||||
|
/* ERRORS */
|
||||||
|
parse_failed:
|
||||||
|
{
|
||||||
|
GST_LOG_OBJECT (qtdemux, "Parsing of index %u failed!", index + 1);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* find the index of the keyframe needed to decode the sample at @index
|
/* find the index of the keyframe needed to decode the sample at @index
|
||||||
|
@ -1020,8 +1026,6 @@ gst_qtdemux_do_push_seek (GstQTDemux * qtdemux, GstPad * pad, GstEvent * event)
|
||||||
gst_event_parse_seek (event, &rate, &format, &flags,
|
gst_event_parse_seek (event, &rate, &format, &flags,
|
||||||
&cur_type, &cur, &stop_type, &stop);
|
&cur_type, &cur, &stop_type, &stop);
|
||||||
|
|
||||||
if (stop_type != GST_SEEK_TYPE_NONE)
|
|
||||||
goto unsupported_seek;
|
|
||||||
stop = -1;
|
stop = -1;
|
||||||
|
|
||||||
/* only forward streaming and seeking is possible */
|
/* only forward streaming and seeking is possible */
|
||||||
|
@ -4118,24 +4122,15 @@ static gboolean
|
||||||
qtdemux_parse_samples (GstQTDemux * qtdemux, QtDemuxStream * stream, guint32 n)
|
qtdemux_parse_samples (GstQTDemux * qtdemux, QtDemuxStream * stream, guint32 n)
|
||||||
{
|
{
|
||||||
gint i, j, k;
|
gint i, j, k;
|
||||||
int index = 0;
|
gint index = 0;
|
||||||
|
|
||||||
if (n >= stream->n_samples) {
|
if (n >= stream->n_samples)
|
||||||
GST_LOG_OBJECT (qtdemux,
|
goto out_of_samples;
|
||||||
"Tried to parse up to sample %u but there are only %u samples", n + 1,
|
|
||||||
stream->n_samples);
|
|
||||||
GST_ELEMENT_ERROR (qtdemux, STREAM, DECODE,
|
|
||||||
(_("This file is corrupt and cannot be played.")), (NULL));
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (n <= stream->stbl_index) {
|
if (n <= stream->stbl_index)
|
||||||
GST_LOG_OBJECT (qtdemux,
|
goto already_parsed;
|
||||||
"Tried to parse up to sample %u but this sample has already been parsed",
|
|
||||||
n);
|
stream->stbl_index++;
|
||||||
return TRUE;
|
|
||||||
} else
|
|
||||||
stream->stbl_index++;
|
|
||||||
|
|
||||||
if (stream->chunks_are_chunks) {
|
if (stream->chunks_are_chunks) {
|
||||||
/* set the sample sizes */
|
/* set the sample sizes */
|
||||||
|
@ -4156,6 +4151,7 @@ qtdemux_parse_samples (GstQTDemux * qtdemux, QtDemuxStream * stream, guint32 n)
|
||||||
}
|
}
|
||||||
|
|
||||||
index = stream->stbl_index;
|
index = stream->stbl_index;
|
||||||
|
|
||||||
for (i = stream->stsc_index; i < stream->n_samples_per_chunk; i++) {
|
for (i = stream->stsc_index; i < stream->n_samples_per_chunk; i++) {
|
||||||
if (stream->stsc_chunk_index >= stream->last_chunk
|
if (stream->stsc_chunk_index >= stream->last_chunk
|
||||||
|| stream->stsc_chunk_index < stream->first_chunk) {
|
|| stream->stsc_chunk_index < stream->first_chunk) {
|
||||||
|
@ -4166,12 +4162,10 @@ qtdemux_parse_samples (GstQTDemux * qtdemux, QtDemuxStream * stream, guint32 n)
|
||||||
gst_byte_reader_skip_unchecked (&stream->stsc, 4);
|
gst_byte_reader_skip_unchecked (&stream->stsc, 4);
|
||||||
|
|
||||||
/* chunk numbers are counted from 1 it seems */
|
/* chunk numbers are counted from 1 it seems */
|
||||||
if (G_UNLIKELY (stream->first_chunk == 0)) {
|
if (G_UNLIKELY (stream->first_chunk == 0))
|
||||||
GST_ELEMENT_ERROR (qtdemux, STREAM, DECODE,
|
goto corrupt_file;
|
||||||
(_("This file is corrupt and cannot be played.")), (NULL));
|
|
||||||
return FALSE;
|
--stream->first_chunk;
|
||||||
} else
|
|
||||||
--stream->first_chunk;
|
|
||||||
|
|
||||||
/* the last chunk of each entry is calculated by taking the first chunk
|
/* the last chunk of each entry is calculated by taking the first chunk
|
||||||
* of the next entry; except if there is no next, where we fake it with
|
* of the next entry; except if there is no next, where we fake it with
|
||||||
|
@ -4181,41 +4175,31 @@ qtdemux_parse_samples (GstQTDemux * qtdemux, QtDemuxStream * stream, guint32 n)
|
||||||
} else {
|
} else {
|
||||||
stream->last_chunk =
|
stream->last_chunk =
|
||||||
gst_byte_reader_peek_uint32_be_unchecked (&stream->stsc);
|
gst_byte_reader_peek_uint32_be_unchecked (&stream->stsc);
|
||||||
if (G_UNLIKELY (stream->last_chunk == 0)) {
|
if (G_UNLIKELY (stream->last_chunk == 0))
|
||||||
GST_ELEMENT_ERROR (qtdemux, STREAM, DECODE,
|
goto corrupt_file;
|
||||||
(_("This file is corrupt and cannot be played.")), (NULL));
|
|
||||||
return FALSE;
|
--stream->last_chunk;
|
||||||
} else
|
|
||||||
--stream->last_chunk;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_LOG_OBJECT (qtdemux,
|
GST_LOG_OBJECT (qtdemux,
|
||||||
"entry %d has first_chunk %d, last_chunk %d, samples_per_chunk %d", i,
|
"entry %d has first_chunk %d, last_chunk %d, samples_per_chunk %d", i,
|
||||||
stream->first_chunk, stream->last_chunk, stream->samples_per_chunk);
|
stream->first_chunk, stream->last_chunk, stream->samples_per_chunk);
|
||||||
|
|
||||||
if (G_UNLIKELY (stream->last_chunk < stream->first_chunk)) {
|
if (G_UNLIKELY (stream->last_chunk < stream->first_chunk))
|
||||||
GST_ELEMENT_ERROR (qtdemux, STREAM, DECODE,
|
goto corrupt_file;
|
||||||
(_("This file is corrupt and cannot be played.")), (NULL));
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stream->last_chunk != G_MAXUINT32) {
|
if (stream->last_chunk != G_MAXUINT32) {
|
||||||
if (!qt_atom_parser_peek_sub (&stream->stco,
|
if (!qt_atom_parser_peek_sub (&stream->stco,
|
||||||
stream->first_chunk * stream->co_size,
|
stream->first_chunk * stream->co_size,
|
||||||
(stream->last_chunk - stream->first_chunk) * stream->co_size,
|
(stream->last_chunk - stream->first_chunk) * stream->co_size,
|
||||||
&stream->co_chunk)) {
|
&stream->co_chunk))
|
||||||
GST_ELEMENT_ERROR (qtdemux, STREAM, DECODE,
|
goto corrupt_file;
|
||||||
(_("This file is corrupt and cannot be played.")), (NULL));
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
stream->co_chunk = stream->stco;
|
stream->co_chunk = stream->stco;
|
||||||
if (!gst_byte_reader_skip (&stream->co_chunk,
|
if (!gst_byte_reader_skip (&stream->co_chunk,
|
||||||
stream->first_chunk * stream->co_size)) {
|
stream->first_chunk * stream->co_size))
|
||||||
GST_ELEMENT_ERROR (qtdemux, STREAM, DECODE,
|
goto corrupt_file;
|
||||||
(_("This file is corrupt and cannot be played.")), (NULL));
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stream->stsc_chunk_index = stream->first_chunk;
|
stream->stsc_chunk_index = stream->first_chunk;
|
||||||
|
@ -4225,11 +4209,8 @@ qtdemux_parse_samples (GstQTDemux * qtdemux, QtDemuxStream * stream, guint32 n)
|
||||||
for (j = stream->stsc_chunk_index; j < stream->last_chunk; j++) {
|
for (j = stream->stsc_chunk_index; j < stream->last_chunk; j++) {
|
||||||
if (!stream->stsc_sample_index
|
if (!stream->stsc_sample_index
|
||||||
&& !qt_atom_parser_get_offset (&stream->co_chunk, stream->co_size,
|
&& !qt_atom_parser_get_offset (&stream->co_chunk, stream->co_size,
|
||||||
&stream->chunk_offset)) {
|
&stream->chunk_offset))
|
||||||
GST_ELEMENT_ERROR (qtdemux, STREAM, DECODE,
|
goto corrupt_file;
|
||||||
(_("This file is corrupt and cannot be played.")), (NULL));
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (k = stream->stsc_sample_index; k < stream->samples_per_chunk; k++) {
|
for (k = stream->stsc_sample_index; k < stream->samples_per_chunk; k++) {
|
||||||
GST_LOG_OBJECT (qtdemux, "Creating entry %d with offset %"
|
GST_LOG_OBJECT (qtdemux, "Creating entry %d with offset %"
|
||||||
|
@ -4411,6 +4392,29 @@ done:
|
||||||
stream->stbl_index = n;
|
stream->stbl_index = n;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
/* SUCCESS */
|
||||||
|
already_parsed:
|
||||||
|
{
|
||||||
|
GST_LOG_OBJECT (qtdemux,
|
||||||
|
"Tried to parse up to sample %u but this sample has already been parsed",
|
||||||
|
n);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
/* ERRORS */
|
||||||
|
out_of_samples:
|
||||||
|
{
|
||||||
|
GST_LOG_OBJECT (qtdemux,
|
||||||
|
"Tried to parse up to sample %u but there are only %u samples", n + 1,
|
||||||
|
stream->n_samples);
|
||||||
|
goto corrupt_file;
|
||||||
|
}
|
||||||
|
corrupt_file:
|
||||||
|
{
|
||||||
|
GST_ELEMENT_ERROR (qtdemux, STREAM, DECODE,
|
||||||
|
(_("This file is corrupt and cannot be played.")), (NULL));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* collect all segment info for @stream.
|
/* collect all segment info for @stream.
|
||||||
|
|
Loading…
Reference in a new issue