Permalink
Browse files

Emit appropriate signals indicating playback status.

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...
1 parent 1216d2a commit 4771897718abfcfabe5bf0a276664ab3741d1bcf @jyavenard jyavenard committed Jul 14, 2012
Showing with 71 additions and 10 deletions.
  1. +45 −4 mythtv/libs/libmythtv/tv_play.cpp
  2. +26 −6 mythtv/libs/libmythtv/tv_play.h
@@ -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;
@@ -291,7 +294,6 @@ bool TV::StartTV(ProgramInfo *tvrec, uint flags)
ProgramInfo *curProgram = NULL;
bool startSysEventSent = false;
-
if (tvrec)
{
curProgram = new ProgramInfo(*tvrec);
@@ -311,6 +313,7 @@ bool TV::StartTV(ProgramInfo *tvrec, uint flags)
sendPlaybackEnd();
GetMythMainWindow()->PauseIdleTimer(false);
delete curProgram;
+ gCoreContext->emitTVPlaybackAborted();
return false;
}
@@ -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();
@@ -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)
@@ -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;
@@ -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;
@@ -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__);
@@ -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;
@@ -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;
@@ -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__);
@@ -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,
@@ -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;
@@ -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);
@@ -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);

0 comments on commit 4771897

Please sign in to comment.