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

📄 miscfuncs.cpp

📁 完整的基于Conxant平台的USB电视棒的WIN驱动程序。
💻 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 "miscfuncs.h"

#include "audiotable.h"


VOID sleep(LONG time)
{
    if(KeGetCurrentIrql() != PASSIVE_LEVEL)
        return;

    LARGE_INTEGER wait_time;

    wait_time.LowPart = -(time*10000);
    wait_time.HighPart = -1;

    KeDelayExecutionThread(
        KernelMode,
        FALSE,
        &wait_time);
}

Device* getDevice(PIRP p_irp)
{
    PKSFILTER p_filter = KsGetFilterFromIrp(p_irp);
    if(!p_filter)
    {
        return NULL;
    }

    PKSDEVICE p_device = KsFilterGetDevice(p_filter);
    if(!p_device)
    {
        return NULL;
    }

    return (Device*)p_device->Context;
}

/////////////////////////////////////////////////////////////////////////////////////////
NTSTATUS editKsFilterPinDescriptors(PKSFILTER p_filter)
{
    NTSTATUS status = KsEdit(p_filter, &p_filter->Descriptor, 'TXNC');

    if(!NT_SUCCESS(status))
    {
        return status;
    }

    DWORD num_pins = p_filter->Descriptor->PinDescriptorsCount;

    //NOTE: When editing an array of more than one item, we must use KsEditSized, or
    // we will only get the size of one item in the array.

    return KsEditSized(
        p_filter, 
        &p_filter->Descriptor->PinDescriptors, 
        sizeof(KSPIN_DESCRIPTOR_EX) * num_pins,
        sizeof(KSPIN_DESCRIPTOR_EX) * num_pins,
        'TXNC');
}


/////////////////////////////////////////////////////////////////////////////////////////
NTSTATUS setMediumId(PKSFILTER p_filter, DWORD pin_index, DWORD medium_id)
{
    NTSTATUS status = editKsFilterPinDescriptors(p_filter);

    if(!NT_SUCCESS(status))
    {
        return status;
    }


    PKSPIN_MEDIUM* p_medium = 
        (PKSPIN_MEDIUM*)&p_filter->Descriptor->PinDescriptors[pin_index].PinDescriptor.Mediums;

	if(!p_medium)
    {
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    status = KsEdit(p_filter, 
                    p_medium, 
                    'TXNC');

    if(!NT_SUCCESS(status))
    {
        return status;
    }


    (*p_medium)->Id = medium_id;

    return STATUS_SUCCESS;
}


/////////////////////////////////////////////////////////////////////////////////////////
NTSTATUS setMediumId(PKSFILTER_DESCRIPTOR p_filter, DWORD pin_index, DWORD medium_id)
{

    PKSPIN_MEDIUM* p_medium = 
        (PKSPIN_MEDIUM*)&p_filter->PinDescriptors[pin_index].PinDescriptor.Mediums;

	if(!p_medium)
    {
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    (*p_medium)->Id = medium_id;

	return STATUS_SUCCESS;
}

/////////////////////////////////////////////////////////////////////////////////////////
BOOLEAN getVideoAndAudioStandardsForCountry(DWORD country_code, 
                                            KS_AnalogVideoStandard* p_video_standard, 
                                            AUDIO_STANDARD* p_audio_standard)
{
    if(country_code == 0xFFFFFFFF)
    {
        //This invalid value gets sent when the country code is not set.  
        // In that case, leave it alone.
        return FALSE;
    }

    KS_AnalogVideoStandard new_video_standard = KS_AnalogVideo_None;

    // Get the video standard based on the country code
    for(int i = 0; i < sizeof(g_country_to_video_table)/sizeof(COUNTRY_TABLE_ENTRY); i++)
    {
        if(g_country_to_video_table[i].country_code == country_code)
        {
            new_video_standard = g_country_to_video_table[i].video_standard;
            break;
        }
    }

    if(new_video_standard == KS_AnalogVideo_None)
    {
        return FALSE;
    }

    //Now get the audio standard from the video standard
    AUDIO_STANDARD audio_standard=AUDIO_STANDARD_NONE;
    if(country_code == CTRY_SOUTH_KOREA)
    {
        //Korea is a special case.
        audio_standard = AUDIO_STANDARD_A2_M;
    }
    else
    {
        for(int i = 0; i < sizeof(g_video_to_audio_table)/sizeof(TV_AUDIO_ENTRY); i++)
        {
            if(g_video_to_audio_table[i].video_standard == new_video_standard)
            {
                audio_standard = g_video_to_audio_table[i].audio_standard;
                break;
            }
        }
    }

    *p_video_standard = new_video_standard;
    *p_audio_standard = audio_standard;

    return TRUE;
}

⌨️ 快捷键说明

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