From 932d745bc8a3677e15845a58f1adb00c413cc839 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Wed, 18 Aug 2021 21:18:29 +0200 Subject: [PATCH] mp4: Merge chunk_to_offset() into mp4_set_sample_position(). Another equivalent transformation which shortens the code and improves readability. --- mp4.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/mp4.c b/mp4.c index 9f11a66e..1c20d89f 100644 --- a/mp4.c +++ b/mp4.c @@ -1023,23 +1023,6 @@ static int32_t chunk_of_sample(const struct mp4 *f, int32_t track, return 0; } -static int32_t chunk_to_offset(const struct mp4 *f, int32_t track, - int32_t chunk) -{ - const struct mp4_track *p_track = f->track[track]; - - if (p_track->stco_entry_count && (chunk > p_track->stco_entry_count)) { - return p_track->stco_chunk_offset[p_track->stco_entry_count - - 1]; - } else if (p_track->stco_entry_count) { - return p_track->stco_chunk_offset[chunk - 1]; - } else { - return 8; - } - - return 0; -} - /** * Return the number of milliseconds of the given track. * @@ -1092,8 +1075,13 @@ int mp4_set_sample_position(struct mp4 *f, uint32_t track, int32_t sample) for (srs = 0, n = chunk_sample; n < sample; n++) srs += t->stsz_table[n]; } - offset = chunk_to_offset(f, track, chunk) + srs; - set_position(f, offset); + if (t->stco_entry_count > 0 && chunk > t->stco_entry_count) + offset = t->stco_chunk_offset[t->stco_entry_count - 1]; + else if (t->stco_entry_count > 0) + offset = t->stco_chunk_offset[chunk - 1]; + else + offset = 8; + set_position(f, offset + srs); return 1; } -- 2.39.2