I try to implement a Video Player like mentioned here:
Supplying a Custom Allocator-Presenter for VMR-9
But my program hangs in the moment, when the video should be played.
Here is my Code:
class VideoAllocatorPresenter
: public IVMRSurfaceAllocator9,
public IVMRImagePresenter9
{
public:
STDMETHODIMP QueryInterface(REFIID riid, void **ppv) {
dbglog() << "QueryInterface " << std::endl;
//return S_OK; //GetOwner()->QueryInterface(riid,ppv);
ppv = NULL;
return E_NOINTERFACE;
};
STDMETHODIMP_(ULONG) AddRef() {
dbglog() << "AddRef" << std::endl;
return 1 ;//GetOwner()->AddRef();
};
STDMETHODIMP_(ULONG) Release() {
dbglog() << "Release" << std::endl;
return 1;//GetOwner()->Release();
};
VideoAllocatorPresenter() {};
virtual ~VideoAllocatorPresenter() {};
/*virtual HRESULT */STDMETHODIMP AdviseNotify( IVMRSurfaceAllocatorNotify9* lpIVMRSurfAllocNotify )
{
dbglog() << "AdviseNotify" << std::endl;
allocNotify_ = lpIVMRSurfAllocNotify;
return S_OK;
};
/*virtual HRESULT */STDMETHODIMP GetSurface( DWORD_PTR dwUserID, DWORD SurfaceIndex, DWORD SurfaceFlags,
IDirect3DSurface9** lplpSurface )
{
dbglog() << "GetSurface " << SurfaceIndex << std::endl;
*lplpSurface = surfaces_[SurfaceIndex];
dbglog() << "GetSurface done" << std::endl;
return S_OK;
};
/*virtual HRESULT */STDMETHODIMP InitializeDevice( DWORD_PTR dwUserID, VMR9AllocationInfo* lpAllocInfo,
DWORD* lpNumBuffers )
{
dbglog() << "InitializeDevice" << std::endl;
surfaces_ = (IDirect3DSurface9**) malloc(sizeof( IDirect3DSurface9*) * (*lpNumBuffers) );
allocNotify_->AllocateSurfaceHelper( lpAllocInfo, lpNumBuffers, surfaces_ );
dbglog() << " number buffers: " << (*lpNumBuffers) << std::endl;
return S_OK;
};
/*virtual HRESULT */STDMETHODIMP TerminateDevice( DWORD_PTR dwID )
{
dbglog() << "TerminateDevice" << std::endl;
return S_OK;
};
/*virtual HRESULT */STDMETHODIMP PresentImage( DWORD_PTR dwUserID, VMR9PresentationInfo* lpPresInfo )
{
dbglog() << "PresentImage" << std::endl;
return S_OK;
};
/*virtual HRESULT */STDMETHODIMP StartPresenting( DWORD_PTR dwUserID )
{
dbglog() << "StartPresenting" << std::endl;
return S_OK;
};
/*virtual HRESULT */STDMETHODIMP StopPresenting( DWORD_PTR dwUserID )
{
dbglog() << "StopPresenting" << std::endl;
return S_OK;
};
private:
IVMRSurfaceAllocatorNotify9* allocNotify_;
IDirect3DSurface9** surfaces_;
};
IMediaControl *m_pMediaControl;
a little later:
CoInitializeEx( NULL, 0 );
static VideoAllocatorPresenter allocPresent;
//create graph manager
IGraphBuilder *m_pGraph;
HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void**)&m_pGraph);
// BUILD the VMR9
IBaseFilter* m_pVMRBaseFilter;
hr = CoCreateInstance(CLSID_VideoMixingRenderer9, 0, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**) &m_pVMRBaseFilter);
// ADD the VMR9 to the graph
hr = m_pGraph->AddFilter(m_pVMRBaseFilter, L"VMR9");
IVMRFilterConfig9* m_pVMRFilterConfig;
hr = m_pVMRBaseFilter->QueryInterface(IID_IVMRFilterConfig9, (void**) &m_pVMRFilterConfig);
m_pVMRFilterConfig->SetRenderingMode(VMR9Mode_Renderless);
//m_pVMRFilterConfig->SetNumberOfStreams(2);
IVMRSurfaceAllocatorNotify9 *surfaceNotify;
hr = m_pVMRBaseFilter->QueryInterface(IID_IVMRSurfaceAllocatorNotify9, (void**) &surfaceNotify);
D3DDEVICE_CREATION_PARAMETERS params;
DXUTGetD3DDevice()->GetCreationParameters(¶ms); // Get parameters of D3D
IDirect3D9* iD3D9;
DXUTGetD3DDevice()->GetDirect3D( &iD3D9 );
HMONITOR hMonitor = iD3D9->GetAdapterMonitor( params.AdapterOrdinal );
surfaceNotify->SetD3DDevice( DXUTGetD3DDevice(), hMonitor );
surfaceNotify->AdviseSurfaceAllocator( 0,&allocPresent );
allocPresent.AdviseNotify( surfaceNotify );
hr = m_pGraph->RenderFile(L"video/intro.avi",L"");
hr = m_pGraph->QueryInterface(IID_IMediaControl, (void**)&m_pMediaControl);
IMediaEvent *m_pMediaEvent;
hr = m_pGraph->QueryInterface(IID_IMediaEvent, (void**)&m_pMediaEvent);
m_pMediaControl->Run();
//long evCode;
//m_pMediaEvent->WaitForCompletion(INFINITE, &evCode );
And here is the logging output:
27.10.2005-12:47:23
AddRef
QueryInterface
AdviseNotify
InitializeDevice
number buffers: 1
GetSurface 0
GetSurface done
As you can see it works till GetSurface and then my program hangs.
I know I need to put some code in the presenter part, but as this code is not called yet, I haven't done it...
Can anybody tell me what the problem is?
Thanks a lot?