summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMisael Lopez Cruz2014-01-20 15:34:13 -0600
committerMisael Lopez Cruz2014-01-22 11:18:40 -0600
commit46be7175bc6fdbbfad4cb143a69f7417b7066c55 (patch)
tree2bbc1a09898b1450bfcf90a00a1fecfcee651d93
parent00efe94be54a29b25da12d9b3afc3e89499addb2 (diff)
downloaddevice-ti-common-open-46be7175bc6fdbbfad4cb143a69f7417b7066c55.tar.gz
device-ti-common-open-46be7175bc6fdbbfad4cb143a69f7417b7066c55.tar.xz
device-ti-common-open-46be7175bc6fdbbfad4cb143a69f7417b7066c55.zip
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.h20
-rw-r--r--audio/utils/src/MonoPipe.cpp16
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 {
138 */ 138 */
139 virtual int availableToWrite() const; 139 virtual int availableToWrite() const;
140 140
141 /**
142 * \brief Shut down the pipe
143 *
144 * Shuts down the pipe, causing any blocking write() calls to unblock
145 * and return.
146 *
147 * \param state true if the pipe is to be shutdown, false otherwise
148 */
149 virtual void shutdown(bool state);
150
151 /**
152 *
153 * \brief Test if the pipe is shutdown
154 *
155 * Tests if the pipe is currently shutdown.
156 *
157 * \return true if the pipe is shutdown, false otherwise
158 */
159 virtual bool isShutdown();
160
141 protected: 161 protected:
142 /** Ratio between pipe frame count and params frame count */ 162 /** Ratio between pipe frame count and params frame count */
143 static const uint32_t kPipeSizeFactor = 3; 163 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
110 return mSink->availableToWrite(); 110 return mSink->availableToWrite();
111} 111}
112 112
113void MonoPipe::shutdown(bool state)
114{
115 mSink->shutdown(state);
116}
117
118bool MonoPipe::isShutdown()
119{
120 return mSink->isShutdown();
121}
122
113/* ---------------------------------------------------------------------------------------- */ 123/* ---------------------------------------------------------------------------------------- */
114 124
115PipeReader::PipeReader(MonoPipe *pipe) 125PipeReader::PipeReader(MonoPipe *pipe)
@@ -226,11 +236,11 @@ void PipeWriter::releaseBuffer(BufferProvider::Buffer *buffer)
226 int pending = buffer->frameCount; 236 int pending = buffer->frameCount;
227 uint32_t frameSize = mPipe->getParams().frameSize(); 237 uint32_t frameSize = mPipe->getParams().frameSize();
228 uint32_t rate = mPipe->getParams().sampleRate; 238 uint32_t rate = mPipe->getParams().sampleRate;
239 uint32_t usecs = (mBuffer.frameCount * 1000 * 1000) / rate;
229 240
230 if (!pending) { 241 if (!pending) {
231 /* Lessen the number of errors */ 242 /* Lessen the number of errors */
232 ALOGV("PipeWriter: release an empty buffer"); 243 ALOGV("PipeWriter: release an empty buffer");
233 uint32_t usecs = (mBuffer.frameCount * 1000 * 1000) / rate;
234 usleep(usecs); 244 usleep(usecs);
235 } 245 }
236 246
@@ -239,6 +249,10 @@ void PipeWriter::releaseBuffer(BufferProvider::Buffer *buffer)
239 if (written < 0) { 249 if (written < 0) {
240 ALOGE("PipeWriter: failed to write to pipe %d", written); 250 ALOGE("PipeWriter: failed to write to pipe %d", written);
241 return; 251 return;
252 } else if (written == 0) {
253 usleep(usecs);
254 if (mPipe->isShutdown())
255 break;
242 } 256 }
243 pending -= written; 257 pending -= written;
244 buf += written * frameSize; 258 buf += written * frameSize;