Ticket #5562: defaultauthority-trunk-r23491.patch

File defaultauthority-trunk-r23491.patch, 11.9 KB (added by Douglas Mackay <douglas.mackay@…>, 10 years ago)
  • mythtv/libs/libmythtv/channelscan/channelscan_sm.cpp

    diff -aur a/mythtv/libs/libmythtv/channelscan/channelscan_sm.cpp b/mythtv/libs/libmythtv/channelscan/channelscan_sm.cpp
    a b  
    146146      sourceID(_sourceID),
    147147      signalTimeout(signal_timeout),
    148148      channelTimeout(channel_timeout),
     149      otherTableTimeout(0),
     150      otherTableTime(0),
     151      setOtherTables(false),
    149152      inputname(_inputname),
    150153      m_test_decryption(test_decryption),
    151154      extend_scan_list(false),
     
    190193        data->AddMPEGListener(this);
    191194        data->AddATSCMainListener(this);
    192195        data->AddDVBMainListener(this);
     196        data->AddDVBOtherListener(this);
    193197    }
    194198}
    195199
     
    375379    UpdateChannelInfo(true);
    376380}
    377381
    378 void ChannelScanSM::HandleSDT(uint, const ServiceDescriptionTable *sdt)
     382void ChannelScanSM::HandleSDT(uint tsid, const ServiceDescriptionTable *sdt)
    379383{
    380384    VERBOSE(VB_CHANSCAN, LOC +
    381385            QString("Got a Service Description Table for %1")
    382386            .arg((*current).FriendlyName) + "\n" + sdt->toString());
    383387
     388    // If this is Astra 28.2 add start listening for Freesat BAT and SDTo
     389    if (!setOtherTables && (sdt->OriginalNetworkID() == 2 || sdt->OriginalNetworkID() == 59))
     390    {
     391        GetDTVSignalMonitor()->GetScanStreamData()->SetOtherTablePid(FREESAT_SI_PID);
     392        setOtherTables = true;
     393        otherTableTimeout = 10000; // The whole BAT & SDTo group comes round in 10s
     394        // Delay processing the SDT until we've seen BATs and SDTos
     395        otherTableTime = timer.elapsed() + otherTableTimeout;
     396
     397        VERBOSE(VB_CHANSCAN, LOC + QString("SDT has OriginalNetworkID %1, look for "
     398                                            "additional Freesat SI").arg(sdt->OriginalNetworkID()));
     399    }
     400
     401    if (timer.elapsed() < otherTableTime)
     402    {
     403        // Set the version for the SDT so we see it again.
     404        GetDTVSignalMonitor()->GetDVBStreamData()->SetVersionSDT(sdt->TSID(), -1, 0);
     405    }
     406
    384407    uint id = sdt->OriginalNetworkID() << 16 | sdt->TSID();
    385408    ts_scanned.insert(id);
    386409
     
    404427    UpdateChannelInfo(true);
    405428}
    406429
     430void ChannelScanSM::HandleBAT(const BouquetAssociationTable *bat)
     431{
     432    VERBOSE(VB_CHANSCAN, LOC + "Got a Bouquet Association Table\n" +
     433            bat->toString());
     434
     435    otherTableTime = timer.elapsed() + otherTableTimeout;
     436
     437    for (uint i = 0; i < bat->TransportStreamCount(); i++)
     438    {
     439        uint tsid = bat->TSID(i);
     440        uint netid = bat->OriginalNetworkID(i);
     441        desc_list_t parsed =
     442            MPEGDescriptor::Parse(bat->TransportDescriptors(i),
     443                                  bat->TransportDescriptorsLength(i));
     444        // Look for default authority
     445        const unsigned char *def_auth =
     446            MPEGDescriptor::Find(parsed, DescriptorID::default_authority);
     447        const unsigned char *serv_list =
     448            MPEGDescriptor::Find(parsed, DescriptorID::service_list);
     449
     450        if (def_auth && serv_list)
     451        {
     452            DefaultAuthorityDescriptor authority(def_auth);
     453            ServiceListDescriptor services(serv_list);
     454
     455            for (uint j = 0; j < services.ServiceCount(); j++)
     456            {
     457               // If the default authority is given in the SDT this
     458               // overrides any definition in the BAT (or in the NIT)
     459                VERBOSE(VB_IMPORTANT, LOC + QString("found default authority(BAT) "
     460                                                    "for service %1 %2 %3")
     461                        .arg(netid).arg(tsid).arg(services.ServiceID(j)));
     462               uint64_t index =
     463                   ((uint64_t)netid << 32) | (tsid << 16) | services.ServiceID(j);
     464               if (! defAuthorities.contains(index))
     465                   defAuthorities[index] = authority.DefaultAuthority();
     466            }
     467        }
     468    }
     469}
     470
     471void ChannelScanSM::HandleSDTo(uint tsid, const ServiceDescriptionTable *sdt)
     472{
     473    VERBOSE(VB_CHANSCAN, LOC + "Got a Service Description Table (other)\n" +
     474            sdt->toString());
     475
     476    otherTableTime = timer.elapsed() + otherTableTimeout;
     477
     478    uint netid = sdt->OriginalNetworkID();
     479
     480    for (uint i = 0; i < sdt->ServiceCount(); i++)
     481    {
     482        uint serviceId = sdt->ServiceID(i);
     483        desc_list_t parsed =
     484            MPEGDescriptor::Parse(sdt->ServiceDescriptors(i),
     485                                  sdt->ServiceDescriptorsLength(i));
     486        // Look for default authority
     487        const unsigned char *def_auth =
     488            MPEGDescriptor::Find(parsed, DescriptorID::default_authority);
     489        if (def_auth)
     490        {
     491            DefaultAuthorityDescriptor authority(def_auth);
     492            VERBOSE(VB_IMPORTANT, LOC + QString("found default authority(SDTo) "
     493                                                "for service %1 %2 %3")
     494                    .arg(netid).arg(tsid).arg(serviceId));
     495            defAuthorities[((uint64_t)netid << 32) | (tsid << 16) | serviceId] =
     496                authority.DefaultAuthority();
     497        }
     498    }
     499}
     500
    407501void ChannelScanSM::HandleEncryptionStatus(uint pnum, bool encrypted)
    408502{
    409503    currentEncryptionStatus[pnum] = encrypted ? kEncEncrypted : kEncDecrypted;
     
    660754    }
    661755
    662756    // DVB
    663     if ((!wait_until_complete || sd->HasCachedAllNIT()) && currentInfo->nits.empty())
     757    if ((!wait_until_complete || sd->HasCachedAllNIT()) && (currentInfo->nits.empty() ||
     758        timer.elapsed() > (int)otherTableTime))
     759    {
    664760        currentInfo->nits = sd->GetCachedNIT();
     761    }
    665762
    666763    sdt_vec_t sdttmp = sd->GetCachedSDTs();
    667764    tsid_checked.clear();
     
    823920        currentEncryptionStatus.clear();
    824921        currentEncryptionStatusChecked.clear();
    825922
     923        setOtherTables = false;
     924        otherTableTime = 0;
     925
    826926        if (scanning)
    827927        {
    828928            transportsScanned++;
     
    886986}
    887987
    888988static void update_info(ChannelInsertInfo &info,
    889                         const ServiceDescriptionTable *sdt, uint i)
     989                        const ServiceDescriptionTable *sdt, uint i,
     990                        const QMap<uint64_t, QString> &defAuthorities)
    890991{
    891992    // HACK beg -- special exception for this network
    892993    //             (dbver == "1067")
     
    9251026        (desc && !desc->IsDTV() && !desc->IsDigitalAudio());
    9261027    info.is_audio_service = (desc && desc->IsDigitalAudio());
    9271028
     1029    info.service_id = sdt->ServiceID(i);
    9281030    info.sdt_tsid   = sdt->TSID();
    9291031    info.orig_netid = sdt->OriginalNetworkID();
    9301032    info.in_sdt     = true;
     
    9381040    if (def_auth)
    9391041    {
    9401042        DefaultAuthorityDescriptor authority(def_auth);
     1043        VERBOSE(VB_IMPORTANT, QString("found default authority(SDT) "
     1044                                            "for service %1 %2 %3")
     1045                .arg(info.orig_netid).arg(info.sdt_tsid).arg(info.service_id));
    9411046        info.default_authority = authority.DefaultAuthority();
    9421047    }
     1048    else
     1049    {
     1050        uint64_t index = (uint64_t)info.orig_netid << 32 |
     1051                        info.sdt_tsid << 16 | info.service_id;
     1052        if (defAuthorities.contains(index))
     1053            info.default_authority = defAuthorities[index];
     1054    }
    9431055}
    9441056
    9451057uint ChannelScanSM::GetCurrentTransportInfo(
     
    10901202            {
    10911203                uint pnum = (*sdt_it)->ServiceID(i);
    10921204                PCM_INFO_INIT("dvb");
    1093                 update_info(info, *sdt_it, i);
     1205                update_info(info, *sdt_it, i, defAuthorities);
    10941206            }
    10951207        }
    10961208    }
  • mythtv/libs/libmythtv/channelscan/channelscan_sm.h

    diff -aur a/mythtv/libs/libmythtv/channelscan/channelscan_sm.h b/mythtv/libs/libmythtv/channelscan/channelscan_sm.h
    a b  
    8181
    8282class ChannelScanSM : public MPEGStreamListener,
    8383                      public ATSCMainStreamListener,
    84                       public DVBMainStreamListener
     84                      public DVBMainStreamListener,
     85                      public DVBOtherStreamListener
    8586{
    8687    friend class AnalogSignalHandler;
    8788
     
    144145    void HandleSDT(uint tsid, const ServiceDescriptionTable*);
    145146    void HandleTDT(const TimeDateTable*) {}
    146147
     148    // DVB Other
     149    void HandleNITo(const NetworkInformationTable*) {}
     150    void HandleSDTo(uint tsid, const ServiceDescriptionTable*);
     151    void HandleBAT(const BouquetAssociationTable*);
     152
    147153  private:
    148154    // some useful gets
    149155    DTVChannel       *GetDTVChannel(void);
     
    201207    int               sourceID;
    202208    uint              signalTimeout;
    203209    uint              channelTimeout;
     210    uint              otherTableTimeout;
     211    uint              otherTableTime;
     212    bool              setOtherTables;
    204213    QString           inputname;
    205214    bool              m_test_decryption;
    206215    bool              extend_scan_list;
     
    224233    bool                        currentTestingDecryption;
    225234    QMap<uint, uint>            currentEncryptionStatus;
    226235    QMap<uint, bool>            currentEncryptionStatusChecked;
     236    QMap<uint64_t, QString>     defAuthorities;
    227237
    228238    /// Found Channel Info
    229239    ChannelList       channelList;
  • mythtv/libs/libmythtv/mpeg/scanstreamdata.cpp

    diff -aur a/mythtv/libs/libmythtv/mpeg/scanstreamdata.cpp b/mythtv/libs/libmythtv/mpeg/scanstreamdata.cpp
    a b  
    88    : MPEGStreamData(-1, true),
    99      ATSCStreamData(-1,-1, true),
    1010      DVBStreamData(0, 0, -1, true),
    11       dvb_uk_freesat_si(false)
     11      otherTablepid(-1)
    1212{
    1313}
    1414
     
    1919 */
    2020bool ScanStreamData::IsRedundant(uint pid, const PSIPTable &psip) const
    2121{
    22     // Treat BAT and SDTo as redundant unless they are on the FREESAT_SI_PID
    23     if (dvb_uk_freesat_si &&
    24         (psip.TableID() == TableID::BAT || psip.TableID() == TableID::SDTo))
    25         return pid != FREESAT_SI_PID;
    26 
    27     return (ATSCStreamData::IsRedundant(pid,psip) ||
    28             DVBStreamData::IsRedundant(pid,psip));
     22    if (ATSCStreamData::IsRedundant(pid,psip) ||
     23        DVBStreamData::IsRedundant(pid,psip))
     24        return true;
     25    // Treat BAT and SDTo as redundant unless they are on the required PID.
     26    if (psip.TableID() == TableID::BAT || psip.TableID() == TableID::SDTo)
     27        return otherTablepid < 0 || pid != (uint)otherTablepid;
     28    return false;
    2929}
    3030
    3131/** \fn ScanStreamData::HandleTables(uint, const PSIPTable&)
     
    4848    AddListeningPID(ATSC_PSIP_PID);
    4949    AddListeningPID(DVB_NIT_PID);
    5050    AddListeningPID(DVB_SDT_PID);
    51     if (dvb_uk_freesat_si)
    52         AddListeningPID(FREESAT_SI_PID);
     51    if (otherTablepid >= 0)
     52        AddListeningPID((uint)otherTablepid);
    5353}
    5454
    5555QString ScanStreamData::GetSIStandard(QString guess) const
     
    8888    return "mpeg";
    8989}
    9090
     91/** \fn ScanStreamData::SetOtherTablePid(int pid)
     92 *  \brief Sets the PID to be used to receive BAT and SDTo tables
     93 */
     94void ScanStreamData::SetOtherTablePid(int pid)
     95{
     96    if (pid >= 0)
     97        AddListeningPID((uint)pid);
     98    otherTablepid = pid;
     99}
    91100
    92101bool ScanStreamData::DeleteCachedTable(PSIPTable *psip) const
    93102{
  • mythtv/libs/libmythtv/mpeg/scanstreamdata.h

    diff -aur a/mythtv/libs/libmythtv/mpeg/scanstreamdata.h b/mythtv/libs/libmythtv/mpeg/scanstreamdata.h
    a b  
    2828
    2929    QString GetSIStandard(QString guess = "mpeg") const;
    3030
    31     void SetFreesatAdditionalSI(bool freesat_si);
     31    void SetOtherTablePid(int pid);
    3232
    3333  private:
    3434    virtual bool DeleteCachedTable(PSIPTable *psip) const; 
    3535    /// listen for addiotional Freesat service information
    36     int dvb_uk_freesat_si;
     36    int otherTablepid;;
    3737};
    3838
    39 inline void ScanStreamData::SetFreesatAdditionalSI(bool freesat_si)
    40 {
    41     QMutexLocker locker(&_listener_lock);
    42     dvb_uk_freesat_si = freesat_si;
    43 }
     39
    4440
    4541#endif // SCANSTREAMDATA_H_