Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to build a DirectShow Filter with multiple input pins 1

Status
Not open for further replies.

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(&quot;CMyBaseFilter&quot;), 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(&quot;CMyBaseInputPin&quot;),
pFilter,
pLock,
phr,
L&quot;Input&quot;),
m_pReceiveLock(pReceiveLock),
m_pMyClass(pMyClass)
{
return;
}

HRESULT CMyBaseInputPin::CheckMediaType(const CMediaType*)
{
return S_OK;
}


///////////////////////
//CMyClass
////////////////////////
CMyClass::CMyClass(LPUNKNOWN pUnk, HRESULT *phr):
CUnknown(NAME(&quot;CMyClass&quot;), 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&quot;Input1&quot;, // 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&quot;Input2&quot;, // 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&quot;MyBaseFilter&quot;,
MERIT_DO_NOT_USE,
2,
sudPins
};

//
//Object Creation Stuff
//
CFactoryTemplate g_Templates[] =
{
L&quot;MyBaseFilter&quot;, &CLSID_MyBaseFilter, CMyClass::CreateInstance, NULL, &sudMyClass
};

int g_cTemplates = 1;

//DllRegister
STDAPI DllRegisterServer()
{
return AMovieDllRegisterServer2( TRUE );
}

//DllUnRegister
STDAPI DllUnregisterServer()
{
return AMovieDllRegisterServer2( FALSE );
}


 
I am trying to create a filter graph that reads a live source and renders it. The problem is that when i &quot;Render URL&quot; and place the URL in the graphEditor, the filter graph that is created cannot read the live source. Anyone can help me.
P.S. I can read file from the Internet, the problem is with live sources.
 
If you have a look at the sample code in the directx sdk there is one called texture3D where an avi from the your C drive is streamed and placed as a texture for a cylinder. I would like to stream live video from the internet and place it as the texture. I can do it if I stream a file from the net just by replacing the file path with the URL but when I try to put a URL that contains live videos it tells me it cannot create the graph....
HELP PLEASE...

Bye
Vincenzo
 
Steps you have to take in order to get 2 input pin 1 out filter:
1. const AMOVIESETUP_PIN sudPins[] =
{
{ L&quot;Input1&quot;, // 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&quot;Input2&quot;, // Pin's string name
FALSE, // Is it rendered
FALSE, // Is it an output MAKE SURE ITS INPUT
FALSE, // Allowed none
FALSE, // Allowed many
&CLSID_NULL, // Connects to filter
NULL, // Connects to pin
1, // Number of types
&sudPinTypes }, // Pin information
{ L&quot;Output&quot;, // 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
};
Note: check correct output flag for input/ output pin

const AMOVIESETUP_FILTER sudMyClass =
{
&CLSID_MyBaseFilter,
L&quot;MyBaseFilter&quot;,
MERIT_DO_NOT_USE,
3, /// HERE THE CHANGE
sudPins
};


3. int GetPinCount()
{
return 3;
}

4. Make initialization of all pins (constructor calls) at GetPin() method see transform.cpp file in DirectShow SDK
don't forget to initialize Output Pin too

5. Add to filter destructor pin destruction

After these steps filter can be viewed at graphEdit but all your problems are pretty far from being solved -> to have filter doing something useful

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top