summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Kendall <mkendall@mythtv.org>2011-01-10 14:56:14 (GMT)
committer Mark Kendall <mkendall@mythtv.org>2011-01-15 06:19:33 (GMT)
commita328d996b94f62814cf065e60311d973283ec6c8 (patch)
tree8c7f67cd56e8a9d4ad7145ba8c5d15c3c2176f5d
parent2394a9d70fe03371c124f7427a6791f2556b5748 (diff)
Remove the PlayerTimer class and run the player from TV::StartTV
This is a further natural (and now obvious) improvement following the threading changes in the player code. Instead of contriving playback events to trigger the next frame, just loop inside the main event loop in TV::StartTV and process other application events as needed. There are almost certainly other simplifications possible here - notably in the extensive use of timers; many of which can probably now be removed. Should almost certainly be a fix for #9223 (cherry picked from commit c8825513647b9b95b1c389c84f9e267cade3ef45)
-rw-r--r--mythtv/libs/libmythtv/mythplayer.cpp53
-rw-r--r--mythtv/libs/libmythtv/mythplayer.h15
-rw-r--r--mythtv/libs/libmythtv/tv_play.cpp23
3 files changed, 19 insertions, 72 deletions
diff --git a/mythtv/libs/libmythtv/mythplayer.cpp b/mythtv/libs/libmythtv/mythplayer.cpp
index 5b13fbc..771cc9d 100644
--- a/mythtv/libs/libmythtv/mythplayer.cpp
+++ b/mythtv/libs/libmythtv/mythplayer.cpp
@@ -89,43 +89,6 @@ static unsigned dbg_ident(const MythPlayer*);
#define LOC_ERR QString("Player(%1), Error: ").arg(dbg_ident(this),0,36)
#define LOC_DEC QString("Player(%1): ").arg(dbg_ident(m_mp),0,36)
-QEvent::Type PlayerTimer::kPlayerEventType =
- (QEvent::Type) QEvent::registerEventType();
-
-PlayerTimer::PlayerTimer(MythPlayer *player) : m_mp(player), m_queue_size(0)
-{
- if (!m_mp)
- VERBOSE(VB_IMPORTANT, QString("PlayerTimer has no parent."));
- PostNextEvent();
-}
-
-void PlayerTimer::PostNextEvent(void)
-{
- QEvent *event = new QEvent(kPlayerEventType);
- qApp->postEvent(this, event);
- m_queue_size++;
-}
-
-bool PlayerTimer::event(QEvent *e)
-{
- if (e->type() == kPlayerEventType)
- {
- // TODO this may fail if events are lost and the queue size is wrong
- m_queue_size--;
- uint max_queue = m_mp->GetFFRewSkip() == 1 ? 3 : 1;
- while (m_queue_size < max_queue)
- PostNextEvent();
-
- if (m_mp && !m_mp->IsErrored())
- {
- m_mp->EventLoop();
- m_mp->VideoLoop();
- }
- return true;
- }
- return false;
-}
-
void DecoderThread::run(void)
{
if (!m_mp)
@@ -162,7 +125,6 @@ MythPlayer::MythPlayer(bool muted)
: decoder(NULL), decoder_change_lock(QMutex::Recursive),
videoOutput(NULL), player_ctx(NULL),
decoderThread(NULL), playerThread(NULL),
- playerTimer(NULL),
no_hardware_decoders(false),
// Window stuff
parentWidget(NULL), embedid(0),
@@ -287,12 +249,6 @@ MythPlayer::~MythPlayer(void)
decoderThread = NULL;
}
- if (playerTimer)
- {
- delete playerTimer;
- playerTimer = NULL;
- }
-
if (interactiveTV)
{
delete interactiveTV;
@@ -2448,9 +2404,6 @@ bool MythPlayer::StartPlaying(void)
InitialSeek();
VideoStart();
- if (playerTimer)
- delete playerTimer;
- playerTimer = new PlayerTimer(this);
playerThread->setPriority(QThread::TimeCriticalPriority);
return !IsErrored();
}
@@ -2476,12 +2429,6 @@ void MythPlayer::StopPlaying()
VERBOSE(VB_PLAYBACK, LOC + QString("StopPlaying - begin"));
playerThread->setPriority(QThread::NormalPriority);
- if (playerTimer)
- {
- delete playerTimer;
- playerTimer = NULL;
- }
-
DecoderEnd();
VideoEnd();
AudioEnd();
diff --git a/mythtv/libs/libmythtv/mythplayer.h b/mythtv/libs/libmythtv/mythplayer.h
index 8090e35..21423f6 100644
--- a/mythtv/libs/libmythtv/mythplayer.h
+++ b/mythtv/libs/libmythtv/mythplayer.h
@@ -80,20 +80,6 @@ enum
kDisplayTeletextMenu = 0x100,
};
-class PlayerTimer : public QObject
-{
- Q_OBJECT
- public:
- PlayerTimer(MythPlayer *mp);
- void PostNextEvent(void);
- virtual bool event(QEvent *e);
- static enum QEvent::Type kPlayerEventType;
-
- private:
- MythPlayer *m_mp;
- uint32_t m_queue_size;
-};
-
class DecoderThread : public QThread
{
Q_OBJECT
@@ -532,7 +518,6 @@ class MPUBLIC MythPlayer
PlayerContext *player_ctx;
DecoderThread *decoderThread;
QThread *playerThread;
- PlayerTimer *playerTimer;
bool no_hardware_decoders;
// Window stuff
diff --git a/mythtv/libs/libmythtv/tv_play.cpp b/mythtv/libs/libmythtv/tv_play.cpp
index 5f57074..50945e7 100644
--- a/mythtv/libs/libmythtv/tv_play.cpp
+++ b/mythtv/libs/libmythtv/tv_play.cpp
@@ -365,13 +365,28 @@ bool TV::StartTV(ProgramInfo *tvrec, uint flags)
while (true)
{
- qApp->processEvents();
+ if (qApp->hasPendingEvents())
+ qApp->processEvents();
TVState state = tv->GetState(0);
- bool is_err = kState_Error == state;
- bool is_none = kState_None == state;
- if (is_err || is_none)
+ if ((kState_Error == state) || (kState_None == state))
break;
+
+ if (kState_ChangingState == state)
+ continue;
+
+ const PlayerContext *mctx = tv->GetPlayerReadLock(0, __FILE__, __LINE__);
+ if (mctx)
+ {
+ mctx->LockDeletePlayer(__FILE__, __LINE__);
+ if (mctx->player && !mctx->player->IsErrored())
+ {
+ mctx->player->EventLoop();
+ mctx->player->VideoLoop();
+ }
+ }
+ mctx->UnlockDeletePlayer(__FILE__, __LINE__);
+ tv->ReturnPlayerLock(mctx);
}
VERBOSE(VB_PLAYBACK, LOC + "StartTV -- process events end");