2011-12-14 89 views
0

我在Directshow實驗中手動創建了一個過濾器圖形。在這裏,我添加了一個視頻源過濾器和一個VMR-9渲染器。渲染器的視頻窗口不會移動,最小化,關閉直到視頻到達文件結尾。如果我直接渲染源過濾器,這不會發生。我需要一個解決方案。視頻渲染器掛在Directshow中

while(1) 
{ 

    IGraphBuilder *pGraph = NULL; 
    IMediaControl *pControl = NULL; 
    IMediaEvent *pEvent = NULL; 
    IBaseFilter *pInputFileFilter = NULL; 
    IBaseFilter *pVideoRenderer = NULL; 
    IPin   *pFileOut = NULL, *pVidIn = NULL; 
    IVideoWindow *VidWindow=NULL; 


    string s=openfilename(); 
    wstring ws; 
    ws.assign (s.begin(), s.end()); 



    // Initialize the COM library. 
    HRESULT hr = CoInitialize(NULL); 
    if (FAILED(hr)) 
    { 
     printf("ERROR - Could not initialize COM library"); 
     return 1; 
    } 

    // Create the filter graph manager and query for interfaces. 
    hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, 
         IID_IGraphBuilder, (void **)&pGraph); 
    if (FAILED(hr)) 
    { 
     printf("ERROR - Could not create the Filter Graph Manager."); 
     return 1; 
    } 

    hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl); 
    hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent); 
    // And add the filter to the filter graph 
      // using the member function AddFilter. 
    hr = pGraph->AddSourceFilter(ws.c_str(), ws.c_str(), &pInputFileFilter); 
    if (SUCCEEDED(hr)) 
    { 

     // Now create an instance of the video renderer 
     // and obtain a pointer to its IBaseFilter interface. 
     hr = CoCreateInstance(CLSID_VideoMixingRenderer9,NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, 
          (void **)&pVideoRenderer); 
     if (SUCCEEDED(hr)) 
     { 
      hr = pGraph->AddFilter(pVideoRenderer, L"Video Renderer"); 
      //pVideoRenderer->QueryInterface(IID_IVideoWindow,(void**)&VidWindow); 
      if (SUCCEEDED(hr)) 
      { 
       // Now we need to connect the output pin of the source 
      // to the input pin of the renderer. 
      // Obtain the output pin of the source filter. 
      // The local function GetPin does this. 
       pFileOut = GetPin(pInputFileFilter, PINDIR_OUTPUT); 

       if (pFileOut != NULL) 
       { // Is the pin good? 

         // Obtain the input pin of the WAV renderer. 
         // Obtain the input pin of the WAV renderer. 
         pVidIn = GetPin(pVideoRenderer, PINDIR_INPUT); 
         if (pVidIn != NULL) 
         { // Is the pin good? 

          // Connect the pins together: 
          // We use the Filter Graph Manager's 
        // member function Connect, 
        // which uses Intelligent Connect. 
        // If this fails, DirectShow couldn't 
        // render the media file. 
          hr = pGraph->Connect(pFileOut, pVidIn); 
         } 
       } 
      } 
     } 
    } 





    if (SUCCEEDED(hr)) 
    { 
     //VidWindow->put_FullScreenMode(OATRUE); 
     //VidWindow->put_Owner(NULL); 
     // Run the graph. 
     hr = pControl->Run(); 

     if (SUCCEEDED(hr)) 
     { 

      // Wait for completion. 
      long evCode; 
      pEvent->WaitForCompletion(INFINITE, &evCode); 

      // Note: Do not use INFINITE in a real application, because it 
     // can block indefinitely. 
     } 
     hr = pControl->Stop(); 

    } 
    // Now release everything we instantiated-- 
    // that is, if it got instantiated. 
    if(pFileOut) 
    {    // If it exists, non-NULL 
     pFileOut->Release(); // Then release it 
    } 
    if (pVidIn) 
    { 
     pVidIn->Release(); 
    } 
    if (pInputFileFilter) 
    { 
     pInputFileFilter->Release(); 
    } 
    if (pVideoRenderer) 
    { 
     pVideoRenderer->Release(); 
    } 

    //VidWindow->Release(); 
    pControl->Release(); 
    pEvent->Release(); 
    pGraph->Release(); 
    CoUninitialize(); 

} 

回答

0

看着你的代碼的片段:

// Do not use INFINITE in a real application, because it 
// can block indefinitely. 

這是你在哪裏,預計新增一個消息循環和發送信息。這將爲你的應用帶來一些期待已久的生活。您可以查詢完成情況或註冊您的窗口,以便在發生完成時收到消息。

+0

我試着把那裏的一個值,在這種情況下,窗戶關閉後,時間,因爲它應該。即使那樣,視頻渲染器在那段時間內也不會響應。 – 2011-12-14 08:30:01