📄 directx.c
字号:
SystemParametersInfo(SPI_SETPOWEROFFTIMEOUT, 0, NULL, 0); } SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0, &(p_vout->p_sys->i_spi_screensavetimeout), 0); if( 0 != p_vout->p_sys->i_spi_screensavetimeout ) { SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, 0, NULL, 0); } } return VLC_SUCCESS; error: CloseVideo( VLC_OBJECT(p_vout) ); return VLC_EGENERIC;}/***************************************************************************** * Init: initialize DirectX video thread output method ***************************************************************************** * This function create the directx surfaces needed by the output thread. * It is called at the beginning of the thread. *****************************************************************************/static int Init( vout_thread_t *p_vout ){ int i_chroma_backup; vlc_value_t val; /* Get a few default parameters */ var_Get( p_vout, "overlay", &val ); p_vout->p_sys->b_using_overlay = val.b_bool; var_Get( p_vout, "directx-use-sysmem", &val ); p_vout->p_sys->b_use_sysmem = val.b_bool; var_Get( p_vout, "directx-hw-yuv", &val ); p_vout->p_sys->b_hw_yuv = val.b_bool; var_Get( p_vout, "directx-3buffering", &val ); p_vout->p_sys->b_3buf_overlay = val.b_bool; /* Initialise DirectDraw if not already done. * We do this here because on multi-monitor systems we may have to * re-create the directdraw surfaces. */ if( !p_vout->p_sys->p_ddobject && DirectXInitDDraw( p_vout ) != VLC_SUCCESS ) { msg_Err( p_vout, "cannot initialize DirectDraw" ); return VLC_EGENERIC; } /* Create the directx display */ if( !p_vout->p_sys->p_display && DirectXCreateDisplay( p_vout ) != VLC_SUCCESS ) { msg_Err( p_vout, "cannot initialize DirectDraw" ); return VLC_EGENERIC; } /* Initialize the output structure. * Since DirectDraw can do rescaling for us, stick to the default * coordinates and aspect. */ p_vout->output.i_width = p_vout->render.i_width; p_vout->output.i_height = p_vout->render.i_height; p_vout->output.i_aspect = p_vout->render.i_aspect; p_vout->fmt_out = p_vout->fmt_in; UpdateRects( p_vout, true );#define MAX_DIRECTBUFFERS 1 /* Right now we use only 1 directbuffer because we don't want the * video decoder to decode directly into direct buffers as they are * created into video memory and video memory is _really_ slow */ /* Choose the chroma we will try first. */ switch( p_vout->render.i_chroma ) { case VLC_FOURCC('Y','U','Y','2'): case VLC_FOURCC('Y','U','N','V'): p_vout->output.i_chroma = VLC_FOURCC('Y','U','Y','2'); break; case VLC_FOURCC('U','Y','V','Y'): case VLC_FOURCC('U','Y','N','V'): case VLC_FOURCC('Y','4','2','2'): p_vout->output.i_chroma = VLC_FOURCC('U','Y','V','Y'); break; case VLC_FOURCC('Y','V','Y','U'): p_vout->output.i_chroma = VLC_FOURCC('Y','V','Y','U'); break; default: p_vout->output.i_chroma = VLC_FOURCC('Y','V','1','2'); break; } NewPictureVec( p_vout, p_vout->p_picture, MAX_DIRECTBUFFERS ); i_chroma_backup = p_vout->output.i_chroma; if( !I_OUTPUTPICTURES ) { /* hmmm, it didn't work! Let's try commonly supported chromas */ if( p_vout->output.i_chroma != VLC_FOURCC('I','4','2','0') ) { p_vout->output.i_chroma = VLC_FOURCC('Y','V','1','2'); NewPictureVec( p_vout, p_vout->p_picture, MAX_DIRECTBUFFERS ); } if( !I_OUTPUTPICTURES ) { /* hmmm, it still didn't work! Let's try another one */ p_vout->output.i_chroma = VLC_FOURCC('Y','U','Y','2'); NewPictureVec( p_vout, p_vout->p_picture, MAX_DIRECTBUFFERS ); } } if( !I_OUTPUTPICTURES ) { /* If it still didn't work then don't try to use an overlay */ p_vout->output.i_chroma = i_chroma_backup; p_vout->p_sys->b_using_overlay = 0; NewPictureVec( p_vout, p_vout->p_picture, MAX_DIRECTBUFFERS ); } /* Change the window title bar text */ PostMessage( p_vout->p_sys->hwnd, WM_VLC_CHANGE_TEXT, 0, 0 ); p_vout->fmt_out.i_chroma = p_vout->output.i_chroma; return VLC_SUCCESS;}/***************************************************************************** * End: terminate Sys video thread output method ***************************************************************************** * Terminate an output method created by Create. * It is called at the end of the thread. *****************************************************************************/static void End( vout_thread_t *p_vout ){ FreePictureVec( p_vout, p_vout->p_picture, I_OUTPUTPICTURES ); DirectXCloseDisplay( p_vout ); DirectXCloseDDraw( p_vout ); return;}/***************************************************************************** * CloseVideo: destroy Sys video thread output method ***************************************************************************** * Terminate an output method created by Create *****************************************************************************/static void CloseVideo( vlc_object_t *p_this ){ vout_thread_t * p_vout = (vout_thread_t *)p_this; msg_Dbg( p_vout, "CloseVideo" ); if( p_vout->p_sys->p_event ) { vlc_object_detach( p_vout->p_sys->p_event ); /* Kill Vout EventThread */ vlc_object_kill( p_vout->p_sys->p_event ); /* we need to be sure Vout EventThread won't stay stuck in * GetMessage, so we send a fake message */ if( p_vout->p_sys->hwnd ) { PostMessage( p_vout->p_sys->hwnd, WM_NULL, 0, 0); } vlc_thread_join( p_vout->p_sys->p_event ); vlc_object_release( p_vout->p_sys->p_event ); } vlc_mutex_destroy( &p_vout->p_sys->lock ); /* Make sure the wallpaper is restored */ SwitchWallpaperMode( p_vout, false ); /* restore screensaver system settings */ if( 0 != p_vout->p_sys->i_spi_lowpowertimeout ) { SystemParametersInfo(SPI_SETLOWPOWERTIMEOUT, p_vout->p_sys->i_spi_lowpowertimeout, NULL, 0); } if( 0 != p_vout->p_sys->i_spi_powerofftimeout ) { SystemParametersInfo(SPI_SETPOWEROFFTIMEOUT, p_vout->p_sys->i_spi_powerofftimeout, NULL, 0); } if( 0 != p_vout->p_sys->i_spi_screensavetimeout ) { SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, p_vout->p_sys->i_spi_screensavetimeout, NULL, 0); } free( p_vout->p_sys ); p_vout->p_sys = NULL;}/***************************************************************************** * Manage: handle Sys events ***************************************************************************** * This function should be called regularly by the video output thread. * It returns a non null value if an error occurred. *****************************************************************************/static int Manage( vout_thread_t *p_vout ){ /* If we do not control our window, we check for geometry changes * ourselves because the parent might not send us its events. */ vlc_mutex_lock( &p_vout->p_sys->lock ); if( p_vout->p_sys->hparent && !p_vout->b_fullscreen ) { RECT rect_parent; POINT point; vlc_mutex_unlock( &p_vout->p_sys->lock ); GetClientRect( p_vout->p_sys->hparent, &rect_parent ); point.x = point.y = 0; ClientToScreen( p_vout->p_sys->hparent, &point ); OffsetRect( &rect_parent, point.x, point.y ); if( !EqualRect( &rect_parent, &p_vout->p_sys->rect_parent ) ) { p_vout->p_sys->rect_parent = rect_parent; /* This one is to force the update even if only * the position has changed */ SetWindowPos( p_vout->p_sys->hwnd, 0, 1, 1, rect_parent.right - rect_parent.left, rect_parent.bottom - rect_parent.top, 0 ); SetWindowPos( p_vout->p_sys->hwnd, 0, 0, 0, rect_parent.right - rect_parent.left, rect_parent.bottom - rect_parent.top, 0 ); } } else { vlc_mutex_unlock( &p_vout->p_sys->lock ); } /* * Position Change */ if( p_vout->p_sys->i_changes & DX_POSITION_CHANGE ) { p_vout->p_sys->i_changes &= ~DX_POSITION_CHANGE; /* Check if we are still on the same monitor */ if( p_vout->p_sys->MonitorFromWindow && p_vout->p_sys->hmonitor != p_vout->p_sys->MonitorFromWindow( p_vout->p_sys->hwnd, MONITOR_DEFAULTTONEAREST ) ) { /* This will force the vout core to recreate the picture buffers */ p_vout->i_changes |= VOUT_PICTURE_BUFFERS_CHANGE; } } /* Check for cropping / aspect changes */ if( p_vout->i_changes & VOUT_CROP_CHANGE || p_vout->i_changes & VOUT_ASPECT_CHANGE ) { p_vout->i_changes &= ~VOUT_CROP_CHANGE; p_vout->i_changes &= ~VOUT_ASPECT_CHANGE; p_vout->fmt_out.i_x_offset = p_vout->fmt_in.i_x_offset; p_vout->fmt_out.i_y_offset = p_vout->fmt_in.i_y_offset; p_vout->fmt_out.i_visible_width = p_vout->fmt_in.i_visible_width; p_vout->fmt_out.i_visible_height = p_vout->fmt_in.i_visible_height; p_vout->fmt_out.i_aspect = p_vout->fmt_in.i_aspect; p_vout->fmt_out.i_sar_num = p_vout->fmt_in.i_sar_num; p_vout->fmt_out.i_sar_den = p_vout->fmt_in.i_sar_den; p_vout->output.i_aspect = p_vout->fmt_in.i_aspect; UpdateRects( p_vout, true ); } /* We used to call the Win32 PeekMessage function here to read the window * messages. But since window can stay blocked into this function for a * long time (for example when you move your window on the screen), I * decided to isolate PeekMessage in another thread. */ if( p_vout->p_sys->i_changes & DX_WALLPAPER_CHANGE ) { SwitchWallpaperMode( p_vout, !p_vout->p_sys->b_wallpaper ); p_vout->p_sys->i_changes &= ~DX_WALLPAPER_CHANGE; DirectDrawUpdateOverlay( p_vout ); } /* * Fullscreen change */ if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE || p_vout->p_sys->i_changes & VOUT_FULLSCREEN_CHANGE ) { Win32ToggleFullscreen( p_vout ); p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE; p_vout->p_sys->i_changes &= ~VOUT_FULLSCREEN_CHANGE; } /* * Pointer change */ if( p_vout->b_fullscreen && !p_vout->p_sys->b_cursor_hidden && (mdate() - p_vout->p_sys->i_lastmoved) > p_vout->p_sys->i_mouse_hide_timeout ) { POINT point; HWND hwnd; /* Hide the cursor only if it is inside our window */ GetCursorPos( &point ); hwnd = WindowFromPoint(point); if( hwnd == p_vout->p_sys->hwnd || hwnd == p_vout->p_sys->hvideownd ) { PostMessage( p_vout->p_sys->hwnd, WM_VLC_HIDE_MOUSE, 0, 0 ); } else { p_vout->p_sys->i_lastmoved = mdate(); } } /* * "Always on top" status change */ if( p_vout->p_sys->b_on_top_change ) { vlc_value_t val; HMENU hMenu = GetSystemMenu( p_vout->p_sys->hwnd, FALSE ); var_Get( p_vout, "video-on-top", &val ); /* Set the window on top if necessary */ if( val.b_bool && !( GetWindowLong( p_vout->p_sys->hwnd, GWL_EXSTYLE ) & WS_EX_TOPMOST ) ) { CheckMenuItem( hMenu, IDM_TOGGLE_ON_TOP, MF_BYCOMMAND | MFS_CHECKED ); SetWindowPos( p_vout->p_sys->hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE ); } else /* The window shouldn't be on top */ if( !val.b_bool && ( GetWindowLong( p_vout->p_sys->hwnd, GWL_EXSTYLE ) & WS_EX_TOPMOST ) )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -