| 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."); |
| 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 | |