diff mbox series

[FFmpeg-devel,v2] libavformat: Account for negative position differences in ff_configure_buffers_for_index

Message ID 20230324215037.48396-1-martin@martin.st
State New
Headers show
Series [FFmpeg-devel,v2] libavformat: Account for negative position differences in ff_configure_buffers_for_index | expand

Checks

Context Check Description
andriy/make_fate_x86 success Make fate finished
andriy/make_x86 warning New warnings during build

Commit Message

Martin Storsjö March 24, 2023, 9:50 p.m. UTC
When scanning through the index, account for the fact that the
compared samples may be located in an unexpected order in the file;
this function is mainly interested in the absolute difference between
file locations.

Signed-off-by: Martin Storsjö <martin@martin.st>
---
v2: Use FFABS instead of llabs, avoid expanding the abs() operation
twice in the FFMAX arguments.
---
 libavformat/seek.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

James Almer March 24, 2023, 9:54 p.m. UTC | #1
On 3/24/2023 6:50 PM, Martin Storsjö wrote:
> When scanning through the index, account for the fact that the
> compared samples may be located in an unexpected order in the file;
> this function is mainly interested in the absolute difference between
> file locations.
> 
> Signed-off-by: Martin Storsjö <martin@martin.st>
> ---
> v2: Use FFABS instead of llabs, avoid expanding the abs() operation
> twice in the FFMAX arguments.
> ---
>   libavformat/seek.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/seek.c b/libavformat/seek.c
> index 818549dfef..23fbcb8d84 100644
> --- a/libavformat/seek.c
> +++ b/libavformat/seek.c
> @@ -210,7 +210,8 @@ void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance)
>                       int64_t e2_pts = av_rescale_q(e2->timestamp, st2->time_base, AV_TIME_BASE_Q);
>                       if (e2_pts < e1_pts || e2_pts - (uint64_t)e1_pts < time_tolerance)
>                           continue;
> -                    pos_delta = FFMAX(pos_delta, e1->pos - e2->pos);
> +                    int64_t cur_delta = FFABS(e1->pos - e2->pos);

This is going to give a warning about mixed declarations and code. 
Declare it alongside e2_pts above.

> +                    pos_delta = FFMAX(pos_delta, cur_delta);
>                       break;
>                   }
>               }
diff mbox series

Patch

diff --git a/libavformat/seek.c b/libavformat/seek.c
index 818549dfef..23fbcb8d84 100644
--- a/libavformat/seek.c
+++ b/libavformat/seek.c
@@ -210,7 +210,8 @@  void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance)
                     int64_t e2_pts = av_rescale_q(e2->timestamp, st2->time_base, AV_TIME_BASE_Q);
                     if (e2_pts < e1_pts || e2_pts - (uint64_t)e1_pts < time_tolerance)
                         continue;
-                    pos_delta = FFMAX(pos_delta, e1->pos - e2->pos);
+                    int64_t cur_delta = FFABS(e1->pos - e2->pos);
+                    pos_delta = FFMAX(pos_delta, cur_delta);
                     break;
                 }
             }