Ticket #11739: libmythtv.140128.patch

File libmythtv.140128.patch, 15.5 KB (added by deadletterfile@…, 10 years ago)

patch to stabilize EIT over-the-air broachast schedule

  • eithelper.cpp

    diff -Naur libmythtv/eithelper.cpp libmythtvclone/eithelper.cpp
    old new  
    7878    for (uint i = 0; (i < kChunkSize) && (db_events.size() > 0); i++)
    7979    {
    8080        DBEventEIT *event = db_events.dequeue();
    81         eitList_lock.unlock();
     81//        eitList_lock.unlock();
    8282
    8383        eitfixup->Fix(*event);
    8484
     85        LOG(VB_EIT, LOG_INFO, LOC +
     86            QString("\n%1 CHANID::%1<-\n%1 STARTTIME::%2<-\n%1 TITLE::%3<-\n%1 SUBTITLE::%4<-\n%1 DESCRIPTION::%5<-")
     87            .arg(event->chanid).arg(event->starttime.toString())
     88            .arg(event->title).arg(event->subtitle)
     89            .arg(event->description));
     90
    8591        insertCount += event->UpdateDB(query, 1000);
    8692        maxStarttime = max (maxStarttime, event->starttime);
    8793
    8894        delete event;
    89         eitList_lock.lock();
     95//        eitList_lock.lock();
    9096    }
    9197
    9298    if (!insertCount)
     
    205211    }
    206212
    207213    // Couldn't find matching EIT. If not yet in unmatched ETT map, insert it.
    208     EventIDToETT &elist = unmatched_etts[atsc_key];
    209     if (elist.find(ett->EventID()) == elist.end())
    210     {
    211         elist[ett->EventID()] = ett->ExtendedTextMessage()
    212             .GetBestMatch(languagePreferences);
    213     }
     214//     EventIDToETT &elist = unmatched_etts[atsc_key];
     215//     if (elist.find(ett->EventID()) == elist.end())
     216//     {
     217//         elist[ett->EventID()] = ett->ExtendedTextMessage()
     218//             .GetBestMatch(languagePreferences);
     219//     }
    214220}
    215221
    216222static void parse_dvb_event_descriptors(desc_list_t list, uint fix,
  • eitscanner.cpp

    diff -Naur libmythtv/eitscanner.cpp libmythtvclone/eitscanner.cpp
    old new  
    4545
    4646void EITScanner::TeardownAll(void)
    4747{
     48    QMutexLocker locker(&mutex);
     49    LOG(VB_EIT, LOG_INFO,
     50        LOC_ID + QString("EITScanner::TeardownAll"));
    4851    StopActiveScan();
    4952    if (!exitThread)
    5053    {
    51         lock.lock();
     54        // lock.lock();
    5255        exitThread = true;
    5356        exitThreadCond.wakeAll();
    54         lock.unlock();
     57        // lock.unlock();
    5558    }
    5659    eventThread->wait();
    5760    delete eventThread;
     
    6972 */
    7073void EITScanner::run(void)
    7174{
     75    QMutexLocker locker(&mutex);
     76   
    7277    static const uint  sz[] = { 2000, 1800, 1600, 1400, 1200, };
    7378    static const float rt[] = { 0.0f, 0.2f, 0.4f, 0.6f, 0.8f, };
    7479
    75     lock.lock();
     80    // lock.lock();
    7681
    7782    MythTimer t;
    7883    uint eitCount = 0;
    7984
    8085    while (!exitThread)
    8186    {
    82         lock.unlock();
     87        // lock.unlock();
    8388        uint list_size = eitHelper->GetListSize();
    8489
    8590        float rate = 1.0f;
     
    9297            }
    9398        }
    9499
    95         lock.lock();
     100        // lock.lock();
    96101        if (eitSource)
    97102            eitSource->SetEITRate(rate);
    98         lock.unlock();
     103        // lock.unlock();
    99104
    100105        if (list_size)
    101106        {
     107                            LOG(VB_EIT, LOG_INFO,
     108                    LOC_ID + QString("BEGIN eitHelper->ProcessEvents"));
    102109            eitCount += eitHelper->ProcessEvents();
    103110            t.start();
     111                            LOG(VB_EIT, LOG_INFO,
     112                    LOC_ID + QString("END   eitHelper->ProcessEvents"));
     113            t.start();
    104114        }
    105115
    106116        // Tell the scheduler to run if
     
    118128        // Is it time to move to the next transport in active scan?
    119129        if (activeScan && (MythDate::current() > activeScanNextTrig))
    120130        {
    121             // if there have been any new events, tell scheduler to run.
     131        LOG(VB_EIT, LOG_INFO,
     132                    LOC_ID + QString("activeScan and time to move to the next channel"));
     133    // if there have been any new events, tell scheduler to run.
    122134            if (eitCount)
    123135            {
    124136                LOG(VB_EIT, LOG_INFO,
     
    150162
    151163            // 24 hours ago
    152164            eitHelper->PruneEITCache(activeScanNextTrig.toTime_t() - 86400);
     165            LOG(VB_EIT, LOG_INFO,
     166                        LOC_ID + QString("PruneEITCache DONE "));
     167            if (activeScanNextChan == activeScanChannels.end())
     168            {
     169                activeScanNextChan = activeScanChannels.begin();
     170                activeScanStopped = true;
     171                activeScanCond.wakeAll();
     172            }
     173
    153174        }
    154175
    155         lock.lock();
     176        // lock.lock();
    156177        if ((activeScan || activeScanStopped) && !exitThread)
    157             exitThreadCond.wait(&lock, 400); // sleep up to 400 ms.
     178            exitThreadCond.wait(&mutex, 400); // sleep up to 400 ms.
    158179
    159180        if (!activeScan && !activeScanStopped)
    160181        {
     182            LOG(VB_EIT, LOG_INFO,
     183                        LOC_ID + QString("Not activeScan and not activeScanStopped "));
    161184            activeScanStopped = true;
    162185            activeScanCond.wakeAll();
    163186        }
    164     }
     187    } // End while
     188    LOG(VB_EIT, LOG_INFO, LOC_ID +
     189        QString("Exiting while not exitThread loop - channel %1"
     190                " activeScanNextTrig 2").arg(*activeScanNextChan));
    165191
    166192    if (eitCount) /* some events have been handled since the last schedule request */
    167193    {
     
    171197
    172198    activeScanStopped = true;
    173199    activeScanCond.wakeAll();
    174     lock.unlock();
     200    // lock.unlock();
    175201}
    176202
    177203/** \fn EITScanner::RescheduleRecordings(void)
     
    192218void EITScanner::StartPassiveScan(ChannelBase *_channel,
    193219                                  EITSource *_eitSource)
    194220{
    195     QMutexLocker locker(&lock);
     221    QMutexLocker locker(&mutex);
    196222
    197223    eitSource     = _eitSource;
    198224    channel       = _channel;
     
    210236 */
    211237void EITScanner::StopPassiveScan(void)
    212238{
    213     QMutexLocker locker(&lock);
     239    QMutexLocker locker(&mutex);
    214240
    215241    if (eitSource)
    216242    {
     
    227253void EITScanner::StartActiveScan(TVRec *_rec, uint max_seconds_per_source)
    228254{
    229255    rec = _rec;
     256    uint i, randomStart;
    230257
    231258    if (activeScanChannels.isEmpty())
    232259    {
    233260        // TODO get input name and use it in crawl.
     261        // Place channels with earliest "latest starttime" first in list
    234262        MSqlQuery query(MSqlQuery::InitCon());
    235263        query.prepare(
    236             "SELECT channum, MIN(chanid) "
    237             "FROM channel, cardinput, capturecard, videosource "
     264            "SELECT channum, channel.chanid "
     265            "FROM cardinput, capturecard, videosource, channel LEFT JOIN program "
     266            "ON channel.chanid = program.chanid                "
    238267            "WHERE cardinput.sourceid   = channel.sourceid AND "
    239268            "      videosource.sourceid = channel.sourceid AND "
    240269            "      capturecard.cardid   = cardinput.cardid AND "
     
    244273            "      channum             != ''               AND "
    245274            "      cardinput.cardid     = :CARDID "
    246275            "GROUP BY mplexid "
    247             "ORDER BY cardinput.sourceid, mplexid, "
    248             "         atsc_major_chan, atsc_minor_chan ");
     276            "ORDER BY MAX(starttime) ");
     277
    249278        query.bindValue(":CARDID", rec->GetCaptureCardNum());
    250279
    251280        if (!query.exec() || !query.isActive())
     
    261290    }
    262291
    263292    LOG(VB_EIT, LOG_INFO, LOC_ID +
    264         QString("StartActiveScan called with %1 multiplexes")
    265             .arg(activeScanChannels.size()));
     293        QString("StartActiveScan called with %1 multiplexes %2")
     294         .arg(activeScanChannels.size()).arg(activeScanChannels.join(",")));
    266295
    267296    // Start at a random channel. This is so that multiple cards with
    268297    // the same source don't all scan the same channels in the same
    269298    // order when the backend is first started up.
    270299    if (activeScanChannels.size())
    271300    {
    272         uint randomStart = random() % activeScanChannels.size();
    273         activeScanNextChan = activeScanChannels.begin()+randomStart;
     301    srandom(time(0));
     302      // If more than 5 channels, only randomize the first five
     303        if (activeScanChannels.size() > 4){
     304          // randomstart one more than number in "if"
     305          randomStart = 5;
     306        }
     307        else{
     308          randomStart = activeScanChannels.size();
     309        }
     310        for (i=0;i<randomStart;i++)
     311          {
     312              activeScanChannels.swap(i,random() % randomStart);
     313              LOG(VB_EIT, LOG_DEBUG, LOC_ID +
     314                  QString("StartActiveScan swap   with %1 multiplexes %2")
     315                   .arg(activeScanChannels.size())
     316                   .arg(activeScanChannels.join(",")));
     317          }
     318        activeScanChannels.swap(activeScanChannels.size() -1 - random() % randomStart, activeScanChannels.size() - 1);
     319        activeScanNextChan = activeScanChannels.begin();
    274320
    275321        activeScanNextTrig = MythDate::current();
    276322        activeScanTrigTime = max_seconds_per_source;
     
    280326        activeScanStopped = false;
    281327        activeScan = true;
    282328    }
     329    LOG(VB_EIT, LOG_INFO, LOC_ID +
     330        QString("StartActiveScan random with %1 multiplexes %2")
     331            .arg(activeScanChannels.size()).arg(activeScanChannels.join(",")));
    283332}
    284333
    285334void EITScanner::StopActiveScan(void)
    286335{
    287     QMutexLocker locker(&lock);
     336    LOG(VB_EIT, LOG_INFO, LOC_ID +
     337        QString("EITScanner::StopActiveScan"));
     338    QMutexLocker locker(&mutex);
    288339
    289340    activeScanStopped = false;
    290341    activeScan = false;
     
    295346    locker.relock();
    296347
    297348    while (!activeScan && !activeScanStopped)
    298         activeScanCond.wait(&lock, 100);
     349        activeScanCond.wait(&mutex, 100);
    299350
    300351    rec = NULL;
    301352}
  • eitscanner.h

    diff -Naur libmythtv/eitscanner.h libmythtvclone/eitscanner.h
    old new  
    77#include <QStringList>
    88#include <QDateTime>
    99#include <QRunnable>
    10 #include <QMutex>
     10// #include <QMutex>
     11#include <QMutexLocker>
    1112
    1213class TVRec;
    1314class MThread;
     
    4849    static void *SpawnEventLoop(void*);
    4950           void  RescheduleRecordings(void);
    5051
    51     QMutex           lock;
     52    // QMutex           lock;
     53    mutable QMutex   mutex;
    5254    ChannelBase     *channel;
    5355    EITSource       *eitSource;
    5456
  • mpeg/atscstreamdata.cpp

    diff -Naur libmythtv/mpeg/atscstreamdata.cpp libmythtvclone/mpeg/atscstreamdata.cpp
    old new  
    305305        }
    306306        case TableID::ETT:
    307307        {
     308            QMutexLocker locker(&_listener_lock);
    308309            ExtendedTextTable ett(psip);
    309310
    310             QMutexLocker locker(&_listener_lock);
    311311            for (uint i = 0; i < _atsc_eit_listeners.size(); i++)
    312312                _atsc_eit_listeners[i]->HandleETT(pid, &ett);
    313313
  • programdata.cpp

    diff -Naur libmythtv/programdata.cpp libmythtvclone/programdata.cpp
    old new  
    218218    int  i     = -1;
    219219
    220220    if (!count)
     221    {
     222        LOG(VB_EIT, LOG_DEBUG,QString("GetOverlappingPrograms returned zero."));
    221223        return InsertDB(query, chanid);
    222 
     224    }
    223225    // move overlapping programs out of the way and update existing if possible
    224226    match = GetMatch(programs, i);
    225227
     
    489491    if (match.subtitle.length() >= lsubtitle.length())
    490492        lsubtitle = match.subtitle;
    491493
    492     if (match.description.length() >= ldesc.length())
    493         ldesc = match.description;
     494//    if (match.description.length() >= ldesc.length())
     495//    if (match.description.length() >= 2)
     496//        ldesc = match.description;
    494497
    495498    if (lcategory.isEmpty() && !match.category.isEmpty())
    496499        lcategory = match.category;
     
    534537    query.prepare(
    535538        "UPDATE program "
    536539        "SET title          = :TITLE,     subtitle      = :SUBTITLE, "
    537         "    description    = :DESC, "
     540        "    description    = :DESCR, "
    538541        "    category       = :CATEGORY,  category_type = :CATTYPE, "
    539542        "    starttime      = :STARTTIME, endtime       = :ENDTIME, "
    540543        "    closecaptioned = :CC,        subtitled     = :HASSUBTITLES, "
     
    554557    query.bindValue(":OLDSTART",    match.starttime);
    555558    query.bindValue(":TITLE",       denullify(ltitle));
    556559    query.bindValue(":SUBTITLE",    denullify(lsubtitle));
    557     query.bindValue(":DESC",        denullify(ldesc));
     560    query.bindValue(":DESCR",        denullify(ldesc));
    558561    query.bindValue(":CATEGORY",    denullify(lcategory));
    559562    query.bindValue(":CATTYPE",     lcattype);
    560563    query.bindValue(":STARTTIME",   starttime);
     
    12351238        "      endtime         = :END        AND "
    12361239        "      title           = :TITLE      AND "
    12371240        "      subtitle        = :SUBTITLE   AND "
    1238         "      description     = :DESC       AND "
     1241        "      description     = :DESCR      AND "
    12391242        "      category        = :CATEGORY   AND "
    12401243        "      category_type   = :CATEGORY_TYPE AND "
    12411244        "      airdate         = :AIRDATE    AND "
     
    12611264    query.bindValue(":END",        pi.endtime);
    12621265    query.bindValue(":TITLE",      denullify(pi.title));
    12631266    query.bindValue(":SUBTITLE",   denullify(pi.subtitle));
    1264     query.bindValue(":DESC",       denullify(pi.description));
     1267    query.bindValue(":DESCR",      denullify(pi.description));
    12651268    query.bindValue(":CATEGORY",   denullify(pi.category));
    12661269    query.bindValue(":CATEGORY_TYPE", cattype);
    12671270    query.bindValue(":AIRDATE",    pi.airdate);
  • tv_rec.cpp

    diff -Naur libmythtv/tv_rec.cpp libmythtvclone/tv_rec.cpp
    old new  
    12671267        scanner = new EITScanner(cardid);
    12681268        eitScanStartTime = eitScanStartTime.addSecs(
    12691269            eitCrawlIdleStart + eit_start_rand(cardid, eitTransportTimeout));
     1270        LOG(VB_GENERAL, LOG_INFO, LOC + "Adjusted Scan start " + eitScanStartTime.toString());
    12701271    }
    12711272    else
     1273    {
    12721274        eitScanStartTime = eitScanStartTime.addYears(1);
     1275        LOG(VB_GENERAL, LOG_INFO, LOC + "EIT scan DISABLED " + eitScanStartTime.toString());
     1276    }
    12731277
    12741278    while (HasFlags(kFlagRunMainLoop))
    12751279    {
     
    14161420            }
    14171421            else
    14181422            {
     1423                LOG(VB_GENERAL, LOG_INFO, LOC + QString("StartActiveScan eitTransportTimeout is %1 ")
     1424                    .arg(eitTransportTimeout));
    14191425                scanner->StartActiveScan(this, eitTransportTimeout);
    14201426                SetFlags(kFlagEITScannerRunning);
    1421                 eitScanStartTime = MythDate::current().addYears(1);
     1427                eitScanStartTime = MythDate::current().addSecs(8192);
     1428                //eitScanStartTime = MythDate::current().addYears(1);
    14221429            }
    14231430        }
    14241431
     
    39323939        ClearFlags(kFlagNeedToStartRecorder);
    39333940        newRecStatus = rsFailed;
    39343941
    3935         if (scanner && HasFlags(kFlagEITScannerRunning))
    3936         {
    3937             scanner->StopActiveScan();
    3938             ClearFlags(kFlagEITScannerRunning);
    3939             eitScanStartTime = MythDate::current();
    3940             eitScanStartTime = eitScanStartTime.addSecs(eitCrawlIdleStart +
    3941                                   eit_start_rand(cardid, eitTransportTimeout));
    3942         }
     3942        return NULL;
     3943//        if (scanner && HasFlags(kFlagEITScannerRunning))
     3944//        {
     3945//            scanner->StopActiveScan();
     3946//            ClearFlags(kFlagEITScannerRunning);
     3947//            eitScanStartTime = MythDate::current();
     3948//            eitScanStartTime = eitScanStartTime.addSecs(eitCrawlIdleStart +
     3949//                                  eit_start_rand(cardid, eitTransportTimeout));
     3950//        }
    39433951    }
    39443952    else
    39453953    {