]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
mp4: Merge sample_range_size() into mp4_set_sample_position().
authorAndre Noll <maan@tuebingen.mpg.de>
Wed, 18 Aug 2021 19:08:45 +0000 (21:08 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 30 May 2022 19:37:35 +0000 (21:37 +0200)
This equivalent transformation shortens the code and improves
readability.

mp4.c

diff --git a/mp4.c b/mp4.c
index 2f9c105dbfec56632556f492b0290a5f575375ff..9f11a66e52aca8b9e561542be7ba6d65b36d9d0b 100644 (file)
--- 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;
 }