Skip to content

Commit

Permalink
Make EITScanner thread only be started when needed
Browse files Browse the repository at this point in the history
Currently, an EITScanner thread is started for every source that is capable of
doing EIT scans (DVB/HDHomerun) even if EIT is disabled for that source.  This
means we can have several pointless threads that will do us no good.  Rather
than this, let's only start the thread on capable sources that have EIT
enabled.

Also tweaked the conditional use of the scanner to make sure the scanner
exists to preclude possible NULL pointer crashes.  Moved the check for scanner
first to optimize the execution slightly in the non-EIT case.
  • Loading branch information
Beirdo committed Jun 28, 2011
1 parent ef39225 commit 5e67f94
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions mythtv/libs/libmythtv/tv_rec.cpp
Expand Up @@ -942,7 +942,7 @@ void TVRec::HandleStateChange(void)

// Make sure EIT scan is stopped before any tuning,
// to avoid race condition with it's tuning requests.
if (HasFlags(kFlagEITScannerRunning))
if (scanner && HasFlags(kFlagEITScannerRunning))
{
scanner->StopActiveScan();
ClearFlags(kFlagEITScannerRunning);
Expand Down Expand Up @@ -987,8 +987,7 @@ void TVRec::HandleStateChange(void)
changeState = false;

eitScanStartTime = QDateTime::currentDateTime();
if ((internalState == kState_None) &&
scanner)
if (scanner && (internalState == kState_None))
eitScanStartTime = eitScanStartTime.addSecs(eitCrawlIdleStart);
else
eitScanStartTime = eitScanStartTime.addYears(1);
Expand Down Expand Up @@ -1398,7 +1397,8 @@ void TVRec::RunTV(void)
eitScanStartTime = QDateTime::currentDateTime();
// check whether we should use the EITScanner in this TVRec instance
if (CardUtil::IsEITCapable(genOpt.cardtype) &&
(!GetDVBChannel() || GetDVBChannel()->IsMaster()))
(!GetDTVChannel() || GetDTVChannel()->IsMaster()) &&
(dvbOpt.dvb_eitscan && get_use_eit(cardid)))
{
scanner = new EITScanner(cardid);
uint timeout = eitCrawlIdleStart;
Expand Down Expand Up @@ -1560,7 +1560,7 @@ void TVRec::RunTV(void)
ClearFlags(kFlagExitPlayer);
}

if (channel && scanner &&
if (scanner && channel &&
QDateTime::currentDateTime() > eitScanStartTime)
{
if (!dvbOpt.dvb_eitscan)
Expand Down Expand Up @@ -3637,7 +3637,8 @@ void TVRec::TuningShutdowns(const TuningRequest &request)
QString channum, inputname;
uint newCardID = TuningCheckForHWChange(request, channum, inputname);

if (!(request.flags & kFlagEITScan) && HasFlags(kFlagEITScannerRunning))
if (scanner && !(request.flags & kFlagEITScan) &&
HasFlags(kFlagEITScannerRunning))
{
scanner->StopActiveScan();
ClearFlags(kFlagEITScannerRunning);
Expand Down Expand Up @@ -3908,7 +3909,7 @@ MPEGStreamData *TVRec::TuningSignalCheck(void)
if (curRecording)
curRecording->SetRecordingStatus(rsFailed);

if (HasFlags(kFlagEITScannerRunning))
if (scanner && HasFlags(kFlagEITScannerRunning))
{
scanner->StopActiveScan();
ClearFlags(kFlagEITScannerRunning);
Expand Down

0 comments on commit 5e67f94

Please sign in to comment.