Skip to content

Commit

Permalink
Use recording rule priority as the primary scheduling priority.
Browse files Browse the repository at this point in the history
Previously, priorities like input and channel were added to the
recording rule priority to calculate a single priority used in
scheduling.  Now, the recording rule priority is used by itself as the
primary priority.  The other priorities are summed together and used
as a secondary priority.

What this means is all programs matching a given recording rule,
including those on less desirable inputs and channels, are scheduled
before any programs matching lower priority rules.  This is more in
line with the way most users assume and expect the scheduler to work
and still allows the ancillary priorities to influence the scheduling
of specific showings.

Note: this is essentially a reintroduction of the "ComplexPriority"
scheme.
  • Loading branch information
gigem committed Jan 30, 2013
1 parent 4aabde2 commit 5587501
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 17 deletions.
9 changes: 8 additions & 1 deletion mythtv/libs/libmythtv/recordinginfo.cpp
Expand Up @@ -103,7 +103,8 @@ RecordingInfo::RecordingInfo(
uint _subtitleType,
uint _videoproperties,
uint _audioproperties,
bool _future) :
bool _future,
int _schedorder) :
ProgramInfo(
_title, _subtitle, _description, _season, _episode,
_category, _chanid, _chanstr, _chansign, _channame,
Expand All @@ -113,6 +114,7 @@ RecordingInfo::RecordingInfo(
oldrecstatus(_oldrecstatus),
savedrecstatus(rsUnknown),
future(_future),
schedorder(_schedorder),
desiredrecstartts(_startts),
desiredrecendts(_endts),
record(NULL)
Expand Down Expand Up @@ -211,6 +213,7 @@ RecordingInfo::RecordingInfo(
oldrecstatus(rsUnknown),
savedrecstatus(rsUnknown),
future(false),
schedorder(0),
desiredrecstartts(_startts),
desiredrecendts(_endts),
record(NULL)
Expand Down Expand Up @@ -244,6 +247,7 @@ RecordingInfo::RecordingInfo(
oldrecstatus(rsUnknown),
savedrecstatus(rsUnknown),
future(false),
schedorder(0),
desiredrecstartts(),
desiredrecendts(),
record(NULL)
Expand Down Expand Up @@ -394,6 +398,7 @@ void RecordingInfo::clone(const RecordingInfo &other,
oldrecstatus = other.oldrecstatus;
savedrecstatus = other.savedrecstatus;
future = other.future;
schedorder = other.schedorder;
desiredrecstartts = other.desiredrecstartts;
desiredrecendts = other.desiredrecendts;
}
Expand All @@ -420,6 +425,7 @@ void RecordingInfo::clone(const ProgramInfo &other,
oldrecstatus = rsUnknown;
savedrecstatus = rsUnknown;
future = false;
schedorder = 0;
desiredrecstartts = QDateTime();
desiredrecendts = QDateTime();
}
Expand All @@ -434,6 +440,7 @@ void RecordingInfo::clear(void)
oldrecstatus = rsUnknown;
savedrecstatus = rsUnknown;
future = false;
schedorder = 0;
desiredrecstartts = QDateTime();
desiredrecendts = QDateTime();
}
Expand Down
9 changes: 8 additions & 1 deletion mythtv/libs/libmythtv/recordinginfo.h
Expand Up @@ -36,6 +36,7 @@ class MTV_PUBLIC RecordingInfo : public ProgramInfo
oldrecstatus(rsUnknown),
savedrecstatus(rsUnknown),
future(false),
schedorder(0),
desiredrecstartts(),
desiredrecendts(),
record(NULL) {}
Expand All @@ -44,6 +45,7 @@ class MTV_PUBLIC RecordingInfo : public ProgramInfo
oldrecstatus(other.oldrecstatus),
savedrecstatus(other.savedrecstatus),
future(other.future),
schedorder(other.schedorder),
desiredrecstartts(other.desiredrecstartts),
desiredrecendts(other.desiredrecendts),
record(NULL) {}
Expand All @@ -52,6 +54,7 @@ class MTV_PUBLIC RecordingInfo : public ProgramInfo
oldrecstatus(rsUnknown),
savedrecstatus(rsUnknown),
future(false),
schedorder(0),
desiredrecstartts(startts),
desiredrecendts(endts),
record(NULL) {}
Expand All @@ -60,6 +63,7 @@ class MTV_PUBLIC RecordingInfo : public ProgramInfo
oldrecstatus(rsUnknown),
savedrecstatus(rsUnknown),
future(false),
schedorder(0),
desiredrecstartts(startts),
desiredrecendts(endts),
record(NULL) {}
Expand All @@ -69,6 +73,7 @@ class MTV_PUBLIC RecordingInfo : public ProgramInfo
oldrecstatus(rsUnknown),
savedrecstatus(rsUnknown),
future(false),
schedorder(0),
desiredrecstartts(startts),
desiredrecendts(endts),
record(NULL) {}
Expand Down Expand Up @@ -134,7 +139,8 @@ class MTV_PUBLIC RecordingInfo : public ProgramInfo
uint subtitleType,
uint videoproperties,
uint audioproperties,
bool future);
bool future,
int schedorder);

/// Create RecordingInfo from 'record'+'channel' tables,
/// user in scheduler.cpp @ ~ 3566 & ~ 3643
Expand Down Expand Up @@ -253,6 +259,7 @@ class MTV_PUBLIC RecordingInfo : public ProgramInfo
RecStatusType oldrecstatus;
RecStatusType savedrecstatus;
bool future;
int schedorder;
QDateTime desiredrecstartts;
QDateTime desiredrecendts;

Expand Down
77 changes: 62 additions & 15 deletions mythtv/programs/mythbackend/scheduler.cpp
Expand Up @@ -323,6 +323,9 @@ static bool comp_priority(RecordingInfo *a, RecordingInfo *b)
if (a->GetRecordingPriority() != b->GetRecordingPriority())
return a->GetRecordingPriority() > b->GetRecordingPriority();

if (a->GetRecordingPriority2() != b->GetRecordingPriority2())
return a->GetRecordingPriority2() > b->GetRecordingPriority2();

QDateTime pasttime = MythDate::current().addSecs(-30);
int apast = (a->GetRecordingStartTime() < pasttime &&
!a->IsReactivated());
Expand All @@ -346,15 +349,58 @@ static bool comp_priority(RecordingInfo *a, RecordingInfo *b)
return a->GetRecordingStartTime() < b->GetRecordingStartTime();
}

if (a->GetRecordingPriority2() != b->GetRecordingPriority2())
return a->GetRecordingPriority2() < b->GetRecordingPriority2();
if (a->schedorder != b->schedorder)
return a->schedorder < b->schedorder;

if (a->GetInputID() != b->GetInputID())
return a->GetInputID() < b->GetInputID();

return a->GetRecordingRuleID() < b->GetRecordingRuleID();
}

static bool comp_retry(RecordingInfo *a, RecordingInfo *b)
{
int arec = (a->GetRecordingStatus() != rsRecording &&
a->GetRecordingStatus() != rsTuning);
int brec = (b->GetRecordingStatus() != rsRecording &&
b->GetRecordingStatus() != rsTuning);

if (arec != brec)
return arec < brec;

if (a->GetRecordingPriority() != b->GetRecordingPriority())
return a->GetRecordingPriority() > b->GetRecordingPriority();

if (a->GetRecordingPriority2() != b->GetRecordingPriority2())
return a->GetRecordingPriority2() > b->GetRecordingPriority2();

QDateTime pasttime = MythDate::current().addSecs(-30);
int apast = (a->GetRecordingStartTime() < pasttime &&
!a->IsReactivated());
int bpast = (b->GetRecordingStartTime() < pasttime &&
!b->IsReactivated());

if (apast != bpast)
return apast < bpast;

int aprec = RecTypePrecedence(a->GetRecordingRuleType());
int bprec = RecTypePrecedence(b->GetRecordingRuleType());

if (aprec != bprec)
return aprec < bprec;

if (a->GetRecordingStartTime() != b->GetRecordingStartTime())
return a->GetRecordingStartTime() > b->GetRecordingStartTime();

if (a->schedorder != b->schedorder)
return a->schedorder > b->schedorder;

if (a->GetInputID() != b->GetInputID())
return a->GetInputID() > b->GetInputID();

return a->GetRecordingRuleID() < b->GetRecordingRuleID();
}

bool Scheduler::FillRecordList(void)
{
schedTime = MythDate::current();
Expand Down Expand Up @@ -1139,7 +1185,9 @@ bool Scheduler::TryAnotherShowing(RecordingInfo *p, bool samePriority,
continue;

if (samePriority &&
(q->GetRecordingPriority() < p->GetRecordingPriority()))
(q->GetRecordingPriority() < p->GetRecordingPriority() ||
(q->GetRecordingPriority() == p->GetRecordingPriority() &&
q->GetRecordingPriority2() < p->GetRecordingPriority2())))
{
continue;
}
Expand Down Expand Up @@ -1255,7 +1303,7 @@ void Scheduler::SchedNewRecords(void)
}
else
{
retrylist.push_front(p);
retrylist.push_back(p);
PrintRec(p, " #");
PrintRec(conflict, " !");
}
Expand All @@ -1265,6 +1313,7 @@ void Scheduler::SchedNewRecords(void)
++i;
if (i == worklist.end() || lastpri != (*i)->GetRecordingPriority())
{
SORT_RECLIST(retrylist, comp_retry);
MoveHigherRecords();
retrylist.clear();
}
Expand Down Expand Up @@ -1313,9 +1362,6 @@ void Scheduler::MoveHigherRecords(bool livetv)

PrintRec(p, " ?");

if (!livetv && TryAnotherShowing(p, false))
continue;

BackupRecStatus();
p->SetRecordingStatus(rsWillRecord);
if (!livetv)
Expand Down Expand Up @@ -1343,6 +1389,7 @@ void Scheduler::MoveHigherRecords(bool livetv)
void Scheduler::PruneRedundants(void)
{
RecordingInfo *lastp = NULL;
int lastrecpri2 = 0;

RecIter i = worklist.begin();
while (i != worklist.end())
Expand Down Expand Up @@ -1394,6 +1441,7 @@ void Scheduler::PruneRedundants(void)
!lastp->IsSameTimeslot(*p))
{
lastp = p;
lastrecpri2 = lastp->GetRecordingPriority2();
lastp->SetRecordingPriority2(0);
++i;
}
Expand All @@ -1402,11 +1450,11 @@ void Scheduler::PruneRedundants(void)
// Flag lower priority showings that will recorded so we
// can warn the user about them
if (lastp->GetRecordingStatus() == rsWillRecord &&
p->GetRecordingPriority() >
lastp->GetRecordingPriority() - lastp->GetRecordingPriority2())
p->GetRecordingPriority2() >
lastrecpri2 - lastp->GetRecordingPriority2())
{
lastp->SetRecordingPriority2(
lastp->GetRecordingPriority() - p->GetRecordingPriority());
lastrecpri2 - p->GetRecordingPriority2());
}
delete p;
*(i++) = NULL;
Expand Down Expand Up @@ -4073,8 +4121,8 @@ void Scheduler::AddNewRecords(void)
result.value(40).toUInt(),//subtitleType
result.value(39).toUInt(),//videoproperties
result.value(41).toUInt(),//audioproperties
result.value(46).toInt());//future
p->SetRecordingPriority2(result.value(47).toInt()); // schedorder
result.value(46).toInt(),//future
result.value(47).toInt());//schedorder

if (!p->future && !p->IsReactivated() &&
p->oldrecstatus != rsAborted &&
Expand All @@ -4083,8 +4131,7 @@ void Scheduler::AddNewRecords(void)
p->SetRecordingStatus(p->oldrecstatus);
}

p->SetRecordingPriority(p->GetRecordingPriority() +
result.value(51).toInt());
p->SetRecordingPriority2(result.value(51).toInt());

// Check to see if the program is currently recording and if
// the end time was changed. Ideally, checking for a new end
Expand Down Expand Up @@ -4121,7 +4168,7 @@ void Scheduler::AddNewRecords(void)
RecStatusType newrecstatus = rsUnknown;
// Check for rsOffLine
if ((doRun || specsched) &&
(!cardMap.contains(p->GetCardID()) || !p->GetRecordingPriority2()))
(!cardMap.contains(p->GetCardID()) || !p->schedorder))
newrecstatus = rsOffLine;

// Check for rsTooManyRecordings
Expand Down

0 comments on commit 5587501

Please sign in to comment.