diff options
author | Misael Lopez Cruz <misael.lopez@ti.com> | 2014-01-20 15:34:13 -0600 |
---|---|---|
committer | Misael Lopez Cruz <misael.lopez@ti.com> | 2014-01-22 11:18:40 -0600 |
commit | 46be7175bc6fdbbfad4cb143a69f7417b7066c55 (patch) | |
tree | 2bbc1a09898b1450bfcf90a00a1fecfcee651d93 | |
parent | 00efe94be54a29b25da12d9b3afc3e89499addb2 (diff) | |
download | common-open-46be7175bc6fdbbfad4cb143a69f7417b7066c55.tar.gz |
audio: utils: Add pipe shutdown state
write() call to the mono pipe will block until the pipe has enough
space for the requested data. The shutdown state helps to break
this blocking behavior when the pipe might not have available space
soon (e.g. if the reader is no longer active).
Change-Id: I4f63fbe7e3ec8d20862240faa70368f239dfc251
Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com>
-rw-r--r-- | audio/utils/include/tiaudioutils/MonoPipe.h | 20 | ||||
-rw-r--r-- | audio/utils/src/MonoPipe.cpp | 16 |
2 files changed, 35 insertions, 1 deletions
diff --git a/audio/utils/include/tiaudioutils/MonoPipe.h b/audio/utils/include/tiaudioutils/MonoPipe.h index c0c352b..7fcef8c 100644 --- a/audio/utils/include/tiaudioutils/MonoPipe.h +++ b/audio/utils/include/tiaudioutils/MonoPipe.h @@ -138,6 +138,26 @@ class MonoPipe { */ virtual int availableToWrite() const; + /** + * \brief Shut down the pipe + * + * Shuts down the pipe, causing any blocking write() calls to unblock + * and return. + * + * \param state true if the pipe is to be shutdown, false otherwise + */ + virtual void shutdown(bool state); + + /** + * + * \brief Test if the pipe is shutdown + * + * Tests if the pipe is currently shutdown. + * + * \return true if the pipe is shutdown, false otherwise + */ + virtual bool isShutdown(); + protected: /** Ratio between pipe frame count and params frame count */ static const uint32_t kPipeSizeFactor = 3; diff --git a/audio/utils/src/MonoPipe.cpp b/audio/utils/src/MonoPipe.cpp index 48380ae..e463f79 100644 --- a/audio/utils/src/MonoPipe.cpp +++ b/audio/utils/src/MonoPipe.cpp @@ -110,6 +110,16 @@ int MonoPipe::availableToWrite() const return mSink->availableToWrite(); } +void MonoPipe::shutdown(bool state) +{ + mSink->shutdown(state); +} + +bool MonoPipe::isShutdown() +{ + return mSink->isShutdown(); +} + /* ---------------------------------------------------------------------------------------- */ PipeReader::PipeReader(MonoPipe *pipe) @@ -226,11 +236,11 @@ void PipeWriter::releaseBuffer(BufferProvider::Buffer *buffer) int pending = buffer->frameCount; uint32_t frameSize = mPipe->getParams().frameSize(); uint32_t rate = mPipe->getParams().sampleRate; + uint32_t usecs = (mBuffer.frameCount * 1000 * 1000) / rate; if (!pending) { /* Lessen the number of errors */ ALOGV("PipeWriter: release an empty buffer"); - uint32_t usecs = (mBuffer.frameCount * 1000 * 1000) / rate; usleep(usecs); } @@ -239,6 +249,10 @@ void PipeWriter::releaseBuffer(BufferProvider::Buffer *buffer) if (written < 0) { ALOGE("PipeWriter: failed to write to pipe %d", written); return; + } else if (written == 0) { + usleep(usecs); + if (mPipe->isShutdown()) + break; } pending -= written; buf += written * frameSize; |