Skip to content

Commit

Permalink
Don't create an additional thread for media playback.
Browse files Browse the repository at this point in the history
After the threading changes prior to the 0.24 release, this extra thread
serves no purpose and is slowing down both startup and exiting of video
playback. It may also have an impact on sluggish keypress responses
reported by several people.

There are various cleanups that can now be made in the TV class.
  • Loading branch information
Mark Kendall committed Dec 12, 2010
1 parent 8155c43 commit 7b4f3fb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 72 deletions.
78 changes: 21 additions & 57 deletions mythtv/libs/libmythtv/tv_play.cpp
Expand Up @@ -841,14 +841,6 @@ void TV::ResetKeys(void)
} }




class TVInitRunnable : public QRunnable
{
public:
TVInitRunnable(TV *ourTV) : tv(ourTV) {}
virtual void run(void) { tv->InitFromDB(); }
TV *tv;
};

/** \fn TV::TV(void) /** \fn TV::TV(void)
* \sa Init(void) * \sa Init(void)
*/ */
Expand Down Expand Up @@ -950,7 +942,7 @@ TV::TV(void)
playerActive = 0; playerActive = 0;
playerLock.unlock(); playerLock.unlock();


QThreadPool::globalInstance()->start(new TVInitRunnable(this), 99); InitFromDB();


VERBOSE(VB_PLAYBACK, LOC + "ctor -- end"); VERBOSE(VB_PLAYBACK, LOC + "ctor -- end");
} }
Expand Down Expand Up @@ -1177,15 +1169,29 @@ bool TV::Init(bool createWindow)
} }
} }


mainLoopCondLock.lock(); PlayerContext *mctx = GetPlayerReadLock(0, __FILE__, __LINE__);
start(); mctx->paused = false;
mainLoopCond.wait(&mainLoopCondLock); mctx->ff_rew_state = 0;
mctx->ff_rew_index = kInitFFRWSpeed;
mctx->ff_rew_speed = 0;
mctx->ts_normal = 1.0f;
ReturnPlayerLock(mctx);

sleep_index = 0;

SetUpdateOSDPosition(false);

const PlayerContext *ctx = GetPlayerReadLock(0, __FILE__, __LINE__);
ClearInputQueues(ctx, false);
ReturnPlayerLock(ctx);

switchToRec = NULL;
SetExitPlayer(false, false);

errorRecoveryTimerId = StartTimer(kErrorRecoveryCheckFrequency, __LINE__); errorRecoveryTimerId = StartTimer(kErrorRecoveryCheckFrequency, __LINE__);
lcdTimerId = StartTimer(1, __LINE__); lcdTimerId = StartTimer(1, __LINE__);
speedChangeTimerId = StartTimer(kSpeedChangeCheckFrequency, __LINE__); speedChangeTimerId = StartTimer(kSpeedChangeCheckFrequency, __LINE__);


mainLoopCondLock.unlock();

VERBOSE(VB_PLAYBACK, LOC + "Init -- end"); VERBOSE(VB_PLAYBACK, LOC + "Init -- end");
return true; return true;
} }
Expand Down Expand Up @@ -1214,9 +1220,6 @@ TV::~TV(void)
myWindow = NULL; myWindow = NULL;
} }


TV::exit(0);
TV::wait();

VERBOSE(VB_PLAYBACK, "TV::~TV() -- lock"); VERBOSE(VB_PLAYBACK, "TV::~TV() -- lock");


// restore window to gui size and position // restore window to gui size and position
Expand Down Expand Up @@ -2446,44 +2449,6 @@ void TV::TeardownPlayer(PlayerContext *mctx, PlayerContext *ctx)
} }
} }


void TV::run(void)
{
PlayerContext *mctx = GetPlayerReadLock(0, __FILE__, __LINE__);
mctx->paused = false;
mctx->ff_rew_state = 0;
mctx->ff_rew_index = kInitFFRWSpeed;
mctx->ff_rew_speed = 0;
mctx->ts_normal = 1.0f;
ReturnPlayerLock(mctx);

sleep_index = 0;

SetUpdateOSDPosition(false);

const PlayerContext *ctx = GetPlayerReadLock(0, __FILE__, __LINE__);
ClearInputQueues(ctx, false);
ReturnPlayerLock(ctx);

switchToRec = NULL;
SetExitPlayer(false, false);

mainLoopCondLock.lock();
mainLoopCond.wakeAll();
mainLoopCondLock.unlock();

exec();

mctx = GetPlayerWriteLock(0, __FILE__, __LINE__);
if (!mctx->IsErrored() && (GetState(mctx) != kState_None))
{
mctx->ForceNextStateNone();
HandleStateChange(mctx, mctx);
if (jumpToProgram)
TeardownPlayer(mctx, mctx);
}
ReturnPlayerLock(mctx);
}

void TV::timerEvent(QTimerEvent *te) void TV::timerEvent(QTimerEvent *te)
{ {
const int timer_id = te->timerId(); const int timer_id = te->timerId();
Expand All @@ -2492,7 +2457,6 @@ void TV::timerEvent(QTimerEvent *te)
if (mctx->IsErrored()) if (mctx->IsErrored())
{ {
ReturnPlayerLock(mctx); ReturnPlayerLock(mctx);
QThread::exit(1);
return; return;
} }
ReturnPlayerLock(mctx); ReturnPlayerLock(mctx);
Expand Down Expand Up @@ -3458,7 +3422,7 @@ bool TV::event(QEvent *e)
break; break;
} }


return QThread::event(e); return QObject::event(e);
} }


bool TV::HandleTrackAction(PlayerContext *ctx, const QString &action) bool TV::HandleTrackAction(PlayerContext *ctx, const QString &action)
Expand Down
11 changes: 1 addition & 10 deletions mythtv/libs/libmythtv/tv_play.h
Expand Up @@ -164,9 +164,8 @@ class AskProgramInfo
ProgramInfo *info; ProgramInfo *info;
}; };


class MPUBLIC TV : public QThread class MPUBLIC TV : public QObject
{ {
friend class QTVEventThread;
friend class PlaybackBox; friend class PlaybackBox;
friend class GuideGrid; friend class GuideGrid;
friend class TvPlayWindow; friend class TvPlayWindow;
Expand Down Expand Up @@ -233,9 +232,6 @@ class MPUBLIC TV : public QThread
// Boolean queries // Boolean queries
/// Returns true if we are currently in the process of switching recorders. /// Returns true if we are currently in the process of switching recorders.
bool IsSwitchingCards(void) const { return switchToRec; } bool IsSwitchingCards(void) const { return switchToRec; }
/// Returns true if the TV event thread is running. Should always be true
/// between the end of the constructor and the beginning of the destructor.
bool IsRunning(void) const { return isRunning(); }
/// Returns true if the user told Mythtv to allow re-recording of the show /// Returns true if the user told Mythtv to allow re-recording of the show
bool getAllowRerecord(void) const { return allowRerecord; } bool getAllowRerecord(void) const { return allowRerecord; }
/// This is set to true if the player reaches the end of the /// This is set to true if the player reaches the end of the
Expand Down Expand Up @@ -298,7 +294,6 @@ class MPUBLIC TV : public QThread


void DoEditSchedule(int editType = kScheduleProgramGuide); void DoEditSchedule(int editType = kScheduleProgramGuide);


virtual void run(void);
void TVEventThreadChecks(void); void TVEventThreadChecks(void);


void PauseAudioUntilBuffered(PlayerContext *ctx); void PauseAudioUntilBuffered(PlayerContext *ctx);
Expand Down Expand Up @@ -863,10 +858,6 @@ class MPUBLIC TV : public QThread
TimerContextMap signalMonitorTimerId; TimerContextMap signalMonitorTimerId;
TimerContextMap tvchainUpdateTimerId; TimerContextMap tvchainUpdateTimerId;


/// Condition to signal that the Event thread is up and running
QWaitCondition mainLoopCond;
QMutex mainLoopCondLock;

/// Condition to signal State changes /// Condition to signal State changes
QWaitCondition stateChangeCond; QWaitCondition stateChangeCond;
QMutex stateChangeCondLock; QMutex stateChangeCondLock;
Expand Down
7 changes: 2 additions & 5 deletions mythtv/programs/mythfrontend/guidegrid.cpp
Expand Up @@ -264,9 +264,6 @@ GuideGrid::GuideGrid(MythScreenStack *parent,
m_currentStartTime = m_originalStartTime.addSecs(secsoffset); m_currentStartTime = m_originalStartTime.addSecs(secsoffset);
m_startChanID = chanid; m_startChanID = chanid;
m_startChanNum = channum; m_startChanNum = channum;

if (m_player)
m_embedVideo = m_player->IsRunning() && m_embedVideo;
} }


bool GuideGrid::Create() bool GuideGrid::Create()
Expand Down Expand Up @@ -2200,7 +2197,7 @@ void GuideGrid::EmbedTVWindow(void)


void GuideGrid::refreshVideo(void) void GuideGrid::refreshVideo(void)
{ {
if (m_player && m_player->IsRunning() && m_usingNullVideo) if (m_player && m_usingNullVideo)
{ {
GetMythMainWindow()->GetPaintWindow()->update(m_videoRect); GetMythMainWindow()->GetPaintWindow()->update(m_videoRect);
} }
Expand All @@ -2216,7 +2213,7 @@ void GuideGrid::aboutToHide(void)


void GuideGrid::aboutToShow(void) void GuideGrid::aboutToShow(void)
{ {
if (m_player && m_player->IsRunning()) if (m_player)
EmbedTVWindow(); EmbedTVWindow();


MythScreenType::aboutToShow(); MythScreenType::aboutToShow();
Expand Down

0 comments on commit 7b4f3fb

Please sign in to comment.