| 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."); |
| 1567 | VERBOSE(VB_EIT, LOC + "Reached Active Scan Duration, ceasing active scan until next cycle. Flushing cache..."); |
| 1568 | scanner->StopActiveScan(); |
| 1569 | ClearFlags(kFlagEITScannerRunning); |
| 1570 | ScanStopped = true ; |
| 1571 | |
| 1572 | if (HasFlags(kFlagSignalMonitorRunning)) |
| 1573 | { |
| 1574 | VERBOSE(VB_EIT, LOC + "Stopping Signal Monitor..."); |
| 1575 | MPEGStreamData *sd = NULL; |
| 1576 | if (GetDTVSignalMonitor()) |
| 1577 | sd = GetDTVSignalMonitor()->GetStreamData(); |
| 1578 | TeardownSignalMonitor(); |
| 1579 | ClearFlags(kFlagSignalMonitorRunning); |
| 1580 | |
| 1581 | // Delete StreamData if it is not in use by the recorder. |
| 1582 | MPEGStreamData *rec_sd = NULL; |
| 1583 | if (GetDTVRecorder()) |
| 1584 | rec_sd = GetDTVRecorder()->GetStreamData(); |
| 1585 | if (sd && (sd != rec_sd)) |
| 1586 | delete sd; |
| 1587 | } |
| 1588 | else |
| 1589 | VERBOSE(VB_EIT, LOC + "For Reference - Signal Monitor not running."); |
| 1590 | |
| 1591 | if (!HasFlags(kFlagRecorderRunning)) |
| 1592 | CloseChannel(); |
| 1593 | else |
| 1594 | VERBOSE(VB_EIT, LOC + "For Reference - Recording was running. Not closed channel."); |
| 1595 | |
| 1596 | // Now calculate the number of seconds we have to wait to complete the |
| 1597 | // Active Scan Cycle. This way, the cycle will always be same length. |
| 1598 | // (Apart from recordings which will extend the cycle) |
| 1599 | // activeScanCycleTime is in minutes and activeScanDuration is in secs |
| 1600 | activeCycleSleepSecs = activeScanCycleTime * 60 - activeScanDuration; |
| 1601 | VERBOSE(VB_EIT, LOC + |
| 1602 | QString("Calculated Active Scan wait time of %1 minutes. Active Scan will resume then.") |
| 1603 | .arg(activeCycleSleepSecs/60)); |
| 1604 | |
| 1605 | // We have to wait for activeCycleSleepSecs. This is easily achieved |
| 1606 | // by doing nothing until the appropriate time is reached |
| 1607 | eitScanStartTime = QDateTime::currentDateTime().addSecs(activeCycleSleepSecs); |
| 1608 | } |
| 1609 | |