Skip to content
Browse files

libmythtv: Use the actual MythPlayer pause state

Remove the pause member variable from PlayerContext and access the pause
state of the player directly. Fixes some inconsistencies in the pause
state and another step along the long road of removing PlayerContext
entirely.

Refs #9665
  • Loading branch information...
1 parent 08e27a4 commit 8c18a320ac62b4921a0a57248a8aaa0e6d7732a4 Mark Kendall committed Mar 28, 2011
View
1 mythtv/libs/libmythtv/mythplayer.h
@@ -173,6 +173,7 @@ class MTV_PUBLIC MythPlayer
PIPLocation GetNextPIPLocation(void) const;
// Bool Gets
+ bool IsPaused(void) { return allpaused; }
bool GetRawAudioState(void) const;
bool GetLimitKeyRepeat(void) const { return limitKeyRepeat; }
bool GetEof(void);
View
2 mythtv/libs/libmythtv/playercontext.cpp
@@ -42,7 +42,7 @@ PlayerContext::PlayerContext(const QString &inUseID) :
// Fast forward state
ff_rew_state(0), ff_rew_index(0), ff_rew_speed(0),
// Other state
- paused(false), playingState(kState_None),
+ playingState(kState_None),
errored(false),
// pseudo states
pseudoLiveTVRec(NULL), pseudoLiveTVState(kPseudoNormalLiveTV),
View
1 mythtv/libs/libmythtv/playercontext.h
@@ -182,7 +182,6 @@ class MTV_PUBLIC PlayerContext
int ff_rew_index;
/// Caches value of ff_rew_speeds[ff_rew_index]
int ff_rew_speed;
- bool paused;
TVState playingState;
bool errored;
View
118 mythtv/libs/libmythtv/tv_play.cpp
@@ -1125,7 +1125,6 @@ bool TV::Init(bool createWindow)
}
PlayerContext *mctx = GetPlayerReadLock(0, __FILE__, __LINE__);
- mctx->paused = false;
mctx->ff_rew_state = 0;
mctx->ff_rew_index = kInitFFRWSpeed;
mctx->ff_rew_speed = 0;
@@ -2929,18 +2928,12 @@ void TV::HandleEndOfPlaybackTimerEvent(void)
void TV::HandleIsNearEndWhenEmbeddingTimerEvent(void)
{
PlayerContext *actx = GetPlayerReadLock(-1, __FILE__, __LINE__);
-
- bool toggle = !actx->paused && !StateIsLiveTV(GetState(actx));
-
- if (toggle)
+ if (!StateIsLiveTV(GetState(actx)))
{
actx->LockDeletePlayer(__FILE__, __LINE__);
-
- toggle = actx->player && actx->player->IsEmbedding()
- && actx->player->IsNearEnd();
-
+ bool toggle = actx->player && actx->player->IsEmbedding() &&
+ actx->player->IsNearEnd() && !actx->player->IsPaused();
actx->UnlockDeletePlayer(__FILE__, __LINE__);
-
if (toggle)
DoTogglePause(actx, true);
}
@@ -2973,7 +2966,7 @@ void TV::HandleEndOfRecordingExitPromptTimerEvent(void)
jumped_back = false;
do_prompt = mctx->player->IsNearEnd() && !jumped_back &&
- !mctx->player->IsEmbedding() && !mctx->paused;
+ !mctx->player->IsEmbedding() && !mctx->player->IsPaused();
}
mctx->UnlockDeletePlayer(__FILE__, __LINE__);
@@ -3716,7 +3709,7 @@ bool TV::ActiveHandleAction(PlayerContext *ctx,
DoPlay(ctx);
else if (has_action("PAUSE", actions))
{
- if (ctx->paused)
+ if (ContextIsPaused(ctx, __FILE__, __LINE__))
SendMythSystemPlayEvent("PLAY_UNPAUSED", ctx->playingInfo);
else
SendMythSystemPlayEvent("PLAY_PAUSED", ctx->playingInfo);
@@ -4295,12 +4288,13 @@ void TV::ProcessNetworkControlCommand(PlayerContext *ctx,
}
else if (tokens.size() == 3 && tokens[1] == "SPEED")
{
+ bool paused = ContextIsPaused(ctx, __FILE__, __LINE__);
+
if (tokens[2] == "0x")
{
NormalSpeed(ctx);
StopFFRew(ctx);
-
- if (!ctx->paused)
+ if (!paused)
DoTogglePause(ctx, true);
}
else
@@ -4342,15 +4336,15 @@ void TV::ProcessNetworkControlCommand(PlayerContext *ctx,
float searchSpeed = fabs(tmpSpeed);
unsigned int index;
- if (ctx->paused)
+ if (paused)
DoTogglePause(ctx, true);
if (tmpSpeed == 0.0f)
{
NormalSpeed(ctx);
StopFFRew(ctx);
- if (!ctx->paused)
+ if (!paused)
DoTogglePause(ctx, true);
}
else if (tmpSpeed == 1.0f)
@@ -4488,8 +4482,7 @@ void TV::ProcessNetworkControlCommand(PlayerContext *ctx,
if (tokens[2] == "POSITION")
{
QString speedStr;
-
- if (ctx->paused)
+ if (ContextIsPaused(ctx, __FILE__, __LINE__))
{
speedStr = "pause";
}
@@ -5335,10 +5328,9 @@ void TV::DoPlay(PlayerContext *ctx)
ctx->player->Play(ctx->ts_normal, true);
ctx->ff_rew_speed = 0;
}
- else if (ctx->paused || (ctx->ff_rew_speed != 0))
+ else if (ctx->player->IsPaused() || (ctx->ff_rew_speed != 0))
{
ctx->player->Play(ctx->ts_normal, true);
- ctx->paused = false;
ctx->ff_rew_speed = 0;
}
ctx->UnlockDeletePlayer(__FILE__, __LINE__);
@@ -5368,7 +5360,7 @@ float TV::DoTogglePauseStart(PlayerContext *ctx)
ctx->UnlockDeletePlayer(__FILE__, __LINE__);
return 0.0f;
}
- if (ctx->paused)
+ if (ctx->player->IsPaused())
{
ctx->player->Play(ctx->ts_normal, true);
}
@@ -5379,9 +5371,6 @@ float TV::DoTogglePauseStart(PlayerContext *ctx)
ctx->player->Pause();
}
ctx->UnlockDeletePlayer(__FILE__, __LINE__);
-
- ctx->paused = !ctx->paused;
-
return time;
}
@@ -5393,7 +5382,7 @@ void TV::DoTogglePauseFinish(PlayerContext *ctx, float time, bool showOSD)
if (ctx->buffer && ctx->buffer->IsInDiscMenuOrStillFrame())
return;
- if (ctx->paused)
+ if (ContextIsPaused(ctx, __FILE__, __LINE__))
{
if (ctx->buffer)
ctx->buffer->WaitForPause();
@@ -5483,7 +5472,7 @@ bool TV::SeekHandleAction(PlayerContext *actx, const QStringList &actions,
{
DoArbSeek(actx, static_cast<ArbSeekWhence>(flags & kWhenceMask));
}
- else if (actx->paused)
+ else if (ContextIsPaused(actx, __FILE__, __LINE__))
{
if (!isDVD)
{
@@ -5492,7 +5481,6 @@ bool TV::SeekHandleAction(PlayerContext *actx, const QStringList &actions,
if (actx->player)
rate = actx->player->GetFrameRate();
actx->UnlockDeletePlayer(__FILE__, __LINE__);
-
float time = (flags & kAbsolute) ? direction :
direction * (1.001 / rate);
QString message = (flags & kRewind) ? QString(tr("Rewind")) :
@@ -5591,7 +5579,7 @@ void TV::ChangeSpeed(PlayerContext *ctx, int direction)
{
int old_speed = ctx->ff_rew_speed;
- if (ctx->paused)
+ if (ContextIsPaused(ctx, __FILE__, __LINE__))
ctx->ff_rew_speed = -4;
ctx->ff_rew_speed += direction;
@@ -5627,8 +5615,6 @@ void TV::ChangeSpeed(PlayerContext *ctx, int direction)
return;
}
ctx->UnlockDeletePlayer(__FILE__, __LINE__);
-
- ctx->paused = false;
DoPlayerSeek(ctx, time);
UpdateOSDSeekMessage(ctx, mesg, kOSDTimeout_Med);
@@ -5688,7 +5674,6 @@ void TV::ChangeFFRew(PlayerContext *ctx, int direction)
else
{
NormalSpeed(ctx);
- ctx->paused = false;
ctx->ff_rew_state = direction;
SetFFRew(ctx, kInitFFRWSpeed);
}
@@ -6246,12 +6231,11 @@ void TV::ToggleInputs(PlayerContext *ctx, uint inputid)
return;
}
- // If Nuppel Video Player is paused, unpause it
- if (ctx->paused)
+ // If MythPlayer is paused, unpause it
+ if (ContextIsPaused(ctx, __FILE__, __LINE__))
{
HideOSDWindow(ctx, "osd_status");
GetMythUI()->DisableScreensaver();
- ctx->paused = false;
}
const QString curinputname = ctx->recorder->GetInput();
@@ -6576,11 +6560,10 @@ void TV::ChangeChannel(PlayerContext *ctx, int direction)
QString oldinputname = ctx->recorder->GetInput();
- if (ctx->paused)
+ if (ContextIsPaused(ctx, __FILE__, __LINE__))
{
HideOSDWindow(ctx, "osd_status");
GetMythUI()->DisableScreensaver();
- ctx->paused = false;
}
// Save the current channel if this is the first time
@@ -6689,11 +6672,10 @@ void TV::ChangeChannel(PlayerContext *ctx, uint chanid, const QString &chan)
if (getit || !ctx->recorder || !ctx->recorder->CheckChannel(channum))
return;
- if (ctx->paused)
+ if (ContextIsPaused(ctx, __FILE__, __LINE__))
{
HideOSDWindow(ctx, "osd_status");
GetMythUI()->DisableScreensaver();
- ctx->paused = false;
}
// Save the current channel if this is the first time
@@ -6818,12 +6800,12 @@ bool TV::ClearOSD(const PlayerContext *ctx)
/** \fn TV::ToggleOSD(const PlayerContext*, bool includeStatus)
* \brief Cycle through the available Info OSDs.
*/
-void TV::ToggleOSD(const PlayerContext *ctx, bool includeStatusOSD)
+void TV::ToggleOSD(PlayerContext *ctx, bool includeStatusOSD)
{
OSD *osd = GetOSDLock(ctx);
bool hideAll = false;
bool showStatus = false;
- if (ctx->paused || !osd)
+ if (ContextIsPaused(ctx, __FILE__, __LINE__) || !osd)
{
ReturnOSDLock(ctx, osd);
return;
@@ -7464,7 +7446,9 @@ vector<bool> TV::DoSetPauseState(PlayerContext *lctx, const vector<bool> &pause)
vector<float> times;
for (uint i = 0; lctx && i < player.size() && i < pause.size(); i++)
{
- was_paused.push_back(GetPlayer(lctx,i)->paused);
+ PlayerContext *actx = GetPlayer(lctx, i);
+ if (actx)
+ was_paused.push_back(ContextIsPaused(actx, __FILE__, __LINE__));
float time = 0.0f;
if (pause[i] ^ was_paused.back())
time = DoTogglePauseStart(GetPlayer(lctx,i));
@@ -7515,14 +7499,19 @@ void TV::DoEditSchedule(int editType)
bool isNearEnd = false;
bool isLiveTV = StateIsLiveTV(GetState(actx));
bool allowEmbedding = false;
+ bool paused = false;
{
actx->LockDeletePlayer(__FILE__, __LINE__);
pause_active = !actx->player || !actx->player->getVideoOutput();
- if (actx->player && actx->player->getVideoOutput())
- allowEmbedding = actx->player->getVideoOutput()->AllowPreviewEPG();
- if (!pause_active)
- isNearEnd = actx->player->IsNearEnd();
+ if (actx->player)
+ {
+ paused = actx->player->IsPaused();
+ if (actx->player->getVideoOutput())
+ allowEmbedding = actx->player->getVideoOutput()->AllowPreviewEPG();
+ if (!pause_active)
+ isNearEnd = actx->player->IsNearEnd();
+ }
actx->UnlockDeletePlayer(__FILE__, __LINE__);
}
@@ -7531,7 +7520,7 @@ void TV::DoEditSchedule(int editType)
pause_active |= kScheduleProgramFinder == editType;
pause_active |=
!isLiveTV && (!db_continue_embedded || isNearEnd);
- pause_active |= actx->paused;
+ pause_active |= paused;
vector<bool> do_pause;
do_pause.insert(do_pause.begin(), true, player.size());
do_pause[find_player_index(actx)] = pause_active;
@@ -7694,13 +7683,10 @@ void TV::ChangeTimeStretch(PlayerContext *ctx, int dir, bool allowEdit)
ctx->ts_normal = new_ts_normal;
- if (!ctx->paused)
- {
- ctx->LockDeletePlayer(__FILE__, __LINE__);
- if (ctx->player)
+ ctx->LockDeletePlayer(__FILE__, __LINE__);
+ if (ctx->player && !ctx->player->IsPaused())
ctx->player->Play(ctx->ts_normal, true);
- ctx->UnlockDeletePlayer(__FILE__, __LINE__);
- }
+ ctx->UnlockDeletePlayer(__FILE__, __LINE__);
if (!browsehelper->IsBrowsing())
{
@@ -8885,7 +8871,7 @@ void TV::ShowOSDAlreadyEditing(PlayerContext *ctx)
if (osd)
{
osd->DialogQuit();
- bool was_paused = ctx->paused;
+ bool was_paused = ContextIsPaused(ctx, __FILE__, __LINE__);
if (!was_paused)
DoTogglePause(ctx, true);
@@ -8906,13 +8892,15 @@ void TV::HandleOSDAlreadyEditing(PlayerContext *ctx, QString action,
if (!DialogIsVisible(ctx, OSD_DLG_EDITING))
return;
+ bool paused = ContextIsPaused(ctx, __FILE__, __LINE__);
+
if (action == "STOP")
{
ctx->LockPlayingInfo(__FILE__, __LINE__);
if (ctx->playingInfo)
ctx->playingInfo->SaveEditing(false);
ctx->UnlockPlayingInfo(__FILE__, __LINE__);
- if (!was_paused && ctx->paused)
+ if (!was_paused && paused)
DoTogglePause(ctx, true);
}
else // action == "CONTINUE"
@@ -8922,7 +8910,7 @@ void TV::HandleOSDAlreadyEditing(PlayerContext *ctx, QString action,
{
ctx->playingInfo->SaveEditing(false);
editmode = ctx->player->EnableEdit();
- if (!editmode && !was_paused && ctx->paused)
+ if (!editmode && !was_paused && paused)
DoTogglePause(ctx, false);
}
ctx->UnlockDeletePlayer(__FILE__, __LINE__);
@@ -9411,7 +9399,7 @@ void TV::OSDDialogEvent(int result, QString text, QString action)
StopFFRew(actx);
- if (actx->paused)
+ if (ContextIsPaused(actx, __FILE__, __LINE__))
DoTogglePause(actx, true);
ChangeTimeStretch(actx, 0, !floatRead); // just display
@@ -11072,7 +11060,7 @@ void TV::ITVRestart(PlayerContext *ctx, bool isLive)
uint chanid = 0;
uint cardid = 0;
- if (ctx->paused)
+ if (ContextIsPaused(ctx, __FILE__, __LINE__))
return;
ctx->LockPlayingInfo(__FILE__, __LINE__);
@@ -11275,7 +11263,7 @@ void TV::ShowOSDStopWatchingRecording(PlayerContext *ctx)
if ((ctx != GetPlayer(ctx, 0)))
return;
- if (!ctx->paused)
+ if (!ContextIsPaused(ctx, __FILE__, __LINE__))
DoTogglePause(ctx, false);
QString message;
@@ -11399,7 +11387,7 @@ void TV::ShowOSDPromptDeleteRecording(PlayerContext *ctx, QString title,
ClearOSD(ctx);
- bool paused = ctx->paused;
+ bool paused = ContextIsPaused(ctx, __FILE__, __LINE__);
if (!paused)
DoTogglePause(ctx, false);
@@ -11549,6 +11537,18 @@ void TV::RestoreScreenSaver(const PlayerContext *ctx)
GetMythUI()->RestoreScreensaver();
}
+bool TV::ContextIsPaused(PlayerContext *ctx, const char *file, int location)
+{
+ if (!ctx)
+ return false;
+ bool paused = false;
+ ctx->LockDeletePlayer(file, location);
+ if (ctx->player)
+ paused = ctx->player->IsPaused();
+ ctx->UnlockDeletePlayer(file, location);
+ return paused;
+}
+
OSD *TV::GetOSDL(const char *file, int location)
{
PlayerContext *actx = GetPlayerReadLock(-1, file, location);
View
3 mythtv/libs/libmythtv/tv_play.h
@@ -311,6 +311,7 @@ class MTV_PUBLIC TV : public QObject
static EMBEDRETURNVOIDSCHEDIT RunScheduleEditorPtr;
private:
+ bool ContextIsPaused(PlayerContext *ctx, const char *file, int location);
void SetActive(PlayerContext *lctx, int index, bool osd_msg);
PlayerContext *GetPlayerWriteLock(
@@ -465,7 +466,7 @@ class MTV_PUBLIC TV : public QObject
const QStringList &actions);
bool ClearOSD(const PlayerContext*);
- void ToggleOSD(const PlayerContext*, bool includeStatusOSD);
+ void ToggleOSD(PlayerContext*, bool includeStatusOSD);
void UpdateOSDProgInfo(const PlayerContext*, const char *whichInfo);
void UpdateOSDStatus(const PlayerContext *ctx, QString title, QString desc,
QString value, int type, QString units,
View
8 mythtv/libs/libmythtv/tvbrowsehelper.cpp
@@ -6,6 +6,7 @@
#include "playercontext.h"
#include "remoteencoder.h"
#include "recordinginfo.h"
+#include "mythplayer.h"
#include "tv_play.h"
#define GetPlayer(X,Y) GetPlayerHaveLock(X, Y, __FILE__ , __LINE__)
@@ -65,7 +66,12 @@ bool TVBrowseHelper::BrowseStart(PlayerContext *ctx, bool skip_browse)
if (m_ctx)
return m_ctx == ctx;
- if (ctx->paused)
+ bool paused = false;
+ ctx->LockDeletePlayer(__FILE__, __LINE__);
+ if (ctx->player)
+ paused = ctx->player->IsPaused();
+ ctx->UnlockDeletePlayer(__FILE__, __LINE__);
+ if (paused)
return false;
m_tv->ClearOSD(ctx);

0 comments on commit 8c18a32

Please sign in to comment.
Something went wrong with that request. Please try again.