请问大侠,在VMR Renderless模式下,调用IMediaControl老是返回S_FALSE是什么原因呢?谢谢...... 请问大侠,在VMR Renderless模式下,调用IMediaControl老是返回S_FALSE是什么原因呢?谢谢...... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 勤奋确定是否支持IMediaControl接口 #include "DirectShowVideoDevice.h"#include "TCHAR.h"namespace Video { DirectShowVideoDevice::DirectShowVideoDevice( LPCTSTR pszDisplayName ) { this->m_pCaptureFilter = NULL; this->m_pRenderFilter = NULL; this->m_pVMRSurfaceAllocatorNotify = NULL; this->m_pVMRSurfaceAllocator = NULL; this->m_pGraphBuilder = NULL; this->m_pCaptureGraphBuilder = NULL; this->m_pVMRWindowlessControl = NULL; _tcscpy(this->m_szDisplayName, pszDisplayName ); } DirectShowVideoDevice::~DirectShowVideoDevice(void) { } LPCTSTR DirectShowVideoDevice::getDescription( void ) const { return this->m_szDisplayName; } LPCTSTR DirectShowVideoDevice::getName( void ) const { return this->m_szFriendlyName; } bool DirectShowVideoDevice::Initialize( HWND hWnd ) { HRESULT hr = S_OK; this->m_hWnd = hWnd; // 创建IGraphBuilder接口 hr=CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&this->m_pGraphBuilder ); // 创建ICaptureGraphBuilder2接口 hr = CoCreateInstance (CLSID_CaptureGraphBuilder2 , NULL, CLSCTX_INPROC, IID_ICaptureGraphBuilder2, (void **) & this->m_pCaptureGraphBuilder ); //m_pCapture->SetFiltergraph(m_pGB); hr = this->m_pCaptureGraphBuilder->SetFiltergraph( this->m_pGraphBuilder ); hr = this->m_pGraphBuilder->QueryInterface( IID_IMediaControl, (void**) &this->m_pMediaControl ); //hr = this->m_pGraphBuilder->QueryInterface( IID_IOverlay, ( void ** ) & this->m_pOverlay ); /*** 建立 BaseFilter ***/ IBindCtx * pBindCtx = 0; IMoniker * pMoniker = NULL; ULONG ulEaten = 0; hr = ::CreateBindCtx( 0, &pBindCtx ); hr = ::MkParseDisplayName( pBindCtx, this->m_szDisplayName, &ulEaten, &pMoniker ); hr = pMoniker->BindToObject( 0, 0, IID_IBaseFilter, ( void ** ) &this->m_pCaptureFilter ); hr = pMoniker->Release(); pBindCtx->Release(); hr = this->m_pGraphBuilder->AddFilter( this->m_pCaptureFilter, TEXT("Capturer") ); /*** 建立 VMR Filter ***/ hr = ::CoCreateInstance ( ::CLSID_VideoMixingRenderer, NULL, CLSCTX_INPROC, IID_IBaseFilter, ( void ** ) & this->m_pRenderFilter ); hr = this->m_pGraphBuilder->AddFilter( this->m_pRenderFilter, TEXT("VMR Render") ); IVMRFilterConfig* pConfig = NULL; /*** VMR 配置器 ***/ hr = this->m_pRenderFilter->QueryInterface( IID_IVMRFilterConfig, ( void ** ) & pConfig ); hr = pConfig->SetNumberOfStreams( (DWORD)1 ); hr = pConfig->SetRenderingMode( VMRMode_Renderless ); pConfig->Release(); pConfig = NULL; ///** 建立 VMR Renderless 部分***/ hr = this->m_pRenderFilter->QueryInterface( IID_IVMRSurfaceAllocatorNotify, (void **)& this->m_pVMRSurfaceAllocatorNotify ); //***** Presenter **********/ hr = CoCreateInstance(CLSID_AllocPresenter, NULL, CLSCTX_INPROC_SERVER, IID_IVMRSurfaceAllocator, (LPVOID*)&this->m_pVMRSurfaceAllocator); hr = this->m_pVMRSurfaceAllocator->AdviseNotify( this ); hr = this->m_pVMRSurfaceAllocator->QueryInterface( IID_IVMRImagePresenter, ( void ** ) &this->m_pVMRImagePresenter ); hr = this->m_pVMRSurfaceAllocator->QueryInterface( IID_IVMRWindowlessControl, ( void **) &this->m_pVMRWindowlessControl ); hr = this->m_pVMRWindowlessControl->SetVideoClippingWindow( this->m_hWnd ); this->m_pVMRSurfaceAllocatorNotify->AdviseSurfaceAllocator( 0x1234ACDE, this ); hr = this->m_pCaptureGraphBuilder->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, this->m_pCaptureFilter, NULL, this->m_pRenderFilter); OAFilterState fs; while ( ( hr = this->m_pMediaControl->GetState(INFINITE, &fs) ) != S_OK ) {}; hr = this->m_pMediaControl->Run(); hr = this->m_pMediaControl->GetState(INFINITE, &fs); return true; } bool DirectShowVideoDevice::Uninitialize( void ) { HRESULT hr = S_OK; if ( this->m_pCaptureFilter != NULL ) { hr = this->m_pCaptureFilter->Release(); this->m_pCaptureFilter = NULL; } if ( this->m_pRenderFilter != NULL ) { hr = this->m_pRenderFilter->Release(); this->m_pRenderFilter = NULL; } if ( this->m_pMediaControl != NULL ) { this->m_pMediaControl->Release(); } if ( this->m_pCaptureGraphBuilder != NULL ) { this->m_pCaptureGraphBuilder ->Release(); this->m_pCaptureGraphBuilder = NULL; } if ( this->m_pVMRWindowlessControl != NULL ) { hr = this->m_pVMRWindowlessControl->Release(); this->m_pVMRWindowlessControl = NULL; } return true; } HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::QueryInterface( /* [in] */ REFIID riid, /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject) { HRESULT hr = this->m_pVMRSurfaceAllocator->QueryInterface( riid, ppvObject ); return hr; } ULONG STDMETHODCALLTYPE DirectShowVideoDevice::AddRef( void) { return this->m_pVMRSurfaceAllocator->AddRef(); } ULONG STDMETHODCALLTYPE DirectShowVideoDevice::Release( void) { return this->m_pVMRSurfaceAllocator->Release(); } HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::AdviseSurfaceAllocator( /* [in] */ DWORD_PTR dwUserID, /* [in] */ IVMRSurfaceAllocator *lpIVRMSurfaceAllocator) { return this->m_pVMRSurfaceAllocatorNotify->AdviseSurfaceAllocator( dwUserID, lpIVRMSurfaceAllocator ); } HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::SetDDrawDevice( /* [in] */ LPDIRECTDRAW7 lpDDrawDevice, /* [in] */ HMONITOR hMonitor) { HRESULT hr = this->m_pVMRSurfaceAllocatorNotify->SetDDrawDevice( lpDDrawDevice, hMonitor ); return hr; }; HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::ChangeDDrawDevice( /* [in] */ LPDIRECTDRAW7 lpDDrawDevice, /* [in] */ HMONITOR hMonitor) { return this->m_pVMRSurfaceAllocatorNotify->ChangeDDrawDevice( lpDDrawDevice, hMonitor ); } HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::RestoreDDrawSurfaces( void ) { return this->m_pVMRSurfaceAllocatorNotify->RestoreDDrawSurfaces( ); } HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::NotifyEvent( /* [in] */ LONG EventCode, /* [in] */ LONG_PTR Param1, /* [in] */ LONG_PTR Param2) { return this->m_pVMRSurfaceAllocatorNotify->NotifyEvent( EventCode, Param1, Param2 ); } HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::SetBorderColor( /* [in] */ COLORREF clrBorder) { return this->m_pVMRSurfaceAllocatorNotify->SetBorderColor( clrBorder ); } HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::AllocateSurface( /* [in] */ DWORD_PTR dwUserID, /* [in] */ VMRALLOCATIONINFO *lpAllocInfo, /* [out][in] */ DWORD *lpdwActualBuffers, /* [out] */ LPDIRECTDRAWSURFACE7 *lplpSurface) { return this->m_pVMRSurfaceAllocator->AllocateSurface( dwUserID, lpAllocInfo, lpdwActualBuffers, lplpSurface ); } HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::FreeSurface( /* [in] */ DWORD_PTR dwID) { return this->m_pVMRSurfaceAllocator->FreeSurface( dwID ); } HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::PrepareSurface( /* [in] */ DWORD_PTR dwUserID, /* [in] */ LPDIRECTDRAWSURFACE7 lpSurface, /* [in] */ DWORD dwSurfaceFlags) { return this->m_pVMRSurfaceAllocator->PrepareSurface( dwUserID, lpSurface, dwSurfaceFlags ); } HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::AdviseNotify( /* [in] */ IVMRSurfaceAllocatorNotify *lpIVMRSurfAllocNotify) { return this->m_pVMRSurfaceAllocator->AdviseNotify( lpIVMRSurfAllocNotify ); } HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::StartPresenting( /* [in] */ DWORD_PTR dwUserID) { return this->m_pVMRImagePresenter->StartPresenting( dwUserID ); } HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::StopPresenting( /* [in] */ DWORD_PTR dwUserID) { return this->m_pVMRImagePresenter->StopPresenting( dwUserID ); } HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::PresentImage( /* [in] */ DWORD_PTR dwUserID, /* [in] */ VMRPRESENTATIONINFO *lpPresInfo) { return this->m_pVMRImagePresenter->PresentImage( dwUserID, lpPresInfo ); }} 窗口大小变化到底是响应哪个消息? 想用SSL来传送密钥,可以吗?急急急 求“C#”的文章翻译 菜鸟提问:获取控件句柄 关于mfc扩展dll中实现对话框的问题 高分求助KoDak 缩略图控件 的使用方法? 一个单文档多视图的问题(mdi)? 如何在CEdit控件里用鼠标双击的方式选中某一行,并使其呈高亮度显示 如何给分,如何赚分,如何结贴 基于对话框的MFC程序启动界面制作 哪有比较简单的单文档应用程序例子 关于recv的问题
#include "TCHAR.h"
namespace Video
{ DirectShowVideoDevice::DirectShowVideoDevice( LPCTSTR pszDisplayName )
{
this->m_pCaptureFilter = NULL; this->m_pRenderFilter = NULL;
this->m_pVMRSurfaceAllocatorNotify = NULL;
this->m_pVMRSurfaceAllocator = NULL; this->m_pGraphBuilder = NULL;
this->m_pCaptureGraphBuilder = NULL; this->m_pVMRWindowlessControl = NULL; _tcscpy(this->m_szDisplayName, pszDisplayName );
} DirectShowVideoDevice::~DirectShowVideoDevice(void)
{
} LPCTSTR DirectShowVideoDevice::getDescription( void ) const
{
return this->m_szDisplayName;
} LPCTSTR DirectShowVideoDevice::getName( void ) const
{
return this->m_szFriendlyName;
} bool DirectShowVideoDevice::Initialize( HWND hWnd )
{
HRESULT hr = S_OK;
this->m_hWnd = hWnd; // 创建IGraphBuilder接口
hr=CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder,
(void **)&this->m_pGraphBuilder );
// 创建ICaptureGraphBuilder2接口
hr = CoCreateInstance (CLSID_CaptureGraphBuilder2 , NULL, CLSCTX_INPROC,
IID_ICaptureGraphBuilder2, (void **) & this->m_pCaptureGraphBuilder ); //m_pCapture->SetFiltergraph(m_pGB);
hr = this->m_pCaptureGraphBuilder->SetFiltergraph( this->m_pGraphBuilder ); hr = this->m_pGraphBuilder->QueryInterface( IID_IMediaControl,
(void**) &this->m_pMediaControl ); //hr = this->m_pGraphBuilder->QueryInterface( IID_IOverlay, ( void ** ) & this->m_pOverlay ); /*** 建立 BaseFilter ***/
IBindCtx * pBindCtx = 0;
IMoniker * pMoniker = NULL;
ULONG ulEaten = 0; hr = ::CreateBindCtx( 0, &pBindCtx ); hr = ::MkParseDisplayName( pBindCtx, this->m_szDisplayName, &ulEaten, &pMoniker ); hr = pMoniker->BindToObject( 0, 0, IID_IBaseFilter, ( void ** ) &this->m_pCaptureFilter ); hr = pMoniker->Release(); pBindCtx->Release(); hr = this->m_pGraphBuilder->AddFilter( this->m_pCaptureFilter, TEXT("Capturer") );
/*** 建立 VMR Filter ***/
hr = ::CoCreateInstance ( ::CLSID_VideoMixingRenderer, NULL, CLSCTX_INPROC,
IID_IBaseFilter, ( void ** ) & this->m_pRenderFilter ); hr = this->m_pGraphBuilder->AddFilter( this->m_pRenderFilter, TEXT("VMR Render") ); IVMRFilterConfig* pConfig = NULL; /*** VMR 配置器 ***/
hr = this->m_pRenderFilter->QueryInterface( IID_IVMRFilterConfig, ( void ** ) & pConfig );
hr = pConfig->SetNumberOfStreams( (DWORD)1 );
hr = pConfig->SetRenderingMode( VMRMode_Renderless );
pConfig->Release();
pConfig = NULL; ///** 建立 VMR Renderless 部分***/ hr = this->m_pRenderFilter->QueryInterface( IID_IVMRSurfaceAllocatorNotify,
(void **)& this->m_pVMRSurfaceAllocatorNotify ); //***** Presenter **********/
hr = CoCreateInstance(CLSID_AllocPresenter, NULL,
CLSCTX_INPROC_SERVER,
IID_IVMRSurfaceAllocator,
(LPVOID*)&this->m_pVMRSurfaceAllocator);
hr = this->m_pVMRSurfaceAllocator->AdviseNotify( this ); hr = this->m_pVMRSurfaceAllocator->QueryInterface( IID_IVMRImagePresenter,
( void ** ) &this->m_pVMRImagePresenter ); hr = this->m_pVMRSurfaceAllocator->QueryInterface( IID_IVMRWindowlessControl,
( void **) &this->m_pVMRWindowlessControl );
hr = this->m_pVMRWindowlessControl->SetVideoClippingWindow( this->m_hWnd );
this->m_pVMRSurfaceAllocatorNotify->AdviseSurfaceAllocator( 0x1234ACDE, this );
hr = this->m_pCaptureGraphBuilder->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,
this->m_pCaptureFilter, NULL, this->m_pRenderFilter);
OAFilterState fs;
while ( ( hr = this->m_pMediaControl->GetState(INFINITE, &fs) ) != S_OK ) {};
hr = this->m_pMediaControl->Run();
hr = this->m_pMediaControl->GetState(INFINITE, &fs); return true;
}
{
HRESULT hr = S_OK; if ( this->m_pCaptureFilter != NULL )
{
hr = this->m_pCaptureFilter->Release();
this->m_pCaptureFilter = NULL;
} if ( this->m_pRenderFilter != NULL )
{
hr = this->m_pRenderFilter->Release();
this->m_pRenderFilter = NULL;
} if ( this->m_pMediaControl != NULL )
{
this->m_pMediaControl->Release();
} if ( this->m_pCaptureGraphBuilder != NULL )
{
this->m_pCaptureGraphBuilder ->Release();
this->m_pCaptureGraphBuilder = NULL;
} if ( this->m_pVMRWindowlessControl != NULL )
{
hr = this->m_pVMRWindowlessControl->Release();
this->m_pVMRWindowlessControl = NULL;
} return true;
} HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::QueryInterface(
/* [in] */ REFIID riid,
/* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
{
HRESULT hr = this->m_pVMRSurfaceAllocator->QueryInterface( riid, ppvObject );
return hr; }
ULONG STDMETHODCALLTYPE DirectShowVideoDevice::AddRef( void)
{
return this->m_pVMRSurfaceAllocator->AddRef();
}
ULONG STDMETHODCALLTYPE DirectShowVideoDevice::Release( void)
{
return this->m_pVMRSurfaceAllocator->Release();
} HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::AdviseSurfaceAllocator(
/* [in] */ DWORD_PTR dwUserID,
/* [in] */ IVMRSurfaceAllocator *lpIVRMSurfaceAllocator)
{
return this->m_pVMRSurfaceAllocatorNotify->AdviseSurfaceAllocator( dwUserID, lpIVRMSurfaceAllocator );
}
HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::SetDDrawDevice(
/* [in] */ LPDIRECTDRAW7 lpDDrawDevice,
/* [in] */ HMONITOR hMonitor)
{
HRESULT hr = this->m_pVMRSurfaceAllocatorNotify->SetDDrawDevice( lpDDrawDevice, hMonitor );
return hr;
};
HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::ChangeDDrawDevice(
/* [in] */ LPDIRECTDRAW7 lpDDrawDevice,
/* [in] */ HMONITOR hMonitor)
{
return this->m_pVMRSurfaceAllocatorNotify->ChangeDDrawDevice( lpDDrawDevice, hMonitor );
}
HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::RestoreDDrawSurfaces( void )
{
return this->m_pVMRSurfaceAllocatorNotify->RestoreDDrawSurfaces( );
}
HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::NotifyEvent(
/* [in] */ LONG EventCode,
/* [in] */ LONG_PTR Param1,
/* [in] */ LONG_PTR Param2)
{
return this->m_pVMRSurfaceAllocatorNotify->NotifyEvent( EventCode, Param1, Param2 );
}
HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::SetBorderColor(
/* [in] */ COLORREF clrBorder)
{
return this->m_pVMRSurfaceAllocatorNotify->SetBorderColor( clrBorder );
} HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::AllocateSurface(
/* [in] */ DWORD_PTR dwUserID,
/* [in] */ VMRALLOCATIONINFO *lpAllocInfo,
/* [out][in] */ DWORD *lpdwActualBuffers,
/* [out] */ LPDIRECTDRAWSURFACE7 *lplpSurface)
{
return this->m_pVMRSurfaceAllocator->AllocateSurface( dwUserID, lpAllocInfo, lpdwActualBuffers, lplpSurface );
}
HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::FreeSurface(
/* [in] */ DWORD_PTR dwID)
{
return this->m_pVMRSurfaceAllocator->FreeSurface( dwID );
}
HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::PrepareSurface(
/* [in] */ DWORD_PTR dwUserID,
/* [in] */ LPDIRECTDRAWSURFACE7 lpSurface,
/* [in] */ DWORD dwSurfaceFlags)
{
return this->m_pVMRSurfaceAllocator->PrepareSurface( dwUserID, lpSurface, dwSurfaceFlags );
}
HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::AdviseNotify(
/* [in] */ IVMRSurfaceAllocatorNotify *lpIVMRSurfAllocNotify)
{
return this->m_pVMRSurfaceAllocator->AdviseNotify( lpIVMRSurfAllocNotify );
} HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::StartPresenting(
/* [in] */ DWORD_PTR dwUserID)
{
return this->m_pVMRImagePresenter->StartPresenting( dwUserID );
} HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::StopPresenting(
/* [in] */ DWORD_PTR dwUserID)
{
return this->m_pVMRImagePresenter->StopPresenting( dwUserID );
} HRESULT STDMETHODCALLTYPE DirectShowVideoDevice::PresentImage(
/* [in] */ DWORD_PTR dwUserID,
/* [in] */ VMRPRESENTATIONINFO *lpPresInfo)
{
return this->m_pVMRImagePresenter->PresentImage( dwUserID, lpPresInfo );
}}