btcard.cpp

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

CPP
1,724
字号

	// Noone handled it, use the default way
	int idx = -1; // assume not present

	// Get Information about the card
	CInfo* Info = GetCardInfo();

	switch (conn) {
		case VideoConSVideo0:

			// set to composite or Y/C component video depends on video source
			idx = Info->svhs0;

			// If not present, don't set it
			if (idx < 0 || idx >= MAX_VIDEOINS) return;

			// This is analog video!
			VideoSetVideoKind(false);
			break;

		case VideoConTuner:

			// set to composite or Y/C component video depends on video source
			idx = Info->tuner0;

			// If not present, don't set it
			if (idx < 0 || idx >= MAX_VIDEOINS) return;

			// This is analog video!
			VideoSetVideoKind(false);
			break;

		case VideoConComposite0:
		case VideoConComposite1:
		case VideoConComposite2:
		case VideoConComposite3:
		case VideoConComposite4:
		case VideoConComposite5:
		case VideoConComposite6:
		case VideoConComposite7:
		case VideoConComposite8:
		case VideoConComposite9:
		case VideoConComposite10:
		case VideoConComposite11:
		case VideoConComposite12:
		case VideoConComposite13:
		case VideoConComposite14:
		case VideoConComposite15:
		case VideoConComposite16:
		case VideoConComposite17:
		case VideoConComposite18:
		case VideoConComposite19:
		case VideoConComposite20:
		case VideoConComposite21:
		case VideoConComposite22:
		case VideoConComposite23:
		case VideoConComposite24:
		case VideoConComposite25:
		case VideoConComposite26:
		case VideoConComposite27:
		case VideoConComposite28:
		case VideoConComposite29:
		case VideoConComposite30:
		case VideoConComposite31:
			{
				int cn = 3; // Else, default to the 3rd entry... Probably will be overriden by the videoChip
				switch (conn) {
					case VideoConComposite0: cn = 0; break;
					case VideoConComposite1: cn = 1; break;
					case VideoConComposite2: cn = 2; break;
					case VideoConComposite3: cn = 3; break;
				};

				// Get idx of composite #cn
				idx = 0;
				while (1) { // Mods by Kevin Liao (11/20/2001)
					// skip all the tuner and svideo i/dexes
					while (idx < MAX_VIDEOINS && (idx == Info->tuner0 || idx == Info->svhs0))
						idx++;
					if (cn--)
						idx++;
					else
						break;
				};

				// If not present, use the last valid...
				if (idx >= MAX_VIDEOINS) {
					idx = MAX_VIDEOINS-1; 
				}

				// Force switching to analog video
				VideoSetVideoKind(false);
			}
			break;

		case VideoConSDI0: // This is an special connector: We are forced to use the digital in
		case VideoConSDI1:
		case VideoConSDI2:
		case VideoConSDI3:
		case VideoConPDI0: // This is an special connector: We are forced to use the digital in
		case VideoConPDI1:
		case VideoConPDI2:
		case VideoConPDI3:

			{
				// Digital video does NOT need to set the video mux - don磘 do it!
				VideoMux = conn;

				// This is truly digital video!
				VideoSetVideoKind(true);

				return;
			}
			
		default:
			return;
	}

	// Get real value
	int val = Info->videomux[idx] & 3;

	// Set Video Connector
	GetBtPisces().SetConnector(val , conn == VideoConSVideo0 || conn == VideoConSVideo1 || conn == VideoConSVideo2 || conn == VideoConSVideo3 );

	// Remember the last selected connector
	VideoMux = conn;
}

/* Method: BtCard::GetSupportedStandards
 * Purpose: Returns all supported standards by Decoder
 * Input: None
 * Output: LONG: standard flags
 */
LONG BtCard::VideoGetSupportedStandards()
{
	return	( (HasPLL() || Has28Xtal()) ? ( KS_AnalogVideo_PAL_M | KS_AnalogVideo_NTSC_M | KS_AnalogVideo_NTSC_M_J ) : 0 ) |
			( (HasPAL_NC()) ? KS_AnalogVideo_PAL_NC : 0 ) |
			( (HasPLL() || Has35Xtal()) ? 
				(	KS_AnalogVideo_PAL_N | KS_AnalogVideo_PAL_B | KS_AnalogVideo_PAL_D |
					KS_AnalogVideo_PAL_G | KS_AnalogVideo_PAL_H	| KS_AnalogVideo_PAL_I |
					KS_AnalogVideo_SECAM_B | KS_AnalogVideo_SECAM_D	| KS_AnalogVideo_SECAM_G |
					KS_AnalogVideo_SECAM_H | KS_AnalogVideo_SECAM_K	| KS_AnalogVideo_SECAM_K1 |
					KS_AnalogVideo_SECAM_L ) : 0 ) |
			( (IsBt878Family()) ? (KS_AnalogVideo_NTSC_50 | KS_AnalogVideo_PAL_60) : 0 )
			;
}

NTSTATUS BtCard::VideoSetVideoKind( bool IsDigital )
{
	// Force switching!
	if (m_IsDigitalVideo != IsDigital) {
		m_IsDigitalVideo = IsDigital;

		// Force Switch to asked
		KS_AnalogVideoStandard old = m_ksCurrentVideoStandard;
		m_ksCurrentVideoStandard = KS_AnalogVideoStandard(0);
		return VideoSetCurrentStandard(old);
	}
	return STATUS_SUCCESS;
}

NTSTATUS BtCard::VideoSetCurrentStandard( KS_AnalogVideoStandard ksStandard )
{
	DUMP(( "Decoder::SetCurrentVideoDecoderStandard( 0x%08X )\n", (DWORD)ksStandard ));

	// Only if really changing Video Standard ...
	// (note that to switch to digital video m_ksCurrentVideoStandard
	//  is forced to 0 before calling this routine. Also to switch to analog
	//  video)
	if (ksStandard == m_ksCurrentVideoStandard) 
		return STATUS_SUCCESS;

	ULONG f_req = 0;

	VideoFormat m_vf;

	switch( ksStandard ) {

		case KS_AnalogVideo_NTSC_M:  
			m_vf = VFormat_NTSC;
			break;
		case KS_AnalogVideo_NTSC_M_J:
			m_vf = VFormat_NTSC_J;
			break;
		case KS_AnalogVideo_PAL_B:   
		case KS_AnalogVideo_PAL_D:   
		case KS_AnalogVideo_PAL_G:   
		case KS_AnalogVideo_PAL_H:   
		case KS_AnalogVideo_PAL_I:   
			m_vf = VFormat_PAL_BDGHI;
			break;
		case KS_AnalogVideo_PAL_M:   
			m_vf = VFormat_PAL_M;
			break;
		case KS_AnalogVideo_PAL_N:  
			m_vf = VFormat_PAL_N;
			break;
		case KS_AnalogVideo_PAL_NC:
			if (!HasPAL_NC()) 
				return false;
			m_vf = VFormat_PAL_N_COMB;
			break;
		case KS_AnalogVideo_SECAM_B: 
		case KS_AnalogVideo_SECAM_D: 
		case KS_AnalogVideo_SECAM_G: 
		case KS_AnalogVideo_SECAM_H: 
		case KS_AnalogVideo_SECAM_K: 
		case KS_AnalogVideo_SECAM_K1:
		case KS_AnalogVideo_SECAM_L: 
		case KS_AnalogVideo_SECAM_L1:
			m_vf = VFormat_SECAM;
			break;
		case KS_AnalogVideo_PAL_60:
			if (!IsBt878Family()) 
				return false;
			m_vf = VFormat_PAL_60;
			break;
		case KS_AnalogVideo_NTSC_50: // = NTSC-50
			if (!IsBt878Family()) 
				return false;
			m_vf = VFormat_NTSC_50;
			break;
		default:
			return STATUS_INVALID_PARAMETER;
	}

	// Translate to digital formats if we need to
	VideoFormat vf = m_vf;

	// If we are going to get digital video, Make sure to select a digital mode.
	if (m_IsDigitalVideo) {
		switch (GetCardInfo()->digxface) {
			default:
			case CCIR656_Digital:
				if (vf == VFormat_NTSC_J || vf == VFormat_NTSC) {
					// Use NTSC as the video norm for digital video
					vf = VFormat_NTSC_Digital;
				} else {
					// All the other formats are assumed to be PAL
					vf = VFormat_PAL_Digital;
				}
				break;
			case RQS_Digital:
				vf = VFormat_RQS_Digital;
				break;
			case SVI_Digital:
				vf = VFormat_SVI_Digital;
				break;
			case LVM_Digital:
				vf = VFormat_LVM_Digital;
				break;
		}
	}

	// Now set the videoMode
	if( GetBtPisces().SetVideoFormat( m_xtal0freq, m_xtal1freq, vf ) == Fail )
	{
		ERROR(( " Failed SetVideoFormat( %d )\n", (DWORD)vf ));
		return STATUS_INVALID_PARAMETER;
	}

	// Inform all videoChips of change!
	for (DWORD Idx = 0 ; Idx < VideoCount ; Idx ++) {
		VideoChip[Idx]->SetFormat(m_vf); // (use the untranslated std)
	}

	// Remember Standard
	m_ksCurrentVideoStandard = ksStandard;

	return STATUS_SUCCESS;
}

// Tuner Functions
LONG BtCard::TunerGetSupportedModes()
{
	// Verify all tuners , checking for available Modes
	ULONG Modes = 0;	// By default, nothing!

	// Go tuner by tuner checking it磗 type
	for (DWORD Idx = 0 ; Idx < TunerCount ; Idx ++) {
		if (TunerChip[Idx]->CanTuneTV()) {
			Modes |= KSPROPERTY_TUNER_MODE_TV;
		}
		if (TunerChip[Idx]->CanTuneAM()) {
			Modes |= KSPROPERTY_TUNER_MODE_AM_RADIO;
		}
		if (TunerChip[Idx]->CanTuneFM()) {
			Modes |= KSPROPERTY_TUNER_MODE_FM_RADIO;
		}
	}

	// Return the available modes
	return Modes;
}

LONG BtCard::TunerGetSupportedStandards()
{
	// Verify all tuners , checking for available Stds
	ULONG Stds = 0;	// By default, no standards

	// Consider only the TV Tuners (obviously!)
	for (DWORD Idx = 0 ; Idx < TunerCount ; Idx ++) {
		if (TunerChip[Idx]->CanTuneTV()) {
			Stds |= TunerChip[Idx]->TVTunerVideoStandardsSupported();
		}
	}

	// Return the detected standards
	return Stds;
}

NTSTATUS BtCard::TunerSetCurrentStandard( KS_AnalogVideoStandard ksStandard )
{
	TRACE(("BtCard::TunerSetCurrentStandard"));

	// Assume failure
	NTSTATUS st = STATUS_INVALID_PARAMETER;

	// Only if really changing VideoStandard ...
	if (ksStandard != m_ksCurrentTunerStandard) {

		// Look for a tuner that supports this Standard (There's a potential IF change, so this is required...)
		for (DWORD Idx = 0 ; Idx < TunerCount ; Idx ++) {

			// Only try this if Tuner supports TV mode...
			if (TunerChip[Idx]->CanTuneTV()) {

				// If tuner supports the requested standard...
				if (TunerChip[Idx]->TVTunerVideoStandardsSupported() & ksStandard) {

					// Set the tuner Standard!
					if (m_CurrentTunerMode == HwTuner::Tm_TV) {

						ULONG RealFreq = TunerChip[Idx]->SetFrequency(ksStandard,m_CurrentTunerMode,m_CurrentTunerFrequency ,HwTuner::Tm_Fine);
						if (RealFreq) {
							m_CurrentTunerFrequency = RealFreq;
						}
						m_TunerSignalDetected = (RealFreq != 0);

					} else {
						// We are not on TV mode...
						DUMP(("m_CurrentTumerMode != HWTuner::Tm_TV, but %d\n",m_CurrentTunerMode));
					}

					// Remember the current standard...

⌨️ 快捷键说明

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