[MPlayer-dev-eng] [PATCH] round delay properly
Oskar Liljeblad
oskar at osk.mine.nu
Thu Dec 26 11:54:28 CET 2002
On Thursday, December 26, 2002 at 00:35, Arpi wrote:
Hi Arpi!
> > This patch makes subtitle and A-V delays display correctly rounded
> > ("3800 ms" instead of "3799 ms" etc).
> >
> > (I submitted this some time ago, but it was not applied. This
> > new patch doesn't define _BSD_SOURCE or _ISOC99_SOURCE, only
>
> do we really need all this mess for this so-easy function lround()?
> why don't we do the rounding manually, like (x<0)?(x-1):x or so.
>
> just remember the case of lrint() in ffmpeg, it made lots of portability
> issues for a month...
You're right, using this instead of lround will work just fine:
#define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
(In any case, when going from -70200 ms to -70300 ms you'll end up
with -70299 ms because of floating-point number precision... It
doesn't matter if you're using ROUND of lround. But who cares :)
See the attached patch.
Oskar (oskar at osk.mine.nu)
-------------- next part --------------
diff -u -p mplayer.c.v0 mplayer.c
--- mplayer.c.v0 2002-12-26 11:34:28.000000000 +0100
+++ mplayer.c 2002-12-26 11:52:41.000000000 +0100
@@ -80,6 +80,7 @@ int identify=0;
static int quiet=0;
#define ABS(x) (((x)>=0)?(x):(-(x)))
+#define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
#ifdef HAVE_RTC
#include <linux/rtc.h>
@@ -2925,7 +2926,7 @@ if(rel_seek_secs || abs_seek_pos){
osd_show_vobsub_changed--;
} else
if (osd_show_sub_delay) {
- sprintf(osd_text_tmp, "Sub delay: %d ms",(int)(sub_delay*1000));
+ sprintf(osd_text_tmp, "Sub delay: %d ms %.10f", ROUND(sub_delay*1000));
osd_show_sub_delay--;
} else
if (osd_show_sub_pos) {
@@ -2939,7 +2940,7 @@ if(rel_seek_secs || abs_seek_pos){
osd_show_sub_alignment--;
} else
if (osd_show_av_delay) {
- sprintf(osd_text_tmp, "A-V delay: %d ms",(int)(audio_delay*1000));
+ sprintf(osd_text_tmp, "A-V delay: %d ms", ROUND(audio_delay*1000));
osd_show_av_delay--;
} else if(osd_level>=2)
sprintf(osd_text_tmp,"%c %02d:%02d:%02d",osd_function,pts/3600,(pts/60)%60,pts%60);
More information about the MPlayer-dev-eng
mailing list