private bool BeforeTune(IChannel channel, ref int subChannelId, out int pmtPid) { int frequency = 0; int symbolRate = 0; int modulation = (int)eModulationTAG.QAM_64; int bandWidth = 0; LNBSelectionType lnbSelection = LNBSelectionType.Lnb0; const int lnbKhzTone = 22; const int fec = (int)FecType.Fec_Auto; int polarity = 0; SS2DisEqcType disType = SS2DisEqcType.None; int switchFreq = 0; pmtPid = 0; int satelliteIndex = 0; Log.Log.WriteFile("ss2:Tune({0})", channel); if (_epgGrabbing) { _epgGrabbing = false; if (_epgGrabberCallback != null && _epgGrabbing) { _epgGrabberCallback.OnEpgCancelled(); } } switch (_cardType) { case CardType.DvbS: DVBSChannel dvbsChannel = channel as DVBSChannel; if (dvbsChannel == null) { Log.Log.Error("Channel is not a DVBS channel!!! {0}", channel.GetType().ToString()); return(false); } if (CurrentChannel != null) { DVBSChannel oldChannels = (DVBSChannel)CurrentChannel; if (oldChannels.Equals(channel)) { //@FIX this fails for back-2-back recordings //Log.Log.WriteFile("ss2:already tuned on this channel"); //return _mapSubChannels[0]; } } frequency = (int)dvbsChannel.Frequency; symbolRate = dvbsChannel.SymbolRate; satelliteIndex = dvbsChannel.SatelliteIndex; bool hiBand = BandTypeConverter.IsHiBand(dvbsChannel, Parameters); int lof1, lof2, sw; BandTypeConverter.GetDefaultLnbSetup(Parameters, dvbsChannel.BandType, out lof1, out lof2, out sw); int lnbFrequency; if (BandTypeConverter.IsHiBand(dvbsChannel, Parameters)) { lnbFrequency = lof2 * 1000; } else { lnbFrequency = lof1 * 1000; } //0=horizontal or left, 1=vertical or right polarity = 0; if (dvbsChannel.Polarisation == Polarisation.LinearV) { polarity = 1; } if (dvbsChannel.Polarisation == Polarisation.CircularR) { polarity = 1; } Log.Log.WriteFile("ss2: Polarity:{0} {1}", dvbsChannel.Polarisation, polarity); lnbSelection = LNBSelectionType.Lnb0; if (dvbsChannel.BandType == BandType.Universal) { //only set the LNB (22,33,44) Khz tone when we use ku-band and are in hi-band switch (lnbKhzTone) { case 22: lnbSelection = LNBSelectionType.Lnb22kHz; break; } if (hiBand == false) { lnbSelection = LNBSelectionType.Lnb0; } } switch (dvbsChannel.DisEqc) { case DisEqcType.None: // none disType = SS2DisEqcType.None; break; case DisEqcType.SimpleA: // Simple A disType = SS2DisEqcType.Simple_A; break; case DisEqcType.SimpleB: // Simple B disType = SS2DisEqcType.Simple_B; break; case DisEqcType.Level1AA: // Level 1 A/A disType = SS2DisEqcType.Level_1_A_A; break; case DisEqcType.Level1BA: // Level 1 B/A disType = SS2DisEqcType.Level_1_B_A; break; case DisEqcType.Level1AB: // Level 1 A/B disType = SS2DisEqcType.Level_1_A_B; break; case DisEqcType.Level1BB: // Level 1 B/B disType = SS2DisEqcType.Level_1_B_B; break; } switchFreq = lnbFrequency / 1000; //in MHz pmtPid = dvbsChannel.PmtPid; break; case CardType.DvbT: DVBTChannel dvbtChannel = channel as DVBTChannel; if (dvbtChannel == null) { Log.Log.Error("Channel is not a DVBT channel!!! {0}", channel.GetType().ToString()); return(false); } if (CurrentChannel != null) { DVBTChannel oldChannelt = (DVBTChannel)CurrentChannel; if (oldChannelt.Equals(channel)) { //@FIX this fails for back-2-back recordings //Log.Log.WriteFile("ss2:already tuned on this channel"); //return _mapSubChannels[0]; } } frequency = (int)dvbtChannel.Frequency; bandWidth = dvbtChannel.BandWidth; pmtPid = dvbtChannel.PmtPid; break; case CardType.DvbC: DVBCChannel dvbcChannel = channel as DVBCChannel; if (dvbcChannel == null) { Log.Log.Error("Channel is not a DVBC channel!!! {0}", channel.GetType().ToString()); return(false); } if (CurrentChannel != null) { DVBCChannel oldChannelc = (DVBCChannel)CurrentChannel; if (oldChannelc.Equals(channel)) { //@FIX this fails for back-2-back recordings //Log.Log.WriteFile("ss2:already tuned on this channel"); //return _mapSubChannels[0]; } } frequency = (int)dvbcChannel.Frequency; symbolRate = dvbcChannel.SymbolRate; switch (dvbcChannel.ModulationType) { case ModulationType.Mod16Qam: modulation = (int)eModulationTAG.QAM_16; break; case ModulationType.Mod32Qam: modulation = (int)eModulationTAG.QAM_32; break; case ModulationType.Mod64Qam: modulation = (int)eModulationTAG.QAM_64; break; case ModulationType.Mod128Qam: modulation = (int)eModulationTAG.QAM_128; break; case ModulationType.Mod256Qam: modulation = (int)eModulationTAG.QAM_256; break; } pmtPid = dvbcChannel.PmtPid; break; case CardType.Atsc: ATSCChannel dvbaChannel = channel as ATSCChannel; if (dvbaChannel == null) { Log.Log.Error("Channel is not a ATSC channel!!! {0}", channel.GetType().ToString()); return(false); } if (CurrentChannel != null) { ATSCChannel oldChannela = (ATSCChannel)CurrentChannel; if (oldChannela.Equals(channel)) { //@FIX this fails for back-2-back recordings //Log.Log.WriteFile("ss2:already tuned on this channel"); //return _mapSubChannels[0]; } } //if modulation = 256QAM assume ATSC QAM for HD5000 if (dvbaChannel.ModulationType == ModulationType.Mod256Qam) { Log.Log.WriteFile("DVBGraphB2C2: ATSC Channel:{0} Frequency:{1}", dvbaChannel.PhysicalChannel, dvbaChannel.Frequency); frequency = (int)dvbaChannel.Frequency; pmtPid = dvbaChannel.PmtPid; } else { Log.Log.WriteFile("DVBGraphSkyStar2: ATSC Channel:{0}", dvbaChannel.PhysicalChannel); //#DM B2C2 SDK says ATSC is tuned by frequency. Here we work the OTA frequency by channel number# int atscfreq = 0; if (dvbaChannel.PhysicalChannel <= 6) { atscfreq = 45 + (dvbaChannel.PhysicalChannel * 6); } if (dvbaChannel.PhysicalChannel >= 7 && dvbaChannel.PhysicalChannel <= 13) { atscfreq = 177 + ((dvbaChannel.PhysicalChannel - 7) * 6); } if (dvbaChannel.PhysicalChannel >= 14) { atscfreq = 473 + ((dvbaChannel.PhysicalChannel - 14) * 6); } //#DM changed tuning parameter from physical channel to calculated frequency above. frequency = atscfreq; Log.Log.WriteFile("ss2: ATSC Frequency:{0} MHz", frequency); pmtPid = dvbaChannel.PmtPid; } break; } if (_graphState == GraphState.Idle) { BuildGraph(); } if (_mapSubChannels.ContainsKey(subChannelId) == false) { subChannelId = GetNewSubChannel(channel); } _mapSubChannels[subChannelId].CurrentChannel = channel; _mapSubChannels[subChannelId].OnBeforeTune(); if (_interfaceEpgGrabber != null) { _interfaceEpgGrabber.Reset(); } if (frequency > 13000) { frequency /= 1000; } Log.Log.WriteFile("ss2: Transponder Frequency:{0} MHz", frequency); int hr = _interfaceB2C2TunerCtrl.SetFrequency(frequency); if (hr != 0) { Log.Log.Error("ss2:SetFrequencyKHz() failed:0x{0:X}", hr); return(false); } switch (_cardType) { case CardType.DvbC: Log.Log.WriteFile("ss2: SymbolRate:{0} KS/s", symbolRate); hr = _interfaceB2C2TunerCtrl.SetSymbolRate(symbolRate); if (hr != 0) { Log.Log.Error("ss2:SetSymbolRate() failed:0x{0:X}", hr); return(false); } Log.Log.WriteFile("ss2: Modulation:{0}", ((eModulationTAG)modulation)); hr = _interfaceB2C2TunerCtrl.SetModulation(modulation); if (hr != 0) { Log.Log.Error("ss2:SetModulation() failed:0x{0:X}", hr); return(false); } break; case CardType.DvbT: Log.Log.WriteFile("ss2: GuardInterval:auto"); hr = _interfaceB2C2TunerCtrl.SetGuardInterval((int)GuardIntervalType.Interval_Auto); if (hr != 0) { Log.Log.Error("ss2:SetGuardInterval() failed:0x{0:X}", hr); return(false); } Log.Log.WriteFile("ss2: Bandwidth:{0} MHz", bandWidth); //hr = _interfaceB2C2TunerCtrl.SetBandwidth((int)dvbtChannel.BandWidth); // Set Channel Bandwidth (NOTE: Temporarily use polarity function to avoid having to // change SDK interface for SetBandwidth) // from Technisat SDK 03/2006 hr = _interfaceB2C2TunerCtrl.SetPolarity(bandWidth); if (hr != 0) { Log.Log.Error("ss2:SetBandwidth() failed:0x{0:X}", hr); return(false); } break; case CardType.DvbS: Log.Log.WriteFile("ss2: SymbolRate:{0} KS/s", symbolRate); hr = _interfaceB2C2TunerCtrl.SetSymbolRate(symbolRate); if (hr != 0) { Log.Log.Error("ss2:SetSymbolRate() failed:0x{0:X}", hr); return(false); } Log.Log.WriteFile("ss2: Fec:{0} {1}", ((FecType)fec), fec); hr = _interfaceB2C2TunerCtrl.SetFec(fec); if (hr != 0) { Log.Log.Error("ss2:SetFec() failed:0x{0:X}", hr); return(false); } hr = _interfaceB2C2TunerCtrl.SetPolarity(polarity); if (hr != 0) { Log.Log.Error("ss2:SetPolarity() failed:0x{0:X}", hr); return(false); } Log.Log.WriteFile("ss2: Lnb:{0}", lnbSelection); hr = _interfaceB2C2TunerCtrl.SetLnbKHz((int)lnbSelection); if (hr != 0) { Log.Log.Error("ss2:SetLnbKHz() failed:0x{0:X}", hr); return(false); } Log.Log.WriteFile("ss2: Diseqc:{0} {1}", disType, disType); hr = _interfaceB2C2TunerCtrl.SetDiseqc((int)disType); if (hr != 0) { Log.Log.Error("ss2:SetDiseqc() failed:0x{0:X}", hr); return(false); } Log.Log.WriteFile("ss2: LNBFrequency:{0} MHz", switchFreq); hr = _interfaceB2C2TunerCtrl.SetLnbFrequency(switchFreq); if (hr != 0) { Log.Log.Error("ss2:SetLnbFrequency() failed:0x{0:X}", hr); return(false); } if (_useDISEqCMotor) { if (satelliteIndex > 0) { DisEqcGotoPosition((byte)satelliteIndex); } } break; } return(true); }