summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Kendall <mkendall@mythtv.org>2011-03-16 00:17:43 (GMT)
committer Mark Kendall <mkendall@mythtv.org>2011-03-16 00:17:43 (GMT)
commitdf1df86b62bb6f87de41a65c6d8a17c9ddaae7ca (patch)
tree6a9d643c087c10196246ba421c39cb0a70613a58
parent69b060565f0d4886ca43b2bde2641d170e068249 (diff)
MythPlayer: Fix decoder locking.
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.
-rw-r--r--mythtv/libs/libmythtv/mythdvdplayer.cpp8
-rw-r--r--mythtv/libs/libmythtv/mythplayer.cpp38
2 files changed, 30 insertions, 16 deletions
diff --git a/mythtv/libs/libmythtv/mythdvdplayer.cpp b/mythtv/libs/libmythtv/mythdvdplayer.cpp
index a7825cd..16450c9 100644
--- a/mythtv/libs/libmythtv/mythdvdplayer.cpp
+++ b/mythtv/libs/libmythtv/mythdvdplayer.cpp
@@ -69,9 +69,13 @@ bool MythDVDPlayer::PrebufferEnoughFrames(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)
diff --git a/mythtv/libs/libmythtv/mythplayer.cpp b/mythtv/libs/libmythtv/mythplayer.cpp
index 5797252..7f09f1c 100644
--- a/mythtv/libs/libmythtv/mythplayer.cpp
+++ b/mythtv/libs/libmythtv/mythplayer.cpp
@@ -2816,13 +2816,15 @@ void MythPlayer::DecoderLoop(bool pause)
{
DecoderPauseCheck();
- decoder_change_lock.lock();
+ if (!decoder_change_lock.tryLock(1))
+ continue;
noVideoTracks = allowAudioOnly && !decoder->GetTrackCount(kTrackTypeVideo);
decoder_change_lock.unlock();
if (forcePositionMapSync)
{
- decoder_change_lock.lock();
+ if (!decoder_change_lock.tryLock(1))
+ continue;
if (decoder)
{
forcePositionMapSync = false;
@@ -2833,7 +2835,8 @@ void MythPlayer::DecoderLoop(bool pause)
if (decoderSeek >= 0)
{
- decoder_change_lock.lock();
+ if (!decoder_change_lock.tryLock(1))
+ continue;
if (decoder)
{
decoderSeekLock.lock();
@@ -2928,17 +2931,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;
}
@@ -4547,16 +4552,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();
}
}