[MPlayer-dev-eng] [PATCH] round delay properly

Oskar Liljeblad oskar at osk.mine.nu
Thu Dec 26 02:28:07 CET 2002


On Thursday, December 26, 2002 at 00:35, Arpi wrote:

> 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 could do this:

  sprintf(osd_text_tmp, "Sub delay: %d ms",(int)((sub_delay+0.000001)*1000));

and you wouldn't get "2299 ms" (sub_delay would be 2.3000001 instead of
2.2999999 or something). But this is a hack, and you can't be sure it
is going to work always... (at least I can't be sure :)

Speaking of lrint, you could use that instead of lround... But you'd need

#ifdef HAVE_LRINTF
#define _GNU_SOURCE
#include <math.h>
#else
#define lrint(x) ((int)(x))
#endif

in top of mplayer.c. (_GNU_SOURCE is needed for lrint in GNU libc
math.h...) I guess that'd be a better idea since configure checks
for lrintf. If lrintf is supported I'm sure lrint is too...

See the attached patch! (Note that the #include "config.h" statement
was moved to the top of mplayer.c. This was necessary because if you
include <math.h> before defining _GNU_SOURCE you won't get lrint etc.)

> > _GNU_SOURCE. It shouldn't matter though, since only GNU systems
> > care.)
> 
> is solaris or windows a gnu system?

What I meant was that only GNU libc cares about the _GNU_SOURCE,
_BSD_SOURCE defines etc. AFAIK. So unless you're using GNU libc
you're not on a GNU system. However, lround/lrint is in the ISO99
standard. Many systems NOT supporting this standard does however
supports lround, lrint, and c:o.

Oskar (oskar at osk.mine.nu)
-------------- next part --------------
diff -u -p mplayer.c.v0 mplayer.c
--- mplayer.c.v0	2002-12-26 02:15:06.000000000 +0100
+++ mplayer.c	2002-12-26 02:22:26.000000000 +0100
@@ -1,5 +1,14 @@
 // Movie Player    v0.90   (C) 2000-2002. by A'rpi/ESP-team & `cat AUTHORS`
 
+#include "config.h"
+
+#ifdef HAVE_LRINTF
+#define _GNU_SOURCE
+#include <math.h>
+#else
+#define lrint(x) ((int)(x))
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -19,7 +28,6 @@
 #include <errno.h>
 
 #include "version.h"
-#include "config.h"
 
 #include "mp_msg.h"
 
@@ -2925,7 +2933,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: %ld ms", lrint(sub_delay*1000));
 	  osd_show_sub_delay--;
       } else
       if (osd_show_sub_pos) {
@@ -2939,7 +2947,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: %ld ms", lrint(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