Ticket #10076: 0004-EIT-make-EIT-start-at-time.patch

File 0004-EIT-make-EIT-start-at-time.patch, 13.7 KB (added by warpme, 3 years ago)

Patch for current master

  • mythtv/libs/libmythtv/tv_rec.cpp

    diff -Naur mythtv-master-20201010-g68e85b9-old/mythtv/libs/libmythtv/tv_rec.cpp mythtv-master-20201010-g68e85b9-new/mythtv/libs/libmythtv/tv_rec.cpp
    old new  
    157157    m_eitTransportTimeout =
    158158        std::max(gCoreContext->GetNumSetting("EITTransportTimeout", 5) * 60, 6);
    159159    m_eitCrawlIdleStart = gCoreContext->GetNumSetting("EITCrawIdleStart", 60);
     160    // EITCrawlDuration currently defaulted to 240min.
     161    // if user wants diferent value, EITCrawlDuration setting shoud be added to settings table
     162    m_eitCrawlDuration  = gCoreContext->GetNumSetting("EITCrawDuration", 240);
     163    // m_eitCrawlDuration  = 240;
    160164    m_audioSampleRateDB = gCoreContext->GetNumSetting("AudioSampleRate");
    161165    m_overRecordSecNrml = gCoreContext->GetNumSetting("RecordOverTime");
    162166    m_overRecordSecCat  = gCoreContext->GetNumSetting("CategoryOverTime") * 60;
     
    10511055        ClearFlags(kFlagEITScannerRunning, __FILE__, __LINE__);
    10521056        m_eitScanStartTime = MythDate::current().addSecs(
    10531057            m_eitCrawlIdleStart + eit_start_rand(m_inputId, m_eitTransportTimeout));
     1058        LOG(VB_GENERAL, LOG_INFO, LOC +
     1059            "EIT active scanner stopped by Recording or LiveTV");
    10541060    }
    10551061
    10561062    // Handle different state transitions
     
    11031109    m_internalState = nextState;
    11041110    m_changeState = false;
    11051111
    1106     m_eitScanStartTime = MythDate::current();
     1112    m_eitScanStartTime = QDateTime::currentDateTime();
    11071113    if (m_scanner && (m_internalState == kState_None))
    11081114    {
    1109         m_eitScanStartTime = m_eitScanStartTime.addSecs(
    1110             m_eitCrawlIdleStart + eit_start_rand(m_inputId, m_eitTransportTimeout));
     1115        int start_delay = eit_start_rand(m_inputId, m_eitTransportTimeout);
     1116        // If eitCrawlIdleStart is above 3600 then we enter schedulled mode.
     1117        // For values 3600 and below we have old behaviour.
     1118        if (m_eitCrawlIdleStart <= 3600)
     1119        {
     1120            m_eitScanStartTime = m_eitScanStartTime.addSecs(
     1121                m_eitCrawlIdleStart + start_delay);
     1122            m_eitScanEndTime   = m_eitScanStartTime.addYears(10);
     1123            LOG(VB_GENERAL, LOG_INFO, LOC +
     1124                QString("EIT active scan will resume after %1 sec.").arg(m_eitCrawlIdleStart + start_delay));
     1125        }
     1126        else
     1127        {
     1128            // Check is current event within active EIT scan window. If it is,
     1129            // then scanner will be resumed after 60sec.
     1130            // If not, set start/end times next nearest window.
     1131            if ((QDateTime::currentDateTime() < m_eitScanStartTime) ||
     1132               (QDateTime::currentDateTime() > m_eitScanEndTime))
     1133            {
     1134                m_eitScanStartTime.setTime(QTime(0, 0));
     1135                m_eitScanStartTime = m_eitScanStartTime.addSecs(m_eitCrawlIdleStart);
     1136                m_eitScanEndTime = m_eitScanStartTime.addSecs(m_eitCrawlDuration*60);
     1137
     1138                // distribute scan resume time evenly over m_eitTransportTimeout
     1139                m_eitScanStartTime = m_eitScanStartTime.addSecs(start_delay);
     1140
     1141                // IF we started after window, move start & end
     1142                // time to next day
     1143                if (QDateTime::currentDateTime() > m_eitScanEndTime)
     1144                {
     1145                    m_eitScanStartTime = m_eitScanStartTime.addDays(1);
     1146                    m_eitScanEndTime = m_eitScanEndTime.addDays(1);
     1147                }
     1148                LOG(VB_GENERAL, LOG_INFO, LOC +
     1149                    QString("EIT active scan will resume at:%1").arg(m_eitScanStartTime.toString(Qt::ISODate)));
     1150            }
     1151            else
     1152            {
     1153                m_eitScanStartTime = m_eitScanStartTime.addSecs(60 + start_delay);
     1154                LOG(VB_GENERAL, LOG_INFO, LOC +
     1155                    QString("EIT active scan is in %1min. window. If enabled, will (re)start after %2 sec.")
     1156                    .arg(m_eitCrawlDuration).arg(60 + start_delay));
     1157            }
     1158        }
    11111159    }
    11121160    else
    11131161    {
     
    13091357    SetFlags(kFlagRunMainLoop, __FILE__, __LINE__);
    13101358    ClearFlags(kFlagExitPlayer | kFlagFinishRecording, __FILE__, __LINE__);
    13111359
    1312     m_eitScanStartTime = MythDate::current();
     1360    m_eitScanStartTime = QDateTime::currentDateTime();
    13131361
    13141362    // Check whether we should use the EITScanner in this TVRec instance
    13151363    if (CardUtil::IsEITCapable(m_genOpt.m_inputType) &&         // Card type capable of receiving EIT?
    13161364        (!GetDTVChannel() || GetDTVChannel()->IsMaster()) &&    // Card is master and not a multirec instance
    13171365        (m_dvbOpt.m_dvbEitScan || get_use_eit(m_inputId)))      // EIT is selected for card OR EIT is selected for video source
    13181366    {
    13191367        m_scanner = new EITScanner(m_inputId);
    1320         m_eitScanStartTime = m_eitScanStartTime.addSecs(
     1368        int start_delay = eit_start_rand(m_inputId, m_eitTransportTimeout);
     1369
     1370        if (m_eitCrawlIdleStart <= 3600)
     1371        {
     1372            m_eitScanStartTime = m_eitScanStartTime.addSecs(m_eitCrawlIdleStart + start_delay);
     1373
     1374            m_eitScanEndTime   = m_eitScanStartTime.addYears(10);
     1375            LOG(VB_GENERAL, LOG_INFO, LOC +
     1376                QString("EIT active scan start after %1 sec.").arg(m_eitCrawlIdleStart + start_delay));
     1377        }
     1378        else
     1379        {
     1380            // Set initial scan start / end times to
     1381            // 0:00+eitCrawlIdleStart / eitCrawlIdleStart+m_eitCrawlDuration.
     1382            m_eitScanStartTime.setTime(QTime(0, 0));
     1383            m_eitScanStartTime = m_eitScanStartTime.addSecs(m_eitCrawlIdleStart + start_delay);
     1384            m_eitScanEndTime = m_eitScanStartTime.addSecs(m_eitCrawlDuration*60);
     1385
     1386            // If we are in scan window then delay and randomize start
     1387            if (QDateTime::currentDateTime() > m_eitScanStartTime && QDateTime::currentDateTime() < m_eitScanEndTime)
     1388            {
     1389                m_eitScanStartTime = QDateTime::currentDateTime();
     1390                m_eitScanStartTime = m_eitScanStartTime.addSecs(60 + start_delay);
     1391                LOG(VB_GENERAL, LOG_INFO, LOC +
     1392                   QString("EIT scanner is in window & will start: %1").arg(m_eitScanStartTime.toString(Qt::ISODate)));
     1393            }
     1394
     1395            // If we are started after scan window, then move start & end
     1396            // times to next day
     1397            if (QDateTime::currentDateTime() > m_eitScanEndTime)
     1398            {
     1399                m_eitScanStartTime = m_eitScanStartTime.addDays(1);
     1400                m_eitScanEndTime = m_eitScanEndTime.addDays(1);
     1401            }
     1402
     1403            LOG(VB_GENERAL, LOG_INFO, LOC +
     1404                QString("EIT active scan window: %1").arg(m_eitScanStartTime.toString(Qt::ISODate)) +
     1405                QString(" <--> %1 ").arg(m_eitScanEndTime.toString(Qt::ISODate)) + QString("(%1min duration)").arg(m_eitCrawlDuration));
     1406        }        m_eitScanStartTime = m_eitScanStartTime.addSecs(
    13211407            m_eitCrawlIdleStart + eit_start_rand(m_inputId, m_eitTransportTimeout));
    13221408    }
    13231409    else
    13241410    {
    13251411        m_eitScanStartTime = m_eitScanStartTime.addYears(10);
     1412        m_eitScanEndTime = m_eitScanStartTime;
    13261413    }
    13271414
  • mythtv/libs/libmythtv/tv_rec.h

         while (HasFlags(kFlagRunMainLoop))
    @@ -1462,46 +1549,61 @@
     
             // Start active EIT scan
             if (m_scanner && m_channel &&
    -            MythDate::current() > m_eitScanStartTime)
    +            (QDateTime::currentDateTime() > m_eitScanStartTime || QDateTime::currentDateTime() > m_eitScanEndTime))
             {
                 if (!m_dvbOpt.m_dvbEitScan)
                 {
                     LOG(VB_EIT, LOG_INFO, LOC +
                         "EIT scanning disabled for this input.");
                     m_eitScanStartTime = m_eitScanStartTime.addYears(10);
    +                m_eitScanEndTime = m_eitScanEndTime.addYears(10);
                 }
                 else if (!get_use_eit(GetInputId()))
                 {
                     LOG(VB_EIT, LOG_INFO, LOC +
                         "EIT scanning disabled for all channels on this input.");
                     m_eitScanStartTime = m_eitScanStartTime.addYears(10);
    +                m_eitScanEndTime = m_eitScanEndTime.addYears(10);
                 }
                 else
                 {
    -                // Check if another card in the same input group is
    -                // busy.  This could be either virtual DVB-devices or
    -                // a second tuner on a single card
    -                s_inputsLock.lockForRead();
    -                bool allow_eit = true;
    -                vector<uint> inputids =
    -                    CardUtil::GetConflictingInputs(m_inputId);
    -                InputInfo busy_input;
    -                for (uint i = 0; i < inputids.size() && allow_eit; ++i)
    -                    allow_eit = !RemoteIsBusy(inputids[i], busy_input);
    -                if (allow_eit)
    -                {
    -                    m_scanner->StartActiveScan(this, m_eitTransportTimeout);
    -                    SetFlags(kFlagEITScannerRunning, __FILE__, __LINE__);
    -                    m_eitScanStartTime =
    -                        QDateTime::currentDateTime().addYears(10);
    -                }
    -                else
    +
    +                if (QDateTime::currentDateTime() > m_eitScanStartTime && QDateTime::currentDateTime() < m_eitScanEndTime)
                     {
    -                    LOG(VB_EIT, LOG_INFO, LOC + QString(
    +
    +                    // Check if another card in the same input group is
    +                    // busy.  This could be either virtual DVB-devices or
    +                    // a second tuner on a single card
    +                    s_inputsLock.lockForRead();
    +                    bool allow_eit = true;
    +                    vector<uint> inputids =
    +                        CardUtil::GetConflictingInputs(m_inputId);
    +                    InputInfo busy_input;
    +                    for (uint i = 0; i < inputids.size() && allow_eit; ++i)
    +                        allow_eit = !RemoteIsBusy(inputids[i], busy_input);
    +                    if (allow_eit)
    +                    {
    +                        m_scanner->StartActiveScan(this, m_eitTransportTimeout);
    +                        SetFlags(kFlagEITScannerRunning, __FILE__, __LINE__);
    +                        m_eitScanStartTime = MythDate::current().addYears(10);
    +                        LOG(VB_GENERAL, LOG_INFO, LOC +
    +                            "EIT active scan started.");
    +                    }
    +                    else
    +                    {
    +                        LOG(VB_GENERAL, LOG_INFO, LOC + QString(
                                 "Postponing EIT scan on input [%1] "
                                 "because input %2 is busy")
    -                        .arg(m_inputId).arg(busy_input.m_inputId));
    -                    m_eitScanStartTime = m_eitScanStartTime.addSecs(300);
    +                            .arg(m_inputId).arg(busy_input.m_inputId));
    +                        m_eitScanStartTime = m_eitScanStartTime.addSecs(300);
    +                    }
    +                }
    +                else if (QDateTime::currentDateTime() > m_eitScanEndTime && HasFlags(kFlagEITScannerRunning))
    +                {
    +                    m_scanner->StopActiveScan();
    +                    ClearFlags(kFlagEITScannerRunning, __FILE__, __LINE__);
    +                    LOG(VB_GENERAL, LOG_INFO, LOC +
    +                        "EIT active scan stopped by reaching time window.");
                     }
                     s_inputsLock.unlock();
                 }
    diff -Naur mythtv-master-20201010-g68e85b9-old/mythtv/libs/libmythtv/tv_rec.h mythtv-master-20201010-g68e85b9-new/mythtv/libs/libmythtv/tv_rec.h
    old new  
    360360    bool               m_runJobOnHostOnly         {false};
    361361    int                m_eitCrawlIdleStart        {60};
    362362    int                m_eitTransportTimeout      {5*60};
     363    int                m_eitCrawlDuration         {240};
    363364    int                m_audioSampleRateDB        {0};
    364365    int                m_overRecordSecNrml        {0};
    365366    int                m_overRecordSecCat         {0};
     
    390391    TuningQueue        m_tuningRequests;
    391392    TuningRequest      m_lastTuningRequest        {0};
    392393    QDateTime          m_eitScanStartTime;
     394    QDateTime          m_eitScanEndTime;
    393395    mutable QMutex     m_triggerEventLoopLock     {QMutex::NonRecursive};
    394396    QWaitCondition     m_triggerEventLoopWait;
    395397    bool               m_triggerEventLoopSignal   {false};
  • mythtv/programs/mythtv-setup/backendsettings.cpp

    diff -Naur mythtv-master-20201010-g68e85b9-old/mythtv/programs/mythtv-setup/backendsettings.cpp mythtv-master-20201010-g68e85b9-new/mythtv/programs/mythtv-setup/backendsettings.cpp
    old new  
    381381
    382382static GlobalSpinBoxSetting *EITCrawIdleStart()
    383383{
    384     auto *gc = new GlobalSpinBoxSetting("EITCrawIdleStart", 30, 7200, 30);
     384    auto *gc = new GlobalSpinBoxSetting("EITCrawIdleStart", 30, 86400, 20);
    385385    gc->setLabel(QObject::tr("Backend idle before EIT crawl (secs)"));
    386386    gc->setValue(60);
    387387    QString help = QObject::tr(
    388         "The minimum number of seconds after a recorder becomes idle "
    389         "to wait before MythTV begins collecting EIT listings data.");
     388        "The number of seconds for idle recorders when collecting EIT listings begins. "
     389        "If this value is higher than 3600 sec, MythTV will switch to schedulled mode"
     390        " where collecting starts this number of seconds after midnight and will go"
     391        " for EITCrawDuration or if not defined, 4h time window."
     392        );
    390393    gc->setHelpText(help);
    391394    return gc;
    392395}