最近在写一个解码yuv的transform filter,文件为.yuv格式,视频大小为320*240,内容为YYYY...Y共320*240个,UUUU..U共160*120个,VVVV...V共160*120.由于不想写SourceFilter,就用系统自带的一个叫做:File Source(Async.)的Source Filter,但是在GraphEdit中调试时,一连线就停止工作,debug时看到Source Filter传过来的视频格式为MEDIATYPE_NULL,和MEDIASUBTYPE_NULL,这样一步一步的调试也不知道哪出了问题,希望大家能帮我一下,谢谢!
下面是大概的源代码
#include <windows.h>
#include <streams.h>
#include <initguid.h>
#include <olectl.h>
#include <fstream>
#include "Decoder.h"
const AMOVIESETUP_MEDIATYPE sudPinTypes=
{
&MEDIATYPE_NULL,
&MEDIASUBTYPE_NULL
};
const AMOVIESETUP_MEDIATYPE outputpinType=
{
&MEDIATYPE_Video,
&MEDIASUBTYPE_NULL
};
const AMOVIESETUP_PIN sudPins[]=
{
{
L"Input", // Pins string name
FALSE, // Is it rendered
FALSE, // Is it an output
FALSE, // Are we allowed none
FALSE, // And allowed many
&CLSID_NULL, // Connects to filter
NULL, // Connects to pin
1, // Number of types
&sudPinTypes // Pin information
},
{
L"Output", // Pins string name
FALSE, // Is it rendered
TRUE, // Is it an output
FALSE, // Are we allowed none
FALSE, // And allowed many
&CLSID_NULL, // Connects to filter
NULL, // Connects to pin
1, // Number of types
&outputpinType // Pin information
}
};
const AMOVIESETUP_FILTER sudDecoder=
{
&CLSID_Decoder, // Filter CLSID
L"A test Decoder", // String name
MERIT_PREFERRED, // Filter merit
2, // Number of pins
sudPins // Pin information
};
CFactoryTemplate g_Templates[]=
{
{
L"A Test Decoder",
&CLSID_Decoder,
Decoder::CreateInstance,
NULL,
&sudDecoder
}
};
int g_cTemplates=sizeof(g_Templates)/sizeof(g_Templates[0]);
STDAPI DllRegisterServer()
{
return AMovieDllRegisterServer2(TRUE);
}
STDAPI DllUnregisterServer()
{
return AMovieDllRegisterServer2(FALSE);
}
extern "C" BOOL WINAPI DllEntryPoint(HINSTANCE, ULONG, LPVOID);
//
// DllMain
//
BOOL APIENTRY DllMain(HANDLE hModule,DWORD dwReason,LPVOID lpReserved)
{
return DllEntryPoint((HINSTANCE)(hModule),dwReason,lpReserved);
}
//
// Debug
//
void Debuginfo(char *info)
{
FILE *pf;
fopen_s(&pf,"C:\\debug.txt","a+");
fprintf(pf,info);
fclose(pf);
}
Decoder::Decoder(TCHAR *tszName,LPUNKNOWN punk,HRESULT *phr):CTransformFilter(tszName, punk, CLSID_Decoder),fillnum(0),samplesize(115200),startTime(0)
{
buffers=(unsigned char *)malloc(1048576);//1048576:pow(2,20)
if(!buffers)
exit(-1);
}
Decoder::~Decoder()
{
free(buffers);
}
//
// CreateInstance
//
CUnknown *Decoder::CreateInstance(LPUNKNOWN punk, HRESULT *phr)
{
ASSERT(phr);
Debuginfo("now create an intance\n");
Decoder *pNewObject=new Decoder(NAME("A Test Decoder"), punk, phr);
if (pNewObject == NULL)
{
if (phr)
*phr = E_OUTOFMEMORY;
}
return pNewObject;
}
STDMETHODIMP Decoder::NonDelegatingQueryInterface(REFIID riid, void **ppv)
{
CheckPointer(ppv,E_POINTER);
return CTransformFilter::NonDelegatingQueryInterface(riid, ppv);
}
//
// Transform
//
HRESULT Decoder::Transform(IMediaSample *pIn, IMediaSample *pOut)
{
Debuginfo("in Transform\n");
CheckPointer(pIn,E_POINTER);
CheckPointer(pOut,E_POINTER);
Debuginfo("in Transform\n");
BYTE *pSourceBuffer,*pDestBuffer;