directshow 之 视频控制

本文详细阐述了视频源播放和停止过程中的关键步骤,包括初始化、渲染视频流、控制流状态以及停止播放操作。


HRESULT CVideoSource::RenderStream( )
{
 //CoInitialize(NULL);
 HRESULT hr = NULL;
 hr=m_pBuilder->RenderStream(
   &PIN_CATEGORY_PREVIEW,  //&PIN_CATEGORY_CAPTURE,  // Pin category
   &MEDIATYPE_Video,       // Media type
   m_pVideoCap,                   // Capture filter
   NULL, //m_pVidCompress,                   // Compression filter (optional)
   NULL //m_pVideoRender                     // Multiplexer or renderer filter
   );
   
 
 if(hr == VFW_S_NOPREVIEWPIN)
 {
  // preview was faked up for us using the (only) capture pin
  //gcap.fPreviewFaked = TRUE;
 }
 else if(hr != S_OK)
 {
  ErrMsg(TEXT("该视频卡不能进行视频浏览,请检查!"));  
 }
 /*
 hr = m_pGrapher->QueryInterface(IID_IVideoWindow, (void **)&m_pVidWin);
 RECT rc;
 m_pVidWin->put_Owner((OAHWND)AfxGetMainWnd()->m_hWnd);    // We own the window now
 m_pVidWin->put_WindowStyle(WS_CHILD);    // you are now a child

 // give the preview window all our space but where the status bar is
 GetClientRect(AfxGetMainWnd()->m_hWnd, &rc);
 

 m_pVidWin->SetWindowPosition(0, 0, rc.right, rc.bottom); // be this big
 m_pVidWin->put_Visible(OATRUE);
 */

 //hr=m_pBuilder->RenderStream(
 // &PIN_CATEGORY_CAPTURE,  // Pin category
 // &MEDIATYPE_Video,       // Media type
 // m_pVideoCap,                   // Capture filter
 // NULL,//m_pVidCompress,                   // Compression filter (optional)
 // m_pVideoRender                     // Multiplexer or renderer filter
 // );

 
 return hr;
}

 


HRESULT CVideoSource::Stop()
{
 // TODO: Add your implementation code here
 HRESULT hr = NULL;
 //REFERENCE_TIME t=0x7FFFFFFFFFFFFFFF;
 //HRESULT hr=m_pBuilder->ControlStream(
 // &PIN_CATEGORY_CAPTURE,//const GUID *pCategory,
 // NULL,//const GUID *pType,
 // NULL,//IBaseFilter *pFilter,
 // &t,//REFERENCE_TIME *pstart,
 // NULL,//REFERENCE_TIME *pstop,
 // 0,//WORD wStartCookie,
 // 0//WORD wStopCookie
 // );
 //// return hr;

 IMediaControl *pMediaControl;
 // HRESULT hr=m_pGraph->QueryInterface(IID_IMediaControl, (void **)&pMediaControl);
 hr=m_pGrapher->QueryInterface(IID_IMediaControl, (void **)&pMediaControl);
 if(hr==S_OK){
  pMediaControl->Stop();
  pMediaControl->Release();
 }
 return hr;

}
HRESULT CVideoSource::Play()
{
 // TODO: Add your implementation code here
 //REFERENCE_TIME t=0x7FFFFFFFFFFFFFFF;
 //m_pBuilder->ControlStream(
 // &PIN_CATEGORY_CAPTURE,//const GUID *pCategory,
 // NULL,//const GUID *pType,
 // NULL,//IBaseFilter *pFilter,
 // NULL,//REFERENCE_TIME *pstart,
 // &t,//REFERENCE_TIME *pstop,
 // 0,//WORD wStartCookie,
 // 0//WORD wStopCookie
 // );

 IMediaControl *pMediaControl;
 HRESULT hr=m_pGrapher->QueryInterface(IID_IMediaControl, (void **)&pMediaControl);
 if(hr==S_OK){
  pMediaControl->Run();
  pMediaControl->Release();
 }
 return hr;
}

转载于:https://www.cnblogs.com/cngreatwall/archive/2011/09/02/2163546.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值