home *** CD-ROM | disk | FTP | other *** search
- //==========================================================================;
- //
- // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
- // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
- // PURPOSE.
- //
- // Copyright (c) 1992 - 1996 Microsoft Corporation. All Rights Reserved.
- //
- //--------------------------------------------------------------------------;
-
-
- /*
- * Null-InPlace
- *
- *
- */
-
- /* An example of a transform-in-place filter.
- This filter has one input pin, one output pin and
- does its transform in-place (i.e. without copying the data)
- on the push thread (i.e. it is called with a buffer, which it
- transforms and gives to the next filter downstream. It is
- then blocked until that filter returns. It then returns
- to its own caller.
-
- */
-
-
- #include <streams.h> // quartz, includes windows
- #include <measure.h> // performance measurement (MSR_)
-
- #include <initguid.h>
- #include <olectl.h>
- #include <olectlid.h>
-
- #include "nullUids.h" // our own uuids
-
- #include "INull.h"
- #include "nullprop.h"
- #include "NullIP.h" //
-
-
- // Put out the name of the function and instance on the debugger.
- #define DbgFunc(a) DbgLog(( LOG_TRACE \
- , 2 \
- , TEXT("CNullInPlace(Instance %d)::%s") \
- , m_nThisInstance \
- , TEXT(a) \
- ));
-
- // setup data
-
- AMOVIESETUP_MEDIATYPE sudPinTypes = { &MEDIATYPE_NULL // clsMajorType
- , &MEDIASUBTYPE_NULL } ; // clsMinorType
-
- AMOVIESETUP_PIN psudPins[] = { { L"Input" // strName
- , FALSE // bRendered
- , FALSE // bOutput
- , FALSE // bZero
- , FALSE // bMany
- , &CLSID_NULL // clsConnectsToFilter
- , L"Output" // strConnectsToPin
- , 1 // nTypes
- , &sudPinTypes } // lpTypes
- , { L"Output" // strName
- , FALSE // bRendered
- , TRUE // bOutput
- , FALSE // bZero
- , FALSE // bMany
- , &CLSID_NULL // clsConnectsToFilter
- , L"Input" // strConnectsToPin
- , 1 // nTypes
- , &sudPinTypes } }; // lpTypes
-
-
- AMOVIESETUP_FILTER sudNullIP = { &CLSID_NullInPlace // clsID
- , L"Null In Place" // strName
- , MERIT_DO_NOT_USE // dwMerit
- , 2 // nPins
- , psudPins }; // lpPin
-
-
- // Needed for the CreateInstance mechanism
- CFactoryTemplate g_Templates[]=
- { {L"Null-In-Place", &CLSID_NullInPlace, CNullInPlace::CreateInstance},
- {L"Null IP Property Page", &CLSID_NullIPPropertyPage, NullIPProperties::CreateInstance}
-
- };
- int g_cTemplates = sizeof(g_Templates)/sizeof(g_Templates[0]);
-
- // initialise the static instance count.
- int CNullInPlace::m_nInstanceCount = 0;
-
-
- /****************************/
- /*** CNullInPlaceInputPin ***/
- /****************************/
-
- // CheckMediaType
- // - agree to anything if not connected, other wise pass through to
- // the downstream filter
- HRESULT CNullInPlaceInputPin::CheckMediaType( const CMediaType *pmt )
- { CNullInPlace *pNull = (CNullInPlace *) m_pTIPFilter;
-
- #ifdef DEBUG
- DisplayType(TEXT("Input type proposed"),pmt);
- #endif
-
- if (pNull->m_mtPreferred.IsValid() == FALSE)
- {
- if( pNull->m_pOutput->IsConnected() ) {
- if ( *pmt->Subtype() == *pNull->m_pOutput->CurrentMediaType().Subtype() ) {
- return pNull->m_pOutput->GetConnected()->QueryAccept( pmt );
- }
- return VFW_E_TYPE_NOT_ACCEPTED;
- }
- return S_OK;
- }
- else
- if (*pmt == pNull->m_mtPreferred)
- return S_OK ;
- else
- return VFW_E_TYPE_NOT_ACCEPTED;
-
- }
-
- /****************************/
- /*** CNullInPlaceOutputPin ***/
- /****************************/
-
- // CheckMediaType
- //
- // Pass on to base class unless there is a preferred format set.
-
- HRESULT CNullInPlaceOutputPin::CheckMediaType( const CMediaType *pmt )
- { CNullInPlace *pNull = (CNullInPlace *) m_pTIPFilter;
-
- if (pNull->m_mtPreferred.IsValid() == FALSE)
- {
- return CTransInPlaceOutputPin::CheckMediaType (pmt) ;
- }
- else
- if (*pmt == pNull->m_mtPreferred)
- return S_OK ;
- else
- return VFW_E_TYPE_NOT_ACCEPTED;
-
- }
-
- /********************/
- /*** CNullInPlace ***/
- /********************/
-
- //
- // CNullInPlace::Constructor
- //
- CNullInPlace::CNullInPlace(TCHAR *tszName, LPUNKNOWN punk, HRESULT *phr)
- : CTransInPlaceFilter (tszName, punk, CLSID_NullInPlace, phr)
- {
- m_nThisInstance = ++m_nInstanceCount;
- m_mtPreferred.InitMediaType () ;
- DbgFunc("CNullInPlace");
-
- #ifdef PERF
- TCHAR msg[64];
- wsprintf(msg, TEXT("Null %d passthru"), m_nThisInstance);
- m_idReceive = Msr_Register(msg);
- #endif
-
- } // (CNullInPlace constructor)
-
-
- //
- // CreateInstance
- //
- // Provide the way for COM to create a CNullInPlace object
- CUnknown *CNullInPlace::CreateInstance(LPUNKNOWN punk, HRESULT *phr) {
-
- CNullInPlace *pNewObject = new CNullInPlace(NAME("Null-In-Place Filter"), punk, phr );
- if (pNewObject == NULL) {
- *phr = E_OUTOFMEMORY;
- }
-
- return pNewObject;
- } // CreateInstance
-
-
- //
- // GetSetupData
- //
- LPAMOVIESETUP_FILTER CNullInPlace::GetSetupData()
- {
- return &sudNullIP;
- }
-
- // return a non-addrefed CBasePin * for the user to addref if he holds onto it
- // for longer than his pointer to us.
- CBasePin *CNullInPlace::GetPin(int n)
- {
- /* Create the single input and output pins */
-
- if (m_pInput == NULL || m_pOutput == NULL) {
-
- HRESULT hr = S_OK;
-
- m_pInput = new CNullInPlaceInputPin(NAME("Null input pin"),
- this, // Owner filter
- &hr, // Result code
- L"Input"); // Pin name
-
- // a failed return code should delete the object
-
- if (FAILED(hr) || m_pInput == NULL) {
- delete m_pInput;
- m_pInput = NULL;
- return NULL;
- }
-
- m_pOutput = new CNullInPlaceOutputPin(NAME("Null output pin"),
- this, // Owner filter
- &hr, // Result code
- L"Output"); // Pin name
-
- // failed return codes cause both objects to be deleted
-
- if (FAILED(hr) || m_pOutput == NULL) {
- delete m_pInput;
- m_pInput = NULL;
- delete m_pOutput;
- m_pOutput = NULL;
- return NULL;
- }
- }
-
- /* Find which pin is required */
-
- switch(n) {
- case 0:
- return m_pInput;
- case 1:
- return m_pOutput;
- }
- return NULL;
- }
-
-
- //
- // NonDelegatingQueryInterface
- //
- STDMETHODIMP CNullInPlace::NonDelegatingQueryInterface(REFIID riid, void **ppv) {
-
- if (riid == IID_INullIPP) {
- return GetInterface((INullIPP *) this, ppv);
- }
- else if (riid == IID_ISpecifyPropertyPages) {
- return GetInterface((ISpecifyPropertyPages *) this, ppv);
- }
- else {
- return CTransformFilter::NonDelegatingQueryInterface(riid, ppv);
- }
-
- } // NonDelegatingQueryInterface
-
- //
- // Receive the sample from upstream and process it in place.
- //
- HRESULT CNullInPlace::Receive(IMediaSample *pSample)
- {
-
- // By declaring a dummy variable (foo) of type CAutoLock we enter
- // a CRITICAL_SECTION and automatically leave it at the end of
- // the function.
- CAutoLock foo(&m_NullIPLock);
- HRESULT hr;
-
- DbgFunc("Receive");
-
- #ifdef PERF
- Msr_Start(m_idReceive);
- #endif
-
- hr = m_pOutput->Deliver(pSample);
-
- #ifdef PERF
- Msr_Stop(m_idReceive);
- #endif
-
- return hr;
- } // Receive
-
-
- //
- // --- INullIPP
- //
-
-
- //
- // get_IPin
- //
-
- STDMETHODIMP CNullInPlace::get_IPin (IPin **ppPin)
- {
- CAutoLock l(&m_NullIPLock);
- if (!m_pInput)
- {
- *ppPin = NULL ;
- return NOERROR ;
- }
- if( !m_pInput->IsConnected() )
- *ppPin = NULL ;
- else
- {
- *ppPin = m_pInput->GetConnected () ;
- (*ppPin)->AddRef() ;
- }
- return NOERROR ;
- }
-
- //
- // put_MediaType
- //
-
- STDMETHODIMP CNullInPlace::put_MediaType(CMediaType *pmt)
- {
- CAutoLock l(&m_NullIPLock);
-
- // if the state of the graph is running, fail the call.
- if (m_State == State_Running)
- return E_UNEXPECTED ;
-
- // check the source and sink filters like this media type
-
- if (pmt == NULL)
- m_mtPreferred.InitMediaType () ;
- else {
- IPin *pPin= m_pInput->GetConnected();
- if (pPin) {
- if (pPin->QueryAccept(pmt) != NOERROR) {
- MessageBox(NULL,TEXT("Source filter cannot provide this type"),
- TEXT("Format Selection"),
- MB_OK | MB_ICONEXCLAMATION);
- return VFW_E_TYPE_NOT_ACCEPTED;
- }
- }
- pPin= m_pOutput->GetConnected();
- if (pPin) {
- if (pPin->QueryAccept(pmt) != NOERROR) {
- MessageBox(NULL,TEXT("Target filter cannot accept this type"),
- TEXT("Format Selection"),
- MB_OK | MB_ICONEXCLAMATION);
- return VFW_E_TYPE_NOT_ACCEPTED;
- }
- }
- m_mtPreferred = *pmt ;
- }
-
- // force reconnect of input if the media type of connection does not match.
- if( m_pInput->IsConnected() )
- {
- if (m_pInput->CurrentMediaType()!= m_mtPreferred)
- m_pGraph->Reconnect(m_pInput);
- }
- return NOERROR ;
- }
-
- STDMETHODIMP CNullInPlace::get_MediaType(CMediaType **pmt)
- {
- CAutoLock l(&m_NullIPLock);
-
- *pmt = &m_mtPreferred ;
- return NOERROR ;
- }
-
-
- //
- // get_State
- //
- STDMETHODIMP CNullInPlace::get_State(FILTER_STATE *state)
- {
- CAutoLock l(&m_NullIPLock);
- *state = m_State ;
- return NOERROR;
- }
-
-
- // Reconnect the input and output pins as necessary
-
- HRESULT CNullInPlace::CompleteConnect(PIN_DIRECTION dir,IPin *pReceivePin)
- {
- ASSERT(m_pInput);
- ASSERT(m_pOutput);
-
- // Always reconnect the input to account for buffering changes
-
- if (dir == PINDIR_OUTPUT) {
- if( m_pInput->IsConnected() ) {
- return m_pGraph->Reconnect( m_pInput );
- }
- return NOERROR;
- }
-
- ASSERT(dir == PINDIR_INPUT);
-
- // Reconnect output if necessary
-
- if( m_pOutput->IsConnected() ) {
- if ( *m_pInput->CurrentMediaType().Subtype() !=
- *m_pOutput->CurrentMediaType().Subtype() ) {
- return m_pGraph->Reconnect( m_pOutput );
- }
- }
- return NOERROR;
- }
-
-
- //
- // --- ISpecifyPropertyPages ---
- //
-
-
- //
- // GetPages
- //
- // Returns the clsid's of the property pages we support
- STDMETHODIMP CNullInPlace::GetPages(CAUUID *pPages) {
-
- pPages->cElems = 1;
- pPages->pElems = (GUID *) CoTaskMemAlloc(sizeof(GUID));
- if (pPages->pElems == NULL) {
- return E_OUTOFMEMORY;
- }
- *(pPages->pElems) = CLSID_NullIPPropertyPage;
-
- return NOERROR;
- }
-
- /******************************Public*Routine******************************\
- * exported entry points for registration and
- * unregistration (in this case they only call
- * through to default implmentations).
- *
- *
- *
- * History:
- *
- \**************************************************************************/
- HRESULT
- DllRegisterServer()
- {
- return AMovieDllRegisterServer();
- }
-
- HRESULT
- DllUnregisterServer()
- {
- return AMovieDllUnregisterServer();
- }
-
-
- // Microsoft C Compiler will give hundreds of warnings about
- // unused inline functions in header files. Try to disable them.
- #pragma warning( disable:4514)
-
-
-