Skip to content

Commit

Permalink
Emit appropriate signals indicating playback status.
Browse files Browse the repository at this point in the history
Signals currently emitted are:
- TVPlaybackAborted: TV playback failed to start (typically, TV playback was started when another playback is currently going)
- TVPlaybackStarted: TV playback has started, video is now playing
- TVPlaybackStopped: TV playback has stopped and playback has exited
- TVPlaybackUnpaused: TV playback has resumed, following a Pause action
- TVPlaybackPaused: TV playback has been paused
- TVPlaybackSought(qint position_seconds): Absolute seek has completed

Also add IsPaused utility (static). Will return true is playback is currently ongoing.
  • Loading branch information
jyavenard committed Jul 14, 2012
1 parent 1216d2a commit 4771897
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 10 deletions.
49 changes: 45 additions & 4 deletions mythtv/libs/libmythtv/tv_play.cpp
Expand Up @@ -279,7 +279,10 @@ bool TV::StartTV(ProgramInfo *tvrec, uint flags)
{
TV *tv = GetTV();
if (!tv)
{
gCoreContext->emitTVPlaybackAborted();
return false;
}

LOG(VB_PLAYBACK, LOG_INFO, LOC + "StartTV() -- begin");
bool startInGuide = flags & kStartTVInGuide;
Expand All @@ -291,7 +294,6 @@ bool TV::StartTV(ProgramInfo *tvrec, uint flags)
ProgramInfo *curProgram = NULL;
bool startSysEventSent = false;


if (tvrec)
{
curProgram = new ProgramInfo(*tvrec);
Expand All @@ -311,6 +313,7 @@ bool TV::StartTV(ProgramInfo *tvrec, uint flags)
sendPlaybackEnd();
GetMythMainWindow()->PauseIdleTimer(false);
delete curProgram;
gCoreContext->emitTVPlaybackAborted();
return false;
}

Expand Down Expand Up @@ -377,6 +380,8 @@ bool TV::StartTV(ProgramInfo *tvrec, uint flags)
tv->setInPlayList(inPlaylist);
tv->setUnderNetworkControl(initByNetworkCommand);

gCoreContext->emitTVPlaybackStarted();

// Process Events
LOG(VB_GENERAL, LOG_INFO, LOC + "Entering main playback loop.");
tv->PlaybackLoop();
Expand Down Expand Up @@ -420,6 +425,8 @@ bool TV::StartTV(ProgramInfo *tvrec, uint flags)
bool allowrerecord = tv->getAllowRerecord();
bool deleterecording = tv->requestDelete;

gCoreContext->emitTVPlaybackStopped();

ReleaseTV(tv);

if (curProgram)
Expand Down Expand Up @@ -1429,6 +1436,7 @@ void TV::GetStatus(void)
status.insert("chanid",
QString::number(ctx->playingInfo->GetChanID()));
status.insert("programid", ctx->playingInfo->GetProgramID());
status.insert("pathname", ctx->playingInfo->GetPathname());
}
ctx->UnlockPlayingInfo(__FILE__, __LINE__);
osdInfo info;
Expand Down Expand Up @@ -1826,7 +1834,7 @@ void TV::ShowOSDAskAllow(PlayerContext *ctx)
{
if (!(*it).is_in_same_input_group)
(*it).is_conflicting = false;
else if ((cardid == (uint)(*it).info->GetCardID()))
else if (cardid == (uint)(*it).info->GetCardID())
(*it).is_conflicting = true;
else if (!CardUtil::IsTunerShared(cardid, (*it).info->GetCardID()))
(*it).is_conflicting = true;
Expand Down Expand Up @@ -5762,6 +5770,7 @@ void TV::DoPlay(PlayerContext *ctx)
SendMythSystemPlayEvent("PLAY_UNPAUSED", ctx->playingInfo);

ctx->player->Play(ctx->ts_normal, true);
gCoreContext->emitTVPlaybackUnpaused();
ctx->ff_rew_speed = 0;
}
ctx->UnlockDeletePlayer(__FILE__, __LINE__);
Expand Down Expand Up @@ -5838,6 +5847,34 @@ void TV::DoTogglePauseFinish(PlayerContext *ctx, float time, bool showOSD)
SetSpeedChangeTimer(0, __LINE__);
}

/**
* \fn bool TV::IsPaused(void) [static]
* Returns true if a TV playback is currently going; otherwise returns false
*/
bool TV::IsPaused(void)
{
if (!IsTVRunning())
return false;

QMutexLocker lock(gTVLock);
PlayerContext *ctx = gTV->GetPlayerReadLock(0, __FILE__, __LINE__);

if (!ctx || ctx->IsErrored())
{
gTV->ReturnPlayerLock(ctx);
return false;
}
ctx->LockDeletePlayer(__FILE__, __LINE__);
bool paused = false;
if (ctx->player)
{
paused = ctx->player->IsPaused();
}
ctx->UnlockDeletePlayer(__FILE__, __LINE__);
gTV->ReturnPlayerLock(ctx);
return paused;
}

void TV::DoTogglePause(PlayerContext *ctx, bool showOSD)
{
bool ignore = false;
Expand All @@ -5857,13 +5894,15 @@ void TV::DoTogglePause(PlayerContext *ctx, bool showOSD)

if (!ignore)
DoTogglePauseFinish(ctx, DoTogglePauseStart(ctx), showOSD);
// Emit Pause or Unpaused signal
paused ? gCoreContext->emitTVPlaybackUnpaused() : gCoreContext->emitTVPlaybackPaused();
}

bool TV::DoPlayerSeek(PlayerContext *ctx, float time)
{
if (!ctx || !ctx->buffer)
return false;

if (time > -0.001f && time < +0.001f)
return false;

Expand Down Expand Up @@ -5974,7 +6013,7 @@ void TV::DoSeek(PlayerContext *ctx, float time, const QString &mesg,
{
if (!ctx->player)
return;

bool limitkeys = false;

ctx->LockDeletePlayer(__FILE__, __LINE__);
Expand Down Expand Up @@ -6013,12 +6052,14 @@ void TV::DoSeekAbsolute(PlayerContext *ctx, long long seconds,
if (!ctx->player)
{
ctx->UnlockDeletePlayer(__FILE__, __LINE__);
gCoreContext->emitTVPlaybackSought((qint64)-1);
return;
}
ctx->UnlockDeletePlayer(__FILE__, __LINE__);
DoSeek(ctx, seconds, tr("Jump To"),
/*timeIsOffset*/false,
honorCutlist);
gCoreContext->emitTVPlaybackSought((qint64)seconds);
}

void TV::DoArbSeek(PlayerContext *ctx, ArbSeekWhence whence,
Expand Down
32 changes: 26 additions & 6 deletions mythtv/libs/libmythtv/tv_play.h
Expand Up @@ -137,6 +137,24 @@ class AskProgramInfo
ProgramInfo *info;
};

/**
* \class TV
*
* \brief Control TV playback
* \qmlsignal TVPlaybackAborted(void)
*
* TV playback failed to start (typically, TV playback was started when another playback is currently going)
* \qmlsignal TVPlaybackStarted(void)
* TV playback has started, video is now playing
* \qmlsignal TVPlaybackStopped(void)
* TV playback has stopped and playback has exited
* \qmlsignal TVPlaybackUnpaused(void)
* TV playback has resumed, following a Pause action
* \qmlsignal TVPlaybackPaused(void)
* TV playback has been paused
* \qmlsignal TVPlaybackSought(qint position_seconds)
* Absolute seek has completed to position_seconds
*/
class MTV_PUBLIC TV : public QObject
{
friend class PlaybackBox;
Expand All @@ -151,10 +169,12 @@ class MTV_PUBLIC TV : public QObject
Q_OBJECT
public:
// Check whether we already have a TV object
static bool IsTVRunning(void);
static bool IsTVRunning(void);
static TV* CurrentTVInstance(void) { return gTV; }
// Start media playback
static bool StartTV(ProgramInfo *tvrec = NULL,
static bool StartTV(ProgramInfo *tvrec = NULL,
uint flags = kStartTVNoFlags);
static bool IsPaused(void);

// Public event handling
bool event(QEvent *e);
Expand Down Expand Up @@ -201,10 +221,10 @@ class MTV_PUBLIC TV : public QObject
private:
TV();
~TV();
static TV* GetTV(void);
static void ReleaseTV(TV* tv);
static QMutex *gTVLock;
static TV *gTV;
static TV* GetTV(void);
static void ReleaseTV(TV* tv);
static QMutex *gTVLock;
static TV *gTV;

// Private initialisation
bool Init(bool createWindow = true);
Expand Down

0 comments on commit 4771897

Please sign in to comment.