Ticket #10784: 0007-Handle-EIT-events-of-the-active-transport-without-lo.patch

File 0007-Handle-EIT-events-of-the-active-transport-without-lo.patch, 10.4 KB (added by dekarl@…, 13 years ago)

first version of the patch

  • mythtv/libs/libmythtv/eithelper.cpp

    From 59509b4e918123e1faeaae46b5ae8c6506f36dfc Mon Sep 17 00:00:00 2001
    From: Karl Dietz <dekarl@users.sourceforge.net>
    Date: Tue, 22 May 2012 23:30:38 +0200
    Subject: [PATCH 7/7] Handle EIT events of the active transport without looking at original_network_id or transport_id
    
    Refs #10217
    ---
     mythtv/libs/libmythtv/eithelper.cpp  |  112 ++++++++++++++++++++++++++++++----
     mythtv/libs/libmythtv/eithelper.h    |    6 ++
     mythtv/libs/libmythtv/eitscanner.cpp |    3 +
     mythtv/libs/libmythtv/tv_rec.cpp     |   10 +++
     mythtv/libs/libmythtv/tv_rec.h       |    1 +
     5 files changed, 120 insertions(+), 12 deletions(-)
    
    diff --git a/mythtv/libs/libmythtv/eithelper.cpp b/mythtv/libs/libmythtv/eithelper.cpp
    index df145fc..dd82960 100644
    a b using namespace std; 
    2525const uint EITHelper::kChunkSize = 20;
    2626EITCache *EITHelper::eitcache = new EITCache();
    2727
    28 static uint get_chan_id_from_db(uint sourceid,
    29                                 uint atscmajor, uint atscminor);
    30 static uint get_chan_id_from_db(uint sourceid,  uint serviceid,
    31                                 uint networkid, uint transportid);
     28static uint get_chan_id_from_db_atsc(uint sourceid,
     29                                     uint atscmajor, uint atscminor);
     30static uint get_chan_id_from_db_dvb(uint sourceid,  uint serviceid,
     31                                    uint networkid, uint transportid);
     32static uint get_chan_id_from_db_dtv(uint sourceid,
     33                                    uint programnumber, uint tunedchanid);
    3234static void init_fixup(QMap<uint64_t,uint> &fix);
    3335static int calc_eit_utc_offset(void);
    3436
    static int calc_eit_utc_offset(void); 
    3739EITHelper::EITHelper() :
    3840    eitfixup(new EITFixUp()),
    3941    gps_offset(-1 * GPS_LEAP_SECONDS),          utc_offset(0),
    40     sourceid(0)
     42    sourceid(0), channelid(0)
    4143{
    4244    init_fixup(fixup);
    4345
    void EITHelper::SetSourceID(uint _sourceid) 
    146148    sourceid = _sourceid;
    147149}
    148150
     151void EITHelper::SetChannelID(uint _channelid)
     152{
     153    QMutexLocker locker(&eitList_lock);
     154    channelid = _channelid;
     155}
     156
    149157void EITHelper::AddEIT(uint atsc_major, uint atsc_minor,
    150158                       const EventInformationTable *eit)
    151159{
    void EITHelper::AddEIT(const DVBEventInformationTable *eit) 
    318326                  (uint64_t)eit->ServiceID());
    319327    fix |= EITFixUp::kFixGenericDVB;
    320328
    321     uint chanid = GetChanID(eit->ServiceID(), eit->OriginalNetworkID(),
    322                             eit->TSID());
     329    uint chanid = 0;
     330    if ((eit->TableID() == TableID::PF_EIT) ||
     331        ((eit->TableID() >= TableID::SC_EITbeg) && (eit->TableID() <= TableID::SC_EITend)))
     332    {
     333        // EITa(ctive)
     334        chanid = GetChanID(eit->ServiceID());
     335    }
     336    else
     337    {
     338        // EITo(ther)
     339        chanid = GetChanID(eit->ServiceID(), eit->OriginalNetworkID(), eit->TSID());
     340    }
    323341    if (!chanid)
    324342        return;
    325343
    uint EITHelper::GetChanID(uint atsc_major, uint atsc_minor) 
    684702    if (it != srv_to_chanid.end())
    685703        return max(*it, 0);
    686704
    687     uint chanid = get_chan_id_from_db(sourceid, atsc_major, atsc_minor);
     705    uint chanid = get_chan_id_from_db_atsc(sourceid, atsc_major, atsc_minor);
    688706    if (chanid)
    689707        srv_to_chanid[key] = chanid;
    690708
    uint EITHelper::GetChanID(uint serviceid, uint networkid, uint tsid) 
    703721    if (it != srv_to_chanid.end())
    704722        return max(*it, 0);
    705723
    706     uint chanid = get_chan_id_from_db(sourceid, serviceid, networkid, tsid);
     724    uint chanid = get_chan_id_from_db_dvb(sourceid, serviceid, networkid, tsid);
    707725    if (chanid)
    708726        srv_to_chanid[key] = chanid;
    709727
    710728    return chanid;
    711729}
    712730
    713 static uint get_chan_id_from_db(uint sourceid,
     731uint EITHelper::GetChanID(uint program_number)
     732{
     733    uint64_t key;
     734    key  = ((uint64_t) sourceid);
     735    key |= ((uint64_t) program_number) << 16;
     736    key |= ((uint64_t) channelid)      << 32;
     737
     738    ServiceToChanID::const_iterator it = srv_to_chanid.find(key);
     739    if (it != srv_to_chanid.end())
     740        return max(*it, 0);
     741
     742    uint chanid = get_chan_id_from_db_dtv(sourceid, program_number, channelid);
     743    if (chanid)
     744        srv_to_chanid[key] = chanid;
     745
     746    return chanid;
     747}
     748
     749static uint get_chan_id_from_db_atsc(uint sourceid,
    714750                                uint atsc_major, uint atsc_minor)
    715751{
    716752    MSqlQuery query(MSqlQuery::InitCon());
    static uint get_chan_id_from_db(uint sourceid, 
    736772}
    737773
    738774// Figure out the chanid for this channel
    739 static uint get_chan_id_from_db(uint sourceid, uint serviceid,
     775static uint get_chan_id_from_db_dvb(uint sourceid, uint serviceid,
    740776                                uint networkid, uint transportid)
    741777{
    742778    uint chanid = 0;
    static uint get_chan_id_from_db(uint sourceid, uint serviceid, 
    769805            return useOnAirGuide ? chanid : 0;
    770806    }
    771807
    772     if (query.size() > 1) {
     808    if (query.size() > 1)
     809    {
    773810        LOG(VB_EIT, LOG_INFO,
    774811            LOC + QString("found %1 channels for networdid %2, "
    775812                          "transportid %3, serviceid %4 but none "
    static uint get_chan_id_from_db(uint sourceid, uint serviceid, 
    781818    return useOnAirGuide ? chanid : 0;
    782819}
    783820
     821/* Figure out the chanid for this channel from the sourceid,
     822 * program_number/service_id and the chanid of the channel we are tuned to
     823 *
     824 * TODO for SPTS (e.g. HLS / IPTV) it would be useful to match without an entry
     825 * in dtv_multiplex
     826 */
     827static uint get_chan_id_from_db_dtv(uint sourceid, uint serviceid,
     828                                uint tunedchanid)
     829{
     830    uint chanid = 0;
     831    bool useOnAirGuide = false;
     832    MSqlQuery query(MSqlQuery::InitCon());
     833
     834    // DVB Link to chanid
     835    QString qstr =
     836        "SELECT c1.chanid, c1.useonairguide, c1.sourceid "
     837        "FROM channel c1, dtv_multiplex m, channel c2 "
     838        "WHERE c1.serviceid        = :SERVICEID   AND "
     839        "      c1.mplexid  = m.mplexid AND "
     840        "      m.mplexid = c2.mplexid AND "
     841        "      c2.chanid = :CHANID";
     842
     843    query.prepare(qstr);
     844    query.bindValue(":SERVICEID",   serviceid);
     845    query.bindValue(":CHANID", tunedchanid);
     846
     847    if (!query.exec() || !query.isActive())
     848        MythDB::DBError("Looking up chanID", query);
     849
     850    while (query.next())
     851    {
     852        // Check to see if we are interested in this channel
     853        chanid        = query.value(0).toUInt();
     854        useOnAirGuide = query.value(1).toBool();
     855        if (sourceid == query.value(2).toUInt())
     856            return useOnAirGuide ? chanid : 0;
     857    }
     858
     859    if (query.size() > 1)
     860    {
     861        LOG(VB_EIT, LOG_INFO,
     862            LOC + QString("found %1 channels for multiplex of chanid %2, "
     863                          "serviceid %3 but none "
     864                          "for current sourceid %4.")
     865                .arg(query.size()).arg(tunedchanid)
     866                .arg(serviceid).arg(sourceid));
     867    }
     868
     869    return useOnAirGuide ? chanid : 0;
     870}
     871
    784872static void init_fixup(QMap<uint64_t,uint> &fix)
    785873{
    786874    ///////////////////////////////////////////////////////////////////////////
  • mythtv/libs/libmythtv/eithelper.h

    diff --git a/mythtv/libs/libmythtv/eithelper.h b/mythtv/libs/libmythtv/eithelper.h
    index 6fca7d5..e83244a 100644
    a b class EITHelper 
    6666
    6767    uint GetGPSOffset(void) const { return (uint) (0 - gps_offset); }
    6868
     69    void SetChannelID(uint _channelid);
    6970    void SetGPSOffset(uint _gps_offset) { gps_offset = 0 - _gps_offset; }
    7071    void SetFixup(uint atsc_major, uint atsc_minor, uint eitfixup);
    7172    void SetLanguagePreferences(const QStringList &langPref);
    class EITHelper 
    9091    void WriteEITCache(void);
    9192
    9293  private:
     94    // only ATSC
    9395    uint GetChanID(uint atsc_major, uint atsc_minor);
     96    // only DVB
    9497    uint GetChanID(uint serviceid, uint networkid, uint transportid);
     98    // any DTV
     99    uint GetChanID(uint program_number);
    95100
    96101    void CompleteEvent(uint atsc_major, uint atsc_minor,
    97102                       const ATSCEvent &event,
    class EITHelper 
    107112    int                     gps_offset;
    108113    int                     utc_offset;
    109114    uint                    sourceid;
     115    uint                    channelid;
    110116    QMap<uint64_t,uint>     fixup;
    111117    ATSCSRCToEvents         incomplete_events;
    112118    ATSCSRCToETTs           unmatched_etts;
  • mythtv/libs/libmythtv/eitscanner.cpp

    diff --git a/mythtv/libs/libmythtv/eitscanner.cpp b/mythtv/libs/libmythtv/eitscanner.cpp
    index 2e42bd5..8acf7e9 100644
    a b void EITScanner::run(void) 
    134134            {
    135135                eitHelper->WriteEITCache();
    136136                rec->SetChannel(*activeScanNextChan, TVRec::kFlagEITScan);
     137                eitHelper->SetChannelID(ChannelUtil::GetChanID(rec->GetSourceID(),
     138                                                            *activeScanNextChan));
    137139                LOG(VB_EIT, LOG_INFO,
    138140                    LOC_ID + QString("Now looking for EIT data on "
    139141                                     "multiplex of channel %1")
    void EITScanner::StartPassiveScan(ChannelBase *_channel, 
    204206    eitHelper->SetSourceID(sourceid);
    205207    eitSource->SetEITHelper(eitHelper);
    206208    eitSource->SetEITRate(1.0f);
     209    eitHelper->SetChannelID(_channel->GetChanID());
    207210
    208211    LOG(VB_EIT, LOG_INFO, LOC_ID + "Started passive scan.");
    209212}
  • mythtv/libs/libmythtv/tv_rec.cpp

    diff --git a/mythtv/libs/libmythtv/tv_rec.cpp b/mythtv/libs/libmythtv/tv_rec.cpp
    index a5d4986..fc9e96c 100644
    a b QString TVRec::GetInput(void) const 
    29342934    return QString::null;
    29352935}
    29362936
     2937/** \fn TVRec::GetSourceID(void) const
     2938 *  \brief Returns current source id.
     2939 */
     2940uint TVRec::GetSourceID(void) const
     2941{
     2942    if (channel)
     2943        return channel->GetCurrentSourceID();
     2944    return 0;
     2945}
     2946
    29372947/** \fn TVRec::SetInput(QString, uint)
    29382948 *  \brief Changes to the specified input.
    29392949 *
  • mythtv/libs/libmythtv/tv_rec.h

    diff --git a/mythtv/libs/libmythtv/tv_rec.h b/mythtv/libs/libmythtv/tv_rec.h
    index ce54bff..6c2aaf8 100644
    a b class MTV_PUBLIC TVRec : public SignalMonitorListener, public QRunnable 
    192192
    193193    vector<InputInfo> GetFreeInputs(const vector<uint> &excluded_cards) const;
    194194    QString     GetInput(void) const;
     195    uint        GetSourceID(void) const;
    195196    QString     SetInput(QString input, uint requestType = kFlagDetect);
    196197
    197198    /// Changes to a channel in the 'dir' channel change direction.