Skip to content

Commit

Permalink
Fixes REC_PENDING and wakeup handling handling.
Browse files Browse the repository at this point in the history
I accidentally broke this with commit [9b22460] in master.

This also fixes a pre-existing memory leak in the REC_PENDING handling.
  • Loading branch information
daniel-kristjansson committed Jul 16, 2011
1 parent 3d8bac5 commit 6172413
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
36 changes: 30 additions & 6 deletions mythtv/programs/mythbackend/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1812,6 +1812,8 @@ void Scheduler::run(void)
{
int sched_sleep = (secs_to_next - schedRunTime - 1) * 1000;
sched_sleep = min(sched_sleep, maxSleep);
if (secs_to_next < prerollseconds + (maxSleep/1000))
sched_sleep = min(sched_sleep, 5000);
LOG(VB_SCHEDULE, LOG_INFO,
QString("sleeping for %1 ms (interuptable)")
.arg(sched_sleep));
Expand Down Expand Up @@ -1892,7 +1894,7 @@ void Scheduler::run(void)

/// Wake any slave backends that need waking
curtime = QDateTime::currentDateTime();
for (RecIter it = startIter; it != reclist.end() && !done; ++it)
for (RecIter it = startIter; it != reclist.end(); ++it)
{
int secsleft = curtime.secsTo((*it)->GetRecordingStartTime());
if ((secsleft - prerollseconds) <= wakeThreshold)
Expand Down Expand Up @@ -2146,8 +2148,6 @@ bool Scheduler::HandleRunSchedulerStartup(
void Scheduler::HandleWakeSlave(RecordingInfo &ri, int prerollseconds)
{
static const int sysEventSecs[5] = { 120, 90, 60, 30, 0 };
QString sysEventKey;
QList<QString> sysEvents[4];

QDateTime curtime = QDateTime::currentDateTime();
QDateTime nextrectime = ri.GetRecordingStartTime();
Expand All @@ -2157,8 +2157,7 @@ void Scheduler::HandleWakeSlave(RecordingInfo &ri, int prerollseconds)
if (tvit == m_tvList->end())
return;

sysEventKey = QString("%1:%2").arg(ri.GetChanID())
.arg(nextrectime.toString(Qt::ISODate));
QString sysEventKey = ri.MakeUniqueKey();

int i = 0;
bool pendingEventSent = false;
Expand All @@ -2173,12 +2172,37 @@ void Scheduler::HandleWakeSlave(RecordingInfo &ri, int prerollseconds)
QString("REC_PENDING SECS %1").arg(secsleft), &ri);
}

sysEvents[i].append(sysEventKey);
sysEvents[i].insert(sysEventKey);
pendingEventSent = true;
}
i++;
}

// cleanup old sysEvents once in a while
QSet<QString> keys;
for (i = 0; sysEventSecs[i] != 0; i++)
{
if (sysEvents[i].size() < 20)
continue;

if (keys.empty())
{
RecConstIter it = reclist.begin();
for ( ; it != reclist.end(); ++it)
keys.insert((*it)->MakeUniqueKey());
keys.insert("something");
}

QSet<QString>::iterator sit = sysEvents[i].begin();
while (sit != sysEvents[i].end())
{
if (!keys.contains(*sit))
sit = sysEvents[i].erase(sit);
else
++sit;
}
}

EncoderLink *nexttv = *tvit;

if (nexttv->IsAsleep() && !nexttv->IsWaking())
Expand Down
3 changes: 3 additions & 0 deletions mythtv/programs/mythbackend/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ using namespace std;
#include <QThread>
#include <QMutex>
#include <QMap>
#include <QSet>

// MythTV headers
#include "recordinginfo.h"
Expand Down Expand Up @@ -207,6 +208,8 @@ class Scheduler : public QThread

int error;

QSet<QString> sysEvents[4];

// Try to avoid LiveTV sessions until this time
QDateTime livetvTime;
int livetvpriority;
Expand Down

0 comments on commit 6172413

Please sign in to comment.