[FFmpeg-cvslog] avformat/matroskadec: Refactor some functions
Andreas Rheinhardt
git at videolan.org
Tue Jul 16 22:49:36 EEST 2019
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at gmail.com> | Fri May 17 00:30:04 2019 +0200| [559e3422c78b40df2757c29388ebf1a4f6a60f5b] | committer: James Almer
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 at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=559e3422c78b40df2757c29388ebf1a4f6a60f5b
---
libavformat/matroskadec.c | 59 +++++++++++++++++++++++------------------------
1 file changed, 29 insertions(+), 30 deletions(-)
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 400c7b7ed5..eec7181d20 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -1056,40 +1056,17 @@ static int matroska_ebmlnum_sint(MatroskaDemuxContext *matroska,
return res;
}
-static int ebml_parse_elem(MatroskaDemuxContext *matroska,
- EbmlSyntax *syntax, void *data);
+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,8 +1151,8 @@ static MatroskaLevel1Element *matroska_find_level1_elem(MatroskaDemuxContext *ma
return elem;
}
-static int ebml_parse_elem(MatroskaDemuxContext *matroska,
- EbmlSyntax *syntax, void *data)
+static int ebml_parse(MatroskaDemuxContext *matroska,
+ EbmlSyntax *syntax, void *data)
{
static const uint64_t max_lengths[EBML_TYPE_COUNT] = {
[EBML_UINT] = 8,
@@ -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;
More information about the ffmpeg-cvslog
mailing list