video.cpp
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:7k
源码类别:

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * video.cpp : WinCE gui plugin for VLC
  3.  *****************************************************************************
  4.  * Copyright (C) 2000-2004, 2003 the VideoLAN team
  5.  * $Id: 09501f253ee2bcd0342089dec72976352ed1396b $
  6.  *
  7.  * Authors: Marodon Cedric <cedric_marodon@yahoo.fr>
  8.  *          Gildas Bazin <gbazin@videolan.org>
  9.  *
  10.  * This program is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2 of the License, or
  13.  * (at your option) any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to the Free Software
  22.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  23.  *****************************************************************************/
  24. /*****************************************************************************
  25.  * Preamble
  26.  *****************************************************************************/
  27. #ifdef HAVE_CONFIG_H
  28. # include "config.h"
  29. #endif
  30. #include <vlc_common.h>
  31. #include <vlc_vout.h>
  32. #include <vlc_interface.h>
  33. #include "wince.h"
  34. static void *GetWindow( intf_thread_t *p_intf, vout_thread_t *,
  35.                         int *pi_x_hint, int *pi_y_hint,
  36.                         unsigned int *pi_width_hint,
  37.                         unsigned int *pi_height_hint );
  38. static void ReleaseWindow( intf_thread_t *p_intf, void *p_window );
  39. static int ControlWindow( intf_thread_t *p_intf, void *p_window,
  40.                           int i_query, va_list args );
  41. /* IDs for the controls and the menu commands */
  42. enum
  43. {
  44.     UpdateSize_Event = 1000 + 1,
  45.     UpdateHide_Event
  46. };
  47. /* Video Window */
  48. class VideoWindow : public CBaseWindow
  49. {
  50. public:
  51.     /* Constructor */
  52.     VideoWindow( intf_thread_t *_p_intf, HWND _p_parent );
  53.     virtual ~VideoWindow();
  54.     void *GetWindow( vout_thread_t *, int *, int *, unsigned int *,
  55.                      unsigned int * );
  56.     void ReleaseWindow( void * );
  57.     int  ControlWindow( void *, int, va_list );
  58.  
  59.     HWND p_child_window; // public because of menu
  60. private:
  61.     intf_thread_t *p_intf;
  62.     vout_thread_t *p_vout;
  63.     HWND p_parent;
  64.     vlc_mutex_t lock;
  65.     virtual LRESULT WndProc( HWND, UINT, WPARAM, LPARAM );
  66. };
  67. /*****************************************************************************
  68.  * Public methods.
  69.  *****************************************************************************/
  70. CBaseWindow *CreateVideoWindow( intf_thread_t *p_intf, HWND p_parent )
  71. {
  72.     return new VideoWindow( p_intf, p_parent );
  73. }
  74. /*****************************************************************************
  75.  * Constructor.
  76.  *****************************************************************************/
  77. VideoWindow::VideoWindow( intf_thread_t *_p_intf, HWND _p_parent )
  78. {
  79.     RECT rect;
  80.     WNDCLASS wc;
  81.     /* Initializations */
  82.     p_intf = _p_intf;
  83.     p_parent = _p_parent;
  84.     p_child_window = NULL;
  85.     vlc_mutex_init( &lock );
  86.     p_vout = NULL;
  87.     // Changeset 138da19...
  88.     //p_intf->pf_request_window = ::GetWindow;
  89.     //p_intf->pf_release_window = ::ReleaseWindow;
  90.     //p_intf->pf_control_window = ::ControlWindow;
  91.     p_intf->p_sys->p_video_window = this;
  92.     GetClientRect( p_parent, &rect );
  93.     wc.style = CS_HREDRAW | CS_VREDRAW ;
  94.     wc.lpfnWndProc = (WNDPROC)BaseWndProc;
  95.     wc.cbClsExtra = 0;
  96.     wc.cbWndExtra = 0;
  97.     wc.hIcon = NULL;
  98.     wc.hInstance = GetModuleHandle(0);
  99.     wc.hCursor = NULL;
  100.     wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
  101.     wc.lpszMenuName = NULL;
  102.     wc.lpszClassName = _T("VIDEOWINDOW");
  103.     RegisterClass( &wc );
  104.     p_child_window = CreateWindow (
  105.         _T("VIDEOWINDOW"), _T(""),
  106.         WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | WS_BORDER,
  107.         0, 20, rect.right - rect.left,
  108.         rect.bottom - rect.top - 2*(MENU_HEIGHT-1) - SLIDER_HEIGHT - 20,
  109.         p_parent, NULL, GetModuleHandle(0), (void *)this );
  110.     ShowWindow( p_child_window, SW_SHOW );
  111.     UpdateWindow( p_child_window );
  112.     ReleaseWindow( (void*)p_child_window );
  113. }
  114. VideoWindow::~VideoWindow()
  115. {
  116.     vlc_mutex_destroy( &lock );
  117. }
  118. /*****************************************************************************
  119.  * Private methods.
  120.  *****************************************************************************/
  121. static void *GetWindow( intf_thread_t *p_intf,  vout_thread_t *p_vout,
  122.                         int *pi_x_hint, int *pi_y_hint,
  123.                         unsigned int *pi_width_hint,
  124.                         unsigned int *pi_height_hint )
  125. {
  126.     return p_intf->p_sys->p_video_window->GetWindow( p_vout, pi_x_hint,
  127.                                     pi_y_hint, pi_width_hint, pi_height_hint );
  128. }
  129. void *VideoWindow::GetWindow( vout_thread_t *_p_vout,
  130.                               int *pi_x_hint, int *pi_y_hint,
  131.                               unsigned int *pi_width_hint,
  132.                               unsigned int *pi_height_hint )
  133. {
  134.     vlc_mutex_lock( &lock );
  135.     if( p_vout )
  136.     {
  137.         vlc_mutex_unlock( &lock );
  138.         msg_Dbg( p_intf, "Video window already in use" );
  139.         return NULL;
  140.     }
  141.     p_vout = _p_vout;
  142.     vlc_mutex_unlock( &lock );
  143.     ShowWindow( (HWND)p_child_window, SW_SHOW );
  144.     return p_child_window;
  145. }
  146. static void ReleaseWindow( intf_thread_t *p_intf, void *p_window )
  147. {
  148.     p_intf->p_sys->p_video_window->ReleaseWindow( p_window );
  149. }
  150. void VideoWindow::ReleaseWindow( void *p_window )
  151. {
  152.     vlc_mutex_lock( &lock );
  153.     p_vout = NULL;
  154.     vlc_mutex_unlock( &lock );
  155.     ShowWindow( (HWND)p_window, SW_HIDE );
  156.     SetForegroundWindow( p_parent );
  157. }
  158. /***********************************************************************
  159. FUNCTION:
  160.   WndProc
  161. PURPOSE:
  162.   Processes messages sent to the main window.
  163. ***********************************************************************/
  164. LRESULT VideoWindow::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
  165. {
  166.     switch( msg )
  167.     {
  168.     case WM_KILLFOCUS:
  169.         return TRUE;
  170.     case WM_SETFOCUS:
  171.         return TRUE;
  172.     default:
  173.         return DefWindowProc( hwnd, msg, wp, lp );
  174.     }
  175. }
  176. static int ControlWindow( intf_thread_t *p_intf, void *p_window,
  177.                           int i_query, va_list args )
  178. {
  179.     return p_intf->p_sys->p_video_window->ControlWindow( p_window, i_query,
  180.                                                          args );
  181. }
  182. int VideoWindow::ControlWindow( void *p_window, int i_query, va_list args )
  183. {
  184.     int i_ret = VLC_EGENERIC;
  185.     vlc_mutex_lock( &lock );
  186.     switch( i_query )
  187.     {
  188.     case VOUT_SET_STAY_ON_TOP:
  189.         break;
  190.     default:
  191.         msg_Dbg( p_intf, "control query not supported" );
  192.         break;
  193.     }
  194.     vlc_mutex_unlock( &lock );
  195.     return i_ret;
  196. }