Skip to content

Commit

Permalink
Lock the various stream context to prevent racing conditions.
Browse files Browse the repository at this point in the history
SeekReset was called in player thread, which would reset the av streams, while sometimes in the middle of usage in the decoder thread.

Fixes #11705
  • Loading branch information
jyavenard committed Jul 25, 2013
1 parent cf6f6b4 commit 7e7a78c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 7 additions & 2 deletions mythtv/libs/libmythtv/avformatdecoder.cpp
Expand Up @@ -695,6 +695,8 @@ void AvFormatDecoder::SeekReset(long long newKey, uint skipFrames,

DecoderBase::SeekReset(newKey, skipFrames, doflush, discardFrames);

QMutexLocker locker(avcodeclock);

if (doflush)
{
lastapts = 0;
Expand Down Expand Up @@ -871,8 +873,8 @@ extern "C" void HandleStreamChange(void *data)
QString("streams_changed 0x%1 -- stream count %2")
.arg((uint64_t)data,0,16).arg(cnt));

QMutexLocker locker(avcodeclock);
decoder->SeekReset(0, 0, true, true);
QMutexLocker locker(avcodeclock);
decoder->ScanStreams(false);
}

Expand All @@ -887,8 +889,8 @@ extern "C" void HandleDVDStreamChange(void *data)
QString("streams_changed 0x%1 -- stream count %2")
.arg((uint64_t)data,0,16).arg(cnt));

QMutexLocker locker(avcodeclock);
//decoder->SeekReset(0, 0, true, true);
QMutexLocker locker(avcodeclock);
decoder->ScanStreams(true);
}

Expand Down Expand Up @@ -4661,6 +4663,7 @@ bool AvFormatDecoder::GetFrame(DecodeType decodetype)
}

int retval = 0;
avcodeclock->lock();
if (!ic || ((retval = ReadPacket(ic, pkt, storevideoframes)) < 0))
{
if (retval == -EAGAIN)
Expand All @@ -4670,8 +4673,10 @@ bool AvFormatDecoder::GetFrame(DecodeType decodetype)
delete pkt;
errno = -retval;
LOG(VB_GENERAL, LOG_ERR, QString("decoding error") + ENO);
avcodeclock->unlock();
return false;
}
avcodeclock->unlock();

if (waitingForChange && pkt->pos >= readAdjust)
FileChanged();
Expand Down
2 changes: 2 additions & 0 deletions mythtv/libs/libmythtv/nuppeldecoder.cpp
Expand Up @@ -1385,6 +1385,8 @@ void NuppelDecoder::SeekReset(long long newKey, uint skipFrames,
.arg((doFlush) ? "do" : "don't")
.arg((discardFrames) ? "do" : "don't"));

QMutexLocker locker(avcodeclock);

DecoderBase::SeekReset(newKey, skipFrames, doFlush, discardFrames);

if (mpa_vidcodec && doFlush)
Expand Down

0 comments on commit 7e7a78c

Please sign in to comment.