Ticket #10076: make_EIT_start_at_time.patch

File make_EIT_start_at_time.patch, 13.1 KB (added by warpme@…, 13 years ago)
  • mythtv/libs/libmythtv/tv_rec.cpp

    diff -Naur mythtv-master-20111004-g51c8ce1-old/mythtv/libs/libmythtv/tv_rec.cpp mythtv-master-20111004-g51c8ce1-new/mythtv/libs/libmythtv/tv_rec.cpp
    old new  
    8888      // Configuration variables from database
    8989      transcodeFirst(false),
    9090      earlyCommFlag(false),         runJobOnHostOnly(false),
    91       eitCrawlIdleStart(60),        eitTransportTimeout(5*60),
     91      eitCrawlIdleStart(60),        eitTransportTimeout(5*60),  eitCrawlDuration(240),
    9292      audioSampleRateDB(0),
    9393      overRecordSecNrml(0),         overRecordSecCat(0),
    9494      overRecordCategory(""),
     
    164164    runJobOnHostOnly  = gCoreContext->GetNumSetting("JobsRunOnRecordHost", 0);
    165165    eitTransportTimeout=gCoreContext->GetNumSetting("EITTransportTimeout", 5) * 60;
    166166    eitCrawlIdleStart = gCoreContext->GetNumSetting("EITCrawIdleStart", 60);
     167    // eitCrawlDuration currently hardcoded to 240min as I don't want to change DB schema
     168    // by introdution of new setting.
     169    // eitCrawlDuration  = gCoreContext->GetNumSetting("EITCrawDuration", 240);
     170    eitCrawlDuration  = 240;
    167171    audioSampleRateDB = gCoreContext->GetNumSetting("AudioSampleRate");
    168172    overRecordSecNrml = gCoreContext->GetNumSetting("RecordOverTime");
    169173    overRecordSecCat  = gCoreContext->GetNumSetting("CategoryOverTime") * 60;
     
    919923    }
    920924}
    921925
     926static int no_capturecards(uint cardid)
     927{
     928    MSqlQuery query(MSqlQuery::InitCon());
     929
     930    QString str =
     931        "SELECT COUNT(cardid) "
     932        "FROM capturecard ";
     933
     934    if (cardid)
     935        str += "WHERE cardid < :CARDID";
     936
     937    query.prepare(str);
     938
     939    if (cardid)
     940        query.bindValue(":CARDID", cardid);
     941
     942    if (!query.exec() || !query.isActive())
     943    {
     944        MythDB::DBError("no_capturecards", query);
     945        return -1;
     946    }
     947    else if (query.next())
     948        return query.value(0).toInt();
     949    return -1;
     950}
     951
    922952#define TRANSITION(ASTATE,BSTATE) \
    923953   ((internalState == ASTATE) && (desiredNextState == BSTATE))
    924954#define SET_NEXT() do { nextState = desiredNextState; changed = true; } while(0)
     
    955985    {
    956986        scanner->StopActiveScan();
    957987        ClearFlags(kFlagEITScannerRunning);
     988        LOG(VB_GENERAL, LOG_INFO, LOC +
     989            "EIT active scanner stopped by Recording or LiveTV");
    958990    }
    959991
    960992    // Handle different state transitions
     
    9971029
    9981030    eitScanStartTime = QDateTime::currentDateTime();
    9991031    if (scanner && (internalState == kState_None))
    1000         eitScanStartTime = eitScanStartTime.addSecs(eitCrawlIdleStart);
     1032    {
     1033        // If eitCrawlIdleStart is above 3600 then we enter schedulled mode.
     1034        // For values 3600 and below we have old behaviour.
     1035        if (eitCrawlIdleStart <= 3600)
     1036        {
     1037            eitScanStartTime = eitScanStartTime.addSecs(eitCrawlIdleStart);
     1038            eitScanEndAT   = eitScanStartTime.addYears(1);
     1039            LOG(VB_GENERAL, LOG_INFO, LOC +
     1040                QString("EIT active scan will resume after %1 sec.").arg(eitCrawlIdleStart));
     1041        }
     1042        else
     1043        {
     1044            // Check is current event within active EIT scan window. If it is,
     1045            // then scanner will be resumed after 60sec.
     1046            // If not, set start/end times to next nearest scan window.
     1047            if ((QDateTime::currentDateTime() < eitScanStartAT) ||
     1048               (QDateTime::currentDateTime() > eitScanEndAT))
     1049            {
     1050                eitScanStartTime.setTime(QTime(0, 0));
     1051                eitScanStartTime = eitScanStartTime.addSecs(eitCrawlIdleStart);
     1052                eitScanEndAT = eitScanStartTime.addSecs(eitCrawlDuration*60);
     1053                // distribute resume time evenly over eitTransportTimeout
     1054                int card_pos = no_capturecards(cardid);
     1055                int no_cards = no_capturecards(0);
     1056                uint timeout = 0;
     1057                if (no_cards > 0 && card_pos >= 0)
     1058                    timeout += eitTransportTimeout * card_pos / no_cards;
     1059                else
     1060                    timeout += random() % eitTransportTimeout;
     1061                eitScanStartTime = eitScanStartTime.addSecs(timeout);
     1062                eitScanStartAT = eitScanStartTime;
     1063                // IF we started after window, move start & end
     1064                // time to next day
     1065                if (QDateTime::currentDateTime() > eitScanEndAT)
     1066                {
     1067                    eitScanStartTime = eitScanStartTime.addDays(1);
     1068                    eitScanStartAT = eitScanStartAT.addDays(1);
     1069                    eitScanEndAT = eitScanEndAT.addDays(1);
     1070                }
     1071                LOG(VB_GENERAL, LOG_INFO, LOC +
     1072                    QString("EIT active scan will resume at:%1").arg(eitScanStartTime.toString(Qt::ISODate)));
     1073            }
     1074            else
     1075            {
     1076                eitScanStartTime = eitScanStartTime.addSecs(60);
     1077                LOG(VB_GENERAL, LOG_INFO, LOC +
     1078                    QString("EIT active scan is in %1min. window. If enabled, will (re)start after 60 sec.").arg(eitCrawlDuration));
     1079            }
     1080        }
     1081    }
    10011082    else
    10021083        eitScanStartTime = eitScanStartTime.addYears(1);
    10031084}
     
    11421223    return false;
    11431224}
    11441225
    1145 static int no_capturecards(uint cardid)
    1146 {
    1147     MSqlQuery query(MSqlQuery::InitCon());
    1148 
    1149     QString str =
    1150         "SELECT COUNT(cardid) "
    1151         "FROM capturecard ";
    1152 
    1153     if (cardid)
    1154         str += "WHERE cardid < :CARDID";
    1155 
    1156     query.prepare(str);
    1157 
    1158     if (cardid)
    1159         query.bindValue(":CARDID", cardid);
    1160 
    1161     if (!query.exec() || !query.isActive())
    1162     {
    1163         MythDB::DBError("no_capturecards", query);
    1164         return -1;
    1165     }
    1166     else if (query.next())
    1167         return query.value(0).toInt();
    1168     return -1;
    1169 }
    1170 
    11711226/// \brief Event handling method, contains event loop.
    11721227void TVRec::run(void)
    11731228{
     
    11821237        (dvbOpt.dvb_eitscan || get_use_eit(cardid)))
    11831238    {
    11841239        scanner = new EITScanner(cardid);
    1185         uint timeout = eitCrawlIdleStart;
    11861240        // get the number of capture cards and the position of the current card
    1187         // to distribute the the scan start evenly over eitTransportTimeout
     1241        // to help distribute scan start time evenly over eitTransportTimeout
    11881242        int card_pos = no_capturecards(cardid);
    11891243        int no_cards = no_capturecards(0);
    1190         if (no_cards > 0 && card_pos >= 0)
    1191             timeout += eitTransportTimeout * card_pos / no_cards;
     1244
     1245        // If eitCrawlIdleStart is above 3600 then we enter schedulled mode for
     1246        // EIT active scan. For values 3600 and below we have old behaviour.
     1247        if (eitCrawlIdleStart <= 3600)
     1248        {
     1249            uint timeout = eitCrawlIdleStart;
     1250            if (no_cards > 0 && card_pos >= 0)
     1251                timeout += eitTransportTimeout * card_pos / no_cards;
     1252            else
     1253                timeout += random() % eitTransportTimeout;
     1254            eitScanStartTime = eitScanStartTime.addSecs(timeout);
     1255            eitScanEndAT   = eitScanStartTime.addYears(1);
     1256            LOG(VB_GENERAL, LOG_INFO, LOC +
     1257                QString("EIT active scan start after %1 sec.").arg(timeout));
     1258        }
    11921259        else
    1193             timeout += random() % eitTransportTimeout;
     1260        {
     1261            // Set initial scan start/end time to
     1262            // 0:00+eitCrawlIdleStart/eitCrawlIdleStart+eitCrawlDuration respectively
     1263            eitScanStartTime.setTime(QTime(0, 0));
     1264            eitScanStartTime = eitScanStartTime.addSecs(eitCrawlIdleStart);
     1265            eitScanEndAT = eitScanStartTime.addSecs(eitCrawlDuration*60);
     1266            // Distribute scan start time evenly over eitTransportTimeout
     1267            uint timeout = 0;
     1268            if (no_cards > 0 && card_pos >= 0)
     1269                timeout += eitTransportTimeout * card_pos / no_cards;
     1270            else
     1271                timeout += random() % eitTransportTimeout;
     1272            eitScanStartTime = eitScanStartTime.addSecs(timeout);
    11941273
    1195         eitScanStartTime = eitScanStartTime.addSecs(timeout);
     1274            eitScanStartAT = eitScanStartTime;
     1275            // If we started after window, move start & end
     1276            // time to next day
     1277            if (QDateTime::currentDateTime() > eitScanEndAT)
     1278            {
     1279                eitScanStartTime = eitScanStartTime.addDays(1);
     1280                eitScanStartAT = eitScanStartAT.addDays(1);
     1281                eitScanEndAT = eitScanEndAT.addDays(1);
     1282            }
     1283            LOG(VB_GENERAL, LOG_INFO, LOC +
     1284                QString("EIT active scan window: %1").arg(eitScanStartAT.toString(Qt::ISODate)) +
     1285                QString(" <--> %1").arg(eitScanEndAT.toString(Qt::ISODate)));
     1286        }
    11961287    }
    11971288    else
     1289    {
    11981290        eitScanStartTime = eitScanStartTime.addYears(1);
     1291        eitScanEndAT = eitScanStartTime;
     1292    }
    11991293
    12001294    while (HasFlags(kFlagRunMainLoop))
    12011295    {
     
    13271421            ClearFlags(kFlagExitPlayer);
    13281422        }
    13291423
     1424        // Check should we start or stop active scan on this card
    13301425        if (scanner && channel &&
    1331             QDateTime::currentDateTime() > eitScanStartTime)
     1426           (QDateTime::currentDateTime() > eitScanStartTime || QDateTime::currentDateTime() > eitScanEndAT))
    13321427        {
    13331428            if (!dvbOpt.dvb_eitscan)
    13341429            {
    13351430                LOG(VB_EIT, LOG_INFO, LOC +
    13361431                    "EIT scanning disabled for this card.");
    13371432                eitScanStartTime = eitScanStartTime.addYears(1);
     1433                eitScanEndAT = eitScanEndAT.addYears(1);
    13381434            }
    13391435            else if (!get_use_eit(GetCaptureCardNum()))
    13401436            {
    13411437                LOG(VB_EIT, LOG_INFO, LOC +
    13421438                    "EIT scanning disabled for all sources on this card.");
    13431439                eitScanStartTime = eitScanStartTime.addYears(1);
     1440                eitScanEndAT = eitScanEndAT.addYears(1);
    13441441            }
    13451442            else
    13461443            {
    1347                 scanner->StartActiveScan(this, eitTransportTimeout);
    1348                 SetFlags(kFlagEITScannerRunning);
    1349                 eitScanStartTime = QDateTime::currentDateTime().addYears(1);
     1444                if (QDateTime::currentDateTime() > eitScanStartTime && QDateTime::currentDateTime() < eitScanEndAT)
     1445                {
     1446                    scanner->StartActiveScan(this, eitTransportTimeout);
     1447                    SetFlags(kFlagEITScannerRunning);
     1448                    eitScanStartTime = QDateTime::currentDateTime().addYears(1);
     1449                    LOG(VB_GENERAL, LOG_INFO, LOC +
     1450                        "EIT active scan started.");
     1451                }
     1452                else if (QDateTime::currentDateTime() > eitScanEndAT && HasFlags(kFlagEITScannerRunning))
     1453                {
     1454                    scanner->StopActiveScan();
     1455                    ClearFlags(kFlagEITScannerRunning);
     1456                    LOG(VB_GENERAL, LOG_INFO, LOC +
     1457                        "EIT active scan stopped by reaching time window.");
     1458                }
    13501459            }
    13511460        }
    13521461
  • mythtv/libs/libmythtv/tv_rec.h

    diff -Naur mythtv-master-20111004-g51c8ce1-old/mythtv/libs/libmythtv/tv_rec.h mythtv-master-20111004-g51c8ce1-new/mythtv/libs/libmythtv/tv_rec.h
    old new  
    329329    bool    runJobOnHostOnly;
    330330    int     eitCrawlIdleStart;
    331331    int     eitTransportTimeout;
     332    int     eitCrawlDuration;
    332333    int     audioSampleRateDB;
    333334    int     overRecordSecNrml;
    334335    int     overRecordSecCat;
     
    355356    TuningQueue    tuningRequests;
    356357    TuningRequest  lastTuningRequest;
    357358    QDateTime      eitScanStartTime;
     359    QDateTime      eitScanStartAT;
     360    QDateTime      eitScanEndAT;
    358361    mutable QMutex triggerEventLoopLock;
    359362    QWaitCondition triggerEventLoopWait;
    360363    bool           triggerEventLoopSignal;
  • mythtv/programs/mythtv-setup/backendsettings.cpp

    diff -Naur mythtv-master-20111004-g51c8ce1-old/mythtv/programs/mythtv-setup/backendsettings.cpp mythtv-master-20111004-g51c8ce1-new/mythtv/programs/mythtv-setup/backendsettings.cpp
    old new  
    330330
    331331static GlobalSpinBox *EITCrawIdleStart()
    332332{
    333     GlobalSpinBox *gc = new GlobalSpinBox("EITCrawIdleStart", 30, 7200, 30);
     333    GlobalSpinBox *gc = new GlobalSpinBox("EITCrawIdleStart", 30, 86400, 20);
    334334    gc->setLabel(QObject::tr("Backend idle before EIT crawl (secs)"));
    335335    gc->setValue(60);
    336336    QString help = QObject::tr(
    337         "The minimum number of seconds after a recorder becomes idle "
    338         "to wait before MythTV begins collecting EIT listings data.");
     337        "The number of seconds for idle recorders when collecting EIT listings begins. "
     338        "If this value is higher than 3600 sec, MythTV will switch to schedulled mode"
     339        " where collecting starts this number of seconds after midnight and will go"
     340        " for 4h time window."
     341         );
    339342    gc->setHelpText(help);
    340343    return gc;
    341344}