mirror of https://git.ffmpeg.org/ffmpeg.git
avformat/matroskadec: Refactor some functions
Since the changes to the parsing of SimpleBlocks, both ebml_parse_id and ebml_parse_elem are only called from one place, so that it is possible to inline these two function calls. This is done, but not completely: ebml_parse_id still exists in a modified form. This is done in preparation for a further patch regarding the handling of unknown-length elements. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This commit is contained in:
parent
8a286e745d
commit
559e3422c7
|
@ -1056,40 +1056,17 @@ static int matroska_ebmlnum_sint(MatroskaDemuxContext *matroska,
|
|||
return res;
|
||||
}
|
||||
|
||||
static int ebml_parse_elem(MatroskaDemuxContext *matroska,
|
||||
static int ebml_parse(MatroskaDemuxContext *matroska,
|
||||
EbmlSyntax *syntax, void *data);
|
||||
|
||||
static int ebml_parse_id(MatroskaDemuxContext *matroska, EbmlSyntax *syntax,
|
||||
uint32_t id, void *data)
|
||||
static EbmlSyntax *ebml_parse_id(EbmlSyntax *syntax, uint32_t id)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; syntax[i].id; i++)
|
||||
if (id == syntax[i].id)
|
||||
break;
|
||||
if (!syntax[i].id && id == MATROSKA_ID_CLUSTER &&
|
||||
matroska->num_levels > 0 &&
|
||||
matroska->levels[matroska->num_levels - 1].length == EBML_UNKNOWN_LENGTH)
|
||||
return 0; // we reached the end of an unknown size cluster
|
||||
if (!syntax[i].id && id != EBML_ID_VOID && id != EBML_ID_CRC32) {
|
||||
av_log(matroska->ctx, AV_LOG_DEBUG, "Unknown entry 0x%"PRIX32"\n", id);
|
||||
}
|
||||
return ebml_parse_elem(matroska, &syntax[i], data);
|
||||
}
|
||||
|
||||
static int ebml_parse(MatroskaDemuxContext *matroska, EbmlSyntax *syntax,
|
||||
void *data)
|
||||
{
|
||||
if (!matroska->current_id) {
|
||||
uint64_t id;
|
||||
int res = ebml_read_num(matroska, matroska->ctx->pb, 4, &id, 0);
|
||||
if (res < 0) {
|
||||
// in live mode, finish parsing if EOF is reached.
|
||||
return (matroska->is_live && matroska->ctx->pb->eof_reached &&
|
||||
res == AVERROR_EOF) ? 1 : res;
|
||||
}
|
||||
matroska->current_id = id | 1 << 7 * res;
|
||||
}
|
||||
return ebml_parse_id(matroska, syntax, matroska->current_id, data);
|
||||
return &syntax[i];
|
||||
}
|
||||
|
||||
static int ebml_parse_nest(MatroskaDemuxContext *matroska, EbmlSyntax *syntax,
|
||||
|
@ -1174,7 +1151,7 @@ static MatroskaLevel1Element *matroska_find_level1_elem(MatroskaDemuxContext *ma
|
|||
return elem;
|
||||
}
|
||||
|
||||
static int ebml_parse_elem(MatroskaDemuxContext *matroska,
|
||||
static int ebml_parse(MatroskaDemuxContext *matroska,
|
||||
EbmlSyntax *syntax, void *data)
|
||||
{
|
||||
static const uint64_t max_lengths[EBML_TYPE_COUNT] = {
|
||||
|
@ -1189,12 +1166,34 @@ static int ebml_parse_elem(MatroskaDemuxContext *matroska,
|
|||
// no limits for anything else
|
||||
};
|
||||
AVIOContext *pb = matroska->ctx->pb;
|
||||
uint32_t id = syntax->id;
|
||||
uint32_t id;
|
||||
uint64_t length;
|
||||
int res;
|
||||
void *newelem;
|
||||
MatroskaLevel1Element *level1_elem;
|
||||
|
||||
if (!matroska->current_id) {
|
||||
uint64_t id;
|
||||
res = ebml_read_num(matroska, pb, 4, &id, 0);
|
||||
if (res < 0) {
|
||||
// in live mode, finish parsing if EOF is reached.
|
||||
return (matroska->is_live && pb->eof_reached &&
|
||||
res == AVERROR_EOF) ? 1 : res;
|
||||
}
|
||||
matroska->current_id = id | 1 << 7 * res;
|
||||
}
|
||||
|
||||
id = matroska->current_id;
|
||||
|
||||
syntax = ebml_parse_id(syntax, id);
|
||||
if (!syntax->id && id == MATROSKA_ID_CLUSTER &&
|
||||
matroska->num_levels > 0 &&
|
||||
matroska->levels[matroska->num_levels - 1].length == EBML_UNKNOWN_LENGTH)
|
||||
return 0; // we reached the end of an unknown size cluster
|
||||
if (!syntax->id && id != EBML_ID_VOID && id != EBML_ID_CRC32) {
|
||||
av_log(matroska->ctx, AV_LOG_DEBUG, "Unknown entry 0x%"PRIX32"\n", id);
|
||||
}
|
||||
|
||||
data = (char *) data + syntax->data_offset;
|
||||
if (syntax->list_elem_size) {
|
||||
EbmlList *list = data;
|
||||
|
|
Loading…
Reference in New Issue