[FFmpeg-devel,2/4] bavformat/mov: Eliminate variable buf_size from mov_estimate_video_delay()

Submitted by Michael Niedermayer on July 11, 2018, 12:17 a.m.

Details

Message ID 20180711001758.27132-2-michael@niedermayer.cc
State Accepted
Commit 3ce4034308a3726395a2c1b18a3dff3554e0b619
Headers show

Commit Message

Michael Niedermayer July 11, 2018, 12:17 a.m.
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavformat/mov.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

Comments

Sasi Inguva July 11, 2018, 6:13 p.m.
LGTM. thanks

On Tue, Jul 10, 2018 at 5:18 PM Michael Niedermayer <michael@niedermayer.cc>
wrote:

> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavformat/mov.c | 19 ++++++++-----------
>  1 file changed, 8 insertions(+), 11 deletions(-)
>
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index aabf06de12..67b3e11eb9 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -3301,25 +3301,22 @@ static void mov_estimate_video_delay(MOVContext
> *c, AVStream* st) {
>      int ctts_sample = 0;
>      int64_t pts_buf[MAX_REORDER_DELAY + 1]; // Circular buffer to sort
> pts.
>      int buf_start = 0;
> -    int buf_size = 0;
>      int j, r, num_swaps;
>
> +    for (j = 0; j < MAX_REORDER_DELAY + 1; j++)
> +        pts_buf[j] = INT64_MIN;
> +
>      if (st->codecpar->video_delay <= 0 && msc->ctts_data &&
>          st->codecpar->codec_id == AV_CODEC_ID_H264) {
>          st->codecpar->video_delay = 0;
>          for(ind = 0; ind < st->nb_index_entries && ctts_ind <
> msc->ctts_count; ++ind) {
> -            if (buf_size == (MAX_REORDER_DELAY + 1)) {
> -                // If circular buffer is full, then move the first
> element forward.
> -                buf_start = (buf_start + 1);
> -                if (buf_start == MAX_REORDER_DELAY + 1)
> -                    buf_start = 0;
> -            } else {
> -                ++buf_size;
> -            }
> +            buf_start = (buf_start + 1);
> +            if (buf_start == MAX_REORDER_DELAY + 1)
> +                buf_start = 0;
>
>              // Point j to the last elem of the buffer and insert the
> current pts there.
>              j = buf_start - 1;
> -            if (j < 0) j = buf_size - 1;
> +            if (j < 0) j = MAX_REORDER_DELAY;
>              pts_buf[j] = st->index_entries[ind].timestamp +
> msc->ctts_data[ctts_ind].duration;
>
>              // The timestamps that are already in the sorted buffer, and
> are greater than the
> @@ -3331,7 +3328,7 @@ static void mov_estimate_video_delay(MOVContext *c,
> AVStream* st) {
>              num_swaps = 0;
>              while (j != buf_start) {
>                  r = j - 1;
> -                if (r < 0) r = buf_size - 1;
> +                if (r < 0) r = MAX_REORDER_DELAY;
>                  if (pts_buf[j] < pts_buf[r]) {
>                      FFSWAP(int64_t, pts_buf[j], pts_buf[r]);
>                      ++num_swaps;
> --
> 2.18.0
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
Michael Niedermayer July 11, 2018, 6:33 p.m.
On Wed, Jul 11, 2018 at 11:13:43AM -0700, Sasi Inguva wrote:
> LGTM. thanks

will apply

thx

[...]

Patch hide | download patch | download mbox

diff --git a/libavformat/mov.c b/libavformat/mov.c
index aabf06de12..67b3e11eb9 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3301,25 +3301,22 @@  static void mov_estimate_video_delay(MOVContext *c, AVStream* st) {
     int ctts_sample = 0;
     int64_t pts_buf[MAX_REORDER_DELAY + 1]; // Circular buffer to sort pts.
     int buf_start = 0;
-    int buf_size = 0;
     int j, r, num_swaps;
 
+    for (j = 0; j < MAX_REORDER_DELAY + 1; j++)
+        pts_buf[j] = INT64_MIN;
+
     if (st->codecpar->video_delay <= 0 && msc->ctts_data &&
         st->codecpar->codec_id == AV_CODEC_ID_H264) {
         st->codecpar->video_delay = 0;
         for(ind = 0; ind < st->nb_index_entries && ctts_ind < msc->ctts_count; ++ind) {
-            if (buf_size == (MAX_REORDER_DELAY + 1)) {
-                // If circular buffer is full, then move the first element forward.
-                buf_start = (buf_start + 1);
-                if (buf_start == MAX_REORDER_DELAY + 1)
-                    buf_start = 0;
-            } else {
-                ++buf_size;
-            }
+            buf_start = (buf_start + 1);
+            if (buf_start == MAX_REORDER_DELAY + 1)
+                buf_start = 0;
 
             // Point j to the last elem of the buffer and insert the current pts there.
             j = buf_start - 1;
-            if (j < 0) j = buf_size - 1;
+            if (j < 0) j = MAX_REORDER_DELAY;
             pts_buf[j] = st->index_entries[ind].timestamp + msc->ctts_data[ctts_ind].duration;
 
             // The timestamps that are already in the sorted buffer, and are greater than the
@@ -3331,7 +3328,7 @@  static void mov_estimate_video_delay(MOVContext *c, AVStream* st) {
             num_swaps = 0;
             while (j != buf_start) {
                 r = j - 1;
-                if (r < 0) r = buf_size - 1;
+                if (r < 0) r = MAX_REORDER_DELAY;
                 if (pts_buf[j] < pts_buf[r]) {
                     FFSWAP(int64_t, pts_buf[j], pts_buf[r]);
                     ++num_swaps;