⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 directx.c

📁 uclinux 下的vlc播放器源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
            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;    E_(DirectXUpdateRects)( p_vout, VLC_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 );    }    if( p_vout->p_sys->b_using_overlay )    {        p_vout->pf_display = OverlayDisplay;    }    /* 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 DirectXEventThread */        p_vout->p_sys->p_event->b_die = VLC_TRUE;        /* we need to be sure DirectXEventThread 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_destroy( p_vout->p_sys->p_event );    }    vlc_mutex_destroy( &p_vout->p_sys->lock );    /* Make sure the wallpaper is restored */    SwitchWallpaperMode( p_vout, VLC_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);    }    if( p_vout->p_sys )    {        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 ){    WINDOWPLACEMENT window_placement;    /* 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;        E_(DirectXUpdateRects)( p_vout, VLC_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;        E_(DirectXUpdateOverlay)( p_vout );    }    /*     * Fullscreen change     */    if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE        || p_vout->p_sys->i_changes & VOUT_FULLSCREEN_CHANGE )    {        vlc_value_t val;        HWND hwnd = (p_vout->p_sys->hparent && p_vout->p_sys->hfswnd) ?            p_vout->p_sys->hfswnd : p_vout->p_sys->hwnd;        p_vout->b_fullscreen = ! p_vout->b_fullscreen;        /* We need to switch between Maximized and Normal sized window */        window_placement.length = sizeof(WINDOWPLACEMENT);        GetWindowPlacement( hwnd, &window_placement );        if( p_vout->b_fullscreen )        {            /* Change window style, no borders and no title bar */            int i_style = WS_CLIPCHILDREN | WS_VISIBLE;            SetWindowLong( hwnd, GWL_STYLE, i_style );            if( p_vout->p_sys->hparent )            {                /* Retrieve current window position so fullscreen will happen                 * on the right screen */                POINT point = {0,0};                RECT rect;                ClientToScreen( p_vout->p_sys->hwnd, &point );                GetClientRect( p_vout->p_sys->hwnd, &rect );                SetWindowPos( hwnd, 0, point.x, point.y,                              rect.right, rect.bottom,                              SWP_NOZORDER|SWP_FRAMECHANGED );                GetWindowPlacement( hwnd, &window_placement );            }            /* Maximize window */            window_placement.showCmd = SW_SHOWMAXIMIZED;            SetWindowPlacement( hwnd, &window_placement );            SetWindowPos( hwnd, 0, 0, 0, 0, 0,                          SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_FRAMECHANGED);            if( p_vout->p_sys->hparent )            {                RECT rect;                GetClientRect( hwnd, &rect );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -