《DirectShow开发指南》 范例源代码 中的AppIPTransform
这是学习时的笔记注解,主要是便于理清头绪,去其枝叶,知其轮廓,省得自己在云里雾里找不到北
声明变量
CAppTransform* m_pFilter;
IGraphBuilder* m_pGraph;
BuildFromFile{
实例化FilterGraph
HRESULT hr = CoCreateInstance(
CLSID_FilterGraph,
NULL,
CLSCTX_INPROC,
IID_IGraphBuilder,
(void**)&m_pGraph);
// For GraphEdit Dubug purpose
AddToObjectTable();
{
if (SUCCEEDED(GetRunningObjectTable(0, &objectTable)))
HRESULT hr = CreateItemMoniker(L"!", wsz, &pMoniker);
hr = objectTable->Register(0, m_pGraph, pMoniker, &m_dwObjectTable);
}
//加载文件
hr = m_pGraph->RenderFile(pszFile, NULL);
// Try to find the video renderer, by looking for IVideoWindow
hr = FindFilterByInterface(IID_IVideoWindow, &pVR);
{
//looking for a specific interface on the filter
hr = m_pGraph->EnumFilters(&pEnum);
while (pEnum->Next(1, &pFilter, NULL) == S_OK) {
HRESULT hrQuery = pFilter->QueryInterface(riid, (void**)&pUnk);
}
}
//输入Pin
IPin* pPin = InputPinOf(pVR);
//得到输入媒体类信息
AM_MEDIA_TYPE mt;
pPin->ConnectionMediaType(&mt);
//创建transform并加入graph
CreateAppFilter();{
m_pFilter = new CAppTransform(NULL, &hr);
m_pFilter->AddRef();
hr = m_pFilter->QueryInterface(IID_IBaseFilter, (void**)&pFilter);
hr = m_pGraph->AddFilter(pFilter, L"App Transform");
IPin* pPinIn = InputPinOf(pFilter);
}
//Try to insert our transform filter
hr = ConnectUpstreamOf(pVR, m_pFilter){
IPin* pPinIn = InputPinOf(pFilter);
//Pin预连结测试
HRESULT hr = pPinIn->ConnectedTo(&pPinOut);
//断开Pin连结
hr = m_pGraph->Disconnect(pPinOut);
hr = m_pGraph->Disconnect(pPinIn);
//pin中间插入pTransform filter
// Insert pTransform filter by connecting its input pin and output pin
IPin* pPinInXfm = InputPinOf(pTransform);
hr = m_pGraph->Connect(pPinOut, pPinInXfm);
IPin* pPinOutXfm = OutputPinOf(pTransform);
hr = m_pGraph->Connect(pPinOutXfm, pPinIn);
}
}
//窗口设置
m_Graph.MakeChild(GetSafeHwnd()){
HRESULT hr = m_pGraph->QueryInterface(IID_IVideoWindow, (void**)&pVW);
}
//运行
m_Graph.Run(){
HRESULT hr = m_pGraph->QueryInterface(IID_IMediaControl, (void**)&pControl);
}
//程序退出
DestroyGraph();
CoUninitialize();
阅读(2087) | 评论(0) | 转发(0) |