[1/4] lavf: Round the per-stream offset up

Message ID 1415111891-51274-1-git-send-email-martin@martin.st
State New
Headers show

Commit Message

Martin Storsjö Nov. 4, 2014, 2:38 p.m.
This should avoid potential small negative offsets due to rounding
error.
---
 libavformat/mux.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Luca Barbato Nov. 4, 2014, 3:50 p.m. | #1
On 04/11/14 15:38, Martin Storsjö wrote:
> This should avoid potential small negative offsets due to rounding
> error.
> ---
>   libavformat/mux.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/libavformat/mux.c b/libavformat/mux.c
> index 4067c16..e4ba209 100644
> --- a/libavformat/mux.c
> +++ b/libavformat/mux.c
> @@ -327,7 +327,8 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
>               s->offset_timebase = time_base;
>           }
>           if (s->offset)
> -            offset = av_rescale_q(s->offset, s->offset_timebase, time_base);
> +            offset = av_rescale_q_rnd(s->offset, s->offset_timebase, time_base,
> +                                      AV_ROUND_UP);
>
>           if (pkt->dts != AV_NOPTS_VALUE)
>               pkt->dts += offset;
>

Ok, I guess.
Martin Storsjö Nov. 7, 2014, 10:01 a.m. | #2
On Tue, 4 Nov 2014, Martin Storsjö wrote:

> This should avoid potential small negative offsets due to rounding
> error.
> ---
> libavformat/mux.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)

Actually, I'm not so sure if this theoretically can happen, so I'm holding 
off of this one for now.

// Martin

Patch

diff --git a/libavformat/mux.c b/libavformat/mux.c
index 4067c16..e4ba209 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -327,7 +327,8 @@  static int write_packet(AVFormatContext *s, AVPacket *pkt)
             s->offset_timebase = time_base;
         }
         if (s->offset)
-            offset = av_rescale_q(s->offset, s->offset_timebase, time_base);
+            offset = av_rescale_q_rnd(s->offset, s->offset_timebase, time_base,
+                                      AV_ROUND_UP);
 
         if (pkt->dts != AV_NOPTS_VALUE)
             pkt->dts += offset;