summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMisael Lopez Cruz <misael.lopez@ti.com>2013-11-08 01:18:42 -0600
committerMisael Lopez Cruz <misael.lopez@ti.com>2013-11-11 13:01:17 -0600
commit2c752c915aa52925cec575b26f8b221eb524c0ce (patch)
tree5643c4bf72feb77ff613f75d429b006ee73093be
parentd923350772d91d452f8f323d53365920399d635e (diff)
downloadcommon-open-2c752c915aa52925cec575b26f8b221eb524c0ce.tar.gz
audio: utils: Lessen number of errors in pipe providers
Lessen the number of errors in pipe providers (PipeReader and PipeWriter) by sleeping the equivalent time of the provider's buffer size. That helps to keep on retrying to get buffers from a provider that may be in a bad state (e.g. underrun) and to give chance to other threads to run. Change-Id: Ia643b681ed4ffca2958dd3808515c3bbc91acbad Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com>
-rw-r--r--audio/utils/src/MonoPipe.cpp23
1 files changed, 20 insertions, 3 deletions
diff --git a/audio/utils/src/MonoPipe.cpp b/audio/utils/src/MonoPipe.cpp
index 9889c7a..48380ae 100644
--- a/audio/utils/src/MonoPipe.cpp
+++ b/audio/utils/src/MonoPipe.cpp
@@ -143,6 +143,7 @@ int PipeReader::getNextBuffer(BufferProvider::Buffer *buffer)
int8_t *buf = mBuffer.i8;
int pending = buffer->frameCount;
+ bool xrun = false;
while (pending > 0) {
int read = mPipe->read(buf, pending);
@@ -151,7 +152,7 @@ int PipeReader::getNextBuffer(BufferProvider::Buffer *buffer)
buffer->frameCount = 0;
return read;
} else if (read == 0) {
- ALOGW("PipeReader: underrun!");
+ xrun = true;
break;
} else {
pending -= read;
@@ -159,7 +160,8 @@ int PipeReader::getNextBuffer(BufferProvider::Buffer *buffer)
}
}
- ALOGW_IF(pending, "PipeReader: unexpected %u pending frames", pending);
+ ALOGW_IF(pending, "PipeReader: %s %u pending frames",
+ xrun ? "underrun!" : "unexpected", pending);
buffer->frameCount -= pending;
buffer->raw = mBuffer.raw;
@@ -172,7 +174,14 @@ int PipeReader::getNextBuffer(BufferProvider::Buffer *buffer)
void PipeReader::releaseBuffer(BufferProvider::Buffer *buffer)
{
- /* Nothing to do to release the buffer, but must be implemented */
+ uint32_t rate = mPipe->getParams().sampleRate;
+
+ if (!buffer->frameCount) {
+ /* Lessen the number of errors */
+ ALOGV("PipeReader: release an empty buffer");
+ uint32_t usecs = (mBuffer.frameCount * 1000 * 1000) / rate;
+ usleep(usecs);
+ }
}
/* ---------------------------------------------------------------------------------------- */
@@ -216,6 +225,14 @@ void PipeWriter::releaseBuffer(BufferProvider::Buffer *buffer)
int8_t *buf = buffer->i8;
int pending = buffer->frameCount;
uint32_t frameSize = mPipe->getParams().frameSize();
+ uint32_t rate = mPipe->getParams().sampleRate;
+
+ if (!pending) {
+ /* Lessen the number of errors */
+ ALOGV("PipeWriter: release an empty buffer");
+ uint32_t usecs = (mBuffer.frameCount * 1000 * 1000) / rate;
+ usleep(usecs);
+ }
while (pending > 0) {
int written = mPipe->write(buf, pending);