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.
ao: add drain(), reset() to clear buffers
TODO: call backend api
- Loading branch information
Showing
2 changed files
with
25 additions
and
5 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 | ||
|
@@ -88,6 +88,8 @@ class Q_AV_EXPORT AudioOutput : public QObject, public AVOutput | |
* backend name currently in use | ||
*/ | ||
QString backend() const; | ||
bool drain(); | ||
void reset(); //drain and set audio time 0 | ||
bool open(); | ||
bool close(); | ||
bool isOpen() const; | ||
|
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 | ||
|
@@ -151,7 +151,6 @@ class AudioOutputPrivate : public AVOutputPrivate | |
cond.wait(&mutex, (us+500LL)/1000LL); | ||
} | ||
|
||
int bufferSizeTotal() { return nb_buffers * buffer_size; } | ||
struct FrameInfo { | ||
FrameInfo(qreal t = 0, int s = 0) : timestamp(t), data_size(s) {} | ||
qreal timestamp; | ||
|
@@ -352,6 +351,23 @@ QString AudioOutput::backend() const | |
return QString(); | ||
} | ||
|
||
bool AudioOutput::drain() | ||
{ | ||
DPTR_D(AudioOutput); | ||
// TODO: backend drain | ||
while (!d.frame_infos.empty()) { | ||
waitForNextBuffer(); | ||
} | ||
return true; | ||
} | ||
|
||
void AudioOutput::reset() | ||
{ | ||
drain(); | ||
DPTR_D(AudioOutput); | ||
d.resetStatus(); | ||
} | ||
|
||
bool AudioOutput::open() | ||
{ | ||
DPTR_D(AudioOutput); | ||
|
@@ -611,6 +627,8 @@ AudioOutput::DeviceFeatures AudioOutput::supportedDeviceFeatures() const | |
bool AudioOutput::waitForNextBuffer() | ||
{ | ||
DPTR_D(AudioOutput); | ||
if (d.frame_infos.empty()) | ||
return true; | ||
if (!d.backend) | ||
return false; | ||
//don't return even if we can add buffer because we don't know when a buffer is processed and we have /to update dequeue index | ||
|
@@ -665,7 +683,7 @@ bool AudioOutput::waitForNextBuffer() | |
while (!no_wait && d.processed_remain < next) { | ||
const qint64 us = d.format.durationForBytes(next - d.processed_remain); | ||
if (us < 1000LL) | ||
d.uwait(10000LL); | ||
d.uwait(1000LL); | ||
else | ||
d.uwait(us); | ||
d.processed_remain = d.backend->getPlayedBytes(); | ||
|
@@ -689,7 +707,7 @@ bool AudioOutput::waitForNextBuffer() | |
if (elapsed > 0 && us > elapsed*1000LL) | ||
us -= elapsed*1000LL; | ||
if (us < 1000LL) | ||
us = 10000LL; //opensl crash if 1 | ||
us = 1000LL; //opensl crash if 1ms | ||
#endif //AO_USE_TIMER | ||
d.uwait(us); | ||
c = d.backend->getPlayedCount(); | ||
|