From bd238105d0bd2f8a3e97af132a8eb022038ca149 Mon Sep 17 00:00:00 2001 From: wang-bin Date: Tue, 1 Jan 2013 22:40:10 +0800 Subject: [PATCH] video thread sleep a little to wait the audio if not, video thread will loop many times in a small time. sleep some million seconds is ok. --- src/VideoThread.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/VideoThread.cpp b/src/VideoThread.cpp index f624fc42..8be4e530 100644 --- a/src/VideoThread.cpp +++ b/src/VideoThread.cpp @@ -93,6 +93,7 @@ void VideoThread::run() if (qAbs(d.delay) < 2.718) { if (d.delay > kSyncThreshold) { //Slow down //d.delay_cond.wait(&d.mutex, d.delay*1000); //replay may fail. why? + //qDebug("~~~~~wating for %f msecs", d.delay*1000); usleep(d.delay * 1000000); } else if (d.delay < -kSyncThreshold) { //Speed up. drop frame? //d.mutex.unlock(); @@ -100,9 +101,13 @@ void VideoThread::run() } } else { //when to drop off? qDebug("delay %f", d.delay); - //audio packet not cleaned up? - //d.mutex.unlock(); - //continue; + if (d.delay > 0) { + msleep(64); + } else { + //audio packet not cleaned up? + d.mutex.unlock(); + continue; + } } d.clock->updateVideoPts(pkt.pts); //here? if (d.dec->decode(pkt.data)) {