Ticket #3952: linkage_backend.2.diff

File linkage_backend.2.diff, 5.1 KB (added by Wolfgang <mythtv@…>, 13 years ago)

Replaced backend patch with improved version

  • libs/libmythtv/eithelper.cpp

     
    387387            }
    388388        }
    389389
     390        // Find all linked events
     391        desc_list_t linkages =
     392             MPEGDescriptor::FindAll(list, DescriptorID::linkage);
     393        if (linkages.size() > 0)
     394            StoreLinkageList(chanid,linkages,fix);
     395        else if (chanid_has_linkage[chanid])
     396            DeleteLinkageList(chanid);
     397
    390398        QDateTime starttime = MythUTCToLocal(eit->StartTimeUTC(i));
    391399        EITFixUp::TimeFix(starttime);
    392400        QDateTime endtime   = starttime.addSecs(eit->DurationInSeconds(i));
     
    513521    eitcache->WriteToDB();
    514522}
    515523
     524void EITHelper::DeleteLinkageList(uint portal_chanid)
     525{
     526    MSqlQuery query(MSqlQuery::InitCon());
     527    QString qstr = "DELETE FROM linkage where portal_chanid = :CHANID";
     528    query.prepare(qstr);
     529    query.bindValue(":CHANID", portal_chanid);
     530    if (!query.exec() || !query.isActive())
     531        MythContext::DBError("DELETE LINKAGELIST", query);
     532   
     533    VERBOSE(VB_GENERAL, LOC + QString("DELETE LINKAGE %1").arg(portal_chanid));
     534
     535    chanid_has_linkage[portal_chanid] = false;
     536}
     537
     538void EITHelper::StoreLinkageList(uint portal_chanid, desc_list_t linkages, uint fix)
     539{
     540    unsigned char enc_1[3]  = { 0x10, 0x00, 0x01 };
     541    unsigned char enc_15[3] = { 0x10, 0x00, 0x0f };
     542    unsigned char enc_premiere[1] = { 0x5 };
     543    int enc_len = 0;
     544    const unsigned char *enc = NULL;
     545   
     546    MSqlQuery query(MSqlQuery::InitCon());
     547
     548    VERBOSE(VB_GENERAL, LOC + QString("LINKAGE %1").arg(portal_chanid));
     549    //Delete old entries first
     550    DeleteLinkageList(portal_chanid);
     551
     552    // Is this BellExpressVU EIT (Canada) ?
     553    // Use an encoding override of ISO 8859-1 (Latin1)
     554    if (fix & EITFixUp::kEFixForceISO8859_1)
     555    {
     556        enc = enc_1;
     557        enc_len = sizeof(enc_1);
     558    }
     559
     560    // Is this broken DVB provider in Western Europe?
     561    // Use an encoding override of ISO 8859-15 (Latin6)
     562    if (fix & EITFixUp::kEFixForceISO8859_15)
     563    {
     564        enc = enc_15;
     565        enc_len = sizeof(enc_15);
     566    }
     567
     568    // The german provider Premiere needs extra handling
     569    if (fix & EITFixUp::kFixPremiere)
     570    {
     571        enc = enc_premiere;
     572        enc_len = sizeof(enc_premiere);
     573    }
     574
     575    for (uint j=0;j<linkages.size();j++)
     576    {
     577        LinkageDescriptor linkage(linkages[j]);
     578        uint networkid         = linkage.OriginalNetworkID();
     579        uint tsid              = linkage.TSID();
     580        uint serviceid         = linkage.ServiceID();
     581        uint linkagetype       = linkage.LinkageType();
     582        QString subevent       = dvb_decode_text(linkage.PrivateData_N8(),linkage.PrivateDataLength_N8(),enc,enc_len);
     583
     584        uint chanid = GetChanID(serviceid,networkid,tsid);
     585        VERBOSE(VB_GENERAL, LOC + QString("Event: %1 %2 %3").arg(chanid).arg(subevent).arg(serviceid));
     586
     587        // insert links into db
     588        QString qstr =
     589        "INSERT INTO linkage "
     590        "VALUES (:PORTAL, "
     591        "        :SERVICEID, "
     592        "        :CHANID, "
     593        "        :SUBEVENT) ";
     594
     595        query.prepare(qstr);
     596        query.bindValue(":PORTAL",     portal_chanid);
     597        query.bindValue(":SERVICEID",  serviceid);
     598        query.bindValue(":CHANID",     chanid);
     599        query.bindValue(":SUBEVENT",   subevent.utf8());
     600
     601        if (!query.exec() || !query.isActive())
     602            MythContext::DBError("INSERT LINKAGELIST", query);
     603    }
     604
     605    chanid_has_linkage[portal_chanid] = true;
     606}
     607
    516608//////////////////////////////////////////////////////////////////////
    517609// private methods and functions below this line                    //
    518610//////////////////////////////////////////////////////////////////////
  • libs/libmythtv/eithelper.h

     
    1313// MythTV includes
    1414#include "mythdeque.h"
    1515
     16typedef vector<const unsigned char*> desc_list_t;
     17
    1618class MSqlQuery;
    1719
    1820class ATSCEvent
     
    3941typedef QMap<uint,EventIDToATSCEvent>      ATSCSRCToEvents;
    4042typedef QMap<uint,EventIDToETT>            ATSCSRCToETTs;
    4143typedef QMap<unsigned long long,int>       ServiceToChanID;
     44typedef QMap<int,bool>                     ChanIDHasLinkage;
    4245
    4346class DBEvent;
    4447class EITFixUp;
     
    8285    // EIT cache handling
    8386    void PruneEITCache(uint timestamp);
    8487    void WriteEITCache(void);
     88    void DeleteLinkageList(uint portal_chanid);
     89    void StoreLinkageList(uint portal_chanid, desc_list_t linkages, uint fix);
    8590
    8691  private:
    8792    uint GetChanID(uint atsc_major, uint atsc_minor);
     
    9499        //QListList_Events  eitList;      ///< Event Information Tables List
    95100    mutable QMutex    eitList_lock; ///< EIT List lock
    96101    mutable ServiceToChanID srv_to_chanid;
     102    mutable ChanIDHasLinkage chanid_has_linkage;
    97103
    98104    EITFixUp               *eitfixup;
    99105    EITCache               *eitcache;