btcard.cpp

来自「一个开放源码的bt848/878驱动程序的源码」· C++ 代码 · 共 1,724 行 · 第 1/5 页

CPP
1,724
字号
void BtCard::AudioUnmute( void )
{
	// Only if we were muted ...
	if (bAudioMuted) {

		// Get card information
		CInfo* Info = GetCardInfo(); 

		// Enable the corresponding GPIO pins to select audio sources...
		GetBtPisces().SetGPOE( GetBtPisces().GetGPOE() | Info->gpoe );

		// Set the correct bits to enable the Line Source
		ULONG Val;
		GetBtPisces().GetGPDATA(&Val,1,0);
		Val &= ~Info->gpoe;							// Keep all bits not involved into audio switching: all the others set to 0
		Val |=  Info->gpoe & Info->audiomux[AudioMux];	// And select the audio source without disrupting the other bits...
		GetBtPisces().SetGPDATA(&Val,1,0);

		// Now, For all the AudioChips, set the input!
		for (DWORD Idx = 0 ; Idx < AudioCount ; Idx ++) {
			AudioChip[Idx]->SetAudioConnector(AudioMux);
		}

		// Unmute!
		bAudioMuted = FALSE; 
	}
}      

void BtCard::AudioMute( void )
{
	// Only if we were not unmuted
	if (!bAudioMuted) {

		// Get card information
		CInfo* Info = GetCardInfo(); 

		// Enable the corresponding GPIO pins to select audio sources...
		GetBtPisces().SetGPOE( GetBtPisces().GetGPOE() | Info->gpoe );

		// Set the correct bits to enable the Line Source
		ULONG Val;
		GetBtPisces().GetGPDATA(&Val,1,0);
		Val &= ~Info->gpoe;								// Keep all bits not involved into audio switching: all the others set to 0
		Val |=  Info->gpoe & Info->audiomux[AudioConMute];	// And select the audio source without disrupting the other bits...
		GetBtPisces().SetGPDATA(&Val,1,0);

		// Now, for all the AudioChips, Mute audio!
		for (DWORD Idx = 0 ; Idx < AudioCount ; Idx ++) {
			AudioChip[Idx]->SetAudioConnector(AudioConMute);
		}

		bAudioMuted = TRUE;
	}
}      

// Gets the Capabilities ...
ULONG BtCard::AudioGetCaps()
{
	// We start with mono Sound AND Lang A
	ULONG Caps = KS_TVAUDIO_MODE_MONO | KS_TVAUDIO_MODE_LANG_A;

	// Now, For all the AudioChips, Get Caps!
	for (DWORD Idx = 0 ; Idx < AudioCount ; Idx ++) {
		// Get Available modes from Audiochip
		AudioModes AvModes = AudioChip[Idx]->AudioModesAvailable();
		// If mono available, mark it!
		if (AvModes & Am_Mono)	 Caps |= KS_TVAUDIO_MODE_MONO   | KS_TVAUDIO_MODE_LANG_A;
		// If Stereo available, mark it!
		if (AvModes & Am_Stereo) Caps |= KS_TVAUDIO_MODE_STEREO | KS_TVAUDIO_MODE_LANG_A; // Yes, Stereo in the first language
		// If Lang A available, mark it!
		if (AvModes & Am_Lang1)	 Caps |= KS_TVAUDIO_MODE_LANG_B | KS_TVAUDIO_MODE_MONO;
		// If Lang B available, mark it!
		if (AvModes & Am_Lang2)	 Caps |= KS_TVAUDIO_MODE_LANG_C | KS_TVAUDIO_MODE_MONO;
	}

	// Now, for all tuners, Get Caps!
	for (Idx = 0 ; Idx < TunerCount ; Idx ++) {
		if (TunerChip[Idx]->AMStereoAvailable() ||
			TunerChip[Idx]->FMStereoAvailable()	||
			TunerChip[Idx]->TVStereoAvailable() ) Caps |= KS_TVAUDIO_MODE_STEREO | KS_TVAUDIO_MODE_LANG_A;
	}

	// Return capacities
	return Caps;
}

// Get all the Supported Modes Right now for the current mode
ULONG BtCard::AudioGetSupportedModes()
{
	// We start with mono Sound
	ULONG Modes = KS_TVAUDIO_MODE_MONO | KS_TVAUDIO_MODE_LANG_A;

	// Now, For all the AudioChips, Get Caps. This is valid for TV (and for FM and AM radio also)
	// Normally, audio Chips handles Stereo of TV, SAP of TV, AND Stereo of FM
	DWORD Idx;
	for (Idx = 0 ; Idx < AudioCount ; Idx ++) {
		// Get Detected modes..
		AudioModes DetModes = AudioChip[Idx]->AudioModesDetected();
		// If mono available, mark it!
		if (DetModes & Am_Mono)		Modes |= KS_TVAUDIO_MODE_MONO   | KS_TVAUDIO_MODE_LANG_A;
		// If Stereo available, mark it!
		if (DetModes & Am_Stereo)	Modes |= KS_TVAUDIO_MODE_STEREO | KS_TVAUDIO_MODE_LANG_A;
		// If Lang A available, mark it!
		if (DetModes & Am_Lang1)	Modes |= KS_TVAUDIO_MODE_LANG_B | KS_TVAUDIO_MODE_MONO;
		// If Lang B available, mark it!
		if (DetModes & Am_Lang2)	Modes |= KS_TVAUDIO_MODE_LANG_C | KS_TVAUDIO_MODE_MONO;
	}

	// Now, for all tuners, Get Caps. 
	// Here we must select the correct tuner only, because there can be more than 1 tuner in the system!
	for (Idx = 0 ; Idx < TunerCount ; Idx ++) {
		if ((m_CurrentTunerMode == HwTuner::Tm_TV && TunerChip[Idx]->CanTuneTV())) {
			if (TunerChip[Idx]->TVStereoDetected()) Modes |= KS_TVAUDIO_MODE_STEREO | KS_TVAUDIO_MODE_LANG_A;
		}
		if ((m_CurrentTunerMode == HwTuner::Tm_Radio_AM && TunerChip[Idx]->CanTuneAM())) {
			if (TunerChip[Idx]->AMStereoDetected()) Modes |= KS_TVAUDIO_MODE_STEREO | KS_TVAUDIO_MODE_LANG_A;
		}
		if ((m_CurrentTunerMode == HwTuner::Tm_Radio_FM && TunerChip[Idx]->CanTuneFM())) {
			if (TunerChip[Idx]->FMStereoDetected()) Modes |= KS_TVAUDIO_MODE_STEREO | KS_TVAUDIO_MODE_LANG_A;
		}
	}

	// Return capacities
	return Modes;
}

NTSTATUS BtCard::AudioSetMode(ULONG New)
{
	// Note! -- Argh!
	// Microsoft fucked this up! - 
	//		I was assuming that you should be able to specify either Mono or Stereo
	// for each language (A/B/C)... But default TV mode dialogs don't allow this ...
	// You can select one of: Mono,Stereo,LangA,LangB,LangC... That is wrong! - So i have to
	// cope with it. Also, LangA could be either Mono or Stereo... Mono if receiving a Dual
	// trnasmission, Stereo if receiving an Stereo transmission... So we will translate them!
	
	// Fill in all the missing pieces of info... If the calling app is not passing the right parameters... as Microsoft does.
	if (New == KS_TVAUDIO_MODE_LANG_A) {
		// I Assume a Mono transmission of a Dual Channel...
		New |= (KS_TVAUDIO_MODE_LANG_A | KS_TVAUDIO_MODE_MONO);
	} else 
	if (New == KS_TVAUDIO_MODE_LANG_B) {
		// I Assume a Mono transmission of a Dual Channel...
		New |= (KS_TVAUDIO_MODE_LANG_B | KS_TVAUDIO_MODE_MONO);
	} else 
	if (New == KS_TVAUDIO_MODE_LANG_C) {
		// I Assume a Mono transmission of a Dual Channel...
		New |= (KS_TVAUDIO_MODE_LANG_C | KS_TVAUDIO_MODE_MONO);
	} else
	if (New == KS_TVAUDIO_MODE_MONO) {
		// I Assume a Mono transmission of the default channel...
		New |= (KS_TVAUDIO_MODE_LANG_A | KS_TVAUDIO_MODE_MONO);
	} else
	if (New == KS_TVAUDIO_MODE_STEREO) {
		// I Assume an Stereo transmission of the default channel...
		New |= (KS_TVAUDIO_MODE_LANG_A | KS_TVAUDIO_MODE_STEREO);
	}

	// Get actually available modes...
	ULONG ValidModes = AudioGetSupportedModes();

	// Ensure at least one of STEREO / MONO is selected! (could be both)
	if ((New & (KS_TVAUDIO_MODE_MONO | KS_TVAUDIO_MODE_STEREO)) == 0) {

		// Try to get Stereo if supported if it is NOT specified
		if (ValidModes & KS_TVAUDIO_MODE_STEREO) {
			New |= KS_TVAUDIO_MODE_STEREO;
		} else {
			New |= KS_TVAUDIO_MODE_MONO;
		}
	}

	// Ensure at least LANG_A is selected!
	if ( (New & (KS_TVAUDIO_MODE_LANG_A | KS_TVAUDIO_MODE_LANG_B | KS_TVAUDIO_MODE_LANG_C) ) == 0) {
		New |= KS_TVAUDIO_MODE_LANG_A;
	}

	// If something that is NOT supported right now is asked, fail!
	if (
		( (New & (~ValidModes)) &
			(KS_TVAUDIO_MODE_MONO | KS_TVAUDIO_MODE_STEREO | 
			 KS_TVAUDIO_MODE_LANG_A | KS_TVAUDIO_MODE_LANG_B | KS_TVAUDIO_MODE_LANG_C )
		) != 0

		) {
		return STATUS_INVALID_PARAMETER;
	}

	// We usually can receive one of:
	//	-Mono
	//	-Stereo
	//	-Dual A/B
	//	-NICAM... 

	// Note that if we are receiving Dual channels, we won't receive in Stereo...

	// Only if mode has Changed ...
	if (New != m_AudioMode) {

		// Store New AudioMode
		m_AudioMode = New;

		// Translate WDM to our representation
		AudioMode am = Am_Mono;

		if (New & KS_TVAUDIO_MODE_LANG_C) {
			am = Am_Lang2;
		} else 
		if (New & KS_TVAUDIO_MODE_LANG_B) {
			am = Am_Lang1;
		} else 
		if (New & KS_TVAUDIO_MODE_STEREO) {
			am = Am_Stereo;
		}

		// Now, for all tuners, Set Mode!
		DWORD Idx;
		for (Idx = 0 ; Idx < TunerCount ; Idx ++) {
			TunerChip[Idx]->SetAudioMode(am);
		}

		// Now for all audioChips, Set mode and language
		for (Idx = 0 ; Idx < AudioCount ; Idx ++) {
			AudioChip[Idx]->SetAudioMode(am);
		}
	}

	return STATUS_SUCCESS;
}

bool BtCard::HasTunerInput( void ) const
{
	if (!VideoCount) 
		return GetCardInfo()->tuner0 != NONE ? true : false;

	bool c = false;
	for (DWORD Idx = 0 ; Idx < VideoCount ; Idx ++) {
		c |= VideoChip[Idx]->HasTunerInput();
	}
	return c;
}

int	BtCard::SVideoInputCount( void ) const
{
	if (!VideoCount) 
		return GetCardInfo()->svhs0 != NONE ? 1 : 0;

	int c = 0;
	for (DWORD Idx = 0 ; Idx < VideoCount ; Idx ++) {
		c += VideoChip[Idx]->SVideoCount();
	}
	return c;
}

int	BtCard::CompositeInputCount( void ) const
{
	if (!VideoCount) 
		return GetCardInfo()->analogvideoins - SVideoInputCount() - (HasTunerInput() ? 1 : 0);

	int c = 0;
	for (DWORD Idx = 0 ; Idx < VideoCount ; Idx ++) {
		c += VideoChip[Idx]->CompositeCount();
	}
	return c;
}

int	BtCard::SerialDigitalInputCount( void ) const
{
	if (!VideoCount) 
		return GetCardInfo()->digitalvideoins;

	int c = 0;
	for (DWORD Idx = 0 ; Idx < VideoCount ; Idx ++) {
		c += VideoChip[Idx]->SerialDigitalCount();
	}
	return c;
}

int	BtCard::ParallelDigitalInputCount( void ) const
{
	if (!VideoCount) 
		return 0;

	int c = 0;
	for (DWORD Idx = 0 ; Idx < VideoCount ; Idx ++) {
		c += VideoChip[Idx]->ParallelDigitalCount();
	}
	return c;
}

int	BtCard::RGBInputCount( void ) const
{
	if (!VideoCount) 
		return 0;

	int c = 0;
	for (DWORD Idx = 0 ; Idx < VideoCount ; Idx ++) {
		c += VideoChip[Idx]->RGBCount();
	}
	return c;
}

int	BtCard::ComponentVideoInputCount( void ) const
{
	if (!VideoCount) 
		return 0;

	int c = 0;
	for (DWORD Idx = 0 ; Idx < VideoCount ; Idx ++) {
		c += VideoChip[Idx]->ComponentVideoCount();
	}
	return c;
}

// Video Selection
void BtCard::VideoSetInput(VideoConnector conn)
{

	// Try to find a handler for this Video Connector selection
	condesc_t x = -1;
	BOOL done = false;
	for (DWORD Idx = 0 ; Idx < VideoCount ; Idx ++) {

		// Try to set it...
		x = VideoChip[Idx]->SetConnector(conn);

		// If we did it, break loop.
		if (x != -1) {

			// Set kind of required video...
			VideoSetVideoKind(CONDESC_DIGITAL(x) ? true : false);

			// And select the right mux to handle it.
			GetBtPisces().SetConnector(CONDESC_MUX(x) , CONDESC_SVIDEO(x) ? true : false );

			// Remember the last selected connector (required by following call)
			VideoMux = conn;

			// We are done!
			done = true;
		}
	}

	// If done, done!
	if (done) return;

⌨️ 快捷键说明

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