forked from wang-bin/QtAV
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
correctly check clock type in audio thread
- Loading branch information
Showing
1 changed file
with
7 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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(); | ||
|
@@ -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(); | ||
/* | ||
|
@@ -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) | ||
|
@@ -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; | ||
} | ||
} | ||
|
@@ -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); | ||
/* | ||
|