[MPlayer-dev-eng] Make sync-to-vblank optional for vo xv.

Christian Birchinger joker at netswarm.net
Sat Jun 9 21:05:44 CEST 2007


Hello

I run a setup where TV-Out is a secondary head (DISPLAY :0.1).
When playing a video on that TV-Out head cpu uses 100% CPU and
even starts droping frames.

The reason for this is the XV_SYNC_TO_VBLANK option which
mplayer "hard" enables on startup with vo xv.

The solution for this is of course making it optional.
I've tried 4 different styles but i don't really know, which one
is the prefered way. It's all more a question of policy and
style than actual programming (which i suck at).

The 4 different approaches are attached to this mail but heres
a small overview of the different behaviour:


1) Uses the already present -vsync option to set the attribut.
Not using that option and unfortunately also the -novsync make
mplayer not touch the attribute and keep the users previously
set value.

2) -vsync enables it and -novsync (global default) disables it.
This is probably not wanted because it makes disabling the
attribute the default.

3) Adds -vo xv:novsync.
This keeps the the current behaviour of "hard" enabling the
attribute but offers a option to skip the enabling.
"novsync" is maybe not the right name because it would be more
like "dont-enable-vsync".

4) The most complete method (implemented like xv:ck and xv:ck-method)
The syntax is -vo xv:vsync=on|off|cur
on  = enable vsync (current behaviour)
off = disable vsync
cur = don't touch the attribute (also the default when nothing set)


So it's all a question of how mplayer should behave by default.

I personaly would prefer if the default is not messing with the
attribute at all since it's a global attribute for the XV adapter
and not some player internal variable like vsync in vesa or fbdev.

Greetings
Christian
-------------- next part --------------
Index: libvo/vo_xvmc.c
===================================================================
--- libvo/vo_xvmc.c	(revision 23524)
+++ libvo/vo_xvmc.c	(working copy)
@@ -626,7 +626,8 @@
      return -1; // bail out, colorkey setup failed
    }
 
-   vo_xv_enable_vsync();//it won't break anything
+   if (vo_vsync)
+     vo_xv_enable_vsync();//it won't break anything
 
 //taken from vo_xv
    image_height = height;
Index: libvo/vo_xv.c
===================================================================
--- libvo/vo_xv.c	(revision 23524)
+++ libvo/vo_xv.c	(working copy)
@@ -868,7 +868,8 @@
     {
       return -1; // bail out, colorkey setup failed
     }
-    vo_xv_enable_vsync();
+    if (vo_vsync)
+        vo_xv_enable_vsync();
     vo_xv_get_max_img_dim( &max_width, &max_height );
 
     fo = XvListImageFormats(mDisplay, xv_port, (int *) &formats);
-------------- next part --------------
Index: libvo/x11_common.c
===================================================================
--- libvo/x11_common.c	(revision 23527)
+++ libvo/x11_common.c	(working copy)
@@ -2292,7 +2292,10 @@
   Atom xv_atom = xv_intern_atom_if_exists("XV_SYNC_TO_VBLANK");
   if (xv_atom == None)
     return -1;
-  return XvSetPortAttribute(mDisplay, xv_port, xv_atom, 1) == Success;
+  if (vo_vsync)
+    return XvSetPortAttribute(mDisplay, xv_port, xv_atom, 1) == Success;
+  else
+    return XvSetPortAttribute(mDisplay, xv_port, xv_atom, 0) == Success;
 }
 
 /**
-------------- next part --------------
Index: libvo/vo_xvmc.c
===================================================================
--- libvo/vo_xvmc.c	(revision 23527)
+++ libvo/vo_xvmc.c	(working copy)
@@ -59,6 +59,7 @@
 static int xv_port_request = 0;
 static int bob_deinterlace;
 static int top_field_first;
+static int novsync_arg = 0;
 
 static int image_width,image_height;
 static int image_format;
@@ -377,6 +378,7 @@
   {  "sleep",     OPT_ARG_BOOL, &use_sleep,       NULL },
   {  "queue",     OPT_ARG_BOOL, &use_queue,       NULL },
   {  "bobdeint",  OPT_ARG_BOOL, &bob_deinterlace, NULL },
+  {  "novsync",   OPT_ARG_BOOL, &novsync_arg,     NULL },
   {  NULL }
 };
 
@@ -625,9 +627,10 @@
    {
      return -1; // bail out, colorkey setup failed
    }
+   
+   if (novsync_arg != 1)
+       vo_xv_enable_vsync();//it won't break anything
 
-   vo_xv_enable_vsync();//it won't break anything
-
 //taken from vo_xv
    image_height = height;
    image_width = width;
Index: libvo/vo_xv.c
===================================================================
--- libvo/vo_xv.c	(revision 23527)
+++ libvo/vo_xv.c	(working copy)
@@ -759,16 +759,18 @@
 {
     XvPortID xv_p;
     int busy_ports = 0;
+    int novsync_arg = 0;
     unsigned int i;
     strarg_t ck_src_arg = { 0, NULL };
     strarg_t ck_method_arg = { 0, NULL };
 
     opt_t subopts[] =
     {  
-      /* name         arg type     arg var         test */
-      {  "port",      OPT_ARG_INT, &xv_port,       (opt_test_f)int_pos },
-      {  "ck",        OPT_ARG_STR, &ck_src_arg,    xv_test_ck },
-      {  "ck-method", OPT_ARG_STR, &ck_method_arg, xv_test_ckm },
+      /* name         arg type      arg var         test */
+      {  "port",      OPT_ARG_INT,  &xv_port,       (opt_test_f)int_pos },
+      {  "ck",        OPT_ARG_STR,  &ck_src_arg,    xv_test_ck },
+      {  "ck-method", OPT_ARG_STR,  &ck_method_arg, xv_test_ckm },
+      {  "novsync",   OPT_ARG_BOOL, &novsync_arg,   NULL },
       {  NULL }
     };
 
@@ -868,7 +870,8 @@
     {
       return -1; // bail out, colorkey setup failed
     }
-    vo_xv_enable_vsync();
+    if (novsync_arg != 1)
+        vo_xv_enable_vsync();
     vo_xv_get_max_img_dim( &max_width, &max_height );
 
     fo = XvListImageFormats(mDisplay, xv_port, (int *) &formats);
-------------- next part --------------
Index: libvo/x11_common.c
===================================================================
--- libvo/x11_common.c	(revision 23528)
+++ libvo/x11_common.c	(working copy)
@@ -2287,12 +2287,23 @@
  * \brief Try to enable vsync for xv.
  * \return Returns -1 if not available, 0 on failure and 1 on success.
  */
-int vo_xv_enable_vsync(void)
+int vo_xv_enable_vsync(char const * ck_vsync_str)
 {
+  if ( ck_vsync_str == NULL || strncmp( ck_vsync_str, "cur", 3 ) == 0 )
+    return 0;
+
   Atom xv_atom = xv_intern_atom_if_exists("XV_SYNC_TO_VBLANK");
   if (xv_atom == None)
     return -1;
-  return XvSetPortAttribute(mDisplay, xv_port, xv_atom, 1) == Success;
+
+  if ( strncmp( ck_vsync_str, "on", 2 ) == 0 )
+  {
+    return XvSetPortAttribute(mDisplay, xv_port, xv_atom, 1) == Success;
+  }
+  else 
+  {
+    return XvSetPortAttribute(mDisplay, xv_port, xv_atom, 0) == Success;
+  }
 }
 
 /**
@@ -2571,7 +2582,20 @@
 
   return 0;
 }
+/** \brief Tests if a valid arguments for the vsync suboption was given. */
+int xv_test_vsync( void * arg )
+{
+  strarg_t * strarg = (strarg_t *)arg;
 
+  if ( strargcmp( strarg, "off" ) == 0 ||
+       strargcmp( strarg, "on" )  == 0 ||
+       strargcmp( strarg, "cur" ) == 0    )
+  {
+    return 1;
+  }
+   
+  return 0;
+}
 /**
  * \brief Modify the colorkey_handling var according to str
  *
Index: libvo/x11_common.h
===================================================================
--- libvo/x11_common.h	(revision 23528)
+++ libvo/x11_common.h	(working copy)
@@ -74,7 +74,7 @@
 extern int vo_xv_set_eq(uint32_t xv_port, char * name, int value);
 extern int vo_xv_get_eq(uint32_t xv_port, char * name, int *value);
 
-extern int vo_xv_enable_vsync(void);
+extern int vo_xv_enable_vsync(char const * ck_vsync_str);
 
 extern void vo_xv_get_max_img_dim( uint32_t * width, uint32_t * height );
 
@@ -103,6 +103,7 @@
 /*** test functions for common suboptions ***/
 int xv_test_ck( void * arg );
 int xv_test_ckm( void * arg );
+int xv_test_vsync( void * arg );
 #endif
 
 #ifdef HAVE_NEW_GUI
Index: libvo/vo_xvmc.c
===================================================================
--- libvo/vo_xvmc.c	(revision 23528)
+++ libvo/vo_xvmc.c	(working copy)
@@ -59,6 +59,7 @@
 static int xv_port_request = 0;
 static int bob_deinterlace;
 static int top_field_first;
+static strarg_t ck_vsync_arg = { 0, NULL }; 
 
 static int image_width,image_height;
 static int image_format;
@@ -373,6 +374,7 @@
   {  "port",      OPT_ARG_INT,  &xv_port_request, (opt_test_f)int_pos },
   {  "ck",        OPT_ARG_STR,  &ck_src_arg,      xv_test_ck },
   {  "ck-method", OPT_ARG_STR,  &ck_method_arg,   xv_test_ckm },
+  {  "vsync",     OPT_ARG_STR,  &ck_vsync_arg,    xv_test_vsync },
   {  "benchmark", OPT_ARG_BOOL, &benchmark,       NULL },
   {  "sleep",     OPT_ARG_BOOL, &use_sleep,       NULL },
   {  "queue",     OPT_ARG_BOOL, &use_queue,       NULL },
@@ -625,9 +627,9 @@
    {
      return -1; // bail out, colorkey setup failed
    }
+   
+   vo_xv_enable_vsync( ck_vsync_arg.str );//it won't break anything
 
-   vo_xv_enable_vsync();//it won't break anything
-
 //taken from vo_xv
    image_height = height;
    image_width = width;
Index: libvo/vo_xv.c
===================================================================
--- libvo/vo_xv.c	(revision 23528)
+++ libvo/vo_xv.c	(working copy)
@@ -762,13 +762,15 @@
     unsigned int i;
     strarg_t ck_src_arg = { 0, NULL };
     strarg_t ck_method_arg = { 0, NULL };
+    strarg_t ck_vsync_arg = { 0, NULL };
 
     opt_t subopts[] =
     {  
-      /* name         arg type     arg var         test */
-      {  "port",      OPT_ARG_INT, &xv_port,       (opt_test_f)int_pos },
-      {  "ck",        OPT_ARG_STR, &ck_src_arg,    xv_test_ck },
-      {  "ck-method", OPT_ARG_STR, &ck_method_arg, xv_test_ckm },
+      /* name         arg type      arg var         test */
+      {  "port",      OPT_ARG_INT,  &xv_port,       (opt_test_f)int_pos },
+      {  "ck",        OPT_ARG_STR,  &ck_src_arg,    xv_test_ck },
+      {  "ck-method", OPT_ARG_STR,  &ck_method_arg, xv_test_ckm },
+      {  "vsync",     OPT_ARG_STR,  &ck_vsync_arg,  xv_test_vsync },
       {  NULL }
     };
 
@@ -868,7 +870,7 @@
     {
       return -1; // bail out, colorkey setup failed
     }
-    vo_xv_enable_vsync();
+    vo_xv_enable_vsync( ck_vsync_arg.str );
     vo_xv_get_max_img_dim( &max_width, &max_height );
 
     fo = XvListImageFormats(mDisplay, xv_port, (int *) &formats);


More information about the MPlayer-dev-eng mailing list