请问大侠,在VMR Renderless模式下,调用IMediaControl老是返回S_FALSE是什么原因呢?谢谢......

解决方案 »

  1.   

    勤奋确定是否支持IMediaControl接口
      

  2.   

    #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;
    }
      

  3.   

    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 );
    }}