• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            In my way

            On my way

            常用鏈接

            統計

            最新評論

            How To Play a File use DirectShow?


            DirectShow application always performs the same basic steps:
            1. Create an instance of the Filter Graph Manager.
            2. Use the Filter Graph Manager to build a filter graph.
            3. Run the graph, causing data to move through the filters.

            Start by calling CoInitialize to initialize the COM library:

            HRESULT hr = CoInitialize(NULL);
            if (FAILED(hr))
            {
            // Add error-handling code here. (Omitted for clarity.)
            }
            

            To keep things simple, this example ignores the return value, but you should always check the HRESULT value from any method call.

            Next, call CoCreateInstance to create the Filter Graph Manager:

            IGraphBuilder *pGraph;
            HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL,
            CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph);
            

            As shown, the class identifier (CLSID) is CLSID_FilterGraph. The Filter Graph Manager is provided by an in-process DLL, so the execution context is CLSCTX_INPROC_SERVER. DirectShow supports the free-threading model, so you can also call CoInitializeEx with the COINIT_MULTITHREADED flag.

            The call to CoCreateInstance returns the IGraphBuilder interface, which mostly contains methods for building the filter graph. Two other interfaces are needed for this example:

            • IMediaControl controls streaming. It contains methods for stopping and starting the graph.
            • IMediaEvent has methods for getting events from the Filter Graph Manager. In this example, the interface is used to wait for playback to complete.

            Both of these interfaces are exposed by the Filter Graph Manager. Use the returned IGraphBuilder pointer to query for them:

            IMediaControl *pControl;
            IMediaEvent   *pEvent;
            hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
            hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
            

            Now you can build the filter graph. For file playback, this is done by a single method call:

            hr = pGraph->RenderFile(L"C:\\Example.avi", NULL);
            

            The IGraphBuilder::RenderFile method builds a filter graph that can play the specified file. The first parameter is the file name, represented as a wide character (2-byte) string. The second parameter is reserved and must equal NULL.

            This method can fail if the specified file does not exist, or the file format is not recognized. Assuming that the method succeeds, however, the filter graph is now ready for playback. To run the graph, call the IMediaControl::Run method:

            hr = pControl->Run();
            

            When the filter graph runs, data moves through the filters and is rendered as video and audio. Playback occurs on a separate thread. You can wait for playback to complete by calling the IMediaEvent::WaitForCompletion method:

            long evCode = 0;
            pEvent->WaitForCompletion(INFINITE, &evCode);
            

            This method blocks until the file is done playing, or until the specified time-out interval elapses. The value INFINITE means the application blocks indefinitely until the file is done playing. For a more realistic example of event handling, see Responding to Events.

            When the application is finished, release the interface pointers and close the COM library:

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

            Sample Code

            Here is the complete code for the example described in this article:



            #include 
            <dshow.h>
            void main(void)
            {
                IGraphBuilder 
            *pGraph = NULL;
                IMediaControl 
            *pControl = NULL;
                IMediaEvent   
            *pEvent = NULL;

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


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


                hr 
            = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
                hr 
            = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);

                
            // Build the graph. IMPORTANT: Change this string to a file on your system.
                hr = pGraph->RenderFile(L"C:\\Example.avi", NULL);
                
            if (SUCCEEDED(hr))
                
            {
                    
            // 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.
                    }

                }

                pControl
            ->Release();
                pEvent
            ->Release();
                pGraph
            ->Release();
                CoUninitialize();
            }



            posted on 2009-04-09 10:26 谷主 閱讀(549) 評論(0)  編輯 收藏 引用

            久久人妻少妇嫩草AV蜜桃| 91久久九九无码成人网站| 日本精品久久久久影院日本| 久久久久亚洲AV综合波多野结衣 | 久久亚洲国产最新网站| 婷婷久久精品国产| 久久久久国产精品熟女影院| 999久久久免费精品国产| 国产精品内射久久久久欢欢| 亚洲国产成人精品91久久久| 久久久久人妻一区精品色| 久久久亚洲精品蜜桃臀| 久久综合噜噜激激的五月天| 久久一本综合| 久久99国产精品久久99果冻传媒 | 麻豆成人久久精品二区三区免费| 91精品国产91久久综合| 久久亚洲精品国产精品婷婷| 7国产欧美日韩综合天堂中文久久久久 | 97久久超碰国产精品2021| 伊人久久大香线蕉综合热线| 亚洲国产精久久久久久久| 亚洲av成人无码久久精品| 热综合一本伊人久久精品| 品成人欧美大片久久国产欧美... 品成人欧美大片久久国产欧美 | 久久久久久久亚洲Av无码| 漂亮人妻被中出中文字幕久久| 国产巨作麻豆欧美亚洲综合久久 | 免费一级做a爰片久久毛片潮| 国内精品久久久久久99蜜桃 | 久久久无码一区二区三区| 99精品国产99久久久久久97| 久久综合给合综合久久| 狠狠精品干练久久久无码中文字幕 | 久久精品国产亚洲Aⅴ蜜臀色欲| 国产精品岛国久久久久| 亚洲国产一成人久久精品| 久久精品国产亚洲AV香蕉| 久久精品桃花综合| 久久精品国产亚洲AV影院| 婷婷综合久久中文字幕蜜桃三电影|