How to creat a filter with multiple inputs?

Hi,
I am trying to create a directshow filter which has 2 input
pins and 1 output pin . I have added the pin details to the array of AMOVIESETUP_PIN's, and I have changed the umber of pins in the AMOVIESETUP_FILTER structure. Override the GetPinCount,GetPin.

class CAudioSwichInPlaceFilter : public CTransInPlaceFilter
,public ISpecifyPropertyPages
,public IAudioSwControler
{
public:
CAudioSwichInPlaceFilter(TCHAR *tszName, LPUNKNOWN punk, HRESULT *phr);
virtual ~CAudioSwichInPlaceFilter();
public:
DECLARE_IUNKNOWN;

STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void **ppv);

static CUnknown * WINAPI CreateInstance(LPUNKNOWN punk, HRESULT *phr);

//is called when the upstream filter proposes a media type to the transform filter
HRESULT CheckInputType(const CMediaType* mtIn);

//
// Overrides the PURE virtual Transform of CTransInPlaceFilter base class
// This is where the "real work" is done.
//
HRESULT Transform(IMediaSample *pSample);


HRESULT Receive(IMediaSample *pSample);

CBasePin * GetPin(int n);
int GetPinCount(){return 3;}

// override state changes to allow derived transform filter
// to control streaming start/stop
STDMETHODIMP Stop();
STDMETHODIMP Pause();

//ISpecifyPropertyPages
public:
STDMETHODIMP GetPages(CAUUID *pPages);

//IViaAudioSwControler
private:
CCritSec m_csShared; // Protects shared data.
public:
private:
friend class CAudioSwIPPin;
friend class CTransformOutputPin;
CAudioSwIPPin *m_pInput1,*m_pInput2;
CTransformOutputPin *m_pOutput1;

private:

...

};

the filter has tow pins,CAudioSwIPPin *m_pInput1,*m_pInput2,but the base filter CTransInPlaceFilter has a default pin m_pInput,and all of the operation are based m_pInput.

and when m_pInput->Receive(...),it call the filter->Receive(..),how can i know which pin called this?

Does have some samples?

[2038 byte] By [Brilly] at [2008-2-22]
# 1
Use the Video Mixing Renderer 9 filter, it automatically adds input pins. With intelligent connect there is no need for the extra pin connect code.
DouglasJordan at 2007-9-8 > top of Msdn Tech,Software Development for Windows Vista,DirectShow Development...
# 2
but i need process the audio stream data.It is a transform filter,not a video renderer!
Brilly at 2007-9-8 > top of Msdn Tech,Software Development for Windows Vista,DirectShow Development...
# 3
Sorry about that, dropped a bit.
DouglasJordan at 2007-9-8 > top of Msdn Tech,Software Development for Windows Vista,DirectShow Development...
# 4

I have also been trying to accomplish a similar filter design with two inputs and one or more outputs. From what I've read on DirectShow base classes, CTransInPlaceFilter derives from CTransformFilter which in turn derives from CBaseFilter. SDK documentation for CTransformFilter states that class is designed specifically for single-input/single-output filters. I believe you need to design your own class that is derived directly from CBaseFilter with pins derived from CBasePin. Then override the pure virtual methods CBaseFilter::GetPin and CBaseFilter::GetPinCount as well provide your own methods for processing the data in a unique way that takes advantage of two input pins. Beyond that, I am still looking for answers on specifics and/or helpful source code to get the two-input filter operational. My only other reference is the SDK Infinite Tee Sample that shows how to dynamically add more outputs as well as internal workings of the CTransformFilter derived class. If anyone knows more, please post...

If you want a third party SDK to do the job, check this link out: http://dsfilters.agava.com/

BLH at 2007-9-8 > top of Msdn Tech,Software Development for Windows Vista,DirectShow Development...
# 5
This is pretty simple. Here is some code with the neccesary stuff you need. These are just the pin stuff, you will still need locks to synchronize access.

Regards,
Mark Essien.
--
http://www.essien.de | DirectEncode MPEG Encoder

-
//// In the HEADER file
class CMyFilter : public CBaseFilter
{
public:
CCritSec* GetMainLock();

// Pin enumeration
CBasePin * GetPin(int n);
int GetPinCount();

// Open and close the file as necessary
STDMETHODIMP Run(REFERENCE_TIME tStart);
STDMETHODIMP Pause();
STDMETHODIMP Stop();

private:
CMyInputPin *m_pPinVideo;
CMyInputPin *m_pPinAudio;
};

///////////////////////
// In the implementation (.cpp) file

// We define our input media types.
const AMOVIESETUP_MEDIATYPE sudPinTypes[] =
{
{ &MEDIATYPE_Video, // Major CLSID
&MEDIASUBTYPE_RGB24 }, // Minor type
{ &MEDIATYPE_Audio, // Major CLSID
&MEDIASUBTYPE_PCM } // Minor type
};

// Define our pins
const AMOVIESETUP_PIN psudPins[] =
{
{ L"Input 01", // Pin's string name
FALSE, // Is it rendered
FALSE, // Is it an output
FALSE, // Allowed none
FALSE, // Allowed many
&CLSID_NULL, // Connects to filter
L"Output", // Connects to pin
1, // Number of types
&sudPinTypes[0] }, // Pin information

{ L"Input 02", // Pin's string name
FALSE, // Is it rendered
FALSE, // Is it an output
FALSE, // Allowed none
FALSE, // Allowed many
&CLSID_NULL, // Connects to filter
L"Output", // Connects to pin
1, // Number of types
&sudPinTypes[1] } // Pin information
};

const AMOVIESETUP_FILTER sudInfTee =
{
&CLSID_MyFilter, // CLSID of filter
L"My Filter v4", // Filter's name
MERIT_DO_NOT_USE, // Filter merit
2, // Number of pins
psudPins // Pin information
};

CMyFilter::CMyFilter( LPUNKNOWN pUnk,
HRESULT *phr) :

CBaseFilter(NAME("CMyFilter"),
pUnk, &m_Lock,
CLSID_MyFilter)
{

m_pPinVideo = new CMyInputPin(pUnk,
this,
&m_Lock,
&m_ReceiveLock,
Video,
L"Video Input",
phr);
if (m_pPinVideo == NULL) {
*phr = E_OUTOFMEMORY;
return;
}

m_pPinAudio = new CMyInputPin(pUnk,
this,
&m_Lock,
&m_ReceiveLock,
Audio,
L"Audio Input",
phr);
if (m_pPinAudio == NULL) {
*phr = E_OUTOFMEMORY;
return;
}
}

CBasePin * CMyFilter::GetPin(int n)
{
if (n == 0) {
return m_pPinVideo;
} else if (n == 1) {
return m_pPinAudio;
}

return NULL;
}

int CMyFilter::GetPinCount()
{
return 2;
}

MarkEssien at 2007-9-8 > top of Msdn Tech,Software Development for Windows Vista,DirectShow Development...
# 6

Sounds easy, could you send me the whole source code. I would like to create chroma-key filter, but i can't input 2 source movies.

You didn't explain how you define CMyInputPin class. Could you do that?

My email:krzag@poczta.onet.pl

Thank you!

Best regards,

krzag at 2007-9-8 > top of Msdn Tech,Software Development for Windows Vista,DirectShow Development...

Software Development for Windows Vista

Site Classified