×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to build a DirectShow Filter with multiple input pins

How to build a DirectShow Filter with multiple input pins

How to build a DirectShow Filter with multiple input pins

(OP)
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 );
}


RE: How to build a DirectShow Filter with multiple input pins

Did you ever figure this out ???

RE: How to build a DirectShow Filter with multiple input pins

I too want to make this filter
But it don't works

RE: How to build a DirectShow Filter with multiple input pins

I am trying to create a filter graph that reads a live source and renders it.  The problem is that when i "Render URL" 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.

RE: How to build a DirectShow Filter with multiple input pins

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

RE: How to build a DirectShow Filter with multiple input pins

Steps you have to take in order to get 2 input pin 1 out filter:
1. 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
      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"Output",            // 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"MyBaseFilter",
    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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close