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

📄 device.cpp

📁 ATI显卡Windows驱动
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//==========================================================================;
//
//	Device - Implementation of the Bt829 CVideoDecoderDevice
//
//		$Date:   28 Aug 1998 14:44:20  $
//	$Revision:   1.2  $
//	  $Author:   Tashjian  $
//
// $Copyright:	(c) 1997 - 1998  ATI Technologies Inc.  All Rights Reserved.  $
//
//==========================================================================;

#include "register.h"
#include "defaults.h"
#include "device.h"
#include "mediums.h"
#include "capdebug.h"
#include "StrmInfo.h"

#include "initguid.h"
DEFINE_GUID(DDVPTYPE_BROOKTREE,     0x1352A560L,0xDA61,0x11CF,0x9B,0x06,0x00,0xA0,0xC9,0x03,0xA3,0xB8);


// #define BT829_VPCONNECTIONS_NUMBER  2
#define BT829_VPCONNECTIONS_NUMBER  1
#define BT829_PIXELFORMATS_NUMBER   1
#define NTSC_FRAME_RATE 30
#define PAL_FRAME_RATE 25
#define BT829_LOST_LINES	2  // BT829
#define BT829A_LOST_LINES	3   // BT829a


Device::Device( PPORT_CONFIGURATION_INFORMATION ConfigInfo,
			    PDEVICE_PARMS pDeviceParms, 
				PUINT puiError) :

		m_pDeviceParms(pDeviceParms),

        // Corresponds to KS_DEFAULTs
        hue(128),
        saturation(128),
        contrast(128),
        brightness(128),
        source(ConTuner),
        VBIEN(FALSE),
        VBIFMT(FALSE),

        // Beware of these hardcoded values

        //Paul:  Setup default for NTSC and PAL
        NTSCDecoderWidth(720),
        NTSCDecoderHeight(240),
        PALDecoderWidth(720),
        PALDecoderHeight(288),
        // Now set via registry
        defaultDecoderWidth(720),
        defaultDecoderHeight(240)
{
	*puiError = 0;

    RegisterB devRegIDCODE (0x17, RO, pDeviceParms);
    RegField devFieldPART_ID (devRegIDCODE, 4, 4);
    RegField devFieldPART_REV (devRegIDCODE, 0, 4);

    m_pDeviceParms->chipID = (int)devFieldPART_ID;
    m_pDeviceParms->chipRev = (int)devFieldPART_REV;

	DBGINFO(("Chip ID: 0x%x\n", m_pDeviceParms->chipID));
	DBGINFO(("Chip revision: 0x%x\n", m_pDeviceParms->chipRev));

    // Bt829 should have a PartID of 1110b (0xe).
    if (m_pDeviceParms->chipID != 0xe)
    {
		DBGERROR(("I2c failure or wrong decoder.\n"));
		*puiError = 1;
        return;
    }

    PDEVICE_DATA_EXTENSION pHwExt = (PDEVICE_DATA_EXTENSION)ConfigInfo->HwDeviceExtension;
    decoder = (Decoder *)	new ((PVOID)&pHwExt->CDecoder) Decoder(m_pDeviceParms);
    scaler =  (Scaler *)	new ((PVOID)&pHwExt->CScaler) Scaler(m_pDeviceParms);
    xbar =	  (CrossBar *)	new ((PVOID)&pHwExt->CXbar) CrossBar();

    UseRegistryValues(ConfigInfo);

    // According to Brooktree, 4 is the magic dividing line
    // between 829 and 829a. Apparently, there is an 829b on the
    // horizon, but I don't have the details yet.
    // This is meant to be a kind of fail-safe
/*
    if (pHwExt->chipRev < 4) {
        outputEnablePolarity = 0;
    }
*/
 
    if (defaultDecoderWidth != 360 && defaultDecoderWidth != 720)
    {
        DBGERROR(("Unexpected defaultDecoderWidth: %d.\n", defaultDecoderWidth));
        TRAP();
    }

    destRect = MRect(0, 0, defaultDecoderWidth, defaultDecoderHeight);

    RestoreState();

    // by default, outputs will be tri-stated. Transitioning to the run state will enable it.
	SetOutputEnabled(FALSE);
}

Device::~Device()
{
    delete decoder;
    delete scaler;
    delete xbar;
}

void Device::SaveState()
{
    // save picture attributes
    hue = decoder->GetHue();
    saturation = decoder->GetSaturation();
    contrast =  decoder->GetContrast();
    brightness = decoder->GetBrightness();

    // save video source
    source = (Connector) GetVideoInput();

    // save configuration of data stream to video port
    isCodeInDataStream = IsCodeInsertionEnabled();
    is16 = Is16BitDataStream();
    
    // save VBI related settings
    VBIEN = IsVBIEN();
    VBIFMT = IsVBIFMT();

    // save scaling dimensions
    scaler->GetDigitalWin(destRect);
}

void Device::RestoreState(DWORD dwStreamsOpen)
{
    Reset();
    
    // (re)initialize image 
    decoder->SetInterlaced(FALSE);
    decoder->SetHue(hue);
    decoder->SetSaturation(saturation);
    decoder->SetContrast(contrast);
    decoder->SetBrightness(brightness);

    // (re)initialize video source
    SetVideoInput(source);

    SetOutputEnablePolarity(m_pDeviceParms->outputEnablePolarity);

    // (re)initialize corresponding xbar setting.
    // 'source' is one-based; Route expects zero-based
    Route(0, source);

    // (re)initialize configuration of data stream to video port
    SetCodeInsertionEnabled(isCodeInDataStream);
    Set16BitDataStream(is16);

    // restore VBI settings
    SetVBIEN(VBIEN);
    SetVBIFMT(VBIFMT);

    SetVideoDecoderStandard( GetVideoDecoderStandard() );
    // initialize scaling dimensions
    //SetRect(destRect);    Paul:  Use set video decoder standard instead

	if(!dwStreamsOpen)
		SetOutputEnabled(IsOutputEnabled());
}

void Device::SetRect(MRect &rect)
{
    destRect = rect;
    scaler->SetAnalogWin(rect);
    scaler->SetDigitalWin(rect);

    // for Debugging
#ifdef DBG
    scaler->DumpSomeState();
#endif
}

void Device::Reset()
{
    SoftwareReset();
}

int Device::GetDecoderWidth()
{
    MRect tmpRect;
    scaler->GetDigitalWin(tmpRect);

    return tmpRect.right;
}

int Device::GetDecoderHeight()
{
    MRect tmpRect;
    scaler->GetDigitalWin(tmpRect);

    return tmpRect.bottom;
}

int Device::GetDefaultDecoderWidth()
{
    return defaultDecoderWidth;
}

int Device::GetDefaultDecoderHeight()
{
    return defaultDecoderHeight;
}

int Device::GetPartID()
{
  return m_pDeviceParms->chipID;
}

int Device::GetPartRev()
{
  return m_pDeviceParms->chipRev;
}

NTSTATUS
Device::GetRegistryValue(
                   IN HANDLE Handle,
                   IN PWCHAR KeyNameString,
                   IN ULONG KeyNameStringLength,
                   IN PWCHAR Data,
                   IN ULONG DataLength
)
/*++

Routine Description:

    Reads the specified registry value

Arguments:

    Handle - handle to the registry key
    KeyNameString - value to read
    KeyNameStringLength - length of string
    Data - buffer to read data into
    DataLength - length of data buffer

Return Value:

    NTSTATUS returned as appropriate

--*/
{
    NTSTATUS        Status = STATUS_INSUFFICIENT_RESOURCES;
    UNICODE_STRING  KeyName;
    ULONG           Length;
    PKEY_VALUE_FULL_INFORMATION FullInfo;

    RtlInitUnicodeString(&KeyName, KeyNameString);

    Length = sizeof(KEY_VALUE_FULL_INFORMATION) +
        KeyNameStringLength + DataLength;

    FullInfo = (struct _KEY_VALUE_FULL_INFORMATION *)ExAllocatePool(PagedPool, Length);

    if (FullInfo) {
        Status = ZwQueryValueKey(Handle,
                                 &KeyName,
                                 KeyValueFullInformation,
                                 FullInfo,
                                 Length,
                                 &Length);

        if (NT_SUCCESS(Status)) {

            if (DataLength >= FullInfo->DataLength) {
                RtlCopyMemory(Data, ((PUCHAR) FullInfo) + FullInfo->DataOffset, FullInfo->DataLength);

            } else {

                TRAP();
                Status = STATUS_BUFFER_TOO_SMALL;
            }                   // buffer right length

        }                       // if success
        ExFreePool(FullInfo);

    }                           // if fullinfo
    return Status;

}

#define MAX_REG_STRING_LENGTH  128


VOID
Device::UseRegistryValues(PPORT_CONFIGURATION_INFORMATION ConfigInfo)
/*++

Routine Description:

    Reads all registry values for the device

Arguments:

    PhysicalDeviceObject - pointer to the PDO

Return Value:

     None.

--*/

{
    NTSTATUS        Status;
    HANDLE          handle;

    WCHAR   MUX0String[] =              L"MUX0";
    WCHAR   MUX1String[] =              L"MUX1";
    WCHAR   MUX2String[] =              L"MUX2";
    WCHAR   buf[MAX_REG_STRING_LENGTH];

    ASSERT(KeGetCurrentIrql() <= PASSIVE_LEVEL);

    Status = IoOpenDeviceRegistryKey(ConfigInfo->PhysicalDeviceObject,

⌨️ 快捷键说明

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