Upload
darel-zzarco
View
220
Download
0
Embed Size (px)
Citation preview
8/2/2019 DShow Tutorial
1/15
A Tutorial toDirectShow
Ruigang Yang
August, 2001
8/2/2019 DShow Tutorial
2/15
What is DirectShowA part of the DirectX family
Play almost any type of media
Dx8.1
DirectXDirect3D
DirectPlay
DirectShow
DirectMusic
DirectDraw
8/2/2019 DShow Tutorial
3/15
DirectShow Overview
8/2/2019 DShow Tutorial
4/15
Pros and ConsBenefits
Very very flexible architecture
Reusable components (filters)
Downside
You are doomed with M$
Learn the Window programming
MFC (you dont have to, but better to)
8/2/2019 DShow Tutorial
5/15
DirectShow FiltersThe basic building block, which can
Read files.
Get video from a video capture device.
Code/decode streams
Pass data to the graphics or sound card.
An sample MPEG filter
8/2/2019 DShow Tutorial
6/15
Filter GraphSeveral filters connected together to
perform a specific task
8/2/2019 DShow Tutorial
7/15
Filter Graph ManagerHigh-level API to the APP
Controls the data flow in the filters
Simple API
AddFilter, queryInterface
Run, stop, and pause
8/2/2019 DShow Tutorial
8/15
DemoGraph Builder
(mssdkDirectX utilityGraph Builder)
8/2/2019 DShow Tutorial
9/15
Writing a Dshow App.DirectShow API through COM
interface
Component Object Model (COM) Getting a pointer to the interface
ptr = CoCreateInstance()
Release the pointer after you are doneptr->Release()
8/2/2019 DShow Tutorial
10/15
Three steps
Create filter graph ganager (FGM)
Create the filter graph (through FGM)
Run the graph and respond to event
8/2/2019 DShow Tutorial
11/15
Hello World
COM Init, Remember this
Get DS Interface
Release COM pointer
#include
void main(void) {
IGraphBuilder *pGraph; IMediaControl *pMediaControl; IMediaEvent *pEvent;
CoInitialize(NULL);
// Create the filter graph manager and query for interfaces.
CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
IID_IGraphBuilder, (void **)&pGraph);
pGraph->QueryInterface(IID_IMediaControl, (void **)&pMediaControl);
pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
// Build the graph.
pGraph->RenderFile(L"C:\\Hello_World.avi", NULL);
pMediaControl->Run(); // Run the graph.
pEvent->WaitForCompletion(INFINITE, &evCode); // Wait for completion.
// Clean up.
pMediaControl->Release(); pEvent->Release(); pGraph->Release();
CoUninitialize(); }
8/2/2019 DShow Tutorial
12/15
Building Filter GraphAdd filters to the FGM
Two ways
Intelligent connect (as in previous
example)
Manual connect (pout pin)
Format negotiation
8/2/2019 DShow Tutorial
13/15
Frame grabberSample Grabber Filter
8/2/2019 DShow Tutorial
14/15
A Few TipsMulti-thread
Avoid in-place transform filter
Image origins
A few useful filters Color space converter
T-adaptor
Stream-multiplex
8/2/2019 DShow Tutorial
15/15
ReferencesMSDN