From 8cad8d7112afc13a906f5c20026262bccecd95b5 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Wed, 18 Aug 2021 21:08:45 +0200 Subject: [PATCH 1/1] mp4: Merge sample_range_size() into mp4_set_sample_position(). This equivalent transformation shortens the code and improves readability. --- mp4.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/mp4.c b/mp4.c index 2f9c105d..9f11a66e 100644 --- a/mp4.c +++ b/mp4.c @@ -1040,19 +1040,6 @@ static int32_t chunk_to_offset(const struct mp4 *f, int32_t track, return 0; } -static int32_t sample_range_size(const struct mp4 *f, int32_t track, - int32_t chunk_sample, int32_t sample) -{ - int32_t i, total; - const struct mp4_track *t = f->track[track]; - - if (t->stsz_sample_size) - return (sample - chunk_sample) * t->stsz_sample_size; - for (i = chunk_sample, total = 0; i < sample; i++) - total += t->stsz_table[i]; - return total; -} - /** * Return the number of milliseconds of the given track. * @@ -1094,12 +1081,18 @@ int mp4_set_sample_position(struct mp4 *f, uint32_t track, int32_t sample) { const struct mp4_track *t = f->track[track]; int32_t offset, chunk, chunk_sample; + uint32_t n, srs; /* sample range size */ if (sample >= t->stsz_sample_count || track >= f->total_tracks) return -ERRNO_TO_PARA_ERROR(EINVAL); chunk_of_sample(f, track, sample, &chunk_sample, &chunk); - offset = chunk_to_offset(f, track, chunk) - + sample_range_size(f, track, chunk_sample, sample); + if (t->stsz_sample_size > 0) + srs = (sample - chunk_sample) * t->stsz_sample_size; + else { + 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); return 1; } -- 2.39.2