Ticket #5754: activeeit-improved-031008.diff

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