cngreatwall

赫赫盛唐艺轩

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

HRESULT CVideoSource::AddWindowLessRender( HWND hwndApp, RECT win_rect)                  // Window to hold the video.
{

 HRESULT hr = NULL;
 CRect rcSrc, rcDest;
 hr=CoCreateInstance(CLSID_VideoMixingRenderer, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **)&m_pVideoRender);
 if(hr!=S_OK)return hr;
 // Create the VMR.

 // Add the VMR to the filter graph.
 hr = m_pGrapher->AddFilter(m_pVideoRender, L"Video Mixing Renderer");
 if (FAILED(hr))
 {
  m_pVideoRender->Release();
  return hr;
 }
 // Set the rendering mode. 
 long lWidth, lHeight, lARWidth, lARHeight;
 hr = m_pVideoRender->QueryInterface(IID_IVMRFilterConfig, (void**)&m_pFilterConfig);
 if (FAILED(hr))
 {
  m_pVideoRender->Release();
  return hr;
 }
 
 hr = m_pFilterConfig->SetRenderingMode(VMRMode_Windowless); //
 if (FAILED(hr))
 {
  m_pVideoRender->Release();
  return hr;
 }
 
 // Set the window.
 hr = m_pVideoRender->QueryInterface(IID_IVMRWindowlessControl, (void**)&m_pWindowsLessControl);
 if (FAILED(hr))
 {
  m_pVideoRender->Release();
  return hr;
 }
 if (m_bSetVedioFormat)  //当进行视频调整时,进行格式设置
 {
  hr =  UpdateVideoCapConfig();
  m_bSetVedioFormat = false; //视频格式调整结束,开关置为原位
 }
 //RenderStream();
 IPin *pPin2;
 hr = m_pBuilder->FindPin(m_pSmartTee, PINDIR_OUTPUT, 0, 0, TRUE, 1, &pPin2);
 hr = m_pBuilder->RenderStream(0, 0, pPin2, 0, m_pVideoRender);
 //hr = m_pBuilder->RenderStream(0, 0, m_pSmartTee, 0, m_pVideoRender);
 

 //hr=m_pBuilder->RenderStream(
 // &PIN_CATEGORY_PREVIEW,  //&PIN_CATEGORY_CAPTURE,  // Pin category
 // &MEDIATYPE_Video,       // Media type
 // m_pSmartTee, //m_pVideoCap,                   // Capture filter
 // NULL, //m_pVidCompress,                   // Compression filter (optional)
 // m_pVideoRender                     // Multiplexer or renderer filter
 // );
 hr = m_pWindowsLessControl->SetVideoClippingWindow(hwndApp);
 hr = m_pWindowsLessControl->GetNativeVideoSize(&lWidth, &lHeight,NULL,NULL);
 if (FAILED(hr))
 {
  m_pVideoRender->Release();
  return hr;
 }
 // Set the source rectangle.
 SetRect(&rcSrc, 0, 0, lWidth, lHeight);
 
 // Get the window client area.
 GetClientRect(hwndApp, &rcDest);
 // Set the destination rectangle.
 SetRect(&rcDest, 10, 10, win_rect.right, win_rect.bottom);
 //SetRect(&rcDest, 0, 0, rcDest.right, rcDest.bottom);

 hr = m_pWindowsLessControl->SetVideoPosition(&rcSrc, &rcDest);
 // make sure we process events while we're previewing!
 hr = m_pGrapher->QueryInterface(IID_IMediaEventEx, (void **)&m_pMediaEventEx);
 if(hr == NOERROR)
 {
  m_pMediaEventEx->SetNotifyWindow((OAHWND)hwndApp, WM_FGNOTIFY, 0);
 }
 return hr;
}

posted on 2011-09-02 11:39  cngreatwall  阅读(558)  评论(0)    收藏  举报