diff options
author | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2008-12-02 18:02:05 +0200 |
---|---|---|
committer | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2008-12-02 18:02:05 +0200 |
commit | e62517ef6a8d23cd78325a9661f8865bd222e004 (patch) | |
tree | 76b7a0af867236c2989ceca1cffcae541ceda9c5 /libvo | |
parent | 62dda60800a902fdaf9b0ec63d8488aaa48c485f (diff) | |
parent | 27b167bb75b908541563bab964e97b06d621f837 (diff) |
Merge svn changes up to r28065
Diffstat (limited to 'libvo')
-rw-r--r-- | libvo/vo_direct3d.c | 338 | ||||
-rw-r--r-- | libvo/vo_macosx.h | 4 | ||||
-rw-r--r-- | libvo/vo_macosx.m | 66 | ||||
-rw-r--r-- | libvo/vo_sdl.c | 79 |
4 files changed, 287 insertions, 200 deletions
diff --git a/libvo/vo_direct3d.c b/libvo/vo_direct3d.c index 3b9ce21968..1958fb45ca 100644 --- a/libvo/vo_direct3d.c +++ b/libvo/vo_direct3d.c @@ -84,10 +84,10 @@ typedef struct { fourcc. This is needed to perform the format query. */ static const struct_fmt_table fmt_table[] = { - {IMGFMT_YV12, MAKEFOURCC('Y','V','1','2')}, - {IMGFMT_I420, MAKEFOURCC('I','4','2','0')}, - {IMGFMT_IYUV, MAKEFOURCC('I','Y','U','V')}, - {IMGFMT_YVU9, MAKEFOURCC('Y','V','U','9')}, + {IMGFMT_YV12, MAKEFOURCC('Y','V','1','2')}, + {IMGFMT_I420, MAKEFOURCC('I','4','2','0')}, + {IMGFMT_IYUV, MAKEFOURCC('I','Y','U','V')}, + {IMGFMT_YVU9, MAKEFOURCC('Y','V','U','9')}, {IMGFMT_YUY2, D3DFMT_YUY2}, {IMGFMT_UYVY, D3DFMT_UYVY}, {IMGFMT_BGR32, D3DFMT_X8R8G8B8}, @@ -98,8 +98,7 @@ static const struct_fmt_table fmt_table[] = { {IMGFMT_BGR8 , D3DFMT_R3G3B2}, //untested }; -#define DISPLAY_FORMAT_TABLE_ENTRIES \ - (sizeof(fmt_table) / sizeof(fmt_table[0])) +#define DISPLAY_FORMAT_TABLE_ENTRIES (sizeof(fmt_table) / sizeof(fmt_table[0])) /**************************************************************************** * * @@ -117,7 +116,7 @@ static const struct_fmt_table fmt_table[] = { static void calc_fs_rect(void) { int scaled_height = 0; - int scaled_width = 0; + int scaled_width = 0; // set default values priv->fs_movie_rect.left = 0; @@ -157,10 +156,10 @@ static void calc_fs_rect(void) priv->fs_movie_rect.bottom = priv->fs_movie_rect.top + scaled_height; } - mp_msg(MSGT_VO,MSGL_V, - "<vo_direct3d>Fullscreen Movie Rect: t: %ld, l: %ld, r: %ld, b:%ld\r\n", - priv->fs_movie_rect.top, priv->fs_movie_rect.left, - priv->fs_movie_rect.right, priv->fs_movie_rect.bottom); + mp_msg(MSGT_VO, MSGL_V, + "<vo_direct3d>Fullscreen Movie Rect: t: %ld, l: %ld, r: %ld, b:%ld\r\n", + priv->fs_movie_rect.top, priv->fs_movie_rect.left, + priv->fs_movie_rect.right, priv->fs_movie_rect.bottom); /* The backbuffer should be cleared before next StretchRect. This is * necessary because our new draw area could be smaller than the @@ -169,55 +168,91 @@ static void calc_fs_rect(void) priv->is_clear_needed = 1; } -/** @brief Destroy D3D Context related to the current window. +/** @brief Destroy D3D Offscreen and Backbuffer surfaces. */ -static void destroy_d3d_context(void) +static void destroy_d3d_surfaces(void) { - mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>destroy_d3d_context called\r\n"); - /* Let's destroy the old (if any) D3D Content */ + mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>destroy_d3d_surfaces called\r\n"); + /* Let's destroy the old (if any) D3D Surfaces */ if (priv->locked_rect.pBits) { IDirect3DSurface9_UnlockRect(priv->d3d_surface); priv->locked_rect.pBits = NULL; } - if (priv->d3d_surface != NULL) { - IDirect3DSurface9_Release (priv->d3d_surface); + if (priv->d3d_surface) { + IDirect3DSurface9_Release(priv->d3d_surface); priv->d3d_surface = NULL; } - if (priv->d3d_device != NULL) { - IDirect3DDevice9_Release (priv->d3d_device); - priv->d3d_device = NULL; + if (priv->d3d_backbuf) { + IDirect3DSurface9_Release(priv->d3d_backbuf); + priv->d3d_backbuf = NULL; } +} - /* The following is not a memory leak. d3d_backbuf is not malloc'ed - * but just holds a pointer to the back buffer. Nobody gets hurt from - * setting it to NULL. - */ - priv->d3d_backbuf = NULL; +/** @brief Create D3D Offscreen and Backbuffer surfaces. + * @return 1 on success, 0 on failure + */ +static int create_d3d_surfaces(void) +{ + mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d><INFO>create_d3d_surfaces called.\n"); + + if (FAILED(IDirect3DDevice9_CreateOffscreenPlainSurface( + priv->d3d_device, priv->src_width, priv->src_height, + priv->movie_src_fmt, D3DPOOL_DEFAULT, &priv->d3d_surface, NULL))) { + mp_msg(MSGT_VO, MSGL_ERR, + "<vo_direct3d><INFO>IDirect3D9_CreateOffscreenPlainSurface Failed.\n"); + return 0; + } + + if (FAILED(IDirect3DDevice9_GetBackBuffer(priv->d3d_device, 0, 0, + D3DBACKBUFFER_TYPE_MONO, + &priv->d3d_backbuf))) { + mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Back Buffer address get failed\n"); + return 0; + } + + return 1; } +/** @brief Fill D3D Presentation parameters + */ +static void fill_d3d_presentparams(D3DPRESENT_PARAMETERS *present_params) +{ + /* Prepare Direct3D initialization parameters. */ + memset(present_params, 0, sizeof(D3DPRESENT_PARAMETERS)); + present_params->Windowed = TRUE; + present_params->SwapEffect = D3DSWAPEFFECT_COPY; + present_params->Flags = D3DPRESENTFLAG_VIDEO; + present_params->hDeviceWindow = vo_w32_window; /* w32_common var */ + present_params->BackBufferWidth = 0; /* Fill up window Width */ + present_params->BackBufferHeight = 0; /* Fill up window Height */ + present_params->MultiSampleType = D3DMULTISAMPLE_NONE; + /* D3DPRESENT_INTERVAL_ONE = vsync */ + present_params->PresentationInterval = D3DPRESENT_INTERVAL_ONE; + present_params->BackBufferFormat = priv->desktop_fmt; + present_params->BackBufferCount = 1; + present_params->EnableAutoDepthStencil = FALSE; +} -/** @brief (Re)Initialize Direct3D. Kill and recreate context. - * The first function called to initialize D3D context. +/** @brief Configure initial Direct3D context. The first + * function called to initialize the D3D context. * @return 1 on success, 0 on failure */ -static int reconfigure_d3d(void) +static int configure_d3d(void) { D3DPRESENT_PARAMETERS present_params; D3DDISPLAYMODE disp_mode; - mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d><INFO>reconfigure_d3d called \n"); - - destroy_d3d_context(); + mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d><INFO>configure_d3d called\n"); /* Get the current desktop display mode, so we can set up a back buffer * of the same format. */ if (FAILED(IDirect3D9_GetAdapterDisplayMode(priv->d3d_handle, D3DADAPTER_DEFAULT, &disp_mode))) { - mp_msg(MSGT_VO,MSGL_ERR, + mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d><INFO>Could not read adapter display mode.\n"); return 0; } @@ -225,52 +260,96 @@ static int reconfigure_d3d(void) /* Write current Desktop's colorspace format in the global storage. */ priv->desktop_fmt = disp_mode.Format; - /* Prepare Direct3D initialization parameters. */ - memset(&present_params, 0, sizeof(D3DPRESENT_PARAMETERS)); - present_params.Windowed = TRUE; - present_params.SwapEffect = D3DSWAPEFFECT_COPY; - present_params.Flags = D3DPRESENTFLAG_VIDEO; - present_params.hDeviceWindow = vo_w32_window; /* w32_common var */ - present_params.BackBufferWidth = 0; /* Fill up window Width */ - present_params.BackBufferHeight = 0; /* Fill up window Height */ - present_params.MultiSampleType = D3DMULTISAMPLE_NONE; - /* D3DPRESENT_INTERVAL_ONE = vsync */ - present_params.PresentationInterval = D3DPRESENT_INTERVAL_ONE; - present_params.BackBufferFormat = priv->desktop_fmt; - present_params.BackBufferCount = 1; - present_params.EnableAutoDepthStencil = FALSE; + fill_d3d_presentparams(&present_params); /* vo_w32_window is w32_common variable. It's a handle to the window. */ if (FAILED(IDirect3D9_CreateDevice(priv->d3d_handle, - D3DADAPTER_DEFAULT, - D3DDEVTYPE_HAL, vo_w32_window, - D3DCREATE_SOFTWARE_VERTEXPROCESSING, - &present_params, &priv->d3d_device))) { - mp_msg(MSGT_VO,MSGL_ERR, + D3DADAPTER_DEFAULT, + D3DDEVTYPE_HAL, vo_w32_window, + D3DCREATE_SOFTWARE_VERTEXPROCESSING, + &present_params, &priv->d3d_device))) { + mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d><INFO>Could not create the D3D device\n"); return 0; } - mp_msg(MSGT_VO,MSGL_V, - "New BackBuffer: Width: %d, Height:%d. VO Dest Width:%d, Height: %d\n", - present_params.BackBufferWidth, present_params.BackBufferHeight, - vo_dwidth, vo_dheight); - - if (FAILED(IDirect3DDevice9_CreateOffscreenPlainSurface( - priv->d3d_device, priv->src_width, priv->src_height, - priv->movie_src_fmt, D3DPOOL_DEFAULT, &priv->d3d_surface, NULL))) { - mp_msg(MSGT_VO,MSGL_ERR, - "<vo_direct3d><INFO>IDirect3D9_CreateOffscreenPlainSurface Failed.\n"); + if (!create_d3d_surfaces()) return 0; + + mp_msg(MSGT_VO, MSGL_V, + "New BackBuffer: Width: %d, Height:%d. VO Dest Width:%d, Height: %d\n", + present_params.BackBufferWidth, present_params.BackBufferHeight, + vo_dwidth, vo_dheight); + + calc_fs_rect(); + + return 1; +} + +/** @brief Reconfigure the whole Direct3D. Called only + * when the video adapter becomes uncooperative. + * @return 1 on success, 0 on failure + */ +static int reconfigure_d3d(void) +{ + mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d><INFO>reconfigure_d3d called.\n"); + + /* Destroy the Offscreen and Backbuffer surfaces */ + destroy_d3d_surfaces(); + + /* Destroy the D3D Device */ + if (priv->d3d_device) { + IDirect3DDevice9_Release(priv->d3d_device); + priv->d3d_device = NULL; } - if (FAILED(IDirect3DDevice9_GetBackBuffer(priv->d3d_device, 0, 0, - D3DBACKBUFFER_TYPE_MONO, - &(priv->d3d_backbuf)))) { - mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>Back Buffer address get failed\n"); + /* Stop the whole Direct3D */ + IDirect3D9_Release(priv->d3d_handle); + + /* Initialize Direct3D from the beginning */ + priv->d3d_handle = Direct3DCreate9(D3D_SDK_VERSION); + if (!priv->d3d_handle) { + mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Unable to initialize Direct3D\n"); + return -1; + } + + /* Configure Direct3D */ + if (!configure_d3d()) + return 0; + + return 1; +} + + +/** @brief Resize Direct3D context on window resize. + * @return 1 on success, 0 on failure + */ +static int resize_d3d(void) +{ + D3DPRESENT_PARAMETERS present_params; + + mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d><INFO>resize_d3d called.\n"); + + destroy_d3d_surfaces(); + + /* Reset the D3D Device with all parameters the same except the new + * width/height. + */ + fill_d3d_presentparams(&present_params); + if (FAILED(IDirect3DDevice9_Reset(priv->d3d_device, &present_params))) { + mp_msg(MSGT_VO, MSGL_ERR, + "<vo_direct3d><INFO>Could not reset the D3D device\n"); return 0; } + if (!create_d3d_surfaces()) + return 0; + + mp_msg(MSGT_VO, MSGL_V, + "New BackBuffer: Width: %d, Height:%d. VO Dest Width:%d, Height: %d\n", + present_params.BackBufferWidth, present_params.BackBufferHeight, + vo_dwidth, vo_dheight); + calc_fs_rect(); return 1; @@ -280,14 +359,19 @@ static int reconfigure_d3d(void) */ static void uninit_d3d(void) { - mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>uninit_d3d called\r\n"); + mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>uninit_d3d called\r\n"); - /* Destroy D3D Context inside the window. */ - destroy_d3d_context(); + destroy_d3d_surfaces(); + + /* Destroy the D3D Device */ + if (priv->d3d_device) { + IDirect3DDevice9_Release(priv->d3d_device); + priv->d3d_device = NULL; + } /* Stop the whole D3D. */ - if (NULL != priv->d3d_handle) { - mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Calling IDirect3D9_Release\r\n"); + if (priv->d3d_handle) { + mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Calling IDirect3D9_Release\r\n"); IDirect3D9_Release(priv->d3d_handle); } } @@ -306,16 +390,16 @@ static uint32_t render_d3d_frame(mp_image_t *mpi) goto skip_upload; if (mpi->flags & MP_IMGFLAG_PLANAR) { /* Copy a planar frame. */ - draw_slice(mpi->planes,mpi->stride,mpi->w,mpi->h,0,0); + draw_slice(mpi->planes, mpi->stride, mpi->w, mpi->h, 0, 0); goto skip_upload; } /* If we're here, then we should lock the rect and copy a packed frame */ if (!priv->locked_rect.pBits) { if (FAILED(IDirect3DSurface9_LockRect(priv->d3d_surface, - &priv->locked_rect, NULL, 0))) { - mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>Surface lock failure\n"); - return VO_ERROR; + &priv->locked_rect, NULL, 0))) { + mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Surface lock failure\n"); + return VO_ERROR; } } @@ -325,19 +409,19 @@ static uint32_t render_d3d_frame(mp_image_t *mpi) skip_upload: /* This unlock is used for both slice_draw path and render_d3d_frame path. */ if (FAILED(IDirect3DSurface9_UnlockRect(priv->d3d_surface))) { - mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Surface unlock failure\n"); + mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Surface unlock failure\n"); return VO_ERROR; } priv->locked_rect.pBits = NULL; if (FAILED(IDirect3DDevice9_BeginScene(priv->d3d_device))) { - mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>BeginScene failed\n"); + mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>BeginScene failed\n"); return VO_ERROR; } if (priv->is_clear_needed) { - IDirect3DDevice9_Clear (priv->d3d_device, 0, NULL, - D3DCLEAR_TARGET, 0, 0, 0); + IDirect3DDevice9_Clear(priv->d3d_device, 0, NULL, + D3DCLEAR_TARGET, 0, 0, 0); priv->is_clear_needed = 0; } @@ -347,14 +431,14 @@ skip_upload: priv->d3d_backbuf, &priv->fs_movie_rect, D3DTEXF_LINEAR))) { - mp_msg(MSGT_VO,MSGL_ERR, + mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Unable to copy the frame to the back buffer\n"); return VO_ERROR; } if (FAILED(IDirect3DDevice9_EndScene(priv->d3d_device))) { - mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>EndScene failed\n"); - return VO_ERROR; + mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>EndScene failed\n"); + return VO_ERROR; } return VO_TRUE; @@ -368,24 +452,22 @@ skip_upload: static int query_format(uint32_t movie_fmt) { int i; - for (i=0; i < DISPLAY_FORMAT_TABLE_ENTRIES; i++) { + for (i = 0; i < DISPLAY_FORMAT_TABLE_ENTRIES; i++) { if (fmt_table[i].mplayer_fmt == movie_fmt) { /* Test conversion from Movie colorspace to * display's target colorspace. */ - if (FAILED(IDirect3D9_CheckDeviceFormatConversion( - priv->d3d_handle, - D3DADAPTER_DEFAULT, - D3DDEVTYPE_HAL, - fmt_table[i].fourcc, - priv->desktop_fmt))) { - mp_msg(MSGT_VO,MSGL_V, - "<vo_direct3d>Rejected image format: %s\n", - vo_format_name(fmt_table[i].mplayer_fmt)); + if (FAILED(IDirect3D9_CheckDeviceFormatConversion(priv->d3d_handle, + D3DADAPTER_DEFAULT, + D3DDEVTYPE_HAL, + fmt_table[i].fourcc, + priv->desktop_fmt))) { + mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Rejected image format: %s\n", + vo_format_name(fmt_table[i].mplayer_fmt)); return 0; } priv->movie_src_fmt = fmt_table[i].fourcc; - mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Accepted image format: %s\n", + mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Accepted image format: %s\n", vo_format_name(fmt_table[i].mplayer_fmt)); return (VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW /*| VFCAP_OSD*/ | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN); @@ -421,9 +503,9 @@ static int preinit(const char *arg) D3DDISPLAYMODE disp_mode; /* Set to zero all global variables. */ - priv = calloc(1, sizeof (struct global_priv)); + priv = calloc(1, sizeof(struct global_priv)); if (!priv) { - mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>Not enough memory\r\n"); + mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Not enough memory\r\n"); return -1; } @@ -434,28 +516,28 @@ static int preinit(const char *arg) priv->d3d_handle = Direct3DCreate9(D3D_SDK_VERSION); if (!priv->d3d_handle) { - mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>Unable to initialize Direct3D\n"); + mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Unable to initialize Direct3D\n"); return -1; } if (FAILED(IDirect3D9_GetAdapterDisplayMode(priv->d3d_handle, D3DADAPTER_DEFAULT, &disp_mode))) { - mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>Could not read display mode\n"); + mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Could not read display mode\n"); return -1; } /* Store in priv->desktop_fmt the user desktop's colorspace. Usually XRGB. */ priv->desktop_fmt = disp_mode.Format; - mp_msg(MSGT_VO,MSGL_V,"disp_mode.Width %d, disp_mode.Height %d\n", + mp_msg(MSGT_VO, MSGL_V, "disp_mode.Width %d, disp_mode.Height %d\n", disp_mode.Width, disp_mode.Height); /* w32_common framework call. Configures window on the screen, gets * fullscreen dimensions and does other useful stuff. */ if (!vo_w32_init()) { - mp_msg(MSGT_VO,MSGL_V,"Unable to configure onscreen window\r\n"); + mp_msg(MSGT_VO, MSGL_V, "Unable to configure onscreen window\r\n"); return -1; } @@ -473,14 +555,14 @@ static int control(uint32_t request, void *data, ...) case VOCTRL_QUERY_FORMAT: return query_format(*(uint32_t*) data); case VOCTRL_GET_IMAGE: /* Direct Rendering. Not implemented yet. */ - mp_msg(MSGT_VO,MSGL_V, + mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Direct Rendering request. Not implemented yet\n"); return VO_NOTIMPL; case VOCTRL_DRAW_IMAGE: return render_d3d_frame(data); case VOCTRL_FULLSCREEN: vo_w32_fullscreen(); - reconfigure_d3d(); + resize_d3d(); return VO_TRUE; case VOCTRL_RESET: return VO_NOTIMPL; @@ -501,13 +583,13 @@ static int control(uint32_t request, void *data, ...) return VO_TRUE; case VOCTRL_BORDER: vo_w32_border(); - reconfigure_d3d(); + resize_d3d(); return VO_TRUE; case VOCTRL_UPDATE_SCREENINFO: w32_update_xinerama_info(); return VO_TRUE; case VOCTRL_SET_PANSCAN: - calc_fs_rect (); + calc_fs_rect(); return VO_TRUE; case VOCTRL_GET_PANSCAN: return VO_TRUE; @@ -531,18 +613,31 @@ static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t format) { - priv->src_width = width; + priv->src_width = width; priv->src_height = height; /* w32_common framework call. Creates window on the screen with * the given coordinates. */ if (!vo_w32_config(d_width, d_height, options)) { - mp_msg(MSGT_VO,MSGL_V,"Unable to create onscreen window\r\n"); + mp_msg(MSGT_VO, MSGL_V, "Unable to create onscreen window\r\n"); return VO_ERROR; } - if (!reconfigure_d3d()) + /* "config" may be called several times, so if this is not the first + * call, we should destroy Direct3D adapter and surfaces before + * calling configure_d3d, which will create them again. + */ + + destroy_d3d_surfaces(); + + /* Destroy the D3D Device */ + if (priv->d3d_device) { + IDirect3DDevice9_Release(priv->d3d_device); + priv->d3d_device = NULL; + } + + if (!configure_d3d()) return VO_ERROR; return 0; /* Success */ @@ -555,19 +650,19 @@ static int config(uint32_t width, uint32_t height, uint32_t d_width, static void flip_page(void) { if (FAILED(IDirect3DDevice9_Present(priv->d3d_device, 0, 0, 0, 0))) { - mp_msg(MSGT_VO,MSGL_V, + mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Video adapter became uncooperative.\n"); - mp_msg(MSGT_VO,MSGL_ERR,"<vo_direct3d>Trying to reinitialize it...\n"); + mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Trying to reinitialize it...\n"); if (!reconfigure_d3d()) { - mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Reinitialization Failed.\n"); + mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Reinitialization Failed.\n"); return; } if (FAILED(IDirect3DDevice9_Present(priv->d3d_device, 0, 0, 0, 0))) { - mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Reinitialization Failed.\n"); + mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Reinitialization Failed.\n"); return; } else - mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Video adapter reinitialized.\n"); + mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Video adapter reinitialized.\n"); } } @@ -585,11 +680,11 @@ static void draw_osd(void) */ static void uninit(void) { - mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Uninitialization\r\n"); + mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Uninitialization\r\n"); uninit_d3d(); vo_w32_uninit(); /* w32_common framework call */ - free (priv); + free(priv); priv = NULL; } @@ -605,7 +700,7 @@ static void check_events(void) */ flags = vo_w32_check_events(); if (flags & VO_EVENT_RESIZE) - reconfigure_d3d(); + resize_d3d(); if ((flags & VO_EVENT_EXPOSE) && priv->is_paused) flip_page(); @@ -623,8 +718,8 @@ static int draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y ) /* Lock the offscreen surface if it's not already locked. */ if (!priv->locked_rect.pBits) { if (FAILED(IDirect3DSurface9_LockRect(priv->d3d_surface, - &priv->locked_rect, NULL, 0))) { - mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>Surface lock failure\n"); + &priv->locked_rect, NULL, 0))) { + mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Surface lock failure\n"); return VO_FALSE; } } @@ -634,19 +729,22 @@ static int draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y ) /* Copy Y */ dst = priv->locked_rect.pBits; dst = dst + priv->locked_rect.Pitch * y + x; - my_src=src[0]; + my_src = src[0]; memcpy_pic(dst, my_src, w, h, priv->locked_rect.Pitch, stride[0]); - w/=2;h/=2;x/=2;y/=2; + w /= 2; + h /= 2; + x /= 2; + y /= 2; /* Copy U */ dst = priv->locked_rect.pBits; dst = dst + priv->locked_rect.Pitch * priv->src_height + uv_stride * y + x; if (priv->movie_src_fmt == MAKEFOURCC('Y','V','1','2')) - my_src=src[2]; + my_src = src[2]; else - my_src=src[1]; + my_src = src[1]; memcpy_pic(dst, my_src, w, h, uv_stride, stride[1]); @@ -669,6 +767,6 @@ static int draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y ) */ static int draw_frame(uint8_t *src[]) { - mp_msg(MSGT_VO,MSGL_V,"<vo_direct3d>draw_frame called\n"); + mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>draw_frame called\n"); return VO_FALSE; } diff --git a/libvo/vo_macosx.h b/libvo/vo_macosx.h index 422a91a462..6320b49651 100644 --- a/libvo/vo_macosx.h +++ b/libvo/vo_macosx.h @@ -56,6 +56,10 @@ NSMenuItem *kAspectFullCmd; NSMenuItem *kAspectWideCmd; NSMenuItem *kPanScanCmd; + + //timestamps for disabling screensaver and mouse hiding + int lastMouseHide; + int lastScreensaverUpdate; } - (BOOL) acceptsFirstResponder; diff --git a/libvo/vo_macosx.m b/libvo/vo_macosx.m index 50f1553c60..daede69573 100644 --- a/libvo/vo_macosx.m +++ b/libvo/vo_macosx.m @@ -9,7 +9,7 @@ #import "vo_macosx.h" #include <sys/types.h> #include <sys/ipc.h> -#include <sys/shm.h> +#include <sys/mman.h> #include <CoreServices/CoreServices.h> //special workaround for Apple bug #6267445 //(OSServices Power API disabled in OSServices.h for 64bit systems) @@ -40,8 +40,7 @@ NSAutoreleasePool *autoreleasepool; OSType pixelFormat; //shared memory -int shm_id; -struct shmid_ds shm_desc; +int shm_fd; BOOL shared_buffer = false; //Screen @@ -161,21 +160,36 @@ static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_ else { movie_aspect = (float)d_width/(float)d_height; - - shm_id = shmget(9849, image_width*image_height*image_bytes, IPC_CREAT | 0666); - if (shm_id == -1) + + // create shared memory + shm_fd = shm_open("mplayerosx", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); + if (shm_fd == -1) { - perror("vo_mplayer shmget: "); + mp_msg(MSGT_VO, MSGL_FATAL, + "vo_macosx: failed to open shared memory. Error: %s\n", strerror(errno)); return 1; } - image_data = shmat(shm_id, NULL, 0); - if (!image_data) - { - perror("vo_mplayer shmat: "); + + if (ftruncate(shm_fd, image_width*image_height*image_bytes) == -1) + { + mp_msg(MSGT_VO, MSGL_FATAL, + "vo_macosx: failed to size shared memory, possibly already in use. Error: %s\n", strerror(errno)); + shm_unlink("mplayerosx"); return 1; } + image_data = mmap(NULL, image_width*image_height*image_bytes, + PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0); + + if (image_data == MAP_FAILED) + { + mp_msg(MSGT_VO, MSGL_FATAL, + "vo_macosx: failed to map shared memory. Error: %s\n", strerror(errno)); + shm_unlink("mplayerosx"); + return 1; + } + //connnect to mplayerosx mplayerosxProxy=[NSConnection rootProxyForConnectionWithRegisteredName:@"mplayerosx" host:nil]; if ([mplayerosxProxy conformsToProtocol:@protocol(MPlayerOSXVOProto)]) { @@ -265,12 +279,13 @@ static void uninit(void) mplayerosxProto = nil; [mplayerosxProxy release]; mplayerosxProxy = nil; - - if (shmdt(image_data) == -1) - mp_msg(MSGT_VO, MSGL_FATAL, "uninit: shmdt failed\n"); - - if (shmctl(shm_id, IPC_RMID, &shm_desc) == -1) - mp_msg(MSGT_VO, MSGL_FATAL, "uninit: shmctl failed\n"); + + if (munmap(image_data, image_width*image_height*image_bytes) == -1) + mp_msg(MSGT_VO, MSGL_FATAL, "uninit: munmap failed. Error: %s\n", strerror(errno)); + + if (shm_unlink("mplayerosx") == -1) + mp_msg(MSGT_VO, MSGL_FATAL, "uninit: shm_unlink failed. Error: %s\n", strerror(errno)); + } SetSystemUIMode( kUIModeNormal, 0); @@ -755,28 +770,25 @@ static int control(uint32_t request, void *data) glFlush(); + curTime = TickCount()/60; + //auto hide mouse cursor (and future on-screen control?) if(isFullscreen && !mouseHide && !isRootwin) { - int curTime = TickCount()/60; - static int lastTime = 0; - - if( ((curTime - lastTime) >= 5) || (lastTime == 0) ) + if( ((curTime - lastMouseHide) >= 5) || (lastMouseHide == 0) ) { CGDisplayHideCursor(kCGDirectMainDisplay); - mouseHide = YES; - lastTime = curTime; + mouseHide = TRUE; + lastMouseHide = curTime; } } //update activity every 30 seconds to prevent //screensaver from starting up. - curTime = TickCount()/60; - - if( ((curTime - lastTime) >= 30) || (lastTime == 0) ) + if( ((curTime - lastScreensaverUpdate) >= 30) || (lastScreensaverUpdate == 0) ) { UpdateSystemActivity(UsrActivity); - lastTime = curTime; + lastScreensaverUpdate = curTime; } } diff --git a/libvo/vo_sdl.c b/libvo/vo_sdl.c index d1aeed2b0d..a1880c0f02 100644 --- a/libvo/vo_sdl.c +++ b/libvo/vo_sdl.c @@ -96,16 +96,14 @@ const LIBVO_EXTERN(sdl) #ifdef SDL_ENABLE_LOCKS #define SDL_OVR_LOCK(x) if (SDL_LockYUVOverlay (priv->overlay)) { \ - if( mp_msg_test(MSGT_VO,MSGL_V) ) { \ - mp_msg(MSGT_VO,MSGL_V, "SDL: Couldn't lock YUV overlay\n"); } \ + mp_msg(MSGT_VO,MSGL_V, "SDL: Couldn't lock YUV overlay\n"); \ return x; \ } #define SDL_OVR_UNLOCK SDL_UnlockYUVOverlay (priv->overlay); #define SDL_SRF_LOCK(srf, x) if(SDL_MUSTLOCK(srf)) { \ if(SDL_LockSurface (srf)) { \ - if( mp_msg_test(MSGT_VO,MSGL_V) ) { \ - mp_msg(MSGT_VO,MSGL_V, "SDL: Couldn't lock RGB surface\n"); } \ + mp_msg(MSGT_VO,MSGL_V, "SDL: Couldn't lock RGB surface\n"); \ return x; \ } \ } @@ -379,8 +377,7 @@ static int sdl_open (void *plugin, void *name) /* other default values */ #ifdef SDL_NOHWSURFACE - if( mp_msg_test(MSGT_VO,MSGL_V) ) { - mp_msg(MSGT_VO,MSGL_V, "SDL: using software-surface\n"); } + mp_msg(MSGT_VO,MSGL_V, "SDL: using software-surface\n"); priv->sdlflags = SDL_SWSURFACE|SDL_RESIZABLE|SDL_ANYFORMAT; priv->sdlfullflags = SDL_SWSURFACE|SDL_FULLSCREEN|SDL_ANYFORMAT; // XXX:FIXME: ASYNCBLIT should be enabled for SMP systems @@ -392,8 +389,7 @@ static int sdl_open (void *plugin, void *name) priv->sdlfullflags = SDL_SWSURFACE|SDL_FULLSCREEN|SDL_ASYNCBLIT|SDL_HWACCEL|SDL_ANYFORMAT; } else { */ - if( mp_msg_test(MSGT_VO,MSGL_V) ) { - mp_msg(MSGT_VO,MSGL_V, "SDL: using hardware-surface\n"); } + mp_msg(MSGT_VO,MSGL_V, "SDL: using hardware-surface\n"); priv->sdlflags = SDL_HWSURFACE|SDL_RESIZABLE/*|SDL_ANYFORMAT*/; priv->sdlfullflags = SDL_HWSURFACE|SDL_FULLSCREEN/*|SDL_ANYFORMAT*/; // XXX:FIXME: ASYNCBLIT should be enabled for SMP systems @@ -443,7 +439,6 @@ static int sdl_open (void *plugin, void *name) priv->bpp = vidInfo->vfmt->BitsPerPixel; if (priv->mode == YUV && priv->bpp < 16) { - if( mp_msg_test(MSGT_VO,MSGL_V) ) mp_msg(MSGT_VO,MSGL_V, "SDL: Your SDL display target wants to be at a color " "depth of (%d), but we need it to be at least 16 " "bits, so we need to emulate 16-bit color. This is " @@ -522,8 +517,7 @@ static int sdl_close (void) #if 0 static SDL_Rect aspect(int srcw, int srch, int dstw, int dsth) { SDL_Rect newres; - if( mp_msg_test(MSGT_VO,MSGL_V) ) { - mp_msg(MSGT_VO,MSGL_V, "SDL Aspect-Destinationres: %ix%i (x: %i, y: %i)\n", newres.w, newres.h, newres.x, newres.y); } + mp_msg(MSGT_VO,MSGL_V, "SDL Aspect-Destinationres: %ix%i (x: %i, y: %i)\n", newres.w, newres.h, newres.x, newres.y); newres.h = ((float)dstw / (float)srcw * (float)srch) * ((float)dsth/((float)dstw/(MONITOR_ASPECT))); if(newres.h > dsth) { newres.w = ((float)dsth / (float)newres.h) * dstw; @@ -537,8 +531,7 @@ static SDL_Rect aspect(int srcw, int srch, int dstw, int dsth) { newres.y = (dsth - newres.h) / 2; } - if( mp_msg_test(MSGT_VO,MSGL_V) ) { - mp_msg(MSGT_VO,MSGL_V, "SDL Mode: %d: %d x %d\n", i, priv->fullmodes[i]->w, priv->fullmodes[i]->h); } + mp_msg(MSGT_VO,MSGL_V, "SDL Mode: %d: %d x %d\n", i, priv->fullmodes[i]->w, priv->fullmodes[i]->h); return newres; } @@ -654,8 +647,7 @@ static void set_fullmode (int mode) { break; } } - if ( mp_msg_test(MSGT_VO,MSGL_V) ) { - mp_msg(MSGT_VO,MSGL_V, "SET SDL Mode: %d: %d x %d\n", mode, priv->fullmodes[mode]->w, priv->fullmodes[mode]->h); } + mp_msg(MSGT_VO,MSGL_V, "SET SDL Mode: %d: %d x %d\n", mode, priv->fullmodes[mode]->w, priv->fullmodes[mode]->h); priv->fullmode = mode; screen_surface_h = priv->fullmodes[mode]->h; screen_surface_w = priv->fullmodes[mode]->w; @@ -764,8 +756,7 @@ config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uin if ( vo_config_count ) sdl_close(); - if( mp_msg_test(MSGT_VO,MSGL_V) ) { - mp_msg(MSGT_VO,MSGL_V, "SDL: Using 0x%X (%s) image format\n", format, vo_format_name(format)); } + mp_msg(MSGT_VO,MSGL_V, "SDL: Using 0x%X (%s) image format\n", format, vo_format_name(format)); if(priv->mode != YUV) { priv->sdlflags |= SDL_ANYFORMAT; @@ -812,13 +803,11 @@ config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uin // printf("SDL: flags are set to: %i\n", flags); // printf("SDL: Width: %i Height: %i D_Width %i D_Height: %i\n", width, height, d_width, d_height); if(flags&VOFLAG_FLIPPING) { - if( mp_msg_test(MSGT_VO,MSGL_V) ) { - mp_msg(MSGT_VO,MSGL_V, "SDL: using flipped video (only with RGB/BGR/packed YUV)\n"); } + mp_msg(MSGT_VO,MSGL_V, "SDL: using flipped video (only with RGB/BGR/packed YUV)\n"); priv->flip = 1; } if(flags&VOFLAG_FULLSCREEN) { - if( mp_msg_test(MSGT_VO,MSGL_V) ) { - mp_msg(MSGT_VO,MSGL_V, "SDL: setting zoomed fullscreen without modeswitching\n");} + mp_msg(MSGT_VO,MSGL_V, "SDL: setting zoomed fullscreen without modeswitching\n"); mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SDL_InfoPleaseUseVmOrZoom); priv->fulltype = VOFLAG_FULLSCREEN; set_fullmode(priv->fullmode); @@ -826,16 +815,14 @@ config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uin SDL_ShowCursor(0);*/ } else if(flags&VOFLAG_MODESWITCHING) { - if( mp_msg_test(MSGT_VO,MSGL_V) ) { - mp_msg(MSGT_VO,MSGL_V, "SDL: setting zoomed fullscreen with modeswitching\n"); } + mp_msg(MSGT_VO,MSGL_V, "SDL: setting zoomed fullscreen with modeswitching\n"); priv->fulltype = VOFLAG_MODESWITCHING; set_fullmode(priv->fullmode); /*if((priv->surface = SDL_SetVideoMode (d_width ? d_width : width, d_height ? d_height : height, priv->bpp, priv->sdlfullflags))) SDL_ShowCursor(0);*/ } else if(flags&VOFLAG_SWSCALE) { - if( mp_msg_test(MSGT_VO,MSGL_V) ) { - mp_msg(MSGT_VO,MSGL_V, "SDL: setting zoomed fullscreen with modeswitching\n"); } + mp_msg(MSGT_VO,MSGL_V, "SDL: setting zoomed fullscreen with modeswitching\n"); priv->fulltype = VOFLAG_SWSCALE; set_fullmode(priv->fullmode); } @@ -847,13 +834,11 @@ config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uin ||(strcmp(priv->driver, "cgx") == 0) ||(strcmp(priv->driver, "os4video") == 0) ||((strcmp(priv->driver, "aalib") == 0) && priv->X)){ - if( mp_msg_test(MSGT_VO,MSGL_V) ) { - mp_msg(MSGT_VO,MSGL_V, "SDL: setting windowed mode\n"); } + mp_msg(MSGT_VO,MSGL_V, "SDL: setting windowed mode\n"); set_video_mode(priv->dstwidth, priv->dstheight, priv->bpp, priv->sdlflags); } else { - if( mp_msg_test(MSGT_VO,MSGL_V) ) { - mp_msg(MSGT_VO,MSGL_V, "SDL: setting zoomed fullscreen with modeswitching\n"); } + mp_msg(MSGT_VO,MSGL_V, "SDL: setting zoomed fullscreen with modeswitching\n"); priv->fulltype = VOFLAG_SWSCALE; set_fullmode(priv->fullmode); } @@ -1136,8 +1121,7 @@ static void check_events (void) priv->windowsize.w = priv->surface->w; priv->windowsize.h = priv->surface->h; //} - if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) { - mp_msg(MSGT_VO,MSGL_DBG3, "SDL: Window resize\n"); } + mp_msg(MSGT_VO,MSGL_DBG3, "SDL: Window resize\n"); break; case SDL_MOUSEBUTTONDOWN: @@ -1174,8 +1158,7 @@ static void check_events (void) case SDL_KEYDOWN: #endif keypressed = event.key.keysym.sym; - if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) { - mp_msg(MSGT_VO,MSGL_DBG2, "SDL: Key pressed: '%i'\n", keypressed); } + mp_msg(MSGT_VO,MSGL_DBG2, "SDL: Key pressed: '%i'\n", keypressed); /* c key pressed. c cycles through available fullscreenmodes, if we have some */ if ( ((keypressed == SDLK_c)) && (priv->fullmodes) ) { @@ -1184,8 +1167,7 @@ static void check_events (void) if (priv->fullmode > (findArrayEnd(priv->fullmodes) - 1)) priv->fullmode = 0; set_fullmode(priv->fullmode); - if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) { - mp_msg(MSGT_VO,MSGL_DBG2, "SDL: Set next available fullscreen mode.\n"); } + mp_msg(MSGT_VO,MSGL_DBG2, "SDL: Set next available fullscreen mode.\n"); } else if ( keypressed == SDLK_n ) { @@ -1196,15 +1178,13 @@ static void check_events (void) set_video_mode(priv->dstwidth, priv->dstheight, priv->bpp, priv->sdlflags); priv->windowsize.w = priv->surface->w; priv->windowsize.h = priv->surface->h; - if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) { - mp_msg(MSGT_VO,MSGL_DBG2, "SDL: Normal size\n"); } + mp_msg(MSGT_VO,MSGL_DBG2, "SDL: Normal size\n"); } else if (priv->surface->w != priv->dstwidth * 2 || priv->surface->h != priv->dstheight * 2) { set_video_mode(priv->dstwidth * 2, priv->dstheight * 2, priv->bpp, priv->sdlflags); priv->windowsize.w = priv->surface->w; priv->windowsize.h = priv->surface->h; - if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) { - mp_msg(MSGT_VO,MSGL_DBG2, "SDL: Double size\n"); } + mp_msg(MSGT_VO,MSGL_DBG2, "SDL: Double size\n"); } } @@ -1526,8 +1506,7 @@ uninit(void) #ifdef CONFIG_X11 struct sdl_priv_s *priv = &sdl_priv; if(priv->X) { - if( mp_msg_test(MSGT_VO,MSGL_V) ) { - mp_msg(MSGT_VO,MSGL_V, "SDL: activating XScreensaver/DPMS\n"); } + mp_msg(MSGT_VO,MSGL_V, "SDL: activating XScreensaver/DPMS\n"); vo_x11_uninit(); } #endif @@ -1537,8 +1516,7 @@ uninit(void) if(SDL_WasInit(SDL_INIT_VIDEO)) SDL_QuitSubSystem(SDL_INIT_VIDEO); - if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) { - mp_msg(MSGT_VO,MSGL_DBG3, "SDL: Closed Plugin\n"); } + mp_msg(MSGT_VO,MSGL_DBG3, "SDL: Closed Plugin\n"); } @@ -1564,8 +1542,7 @@ static int preinit(const char *arg) priv->overlay = NULL; priv->surface = NULL; - if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) { - mp_msg(MSGT_VO,MSGL_DBG3, "SDL: Opening Plugin\n"); } + mp_msg(MSGT_VO,MSGL_DBG3, "SDL: Opening Plugin\n"); if(sdl_driver) { setenv("SDL_VIDEODRIVER", sdl_driver, 1); @@ -1601,13 +1578,11 @@ static int preinit(const char *arg) priv->X = 0; #ifdef CONFIG_X11 if(vo_init()) { - if( mp_msg_test(MSGT_VO,MSGL_V) ) { - mp_msg(MSGT_VO,MSGL_V, "SDL: deactivating XScreensaver/DPMS\n"); } + mp_msg(MSGT_VO,MSGL_V, "SDL: deactivating XScreensaver/DPMS\n"); priv->XWidth = vo_screenwidth; priv->XHeight = vo_screenheight; priv->X = 1; - if( mp_msg_test(MSGT_VO,MSGL_V) ) { - mp_msg(MSGT_VO,MSGL_V, "SDL: X11 Resolution %ix%i\n", priv->XWidth, priv->XHeight); } + mp_msg(MSGT_VO,MSGL_V, "SDL: X11 Resolution %ix%i\n", priv->XWidth, priv->XHeight); } #endif @@ -1672,12 +1647,10 @@ static int control(uint32_t request, void *data) if (priv->surface->flags & SDL_FULLSCREEN) { set_video_mode(priv->windowsize.w, priv->windowsize.h, priv->bpp, priv->sdlflags); SDL_ShowCursor(1); - if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) { - mp_msg(MSGT_VO,MSGL_DBG2, "SDL: Windowed mode\n"); } + mp_msg(MSGT_VO,MSGL_DBG2, "SDL: Windowed mode\n"); } else if (priv->fullmodes) { set_fullmode(priv->fullmode); - if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) { - mp_msg(MSGT_VO,MSGL_DBG2, "SDL: Set fullscreen mode\n"); } + mp_msg(MSGT_VO,MSGL_DBG2, "SDL: Set fullscreen mode\n"); } return VO_TRUE; } |