昨天努了一天,终于搞完了一个全手动连接的filter graph 程序,虽然很简单,但是还是费了老大的劲。不扯了,上菜……
开发环境:Vista+VS2008+DX9.0,控制台应用程序(便于调试)
第一步:在GraphEdit中模拟视频播放过程。
我的graph图如下,如果不能正常播放,先要注册需要的filter,我就注册了MPEG Layer-3 Decoder:
第二步:动手编程吧。
1、包含文件:
#include "stdafx.h"
#include <dshow.h>
#include <dshow.h>
#pragma comment(lib, "strmiids.lib")
2、定义自己注册的filter,在main()函数前进行定义:
static const GUID CLSID_AudioDecoder=
{ 0x38BE3000,0xDBF4,0x11D0,{0x86,0x0e,0x00,0xa0,0x24,0xcf,0xef,0x6d}};
{ 0x38BE3000,0xDBF4,0x11D0,{0x86,0x0e,0x00,0xa0,0x24,0xcf,0xef,0x6d}};
3、定义需要用到的COM组件:
IGraphBuilder *pGraph = NULL;
IMediaControl *pControl = NULL;
IMediaEvent *pEvent = NULL;
IBaseFilter *pInputFileFilter = NULL;
IBaseFilter *pAviSplitter= NULL;
IBaseFilter *pVideoDecoder= NULL;
IBaseFilter *pVideoColour= NULL;
IBaseFilter *pAudioDecoder= NULL;
IBaseFilter *pDVideoRenderer=NULL;
IBaseFilter *pDSoundRenderer = NULL;
IPin *pFileOut = NULL, *pSplitterIn=NULL,
*pSplitterOut1=NULL,*pSplitterOut2=NULL,
*pVideoDecIn = NULL,*pVideoDecOut = NULL,*pVideoColIn = NULL,*pVideoColOut = NULL,
*pVideoRenIn = NULL,*pAudioDecIn = NULL,*pAudioDecOut = NULL,*pAudioRenIn = NULL;
IMediaControl *pControl = NULL;
IMediaEvent *pEvent = NULL;
IBaseFilter *pInputFileFilter = NULL;
IBaseFilter *pAviSplitter= NULL;
IBaseFilter *pVideoDecoder= NULL;
IBaseFilter *pVideoColour= NULL;
IBaseFilter *pAudioDecoder= NULL;
IBaseFilter *pDVideoRenderer=NULL;
IBaseFilter *pDSoundRenderer = NULL;
IPin *pFileOut = NULL, *pSplitterIn=NULL,
*pSplitterOut1=NULL,*pSplitterOut2=NULL,
*pVideoDecIn = NULL,*pVideoDecOut = NULL,*pVideoColIn = NULL,*pVideoColOut = NULL,
*pVideoRenIn = NULL,*pAudioDecIn = NULL,*pAudioDecOut = NULL,*pAudioRenIn = NULL;
4、COM库初始化:
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if (FAILED(hr))
{
printf("ERROR - Could not initialize COM library");
if (FAILED(hr))
{
printf("ERROR - Could not initialize COM library");