Browse code

avformat/mov: remove modulo operations from mov_estimate_video_delay()

0.324 <-0.491 sec

Reviewed-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Reviewed-by: Sasi Inguva <isasi@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit c995e01b1e01ac11cf2545b3ce86569a482ff434)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>

Michael Niedermayer authored on 2018/07/11 09:17:55
Showing 1 changed files
... ...
@@ -3308,13 +3308,16 @@ static void mov_estimate_video_delay(MOVContext *c, AVStream* st) {
3308 3308
         for(ind = 0; ind < st->nb_index_entries && ctts_ind < msc->ctts_count; ++ind) {
3309 3309
             if (buf_size == (MAX_REORDER_DELAY + 1)) {
3310 3310
                 // If circular buffer is full, then move the first element forward.
3311
-                buf_start = (buf_start + 1) % buf_size;
3311
+                buf_start = (buf_start + 1);
3312
+                if (buf_start == MAX_REORDER_DELAY + 1)
3313
+                    buf_start = 0;
3312 3314
             } else {
3313 3315
                 ++buf_size;
3314 3316
             }
3315 3317
 
3316 3318
             // Point j to the last elem of the buffer and insert the current pts there.
3317
-            j = (buf_start + buf_size - 1) % buf_size;
3319
+            j = buf_start - 1;
3320
+            if (j < 0) j = buf_size - 1;
3318 3321
             pts_buf[j] = st->index_entries[ind].timestamp + msc->ctts_data[ctts_ind].duration;
3319 3322
 
3320 3323
             // The timestamps that are already in the sorted buffer, and are greater than the
... ...
@@ -3325,7 +3328,8 @@ static void mov_estimate_video_delay(MOVContext *c, AVStream* st) {
3325 3325
             // go through, to keep this buffer in sorted order.
3326 3326
             num_swaps = 0;
3327 3327
             while (j != buf_start) {
3328
-                r = (j - 1 + buf_size) % buf_size;
3328
+                r = j - 1;
3329
+                if (r < 0) r = buf_size - 1;
3329 3330
                 if (pts_buf[j] < pts_buf[r]) {
3330 3331
                     FFSWAP(int64_t, pts_buf[j], pts_buf[r]);
3331 3332
                     ++num_swaps;