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

📄 wdmtuner.cpp

📁 传说中的 视频抓取驱动源码 啊啊啊啊啊啊啊啊啊啊啊啊啊
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//==========================================================================;
//
//  WDMTuner.CPP
//  WDM Tuner MiniDriver. 
//      Philips Tuner. 
//          CATIWDMTuner class implementation.
//  Copyright (c) 1996 - 1997  ATI Technologies Inc.  All Rights Reserved.
//
//      $Date:   10 Aug 1999 16:15:44  $
//  $Revision:   1.6  $
//    $Author:   KLEBANOV  $
//
//==========================================================================;

extern "C"
{
#include "strmini.h"
#include "ksmedia.h"

#include "wdmdebug.h"
}

#include "atitunep.h"
#include "wdmdrv.h"
#include "aticonfg.h"


#define ATI_TVAUDIO_SUPPORT


/*^^*
 *      AdapterCompleteInitialization()
 * Purpose  : Called when SRB_COMPLETE_UNINITIALIZATION SRB is received.
 *
 * Inputs   :   PHW_STREAM_REQUEST_BLOCK pSrb   : pointer to the current Srb
 *
 * Outputs  : BOOL : returns TRUE
 * Author   : IKLEBANOV
 *^^*/
NTSTATUS CATIWDMTuner::AdapterCompleteInitialization( PHW_STREAM_REQUEST_BLOCK pSrb)
{
    PADAPTER_DATA_EXTENSION pPrivateData = ( PADAPTER_DATA_EXTENSION)( pSrb->HwDeviceExtension);
    PDEVICE_OBJECT pDeviceObject = pPrivateData->PhysicalDeviceObject;
    KSPIN_MEDIUM    mediumKSPin;
    NTSTATUS        ntStatus;
    UINT            nIndex;
    HANDLE          hFolder;
    ULONG           ulInstance;

    ENSURE
    {
        nIndex = 0;

        switch( m_ulNumberOfPins)
        {
            case 2:
                // TVTuner with TVAudio
                ::RtlCopyMemory( &m_pTVTunerPinsMediumInfo[nIndex ++], &ATITVTunerVideoOutMedium, sizeof( KSPIN_MEDIUM));
#ifdef ATI_TVAUDIO_SUPPORT
#pragma message ("\n!!! PAY ATTENTION: Tuner PinMedium is compiled with TVAudio support !!!\n")
                ::RtlCopyMemory( &m_pTVTunerPinsMediumInfo[nIndex], &ATITVTunerTVAudioOutMedium, sizeof( KSPIN_MEDIUM));
#else
#pragma message ("\n!!! PAY ATTENTION: Tuner PinMedium is compiled without TVAudio support !!!\n")
                ::RtlCopyMemory( &m_pTVTunerPinsMediumInfo[nIndex ++], &ATIXBarAudioTunerInMedium, sizeof( KSPIN_MEDIUM));
#endif
                break;

            case 3:
                // TVTuner with TVAudio with separate FM Audio output
                ::RtlCopyMemory( &m_pTVTunerPinsMediumInfo[nIndex ++], &ATITVTunerVideoOutMedium, sizeof( KSPIN_MEDIUM));
#ifdef ATI_TVAUDIO_SUPPORT
                ::RtlCopyMemory( &m_pTVTunerPinsMediumInfo[nIndex ++], &ATITVTunerTVAudioOutMedium, sizeof( KSPIN_MEDIUM));
#else
                ::RtlCopyMemory( &m_pTVTunerPinsMediumInfo[nIndex ++], &ATIXBarAudioTunerInMedium, sizeof( KSPIN_MEDIUM));
#endif

            case 1:
                // it can be FM Tuner only.
                ::RtlCopyMemory( &m_pTVTunerPinsMediumInfo[nIndex], &ATITVTunerRadioAudioOutMedium, sizeof( KSPIN_MEDIUM));
                break;
        }

        ulInstance = ::GetDriverInstanceNumber( pDeviceObject);
        hFolder = ::OpenRegistryFolder( pDeviceObject, UNICODE_WDM_REG_PIN_MEDIUMS);

        for( nIndex = 0; nIndex < m_ulNumberOfPins; nIndex ++)
        {
            if( ::ReadPinMediumFromRegistryFolder( hFolder, nIndex, &mediumKSPin))
                ::RtlCopyMemory( &m_pTVTunerPinsMediumInfo[nIndex], &mediumKSPin, sizeof( KSPIN_MEDIUM));
            m_pTVTunerPinsMediumInfo[nIndex].Id = ulInstance;

            // all the possible pins exposed are the outputs
            m_pTVTunerPinsDirectionInfo[nIndex] = TRUE;
        }

        if( hFolder != NULL)
            ::ZwClose( hFolder);

        ntStatus = StreamClassRegisterFilterWithNoKSPins( \
                        pDeviceObject                   ,       // IN PDEVICE_OBJECT   DeviceObject,
                        &KSCATEGORY_TVTUNER,                    // IN GUID           * InterfaceClassGUID
                        m_ulNumberOfPins,                       // IN ULONG            PinCount,
                        m_pTVTunerPinsDirectionInfo,            // IN ULONG          * Flags,
                        m_pTVTunerPinsMediumInfo,               // IN KSPIN_MEDIUM   * MediumList,
                        NULL);                                  // IN GUID           * CategoryList

        if( !NT_SUCCESS( ntStatus))
            FAIL;

        OutputDebugInfo(( "CATIWDMTuner:AdapterCompleteInitialization() exit\n"));

    } END_ENSURE;

    if( !NT_SUCCESS( ntStatus))
        OutputDebugError(( "CATIWDMTuner:AdapterCompleteInitialization() ntStatus=%x\n",    ntStatus));

    return( ntStatus);
}



/*^^*
 *      AdapterUnInitialize()
 * Purpose  : Called when SRB_UNINITIALIZE_DEVICE SRB is received.
 *
 * Inputs   :   PHW_STREAM_REQUEST_BLOCK pSrb   : pointer to the current Srb
 *
 * Outputs  : BOOL : returns TRUE
 * Author   : IKLEBANOV
 *^^*/
BOOL CATIWDMTuner::AdapterUnInitialize( PHW_STREAM_REQUEST_BLOCK pSrb)
{

    OutputDebugTrace(( "CATIWDMTuner:AdapterUnInitialize()\n"));

    // just deallocate the any memory was allocated at run-time
    if( m_pTVTunerPinsMediumInfo != NULL)
    {
        ::ExFreePool( m_pTVTunerPinsMediumInfo);
        m_pTVTunerPinsMediumInfo = NULL;
    }

    if( m_pTVTunerPinsDirectionInfo != NULL)
    {
        ::ExFreePool( m_pTVTunerPinsDirectionInfo);
        m_pTVTunerPinsDirectionInfo = NULL;
    }

    pSrb->Status = STATUS_SUCCESS;
    return( TRUE);
}


/*^^*
 *      AdapterGetStreamInfo()
 * Purpose  : fills in HW_STREAM_HEADER for StreamClass driver
 *
 * Inputs   : PHW_STREAM_REQUEST_BLOCK pSrb : pointer to the current Srb
 *
 * Outputs  : BOOL : returns TRUE
 * Author   : IKLEBANOV
 *^^*/
BOOL CATIWDMTuner::AdapterGetStreamInfo( PHW_STREAM_REQUEST_BLOCK pSrb)
{
     // pick up the pointer to the stream header data structure
    PHW_STREAM_HEADER pStreamHeader = ( PHW_STREAM_HEADER)&( pSrb->CommandData.StreamBuffer->StreamHeader);

    // no streams are supported
    DEBUG_ASSERT( pSrb->NumberOfBytesToTransfer >= sizeof( HW_STREAM_HEADER));

    OutputDebugTrace(( "CATIWDMTuner:AdapterGetStreamInfo()\n"));

    m_wdmTunerStreamHeader.NumberOfStreams = 0;
    m_wdmTunerStreamHeader.SizeOfHwStreamInformation = sizeof( HW_STREAM_INFORMATION);
    m_wdmTunerStreamHeader.NumDevPropArrayEntries = 1;
    m_wdmTunerStreamHeader.DevicePropertiesArray = &m_wdmTunerPropertySet;
    m_wdmTunerStreamHeader.NumDevEventArrayEntries = 0;
    m_wdmTunerStreamHeader.DeviceEventsArray = NULL;
    m_wdmTunerStreamHeader.Topology = &m_wdmTunerTopology;

    * pStreamHeader = m_wdmTunerStreamHeader;

    pSrb->Status = STATUS_SUCCESS;
    return( TRUE);
}


/*^^*
 *      AdapterQueryUnload()
 * Purpose  : Called when the class driver is about to unload the MiniDriver
 *              The MiniDriver checks if any open stream left.
 *
 * Inputs   :   PHW_STREAM_REQUEST_BLOCK pSrb   : pointer to the current Srb
 *
 * Outputs  : BOOL : returns TRUE
 * Author   : IKLEBANOV
 *^^*/
BOOL CATIWDMTuner::AdapterQueryUnload( PHW_STREAM_REQUEST_BLOCK pSrb)
{

    OutputDebugTrace(( "CATIWDMTuner:AdapterQueryUnload()\n"));

    pSrb->Status = STATUS_SUCCESS;
    return( TRUE);
}



/*^^*
 *      operator new
 * Purpose  : CATIWDMTuner class overloaded operator new.
 *              Provides placement for a CATIWDMTuner class object from the PADAPTER_DEVICE_EXTENSION
 *              allocated by the StreamClassDriver for the MiniDriver.
 *
 * Inputs   :   UINT size_t         : size of the object to be placed
 *              PVOID pAllocation   : casted pointer to the CWDMTuner allocated data
 *
 * Outputs  : PVOID : pointer of the CATIWDMTuner class object
 * Author   : IKLEBANOV
 *^^*/
PVOID CATIWDMTuner::operator new( size_t size_t, PVOID pAllocation)
{

    if( size_t != sizeof( CATIWDMTuner))
    {
        OutputDebugError(( "CATIWDMTuner: operator new() fails\n"));
        return( NULL);
    }
    else
        return( pAllocation);
}



/*^^*
 *      ~CATIWDMTuner()
 * Purpose  : CATIWDMTuner class destructor.
 *              Frees the allocated memory.
 *
 * Inputs   : none
 *
 * Outputs  : none
 * Author   : IKLEBANOV
 *^^*/
CATIWDMTuner::~CATIWDMTuner()
{

    OutputDebugTrace(( "CATIWDMTuner:~CATIWDMTuner()\n"));

    if( m_pTVTunerPinsMediumInfo != NULL)
    {
        ::ExFreePool( m_pTVTunerPinsMediumInfo);
        m_pTVTunerPinsMediumInfo = NULL;
    }

    if( m_pTVTunerPinsDirectionInfo != NULL)
    {
        ::ExFreePool( m_pTVTunerPinsDirectionInfo);
        m_pTVTunerPinsDirectionInfo = NULL;
    }
}



/*^^*
 *      CATIWDMTuner()
 * Purpose  : CATIWDMTuner class constructor.
 *              Performs checking of the hardware presence. Sets the hardware in an initial state.
 *
 * Inputs   :   CI2CScript * pCScript   : pointer to the I2CScript class object
 *              PUINT puiError          : pointer to return a completion error code
 *
 * Outputs  : none
 * Author   : IKLEBANOV
 *^^*/
CATIWDMTuner::CATIWDMTuner( PPORT_CONFIGURATION_INFORMATION pConfigInfo, CI2CScript * pCScript, PUINT puiErrorCode)
    :m_CATIConfiguration( pConfigInfo, pCScript, puiErrorCode)
{
    UINT uiError;

    OutputDebugTrace(( "CATIWDMTuner:CATIWDMTuner() enter\n"));

    // error code was carried over from ATIConfiguration class constructor
    uiError = * puiErrorCode;

    m_pTVTunerPinsMediumInfo = NULL;
    m_pTVTunerPinsDirectionInfo = NULL;
    m_ulPowerState = PowerDeviceD0;
    
    ENSURE
    {
        if( uiError != WDMMINI_NOERROR)
            // ATIConfiguration Class object was constructed with an error
            FAIL;

        if( pCScript == NULL)
        {
            uiError = WDMMINI_INVALIDPARAM;
            FAIL;
        }

        if( !m_CATIConfiguration.GetTunerConfiguration( &m_uiTunerId, &m_uchTunerI2CAddress) ||
            ( !m_uchTunerI2CAddress))
        {
            // there was no hardware information found
            uiError = WDMMINI_NOHARDWARE;
            FAIL;
        }

        // Set tuner capabilities ( RO properties) based upon the TunerId
        if( !SetTunerWDMCapabilities( m_uiTunerId) || ( !m_ulNumberOfPins))

⌨️ 快捷键说明

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