📄 crossbarpinset.cpp
字号:
/*+++ *******************************************************************\
*
* Copyright and Disclaimer:
*
* ---------------------------------------------------------------
* This software is provided "AS IS" without warranty of any kind,
* either expressed or implied, including but not limited to the
* implied warranties of noninfringement, merchantability and/or
* fitness for a particular purpose.
* ---------------------------------------------------------------
*
* Copyright (c) 2008 Conexant Systems, Inc.
* All rights reserved.
*
\******************************************************************* ---*/
#include "crossbarpinset.h"
#include "registryaccess.h"
#include "commonGuid.h"
#include "device.h"
#include "debug.h"
extern "C"
{
#include <strmini.h> //For definition of swprintf
}
/////////////////////////////////////////////////////////////////////////////////////////
//CrossbarPinSet::CrossbarPinSet (constructor)
//
// Gets the pin set from the registry, sets the initial routes,
// and sets up base class and member variables.
//
CrossbarPinSet::
CrossbarPinSet(
Device* p_device,
PDEVICE_OBJECT pdo):
CrossbarProperties(pdo),
_p_device(p_device),
_num_inpins(0),
_force_audio_with_video_pin(FALSE)
{
DbgLogInfo(("CrossbarPinSet::CrossbarPinSet()\n"));
InitializeListHead (&_pin_list_head);
getPinsFromRegistry(pdo);
RegistryAccess registry(pdo);
registry.readDword("ForceAudioWithVideoPin", &_force_audio_with_video_pin);
//Set up initial route.
setRoute(selectedVideoInput(), XBAR_OUTPIN_VIDEO_DECODER);
setRoute(selectedAudioInput(), XBAR_OUTPIN_AUDIO_DECODER);
}
/////////////////////////////////////////////////////////////////////////////////////////
//CrossbarPinSet::~CrossbarPinSet (destructor)
//
// Deletes the linked list of pin descriptors
//
CrossbarPinSet::~CrossbarPinSet()
{
//Clean up our list and delete all entries
while(!IsListEmpty (&_pin_list_head))
{
PPIN_ENTRY p_pin_entry = (PPIN_ENTRY)RemoveHeadList(&_pin_list_head);
delete p_pin_entry;
}
}
/////////////////////////////////////////////////////////////////////////////////////////
//CrossbarPinSet::getPinsFromRegistry
//
// Reads all the crossbar pins from the registry and sets up a linked list with the pin
// data.
//
//The pins are stored in the registry in keys:
// XBarPin0
// XBarPin1
// . . .
//
// Values within the keys are:
// PinType
// InputMux
// GPIOMask
// GPIOSettings
// RelatedPinIndex
//"DriverData\XBarPinXXX" 21 characters + NULL for 1000 pins
#define MAX_BUFFER_SIZE 22
VOID CrossbarPinSet::getPinsFromRegistry(PDEVICE_OBJECT pdo)
{
RegistryAccess registry(pdo);
for(int index =0; index < 1000; index++)
{
//Create the string for the registry key name
WCHAR string_buffer[MAX_BUFFER_SIZE];
swprintf(string_buffer, L"%s%d", L"DriverData\\XBarPin", index);
//Get the pin type
DWORD pin_type = 0;
NTSTATUS status = registry.readDword(
string_buffer,
"PinType",
&pin_type);
if(!(NT_SUCCESS(status)))
{
break;
}
//Get the data for the pin and add it to our list
PPIN_ENTRY p_pin_entry = new PIN_ENTRY;
if(!p_pin_entry)
{
break;
}
RtlZeroMemory(p_pin_entry, sizeof(PIN_ENTRY));
p_pin_entry->input_mux = 0xFFFFFFFF;
p_pin_entry->pin_type = (PIN_INPUT_TYPE) pin_type;
p_pin_entry->gpio_mask = 0;
p_pin_entry->gpio_setting = 0;
switch(pin_type)
{
case VIDEO_INPUT_TUNER_YC:
case VIDEO_INPUT_TUNER:
{
p_pin_entry->properties.type = KS_PhysConn_Video_Tuner;
KSPIN_MEDIUM medium = {TUNER_VIDEO_OUT_GUID, 0, 0};
RtlCopyMemory(&p_pin_entry->properties.medium, &medium, sizeof KSPIN_MEDIUM);
break;
}
case VIDEO_INPUT_SVIDEO:
p_pin_entry->properties.type = KS_PhysConn_Video_SVideo;
break;
case VIDEO_INPUT_COMPONENT:
p_pin_entry->properties.type = KS_PhysConn_Video_YRYBY;
break;
case VIDEO_INPUT_COMPOSITE:
case VIDEO_INPUT_COMPOSITE_YC:
p_pin_entry->properties.type = KS_PhysConn_Video_Composite;
break;
case AUDIO_INPUT_TUNER:
case AUDIO_INPUT_DIF_TUNER: //for dif tuner
{
p_pin_entry->properties.type = KS_PhysConn_Audio_Tuner;
KSPIN_MEDIUM medium = {TV_AUDIO_FILTER_OUT_GUID, 0, 0};
RtlCopyMemory(&p_pin_entry->properties.medium, &medium, sizeof KSPIN_MEDIUM);
break;
}
case AUDIO_INPUT_LINE:
p_pin_entry->properties.type = KS_PhysConn_Audio_Line;
break;
case VIDEO_INPUT_DIF_TUNER: //for dif tuner
{
p_pin_entry->properties.type = KS_PhysConn_Video_Tuner;
KSPIN_MEDIUM medium = {TUNER_DIF_VIDEO_OUT_GUID, 0, 0};
RtlCopyMemory(&p_pin_entry->properties.medium, &medium, sizeof KSPIN_MEDIUM);
break;
}
default:
DbgLogInfo(("CrossbarPinSet: getPinsFromRegistry: unknown type\n"));
return;
//ASSERT(FALSE); //Unknown pin type.
}
//Get the other values from the registry. They will be 0 if any
// of the values are not present.
//InputMux
registry.readDword(
string_buffer,
"InputMux",
&p_pin_entry->input_mux);
//InputMux2
registry.readDword(
string_buffer,
"InputMux2",
&p_pin_entry->input_mux2);
// RelatedPinIndex
registry.readDword(
string_buffer,
"RelatedPinIndex",
&p_pin_entry->properties.related_pin_index);
// GpioMask
registry.readDword(
string_buffer,
"GpioMask",
&p_pin_entry->gpio_mask);
// GpioSettings
registry.readDword(
string_buffer,
"GpioSettings",
&p_pin_entry->gpio_setting);
//Add the pin entry to the list.
InsertTailList(
&_pin_list_head,
&p_pin_entry->link);
_num_inpins++;
}
}
/////////////////////////////////////////////////////////////////////////////////////////
//CrossbarPinSet::findPin
//
// Gets the entry for a pin from the linked list of pin descriptors
//
PPIN_ENTRY CrossbarPinSet::findPin(DWORD index)
{
//Make sure the index is in the valid range
if(index > (_num_inpins - 1))
{
return NULL;
}
PLIST_ENTRY p_entry = _pin_list_head.Flink;
if(index == 0)
{
return (PPIN_ENTRY)p_entry;
}
DWORD i;
for( i = 0; i < index; i++)
{
p_entry = p_entry->Flink;
}
return (PPIN_ENTRY)p_entry;
}
/////////////////////////////////////////////////////////////////////////////////////////
//CrossbarPinSet::getNumInputPins()
//
// virtual function to return the number of input pins in this child class.
//
ULONG CrossbarPinSet::getNumInputPins()
{
return _num_inpins;
}
/////////////////////////////////////////////////////////////////////////////////////////
//CrossbarPinSet::getInputPinInfo
//
// Gets information about one of our input pins.
//
// Parameters:
// index - index of input pin
// p_pin_info - structure to return pin information in.
//
NTSTATUS CrossbarPinSet::getInputPinInfo(ULONG index,
PCROSSBAR_PIN_PROPERTIES p_pin_info)
{
PPIN_ENTRY p_pin_entry = findPin(index);
if(p_pin_entry == NULL)
{
return STATUS_INVALID_PARAMETER;
}
RtlCopyMemory(
p_pin_info,
&p_pin_entry->properties,
sizeof(CROSSBAR_PIN_PROPERTIES));
return STATUS_SUCCESS;
}
/////////////////////////////////////////////////////////////////////////////////////////
//CrossbarPinSet::setPinRoute
//
// Sets a route given the pin number to set. This function is the one that sends
// all the information out to the rest of the driver on how to set up the pin.
//
VOID CrossbarPinSet::setPinRoute(PPIN_ENTRY p_pin_entry)
{
//Set the pin type
_p_device->setCrossbarInputPin(
p_pin_entry->pin_type,
p_pin_entry->input_mux,
p_pin_entry->input_mux2,
p_pin_entry->gpio_mask,
p_pin_entry->gpio_setting);
}
/////////////////////////////////////////////////////////////////////////////////////////
//CrossbarPinSet::setRoute
//
// Sets up the hardware for a specific crossbar route. (virtual)
// Route is guaranteed to be valid or we wouldn't get called.
//
NTSTATUS CrossbarPinSet::setRoute(ULONG input_pin_index,
ULONG output_pin_index)
{
//Special case: if this is a mute command, the input pin index won't be
// valid
DbgLogInfo(("CrossbarPinSet::setRoute(%x,%x)\n", input_pin_index, output_pin_index));
if((input_pin_index == 0xFFFFFFFF) &&
(output_pin_index == XBAR_OUTPIN_AUDIO_DECODER))
{
selectedAudioInput() = input_pin_index;
_p_device->setCrossbarInputPin(AUDIO_INPUT_MUTE);
return STATUS_SUCCESS;
}
//Get the pin entry for this pin
PPIN_ENTRY p_pin_entry = findPin(input_pin_index);
if(!p_pin_entry)
{
//Bad input pin index
return STATUS_INVALID_PARAMETER;
}
switch(output_pin_index)
{
case XBAR_OUTPIN_VIDEO_DECODER:
{
//Save the video input pin
selectedVideoInput() = input_pin_index;
if(_force_audio_with_video_pin)
{
PPIN_ENTRY p_audio_pin =
findPin(p_pin_entry->properties.related_pin_index);
if(p_audio_pin)
{
//Mute the audio while we set the video
_p_device->setCrossbarInputPin(AUDIO_INPUT_MUTE);
}
//Set the video
setPinRoute(p_pin_entry);
if(p_audio_pin)
{
//Set the audio
selectedAudioInput() = p_pin_entry->properties.related_pin_index;
setPinRoute(p_audio_pin);
}
}
else
{
//Set the video
setPinRoute(p_pin_entry);
}
return STATUS_SUCCESS;
}
case XBAR_OUTPIN_AUDIO_DECODER:
{
selectedAudioInput() = input_pin_index;
setPinRoute(p_pin_entry);
return STATUS_SUCCESS;
}
default:
return STATUS_INVALID_PARAMETER;
}
}
/////////////////////////////////////////////////////////////////////////////////////////
//CrossbarPinSet::isAudioPin(ULONG pin_index)
//
// virtual function to determine rather or not a specific input pin index is an audio pin.
//
BOOLEAN CrossbarPinSet::isAudioPin(ULONG pin_index)
{
if(pin_index == 0xFFFFFFFF)
{
return TRUE;
}
PPIN_ENTRY p_pin_entry = findPin(pin_index);
if(!p_pin_entry)
{
//Invalid index
return FALSE;
}
switch(p_pin_entry->pin_type)
{
case AUDIO_INPUT_TUNER:
case AUDIO_INPUT_LINE:
return TRUE;
}
return FALSE;
}
/////////////////////////////////////////////////////////////////////////////////////////
//CrossbarPinSet::isVideoPin(ULONG pin_index)
//
// virtual function to determine rather or not a specific input pin index is a video pin.
//
// If it is a valid pin and is not an audio pin, then it must be a video pin.
//
BOOLEAN CrossbarPinSet::isVideoPin(ULONG pin_index)
{
if(!isValidPin(pin_index, TRUE))
{
return FALSE;
}
return !isAudioPin(pin_index);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -