Skip to content

Commit

Permalink
correctly check clock type in audio thread
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Jan 13, 2016
1 parent abeb416 commit 452e38c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/AudioThread.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2012-2015 Wang Bin <[email protected]>
Copyright (C) 2012-2016 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -82,7 +82,6 @@ void AudioThread::run()
Q_ASSERT(d.clock != 0);
d.init();
//TODO: bool need_sync in private class
bool is_external_clock = d.clock->clockType() == AVClock::ExternalClock;
Packet pkt;
while (true) {
processNextTask();
Expand Down Expand Up @@ -134,6 +133,7 @@ void AudioThread::run()
pkt = Packet(); //mark invalid to take next
continue;
}
const bool is_external_clock = d.clock->clockType() == AVClock::ExternalClock;
if (is_external_clock) {
d.delay = dts - d.clock->value();
/*
Expand All @@ -143,7 +143,8 @@ void AudioThread::run()
* 2. use last delay when seeking
*/
if (qAbs(d.delay) < 2.0) {
if (d.delay < -kSyncThreshold) { //Speed up. drop frame?
if (d.delay < -kSyncThreshold) { //Speed up. drop frame? resample?
//qDebug("audio is too late compared with external clock. skip decoding. %.3f-%.3f=%.3f", dts, d.clock->value(), d.delay);
//continue;
}
if (d.delay > 0)
Expand All @@ -153,6 +154,7 @@ void AudioThread::run()
msleep(64);
} else {
//audio packet not cleaned up?
qDebug("audio is too late compared with external clock. skip decoding. %.3f-%.3f=%.3f", dts, d.clock->value(), d.delay);
continue;
}
}
Expand Down Expand Up @@ -277,7 +279,8 @@ void AudioThread::run()
QByteArray decodedChunk = QByteArray::fromRawData(decoded.constData() + decodedPos, chunk);
ao->play(decodedChunk, pkt.pts);
//qDebug("ao.timestamp: %.3f", ao->timestamp());
d.clock->updateValue(ao->timestamp());
if (!is_external_clock)
d.clock->updateValue(ao->timestamp());
} else {
d.clock->updateDelay(delay += chunk_delay);
/*
Expand Down

0 comments on commit 452e38c

Please sign in to comment.