Skip to content

Commit

Permalink
Optimize EIT reschedules by limiting them to changed schedule parts.
Browse files Browse the repository at this point in the history
Only reschedule all transports if we've handled EIT schedule other.
Only reschedule up to max(starttime).
  • Loading branch information
dekarl committed Jan 22, 2013
1 parent b7bab70 commit c99b296
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 35 deletions.
30 changes: 23 additions & 7 deletions mythtv/libs/libmythtv/eithelper.cpp
Expand Up @@ -17,9 +17,11 @@ using namespace std;
#include "premieretables.h"
#include "dishdescriptors.h"
#include "premieredescriptors.h"
#include "channelutil.h" // for ChannelUtil
#include "mythdate.h"
#include "programdata.h"
#include "programinfo.h" // for subtitle types and audio and video properties
#include "scheduledrecording.h" // for ScheduledRecording
#include "compat.h" // for gmtime_r on windows.

const uint EITHelper::kChunkSize = 20;
Expand All @@ -38,7 +40,8 @@ static void init_fixup(QMap<uint64_t,uint> &fix);
EITHelper::EITHelper() :
eitfixup(new EITFixUp()),
gps_offset(-1 * GPS_LEAP_SECONDS),
sourceid(0), channelid(0)
sourceid(0), channelid(0),
maxStarttime(QDateTime()), seenEITother(false)
{
init_fixup(fixup);
}
Expand Down Expand Up @@ -80,6 +83,7 @@ uint EITHelper::ProcessEvents(void)
eitfixup->Fix(*event);

insertCount += event->UpdateDB(query, 1000);
maxStarttime = max (maxStarttime, event->starttime);

delete event;
eitList_lock.lock();
Expand Down Expand Up @@ -135,12 +139,6 @@ void EITHelper::SetSourceID(uint _sourceid)
sourceid = _sourceid;
}

uint EITHelper::GetSourceID(void)
{
QMutexLocker locker(&eitList_lock);
return sourceid;
}

void EITHelper::SetChannelID(uint _channelid)
{
QMutexLocker locker(&eitList_lock);
Expand Down Expand Up @@ -320,6 +318,11 @@ void EITHelper::AddEIT(const DVBEventInformationTable *eit)
{
// EITo(ther)
chanid = GetChanID(eit->ServiceID(), eit->OriginalNetworkID(), eit->TSID());
// do not reschedule if its only present+following
if (eit->TableID() != TableID::PF_EITo)
{
seenEITother = true;
}
}
if (!chanid)
return;
Expand Down Expand Up @@ -1104,3 +1107,16 @@ static void init_fixup(QMap<uint64_t,uint> &fix)
fix[ 1100LL << 32 | 1 << 16 | 8710 ] = // NRJ 12
EITFixUp::kEFixForceISO8859_15;
}

/** \fn EITHelper::RescheduleRecordings(void)
* \brief Tells scheduler about programming changes.
*
*/
void EITHelper::RescheduleRecordings(void)
{
ScheduledRecording::RescheduleMatch(
0, sourceid, seenEITother ? 0 : ChannelUtil::GetMplexID(channelid),
maxStarttime, "EITScanner");
seenEITother = false;
maxStarttime = QDateTime();
}
12 changes: 9 additions & 3 deletions mythtv/libs/libmythtv/eithelper.h
Expand Up @@ -6,6 +6,7 @@
#include <stdint.h>

// Qt includes
#include <QDateTime>
#include <QMap>
#include <QMutex>
#include <QObject>
Expand Down Expand Up @@ -71,7 +72,7 @@ class EITHelper
void SetFixup(uint atsc_major, uint atsc_minor, uint eitfixup);
void SetLanguagePreferences(const QStringList &langPref);
void SetSourceID(uint _sourceid);
uint GetSourceID(void);
void RescheduleRecordings(void);

#ifdef USING_BACKEND
void AddEIT(uint atsc_major, uint atsc_minor,
Expand Down Expand Up @@ -111,8 +112,13 @@ class EITHelper
static EITCache *eitcache;

int gps_offset;
uint sourceid;
uint channelid;

/* carry some values to optimize channel lookup and reschedules */
uint sourceid; ///< id of the video source
uint channelid; ///< id of the channel
QDateTime maxStarttime; ///< latest starttime of changed events
bool seenEITother; ///< if false we only reschedule the active mplex

QMap<uint64_t,uint> fixup;
ATSCSRCToEvents incomplete_events;
ATSCSRCToETTs unmatched_etts;
Expand Down
31 changes: 7 additions & 24 deletions mythtv/libs/libmythtv/eitscanner.cpp
Expand Up @@ -29,10 +29,6 @@
*
*/

QMutex EITScanner::resched_lock;
QDateTime EITScanner::resched_next_time = MythDate::current();
const uint EITScanner::kMinRescheduleInterval = 150;

EITScanner::EITScanner(uint _cardnum)
: channel(NULL), eitSource(NULL),
eitHelper(new EITHelper()), eventThread(new MThread("EIT", this)),
Expand Down Expand Up @@ -107,9 +103,10 @@ void EITScanner::run(void)
t.start();
}

// If there have been any new events and we haven't
// seen any in a while, tell scheduler to run.
// But only for passive scan which can sit hours on the same channel.
// Tell the scheduler to run if
// we are in passive scan
// and there have been updated events since the last scheduler run
// but not in the last 60 seconds
if (!activeScan && eitCount && (t.elapsed() > 60 * 1000))
{
LOG(VB_EIT, LOG_INFO,
Expand Down Expand Up @@ -183,23 +180,9 @@ void EITScanner::run(void)
* This implements some very basic rate limiting. If a call is made
* to this within kMinRescheduleInterval of the last call it is ignored.
*/
const void EITScanner::RescheduleRecordings(void)
void EITScanner::RescheduleRecordings(void)
{
if (!resched_lock.tryLock())
return;

if (resched_next_time > MythDate::current())
{
LOG(VB_EIT, LOG_INFO, LOC + "Rate limiting reschedules..");
resched_lock.unlock();
return;
}

resched_next_time =
MythDate::current().addSecs(kMinRescheduleInterval);
resched_lock.unlock();

ScheduledRecording::RescheduleMatch(0, eitHelper->GetSourceID(), 0, QDateTime(), "EITScanner");
eitHelper->RescheduleRecordings();
}

/** \fn EITScanner::StartPassiveScan(ChannelBase*, EITSource*, bool)
Expand All @@ -211,7 +194,6 @@ void EITScanner::StartPassiveScan(ChannelBase *_channel,
{
QMutexLocker locker(&lock);

//uint sourceid = _channel->GetCurrentSourceID(); // FIXME why is this 0?
eitSource = _eitSource;
channel = _channel;

Expand All @@ -238,6 +220,7 @@ void EITScanner::StopPassiveScan(void)
channel = NULL;

eitHelper->WriteEITCache();
eitHelper->SetChannelID(0);
eitHelper->SetSourceID(0);
}

Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/eitscanner.h
Expand Up @@ -46,7 +46,7 @@ class EITScanner : public QRunnable
private:
void TeardownAll(void);
static void *SpawnEventLoop(void*);
const void RescheduleRecordings(void);
void RescheduleRecordings(void);

QMutex lock;
ChannelBase *channel;
Expand Down

0 comments on commit c99b296

Please sign in to comment.