[MPlayer-dev-eng] Fix the bug of -vo xv mode when use switch_ratio
minyuanyang
minyuanyang at 163.com
Sat Sep 6 06:26:35 CEST 2008
If i use switch_ratio switch the ratio in -vo xv mode ,
The screen could not scale normally .
So i change the stretching method , below is the patch
_____________________________________________________________________________
--- vo_xv.c 2008-09-06 12:23:44.000000000 +0800
+++ vo_xv_2.c 2008-09-06 12:21:14.000000000 +0800
@@ -84,6 +84,8 @@
static uint32_t image_width;
static uint32_t image_height;
+static uint32_t vo_dw,vo_dh; // tp:vo_dwidth pre scaled
+static uint32_t window_w,window_h;
static uint32_t image_format;
static int flip_flag;
@@ -92,6 +94,7 @@
static Window mRoot;
static uint32_t drwX, drwY, drwBorderWidth, drwDepth;
static uint32_t max_width = 0, max_height = 0; // zero means: not set
+static int standalone_window=0; //tp: whether window is standalone or specified with -wid
static void (*draw_alpha_fnc) (int x0, int y0, int w, int h,
unsigned char *src, unsigned char *srca,
@@ -212,14 +215,14 @@
xv_format = 0;
for (i = 0; i < formats; i++)
- {
+ {
mp_msg(MSGT_VO, MSGL_V,
"Xvideo image format: 0x%x (%4.4s) %s\n", fo[i].id,
(char *) &fo[i].id,
(fo[i].format == XvPacked) ? "packed" : "planar");
if (fo[i].id == format)
xv_format = fo[i].id;
- }
+ }
if (!xv_format)
return -1;
}
@@ -277,32 +280,50 @@
{
vo_window = WinID ? ((Window) WinID) : mRootWin;
if (WinID)
- {
- XUnmapWindow(mDisplay, vo_window);
- XChangeWindowAttributes(mDisplay, vo_window, xswamask,
- &xswa);
- vo_x11_selectinput_witherr(mDisplay, vo_window,
- StructureNotifyMask |
- KeyPressMask |
- PropertyChangeMask |
- PointerMotionMask |
- ButtonPressMask |
- ButtonReleaseMask |
- ExposureMask);
- XMapWindow(mDisplay, vo_window);
- XGetGeometry(mDisplay, vo_window, &mRoot,
- &drwX, &drwY, &vo_dwidth, &vo_dheight,
- &drwBorderWidth, &drwDepth);
- if (vo_dwidth <= 0) vo_dwidth = d_width;
- if (vo_dheight <= 0) vo_dheight = d_height;
- aspect_save_prescale(vo_dwidth, vo_dheight);
- }
+ {
+ XUnmapWindow(mDisplay, vo_window);
+ XChangeWindowAttributes(mDisplay, vo_window, xswamask,
+ &xswa);
+ vo_x11_selectinput_witherr(mDisplay, vo_window,
+ StructureNotifyMask |
+ KeyPressMask |
+ PropertyChangeMask |
+ PointerMotionMask |
+ ButtonPressMask |
+ ButtonReleaseMask |
+ ExposureMask);
+ XMapWindow(mDisplay, vo_window);
+ if (standalone_window)
+ {
+ XGetGeometry(mDisplay, vo_window, &mRoot,
+ &drwX, &drwY, &vo_dwidth, &vo_dheight,
+ &drwBorderWidth, &drwDepth);
+ if (vo_dwidth <= 0) vo_dwidth = d_width;
+ if (vo_dheight <= 0) vo_dheight = d_height;
+ mp_msg(MSGT_VO, MSGL_V, "[xv] dx: %d dy: %d dw: %d dh: %d\n", drwX,
+ drwY, vo_dwidth, vo_dheight);
+ aspect_save_prescale(vo_dwidth, vo_dheight);
+ }else
+ {
+ /* window was specified with option "-wid" */
+ vo_dw=d_width; /*save d_width and d_height for check_events will change it*/
+ vo_dh=d_height;
+ int w_x,w_y;
+ XGetGeometry(mDisplay, vo_window, &mRoot, &w_x, &w_y, &window_w, &window_h, &drwBorderWidth, &drwDepth);
+ float asp=(float)vo_dw/vo_dh;
+ vo_dwidth = window_h*asp>=window_w ? window_w : window_h*asp;
+ vo_dheight = vo_dwidth==window_w ? vo_dwidth/asp : window_h;
+ drwX = (window_w - vo_dwidth) / 2;
+ drwY = (window_h - vo_dheight) / 2;
+ }
+ }
} else
- {
+ {
+ standalone_window=1;
vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, d_width, d_height,
flags, CopyFromParent, "xv", title);
XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa);
- }
+ }
if (vo_gc != None)
XFreeGC(mDisplay, vo_gc);
@@ -356,9 +377,14 @@
set_gamma_correction();
#endif
- aspect(&vo_dwidth, &vo_dheight, A_NOZOOM);
- if ((flags & VOFLAG_FULLSCREEN) && WinID <= 0) vo_fs = 1;
- calc_drwXY(&drwX, &drwY);
+
+ if ((flags & VOFLAG_FULLSCREEN) && WinID <= 0)
+ {
+ //only if switch to fullscreen mode
+ aspect(&vo_dwidth, &vo_dheight, A_NOZOOM);
+ vo_fs = 1;
+ calc_drwXY(&drwX, &drwY);
+ }
panscan_calc();
@@ -487,24 +513,35 @@
static void check_events(void)
{
- int e = vo_x11_check_events(mDisplay);
-
+ int e = vo_x11_check_events(mDisplay); /*unfortunately vo_dwidth and vo_dheight is set to window's width and height in this function!:( */
+ int w_x,w_y;
+
if (e & VO_EVENT_RESIZE)
{
- XGetGeometry(mDisplay, vo_window, &mRoot, &drwX, &drwY, &vo_dwidth,
- &vo_dheight, &drwBorderWidth, &drwDepth);
- mp_msg(MSGT_VO, MSGL_V, "[xv] dx: %d dy: %d dw: %d dh: %d\n", drwX,
- drwY, vo_dwidth, vo_dheight);
-
- calc_drwXY(&drwX, &drwY);
+ XGetGeometry(mDisplay, vo_window, &mRoot, &w_x, &w_y, &window_w, &window_h, &drwBorderWidth, &drwDepth);
+ if (standalone_window)
+ {
+ vo_dwidth=window_w;
+ vo_dheight=window_h;
+ mp_msg(MSGT_VO, MSGL_V, "[xv] dx: %d dy: %d dw: %d dh: %d\n", drwX,
+ drwY, vo_dwidth, vo_dheight);
+ calc_drwXY(&drwX, &drwY);
+ } else
+ {
+ float asp=(float)vo_dw/vo_dh; /*set in function config, the expected size */
+ vo_dwidth = window_h*asp>=window_w ? window_w : window_h*asp;
+ vo_dheight = vo_dwidth==window_w ? vo_dwidth/asp : window_h;
+ drwX = (window_w - vo_dwidth) / 2;
+ drwY = (window_h - vo_dheight) / 2;
+ }
}
if (e & VO_EVENT_EXPOSE || e & VO_EVENT_RESIZE)
{
- vo_xv_draw_colorkey(drwX - (vo_panscan_x >> 1),
- drwY - (vo_panscan_y >> 1),
- vo_dwidth + vo_panscan_x - 1,
- vo_dheight + vo_panscan_y - 1);
+ vo_xv_draw_colorkey(drwX - (vo_panscan_x >> 1),
+ drwY - (vo_panscan_y >> 1),
+ vo_dwidth + vo_panscan_x - 1,
+ vo_dheight + vo_panscan_y - 1);
}
if ((e & VO_EVENT_EXPOSE || e & VO_EVENT_RESIZE) && int_pause)
@@ -675,7 +712,6 @@
}
mpi->flags |= MP_IMGFLAG_DIRECT;
mpi->priv = (void *) current_buf;
-// printf("mga: get_image() SUCCESS -> Direct Rendering ENABLED\n");
return VO_TRUE;
}
return VO_FALSE;
More information about the MPlayer-dev-eng
mailing list