Skip to content

Commit

Permalink
Refs #10948. Fully randomize EIT crawl start time.
Browse files Browse the repository at this point in the history
The deadlocks we've been seeing here should be fixed now, but they
should have been rare to begin with due to randomization of the
EIT Scanning start time. But they were occurring at fairly high
frequency. It turns out we were not applying enough randomness when
there were multiple cards and we were also losing randomness after
the first recording on a tuner finished and we reset the clock.
(cherry picked from commit 0e5d159)
  • Loading branch information
daniel-kristjansson authored and stuartm committed Oct 1, 2012
1 parent eb52783 commit 957c7e2
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions mythtv/libs/libmythtv/tv_rec.cpp
Expand Up @@ -52,7 +52,7 @@ static QString load_profile(QString,void*,RecordingInfo*,RecordingProfile&);
static int init_jobs(const RecordingInfo *rec, RecordingProfile &profile, static int init_jobs(const RecordingInfo *rec, RecordingProfile &profile,
bool on_host, bool transcode_bfr_comm, bool on_line_comm); bool on_host, bool transcode_bfr_comm, bool on_line_comm);
static void apply_broken_dvb_driver_crc_hack(ChannelBase*, MPEGStreamData*); static void apply_broken_dvb_driver_crc_hack(ChannelBase*, MPEGStreamData*);

static int eit_start_rand(uint cardid, int eitTransportTimeout);


/** \class TVRec /** \class TVRec
* \brief This is the coordinating class of the \ref recorder_subsystem. * \brief This is the coordinating class of the \ref recorder_subsystem.
Expand Down Expand Up @@ -161,7 +161,8 @@ bool TVRec::Init(void)
gCoreContext->GetNumSetting("AutoTranscodeBeforeAutoCommflag", 0); gCoreContext->GetNumSetting("AutoTranscodeBeforeAutoCommflag", 0);
earlyCommFlag = gCoreContext->GetNumSetting("AutoCommflagWhileRecording", 0); earlyCommFlag = gCoreContext->GetNumSetting("AutoCommflagWhileRecording", 0);
runJobOnHostOnly = gCoreContext->GetNumSetting("JobsRunOnRecordHost", 0); runJobOnHostOnly = gCoreContext->GetNumSetting("JobsRunOnRecordHost", 0);
eitTransportTimeout=gCoreContext->GetNumSetting("EITTransportTimeout", 5) * 60; eitTransportTimeout =
max(gCoreContext->GetNumSetting("EITTransportTimeout", 5) * 60, 6);
eitCrawlIdleStart = gCoreContext->GetNumSetting("EITCrawIdleStart", 60); eitCrawlIdleStart = gCoreContext->GetNumSetting("EITCrawIdleStart", 60);
audioSampleRateDB = gCoreContext->GetNumSetting("AudioSampleRate"); audioSampleRateDB = gCoreContext->GetNumSetting("AudioSampleRate");
overRecordSecNrml = gCoreContext->GetNumSetting("RecordOverTime"); overRecordSecNrml = gCoreContext->GetNumSetting("RecordOverTime");
Expand Down Expand Up @@ -1034,7 +1035,10 @@ void TVRec::HandleStateChange(void)


eitScanStartTime = QDateTime::currentDateTime(); eitScanStartTime = QDateTime::currentDateTime();
if (scanner && (internalState == kState_None)) if (scanner && (internalState == kState_None))
eitScanStartTime = eitScanStartTime.addSecs(eitCrawlIdleStart); {
eitScanStartTime = eitScanStartTime.addSecs(
eitCrawlIdleStart + eit_start_rand(cardid, eitTransportTimeout));
}
else else
eitScanStartTime = eitScanStartTime.addYears(1); eitScanStartTime = eitScanStartTime.addYears(1);
} }
Expand Down Expand Up @@ -1213,6 +1217,19 @@ static int no_capturecards(uint cardid)
return -1; return -1;
} }


static int eit_start_rand(uint cardid, int eitTransportTimeout)
{
// randomize start time a bit
int timeout = random() % (eitTransportTimeout / 3);
// get the number of capture cards and the position of the current card
// to distribute the the scan start evenly over eitTransportTimeout
int card_pos = no_capturecards(cardid);
int no_cards = no_capturecards(0);
if (no_cards > 0 && card_pos >= 0)
timeout += eitTransportTimeout * card_pos / no_cards;
return timeout;
}

/// \brief Event handling method, contains event loop. /// \brief Event handling method, contains event loop.
void TVRec::run(void) void TVRec::run(void)
{ {
Expand All @@ -1227,17 +1244,8 @@ void TVRec::run(void)
(dvbOpt.dvb_eitscan || get_use_eit(cardid))) (dvbOpt.dvb_eitscan || get_use_eit(cardid)))
{ {
scanner = new EITScanner(cardid); scanner = new EITScanner(cardid);
uint timeout = eitCrawlIdleStart; eitScanStartTime = eitScanStartTime.addSecs(
// get the number of capture cards and the position of the current card eitCrawlIdleStart + eit_start_rand(cardid, eitTransportTimeout));
// to distribute the the scan start evenly over eitTransportTimeout
int card_pos = no_capturecards(cardid);
int no_cards = no_capturecards(0);
if (no_cards > 0 && card_pos >= 0)
timeout += eitTransportTimeout * card_pos / no_cards;
else
timeout += random() % eitTransportTimeout;

eitScanStartTime = eitScanStartTime.addSecs(timeout);
} }
else else
eitScanStartTime = eitScanStartTime.addYears(1); eitScanStartTime = eitScanStartTime.addYears(1);
Expand Down

0 comments on commit 957c7e2

Please sign in to comment.