1 / 60

Microsoft DirectShow

Microsoft DirectShow. Introduction. DirectShow 是 Microsoft 所提供的函式庫 透過 DirectShow, 我們可以很容易的處理電腦上的多媒體資料 : 如聲音 , 影像等. Software Requirements. Operation system Windows XP Development tool Microsoft Visual Studio .NET Visual C++ .NET. Install DirectX 9.0 SDK. 到網站下載 SDK 安裝程式

ranit
Télécharger la présentation

Microsoft DirectShow

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Microsoft DirectShow

  2. Introduction • DirectShow 是 Microsoft 所提供的函式庫 • 透過 DirectShow, 我們可以很容易的處理電腦上的多媒體資料: 如聲音,影像等

  3. Software Requirements • Operation system • Windows XP • Development tool • Microsoft Visual Studio .NET • Visual C++ .NET

  4. Install DirectX 9.0 SDK • 到網站下載 SDK 安裝程式 • http://msdn.microsoft.com/downloads/ • 點選 DirectX 9.0 Software Development Kit with DirectX 9.0b Runtime • 執行所下載程式 • 透過安裝介面選擇要安裝的目錄 • 程式將自動安裝 SDK

  5. Preparing for Compilation • 設定工作環境 • Add include search paths • Add linker search paths • Add project link libraries

  6. Add include search paths (1) • choose Options from the Tools menu

  7. Add include search paths (2) • Select Directories tag Double click the left button on the mouse

  8. Add include search paths (3) • Select the SDK include search path Type or browse to select the search path

  9. Add include search paths (4) • Shift the include search path to the top of the search directories Press this icon

  10. Add linker search paths (1) • choose Options from the Tools menu

  11. Add linker search paths (2) • Select Directories tag Double click the left button on the mouse

  12. Add linker search paths (3) • Select the SDK include search path Type or browse to select the search path

  13. Add linker search paths (4) • Shift the include search path to the top of the search directories Press this icon

  14. Add project link libraries (1) • choose settings from the Project menu

  15. Add project link libraries (2) • Select the link tag type the name of the project link library

  16. DirectShow Example

  17. Filter • DirectShow 中處理 media stream 的基本元件 • 根據功能,可分成三類 • Source filter • Transform filter • Renderer filter

  18. Filter Graph • 將 source filter, transform filter, and Renderer filter 串接起來而形成的圖

  19. Source Filter • 從 data source 獲取資料,並將資料傳送到 filter graph 中 • 資料源可以是攝影機、網際網路、磁片檔等

  20. Transform Filter • 獲取、處理和傳送媒體資料 • Examples • Splitter transform filter • Video decoder • Audio decoder

  21. Renderer Filter • 在硬體上表現媒體資料,如顯示卡和音效卡,或者是任何可以接受媒體資料的地方,如磁片。 • Example • Video renderer filter • Audio renderer filter。

  22. Filter Graph Manager • 掌管 Filter Graph 中 filters 的連接 • 控制 media stream 在 filter 之間的流動

  23. Filter Graph Manager (cont.) • 程式開發人員可透過 API 函數對media stream 控制 • Examples • Run: 啟動 media stream 在 Filter graph 中的流動 • Pause:暫停 media stream 的播放 • Stop:停止播放 media stream

  24. DirectShow 工具示範 Graph Editor

  25. Programming DirectShow Applications Play a File Building a Filter Graph

  26. Interface 1 Interface 2 Interface n Preliminary • DirectShow • Based on Component Object Model(COM) • COM COM object

  27. Coding Flowchart Initializing the COM facilities Creating an Instance of a COM Object Querying Interfaces in the COM Object Running some applications Releasing the COM interfaces Releasing the COM facilities

  28. Initializing the COM facilities Creating an Instance of a COM Object Querying Interfaces in the COM Object Running some applications Releasing the COM interfaces Releasing the COM facilities Example CoInitialize (NULL) //Initializes COM IGraphBuilder *pGraphBuilder = NULL; // Pointer to created object HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraphBuilder); IMediaControl *pMediaControl = NULL; // Store pointer to interface hr = pGraphBuilder->QueryInterface(IID_MediaControl, (void**)&pMediaControl); .…..……Some executions………… pMediaControl->Release(); // Release the object pMediaControl = NULL; // And set it to NULL pGraphBuilder->Release(); // Release the object pGraphBuilder = NULL; // And set it to NULL CoUninitialize(); // Releases COM

  29. Initializing the COM facilities Creating an Instance of a COM Object Querying Interfaces in the COM Object Running some applications Releasing the COM interfaces Releasing the COM facilities Example Object name CoInitialize (NULL) //Initializes COM IGraphBuilder *pGraphBuilder = NULL; // Pointer to created object HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraphBuilder); IMediaControl *pMediaControl = NULL; // Store pointer to interface hr = pGraphBuilder->QueryInterface(IID_MediaControl, (void**)&pMediaControl); .…..……Some executions………… Interface name pMediaControl->Release(); // Release the object pMediaControl = NULL; // And set it to NULL pGraphBuilder->Release(); // Release the object pGraphBuilder = NULL; // And set it to NULL CoUninitialize(); // Releases COM

  30. Initializing the COM facilities Creating an Instance of a COM Object Querying Interfaces in the COM Object Running some applications Releasing the COM interfaces Releasing the COM facilities Example CoInitialize (NULL) //Initializes COM IGraphBuilder *pGraphBuilder = NULL; // Pointer to created object HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraphBuilder); IMediaControl *pMediaControl = NULL; // Store pointer to interface hr = pGraphBuilder->QueryInterface(IID_MediaControl, (void**)&pMediaControl); .…..……Some executions………… pMediaControl->Release(); // Release the object pMediaControl = NULL; // And set it to NULL pGraphBuilder->Release(); // Release the object pGraphBuilder = NULL; // And set it to NULL CoUninitialize(); // Releases COM

  31. Initializing the COM facilities Creating an Instance of a COM Object Querying Interfaces in the COM Object Running some applications Releasing the COM interfaces Releasing the COM facilities Example CoInitialize (NULL) //Initializes COM Interface name IGraphBuilder *pGraphBuilder = NULL; // Pointer to created object HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraphBuilder); IMediaControl *pMediaControl = NULL; // Store pointer to interface hr = pGraphBuilder->QueryInterface(IID_MediaControl, (void**)&pMediaControl); .…..……Some executions………… pMediaControl->Release(); // Release the object pMediaControl = NULL; // And set it to NULL pGraphBuilder->Release(); // Release the object pGraphBuilder = NULL; // And set it to NULL CoUninitialize(); // Releases COM

  32. Initializing the COM facilities Creating an Instance of a COM Object Querying Interfaces in the COM Object Running some applications Releasing the COM interfaces Releasing the COM facilities Example CoInitialize (NULL) //Initializes COM IGraphBuilder *pGraphBuilder = NULL; // Pointer to created object HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraphBuilder); IMediaControl *pMediaControl = NULL; // Store pointer to interface hr = pGraphBuilder->QueryInterface(IID_MediaControl, (void**)&pMediaControl); .…..……Some executions………… pMediaControl->Release(); // Release the object pMediaControl = NULL; // And set it to NULL pGraphBuilder->Release(); // Release the object pGraphBuilder = NULL; // And set it to NULL CoUninitialize(); // Releases COM

  33. Initializing the COM facilities Creating an Instance of a COM Object Querying Interfaces in the COM Object Running some applications Releasing the COM interfaces Releasing the COM facilities Example CoInitialize (NULL) //Initializes COM IGraphBuilder *pGraphBuilder = NULL; // Pointer to created object HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraphBuilder); IMediaControl *pMediaControl = NULL; // Store pointer to interface hr = pGraphBuilder->QueryInterface(IID_MediaControl, (void**)&pMediaControl); .…..……Some executions………… pMediaControl->Release(); // Release the object pMediaControl = NULL; // And set it to NULL pGraphBuilder->Release(); // Release the object pGraphBuilder = NULL; // And set it to NULL CoUninitialize(); // Releases COM

  34. Initializing the COM facilities Creating an Instance of a COM Object Querying Interfaces in the COM Object Running some applications Releasing the COM interfaces Releasing the COM facilities Example CoInitialize (NULL) //Initializes COM IGraphBuilder *pGraphBuilder = NULL; // Pointer to created object HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraphBuilder); IMediaControl *pMediaControl = NULL; // Store pointer to interface hr = pGraphBuilder->QueryInterface(IID_MediaControl, (void**)&pMediaControl); .…..……Some executions………… pMediaControl->Release(); // Release the object pMediaControl = NULL; // And set it to NULL pGraphBuilder->Release(); // Release the object pGraphBuilder = NULL; // And set it to NULL CoUninitialize(); // Releases COM

  35. Initializing the COM facilities Creating an Instance of a COM Object Querying Interfaces in the COM Object Running some applications Releasing the COM interfaces Releasing the COM facilities Example CoInitialize (NULL) //Initializes COM IGraphBuilder *pGraphBuilder = NULL; // Pointer to created object HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraphBuilder); IMediaControl *pMediaControl = NULL; // Store pointer to interface hr = pGraphBuilder->QueryInterface(IID_MediaControl, (void**)&pMediaControl); .…..……Some executions………… pMediaControl->Release(); // Release the object pMediaControl = NULL; // And set it to NULL pGraphBuilder->Release(); // Release the object pGraphBuilder = NULL; // And set it to NULL CoUninitialize(); // Releases COM

  36. Initializing the COM facilities Creating an Instance of a COM Object Querying Interfaces in the COM Object Running some applications Releasing the COM interfaces Releasing the COM facilities Example CoInitialize (NULL) //Initializes COM IGraphBuilder *pGraphBuilder = NULL; // Pointer to created object HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraphBuilder); IMediaControl *pMediaControl = NULL; // Store pointer to interface hr = pGraphBuilder->QueryInterface(IID_MediaControl, (void**)&pMediaControl); .…..……Some executions………… pMediaControl->Release(); // Release the object pMediaControl = NULL; // And set it to NULL pGraphBuilder->Release(); // Release the object pGraphBuilder = NULL; // And set it to NULL CoUninitialize(); // Releases COM

  37. Some interfaces • IGraphBuilder • provides methods that enable an application to build a filter graph • methods:AddSourceFilter, Connect, RenderFile, etc. • IMediaControl • provides methods for controlling the flow of data through the filter graph • methods: Run, Pause, Stop, etc. • IMediaEvent • contains methods for retrieving event notifications • methods: GetEvent, WaitForCompletion, etc.

  38. 1. Play a File #include <dshow.h> void main(void) { IGraphBuilder *pGraph; IMediaControl *pMediaControl; //Handles media streaming in the filter graph IMediaEvent *pEvent; //Handles filter graph events Create the COM object CoInitialize(NULL); // Create the filter graph manager and query for interfaces. CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph); Query Interfaces in the COM object pGraph->QueryInterface(IID_IMediaControl, (void **)&pMediaControl); pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);

  39. 1. Play a File // Build the graph. IMPORTANT: Change string to a file on your system. pGraph->RenderFile(L"C:\\Example.avi", NULL); // Run the graph. pMediaControl->Run(); // Wait for completion. long evCode; pEvent->WaitForCompletion(INFINITE, &evCode); Running …. Release the Interfaces // Clean up. pMediaControl->Release(); pEvent->Release(); pGraph->Release(); CoUninitialize(); } Release the COM

  40. 1. Play a File // Build the graph. //IMPORTANT: Change string to a file on your system. pGraph->RenderFile(L"C:\\Example.avi", NULL); // Run the graph. pMediaControl->Run(); // Wait for completion. long evCode; pEvent->WaitForCompletion(INFINITE, &evCode); // Clean up. pMediaControl->Release(); pEvent->Release(); pGraph->Release(); CoUninitialize(); }

  41. FilterGraph 2. Building a Filter Graph InputFileFilter DSoundRenderer

  42. 2. Building a Filter Graph #include <dshow.h> int main(int argc, char* argv[]) { IGraphBuilder *pGraph = NULL; IMediaControl *pControl = NULL; //Handles media streaming in the filter graph IMediaEvent *pEvent = NULL; //Handles filter graph events IBaseFilter *pInputFileFilter = NULL; IBaseFilter *pDSoundRenderer = NULL; IPin *pFileOut = NULL, *pWAVIn = NULL; // Initialize the COM library. HRESULT hr = CoInitialize(NULL); hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph); // Now get the media control interface... hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl); // And the media event interface. hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent); hr = pGraph->AddSourceFilter(L“C:\\test.mpg", L“Source File", &pInputFileFilter);

  43. FilterGraph 2. Building a Filter Graph #include <dshow.h> int main(int argc, char* argv[]) { IGraphBuilder *pGraph = NULL; IMediaControl *pControl = NULL; //Handles media streaming in the filter graph IMediaEvent *pEvent = NULL; //Handles filter graph events IBaseFilter *pInputFileFilter = NULL; IBaseFilter *pDSoundRenderer = NULL; IPin *pFileOut = NULL, *pWAVIn = NULL;); hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph); // Now get the media control interface... hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl); // And the media event interface. hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent); InputFileFilter DSoundRenderer hr = pGraph->AddSourceFilter(L“C:\\test.mpg", L“Source File", &pInputFileFilter);

  44. 2. Building a Filter Graph #include <dshow.h> int main(int argc, char* argv[]) { IGraphBuilder *pGraph = NULL; IMediaControl *pControl = NULL; //Handles media streaming in the filter graph IMediaEvent *pEvent = NULL; //Handles filter graph events IBaseFilter *pInputFileFilter = NULL; IBaseFilter *pDSoundRenderer = NULL; IPin *pFileOut = NULL, *pWAVIn = NULL; // Initialize the COM library. HRESULT hr = CoInitialize(NULL); hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph); // Now get the media control interface... hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl); // And the media event interface. hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent); hr = pGraph->AddSourceFilter(L“C:\\test.mpg", L“Source File", &pInputFileFilter);

  45. FilterGraph 2. Building a Filter Graph #include <dshow.h> int main(int argc, char* argv[]) { IGraphBuilder *pGraph = NULL; IMediaControl *pControl = NULL; //Handles media streaming in the filter graph IMediaEvent *pEvent = NULL; //Handles filter graph events IBaseFilter *pInputFileFilter = NULL; IBaseFilter *pDSoundRenderer = NULL; IPin *pFileOut = NULL, *pWAVIn = NULL; // Initialize the COM library. HRESULT hr = CoInitialize(NULL); InputFileFilter File name hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph); // Now get the media control interface... hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl); // And the media event interface. hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent); hr = pGraph->AddSourceFilter(L“C:\\test.mpg", L“Source File", &pInputFileFilter); Filter name

  46. 2. Building a Filter Graph hr = CoCreateInstance(CLSID_DSoundRender, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **)&pDSoundRenderer); // And add the filter to the filter graph // using the member function AddFilter. hr = pGraph->AddFilter(pDSoundRenderer, L"Audio Renderer"); // Obtain the output pin of the source filter. // The local function GetPin does this. pFileOut = GetPin(pInputFileFilter, PINDIR_OUTPUT); // Obtain the input pin of the WAV renderer. pWAVIn = GetPin(pDSoundRenderer, PINDIR_INPUT); hr = pGraph->Connect(pFileOut, pWAVIn); hr = pControl->Run(); long evCode; pEvent->WaitForCompletion(INFINITE, &evCode); hr = pControl->Stop();

  47. FilterGraph 2. Building a Filter Graph hr = CoCreateInstance(CLSID_DSoundRender, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **)&pDSoundRenderer); // And add the filter to the filter graph // using the member function AddFilter. hr = pGraph->AddFilter(pDSoundRenderer, L"Audio Renderer"); Object name // Obtain the output pin of the source filter. // The local function GetPin does this. pFileOut = GetPin(pInputFileFilter, PINDIR_OUTPUT); // Obtain the input pin of the WAV renderer. pWAVIn = GetPin(pDSoundRenderer, PINDIR_INPUT); Filter name hr = pGraph->Connect(pFileOut, pWAVIn); hr = pControl->Run(); long evCode; pEvent->WaitForCompletion(INFINITE, &evCode); hr = pControl->Stop(); InputFileFilter DSoundRenderer

  48. 2. Building a Filter Graph hr = CoCreateInstance(CLSID_DSoundRender, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **)&pDSoundRenderer); // And add the filter to the filter graph // using the member function AddFilter. hr = pGraph->AddFilter(pDSoundRenderer, L"Audio Renderer"); // Obtain the output pin of the source filter. // The local function GetPin does this. pFileOut = GetPin(pInputFileFilter, PINDIR_OUTPUT); // Obtain the input pin of the WAV renderer. pWAVIn = GetPin(pDSoundRenderer, PINDIR_INPUT); hr = pGraph->Connect(pFileOut, pWAVIn); hr = pControl->Run(); long evCode; pEvent->WaitForCompletion(INFINITE, &evCode); hr = pControl->Stop();

  49. FilterGraph 2. Building a Filter Graph hr = CoCreateInstance(CLSID_DSoundRender, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **)&pDSoundRenderer); // And add the filter to the filter graph // using the member function AddFilter. hr = pGraph->AddFilter(pDSoundRenderer, L"Audio Renderer"); // Obtain the output pin of the source filter. // The local function GetPin does this. pFileOut = GetPin(pInputFileFilter, PINDIR_OUTPUT); // Obtain the input pin of the WAV renderer. pWAVIn = GetPin(pDSoundRenderer, PINDIR_INPUT); hr = pGraph->Connect(pFileOut, pWAVIn); hr = pControl->Run(); long evCode; pEvent->WaitForCompletion(INFINITE, &evCode); hr = pControl->Stop(); InputFileFilter DSoundRenderer

  50. 2. Building a Filter Graph hr = CoCreateInstance(CLSID_DSoundRender, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **)&pDSoundRenderer); // And add the filter to the filter graph // using the member function AddFilter. hr = pGraph->AddFilter(pDSoundRenderer, L"Audio Renderer"); // Obtain the output pin of the source filter. // The local function GetPin does this. pFileOut = GetPin(pInputFileFilter, PINDIR_OUTPUT); // Obtain the input pin of the WAV renderer. pWAVIn = GetPin(pDSoundRenderer, PINDIR_INPUT); hr = pGraph->Connect(pFileOut, pWAVIn); hr = pControl->Run(); long evCode; pEvent->WaitForCompletion(INFINITE, &evCode); hr = pControl->Stop();

More Related