[MPlayer-dev-eng] [PATCH] xv-options (brightness etc)

Pásztor Szilárd silicon at falcon.sch.bme.hu
Fri Jan 18 00:25:15 CET 2002


Hi,

until libvo2 is done... :)

  Here is a patch against the current CVS version (as of 17. jan. 23:53),
adding support to vo_xv for adjusting brightness/contrast/hue/saturation.
Since it's done by the XV extension its codec-independent, and imo very
useful with ffmpeg codecs or any other than original divx3/divx4.

  The patch fits into mplayer's current architecture. XV is not used where
the codec supports these settings but if it doesnt, adjusting talks to XV
and it looks exactly the same via osd. The only difference is that the osd
layer output is also affected (clock etc) but it's inevitable with XV.

To enable this thing, I had to make a new entry into LIBVO_EXTERN called
set_colors and put it into every other vo_*.c too, as an empty function.
The main thing is done in vo_xv.c, and mplayer.c had to be changed to call
the set_colors() function if set_video_colors returns with 0 (that is, codec
has no support). Upon XV init, the xserver is queried about the attributes
and the ranges and these attributes are handled accordingly later on. If
these attributes (or some of them) are unavailable, set_colors() also
returns 0 and has no effect. I hope it makes the patch usable for any video
card.

Tried to make the code readable and commented where necessary.

surmoka

                ------------------------------------------------
                |  The sooner you die the longer you're dead.  |
                ------------------------------------------------
-------------- next part --------------
diff -Naur j/main/libvo/video_out.h main/libvo/video_out.h
--- j/main/libvo/video_out.h	Thu Nov 29 18:31:58 2001
+++ main/libvo/video_out.h	Thu Jan 17 23:39:50 2002
@@ -89,6 +89,11 @@
         void (*check_events)(void);
 
         /*
+         * Allows driver to set picture options, like brightness etc.
+         */
+        int (*set_colors)(int id, int value);
+
+        /*
          * Closes driver. Should restore the original state of the system.
          */
         void (*uninit)(void);
@@ -119,3 +124,4 @@
 
 extern char *vo_subdevice;
 
+extern int vo_lastkey;
diff -Naur j/main/libvo/video_out_internal.h main/libvo/video_out_internal.h
--- j/main/libvo/video_out_internal.h	Mon Aug 13 13:33:34 2001
+++ main/libvo/video_out_internal.h	Thu Jan 17 23:39:50 2002
@@ -28,6 +28,7 @@
 static void draw_osd(void);
 static void flip_page(void);
 static void check_events(void);
+static int set_colors(int id, int value);
 static void uninit(void);
 static uint32_t query_format(uint32_t format);
 
@@ -41,6 +42,7 @@
      	draw_osd,\
 	flip_page,\
 	check_events,\
+	set_colors,\
 	uninit,\
 };
 
diff -Naur j/main/libvo/vo_3dfx.c main/libvo/vo_3dfx.c
--- j/main/libvo/vo_3dfx.c	Thu Sep 27 14:22:27 2001
+++ main/libvo/vo_3dfx.c	Thu Jan 17 23:39:50 2002
@@ -484,6 +484,9 @@
 }
 
 
+static int set_colors(int id, int value)
+{ return 0; }
+
 static void check_events(void)
 {
 }
diff -Naur j/main/libvo/vo_aa.c main/libvo/vo_aa.c
--- j/main/libvo/vo_aa.c	Fri Jan 11 23:17:54 2002
+++ main/libvo/vo_aa.c	Thu Jan 17 23:39:50 2002
@@ -497,6 +497,9 @@
       show_image(convertbuf);
 }
 
+static int set_colors(int id, int value)
+{ return 0; }
+
 static void 
 check_events(void) {
     /* 
diff -Naur j/main/libvo/vo_dga.c main/libvo/vo_dga.c
--- j/main/libvo/vo_dga.c	Tue Jan  8 21:58:53 2002
+++ main/libvo/vo_dga.c	Thu Jan 17 23:39:50 2002
@@ -532,6 +532,9 @@
 
 //---------------------------------------------------------
 
+static int set_colors(int id, int value)
+{ return 0; }
+
 static void check_events(void)
 {
   int e=vo_x11_check_events(vo_dga_dpy);
diff -Naur j/main/libvo/vo_directfb.c main/libvo/vo_directfb.c
--- j/main/libvo/vo_directfb.c	Sat Dec 22 01:28:49 2001
+++ main/libvo/vo_directfb.c	Thu Jan 17 23:39:50 2002
@@ -793,6 +793,9 @@
 
 #include "../linux/keycodes.h"
 
+static int set_colors(int id, int value)
+{ return 0; }
+
 static void check_events(void)
 {
 
diff -Naur j/main/libvo/vo_dxr3.c main/libvo/vo_dxr3.c
--- j/main/libvo/vo_dxr3.c	Thu Jan 17 20:24:33 2002
+++ main/libvo/vo_dxr3.c	Thu Jan 17 23:39:50 2002
@@ -566,6 +566,9 @@
 	}
 }
 
+static int set_colors(int id, int value)
+{ return 0; }
+
 static void check_events(void)
 {
 }
diff -Naur j/main/libvo/vo_fbdev.c main/libvo/vo_fbdev.c
--- j/main/libvo/vo_fbdev.c	Thu Jan 17 02:15:31 2002
+++ main/libvo/vo_fbdev.c	Thu Jan 17 23:39:50 2002
@@ -1277,6 +1277,9 @@
 	return 0;
 }
 
+static int set_colors(int id, int value)
+{ return 0; }
+
 static void check_events(void)
 {
 }
diff -Naur j/main/libvo/vo_fsdga.c main/libvo/vo_fsdga.c
--- j/main/libvo/vo_fsdga.c	Tue Nov  6 12:21:08 2001
+++ main/libvo/vo_fsdga.c	Thu Jan 17 23:39:50 2002
@@ -168,6 +168,9 @@
   return 0;
 }
 
+static int set_colors(int id, int value)
+{ return 0; }
+
 static void check_events(void)
 {
     int e=vo_x11_check_events(vo_dga_dpy);
diff -Naur j/main/libvo/vo_ggi.c main/libvo/vo_ggi.c
--- j/main/libvo/vo_ggi.c	Tue Nov  6 12:21:08 2001
+++ main/libvo/vo_ggi.c	Thu Jan 17 23:39:50 2002
@@ -610,6 +610,9 @@
 #include "../linux/keycodes.h"
 extern void mplayer_put_key(int code);
 
+static int set_colors(int id, int value)
+{ return 0; }
+
 static void check_events(void)
 {
     struct timeval tv = {0, 0};
diff -Naur j/main/libvo/vo_gl.c main/libvo/vo_gl.c
--- j/main/libvo/vo_gl.c	Sun Jan  6 22:07:20 2002
+++ main/libvo/vo_gl.c	Thu Jan 17 23:39:50 2002
@@ -303,6 +303,9 @@
 }
 
 
+static int set_colors(int id, int value)
+{ return 0; }
+
 static void check_events(void)
 {
     int e=vo_x11_check_events(mDisplay);
diff -Naur j/main/libvo/vo_gl2.c main/libvo/vo_gl2.c
--- j/main/libvo/vo_gl2.c	Sun Jan  6 22:07:20 2002
+++ main/libvo/vo_gl2.c	Thu Jan 17 23:39:50 2002
@@ -972,6 +972,9 @@
 	return 1;
 }
 
+static int set_colors(int id, int value)
+{ return 0; }
+
 static void check_events(void)
 {
 	 XEvent         Event;
diff -Naur j/main/libvo/vo_md5.c main/libvo/vo_md5.c
--- j/main/libvo/vo_md5.c	Mon Aug 13 13:08:18 2001
+++ main/libvo/vo_md5.c	Thu Jan 17 23:39:50 2002
@@ -99,6 +99,9 @@
 }
 
 
+static int set_colors(int id, int value)
+{ return 0; }
+
 static void check_events(void)
 {
 }
diff -Naur j/main/libvo/vo_mga.c main/libvo/vo_mga.c
--- j/main/libvo/vo_mga.c	Sun Oct 21 23:12:00 2001
+++ main/libvo/vo_mga.c	Thu Jan 17 23:39:50 2002
@@ -142,6 +142,9 @@
 }
 
 
+static int set_colors(int id, int value)
+{ return 0; }
+
 static void check_events(void)
 {
 }
diff -Naur j/main/libvo/vo_mpegpes.c main/libvo/vo_mpegpes.c
--- j/main/libvo/vo_mpegpes.c	Mon Nov  5 22:49:20 2001
+++ main/libvo/vo_mpegpes.c	Thu Jan 17 23:39:50 2002
@@ -485,6 +485,9 @@
 }
 
 
+static int set_colors(int id, int value)
+{ return 0; }
+
 static void check_events(void)
 {
 }
diff -Naur j/main/libvo/vo_null.c main/libvo/vo_null.c
--- j/main/libvo/vo_null.c	Mon Aug 13 13:08:18 2001
+++ main/libvo/vo_null.c	Thu Jan 17 23:39:50 2002
@@ -86,6 +86,9 @@
 }
 
 
+static int set_colors(int id, int value)
+{ return 0; }
+
 static void check_events(void)
 {
 }
diff -Naur j/main/libvo/vo_odivx.c main/libvo/vo_odivx.c
--- j/main/libvo/vo_odivx.c	Mon Aug 13 13:33:34 2001
+++ main/libvo/vo_odivx.c	Thu Jan 17 23:39:50 2002
@@ -263,6 +263,9 @@
 
 
 
+static int set_colors(int id, int value)
+{ return 0; }
+
 static void check_events(void)
 {
 }
diff -Naur j/main/libvo/vo_pgm.c main/libvo/vo_pgm.c
--- j/main/libvo/vo_pgm.c	Mon Aug 13 13:33:34 2001
+++ main/libvo/vo_pgm.c	Thu Jan 17 23:39:50 2002
@@ -131,6 +131,9 @@
 }
 
 
+static int set_colors(int id, int value)
+{ return 0; }
+
 static void check_events(void)
 {
 }
diff -Naur j/main/libvo/vo_png.c main/libvo/vo_png.c
--- j/main/libvo/vo_png.c	Tue Jan  8 21:58:53 2002
+++ main/libvo/vo_png.c	Thu Jan 17 23:39:50 2002
@@ -306,6 +306,9 @@
 }
 
 
+static int set_colors(int id, int value)
+{ return 0; }
+
 static void check_events(void)
 {
 }
diff -Naur j/main/libvo/vo_sdl.c main/libvo/vo_sdl.c
--- j/main/libvo/vo_sdl.c	Wed Dec 19 12:50:05 2001
+++ main/libvo/vo_sdl.c	Thu Jan 17 23:39:50 2002
@@ -1019,6 +1019,9 @@
 #include "../linux/keycodes.h"
 extern void mplayer_put_key(int code);
  
+static int set_colors(int id, int value)
+{ return 0; }
+
 static void check_events (void)
 {
 	struct sdl_priv_s *priv = &sdl_priv;
diff -Naur j/main/libvo/vo_svga.c main/libvo/vo_svga.c
--- j/main/libvo/vo_svga.c	Sun Nov 18 20:47:58 2001
+++ main/libvo/vo_svga.c	Thu Jan 17 23:39:50 2002
@@ -548,6 +548,9 @@
   gl_copyscreen(screen);
 }
 
+static int set_colors(int id, int value)
+{ return 0; }
+
 static void check_events(void) {
 }
 
diff -Naur j/main/libvo/vo_syncfb.c main/libvo/vo_syncfb.c
--- j/main/libvo/vo_syncfb.c	Wed Aug 22 22:14:10 2001
+++ main/libvo/vo_syncfb.c	Thu Jan 17 23:39:50 2002
@@ -444,6 +444,9 @@
 
 }
 
+static int set_colors(int id, int value)
+{ return 0; }
+
 static void check_events(void)
 {
 }
diff -Naur j/main/libvo/vo_tdfxfb.c main/libvo/vo_tdfxfb.c
--- j/main/libvo/vo_tdfxfb.c	Tue Nov  6 12:21:08 2001
+++ main/libvo/vo_tdfxfb.c	Thu Jan 17 23:39:50 2002
@@ -763,6 +763,9 @@
 }
 
 
+static int set_colors(int id, int value)
+{ return 0; }
+
 static void check_events(void)
 {
 }
diff -Naur j/main/libvo/vo_vesa.c main/libvo/vo_vesa.c
--- j/main/libvo/vo_vesa.c	Wed Jan 16 16:22:45 2002
+++ main/libvo/vo_vesa.c	Thu Jan 17 23:39:50 2002
@@ -982,6 +982,9 @@
 }
 
 
+static int set_colors(int id, int value)
+{ return 0; }
+
 static void check_events(void)
 {
     if(verbose > 2)
diff -Naur j/main/libvo/vo_x11.c main/libvo/vo_x11.c
--- j/main/libvo/vo_x11.c	Mon Jan  7 18:33:59 2002
+++ main/libvo/vo_x11.c	Thu Jan 17 23:39:50 2002
@@ -109,6 +109,9 @@
 static uint32_t image_height;
 static uint32_t image_format;
 
+static int set_colors(int id, int value)
+{ return 0; }
+
 static void check_events(){
   vo_x11_check_events(mDisplay);
 }
diff -Naur j/main/libvo/vo_xmga.c main/libvo/vo_xmga.c
--- j/main/libvo/vo_xmga.c	Sun Jan  6 22:07:20 2002
+++ main/libvo/vo_xmga.c	Thu Jan 17 23:39:50 2002
@@ -175,6 +175,9 @@
 
 }
 
+static int set_colors(int id, int value)
+{ return 0; }
+
 static void check_events(void)
 {
     int e=vo_x11_check_events(mDisplay);
diff -Naur j/main/libvo/vo_xv.c main/libvo/vo_xv.c
--- j/main/libvo/vo_xv.c	Sat Jan  5 09:49:46 2002
+++ main/libvo/vo_xv.c	Thu Jan 17 23:39:50 2002
@@ -95,6 +95,48 @@
  static uint32_t               mdwidth,mdheight;
 #endif
 
+// type definition for attributes. The list is expandable (handled dynamically).
+// must place SET_DEFAULTS first to ensure correct value detection at init
+static struct
+{
+    char name[50];
+    int min;
+    int basevalue;
+    int max;
+    Atom atomka;
+} xv_attribs[] =
+{
+    { name: "XV_SET_DEFAULTS" },
+    { name: "XV_BRIGHTNESS"   },
+    { name: "XV_CONTRAST"     },
+    { name: "XV_HUE"          },
+    { name: "XV_SATURATION"   },
+    { name: "" }
+};
+
+static int set_colors(int id, int value)
+{
+    int xvvalue;
+    int range;
+
+// if the requested option is not available, don't trigger OSD
+    if (xv_attribs[id].atomka == None) return 0;
+
+// brightness setting is extreme in XV, calm it down (but keep centered)
+    if (!strcmp(xv_attribs[id].name, "XV_BRIGHTNESS")) value = (value >> 1) + 25;
+
+    range = xv_attribs[id].max - xv_attribs[id].min;
+// calculate centerized+scaled value for XV
+    xvvalue = xv_attribs[id].basevalue + (value - 50) * range / 100.0;
+
+// make the range 'open frame' to avoid overflows.
+// needed for HUE for example, where default isn't the middle value
+    if (xvvalue < xv_attribs[id].min) xvvalue += range;
+    if (xvvalue > xv_attribs[id].max) xvvalue -= range;
+
+    XvSetPortAttribute(mDisplay, xv_port, xv_attribs[id].atomka, xvvalue);
+    return 1;
+}
 
 static void (*draw_alpha_fnc)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride);
 
@@ -131,6 +173,8 @@
  XGCValues xgcv;
  XSetWindowAttributes xswa;
  unsigned long xswamask;
+ XvAttribute *attributes;
+ int howmany, j, notyetset = 0;
 
  aspect_save_orig(width,height);
  aspect_save_prescale(d_width,d_height);
@@ -291,6 +335,30 @@
        }
      #endif
 
+// get available attributes
+     attributes = XvQueryPortAttributes(mDisplay, xv_port, &howmany);
+     for (i = 0; i < howmany && attributes; i++)
+// get the values for each attribute
+        for (j = 0; xv_attribs[j].name[0]; j++)
+        {
+            if (!strcmp(xv_attribs[j].name, attributes[i].name) &&
+                attributes[i].flags & XvSettable)
+            {
+                xv_attribs[j].min = attributes[i].min_value;
+                xv_attribs[j].max = attributes[i].max_value;
+                xv_attribs[j].atomka = XInternAtom(mDisplay, xv_attribs[j].name, True);
+// since we have SET_DEFAULTS first in our list, we can check if it's available
+// then trigger it if it's ok so that the other values are at default upon query
+                if (xv_attribs[0].atomka != None && j > 0 && !notyetset)
+                {
+                    notyetset++;
+                    XvSetPortAttribute(mDisplay, xv_port, xv_attribs[0].atomka, 0);
+                }
+		if (attributes[i].flags & XvGettable)
+                    XvGetPortAttribute(mDisplay, xv_port, xv_attribs[j].atomka, &xv_attribs[j].basevalue);
+            }
+        }
+
      XGetGeometry( mDisplay,mywindow,&mRoot,&drwX,&drwY,&drwWidth,&drwHeight,&drwBorderWidth,&drwDepth );
      drwX=0; drwY=0;
      XTranslateCoordinates( mDisplay,mywindow,mRoot,0,0,&drwcX,&drwcY,&mRoot );
diff -Naur j/main/libvo/vo_xvidix.c main/libvo/vo_xvidix.c
--- j/main/libvo/vo_xvidix.c	Wed Jan 16 16:22:45 2002
+++ main/libvo/vo_xvidix.c	Thu Jan 17 23:42:41 2002
@@ -293,6 +293,9 @@
     return;
 }
 
+static int set_colors(int id, int value)
+{ return 0; }
+
 static void check_events(void)
 {
     const int event = vo_x11_check_events(mDisplay);
diff -Naur j/main/libvo/vo_zr.c main/libvo/vo_zr.c
--- j/main/libvo/vo_zr.c	Thu Jan 17 02:32:29 2002
+++ main/libvo/vo_zr.c	Thu Jan 17 23:48:49 2002
@@ -472,6 +472,9 @@
 #endif
 }
 
+static int set_colors(int id, int value)
+{ return 0; }
+
 static void check_events(void) {
 }
 
diff -Naur j/main/mplayer.c main/mplayer.c
--- j/main/mplayer.c	Thu Jan 17 22:22:11 2002
+++ main/mplayer.c	Thu Jan 17 23:39:50 2002
@@ -2060,7 +2060,8 @@
         } else {
     	    if ( --v_cont < 0 ) v_cont = 0;	    
         }
-	if(set_video_colors(sh_video,"Contrast",v_cont)){
+	if(set_video_colors(sh_video,"Contrast",v_cont)
+		|| video_out->set_colors(2, v_cont)){
 #ifdef USE_OSD
     		if(osd_level){
             	    osd_visible=sh_video->fps; // 1 sec
@@ -2079,7 +2080,8 @@
         } else {
     	    if ( --v_bright < 0 ) v_bright = 0;	    
         }
-	if(set_video_colors(sh_video,"Brightness",v_bright)){
+	if(set_video_colors(sh_video,"Brightness",v_bright)
+		|| video_out->set_colors(1, v_bright)){
 #ifdef USE_OSD
     		if(osd_level){
             	    osd_visible=sh_video->fps; // 1 sec
@@ -2098,7 +2100,8 @@
         } else {
     	    if ( --v_hue < 0 ) v_hue = 0;	    
         }
-	if(set_video_colors(sh_video,"Hue",v_hue)){
+	if(set_video_colors(sh_video,"Hue",v_hue)
+		|| video_out->set_colors(3, v_hue)){
 #ifdef USE_OSD
     		if(osd_level){
             	    osd_visible=sh_video->fps; // 1 sec
@@ -2117,7 +2120,8 @@
         } else {
     	    if ( --v_saturation < 0 ) v_saturation = 0;	    
         }
-	if(set_video_colors(sh_video,"Saturation",v_saturation)){
+	if(set_video_colors(sh_video,"Saturation",v_saturation)
+		|| video_out->set_colors(4, v_saturation)){
 #ifdef USE_OSD
     		if(osd_level){
             	    osd_visible=sh_video->fps; // 1 sec


More information about the MPlayer-dev-eng mailing list