Ticket #10076: 0009-make_EIT_start_at_time.2.patch

File 0009-make_EIT_start_at_time.2.patch, 11.3 KB (added by warpme@…, 9 years ago)

Cleaned-up patch + updated for current master

  • mythtv/libs/libmythtv/tv_rec.cpp

    diff -Naur mythtv-master-20150827-g4a81075-old/mythtv/libs/libmythtv/tv_rec.cpp mythtv-master-20150827-g4a81075-new/mythtv/libs/libmythtv/tv_rec.cpp
    old new  
    9595      // Configuration variables from database
    9696      transcodeFirst(false),
    9797      earlyCommFlag(false),         runJobOnHostOnly(false),
    98       eitCrawlIdleStart(60),        eitTransportTimeout(5*60),
     98      eitCrawlIdleStart(60),        eitTransportTimeout(5*60),  eitCrawlDuration(240),
    9999      audioSampleRateDB(0),
    100100      overRecordSecNrml(0),         overRecordSecCat(0),
    101101      overRecordCategory(""),
     
    172172    eitTransportTimeout =
    173173        max(gCoreContext->GetNumSetting("EITTransportTimeout", 5) * 60, 6);
    174174    eitCrawlIdleStart = gCoreContext->GetNumSetting("EITCrawIdleStart", 60);
     175    // eitCrawlDuration currently defaulted to 240min.
     176    // if user wants diferent value, EITCrawlDuration setting shoud be added to settings table
     177    eitCrawlDuration  = gCoreContext->GetNumSetting("EITCrawDuration", 240);
     178    // eitCrawlDuration  = 240;
    175179    audioSampleRateDB = gCoreContext->GetNumSetting("AudioSampleRate");
    176180    overRecordSecNrml = gCoreContext->GetNumSetting("RecordOverTime");
    177181    overRecordSecCat  = gCoreContext->GetNumSetting("CategoryOverTime") * 60;
     
    10651069    {
    10661070        scanner->StopActiveScan();
    10671071        ClearFlags(kFlagEITScannerRunning, __FILE__, __LINE__);
     1072        LOG(VB_GENERAL, LOG_INFO, LOC +
     1073            "EIT active scanner stopped by Recording or LiveTV");
    10681074    }
    10691075
    10701076    // Handle different state transitions
     
    11131119    internalState = nextState;
    11141120    changeState = false;
    11151121
    1116     eitScanStartTime = MythDate::current();
     1122    eitScanStartTime = QDateTime::currentDateTime();
    11171123    if (scanner && (internalState == kState_None))
    11181124    {
    1119         eitScanStartTime = eitScanStartTime.addSecs(
    1120             eitCrawlIdleStart + eit_start_rand(inputid, eitTransportTimeout));
     1125        int start_delay = eit_start_rand(inputid, eitTransportTimeout);
     1126        // If eitCrawlIdleStart is above 3600 then we enter schedulled mode.
     1127        // For values 3600 and below we have old behaviour.
     1128        if (eitCrawlIdleStart <= 3600)
     1129        {
     1130            eitScanStartTime = eitScanStartTime.addSecs(
     1131                eitCrawlIdleStart + start_delay);
     1132            eitScanEndTime   = eitScanStartTime.addYears(1);
     1133            LOG(VB_GENERAL, LOG_INFO, LOC +
     1134                QString("EIT active scan will resume after %1 sec.").arg(eitCrawlIdleStart + start_delay));
     1135        }
     1136        else
     1137        {
     1138            // Check is current event within active EIT scan window. If it is,
     1139            // then scanner will be resumed after 60sec.
     1140            // If not, set start/end times next nearest window.
     1141            if ((QDateTime::currentDateTime() < eitScanStartTime) ||
     1142               (QDateTime::currentDateTime() > eitScanEndTime))
     1143            {
     1144                eitScanStartTime.setTime(QTime(0, 0));
     1145                eitScanStartTime = eitScanStartTime.addSecs(eitCrawlIdleStart);
     1146                eitScanEndTime = eitScanStartTime.addSecs(eitCrawlDuration*60);
     1147
     1148                // distribute scan resume time evenly over eitTransportTimeout
     1149                eitScanStartTime = eitScanStartTime.addSecs(start_delay);
     1150
     1151                // IF we started after window, move start & end
     1152                // time to next day
     1153                if (QDateTime::currentDateTime() > eitScanEndTime)
     1154                {
     1155                    eitScanStartTime = eitScanStartTime.addDays(1);
     1156                    eitScanEndTime = eitScanEndTime.addDays(1);
     1157                }
     1158                LOG(VB_GENERAL, LOG_INFO, LOC +
     1159                    QString("EIT active scan will resume at:%1").arg(eitScanStartTime.toString(Qt::ISODate)));
     1160            }
     1161            else
     1162            {
     1163                eitScanStartTime = eitScanStartTime.addSecs(60 + start_delay);
     1164                LOG(VB_GENERAL, LOG_INFO, LOC +
     1165                    QString("EIT active scan is in %1min. window. If enabled, will (re)start after %2 sec.")
     1166                    .arg(eitCrawlDuration).arg(60 + start_delay));
     1167            }
     1168        }
    11211169    }
    11221170    else
    11231171        eitScanStartTime = eitScanStartTime.addYears(1);
     
    13141362    SetFlags(kFlagRunMainLoop, __FILE__, __LINE__);
    13151363    ClearFlags(kFlagExitPlayer | kFlagFinishRecording, __FILE__, __LINE__);
    13161364
    1317     eitScanStartTime = MythDate::current();
     1365    eitScanStartTime = QDateTime::currentDateTime();
    13181366    // check whether we should use the EITScanner in this TVRec instance
    13191367    if (CardUtil::IsEITCapable(genOpt.inputtype) &&
    13201368        (!GetDTVChannel() || GetDTVChannel()->IsMaster()) &&
    13211369        (dvbOpt.dvb_eitscan || get_use_eit(inputid)))
    13221370    {
    13231371        scanner = new EITScanner(inputid);
    1324         eitScanStartTime = eitScanStartTime.addSecs(
    1325             eitCrawlIdleStart + eit_start_rand(inputid, eitTransportTimeout));
     1372        int start_delay = eit_start_rand(inputid, eitTransportTimeout);
     1373
     1374        if (eitCrawlIdleStart <= 3600)
     1375        {
     1376            eitScanStartTime = eitScanStartTime.addSecs(eitCrawlIdleStart + start_delay);
     1377
     1378            eitScanEndTime   = eitScanStartTime.addYears(1);
     1379            LOG(VB_GENERAL, LOG_INFO, LOC +
     1380                QString("EIT active scan start after %1 sec.").arg(eitCrawlIdleStart + start_delay));
     1381        }
     1382        else
     1383        {
     1384            // Set initial scan start / end times to
     1385            // 0:00+eitCrawlIdleStart / eitCrawlIdleStart+eitCrawlDuration.
     1386            eitScanStartTime.setTime(QTime(0, 0));
     1387            eitScanStartTime = eitScanStartTime.addSecs(eitCrawlIdleStart + start_delay);
     1388            eitScanEndTime = eitScanStartTime.addSecs(eitCrawlDuration*60);
     1389
     1390            // If we are in scan window then delay and randomize start
     1391            if (QDateTime::currentDateTime() > eitScanStartTime && QDateTime::currentDateTime() < eitScanEndTime)
     1392            {
     1393                eitScanStartTime = QDateTime::currentDateTime();
     1394                eitScanStartTime = eitScanStartTime.addSecs(60 + start_delay);
     1395                LOG(VB_GENERAL, LOG_INFO, LOC +
     1396                   QString("EIT scanner is in window & will start: %1").arg(eitScanStartTime.toString(Qt::ISODate)));
     1397            }
     1398
     1399            // If we are started after scan window, then move start & end
     1400            // times to next day
     1401            if (QDateTime::currentDateTime() > eitScanEndTime)
     1402            {
     1403                eitScanStartTime = eitScanStartTime.addDays(1);
     1404                eitScanEndTime = eitScanEndTime.addDays(1);
     1405            }
     1406
     1407            LOG(VB_GENERAL, LOG_INFO, LOC +
     1408                QString("EIT active scan window: %1").arg(eitScanStartTime.toString(Qt::ISODate)) +
     1409                QString(" <--> %1 ").arg(eitScanEndTime.toString(Qt::ISODate)) + QString("(%1min duration)").arg(eitCrawlDuration));
     1410        }
    13261411    }
    13271412    else
     1413    {
    13281414        eitScanStartTime = eitScanStartTime.addYears(1);
     1415        eitScanEndTime = eitScanStartTime;
     1416    }
    13291417
    13301418    while (HasFlags(kFlagRunMainLoop))
    13311419    {
     
    14571545        }
    14581546
    14591547        if (scanner && channel &&
    1460             MythDate::current() > eitScanStartTime)
     1548            (QDateTime::currentDateTime() > eitScanStartTime || QDateTime::currentDateTime() > eitScanEndTime))
    14611549        {
    14621550            if (!dvbOpt.dvb_eitscan)
    14631551            {
    14641552                LOG(VB_EIT, LOG_INFO, LOC +
    14651553                    "EIT scanning disabled for this input.");
    14661554                eitScanStartTime = eitScanStartTime.addYears(1);
     1555                eitScanEndTime = eitScanEndTime.addYears(1);
    14671556            }
    14681557            else if (!get_use_eit(GetInputId()))
    14691558            {
    14701559                LOG(VB_EIT, LOG_INFO, LOC +
    14711560                    "EIT scanning disabled for all sources on this input.");
    14721561                eitScanStartTime = eitScanStartTime.addYears(1);
     1562                eitScanEndTime = eitScanEndTime.addYears(1);
    14731563            }
    14741564            else
    14751565            {
    1476                 scanner->StartActiveScan(this, eitTransportTimeout);
    1477                 SetFlags(kFlagEITScannerRunning, __FILE__, __LINE__);
    1478                 eitScanStartTime = MythDate::current().addYears(1);
     1566                if (QDateTime::currentDateTime() > eitScanStartTime && QDateTime::currentDateTime() < eitScanEndTime)
     1567                {
     1568                    scanner->StartActiveScan(this, eitTransportTimeout);
     1569                    SetFlags(kFlagEITScannerRunning, __FILE__, __LINE__);
     1570                    eitScanStartTime = MythDate::current().addYears(1);
     1571                    LOG(VB_GENERAL, LOG_INFO, LOC +
     1572                        "EIT active scan started.");
     1573                }
     1574                else if (QDateTime::currentDateTime() > eitScanEndTime && HasFlags(kFlagEITScannerRunning))
     1575                {
     1576                    scanner->StopActiveScan();
     1577                    ClearFlags(kFlagEITScannerRunning, __FILE__, __LINE__);
     1578                    LOG(VB_GENERAL, LOG_INFO, LOC +
     1579                        "EIT active scan stopped by reaching time window.");
     1580                }
    14791581            }
    14801582        }
    14811583
  • mythtv/libs/libmythtv/tv_rec.h

    diff -Naur mythtv-master-20150827-g4a81075-old/mythtv/libs/libmythtv/tv_rec.h mythtv-master-20150827-g4a81075-new/mythtv/libs/libmythtv/tv_rec.h
    old new  
    363363    bool    runJobOnHostOnly;
    364364    int     eitCrawlIdleStart;
    365365    int     eitTransportTimeout;
     366    int     eitCrawlDuration;
    366367    int     audioSampleRateDB;
    367368    int     overRecordSecNrml;
    368369    int     overRecordSecCat;
     
    392393    TuningQueue    tuningRequests;
    393394    TuningRequest  lastTuningRequest;
    394395    QDateTime      eitScanStartTime;
     396    QDateTime      eitScanEndTime;
    395397    mutable QMutex triggerEventLoopLock;
    396398    QWaitCondition triggerEventLoopWait;
    397399    bool           triggerEventLoopSignal;
  • mythtv/programs/mythtv-setup/backendsettings.cpp

    diff -Naur mythtv-master-20150827-g4a81075-old/mythtv/programs/mythtv-setup/backendsettings.cpp mythtv-master-20150827-g4a81075-new/mythtv/programs/mythtv-setup/backendsettings.cpp
    old new  
    308308
    309309static GlobalSpinBox *EITCrawIdleStart()
    310310{
    311     GlobalSpinBox *gc = new GlobalSpinBox("EITCrawIdleStart", 30, 7200, 30);
     311    GlobalSpinBox *gc = new GlobalSpinBox("EITCrawIdleStart", 30, 86400, 20);
    312312    gc->setLabel(QObject::tr("Backend idle before EIT crawl (secs)"));
    313313    gc->setValue(60);
    314314    QString help = QObject::tr(
    315         "The minimum number of seconds after a recorder becomes idle "
    316         "to wait before MythTV begins collecting EIT listings data.");
     315        "The number of seconds for idle recorders when collecting EIT listings begins. "
     316        "If this value is higher than 3600 sec, MythTV will switch to schedulled mode"
     317        " where collecting starts this number of seconds after midnight and will go"
     318        " for EITCrawDuration or if not defined, 4h time window."
     319         );
    317320    gc->setHelpText(help);
    318321    return gc;
    319322}