Skip to content

Commit

Permalink
Add CoreContext::TVInWantingPlayback method
Browse files Browse the repository at this point in the history
MythMusic resumes music playback when exiting TV Playback, however we don't want it to resume should TV playback be interrupted by another player (for example AirPlay)
  • Loading branch information
jyavenard committed Jul 14, 2013
1 parent 5201ed1 commit 5ed3c41
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
19 changes: 18 additions & 1 deletion mythtv/libs/libmythbase/mythcorecontext.cpp
Expand Up @@ -91,6 +91,7 @@ class MythCoreContextPrivate : public QObject
QMap<QObject *, QByteArray> m_playbackClients;
QMutex m_playbackLock;
bool m_inwanting;
bool m_intvwanting;

MythPluginManager *m_pluginmanager;
};
Expand Down Expand Up @@ -1492,6 +1493,18 @@ void MythCoreContext::WantingPlayback(QObject *sender)
d->m_inwanting = false;
}

/**
* Let the TV class tell us if we was interrupted following a call to
* WantingPlayback(). TV playback will later issue a TVPlaybackStopped() signal
* which we want to be able to filter
*/
void MythCoreContext::TVInWantingPlayback(bool b)
{
// when called, it will be while the m_playbackLock is held
// following a call to WantingPlayback
d->m_intvwanting = b;
}

/**
* Returns true if a client has requested playback.
* this can be used when one of the TVPlayback* is emitted to find out if you
Expand All @@ -1500,13 +1513,17 @@ void MythCoreContext::WantingPlayback(QObject *sender)
bool MythCoreContext::InWantingPlayback(void)
{
bool locked = d->m_playbackLock.tryLock();
bool intvplayback = d->m_intvwanting;

if (!locked && d->m_inwanting)
return true; // we're in the middle of WantingPlayback

if (!locked)
return false;

d->m_playbackLock.unlock();
return false;

return intvplayback;
}

bool MythCoreContext::TestPluginVersion(const QString &name,
Expand Down
3 changes: 3 additions & 0 deletions mythtv/libs/libmythbase/mythcorecontext.h
Expand Up @@ -176,6 +176,7 @@ class MBASE_PUBLIC MythCoreContext : public QObject, public MythObservable, publ
void UnregisterForPlayback(QObject *sender);
void WantingPlayback(QObject *sender);
bool InWantingPlayback(void);
void TVInWantingPlayback(bool b);

// Plugin related methods
bool TestPluginVersion(const QString &name, const QString &libversion,
Expand All @@ -196,6 +197,8 @@ class MBASE_PUBLIC MythCoreContext : public QObject, public MythObservable, publ

signals:
void TVPlaybackStarted(void);
//// TVPlaybackStopped signal should be used in combination with
//// InWantingPlayback() and treat it accordingly
void TVPlaybackStopped(void);
void TVPlaybackSought(qint64 position);
void TVPlaybackPaused(void);
Expand Down
3 changes: 3 additions & 0 deletions mythtv/libs/libmythtv/tv_play.cpp
Expand Up @@ -301,6 +301,7 @@ void TV::StopPlayback(void)
PrepareToExitPlayer(ctx, __LINE__);
SetExitPlayer(true, true);
ReturnPlayerLock(ctx);
gCoreContext->TVInWantingPlayback(true);
}
}

Expand Down Expand Up @@ -453,6 +454,7 @@ bool TV::StartTV(ProgramInfo *tvrec, uint flags)
ReleaseTV(tv);

gCoreContext->emitTVPlaybackStopped();
gCoreContext->TVInWantingPlayback(false);

if (curProgram)
{
Expand Down Expand Up @@ -2084,6 +2086,7 @@ int TV::Playback(const ProgramInfo &rcinfo)
jumpToProgram = false;
allowRerecord = false;
requestDelete = false;
gCoreContext->TVInWantingPlayback(false);

PlayerContext *mctx = GetPlayerReadLock(0, __FILE__, __LINE__);
if (mctx->GetState() != kState_None)
Expand Down

0 comments on commit 5ed3c41

Please sign in to comment.