Ticket #5754: activeeit-one-in-eight-hours.diff

File activeeit-one-in-eight-hours.diff, 5.2 KB (added by simonwalls@…, 16 years ago)

Patch for 0.21-fixes SVN 17451 to make Active EIT scan for only one hour in eight

  • libs/libmythtv/tv_rec.h

     
    371371    TuningQueue    tuningRequests;
    372372    TuningRequest  lastTuningRequest;
    373373    QDateTime      eitScanStartTime;
     374    QDateTime      eitScanStopTime;
     375    uint           activeScanCycleTime;
     376    uint           activeScanDuration;
    374377    QWaitCondition triggerEventLoop;
    375378    QWaitCondition triggerEventSleep;
    376379    bool           m_switchingBuffer;
  • libs/libmythtv/tv_rec.cpp

     
    890890    // to avoid race condition with it's tuning requests.
    891891    if (HasFlags(kFlagEITScannerRunning))
    892892    {
     893        VERBOSE(VB_EIT, LOC + "Stopping EIT Active Scan due to tuning in TVRec::HandleStateChange.");
    893894        scanner->StopActiveScan();
    894895        ClearFlags(kFlagEITScannerRunning);
    895896    }
     
    13091310    SetFlags(kFlagRunMainLoop);
    13101311    ClearFlags(kFlagExitPlayer | kFlagFinishRecording);
    13111312
     1313    uint ActiveCycleSleepSecs;
     1314    bool ScanStopped;
     1315
     1316    ScanStopped = true;
     1317
    13121318    eitScanStartTime = QDateTime::currentDateTime();   
    13131319    // check whether we should use the EITScanner in this TVRec instance
    13141320    if (CardUtil::IsEITCapable(genOpt.cardtype) &&
     
    14441450            ClearFlags(kFlagExitPlayer);
    14451451        }
    14461452
     1453
     1454        // EIT Scanner handling
    14471455        if (channel && scanner &&
    14481456            QDateTime::currentDateTime() > eitScanStartTime)
    14491457        {
     
    14581466                        "for all sources on this card.");
    14591467                eitScanStartTime = eitScanStartTime.addYears(1);
    14601468            }
     1469            // Things are good to start Active Scan
     1470            // We now know that currentDateTime > eitScanStartTime but we don't know if
     1471            // we have exceeded the eitScanStopTime
    14611472            else
    14621473            {
     1474                // Following are control variables for the improved active scan
     1475                // It stops after a defined period and closes the tuner card,
     1476                // the idea is to see if it saves some power. There is usually no need
     1477                // to scan for EIT data continuously.
     1478       
     1479                // Set the repeat rate of the active scan to 480 minutes (8 hours)
     1480                activeScanCycleTime = 480;
     1481                // It would be wise to schedule an EIT scan shortly before a recording,
     1482                // to check for re-schedules (To Be Done).
     1483       
     1484                // Set the duration of the active scan to 60 minutes (1 hour)
     1485                activeScanDuration = 60 * 60;
     1486       
     1487                eitScanStopTime = eitScanStartTime
     1488                        .addSecs(activeScanDuration);
     1489       
     1490                // Log some information about the settings
     1491                VERBOSE(VB_EIT, LOC +
     1492                QString("Improved Active Scan cycle time %1 minutes")
     1493                .arg(activeScanCycleTime));
     1494                VERBOSE(VB_EIT, LOC +
     1495                QString("Improved Active Scan Duration   %1 minutes")
     1496                .arg(activeScanDuration/60));
     1497       
     1498                ScanStopped = false ;
     1499
     1500                // Active Scan is restarted after a recording uses the tuner, so the
     1501                // relative position of the 'window' moves as recordings are made.
     1502                // If settings give poor programme guide population, they can be changed
     1503                // Ideally there could be a control in mythtv-setup where active scan is enabled
     1504
     1505                VERBOSE(VB_EIT, LOC + "EIT Active Scan being (re)started.");
    14631506                scanner->StartActiveScan(
    14641507                    this, eitTransportTimeout, eitIgnoresSource);
    14651508                SetFlags(kFlagEITScannerRunning);
     1509                // This next line prevents multiple entries into this 'if' if scan has started
    14661510                eitScanStartTime = QDateTime::currentDateTime().addYears(1);
    14671511            }
    14681512        }
     1513        else if (channel && scanner &&
     1514            (QDateTime::currentDateTime() > eitScanStopTime) && !ScanStopped )
     1515        {
     1516            // Now we catch the same conditions but with eitScanStopTime exceeded
     1517            // and we haven't already been here, ie. ScanStopped is still false
    14691518
     1519            VERBOSE(VB_EIT, LOC + "Reached Active Scan Duration, ceasing active scan until next cycle. Flushing cache...");
     1520            scanner->StopActiveScan();
     1521            ScanStopped = true ;
     1522
     1523            // Now calculate the number of seconds we have to wait to complete the
     1524            // Active Scan Cycle. This way, the cycle will always be same length.
     1525            // (Apart from recordings which will extend the cycle)
     1526            // activeScanCycleTime is in minutes and activeScanDuration is in secs
     1527            ActiveCycleSleepSecs = activeScanCycleTime * 60 - activeScanDuration;
     1528            VERBOSE(VB_EIT, LOC +
     1529                QString("Calculated Active Scan wait time of %1 minutes. Active Scan will resume then.")
     1530                   .arg(ActiveCycleSleepSecs/60));
     1531
     1532            // We have to wait for ActiveCycleSleepSecs. This is easily achieved
     1533            // by doing nothing until the appropriate time is reached
     1534            eitScanStartTime = QDateTime::currentDateTime().addSecs(ActiveCycleSleepSecs);
     1535        }
     1536
    14701537        // We should be no more than a few thousand milliseconds,
    14711538        // as the end recording code does not have a trigger...
    14721539        // NOTE: If you change anything here, make sure that