Navigation Menu

Skip to content

Commit

Permalink
MythPlayer: Fix decoder locking.
Browse files Browse the repository at this point in the history
This should complete the overall decoder locking changes.

- when changing the decoder, pause before obtaining the
decoder_change_lock. Also add some logging to assess any delays in
livetv channel changes.

- lock access to the decoder in the main decoder loop. In all cases, use
tryLock and continue to the next loop iteration if it fails. Given that
the decoder_change_lock is now only used when by SetDecoder, the extra
locking should have no performance impact.

Cherry picked from df1df86
  • Loading branch information
Mark Kendall committed Mar 19, 2011
1 parent ccc89dd commit ccd73be
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
8 changes: 6 additions & 2 deletions mythtv/libs/libmythtv/mythdvdplayer.cpp
Expand Up @@ -66,9 +66,13 @@ bool MythDVDPlayer::PrebufferEnoughFrames(bool pause_audio, int min_buffers)

bool MythDVDPlayer::DecoderGetFrameFFREW(void)
{
if (decoder)
decoder->UpdateDVDFramesPlayed();
return MythPlayer::DecoderGetFrameFFREW();
if (decoder_change_lock.tryLock(1))
{
if (decoder)
decoder->UpdateDVDFramesPlayed();
decoder_change_lock.unlock();
}
}

bool MythDVDPlayer::DecoderGetFrameREW(void)
Expand Down
38 changes: 24 additions & 14 deletions mythtv/libs/libmythtv/mythplayer.cpp
Expand Up @@ -2779,14 +2779,16 @@ void MythPlayer::DecoderLoop(bool pause)
{
DecoderPauseCheck();

decoder_change_lock.lock();
if (!decoder_change_lock.tryLock(1))
continue;
if (decoder)
noVideoTracks = !decoder->GetTrackCount(kTrackTypeVideo);
decoder_change_lock.unlock();

if (forcePositionMapSync)
{
decoder_change_lock.lock();
if (!decoder_change_lock.tryLock(1))
continue;
if (decoder)
{
forcePositionMapSync = false;
Expand All @@ -2797,7 +2799,8 @@ void MythPlayer::DecoderLoop(bool pause)

if (decoderSeek >= 0)
{
decoder_change_lock.lock();
if (!decoder_change_lock.tryLock(1))
continue;
if (decoder)
{
decoderSeekLock.lock();
Expand Down Expand Up @@ -2892,17 +2895,19 @@ bool MythPlayer::DecoderGetFrame(DecodeType decodetype, bool unsafe)
videobuf_retries = 0;
}

if (killdecoder)
if (!decoder_change_lock.tryLock(5))
return false;
if (!decoder)
if (killdecoder || !decoder || IsErrored())
{
VERBOSE(VB_IMPORTANT, LOC + "DecoderGetFrame() called with NULL decoder.");
decoder_change_lock.unlock();
return false;
}
else if (ffrew_skip == 1 || decodeOneFrame)

if (ffrew_skip == 1 || decodeOneFrame)
ret = decoder->GetFrame(decodetype);
else if (ffrew_skip != 0)
ret = DecoderGetFrameFFREW();
decoder_change_lock.unlock();
return ret;
}

Expand Down Expand Up @@ -4493,16 +4498,21 @@ bool MythPlayer::SetVideoByComponentTag(int tag)
*/
void MythPlayer::SetDecoder(DecoderBase *dec)
{
QMutexLocker locker(&decoder_change_lock);
PauseDecoder();

if (!decoder)
decoder = dec;
else
{
DecoderBase *d = decoder;
decoder = dec;
delete d;
while (!decoder_change_lock.tryLock(10))
VERBOSE(VB_IMPORTANT, LOC + QString("Waited 10ms for decoder lock"));

if (!decoder)
decoder = dec;
else
{
DecoderBase *d = decoder;
decoder = dec;
delete d;
}
decoder_change_lock.unlock();
}
}

Expand Down

0 comments on commit ccd73be

Please sign in to comment.