summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMisael Lopez Cruz2013-11-08 01:18:42 -0600
committerMisael Lopez Cruz2013-11-11 13:01:17 -0600
commit2c752c915aa52925cec575b26f8b221eb524c0ce (patch)
tree5643c4bf72feb77ff613f75d429b006ee73093be
parentd923350772d91d452f8f323d53365920399d635e (diff)
downloaddevice-ti-common-open-2c752c915aa52925cec575b26f8b221eb524c0ce.tar.gz
device-ti-common-open-2c752c915aa52925cec575b26f8b221eb524c0ce.tar.xz
device-ti-common-open-2c752c915aa52925cec575b26f8b221eb524c0ce.zip
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)
143 143
144 int8_t *buf = mBuffer.i8; 144 int8_t *buf = mBuffer.i8;
145 int pending = buffer->frameCount; 145 int pending = buffer->frameCount;
146 bool xrun = false;
146 147
147 while (pending > 0) { 148 while (pending > 0) {
148 int read = mPipe->read(buf, pending); 149 int read = mPipe->read(buf, pending);
@@ -151,7 +152,7 @@ int PipeReader::getNextBuffer(BufferProvider::Buffer *buffer)
151 buffer->frameCount = 0; 152 buffer->frameCount = 0;
152 return read; 153 return read;
153 } else if (read == 0) { 154 } else if (read == 0) {
154 ALOGW("PipeReader: underrun!"); 155 xrun = true;
155 break; 156 break;
156 } else { 157 } else {
157 pending -= read; 158 pending -= read;
@@ -159,7 +160,8 @@ int PipeReader::getNextBuffer(BufferProvider::Buffer *buffer)
159 } 160 }
160 } 161 }
161 162
162 ALOGW_IF(pending, "PipeReader: unexpected %u pending frames", pending); 163 ALOGW_IF(pending, "PipeReader: %s %u pending frames",
164 xrun ? "underrun!" : "unexpected", pending);
163 165
164 buffer->frameCount -= pending; 166 buffer->frameCount -= pending;
165 buffer->raw = mBuffer.raw; 167 buffer->raw = mBuffer.raw;
@@ -172,7 +174,14 @@ int PipeReader::getNextBuffer(BufferProvider::Buffer *buffer)
172 174
173void PipeReader::releaseBuffer(BufferProvider::Buffer *buffer) 175void PipeReader::releaseBuffer(BufferProvider::Buffer *buffer)
174{ 176{
175 /* Nothing to do to release the buffer, but must be implemented */ 177 uint32_t rate = mPipe->getParams().sampleRate;
178
179 if (!buffer->frameCount) {
180 /* Lessen the number of errors */
181 ALOGV("PipeReader: release an empty buffer");
182 uint32_t usecs = (mBuffer.frameCount * 1000 * 1000) / rate;
183 usleep(usecs);
184 }
176} 185}
177 186
178/* ---------------------------------------------------------------------------------------- */ 187/* ---------------------------------------------------------------------------------------- */
@@ -216,6 +225,14 @@ void PipeWriter::releaseBuffer(BufferProvider::Buffer *buffer)
216 int8_t *buf = buffer->i8; 225 int8_t *buf = buffer->i8;
217 int pending = buffer->frameCount; 226 int pending = buffer->frameCount;
218 uint32_t frameSize = mPipe->getParams().frameSize(); 227 uint32_t frameSize = mPipe->getParams().frameSize();
228 uint32_t rate = mPipe->getParams().sampleRate;
229
230 if (!pending) {
231 /* Lessen the number of errors */
232 ALOGV("PipeWriter: release an empty buffer");
233 uint32_t usecs = (mBuffer.frameCount * 1000 * 1000) / rate;
234 usleep(usecs);
235 }
219 236
220 while (pending > 0) { 237 while (pending > 0) {
221 int written = mPipe->write(buf, pending); 238 int written = mPipe->write(buf, pending);