From 2ca18e6d22391a7eded4a21925a44860a9840ecf Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Wed, 25 Aug 2021 18:41:07 +0200 Subject: [PATCH] mp4: Merge read_mp4a() into read_stsd(). This shortens the code because we already have a track pointer here and can get rid of the duplicated check for the number of tracks. The commit also adds the missing error check for the last read operation, i.e. the one which reads the sample rate. --- mp4.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/mp4.c b/mp4.c index 20aaa2cc..365dce65 100644 --- a/mp4.c +++ b/mp4.c @@ -309,23 +309,6 @@ static int read_stco(struct mp4 *f) return 1; } -static int read_mp4a(struct mp4 *f) -{ - int ret; - struct mp4_track *t; - - if (f->total_tracks == 0) - return -1; - t = f->track[f->total_tracks - 1]; - /* reserved (6), data reference index (2), reserved (8) */ - skip_bytes(f, 16); - ret = read_int16(f, &t->channel_count); - if (ret <= 0) - return ret; - skip_bytes(f, 6); - return read_int16(f, &t->sample_rate); -} - static int read_stsd(struct mp4 *f) { int ret; @@ -349,7 +332,15 @@ static int read_stsd(struct mp4 *f) skip += size; if (!f->audio_track && atom_type == ATOM_MP4A) { f->audio_track = t; - read_mp4a(f); + /* reserved (6), data reference index (2), reserved (8) */ + skip_bytes(f, 16); + ret = read_int16(f, &t->channel_count); + if (ret <= 0) + return ret; + skip_bytes(f, 6); + ret = read_int16(f, &t->sample_rate); + if (ret <= 0) + return ret; } set_position(f, skip); } -- 2.39.2