⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filter.cpp

📁 winddk src目录下的WDM源码压缩!
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*++

Copyright (c) 1999  Microsoft Corporation

Module Name:

    filter.cpp

Abstract:

    Filter core, initialization, etc.

--*/

#include "BDATuner.h"

#ifdef ALLOC_DATA_PRAGMA
#pragma const_seg("PAGECONST")
#endif // ALLOC_DATA_PRAGMA

#ifdef ALLOC_PRAGMA
#pragma code_seg("PAGE")
#endif // ALLOC_PRAGMA

/*
** Create() method of the CFilter class
**
**    Creates the filter object,
**    associates it with the device object, and 
**    initializes member variables for it.
**
*/
STDMETHODIMP_(NTSTATUS)
CFilter::Create(
    IN OUT PKSFILTER pKSFilter,
    IN PIRP Irp
    )
{
    NTSTATUS    Status = STATUS_SUCCESS;
    ULONG       ulPinId;  // just useful when no network provider is present
    PKSDEVICE   pKSDevice = NULL;
    CDevice *   pDevice = NULL;

    _DbgPrintF(DEBUGLVL_VERBOSE,("FilterCreate"));

    ASSERT(pKSFilter);
    ASSERT(Irp);


    //  Create a filter object for the filter instance.
    //
    CFilter* pFilter = new(PagedPool,MS_SAMPLE_TUNER_POOL_TAG) CFilter; // Tags the allocated memory
    if (!pFilter)
    {
        Status = STATUS_INSUFFICIENT_RESOURCES;
        goto errExit;
    }
    //  Link the filter context to the passed in pointer to the KSFILTER structure.
    //
    pKSFilter->Context = pFilter;

    //  Point to the KS device object for this filter.
    //
    pKSDevice = KsFilterGetDevice( pKSFilter);
    ASSERT( pKSDevice);
    if (!pKSDevice)
    {
        Status = STATUS_DEVICE_NOT_CONNECTED;
        goto errExit;
    }

    //  Get the device object from the retrieved pointer to the KSDevice for this filter.
    //
    pDevice = reinterpret_cast<CDevice *>(pKSDevice->Context);
    ASSERT( pDevice);
    if (!pDevice)
    {
        Status = STATUS_DEVICE_NOT_CONNECTED;
        goto errExit;
    }

    //  Link the filter context to the device context.
    //  That is, set the filter's device pointer data member to the obtained device pointer.
    //
    pFilter->m_pDevice = pDevice;

    //  Initialize member variables.
    //
    pFilter->m_KsState = KSSTATE_STOP;
    pFilter->m_BdaChangeState = BDA_CHANGES_COMPLETE;
    pFilter->m_ulResourceID = 0;

    //  Configure the initial resource for ATSC reception of channel 39.
    pFilter->m_CurResource.ulCarrierFrequency = 621250000L;
    pFilter->m_CurResource.ulFrequencyMultiplier = 1;
    pFilter->m_CurResource.guidDemodulator = KSNODE_BDA_8VSB_DEMODULATOR;
    pFilter->m_fResourceAcquired = FALSE;

    //  Call the BDA support library to initialize the
    //  filter instance with the default template topology.
    //
    Status = BdaInitFilter( pKSFilter, &BdaFilterTemplate);
    if (NT_ERROR( Status))
    {
        goto errExit;
    }

#ifdef NO_NETWORK_PROVIDER
    //
    //  This code can be used for initial testing of a filter when
    //  a network provider can't be used to configure the filter.
    //  This situation may arise when the receiver topology includes
    //  filters that have not yet been written or when a new network
    //  type does not yet have a network provider implementation.
    //
    //  This code should NOT be used when a driver is delivered into
    //  a working BDA receiver solution.
    //

    //  Create the transport output pin
    //
    Status = BdaCreatePin( pKSFilter, 
                           PIN_TYPE_TRANSPORT, 
                           &ulOutputPinId
                           );
    if (!NT_SUCCESS(Status))
    {
        goto errExit;
    }
    
    //  Create the topology between the antenna input and
    //  transport output pins.
    //
    //  Note that the antenna input pin was automatically created
    //  because it was included in the pin descriptor list of the
    //  initial filter descriptor passed to BdaCreateFilterFactory.
    //
    Status = BdaCreateTopology( pKSFilter, 
                                INITIAL_ANNTENNA_PIN_ID, 
                                ulOutputPinId
                                );
    if (!NT_SUCCESS(Status))
    {
        goto errExit;
    }

#endif // NO_NETWORK_PROVIDER

exit:
    return Status;

errExit:
    if (pFilter)
    {
        delete pFilter;
    }
    pKSFilter->Context = NULL;

    goto exit;
}


/*
** FilterClose() method of the CFilter class
**
**    Deletes the previously created filter object.
**
*/
STDMETHODIMP_(NTSTATUS)
CFilter::FilterClose(
    IN OUT PKSFILTER Filter,
    IN PIRP Irp
    )
{
    _DbgPrintF(DEBUGLVL_VERBOSE,("FilterClose"));

    ASSERT(Filter);
    ASSERT(Irp);

    CFilter* filter = reinterpret_cast<CFilter*>(Filter->Context);
    ASSERT(filter);

    delete filter;

    return STATUS_SUCCESS;
}

/*
** StartChanges() method of the CFilter class
**
**    Puts the filter into change state.  All changes to BDA topology
**    and properties changed after this will be in effect only after
**    a call to the CFilter::CommitChanges() method.
**
*/
NTSTATUS
CFilter::StartChanges(
    IN PIRP         pIrp,
    IN PKSMETHOD    pKSMethod,
    OPTIONAL PVOID  pvIgnored
    )
{
    NTSTATUS        Status = STATUS_SUCCESS;
    CFilter *       pFilter;

    ASSERT( pIrp);
    ASSERT( pKSMethod);

    //  Obtain a "this" pointer to the filter object.
    //
    //  Because the property dispatch table calls the CFilter::StartChanges() method 
    //  directly, the method must retrieve a pointer to the underlying filter object.
    //
    pFilter = reinterpret_cast<CFilter *>(KsGetFilterFromIrp(pIrp)->Context);
    ASSERT( pFilter);

    //  Call the BDA support library to 
    //  reset any pending BDA topolgoy changes.
    //
    Status = BdaStartChanges( pIrp);
    if (NT_SUCCESS( Status))
    {
        //  Reset any pending resource changes.
        //
        pFilter->m_NewResource = pFilter->m_CurResource;
        pFilter->m_BdaChangeState = BDA_CHANGES_COMPLETE;
    }

    return Status;
}


/*
** CheckChanges() method of the CFilter class
**
**    Checks the changes to BDA interfaces that have occured since the
**    last call to the CFilter::StartChanges() method.  Returns the identical 
**    result that the CFilter::CommitChanges() method returns.
**
*/
NTSTATUS
CFilter::CheckChanges(
    IN PIRP         pIrp,
    IN PKSMETHOD    pKSMethod,
    OPTIONAL PVOID  pvIgnored
    )
{
    NTSTATUS            Status = STATUS_SUCCESS;
    CFilter *           pFilter;
    BDA_CHANGE_STATE    topologyChangeState;

    ASSERT( pIrp);
    ASSERT( pKSMethod);

    //  Obtain a "this" pointer to the filter object.
    //
    //  Because the property dispatch table calls the CFilter::CheckChanges() method 
    //  directly, the method must retrieve a pointer to the underlying filter object.
    //
    pFilter = reinterpret_cast<CFilter *>(KsGetFilterFromIrp(pIrp)->Context);
    ASSERT( pFilter);

    //  Call the BDA support library to 
    //  verify a new set of BDA topology changes.
    //
    Status = BdaCheckChanges( pIrp);
    if (NT_SUCCESS( Status))
    {
        //
        //  Validate the new resource list here.
        //  In this driver the new resource list is always valid.
        //
    }

    return Status;
}


/*
** CommitChanges() method of the CFilter class
**
**    Checks and commits the changes to BDA interfaces that have occured since the
**    last call to the CFilter::StartChanges() method.  
**
*/
NTSTATUS
CFilter::CommitChanges(
    IN PIRP         pIrp,
    IN PKSMETHOD    pKSMethod,
    OPTIONAL PVOID  pvIgnored
    )
{
    NTSTATUS        Status = STATUS_SUCCESS;
    CFilter *       pFilter;

    ASSERT( pIrp);
    ASSERT( pKSMethod);

    //  Obtain a "this" pointer to the filter object.
    //
    //  Because the property dispatch table calls the CFilter::CommitChanges() method 
    //  directly, the method must retrieve a pointer to the underlying filter object.
    //
    pFilter = reinterpret_cast<CFilter *>(KsGetFilterFromIrp(pIrp)->Context);
    ASSERT( pFilter);

    //
    //  Validate the new resource list here.
    //  In this driver the new resource list is always valid.
    //

    //  Mark the changes as having been made.
    //
    pFilter->m_CurResource = pFilter->m_NewResource;
    pFilter->m_BdaChangeState = BDA_CHANGES_COMPLETE;
    
    if (pFilter->m_KsState != KSSTATE_STOP)
    {
        //  Commit the resources on the underlying device
        //
        Status = pFilter->AcquireResources( );
        ASSERT( NT_SUCCESS( Status));
    }

    //  Call the BDA support library to 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -