Permalink
Browse files

Don't create an additional thread for media playback.

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...
1 parent 5b7b93d commit 3429e9b27366503e731f138e2bac1fcfc0c58a72 Mark Kendall committed Dec 8, 2010
Showing with 24 additions and 72 deletions.
  1. +21 −57 mythtv/libs/libmythtv/tv_play.cpp
  2. +1 −10 mythtv/libs/libmythtv/tv_play.h
  3. +2 −5 mythtv/programs/mythfrontend/guidegrid.cpp
@@ -845,14 +845,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)
* \sa Init(void)
*/
@@ -954,7 +946,7 @@ TV::TV(void)
playerActive = 0;
playerLock.unlock();
- QThreadPool::globalInstance()->start(new TVInitRunnable(this), 99);
+ InitFromDB();
VERBOSE(VB_PLAYBACK, LOC + "ctor -- end");
}
@@ -1181,15 +1173,29 @@ bool TV::Init(bool createWindow)
}
}
- mainLoopCondLock.lock();
- start();
- mainLoopCond.wait(&mainLoopCondLock);
+ 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);
+
errorRecoveryTimerId = StartTimer(kErrorRecoveryCheckFrequency, __LINE__);
lcdTimerId = StartTimer(1, __LINE__);
speedChangeTimerId = StartTimer(kSpeedChangeCheckFrequency, __LINE__);
- mainLoopCondLock.unlock();
-
VERBOSE(VB_PLAYBACK, LOC + "Init -- end");
return true;
}
@@ -1218,9 +1224,6 @@ TV::~TV(void)
myWindow = NULL;
}
- TV::exit(0);
- TV::wait();
-
VERBOSE(VB_PLAYBACK, "TV::~TV() -- lock");
// restore window to gui size and position
@@ -2453,44 +2456,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)
{
const int timer_id = te->timerId();
@@ -2499,7 +2464,6 @@ void TV::timerEvent(QTimerEvent *te)
if (mctx->IsErrored())
{
ReturnPlayerLock(mctx);
- QThread::exit(1);
return;
}
ReturnPlayerLock(mctx);
@@ -3465,7 +3429,7 @@ bool TV::event(QEvent *e)
break;
}
- return QThread::event(e);
+ return QObject::event(e);
}
bool TV::HandleTrackAction(PlayerContext *ctx, const QString &action)
@@ -164,9 +164,8 @@ class AskProgramInfo
ProgramInfo *info;
};
-class MPUBLIC TV : public QThread
+class MPUBLIC TV : public QObject
{
- friend class QTVEventThread;
friend class PlaybackBox;
friend class GuideGrid;
friend class TvPlayWindow;
@@ -233,9 +232,6 @@ class MPUBLIC TV : public QThread
// Boolean queries
/// Returns true if we are currently in the process of switching recorders.
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
bool getAllowRerecord(void) const { return allowRerecord; }
/// This is set to true if the player reaches the end of the
@@ -298,7 +294,6 @@ class MPUBLIC TV : public QThread
void DoEditSchedule(int editType = kScheduleProgramGuide);
- virtual void run(void);
void TVEventThreadChecks(void);
void PauseAudioUntilBuffered(PlayerContext *ctx);
@@ -861,10 +856,6 @@ class MPUBLIC TV : public QThread
TimerContextMap signalMonitorTimerId;
TimerContextMap tvchainUpdateTimerId;
- /// Condition to signal that the Event thread is up and running
- QWaitCondition mainLoopCond;
- QMutex mainLoopCondLock;
-
/// Condition to signal State changes
QWaitCondition stateChangeCond;
QMutex stateChangeCondLock;
@@ -264,9 +264,6 @@ GuideGrid::GuideGrid(MythScreenStack *parent,
m_currentStartTime = m_originalStartTime.addSecs(secsoffset);
m_startChanID = chanid;
m_startChanNum = channum;
-
- if (m_player)
- m_embedVideo = m_player->IsRunning() && m_embedVideo;
}
bool GuideGrid::Create()
@@ -2200,7 +2197,7 @@ void GuideGrid::EmbedTVWindow(void)
void GuideGrid::refreshVideo(void)
{
- if (m_player && m_player->IsRunning() && m_usingNullVideo)
+ if (m_player && m_usingNullVideo)
{
GetMythMainWindow()->GetPaintWindow()->update(m_videoRect);
}
@@ -2216,7 +2213,7 @@ void GuideGrid::aboutToHide(void)
void GuideGrid::aboutToShow(void)
{
- if (m_player && m_player->IsRunning())
+ if (m_player)
EmbedTVWindow();
MythScreenType::aboutToShow();

0 comments on commit 3429e9b

Please sign in to comment.