801 lines
24 KiB
C++
801 lines
24 KiB
C++
/* ##C_FILE#
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
FILE : mng_win.cpp
|
|
|
|
DESCRIPTION : One of mplementation files of module of AVI management : VDO
|
|
|
|
VERSION : 1.00/Nicolas Meyer/Creation
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
*/
|
|
|
|
/* ##INCLUDE#----------------------------------------------------------------------------
|
|
Includes Files
|
|
---------------------------------------------------------------------------------------*/
|
|
#include "ToolsCPA.h"
|
|
//#include <afxtempl.h>
|
|
|
|
#include "windows.h"
|
|
#include <vfw.h>
|
|
#include <digitalv.h>
|
|
#include <mciavi.h>
|
|
#include "GEO.h"
|
|
#include "mng_win.h"
|
|
|
|
#include "INO.h"
|
|
|
|
/* ##GLOBVAR#----------------------------------------------------------------------------
|
|
Globale variable declaration
|
|
---------------------------------------------------------------------------------------*/
|
|
|
|
unsigned char g_state;
|
|
|
|
VDO_tdxHandleToVideo g_p_VDO_OpenVideoList[C_VDO_MAXOPENVIDEO];
|
|
unsigned char g_uc_VDO_CurrentOpenVideo;
|
|
HWND g_hParentWindow;
|
|
// *g_ad;
|
|
// LRESULT (*g_ad)( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
|
|
|
|
/* ##F===================================================================================
|
|
NAME : VDO_fn_szGetCommandLine
|
|
DESCRIPTION : Get the command line in VDO
|
|
INPUT :
|
|
OUTPUT : string
|
|
=========================================================================================
|
|
CREATION : Nicolas Meyer
|
|
=======================================================================================*/
|
|
char * VDO_fn_szGetCommandLine()
|
|
{
|
|
return AfxGetApp()->m_lpCmdLine;
|
|
}/*VDO_fn_szGetCommandLine*/
|
|
|
|
/* ##F===================================================================================
|
|
NAME : VDO_fn_hGetVideoHandleFromWindowHandle
|
|
DESCRIPTION : Get the video handle from a window handle
|
|
INPUT : HWND hWnd
|
|
OUTPUT : VDO_tdxHandleToVideo
|
|
=========================================================================================
|
|
CREATION : Nicolas Meyer
|
|
=======================================================================================*/
|
|
VDO_tdxHandleToVideo VDO_fn_hGetVideoHandleFromWindowHandle(HWND hWnd)
|
|
{
|
|
int i;
|
|
VDO_tdxHandleToVideo hVideo=NULL;
|
|
for(i=0;i<g_uc_VDO_CurrentOpenVideo;i++)
|
|
{
|
|
if(g_p_VDO_OpenVideoList[i]->hVideoWindow==hWnd)
|
|
{
|
|
hVideo=g_p_VDO_OpenVideoList[i];
|
|
break;
|
|
}
|
|
}
|
|
return hVideo;
|
|
}/*VDO_fn_hGetVideoHandleFromWindowHandle*/
|
|
|
|
/* ##F===================================================================================
|
|
NAME : VDO_fn_vAddVideoHandleToGlobalList
|
|
DESCRIPTION : Add a video handle to the global list
|
|
INPUT : VDO_tdxHandleToVideo hVideo
|
|
OUTPUT :
|
|
=========================================================================================
|
|
CREATION : Nicolas Meyer
|
|
=======================================================================================*/
|
|
void VDO_fn_vAddVideoHandleToGlobalList(VDO_tdxHandleToVideo hVideo)
|
|
{
|
|
g_p_VDO_OpenVideoList[g_uc_VDO_CurrentOpenVideo]=hVideo;
|
|
g_uc_VDO_CurrentOpenVideo++;
|
|
}/*VDO_fn_vAddVideoHandleToGlobalList*/
|
|
|
|
/* ##F===================================================================================
|
|
NAME : VDO_fn_vRemoveVideoHandleFromGlobalList
|
|
DESCRIPTION : Remove a video handle from the global list
|
|
INPUT : VDO_tdxHandleToVideo hVideo
|
|
OUTPUT :
|
|
=========================================================================================
|
|
CREATION : Nicolas Meyer
|
|
=======================================================================================*/
|
|
void VDO_fn_vRemoveVideoHandleFromGlobalList(VDO_tdxHandleToVideo hVideo)
|
|
{
|
|
int i;
|
|
|
|
for(i=0;i<g_uc_VDO_CurrentOpenVideo;i++)
|
|
{
|
|
if(g_p_VDO_OpenVideoList[i]==hVideo)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
if(i!=g_uc_VDO_CurrentOpenVideo)
|
|
{
|
|
g_uc_VDO_CurrentOpenVideo--;
|
|
if(i!=g_uc_VDO_CurrentOpenVideo)
|
|
{
|
|
g_p_VDO_OpenVideoList[i]=g_p_VDO_OpenVideoList[g_uc_VDO_CurrentOpenVideo];
|
|
}
|
|
}
|
|
}/*VDO_fn_vRemoveVideoHandleFromGlobalList*/
|
|
|
|
/* ##F===================================================================================
|
|
NAME : VDO_fn_hCreateVideoWindow
|
|
DESCRIPTION : Create a video window
|
|
INPUT : VDO_tdxHandleToVideo p_stVideoHandle
|
|
unsigned char ucType
|
|
char *szFilename
|
|
OUTPUT :
|
|
=========================================================================================
|
|
CREATION : Nicolas Meyer
|
|
=======================================================================================*/
|
|
void VDO_fn_hCreateVideoWindow(VDO_tdxHandleToVideo p_stVideoHandle,unsigned char ucType,char *szFilename)
|
|
{
|
|
|
|
HWND m_hMciWindow;
|
|
|
|
p_stVideoHandle->ucMode = C_VDO_ERROR;
|
|
|
|
// Create the Window:
|
|
m_hMciWindow = MCIWndCreate(NULL ,
|
|
AfxGetInstanceHandle(), MCIWNDF_NOTIFYALL | MCIWNDF_NOMENU | MCIWNDF_NOPLAYBAR | WS_POPUP , (LPCSTR) szFilename );
|
|
|
|
SetWindowPos(m_hMciWindow, HWND_TOP, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), SWP_NOMOVE );
|
|
// Is window created ?
|
|
if ( m_hMciWindow == NULL )
|
|
{
|
|
return;
|
|
}
|
|
|
|
// t ShowWindow( m_hMciWindow, SW_SHOWMAXIMIZED );
|
|
|
|
// t SetActiveWindow(m_hMciWindow);
|
|
|
|
p_stVideoHandle->hVideoWindow=m_hMciWindow;
|
|
p_stVideoHandle->ucMode = C_VDO_NONE;
|
|
return;
|
|
|
|
}/*VDO_fn_hCreateVideoWindow*/
|
|
|
|
/* ##F===================================================================================
|
|
NAME : VDO_fn_xPlayVideo
|
|
DESCRIPTION : Play a video
|
|
INPUT : VDO_tdxHandleToVideo p_stVideoHandle
|
|
unsigned char ucMode
|
|
OUTPUT :
|
|
=========================================================================================
|
|
CREATION : Nicolas Meyer
|
|
=======================================================================================*/
|
|
void VDO_fn_xPlayVideo(VDO_tdxHandleToVideo p_stVideoHandle, unsigned char ucMode)
|
|
{
|
|
MCIERROR mciErrorCode;
|
|
|
|
if((p_stVideoHandle!=NULL)&&(p_stVideoHandle->ucMode!=C_VDO_ERROR))
|
|
{
|
|
p_stVideoHandle->ucMode = C_VDO_ERROR;
|
|
|
|
SND_fn_vReleaseDriverSound();
|
|
|
|
// SetForegroundWindow(p_stVideoHandle->hVideoWindow);
|
|
SetForegroundWindow(p_stVideoHandle->hVideoWindow);
|
|
|
|
// SetActiveWindow(p_stVideoHandle->hVideoWindow);
|
|
|
|
// SetFocus(p_stVideoHandle->hVideoWindow);
|
|
|
|
// t
|
|
ShowWindow( p_stVideoHandle->hVideoWindow, SW_SHOWMAXIMIZED );
|
|
|
|
mciErrorCode=MCIWndPlay(p_stVideoHandle->hVideoWindow);
|
|
|
|
SetForegroundWindow(p_stVideoHandle->hVideoWindow);
|
|
|
|
SetActiveWindow(p_stVideoHandle->hVideoWindow);
|
|
|
|
// if ( NoError() )
|
|
if(mciErrorCode==0)
|
|
{
|
|
p_stVideoHandle->ucMode = C_VDO_PLAY;
|
|
g_state=C_VDO_PLAY;
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
|
|
|
|
MSG lpMsg;
|
|
while((p_stVideoHandle->ucMode==C_VDO_PLAY)&&(MCIWndGetPosition(p_stVideoHandle->hVideoWindow)!=MCIWndGetEnd(p_stVideoHandle->hVideoWindow)))
|
|
{
|
|
while(PeekMessage(&lpMsg,NULL,0,0,PM_REMOVE))
|
|
//while(GetMessage(&lpMsg,NULL,0,0))
|
|
{
|
|
TranslateMessage(&lpMsg);
|
|
DispatchMessage(&lpMsg);
|
|
switch ( lpMsg.message )
|
|
{
|
|
|
|
case MM_MCINOTIFY:
|
|
{
|
|
switch ( lpMsg.wParam )
|
|
{
|
|
case MCI_NOTIFY_ABORTED:
|
|
case MCI_NOTIFY_SUCCESSFUL:
|
|
VDO_fn_hGetVideoHandleFromWindowHandle(lpMsg.hwnd)->ucMode=C_VDO_STOP;
|
|
break;
|
|
case MCI_NOTIFY_FAILURE:
|
|
TRACE( "Last mci command failed..\n");
|
|
VDO_fn_hGetVideoHandleFromWindowHandle(lpMsg.hwnd)->ucMode=C_VDO_STOP;
|
|
break;
|
|
default:
|
|
TRACE( "Unknown notification\n");
|
|
}
|
|
}
|
|
case WM_KEYDOWN:
|
|
if(lpMsg.wParam==VK_ESCAPE)
|
|
{
|
|
VDO_fn_hGetVideoHandleFromWindowHandle(lpMsg.hwnd)->ucMode=C_VDO_STOP;
|
|
}
|
|
break;
|
|
|
|
/* case WM_KILLFOCUS:
|
|
VDO_fn_hGetVideoHandleFromWindowHandle(hWnd)->ucMode=C_VDO_STOP;
|
|
break;
|
|
*/
|
|
case WM_ERASEBKGND:
|
|
TRACE("Erase video background\n");
|
|
break;
|
|
|
|
// Needed to display the first frame
|
|
case WM_PAINT:
|
|
// a faire
|
|
break;
|
|
|
|
case WM_DESTROY:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
VDO_fn_xStopVideo(p_stVideoHandle);
|
|
}
|
|
return;
|
|
}/*VDO_fn_xPlayVideo*/
|
|
|
|
/* ##F===================================================================================
|
|
NAME : VDO_fn_xOpenVideo
|
|
DESCRIPTION : Open the video file in VDO
|
|
INPUT : *szFilename (name of the video)
|
|
OUTPUT : handle of object video
|
|
=========================================================================================
|
|
CREATION : Nicolas Meyer
|
|
=======================================================================================*/
|
|
VDO_tdxHandleToVideo VDO_fn_xOpenVideo(char *szFilename)
|
|
{
|
|
|
|
// MCIERROR mciErrorCode;
|
|
VDO_tdxHandleToVideo p_stVideoHandle;
|
|
|
|
GEO_M_CPAMalloc( p_stVideoHandle, VDO_tdxHandleToVideo , sizeof(struct tdstVideo_),E_uwGEONotEnoughtMemory);
|
|
|
|
p_stVideoHandle->ucMode = C_VDO_LOADED;
|
|
|
|
VDO_fn_hCreateVideoWindow(p_stVideoHandle,1,szFilename);
|
|
|
|
|
|
if((p_stVideoHandle!=NULL)&&(p_stVideoHandle->ucMode!=C_VDO_ERROR))
|
|
{
|
|
VDO_fn_vAddVideoHandleToGlobalList(p_stVideoHandle);
|
|
}
|
|
|
|
return p_stVideoHandle;
|
|
}/*VDO_fn_xOpenVideo*/
|
|
|
|
/* ##F===================================================================================
|
|
NAME : VDO_fn_xStopVideo
|
|
DESCRIPTION : Stop the video in VDO
|
|
INPUT : p_stVideoHandle (handle of the video object)
|
|
OUTPUT :
|
|
=========================================================================================
|
|
CREATION : Nicolas Meyer
|
|
=======================================================================================*/
|
|
void VDO_fn_xStopVideo(VDO_tdxHandleToVideo p_stVideoHandle)
|
|
{
|
|
MCIERROR mciErrorCode;
|
|
|
|
if(p_stVideoHandle!=NULL)
|
|
{
|
|
if((p_stVideoHandle->ucMode!=C_VDO_NONE)&&(p_stVideoHandle->ucMode!=C_VDO_ERROR))
|
|
{
|
|
mciErrorCode=MCIWndStop(p_stVideoHandle->hVideoWindow);
|
|
SND_fn_vRestoreDriverSound();
|
|
}
|
|
}
|
|
p_stVideoHandle->ucMode = C_VDO_ERROR;
|
|
|
|
if(mciErrorCode==0)
|
|
{
|
|
p_stVideoHandle->ucMode = C_VDO_STOP;
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
|
|
return;
|
|
}/*VDO_fn_xStopVideo*/
|
|
|
|
/* ##F===================================================================================
|
|
NAME : VDO_fn_xCloseVideo
|
|
DESCRIPTION : Close the video file in VDO
|
|
INPUT : p_stVideoHandle (handle of the video object)
|
|
OUTPUT :
|
|
=========================================================================================
|
|
CREATION : Nicolas Meyer
|
|
=======================================================================================*/
|
|
void VDO_fn_xCloseVideo(VDO_tdxHandleToVideo p_stVideoHandle)
|
|
{
|
|
MCIERROR mciErrorCode;
|
|
|
|
// ReleaseCapture();
|
|
|
|
MCI_GENERIC_PARMS mciParameters;
|
|
mciParameters.dwCallback = NULL;
|
|
|
|
// Free the mci device
|
|
if(p_stVideoHandle!=NULL)
|
|
{
|
|
if(p_stVideoHandle->ucMode!=C_VDO_ERROR)
|
|
{
|
|
|
|
mciErrorCode=MCIWndClose(p_stVideoHandle->hVideoWindow);
|
|
MCIWndDestroy(p_stVideoHandle->hVideoWindow);
|
|
VDO_fn_vRemoveVideoHandleFromGlobalList(p_stVideoHandle);
|
|
p_stVideoHandle->hVideoWindow = NULL;
|
|
|
|
GEO_M_CPAFree(p_stVideoHandle);
|
|
}
|
|
}
|
|
// SetForegroundWindow((AfxGetApp()->m_pMainWnd)->m_hWnd);
|
|
|
|
}/*VDO_fn_xCloseVideo*/
|
|
|
|
/* ##F===================================================================================
|
|
NAME : fnGenMciStreamWindowProc (Callback)
|
|
DESCRIPTION : Event loop of a video window
|
|
INPUT : HWND hWnd
|
|
UINT uMsg
|
|
WPARAM wParam
|
|
LPARAM lParam
|
|
OUTPUT : LRESULT
|
|
=========================================================================================
|
|
CREATION : Nicolas Meyer
|
|
=======================================================================================*/
|
|
LRESULT CALLBACK fnGenMciStreamWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
|
|
{
|
|
|
|
switch ( uMsg )
|
|
{
|
|
|
|
case MM_MCINOTIFY:
|
|
{
|
|
switch ( wParam )
|
|
{
|
|
case MCI_NOTIFY_ABORTED:
|
|
case MCI_NOTIFY_SUCCESSFUL:
|
|
VDO_fn_hGetVideoHandleFromWindowHandle(hWnd)->ucMode=C_VDO_STOP;
|
|
break;
|
|
case MCI_NOTIFY_FAILURE:
|
|
TRACE( "Last mci command failed..\n");
|
|
VDO_fn_hGetVideoHandleFromWindowHandle(hWnd)->ucMode=C_VDO_STOP;
|
|
break;
|
|
default:
|
|
TRACE( "Unknown notification\n");
|
|
}
|
|
return 0L; // Message completely treated
|
|
}
|
|
case WM_KEYDOWN:
|
|
if(wParam==VK_ESCAPE)
|
|
{
|
|
VDO_fn_hGetVideoHandleFromWindowHandle(hWnd)->ucMode=C_VDO_STOP;
|
|
}
|
|
break;
|
|
|
|
/* case WM_KILLFOCUS:
|
|
VDO_fn_hGetVideoHandleFromWindowHandle(hWnd)->ucMode=C_VDO_STOP;
|
|
break;
|
|
*/
|
|
case WM_ERASEBKGND:
|
|
TRACE("Erase video background\n");
|
|
break;
|
|
|
|
// Needed to display the first frame
|
|
case WM_PAINT:
|
|
// a faire
|
|
break;
|
|
|
|
case WM_DESTROY:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
// Let the default procedure do the rest
|
|
return ::DefWindowProc( hWnd, uMsg, wParam, lParam );
|
|
}/*fnGenMciStreamWindowProc*/
|
|
|
|
/* ##F===================================================================================
|
|
NAME : VDO_fn_vInitVideo
|
|
DESCRIPTION : Init the video window
|
|
INPUT :
|
|
OUTPUT :
|
|
=========================================================================================
|
|
CREATION : Nicolas Meyer
|
|
=======================================================================================*/
|
|
void VDO_fn_vInitVideo()
|
|
{
|
|
|
|
WNDCLASS mciWndClass;
|
|
|
|
g_uc_VDO_CurrentOpenVideo=0;
|
|
|
|
// GetClassInfo( Instance, g_szGenWndClassName, &mciWndClass );
|
|
// Set new callback
|
|
mciWndClass.lpfnWndProc = &fnGenMciStreamWindowProc;
|
|
// Set new name
|
|
mciWndClass.lpszClassName = "Classe MCI Video TT";
|
|
// I use GEN DC: faster, and sure it has the good palette selected
|
|
mciWndClass.style = CS_OWNDC & CS_NOCLOSE; //&(~WS_BORDER & ~WS_CAPTION & ~WS_SYSMENU ) & WS_MAXIMIZE;
|
|
// mciWndClass.style |= CS_OWNDC;
|
|
|
|
mciWndClass.cbClsExtra = 0;
|
|
mciWndClass.cbWndExtra = 0;
|
|
mciWndClass.hInstance = AfxGetInstanceHandle();
|
|
mciWndClass.hIcon = NULL ;
|
|
mciWndClass.hCursor = NULL ;
|
|
mciWndClass.hbrBackground = NULL; //(HBRUSH)COLOR_BACKGROUND ;
|
|
mciWndClass.lpszMenuName = NULL;
|
|
|
|
|
|
if ( RegisterClass( &mciWndClass ) == 0 )
|
|
{
|
|
// Problem while registering
|
|
return; // Stop here
|
|
}
|
|
|
|
}/*VDO_fn_vInitVideo*/
|
|
|
|
/* ##F===================================================================================
|
|
NAME : VDO_fn_vDesInitVideo
|
|
DESCRIPTION : Desinit the video window in VDO
|
|
INPUT :
|
|
OUTPUT :
|
|
=========================================================================================
|
|
CREATION : Nicolas Meyer
|
|
=======================================================================================*/
|
|
void VDO_fn_vDesInitVideo()
|
|
{
|
|
UnregisterClass( "Classe MCI Video TT", AfxGetInstanceHandle() );
|
|
}/*VDO_fn_vDesInitVideo*/
|
|
|
|
|
|
/* ##F===================================================================================
|
|
NAME : VDO_fn_hCreateVideoWindowMPEG
|
|
DESCRIPTION : Create a window for a MPEG video file
|
|
INPUT : VDO_tdxHandleToVideo p_stVideoHandle
|
|
unsigned char ucType
|
|
OUTPUT :
|
|
=========================================================================================
|
|
CREATION : Nicolas Meyer
|
|
=======================================================================================*/
|
|
void VDO_fn_hCreateVideoWindowMPEG(VDO_tdxHandleToVideo p_stVideoHandle,unsigned char ucType)
|
|
{
|
|
|
|
HWND m_hMciWindow;
|
|
CRect wndRect;
|
|
HDC hdc=NULL;
|
|
CWnd* pWnd=NULL;
|
|
|
|
short wScreenHeight;
|
|
short wScreenWidth;
|
|
|
|
hdc = GetWindowDC(NULL);
|
|
wScreenHeight = (short)GetDeviceCaps(hdc, VERTRES);
|
|
wScreenWidth = (short)GetDeviceCaps(hdc, HORZRES);
|
|
ReleaseDC(NULL, hdc);
|
|
|
|
switch(ucType)
|
|
{
|
|
|
|
case 0:
|
|
pWnd = AfxGetApp()->m_pMainWnd;
|
|
pWnd->GetClientRect( &wndRect );
|
|
break;
|
|
|
|
case 1:
|
|
|
|
MCI_DGV_RECT_PARMS mciRect;
|
|
// Get the movie dimensions with MCI_WHERE.
|
|
mciSendCommand(p_stVideoHandle->hDeviceId, MCI_WHERE, MCI_DGV_WHERE_SOURCE, (DWORD)(LPSTR)&mciRect);
|
|
wndRect.SetRect(0,0, mciRect.rc.right, mciRect.rc.bottom);
|
|
break;
|
|
}
|
|
|
|
p_stVideoHandle->ucMode = C_VDO_ERROR;
|
|
// Create the Window:
|
|
|
|
m_hMciWindow = CreateWindow(
|
|
"Classe MCI Video TT",
|
|
NULL,
|
|
WS_POPUP | WS_VISIBLE, // & WS_DLGFRAME,// & (~WS_BORDER & ~WS_CAPTION & ~WS_SYSMENU ) & WS_MAXIMIZE,
|
|
0,0,
|
|
GetSystemMetrics(SM_CXSCREEN),
|
|
GetSystemMetrics(SM_CYSCREEN),
|
|
(AfxGetApp()->m_pMainWnd)->m_hWnd, NULL, AfxGetInstanceHandle(), NULL );
|
|
|
|
|
|
// Is window created ?
|
|
if ( m_hMciWindow == NULL )
|
|
{
|
|
return;
|
|
}
|
|
SetWindowPos(m_hMciWindow, HWND_TOP,0 ,0,GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), SWP_NOMOVE );
|
|
|
|
ShowWindow( m_hMciWindow, SW_SHOW );
|
|
|
|
SetActiveWindow(m_hMciWindow);
|
|
|
|
|
|
p_stVideoHandle->hVideoWindow=m_hMciWindow;
|
|
p_stVideoHandle->ucMode = C_VDO_NONE;
|
|
return;
|
|
|
|
}/*VDO_fn_hCreateVideoWindowMPEG*/
|
|
|
|
/* ##F===================================================================================
|
|
NAME : VDO_fn_xPlayVideoMPEG
|
|
DESCRIPTION : Play a MPEG video
|
|
INPUT : p_stVideoHandle (handle of the video object)
|
|
ucMode (playing mode)
|
|
OUTPUT :
|
|
=========================================================================================
|
|
CREATION : Nicolas Meyer
|
|
=======================================================================================*/
|
|
void VDO_fn_xPlayVideoMPEG(VDO_tdxHandleToVideo p_stVideoHandle, unsigned char ucMode)
|
|
{
|
|
MCIERROR mciErrorCode;
|
|
DWORD dwFlags;
|
|
|
|
if((p_stVideoHandle!=NULL)&&(p_stVideoHandle->ucMode!=C_VDO_ERROR))
|
|
{
|
|
p_stVideoHandle->ucMode = C_VDO_ERROR;
|
|
|
|
MCI_STATUS_PARMS mciStatusParameters;
|
|
mciStatusParameters.dwCallback = NULL;
|
|
mciStatusParameters.dwItem = MCI_STATUS_LENGTH; // Last frame asked
|
|
mciStatusParameters.dwTrack = 0;
|
|
|
|
|
|
// Command to mci
|
|
mciErrorCode=mciSendCommand( p_stVideoHandle->hDeviceId, MCI_STATUS, MCI_WAIT | MCI_STATUS_ITEM, (DWORD) &mciStatusParameters );
|
|
|
|
if(mciErrorCode!=0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
|
|
// Parameters
|
|
MCI_PLAY_PARMS mciPlayParameters;
|
|
mciPlayParameters.dwCallback = (DWORD)((WORD)p_stVideoHandle->hVideoWindow);
|
|
mciPlayParameters.dwFrom = 0;
|
|
mciPlayParameters.dwTo = mciStatusParameters.dwReturn; // GetMCILastFrame( ); ****************************************************
|
|
|
|
// Play from current pos to end of video
|
|
// The "from" & "to" info are handled by the SE
|
|
dwFlags = MCI_NOTIFY;
|
|
|
|
/* if(ucMode==C_VDO_FULLSCREEN)
|
|
{
|
|
dwFlags = MCI_NOTIFY | MCI_MCIAVI_PLAY_FULLSCREEN;
|
|
}
|
|
*/
|
|
mciErrorCode=mciSendCommand( p_stVideoHandle->hDeviceId, MCI_PLAY, dwFlags, (DWORD) &mciPlayParameters );
|
|
|
|
SetForegroundWindow(p_stVideoHandle->hVideoWindow);
|
|
|
|
/* RECT stRect;
|
|
|
|
stRect.left=0;
|
|
stRect.top=0;
|
|
stRect.right=GetSystemMetrics(SM_CXSCREEN);
|
|
stRect.bottom=GetSystemMetrics(SM_CYSCREEN);
|
|
|
|
MCIWndPutDest(p_stVideoHandle->hVideoWindow,&stRect);
|
|
|
|
*/
|
|
// if ( NoError() )
|
|
if(mciErrorCode==0)
|
|
{
|
|
p_stVideoHandle->ucMode = C_VDO_PLAY;
|
|
g_state=C_VDO_PLAY;
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
|
|
|
|
MSG lpMsg;
|
|
while(p_stVideoHandle->ucMode==C_VDO_PLAY)
|
|
{
|
|
while(PeekMessage(&lpMsg,NULL,0,0,PM_REMOVE))
|
|
//while(GetMessage(&lpMsg,NULL,0,0))
|
|
{
|
|
TranslateMessage(&lpMsg);
|
|
DispatchMessage(&lpMsg);
|
|
}
|
|
}
|
|
|
|
VDO_fn_xStopVideoMPEG(p_stVideoHandle);
|
|
}
|
|
return;
|
|
}/*VDO_fn_xPlayVideoMPEG*/
|
|
|
|
/* ##F===================================================================================
|
|
NAME : VDO_fn_xOpenVideoMPEG
|
|
DESCRIPTION : Open a MPEG video file
|
|
INPUT : *szFilename (name of the file)
|
|
OUTPUT : handle of the video object
|
|
=========================================================================================
|
|
CREATION : Nicolas Meyer
|
|
=======================================================================================*/
|
|
VDO_tdxHandleToVideo VDO_fn_xOpenVideoMPEG(char *szFilename)
|
|
{
|
|
|
|
MCIERROR mciErrorCode;
|
|
char szExtension[32];
|
|
VDO_tdxHandleToVideo p_stVideoHandle;
|
|
|
|
strcpy(szExtension, szFilename + strlen(szFilename) - 3);
|
|
|
|
//p_stVideoHandle=(VDO_tdxHandleToVideo)M_p_GameMalloc(E_ucGameMiscMemory,sizeof(struct tdstVideo_));
|
|
|
|
GEO_M_CPAMalloc( p_stVideoHandle, VDO_tdxHandleToVideo , sizeof(struct tdstVideo_),E_uwGEONotEnoughtMemory);
|
|
|
|
p_stVideoHandle->ucMode = C_VDO_ERROR;
|
|
|
|
|
|
//--- Get the device type into the WIN.INI file
|
|
char szDeviceType[1024];
|
|
GetProfileString(
|
|
"mci extensions", // address of section name
|
|
szExtension, // address of key name
|
|
"avivideo", // address of default string
|
|
szDeviceType, // address of destination buffer
|
|
1024); // size of destination buffer
|
|
|
|
// Here begin hard stuffs:
|
|
// For each command, fill a structure with parameters....
|
|
// Param for opening
|
|
MCI_OPEN_PARMS mciOpeningParameters;
|
|
|
|
// Callback: procedure to set for notifications.
|
|
mciOpeningParameters.dwCallback = NULL;
|
|
// This value is set by the driver
|
|
mciOpeningParameters.wDeviceID = 0;
|
|
// Type for opening
|
|
mciOpeningParameters.lpstrDeviceType = szDeviceType;
|
|
// Corresponding element
|
|
mciOpeningParameters.lpstrElementName = szFilename;//szRealFileName;
|
|
// Alias for SendString calls...
|
|
mciOpeningParameters.lpstrAlias = "Movie Test";
|
|
|
|
// Send the command
|
|
mciErrorCode=mciSendCommand( 0, MCI_OPEN, MCI_WAIT | MCI_OPEN_TYPE | MCI_OPEN_ELEMENT | MCI_OPEN_ALIAS, (DWORD) &mciOpeningParameters );
|
|
|
|
|
|
// Test if error appeared
|
|
if(mciErrorCode==0)
|
|
{
|
|
p_stVideoHandle->ucMode = C_VDO_LOADED;
|
|
p_stVideoHandle->hDeviceId = mciOpeningParameters.wDeviceID;
|
|
}
|
|
else
|
|
{
|
|
VDO_fn_xCloseVideo(p_stVideoHandle);
|
|
return NULL;
|
|
}
|
|
|
|
VDO_fn_hCreateVideoWindowMPEG(p_stVideoHandle,1);
|
|
|
|
// Attach the window for the device
|
|
MCI_DGV_WINDOW_PARMS mciWindowParameters;
|
|
mciWindowParameters.dwCallback = NULL;
|
|
mciWindowParameters.hWnd = p_stVideoHandle->hVideoWindow;
|
|
|
|
mciErrorCode=mciSendCommand( p_stVideoHandle->hDeviceId, MCI_WINDOW, MCI_WAIT | MCI_DGV_WINDOW_HWND, (DWORD) &mciWindowParameters );
|
|
|
|
// Test if error appeared
|
|
if(mciErrorCode==0)
|
|
{
|
|
p_stVideoHandle->ucMode = C_VDO_STOP;
|
|
VDO_fn_vAddVideoHandleToGlobalList(p_stVideoHandle);
|
|
}
|
|
else
|
|
{
|
|
VDO_fn_xCloseVideoMPEG(p_stVideoHandle);
|
|
return NULL;
|
|
}
|
|
|
|
return p_stVideoHandle;
|
|
}/*VDO_fn_xOpenVideoMPEG*/
|
|
|
|
/* ##F===================================================================================
|
|
NAME : VDO_fn_xStopVideoMPEG
|
|
DESCRIPTION : Stop a MPEG video
|
|
INPUT : p_stVideoHandle (handle of the video object)
|
|
OUTPUT :
|
|
=========================================================================================
|
|
CREATION : Nicolas Meyer
|
|
=======================================================================================*/
|
|
void VDO_fn_xStopVideoMPEG(VDO_tdxHandleToVideo p_stVideoHandle)
|
|
{
|
|
MCIERROR mciErrorCode=1;
|
|
|
|
if(p_stVideoHandle!=NULL)
|
|
{
|
|
if((p_stVideoHandle->ucMode!=C_VDO_NONE)&&(p_stVideoHandle->ucMode!=C_VDO_ERROR))
|
|
{
|
|
MCI_GENERIC_PARMS mciParameters;
|
|
mciParameters.dwCallback = NULL;
|
|
mciErrorCode=mciSendCommand( p_stVideoHandle->hDeviceId, MCI_STOP, MCI_WAIT, (DWORD)&mciParameters );
|
|
}
|
|
}
|
|
p_stVideoHandle->ucMode = C_VDO_ERROR;
|
|
|
|
if(mciErrorCode==0)
|
|
{
|
|
p_stVideoHandle->ucMode = C_VDO_STOP;
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
|
|
return;
|
|
}/*VDO_fn_xStopVideoMPEG*/
|
|
|
|
/* ##F===================================================================================
|
|
NAME : VDO_fn_xCloseVideoMPEG
|
|
DESCRIPTION : Close a MPEG video file
|
|
INPUT : p_stVideoHandle (handle of the video object)
|
|
OUTPUT :
|
|
=========================================================================================
|
|
CREATION : Nicolas Meyer
|
|
=======================================================================================*/
|
|
void VDO_fn_xCloseVideoMPEG(VDO_tdxHandleToVideo p_stVideoHandle)
|
|
{
|
|
MCIERROR mciErrorCode;
|
|
|
|
ReleaseCapture();
|
|
|
|
MCI_GENERIC_PARMS mciParameters;
|
|
mciParameters.dwCallback = NULL;
|
|
|
|
// Free the mci device
|
|
if(p_stVideoHandle!=NULL)
|
|
{
|
|
if(p_stVideoHandle->ucMode!=C_VDO_ERROR)
|
|
{
|
|
|
|
mciErrorCode=mciSendCommand( p_stVideoHandle->hDeviceId, MCI_CLOSE, MCI_WAIT, (DWORD)&mciParameters );
|
|
|
|
VDO_fn_vRemoveVideoHandleFromGlobalList(p_stVideoHandle);
|
|
DestroyWindow( p_stVideoHandle->hVideoWindow );
|
|
|
|
GEO_M_CPAFree(p_stVideoHandle);
|
|
|
|
SetForegroundWindow((AfxGetApp()->m_pMainWnd)->m_hWnd);
|
|
//UnregisterClass( "Classe MCI TT\0", AfxGetInstanceHandle() );
|
|
}
|
|
}
|
|
}/*VDO_fn_xCloseVideoMPEG*/ |