summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMisael Lopez Cruz2013-11-08 01:14:07 -0600
committerMisael Lopez Cruz2013-11-11 13:01:16 -0600
commitd923350772d91d452f8f323d53365920399d635e (patch)
treed5c1f83a92cc035919c6420480e0b5d1fe9695c6
parent9da7b006e3a17b97815a86d8487c2b9dc7b374cf (diff)
downloaddevice-ti-common-open-d923350772d91d452f8f323d53365920399d635e.tar.gz
device-ti-common-open-d923350772d91d452f8f323d53365920399d635e.tar.xz
device-ti-common-open-d923350772d91d452f8f323d53365920399d635e.zip
audio: utils: Unify error reporting in buffer providers
Use a consistent error reporting mechanism for buffer providers, specifically in getNextBuffer(): frameCount is set to 0 and the appropriate error code is returned. Change-Id: I3a865b95ccabbde982f5c62ba713a80d0a6f561f Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com>
-rw-r--r--audio/utils/src/MonoPipe.cpp11
-rw-r--r--audio/utils/src/MumStream.cpp2
-rw-r--r--audio/utils/src/SimpleStream.cpp10
3 files changed, 19 insertions, 4 deletions
diff --git a/audio/utils/src/MonoPipe.cpp b/audio/utils/src/MonoPipe.cpp
index 7cf4d94..9889c7a 100644
--- a/audio/utils/src/MonoPipe.cpp
+++ b/audio/utils/src/MonoPipe.cpp
@@ -126,6 +126,7 @@ PipeReader::~PipeReader()
126int PipeReader::getNextBuffer(BufferProvider::Buffer *buffer) 126int PipeReader::getNextBuffer(BufferProvider::Buffer *buffer)
127{ 127{
128 uint32_t frameSize = mPipe->getParams().frameSize(); 128 uint32_t frameSize = mPipe->getParams().frameSize();
129 int ret = 0;
129 130
130 /* resize our internal buffer if needed */ 131 /* resize our internal buffer if needed */
131 if (mBuffer.frameCount < buffer->frameCount) { 132 if (mBuffer.frameCount < buffer->frameCount) {
@@ -134,6 +135,7 @@ int PipeReader::getNextBuffer(BufferProvider::Buffer *buffer)
134 mBuffer.i8 = new int8_t[buffer->frameCount * frameSize]; 135 mBuffer.i8 = new int8_t[buffer->frameCount * frameSize];
135 if (mBuffer.i8 == NULL) { 136 if (mBuffer.i8 == NULL) {
136 ALOGE("PipeReader: failed to resize internal buffer"); 137 ALOGE("PipeReader: failed to resize internal buffer");
138 buffer->frameCount = 0;
137 return -ENOMEM; 139 return -ENOMEM;
138 } 140 }
139 mBuffer.frameCount = buffer->frameCount; 141 mBuffer.frameCount = buffer->frameCount;
@@ -146,6 +148,7 @@ int PipeReader::getNextBuffer(BufferProvider::Buffer *buffer)
146 int read = mPipe->read(buf, pending); 148 int read = mPipe->read(buf, pending);
147 if (read < 0) { 149 if (read < 0) {
148 ALOGE("PipeReader: failed to read from pipe %d", read); 150 ALOGE("PipeReader: failed to read from pipe %d", read);
151 buffer->frameCount = 0;
149 return read; 152 return read;
150 } else if (read == 0) { 153 } else if (read == 0) {
151 ALOGW("PipeReader: underrun!"); 154 ALOGW("PipeReader: underrun!");
@@ -156,12 +159,15 @@ int PipeReader::getNextBuffer(BufferProvider::Buffer *buffer)
156 } 159 }
157 } 160 }
158 161
162 ALOGW_IF(pending, "PipeReader: unexpected %u pending frames", pending);
163
159 buffer->frameCount -= pending; 164 buffer->frameCount -= pending;
160 buffer->raw = mBuffer.raw; 165 buffer->raw = mBuffer.raw;
161 166
162 ALOGW_IF(pending, "PipeReader: unexpected %u pending frames", pending); 167 if (!buffer->frameCount)
168 ret = -EAGAIN;
163 169
164 return 0; 170 return ret;
165} 171}
166 172
167void PipeReader::releaseBuffer(BufferProvider::Buffer *buffer) 173void PipeReader::releaseBuffer(BufferProvider::Buffer *buffer)
@@ -193,6 +199,7 @@ int PipeWriter::getNextBuffer(BufferProvider::Buffer *buffer)
193 mBuffer.i8 = new int8_t[buffer->frameCount * frameSize]; 199 mBuffer.i8 = new int8_t[buffer->frameCount * frameSize];
194 if (mBuffer.i8 == NULL) { 200 if (mBuffer.i8 == NULL) {
195 ALOGE("PipeWriter: failed to resize internal buffer"); 201 ALOGE("PipeWriter: failed to resize internal buffer");
202 buffer->frameCount = 0;
196 return -ENOMEM; 203 return -ENOMEM;
197 } 204 }
198 mBuffer.frameCount = buffer->frameCount; 205 mBuffer.frameCount = buffer->frameCount;
diff --git a/audio/utils/src/MumStream.cpp b/audio/utils/src/MumStream.cpp
index b49e188..618d602 100644
--- a/audio/utils/src/MumStream.cpp
+++ b/audio/utils/src/MumStream.cpp
@@ -221,6 +221,7 @@ int Merge::process(BufferProvider::Buffer &outBuffer)
221 ALOGE("Merge: cannot merge 0 frame stream"); 221 ALOGE("Merge: cannot merge 0 frame stream");
222 /* Set error here, so can be propogated to the user */ 222 /* Set error here, so can be propogated to the user */
223 inBuffer.i32 = (int32_t*)(-EINVAL); 223 inBuffer.i32 = (int32_t*)(-EINVAL);
224 inBuffer.frameCount = 0;
224 } 225 }
225 else if (outBuffer.frameCount != inBuffer.frameCount) { 226 else if (outBuffer.frameCount != inBuffer.frameCount) {
226 ALOGE("Merge: unable to process whole stream, not enough frames." 227 ALOGE("Merge: unable to process whole stream, not enough frames."
@@ -428,6 +429,7 @@ int UnMerge::process(BufferProvider::Buffer &inBuffer)
428 ALOGE("UnMerge: cannot unmerge 0 frames"); 429 ALOGE("UnMerge: cannot unmerge 0 frames");
429 /* Set error here, so can be propogated to the user */ 430 /* Set error here, so can be propogated to the user */
430 outBuffer.i32 = (int32_t*)(-EINVAL); 431 outBuffer.i32 = (int32_t*)(-EINVAL);
432 outBuffer.frameCount = 0;
431 } 433 }
432 else if (inBuffer.frameCount > outBuffer.frameCount) { 434 else if (inBuffer.frameCount > outBuffer.frameCount) {
433 ALOGE("UnMerge: unable to process whole stream, not enough frames." 435 ALOGE("UnMerge: unable to process whole stream, not enough frames."
diff --git a/audio/utils/src/SimpleStream.cpp b/audio/utils/src/SimpleStream.cpp
index c3f262f..5038e59 100644
--- a/audio/utils/src/SimpleStream.cpp
+++ b/audio/utils/src/SimpleStream.cpp
@@ -390,12 +390,15 @@ int SimpleReader::read(void *buffer, size_t frames)
390 390
391int SimpleReader::ReadProvider::getNextBuffer(BufferProvider::Buffer *buffer) 391int SimpleReader::ReadProvider::getNextBuffer(BufferProvider::Buffer *buffer)
392{ 392{
393 int ret = 0;
394
393 /* resize buffer if needed */ 395 /* resize buffer if needed */
394 if (buffer->frameCount > mReader.mBuffer.frameCount) { 396 if (buffer->frameCount > mReader.mBuffer.frameCount) {
395 delete [] mReader.mBuffer.i8; 397 delete [] mReader.mBuffer.i8;
396 mReader.mBuffer.i8 = new int8_t[buffer->frameCount * mReader.mParams.frameSize()]; 398 mReader.mBuffer.i8 = new int8_t[buffer->frameCount * mReader.mParams.frameSize()];
397 if (mReader.mBuffer.i8) { 399 if (mReader.mBuffer.i8) {
398 ALOGE("SimpleReader: failed to resize internal buffer"); 400 ALOGE("SimpleReader: failed to resize internal buffer");
401 buffer->frameCount = 0;
399 return -ENOMEM; 402 return -ENOMEM;
400 } 403 }
401 mReader.mBuffer.frameCount = buffer->frameCount; 404 mReader.mBuffer.frameCount = buffer->frameCount;
@@ -413,12 +416,15 @@ int SimpleReader::ReadProvider::getNextBuffer(BufferProvider::Buffer *buffer)
413 curBuffer += read * mReader.mParams.frameSize(); 416 curBuffer += read * mReader.mParams.frameSize();
414 } 417 }
415 418
419 ALOGW_IF(pending, "SimpleReader: could not read %d frames", pending);
420
416 buffer->raw = mReader.mBuffer.raw; 421 buffer->raw = mReader.mBuffer.raw;
417 buffer->frameCount -= pending; 422 buffer->frameCount -= pending;
418 423
419 ALOGW_IF(pending, "SimpleReader: could not read %d frames", pending); 424 if (!buffer->frameCount)
425 ret = -EAGAIN;
420 426
421 return 0; 427 return ret;
422} 428}
423 429
424void SimpleReader::ReadProvider::releaseBuffer(BufferProvider::Buffer *buffer) 430void SimpleReader::ReadProvider::releaseBuffer(BufferProvider::Buffer *buffer)