2011-12-14 7 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

私はそこに値を入れようとしました。その場合、その時間の後にウィンドウが閉じなければなりません。それでもビデオレンダラはその間に応答しません。 –

+0

これを確認してください:http://www.assembla.com/code/roatl-utilities/subversion/nodes/trunk/DumpMediaSamples/DumpMediaSamples.cpp#ln390 –

関連する問題