Permalink
Browse files

Refs #10948. Fully randomize EIT crawl start time.

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.
  • Loading branch information...
1 parent 63c0442 commit 0e5d159c6bc98ef29a7b6bb225b43492b45c37ac @daniel-kristjansson daniel-kristjansson committed Jul 30, 2012
Showing with 22 additions and 14 deletions.
  1. +22 −14 mythtv/libs/libmythtv/tv_rec.cpp
@@ -52,7 +52,7 @@ static QString load_profile(QString,void*,RecordingInfo*,RecordingProfile&);
static int init_jobs(const RecordingInfo *rec, RecordingProfile &profile,
bool on_host, bool transcode_bfr_comm, bool on_line_comm);
static void apply_broken_dvb_driver_crc_hack(ChannelBase*, MPEGStreamData*);
-
+static int eit_start_rand(uint cardid, int eitTransportTimeout);
/** \class TVRec
* \brief This is the coordinating class of the \ref recorder_subsystem.
@@ -161,7 +161,8 @@ bool TVRec::Init(void)
gCoreContext->GetNumSetting("AutoTranscodeBeforeAutoCommflag", 0);
earlyCommFlag = gCoreContext->GetNumSetting("AutoCommflagWhileRecording", 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);
audioSampleRateDB = gCoreContext->GetNumSetting("AudioSampleRate");
overRecordSecNrml = gCoreContext->GetNumSetting("RecordOverTime");
@@ -1047,7 +1048,10 @@ void TVRec::HandleStateChange(void)
eitScanStartTime = MythDate::current();
if (scanner && (internalState == kState_None))
- eitScanStartTime = eitScanStartTime.addSecs(eitCrawlIdleStart);
+ {
+ eitScanStartTime = eitScanStartTime.addSecs(
+ eitCrawlIdleStart + eit_start_rand(cardid, eitTransportTimeout));
+ }
else
eitScanStartTime = eitScanStartTime.addYears(1);
}
@@ -1226,6 +1230,19 @@ static int no_capturecards(uint cardid)
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.
void TVRec::run(void)
{
@@ -1240,17 +1257,8 @@ void TVRec::run(void)
(dvbOpt.dvb_eitscan || get_use_eit(cardid)))
{
scanner = new EITScanner(cardid);
- uint timeout = eitCrawlIdleStart;
- // 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;
- else
- timeout += random() % eitTransportTimeout;
-
- eitScanStartTime = eitScanStartTime.addSecs(timeout);
+ eitScanStartTime = eitScanStartTime.addSecs(
+ eitCrawlIdleStart + eit_start_rand(cardid, eitTransportTimeout));
}
else
eitScanStartTime = eitScanStartTime.addYears(1);

0 comments on commit 0e5d159

Please sign in to comment.