Ticket #5754: activeeit-improved-021008.diff

File activeeit-improved-021008.diff, 7.0 KB (added by simonwalls@…, 17 years ago)

Patch for 0.21-fixes SVN 17451 to make Active EIT scan for 2 mins per mux, on a 1 hour cycle

  • 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.");
    893894        scanner->StopActiveScan();
    894895        ClearFlags(kFlagEITScannerRunning);
    895896    }
     
    13091310    SetFlags(kFlagRunMainLoop);
    13101311    ClearFlags(kFlagExitPlayer | kFlagFinishRecording);
    13111312
     1313    uint activeCycleSleepSecs;
     1314    uint activeScanNumMuxes;
     1315    QStringList activeScanChannels;
     1316
     1317    bool ScanStopped;
     1318
     1319    ScanStopped = true;
     1320
    13121321    eitScanStartTime = QDateTime::currentDateTime();   
    13131322    // check whether we should use the EITScanner in this TVRec instance
    13141323    if (CardUtil::IsEITCapable(genOpt.cardtype) &&
     
    14441453            ClearFlags(kFlagExitPlayer);
    14451454        }
    14461455
     1456
     1457        // EIT Scanner handling
    14471458        if (channel && scanner &&
    14481459            QDateTime::currentDateTime() > eitScanStartTime)
    14491460        {
     
    14581469                        "for all sources on this card.");
    14591470                eitScanStartTime = eitScanStartTime.addYears(1);
    14601471            }
     1472            // Things are good to start Active Scan
     1473            // We now know that currentDateTime > eitScanStartTime but we don't know if
     1474            // we have exceeded the eitScanStopTime
    14611475            else
    14621476            {
     1477                // Obtain the number of multiplexes by database query
     1478                MSqlQuery query(MSqlQuery::InitCon());
     1479                query.prepare(
     1480                "SELECT channum, MIN(chanid) "
     1481                "FROM channel, cardinput, capturecard, videosource "
     1482                "WHERE cardinput.sourceid   = channel.sourceid AND "
     1483                "      videosource.sourceid = channel.sourceid AND "
     1484                "      capturecard.cardid   = cardinput.cardid AND "
     1485                "      channel.mplexid        IS NOT NULL      AND "
     1486                "      useonairguide        = 1                AND "
     1487                "      useeit               = 1                AND "
     1488                "      channum             != ''               AND "
     1489                "      cardinput.cardid     = :CARDID "
     1490                "GROUP BY mplexid "
     1491                "ORDER BY cardinput.sourceid, mplexid, "
     1492                "         atsc_major_chan, atsc_minor_chan ");
     1493                query.bindValue(":CARDID", GetCaptureCardNum());
     1494
     1495                if (!query.exec() || !query.isActive())
     1496                {
     1497                MythContext::DBError("TVRec::StartActiveScan", query);
     1498                VERBOSE(VB_EIT, LOC + "Database query for number of multiplexes failed - assuming 1.");
     1499                activeScanNumMuxes = 1;
     1500                }
     1501                else
     1502                {
     1503                    while (query.next())
     1504                    activeScanChannels.push_back(query.value(0).toString());
     1505
     1506                    activeScanNumMuxes = activeScanChannels.size();
     1507
     1508                    VERBOSE(VB_EIT, LOC +
     1509                    QString("Database query returns %1 DVB multiplexes.")
     1510                        .arg(activeScanNumMuxes));
     1511                }
     1512
     1513                // Following are control variables for the improved active scan
     1514                // It stops after a defined period and closes the tuner card,
     1515                // the idea is to see if it saves some power. There is usually no need
     1516                // to scan for EIT data continuously.
     1517       
     1518                // Set the repeat rate of the active scan to 60 minutes
     1519                activeScanCycleTime = 60;
     1520                // It would be wise to schedule an EIT scan shortly before a recording,
     1521                // to check for re-schedules.
     1522       
     1523                // Set the duration of the active scan to 2 minutes per mux per hour
     1524                // Configuration Note:
     1525                // If using less than 5 minutes per mux, set "EIT Transport Timeout"
     1526                // in mythv-setup to a figure which ensures all muxes will be read,
     1527                // i.e. equal to or less than 2 minutes.
     1528                activeScanDuration = activeScanNumMuxes * 2 * 60;
     1529       
     1530                eitScanStopTime = eitScanStartTime
     1531                        .addSecs(activeScanDuration);
     1532       
     1533                // Log some information about the settings
     1534                VERBOSE(VB_EIT, LOC +
     1535                QString("Improved Active Scan cycle time %1 minutes")
     1536                .arg(activeScanCycleTime));
     1537                VERBOSE(VB_EIT, LOC +
     1538                QString("Improved Active Scan Duration   %1 minutes")
     1539                .arg(activeScanDuration/60));
     1540       
     1541                ScanStopped = false ;
     1542
     1543                // Active Scan is restarted after a recording uses the tuner, so the
     1544                // relative position of the 'window' moves as recordings are made.
     1545                // If settings give poor programme guide population, they can be changed
     1546                // Ideally there could be a control in mythtv-setup where active scan is enabled
     1547
     1548                VERBOSE(VB_EIT, LOC + "EIT Active Scan being (re)started.");
    14631549                scanner->StartActiveScan(
    14641550                    this, eitTransportTimeout, eitIgnoresSource);
    14651551                SetFlags(kFlagEITScannerRunning);
     1552                // This next line prevents multiple entries into this 'if' if scan has started
    14661553                eitScanStartTime = QDateTime::currentDateTime().addYears(1);
    14671554            }
    14681555        }
     1556        else if (channel && scanner &&
     1557            (QDateTime::currentDateTime() > eitScanStopTime) && !ScanStopped )
     1558        {
     1559            // Now we catch the same conditions but with eitScanStopTime exceeded
     1560            // and we haven't already been here, ie. ScanStopped is still false
    14691561
     1562            VERBOSE(VB_EIT, LOC + "Reached Active Scan Duration, ceasing active scan until next cycle. Flushing cache...");
     1563            scanner->StopActiveScan();
     1564            ScanStopped = true ;
     1565            CloseChannel();
     1566
     1567            // Now calculate the number of seconds we have to wait to complete the
     1568            // Active Scan Cycle. This way, the cycle will always be same length.
     1569            // (Apart from recordings which will extend the cycle)
     1570            // activeScanCycleTime is in minutes and activeScanDuration is in secs
     1571            activeCycleSleepSecs = activeScanCycleTime * 60 - activeScanDuration;
     1572            VERBOSE(VB_EIT, LOC +
     1573                QString("Calculated Active Scan wait time of %1 minutes. Active Scan will resume then.")
     1574                   .arg(activeCycleSleepSecs/60));
     1575
     1576            // We have to wait for activeCycleSleepSecs. This is easily achieved
     1577            // by doing nothing until the appropriate time is reached
     1578            eitScanStartTime = QDateTime::currentDateTime().addSecs(activeCycleSleepSecs);
     1579        }
     1580
    14701581        // We should be no more than a few thousand milliseconds,
    14711582        // as the end recording code does not have a trigger...
    14721583        // NOTE: If you change anything here, make sure that