Hola.
Loover, a ti te lo paso por el messenger esta noche, será porque nunca hablamos... :D
Loover, a ti te lo paso por el messenger esta noche, será porque nunca hablamos... :D
Esta sección te permite ver todos los posts escritos por este usuario. Ten en cuenta que sólo puedes ver los posts escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menu
IDirect3DSurface8* FrontBuffer;
m_pD3DDevice->CreateImageSurface(ancho,alto, D3DFMT_A8R8G8B8, &FrontBuffer );
m_pD3DDevice->GetFrontBuffer(FrontBuffer));
D3DXSaveSurfaceToFile(FileName,D3DXIFF_BMP,FrontBuffer, NULL, NULL);
RELEASE(FrontBuffer);
CVideo *pVideo;
pVideo = NEW CVideo; // NEW es una macro :P
if (pVideo)
{
if (!pVideo->Init(.......))
{
// controlas errores y demas :)
return false;
}
}
...
/*********************************************************************************
Nombre: Video.cpp
Descripción: Clase que lleva el control de un video
/*********************************************************************************/
#include "Pch_Base.h"
#include "Video.h"
//----------------------------------------------------------------------
// Uso:
// Retorno:
// Parametros:
//----------------------------------------------------------------------
CVideo::CVideo()
{
m_bOk = false;
}
//----------------------------------------------------------------------
// Uso:
// Retorno:
// Parametros:
//----------------------------------------------------------------------
CVideo::~CVideo()
{
End();
}
//----------------------------------------------------------------------
// Uso:
// Retorno:
// Parametros:
//----------------------------------------------------------------------
void CVideo::BorraVars()
{
m_bOk = false;
m_bVideoActivo = false;
m_bFullScreen = false;
m_bLoad = false;
m_hwnd = NULL;
m_dwGraphRegister = 0;
m_tVideoState = VS_STOP;
m_pGraphBuilder = NULL;
m_pMediaControl = NULL;
m_pMediaEvent = NULL;
m_pVideoWindow = NULL;
ZeroMemory(m_sToken,sizeof(m_sToken));
ZeroMemory(m_sFileVideo,sizeof(m_sFileVideo));
}
//----------------------------------------------------------------------
// Uso:
// Retorno:
// Parametros:
//----------------------------------------------------------------------
void CVideo::LiberaVars()
{
if (m_pVideoWindow)
{
m_pVideoWindow -> put_Visible(OAFALSE);
m_pVideoWindow -> put_Owner(NULL);
}
//if (m_pMediaEvent)
//m_pMediaEvent->SetNotifyWindow((OAHWND)NULL, 0, 0);
#ifdef REGISTER_FILTERGRAPH
if (m_dwGraphRegister)
{
RemoveGraphFromRot(m_dwGraphRegister);
m_dwGraphRegister = 0;
}
#endif // REGISTER_FILTERGRAPH
RELEASE (m_pMediaControl);
RELEASE (m_pVideoWindow);
RELEASE (m_pMediaEvent);
RELEASE (m_pGraphBuilder);
}
//----------------------------------------------------------------------
// Uso:
// Retorno:
// Parametros:
//----------------------------------------------------------------------
void CVideo::End()
{
if (m_bOk)
{
LiberaVars();
CoUninitialize();
m_bLoad = false;
m_bOk = false;
}
}
//----------------------------------------------------------------------
// Uso:
// Retorno:
// Parametros:
//----------------------------------------------------------------------
bool CVideo::Init(HWND hwnd,char *sFileVideo,char *sTokenVideo,bool bFullScreen)
{
End();
BorraVars();
if (sTokenVideo[0]) strcpy(m_sToken,sTokenVideo);
if (sFileVideo[0]) strcpy(m_sFileVideo,sFileVideo);
m_hwnd = hwnd;
m_bFullScreen = bFullScreen;
m_bOk = true;
return (m_bOk);
}
//----------------------------------------------------------------------
// Uso:
// Retorno:
// Parametros:
//----------------------------------------------------------------------
void CVideo::InitInterfaces()
{
/* -- Interface: Filter Graph" -- */
CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC,
IID_IGraphBuilder,(void**)&m_pGraphBuilder);
/* -- Interfaces: PlayBack & ScreenSize & Control de eventos -- */
m_pGraphBuilder -> QueryInterface (IID_IMediaControl, (void**) &m_pMediaControl);
m_pGraphBuilder -> QueryInterface (IID_IVideoWindow, (void**) &m_pVideoWindow );
m_pGraphBuilder -> QueryInterface (IID_IMediaEventEx, (void**) &m_pMediaEvent );
}
//----------------------------------------------------------------------
// Uso:
// Retorno:
// Parametros:
//----------------------------------------------------------------------
void CVideo::LoadVideo(char *sFileVideo)
{
WCHAR wstrFileName[MAX_PATH];
RECT area_ventana;
GetClientRect(m_hwnd,&area_ventana);
MultiByteToWideChar(CP_ACP, 0, sFileVideo, -1, wstrFileName, MAX_PATH);
CoInitialize(NULL);
InitInterfaces();
m_pGraphBuilder->RenderFile(wstrFileName,NULL);
m_pVideoWindow->put_MessageDrain((OAHWND)m_hwnd);
if ((m_pVideoWindow->put_Owner((OAHWND)m_hwnd)) == S_OK)
{
//m_pVideoWindow -> put_Visible (OAFALSE);
//m_pVideoWindow -> put_AutoShow (OAFALSE);
m_pVideoWindow -> put_WindowStyle (WS_CHILD | WS_CLIPSIBLINGS);
m_pVideoWindow -> SetWindowPosition (area_ventana.left,area_ventana.top,area_ventana.right,area_ventana.bottom);
}
m_bLoad = true;
}
//----------------------------------------------------------------------
// Uso:
// Retorno:
// Parametros:
//----------------------------------------------------------------------
void CVideo::SetFullScreen()
{
LONG lMode;
if (m_pVideoWindow)
{
m_pVideoWindow->get_FullScreenMode(&lMode);
if (lMode == 0) /* -- No fullscreen -- */
{
m_pVideoWindow->put_MessageDrain((OAHWND)m_hwnd);
lMode = -1; /* -- FullScreen mode -- */
m_pVideoWindow->put_FullScreenMode(lMode);
}
}
}
//----------------------------------------------------------------------
// Uso:
// Retorno:
// Parametros:
//----------------------------------------------------------------------
void CVideo::Play()
{
if (!m_bLoad)
LoadVideo();
if (m_bFullScreen)
SetFullScreen();
m_pMediaControl->Run();
m_tVideoState = VS_PLAY;
/* -- Loop principal mientras el video se reproduce... -- */
while (m_tVideoState == VS_PLAY)
{
MSG msg;
long lEventCode, lParam1, lParam2;
if(E_ABORT != m_pMediaEvent->GetEvent(&lEventCode, (LONG_PTR *) &lParam1,
(LONG_PTR *) &lParam2, 0))
{
m_pMediaEvent->FreeEventParams(lEventCode, lParam1, lParam2);
if (lEventCode == EC_COMPLETE)
m_tVideoState = VS_STOP;
}
while (PeekMessage (&msg, m_hwnd, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
m_pMediaControl->Stop();
End();
}
//----------------------------------------------------------------------
// Uso:
// Retorno:
// Parametros:
//----------------------------------------------------------------------
void CVideo::Run()
{
LONG code;
if (m_pMediaControl)
{
m_bVideoActivo = true;
m_pVideoWindow -> put_Visible(OATRUE);
m_pMediaControl -> Run();
m_pMediaEvent -> WaitForCompletion (INFINITE,&code);
m_pVideoWindow -> put_Visible(OAFALSE);
}
}
#ifdef REGISTER_FILTERGRAPH
//----------------------------------------------------------------------
// Uso:
// Retorno:
// Parametros:
//----------------------------------------------------------------------
HRESULT CVideo::AddGraphToRot(IUnknown *pUnkGraph, DWORD *pdwRegister)
{
IMoniker * pMoniker;
IRunningObjectTable *pROT;
if (FAILED(GetRunningObjectTable(0, &pROT)))
{
return E_FAIL;
}
WCHAR wsz[128];
wsprintfW(wsz, L"FilterGraph %08x pid %08x", (DWORD_PTR)pUnkGraph,
GetCurrentProcessId());
HRESULT hr = CreateItemMoniker(L"!", wsz, &pMoniker);
if (SUCCEEDED(hr))
{
hr = pROT->Register(0, pUnkGraph, pMoniker, pdwRegister);
pMoniker->Release();
}
pROT->Release();
return hr;
}
//----------------------------------------------------------------------
// Uso:
// Retorno:
// Parametros:
//----------------------------------------------------------------------
void CVideo::RemoveGraphFromRot(DWORD pdwRegister)
{
IRunningObjectTable *pROT;
if (SUCCEEDED(GetRunningObjectTable(0, &pROT)))
{
pROT->Revoke(pdwRegister);
pROT->Release();
}
}
#endif // REGISTER_FILTERGRAPH
-----------------------------------------------------------------------------
/*********************************************************************************
Nombre: Video.h
Descripción: Clase que lleva el control de un video
/*********************************************************************************/
#ifndef _Video_H
#define _Video_H
#include <DShow.h>
//#define REGISTER_FILTERGRAPH
class CVideo
{
public:
enum TVideoState
{
VS_PLAY = 1,
VS_PAUSE = 2,
VS_STOP = 3,
};
CVideo ();
~CVideo ();
bool Init (HWND hwnd,char *sFileVideo,char *sTokenVideo,bool bFullScreen);
void End ();
void Run ();
void Play ();
void SetFullScreen ();
HRESULT RunMensajesDelVideo ();
bool IsVideoActivo () { return (m_bVideoActivo); }
bool IsOk () { return (m_bOk); }
char *GetTokenVideo () { return (m_sToken); }
void LoadVideo () { LoadVideo(m_sFileVideo); }
void LoadVideo (char *sFileVideo);
private:
void BorraVars ();
void LiberaVars ();
void InitInterfaces ();
HRESULT AddGraphToRot (IUnknown *pUnkGraph, DWORD *pdwRegister);
void RemoveGraphFromRot (DWORD pdwRegister);
IGraphBuilder *m_pGraphBuilder;
IMediaControl *m_pMediaControl;
IMediaEventEx *m_pMediaEvent;
IVideoWindow *m_pVideoWindow;
HWND m_hwnd;
DWORD m_dwGraphRegister;
TVideoState m_tVideoState;
char m_sToken[255];
char m_sFileVideo[255];
bool m_bLoad;
bool m_bFullScreen;
bool m_bVideoActivo;
bool m_bOk;
};
#endif // _VideDevice_H