summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorMisael Lopez Cruz2014-01-28 14:06:45 -0600
committerMisael Lopez Cruz2014-01-30 17:05:44 -0600
commit7c835cd660854083860e2ee8793ab6b5dff84c21 (patch)
tree0387420e7e4dcf1677091e6779b2b7e97dd0daad /audio
parent46be7175bc6fdbbfad4cb143a69f7417b7066c55 (diff)
downloaddevice-ti-common-open-7c835cd660854083860e2ee8793ab6b5dff84c21.tar.gz
device-ti-common-open-7c835cd660854083860e2ee8793ab6b5dff84c21.tar.xz
device-ti-common-open-7c835cd660854083860e2ee8793ab6b5dff84c21.zip
audio: utils: Add flush() and size() methods to MonoPipe
Add two new methods to the MonoPipe class: - flush(): Flushes the audio frames available in the pipe. It should be called when te pipe is already in shutdown state to ensure that no more new data is pushed. - size(): Queries the pipe size. Change-Id: Ia8c2ac287a475bd3e72f48368d297fc544b19eed Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com>
Diffstat (limited to 'audio')
-rw-r--r--audio/utils/include/tiaudioutils/MonoPipe.h21
-rw-r--r--audio/utils/src/MonoPipe.cpp28
2 files changed, 49 insertions, 0 deletions
diff --git a/audio/utils/include/tiaudioutils/MonoPipe.h b/audio/utils/include/tiaudioutils/MonoPipe.h
index 7fcef8c..8445ddc 100644
--- a/audio/utils/include/tiaudioutils/MonoPipe.h
+++ b/audio/utils/include/tiaudioutils/MonoPipe.h
@@ -139,6 +139,27 @@ class MonoPipe {
139 virtual int availableToWrite() const; 139 virtual int availableToWrite() const;
140 140
141 /** 141 /**
142 * \brief Query the size of the pipe
143 *
144 * Queries the size of the pipe. It might be different to the requested
145 * number of frames if the pipe implementation relies does size rounding.
146 *
147 * \return Size of the pipe (in frames)
148 */
149 virtual size_t size() const;
150
151 /**
152 * \brief Flush the pipe
153 *
154 * Flushes all frames present in the pipe. It should be called when the
155 * pipe is in shutdown state to ensure no new data is written to the
156 * pipe.
157 *
158 * \return 0 on success, otherwise negative error code
159 */
160 virtual int flush();
161
162 /**
142 * \brief Shut down the pipe 163 * \brief Shut down the pipe
143 * 164 *
144 * Shuts down the pipe, causing any blocking write() calls to unblock 165 * Shuts down the pipe, causing any blocking write() calls to unblock
diff --git a/audio/utils/src/MonoPipe.cpp b/audio/utils/src/MonoPipe.cpp
index e463f79..be021f1 100644
--- a/audio/utils/src/MonoPipe.cpp
+++ b/audio/utils/src/MonoPipe.cpp
@@ -110,6 +110,34 @@ int MonoPipe::availableToWrite() const
110 return mSink->availableToWrite(); 110 return mSink->availableToWrite();
111} 111}
112 112
113size_t MonoPipe::size() const
114{
115 return mSink->maxFrames();
116}
117
118int MonoPipe::flush()
119{
120 ALOGW_IF(!isShutdown(), "MonoPipe: flushing while not in shutdown state");
121
122 int avail = availableToRead();
123 int16_t buffer[mParams.channels * avail];
124
125 /* Read all frames still present in the pipe */
126 while (avail > 0) {
127 int ret = read(buffer, avail);
128 if (ret < 0) {
129 ALOGE("MonoPipe: failed to flush the pipe %d", ret);
130 return ret;
131 }
132 avail -= ret;
133 }
134
135 avail = availableToRead();
136 ALOGW_IF(avail, "MonoPipe: %d frames were not flushed", avail);
137
138 return 0;
139}
140
113void MonoPipe::shutdown(bool state) 141void MonoPipe::shutdown(bool state)
114{ 142{
115 mSink->shutdown(state); 143 mSink->shutdown(state);