www.pudn.com > FilterTSSource.rar > CFilterTSSource.cpp


// 
// CFilterTSSource.cpp 
// 
 
#include           // quartz, includes windows 
// Eliminate two expected level 4 warnings from the Microsoft compiler. 
// The class does not have an assignment or copy operator, and so cannot 
// be passed by value.  This is normal.  This file compiles clean at the 
// highest (most picky) warning level (-W4). 
#pragma warning(disable: 4511 4512) 
 
#include  
 
// {237204D5-8343-400e-8037-B3C20DB2AB22} 
DEFINE_GUID(CLSID_MPEG2_TS_Source,  
0x237204d5, 0x8343, 0x400e, 0x80, 0x37, 0xb3, 0xc2, 0xd, 0xb2, 0xab, 0x22); 
 
 
#if (1100 > _MSC_VER) 
#include  
#else 
#include  
#endif 
 
#include "CFilterTSSource.h" 
 
// 
// setup data 
// 
const AMOVIESETUP_MEDIATYPE sudPinTypes = 
{ 
    &MEDIATYPE_NULL,            // Major type 
    &MEDIASUBTYPE_NULL          // Minor type 
}; 
 
const AMOVIESETUP_PIN psudPins[] = 
{ 
   {  
		L"Output",          // String pin name 
		FALSE,              // Is it rendered 
		TRUE,               // Is it an output 
		FALSE,              // Allowed none 
		FALSE,              // Allowed many 
		&CLSID_NULL,        // Connects to filter 
		L"Input",           // Connects to pin 
		1,                  // Number of types 
		&sudPinTypes        // The pin details 
    } 
}; 
 
 
const AMOVIESETUP_FILTER sudFilter = 
{ 
    &CLSID_MPEG2_TS_Source,       // Filter CLSID 
    L"MPEG2 TS Source",           // Filter name 
    MERIT_DO_NOT_USE,         // Its merit 
    1,                        // Number of pins 
    psudPins                  // Pin details 
}; 
 
 
// List of class IDs and creator functions for the class factory. This 
// provides the link between the OLE entry point in the DLL and an object 
// being created. The class factory will call the static CreateInstance 
CFactoryTemplate g_Templates[] =  
{ 
	{  
		L"MPEG2 TS Source", 
		&CLSID_MPEG2_TS_Source, 
		CFilterTSSource::CreateInstance, 
		NULL, 
		&sudFilter  
	} 
}; 
int g_cTemplates = sizeof(g_Templates) / sizeof(g_Templates[0]); 
 
 
// ---------------------------------------------------------------------------- 
//            Filter implementation 
// ---------------------------------------------------------------------------- 
CFilterTSSource::CFilterTSSource(LPUNKNOWN lpunk, HRESULT *phr) : 
CSource(NAME("TS Source"), lpunk, CLSID_MPEG2_TS_Source) 
{ 
	CTSOutPin * outStream = new CTSOutPin(phr, this, L"Output"); 
	if (outStream == NULL) 
	{ 
		*phr = E_OUTOFMEMORY;	 
	} 
} 
 
CFilterTSSource::~CFilterTSSource() 
{ 
} 
 
// 
// CreateInstance 
// 
// Override CClassFactory method. 
// Provide the way for COM to create a CNullInPlace object 
// 
CUnknown * WINAPI CFilterTSSource::CreateInstance(LPUNKNOWN punk, HRESULT *phr)  
{ 
	CFilterTSSource *pNewObject = new CFilterTSSource(punk, phr); 
	if (pNewObject == NULL)  
	{ 
		*phr = E_OUTOFMEMORY; 
	} 
	return pNewObject; 
}  
 
// 
// Basic COM - used here to reveal our own interfaces 
STDMETHODIMP CFilterTSSource::NonDelegatingQueryInterface(REFIID riid, void ** ppv) 
{ 
	CheckPointer(ppv, E_POINTER); 
 
	if (riid == IID_IFileSourceFilter) 
	{ 
		return GetInterface((IFileSourceFilter *) this, ppv); 
	} 
	else 
	{ 
		return CSource::NonDelegatingQueryInterface(riid, ppv); 
	} 
} 
 
int CFilterTSSource::GetPinCount() 
{ 
	return 1; 
} 
 
CBasePin * CFilterTSSource::GetPin(int n) 
{ 
	if (n == 0) 
	{ 
		return m_paStreams[0];	 
	} 
	return NULL; 
} 
 
STDMETHODIMP CFilterTSSource::FindPin(LPCWSTR Id, IPin ** ppPin) 
{ 
	return CBaseFilter::FindPin(Id, ppPin); 
} 
 
// --- IFileSourceFilter methods --- 
STDMETHODIMP CFilterTSSource::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE *pmt) 
{ 
	char szAnsi[MAX_PATH]; 
	WideCharToMultiByte(CP_ACP, 0, pszFileName, -1, szAnsi, MAX_PATH, NULL, NULL); 
	if (OutPin()->SetFileSource(szAnsi)) 
	{ 
		return NOERROR; 
	} 
	return E_FAIL; 
} 
 
STDMETHODIMP CFilterTSSource::GetCurFile(LPOLESTR *ppszFileName, AM_MEDIA_TYPE *pmt) 
{ 
	char szAnsi[MAX_PATH]; 
	OutPin()->GetFileSource(szAnsi); 
 
	DWORD n = sizeof(WCHAR) * (1 + strlen(szAnsi)); 
	*ppszFileName = (LPOLESTR) CoTaskMemAlloc( n ); 
	if (*ppszFileName != NULL)  
	{ 
		WCHAR   szwFile[MAX_PATH]; 
		MultiByteToWideChar(CP_ACP, 0, szAnsi, -1, szwFile, MAX_PATH); 
		CopyMemory(*ppszFileName, szwFile, n); 
	} 
	return NOERROR; 
} 
 
 
 
 
 
 
 
 
 
 
 
 
// 
// DllEntryPoint 
// 
extern "C" BOOL WINAPI DllEntryPoint(HINSTANCE, ULONG, LPVOID); 
 
BOOL APIENTRY DllMain(HANDLE hModule, DWORD  dwReason, LPVOID lpReserved) 
{ 
	return DllEntryPoint((HINSTANCE)(hModule), dwReason, lpReserved); 
} 
 
/******************************Public Routine******************************\ 
* exported entry points for registration and 
* unregistration (in this case they only call 
* through to default implmentations). 
* 
* 
* 
* History: 
* 
\**************************************************************************/ 
STDAPI DllRegisterServer() 
{ 
	return AMovieDllRegisterServer2( TRUE ); 
} 
 
STDAPI DllUnregisterServer() 
{ 
	return AMovieDllRegisterServer2( FALSE ); 
} 
 
// Microsoft C Compiler will give hundreds of warnings about 
// unused inline functions in header files.  Try to disable them. 
#pragma warning( disable:4514)