Ticket #5754: activeeit-improved-031008b.diff

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