--- vdr-vanilla/nit.c	2006-04-15 17:10:42.000000000 +0300
+++ vdr-vanilla/nit.c.new	2006-05-27 00:14:16.000000000 +0300
@@ -7,6 +7,7 @@
  * $Id: nit.c 1.11 2006/04/15 14:10:42 kls Exp $
  */
 
+#include <list>
 #include "nit.h"
 #include <linux/dvb/frontend.h>
 #include "channels.h"
@@ -95,39 +96,75 @@ void cNitFilter::Process(u_short Pid, u_
   SI::NIT::TransportStream ts;
   for (SI::Loop::Iterator it; nit.transportStreamLoop.getNext(ts, it); ) {
       SI::Descriptor *d;
+      std::list<int> Frequencies;
+      std::list<int>::iterator frequency;
+      for (SI::Loop::Iterator it2; (d = ts.transportStreamDescriptors.getNext(it2, SI::FrequencyListDescriptorTag)); ) {
+          SI::FrequencyListDescriptor *fld = (SI::FrequencyListDescriptor *)d;
+          int coding_type = fld->getCodingType();
+          switch (coding_type) {
+            case 1: // Satellite
+                 for (SI::Loop::Iterator it3; fld->frequencies.hasNext(it3); )
+                     Frequencies.push_back(BCD2INT(fld->frequencies.getNext(it3)) / 100);
+                 break;
+            case 2: // Cable
+                 for (SI::Loop::Iterator it3; fld->frequencies.hasNext(it3); )
+                     Frequencies.push_back(BCD2INT(fld->frequencies.getNext(it3)) / 10);
+                 break;
+            case 3: // Terrestrial
+                 for (SI::Loop::Iterator it3; fld->frequencies.hasNext(it3); )
+                     Frequencies.push_back(fld->frequencies.getNext(it3) * 10);
+                 break;
+            default: ;
+            }
+          }
       for (SI::Loop::Iterator it2; (d = ts.transportStreamDescriptors.getNext(it2)); ) {
           switch (d->getDescriptorTag()) {
             case SI::SatelliteDeliverySystemDescriptorTag: {
                  SI::SatelliteDeliverySystemDescriptor *sd = (SI::SatelliteDeliverySystemDescriptor *)d;
                  int Source = cSource::FromData(cSource::stSat, BCD2INT(sd->getOrbitalPosition()), sd->getWestEastFlag());
                  int Frequency = BCD2INT(sd->getFrequency()) / 100;
+                 Frequencies.push_front(Frequency);
                  static char Polarizations[] = { 'h', 'v', 'l', 'r' };
                  char Polarization = Polarizations[sd->getPolarization()];
                  static int CodeRates[] = { FEC_NONE, FEC_1_2, FEC_2_3, FEC_3_4, FEC_5_6, FEC_7_8, FEC_AUTO, FEC_AUTO, FEC_AUTO, FEC_AUTO, FEC_AUTO, FEC_AUTO, FEC_AUTO, FEC_AUTO, FEC_AUTO, FEC_NONE };
                  int CodeRate = CodeRates[sd->getFecInner()];
                  int SymbolRate = BCD2INT(sd->getSymbolRate()) / 10;
                  if (ThisNIT >= 0) {
-                    if (ISTRANSPONDER(cChannel::Transponder(Frequency, Polarization), Transponder())) {
-                       nits[ThisNIT].hasTransponder = true;
-                       //printf("has transponder %d\n", Transponder());
-                       }
+                    for (frequency = Frequencies.begin(); frequency != Frequencies.end(); frequency++) {
+                        if (ISTRANSPONDER(cChannel::Transponder(*frequency, Polarization), Transponder())) {
+                          nits[ThisNIT].hasTransponder = true;
+                          //printf("has transponder %d\n", Transponder());
+                          break;
+                          }
+                        }
                     break;
                     }
                  bool found = false;
                  for (cChannel *Channel = Channels.First(); Channel; Channel = Channels.Next(Channel)) {
                      if (!Channel->GroupSep() && Channel->Source() == Source && Channel->Nid() == ts.getOriginalNetworkId() && Channel->Tid() == ts.getTransportStreamId()) {
-                        if (Setup.UpdateChannels >= 5)
+                        if (Setup.UpdateChannels >= 5) {
+                           if (!ISTRANSPONDER(cChannel::Transponder(Frequency, Polarization), Channel->Transponder())) {
+                              for (frequency = Frequencies.begin(); frequency != Frequencies.end(); frequency++) {
+                                  if (ISTRANSPONDER(cChannel::Transponder(*frequency, Polarization), Channel->Transponder())) {
+                                     Frequency = *frequency;
+                                     break;
+                                     }
+                                  }
+                              }
                            Channel->SetSatTransponderData(Source, Frequency, Polarization, SymbolRate, CodeRate);
+                           }
                         found = true;
                         }
                      }
                  if (!found && Setup.UpdateChannels >= 5) {
-                    cChannel *Channel = new cChannel;
-                    Channel->SetId(ts.getOriginalNetworkId(), ts.getTransportStreamId(), 0, 0);
-                    if (Channel->SetSatTransponderData(Source, Frequency, Polarization, SymbolRate, CodeRate))
-                       EITScanner.AddTransponder(Channel);
-                    else
-                       delete Channel;
+                    for (frequency = Frequencies.begin(); frequency != Frequencies.end(); frequency++) {
+                        cChannel *Channel = new cChannel;
+                        Channel->SetId(ts.getOriginalNetworkId(), ts.getTransportStreamId(), 0, 0);
+                        if (Channel->SetSatTransponderData(Source, *frequency, Polarization, SymbolRate, CodeRate))
+                          EITScanner.AddTransponder(Channel);
+                        else
+                          delete Channel;
+                        }
                     }
                  }
                  break;
@@ -135,6 +172,7 @@ void cNitFilter::Process(u_short Pid, u_
                  SI::CableDeliverySystemDescriptor *sd = (SI::CableDeliverySystemDescriptor *)d;
                  int Source = cSource::FromData(cSource::stCable);
                  int Frequency = BCD2INT(sd->getFrequency()) / 10;
+                 Frequencies.push_front(Frequency);
                  //XXX FEC_outer???
                  static int CodeRates[] = { FEC_NONE, FEC_1_2, FEC_2_3, FEC_3_4, FEC_5_6, FEC_7_8, FEC_AUTO, FEC_AUTO, FEC_AUTO, FEC_AUTO, FEC_AUTO, FEC_AUTO, FEC_AUTO, FEC_AUTO, FEC_AUTO, FEC_NONE };
                  int CodeRate = CodeRates[sd->getFecInner()];
@@ -142,27 +180,41 @@ void cNitFilter::Process(u_short Pid, u_
                  int Modulation = Modulations[min(sd->getModulation(), 6)];
                  int SymbolRate = BCD2INT(sd->getSymbolRate()) / 10;
                  if (ThisNIT >= 0) {
-                    if (ISTRANSPONDER(Frequency / 1000, Transponder())) {
-                       nits[ThisNIT].hasTransponder = true;
-                       //printf("has transponder %d\n", Transponder());
-                       }
+                    for (frequency = Frequencies.begin(); frequency != Frequencies.end(); frequency++) {
+                        if (ISTRANSPONDER(*frequency / 1000, Transponder())) {
+                          nits[ThisNIT].hasTransponder = true;
+                          //printf("has transponder %d\n", Transponder());
+                          break;
+                          }
+                        }
                     break;
                     }
                  bool found = false;
                  for (cChannel *Channel = Channels.First(); Channel; Channel = Channels.Next(Channel)) {
                      if (!Channel->GroupSep() && Channel->Source() == Source && Channel->Nid() == ts.getOriginalNetworkId() && Channel->Tid() == ts.getTransportStreamId()) {
-                        if (Setup.UpdateChannels >= 5)
+                        if (Setup.UpdateChannels >= 5) {
+                           if (!ISTRANSPONDER(Frequency / 1000, Channel->Transponder())) {
+                              for (frequency = Frequencies.begin(); frequency != Frequencies.end(); frequency++) {
+                                  if (ISTRANSPONDER(*frequency / 1000, Channel->Transponder())) {
+                                     Frequency = *frequency;
+                                     break;
+                                     }
+                                  }
+                              }
                            Channel->SetCableTransponderData(Source, Frequency, Modulation, SymbolRate, CodeRate);
+                           }
                         found = true;
                         }
                      }
                  if (!found && Setup.UpdateChannels >= 5) {
-                    cChannel *Channel = new cChannel;
-                    Channel->SetId(ts.getOriginalNetworkId(), ts.getTransportStreamId(), 0, 0);
-                    if (Channel->SetCableTransponderData(Source, Frequency, Modulation, SymbolRate, CodeRate))
-                       EITScanner.AddTransponder(Channel);
-                    else
-                       delete Channel;
+                    for (frequency = Frequencies.begin(); frequency != Frequencies.end(); frequency++) {
+                        cChannel *Channel = new cChannel;
+                        Channel->SetId(ts.getOriginalNetworkId(), ts.getTransportStreamId(), 0, 0);
+                        if (Channel->SetCableTransponderData(Source, *frequency, Modulation, SymbolRate, CodeRate))
+                          EITScanner.AddTransponder(Channel);
+                        else
+                          delete Channel;
+                        }
                     }
                  }
                  break;
@@ -170,6 +222,7 @@ void cNitFilter::Process(u_short Pid, u_
                  SI::TerrestrialDeliverySystemDescriptor *sd = (SI::TerrestrialDeliverySystemDescriptor *)d;
                  int Source = cSource::FromData(cSource::stTerr);
                  int Frequency = sd->getFrequency() * 10;
+                 Frequencies.push_front(Frequency);
                  static int Bandwidths[] = { BANDWIDTH_8_MHZ, BANDWIDTH_7_MHZ, BANDWIDTH_6_MHZ, BANDWIDTH_AUTO, BANDWIDTH_AUTO, BANDWIDTH_AUTO, BANDWIDTH_AUTO, BANDWIDTH_AUTO };
                  int Bandwidth = Bandwidths[sd->getBandwidth()];
                  static int Constellations[] = { QPSK, QAM_16, QAM_64, QAM_AUTO };
@@ -184,27 +237,41 @@ void cNitFilter::Process(u_short Pid, u_
                  static int TransmissionModes[] = { TRANSMISSION_MODE_2K, TRANSMISSION_MODE_8K, TRANSMISSION_MODE_AUTO, TRANSMISSION_MODE_AUTO };
                  int TransmissionMode = TransmissionModes[sd->getTransmissionMode()];
                  if (ThisNIT >= 0) {
-                    if (ISTRANSPONDER(Frequency / 1000000, Transponder())) {
-                       nits[ThisNIT].hasTransponder = true;
-                       //printf("has transponder %d\n", Transponder());
-                       }
+                    for (frequency = Frequencies.begin(); frequency != Frequencies.end(); frequency++) {
+                        if (ISTRANSPONDER(*frequency / 1000000, Transponder())) {
+                            nits[ThisNIT].hasTransponder = true;
+                            //printf("has transponder %d\n", Transponder());
+                            break;
+                            }
+                        }
                     break;
                     }
                  bool found = false;
                  for (cChannel *Channel = Channels.First(); Channel; Channel = Channels.Next(Channel)) {
                      if (!Channel->GroupSep() && Channel->Source() == Source && Channel->Nid() == ts.getOriginalNetworkId() && Channel->Tid() == ts.getTransportStreamId()) {
-                        if (Setup.UpdateChannels >= 5)
+                        if (Setup.UpdateChannels >= 5) {
+                           if (!ISTRANSPONDER(Frequency / 1000000, Channel->Transponder())) {
+                              for (frequency = Frequencies.begin(); frequency != Frequencies.end(); frequency++) {
+                                  if (ISTRANSPONDER(*frequency / 1000000, Channel->Transponder())) {
+                                     Frequency = *frequency;
+                                     break;
+                                     }
+                                  }
+                              }
                            Channel->SetTerrTransponderData(Source, Frequency, Bandwidth, Constellation, Hierarchy, CodeRateHP, CodeRateLP, GuardInterval, TransmissionMode);
+                           }
                         found = true;
                         }
                      }
                  if (!found && Setup.UpdateChannels >= 5) {
-                    cChannel *Channel = new cChannel;
-                    Channel->SetId(ts.getOriginalNetworkId(), ts.getTransportStreamId(), 0, 0);
-                    if (Channel->SetTerrTransponderData(Source, Frequency, Bandwidth, Constellation, Hierarchy, CodeRateHP, CodeRateLP, GuardInterval, TransmissionMode))
-                       EITScanner.AddTransponder(Channel);
-                    else
-                       delete Channel;
+                    for (frequency = Frequencies.begin(); frequency != Frequencies.end(); frequency++) {
+                        cChannel *Channel = new cChannel;
+                        Channel->SetId(ts.getOriginalNetworkId(), ts.getTransportStreamId(), 0, 0);
+                        if (Channel->SetTerrTransponderData(Source, *frequency, Bandwidth, Constellation, Hierarchy, CodeRateHP, CodeRateLP, GuardInterval, TransmissionMode))
+                          EITScanner.AddTransponder(Channel);
+                        else
+                          delete Channel;
+                        }
                     }
                  }
                  break;
