Browse code

avformat/mov: Eliminate variable buf_size from mov_estimate_video_delay()

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 3ce4034308a3726395a2c1b18a3dff3554e0b619)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>

Michael Niedermayer authored on 2018/07/11 09:17:56
Showing 1 changed files
... ...
@@ -3299,25 +3299,22 @@ static void mov_estimate_video_delay(MOVContext *c, AVStream* st) {
3299 3299
     int ctts_sample = 0;
3300 3300
     int64_t pts_buf[MAX_REORDER_DELAY + 1]; // Circular buffer to sort pts.
3301 3301
     int buf_start = 0;
3302
-    int buf_size = 0;
3303 3302
     int j, r, num_swaps;
3304 3303
 
3304
+    for (j = 0; j < MAX_REORDER_DELAY + 1; j++)
3305
+        pts_buf[j] = INT64_MIN;
3306
+
3305 3307
     if (st->codecpar->video_delay <= 0 && msc->ctts_data &&
3306 3308
         st->codecpar->codec_id == AV_CODEC_ID_H264) {
3307 3309
         st->codecpar->video_delay = 0;
3308 3310
         for(ind = 0; ind < st->nb_index_entries && ctts_ind < msc->ctts_count; ++ind) {
3309
-            if (buf_size == (MAX_REORDER_DELAY + 1)) {
3310
-                // If circular buffer is full, then move the first element forward.
3311
-                buf_start = (buf_start + 1);
3312
-                if (buf_start == MAX_REORDER_DELAY + 1)
3313
-                    buf_start = 0;
3314
-            } else {
3315
-                ++buf_size;
3316
-            }
3311
+            buf_start = (buf_start + 1);
3312
+            if (buf_start == MAX_REORDER_DELAY + 1)
3313
+                buf_start = 0;
3317 3314
 
3318 3315
             // Point j to the last elem of the buffer and insert the current pts there.
3319 3316
             j = buf_start - 1;
3320
-            if (j < 0) j = buf_size - 1;
3317
+            if (j < 0) j = MAX_REORDER_DELAY;
3321 3318
             pts_buf[j] = st->index_entries[ind].timestamp + msc->ctts_data[ctts_ind].duration;
3322 3319
 
3323 3320
             // The timestamps that are already in the sorted buffer, and are greater than the
... ...
@@ -3329,7 +3326,7 @@ static void mov_estimate_video_delay(MOVContext *c, AVStream* st) {
3329 3329
             num_swaps = 0;
3330 3330
             while (j != buf_start) {
3331 3331
                 r = j - 1;
3332
-                if (r < 0) r = buf_size - 1;
3332
+                if (r < 0) r = MAX_REORDER_DELAY;
3333 3333
                 if (pts_buf[j] < pts_buf[r]) {
3334 3334
                     FFSWAP(int64_t, pts_buf[j], pts_buf[r]);
3335 3335
                     ++num_swaps;