Skip to content

Commit

Permalink
TV: Fix PiP swap
Browse files Browse the repository at this point in the history
- ensure the main context and other contexts are reset for using null
video and dis/allowing hardware decoders
- ensure there is no deadlock when the decoder for the main context
attempts to call back into the UI thread while holding the global
avlock.
  • Loading branch information
mark-kendall committed Mar 9, 2020
1 parent 8bb58dd commit b150925
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/playercontext.h
Expand Up @@ -105,7 +105,7 @@ class MTV_PUBLIC PlayerContext
void SetPIPLocation(int loc) { m_pipLocation = loc; }
void SetPIPState(PIPState change) { m_pipState = change; }
void SetPlayerChangingBuffers(bool val) { m_playerUnsafe = val; }
void SetNoHardwareDecoders(void) { m_nohardwaredecoders = true; }
void SetNoHardwareDecoders(bool Disallow = true) { m_nohardwaredecoders = Disallow; }

// Gets
QRect GetStandAlonePIPRect(void);
Expand Down
18 changes: 18 additions & 0 deletions mythtv/libs/libmythtv/tv_play.cpp
Expand Up @@ -6110,6 +6110,8 @@ void TV::RestartAllPlayers(PlayerContext *lctx,
mctx->m_buffer->Unpause();
}

mctx->SetNullVideo(false);
mctx->SetNoHardwareDecoders(false);
bool ok = StartPlayer(mctx, mctx, mctx->GetState());

if (ok)
Expand Down Expand Up @@ -6137,6 +6139,20 @@ void TV::RestartAllPlayers(PlayerContext *lctx,
pipctx->m_buffer->Unpause();
}

pipctx->SetNullVideo(true);
pipctx->SetNoHardwareDecoders(true);

// if the main context is using a hardware decoder, it will callback to
// the main thread at some point while holding avcodeclock, which causes
// a deadlock. If we can't obtain the lock, try and process the callback.
while (!avcodeclock->tryLock(10))
{
mctx->LockDeletePlayer(__FILE__, __LINE__);
if (mctx->m_player)
mctx->m_player->ProcessCallbacks();
mctx->UnlockDeletePlayer(__FILE__, __LINE__);
}

ok = StartPlayer(mctx, pipctx, pipctx->GetState());

if (ok)
Expand All @@ -6155,6 +6171,8 @@ void TV::RestartAllPlayers(PlayerContext *lctx,
"Failed to restart new pip context (was main context)");
ForceNextStateNone(pipctx);
}

avcodeclock->unlock();
}

// If old main player had a kMuteAll | kMuteOff setting,
Expand Down

0 comments on commit b150925

Please sign in to comment.