Guest_imported
New member
- Jan 1, 1970
- 0
Help! I'm having a ton of trouble creating a directshow filter that has 2 input pins and one out pin. How can I do this?
I derived my class from CBaseFilter and derived an input pin from the base pin, and I have 2 input pin member variables. But Graphedit only see one pin!!! I'm going nutz...Here is my source:
//Multiple Input Pins....hopefully *fingers crossed*
#include <streams.h>
#include <olectl.h>
#include <initguid.h>
class CMyBaseInputPin;
class CMyClass;
class CMyBaseFilter;
// {1A81A231-1483-44d1-9AED-D0122F6C91B4}
DEFINE_GUID(CLSID_MyBaseFilter, 0x1a81a231, 0x1483, 0x44d1, 0x9a, 0xed, 0xd0, 0x12, 0x2f, 0x6c, 0x91, 0xb4);
//Main Filter Object
class CMyBaseFilter : public CBaseFilter
{
CMyClass * const m_pMyClass;
public:
//constructor
CMyBaseFilter(CMyClass *pMyClass, LPUNKNOWN pUnk, CCritSec *pLock, HRESULT *phr);
//Pin enumeration
CBasePin* GetPin(int n);
int GetPinCount();
};
//Pin
class CMyBaseInputPin : public CBaseInputPin
{
CMyClass * const m_pMyClass; //Main renderer object
CCritSec * const m_pReceiveLock;
public:
CMyBaseInputPin(CMyClass *pMyClass, LPUNKNOWN pUnk,
CBaseFilter *pFilter, CCritSec *pLock,
CCritSec *pReceiveLock, HRESULT *phr);
//Media Sample handlers
STDMETHODIMP Receive(IMediaSample *pSample){ return S_OK; }
STDMETHODIMP EndOfStream(void) { return S_OK; }
//check if Pin can support this type of media
HRESULT CheckMediaType(const CMediaType *);
};
class CMyClass : public CUnknown
{
friend class CMyBaseFilter;
friend class CMybaseFilter;
CMyBaseFilter *m_pFilter;
//CMyBaseInputPin *m_pPin1;
//CMyBaseInputPin *m_pPin2;
CCritSec m_Lock;
CCritSec m_ReceiveLock;
public:
DECLARE_IUNKNOWN
CMyClass(LPUNKNOWN pUnk, HRESULT *phr);
static CUnknown * WINAPI CreateInstance(LPUNKNOWN punk, HRESULT *phr);
private:
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void ** ppv);
};
//IMPLEMENATIONS
////////////////
///CMyBaseFilter
////////////////
CMyBaseFilter::CMyBaseFilter(CMyClass *pMyClass, LPUNKNOWN pUnk, CCritSec *pLock, HRESULT *phr) :
CBaseFilter(NAME("CMyBaseFilter", pUnk, pLock, CLSID_MyBaseFilter), m_pMyClass(pMyClass)
{}
CBasePin * CMyBaseFilter::GetPin(int n)
{
if( n==0 )
{
return NULL;
//return m_pMyClass->m_pPin1;
}
if( n==1 )
{
return NULL;
//return m_pMyClass->m_pPin2;
}
else
{
return NULL;
}
}
int CMyBaseFilter::GetPinCount()
{
return 1;
}
///////////////////
///CMyBaseInputPin
///////////////////
CMyBaseInputPin::CMyBaseInputPin(CMyClass *pMyClass,
LPUNKNOWN pUnk,
CBaseFilter *pFilter,
CCritSec *pLock,
CCritSec *pReceiveLock,
HRESULT *phr) :
CBaseInputPin(NAME("CMyBaseInputPin",
pFilter,
pLock,
phr,
L"Input",
m_pReceiveLock(pReceiveLock),
m_pMyClass(pMyClass)
{
return;
}
HRESULT CMyBaseInputPin::CheckMediaType(const CMediaType*)
{
return S_OK;
}
///////////////////////
//CMyClass
////////////////////////
CMyClass::CMyClass(LPUNKNOWN pUnk, HRESULT *phr):
CUnknown(NAME("CMyClass", pUnk),
m_pFilter(NULL)
//m_pPin1(NULL),
//m_pPin2(NULL)
{
m_pFilter = new CMyBaseFilter(this, GetOwner(), &m_Lock, phr);
if(m_pFilter == NULL)
{
*phr = E_OUTOFMEMORY;
return;
}
/*m_pPin1 = new CMyBaseInputPin(this, GetOwner(), m_pFilter, &m_Lock, &m_ReceiveLock, phr);
if(m_pPin1 == NULL)
{
*phr = E_OUTOFMEMORY;
return;
}
else
{
m_pPin1->AddRef();
}
m_pPin2 = new CMyBaseInputPin(this, GetOwner(), m_pFilter, &m_Lock, &m_ReceiveLock, phr);
if(m_pPin2 == NULL)
{
*phr = E_OUTOFMEMORY;
return;
}
else
{
m_pPin2->AddRef();
}
*/
}
CUnknown * WINAPI CMyClass::CreateInstance(LPUNKNOWN punk, HRESULT *phr)
{
CMyClass *pNewObject = new CMyClass(punk, phr);
if (pNewObject == NULL)
{
*phr = E_OUTOFMEMORY;
}
return pNewObject;
}
STDMETHODIMP CMyClass::NonDelegatingQueryInterface(REFIID riid, void ** ppv)
{
if (riid == IID_IBaseFilter || riid == IID_IMediaFilter || riid == IID_IPersist)
{
return m_pFilter->NonDelegatingQueryInterface(riid, ppv);
}
else
{
return CUnknown::NonDelegatingQueryInterface(riid, ppv);
}
}
//Setup dta
const AMOVIESETUP_MEDIATYPE sudPinTypes =
{
&MEDIATYPE_NULL,
&MEDIASUBTYPE_NULL
};
const AMOVIESETUP_PIN sudPins[] =
{
{ L"Input1", // Pin's string name
FALSE, // Is it rendered
FALSE, // Is it an output
FALSE, // Allowed none
FALSE, // Allowed many
&CLSID_NULL, // Connects to filter
NULL, // Connects to pin
1, // Number of types
&sudPinTypes }, // Pin information
{ L"Input2", // Pin's string name
FALSE, // Is it rendered
TRUE, // Is it an output
FALSE, // Allowed none
FALSE, // Allowed many
&CLSID_NULL, // Connects to filter
NULL, // Connects to pin
1, // Number of types
&sudPinTypes } // Pin information
};
const AMOVIESETUP_FILTER sudMyClass =
{
&CLSID_MyBaseFilter,
L"MyBaseFilter",
MERIT_DO_NOT_USE,
2,
sudPins
};
//
//Object Creation Stuff
//
CFactoryTemplate g_Templates[] =
{
L"MyBaseFilter", &CLSID_MyBaseFilter, CMyClass::CreateInstance, NULL, &sudMyClass
};
int g_cTemplates = 1;
//DllRegister
STDAPI DllRegisterServer()
{
return AMovieDllRegisterServer2( TRUE );
}
//DllUnRegister
STDAPI DllUnregisterServer()
{
return AMovieDllRegisterServer2( FALSE );
}
I derived my class from CBaseFilter and derived an input pin from the base pin, and I have 2 input pin member variables. But Graphedit only see one pin!!! I'm going nutz...Here is my source:
//Multiple Input Pins....hopefully *fingers crossed*
#include <streams.h>
#include <olectl.h>
#include <initguid.h>
class CMyBaseInputPin;
class CMyClass;
class CMyBaseFilter;
// {1A81A231-1483-44d1-9AED-D0122F6C91B4}
DEFINE_GUID(CLSID_MyBaseFilter, 0x1a81a231, 0x1483, 0x44d1, 0x9a, 0xed, 0xd0, 0x12, 0x2f, 0x6c, 0x91, 0xb4);
//Main Filter Object
class CMyBaseFilter : public CBaseFilter
{
CMyClass * const m_pMyClass;
public:
//constructor
CMyBaseFilter(CMyClass *pMyClass, LPUNKNOWN pUnk, CCritSec *pLock, HRESULT *phr);
//Pin enumeration
CBasePin* GetPin(int n);
int GetPinCount();
};
//Pin
class CMyBaseInputPin : public CBaseInputPin
{
CMyClass * const m_pMyClass; //Main renderer object
CCritSec * const m_pReceiveLock;
public:
CMyBaseInputPin(CMyClass *pMyClass, LPUNKNOWN pUnk,
CBaseFilter *pFilter, CCritSec *pLock,
CCritSec *pReceiveLock, HRESULT *phr);
//Media Sample handlers
STDMETHODIMP Receive(IMediaSample *pSample){ return S_OK; }
STDMETHODIMP EndOfStream(void) { return S_OK; }
//check if Pin can support this type of media
HRESULT CheckMediaType(const CMediaType *);
};
class CMyClass : public CUnknown
{
friend class CMyBaseFilter;
friend class CMybaseFilter;
CMyBaseFilter *m_pFilter;
//CMyBaseInputPin *m_pPin1;
//CMyBaseInputPin *m_pPin2;
CCritSec m_Lock;
CCritSec m_ReceiveLock;
public:
DECLARE_IUNKNOWN
CMyClass(LPUNKNOWN pUnk, HRESULT *phr);
static CUnknown * WINAPI CreateInstance(LPUNKNOWN punk, HRESULT *phr);
private:
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void ** ppv);
};
//IMPLEMENATIONS
////////////////
///CMyBaseFilter
////////////////
CMyBaseFilter::CMyBaseFilter(CMyClass *pMyClass, LPUNKNOWN pUnk, CCritSec *pLock, HRESULT *phr) :
CBaseFilter(NAME("CMyBaseFilter", pUnk, pLock, CLSID_MyBaseFilter), m_pMyClass(pMyClass)
{}
CBasePin * CMyBaseFilter::GetPin(int n)
{
if( n==0 )
{
return NULL;
//return m_pMyClass->m_pPin1;
}
if( n==1 )
{
return NULL;
//return m_pMyClass->m_pPin2;
}
else
{
return NULL;
}
}
int CMyBaseFilter::GetPinCount()
{
return 1;
}
///////////////////
///CMyBaseInputPin
///////////////////
CMyBaseInputPin::CMyBaseInputPin(CMyClass *pMyClass,
LPUNKNOWN pUnk,
CBaseFilter *pFilter,
CCritSec *pLock,
CCritSec *pReceiveLock,
HRESULT *phr) :
CBaseInputPin(NAME("CMyBaseInputPin",
pFilter,
pLock,
phr,
L"Input",
m_pReceiveLock(pReceiveLock),
m_pMyClass(pMyClass)
{
return;
}
HRESULT CMyBaseInputPin::CheckMediaType(const CMediaType*)
{
return S_OK;
}
///////////////////////
//CMyClass
////////////////////////
CMyClass::CMyClass(LPUNKNOWN pUnk, HRESULT *phr):
CUnknown(NAME("CMyClass", pUnk),
m_pFilter(NULL)
//m_pPin1(NULL),
//m_pPin2(NULL)
{
m_pFilter = new CMyBaseFilter(this, GetOwner(), &m_Lock, phr);
if(m_pFilter == NULL)
{
*phr = E_OUTOFMEMORY;
return;
}
/*m_pPin1 = new CMyBaseInputPin(this, GetOwner(), m_pFilter, &m_Lock, &m_ReceiveLock, phr);
if(m_pPin1 == NULL)
{
*phr = E_OUTOFMEMORY;
return;
}
else
{
m_pPin1->AddRef();
}
m_pPin2 = new CMyBaseInputPin(this, GetOwner(), m_pFilter, &m_Lock, &m_ReceiveLock, phr);
if(m_pPin2 == NULL)
{
*phr = E_OUTOFMEMORY;
return;
}
else
{
m_pPin2->AddRef();
}
*/
}
CUnknown * WINAPI CMyClass::CreateInstance(LPUNKNOWN punk, HRESULT *phr)
{
CMyClass *pNewObject = new CMyClass(punk, phr);
if (pNewObject == NULL)
{
*phr = E_OUTOFMEMORY;
}
return pNewObject;
}
STDMETHODIMP CMyClass::NonDelegatingQueryInterface(REFIID riid, void ** ppv)
{
if (riid == IID_IBaseFilter || riid == IID_IMediaFilter || riid == IID_IPersist)
{
return m_pFilter->NonDelegatingQueryInterface(riid, ppv);
}
else
{
return CUnknown::NonDelegatingQueryInterface(riid, ppv);
}
}
//Setup dta
const AMOVIESETUP_MEDIATYPE sudPinTypes =
{
&MEDIATYPE_NULL,
&MEDIASUBTYPE_NULL
};
const AMOVIESETUP_PIN sudPins[] =
{
{ L"Input1", // Pin's string name
FALSE, // Is it rendered
FALSE, // Is it an output
FALSE, // Allowed none
FALSE, // Allowed many
&CLSID_NULL, // Connects to filter
NULL, // Connects to pin
1, // Number of types
&sudPinTypes }, // Pin information
{ L"Input2", // Pin's string name
FALSE, // Is it rendered
TRUE, // Is it an output
FALSE, // Allowed none
FALSE, // Allowed many
&CLSID_NULL, // Connects to filter
NULL, // Connects to pin
1, // Number of types
&sudPinTypes } // Pin information
};
const AMOVIESETUP_FILTER sudMyClass =
{
&CLSID_MyBaseFilter,
L"MyBaseFilter",
MERIT_DO_NOT_USE,
2,
sudPins
};
//
//Object Creation Stuff
//
CFactoryTemplate g_Templates[] =
{
L"MyBaseFilter", &CLSID_MyBaseFilter, CMyClass::CreateInstance, NULL, &sudMyClass
};
int g_cTemplates = 1;
//DllRegister
STDAPI DllRegisterServer()
{
return AMovieDllRegisterServer2( TRUE );
}
//DllUnRegister
STDAPI DllUnregisterServer()
{
return AMovieDllRegisterServer2( FALSE );
}