Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
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)
* \sa Init(void)
*/
Expand Down Expand Up @@ -950,7 +942,7 @@ TV::TV(void)
playerActive = 0;
playerLock.unlock();

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

VERBOSE(VB_PLAYBACK, LOC + "ctor -- end");
}
Expand Down Expand Up @@ -1177,15 +1169,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;
}
Expand Down Expand Up @@ -1214,9 +1220,6 @@ TV::~TV(void)
myWindow = NULL;
}

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

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

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

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

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;
};

class MPUBLIC TV : public QThread
class MPUBLIC TV : public QObject
{
friend class QTVEventThread;
friend class PlaybackBox;
friend class GuideGrid;
friend class TvPlayWindow;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -863,10 +858,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;
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_startChanID = chanid;
m_startChanNum = channum;

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

bool GuideGrid::Create()
Expand Down Expand Up @@ -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);
}
Expand All @@ -2216,7 +2213,7 @@ void GuideGrid::aboutToHide(void)

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

MythScreenType::aboutToShow();
Expand Down

0 comments on commit 7b4f3fb

Please sign in to comment.