summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMisael Lopez Cruz2013-12-10 02:48:39 -0600
committerMisael Lopez Cruz2014-01-13 17:36:14 -0600
commite926655ecbaf438e054ba1f2452be3b9768efe51 (patch)
tree8279d32f6583388a35d0d740746ab466b70440fb
parent0e9b0a6d2cc67b7822dd625f60070cfe75b6558b (diff)
downloaddevice-ti-common-open-e926655ecbaf438e054ba1f2452be3b9768efe51.tar.gz
device-ti-common-open-e926655ecbaf438e054ba1f2452be3b9768efe51.tar.xz
device-ti-common-open-e926655ecbaf438e054ba1f2452be3b9768efe51.zip
audio: utils: Add PCM start and stop
PCM start and stop is mostly needed for hostless ports, since they require to be explicitly started/stopped. PCM stop can also be used to unblock read() or write() calls. Change-Id: Ie651d90933022df754c582a89733d607101ea585 Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com>
-rw-r--r--audio/utils/include/tiaudioutils/ALSAPcm.h50
-rw-r--r--audio/utils/include/tiaudioutils/NullPcm.h40
-rw-r--r--audio/utils/include/tiaudioutils/Pcm.h20
-rw-r--r--audio/utils/src/ALSAPcm.cpp52
4 files changed, 162 insertions, 0 deletions
diff --git a/audio/utils/include/tiaudioutils/ALSAPcm.h b/audio/utils/include/tiaudioutils/ALSAPcm.h
index 830e304..030db84 100644
--- a/audio/utils/include/tiaudioutils/ALSAPcm.h
+++ b/audio/utils/include/tiaudioutils/ALSAPcm.h
@@ -116,6 +116,31 @@ class ALSAInPort : public PcmInPort {
116 */ 116 */
117 int read(void *buffer, size_t frames); 117 int read(void *buffer, size_t frames);
118 118
119 /**
120 * \brief Start the ALSA PCM port
121 *
122 * Starts the ALSA PCM capture port. It's mostly needed to start hostless
123 * ports that don't use read() but instead run without CPU intervention.
124 * Regular PCM read through read() method doesn't need to be explicitly
125 * preceded by start(), since it's done internally.
126 *
127 * \return 0 on success, otherwise negative error code
128 */
129 int start();
130
131 /**
132 * \brief Stop the ALSA PCM port
133 *
134 * Stops the ALSA PCM capture port. It's mostly needed to stop hostless
135 * ports that don't use read() but instead run without CPU intervention.
136 * Regular PCM read through read() method doesn't need to be explicitly
137 * stopped, but if done, it will cause read() to immediately return.
138 * This behavior can be desired to unblock read() calls.
139 *
140 * \return 0 on success, otherwise negative error code
141 */
142 int stop();
143
119 /** Default number of periods for the tinyalsa config of the capture port */ 144 /** Default number of periods for the tinyalsa config of the capture port */
120 static const uint32_t kDefaultNumPeriods = 3; 145 static const uint32_t kDefaultNumPeriods = 3;
121 146
@@ -215,6 +240,31 @@ class ALSAOutPort : public PcmOutPort {
215 */ 240 */
216 int write(const void *buffer, size_t frames); 241 int write(const void *buffer, size_t frames);
217 242
243 /**
244 * \brief Start the ALSA PCM port
245 *
246 * Starts the ALSA PCM playback port. It's mostly needed to start hostless
247 * ports that don't use write() but instead run without CPU intervention.
248 * Regular PCM write through write() method doesn't need to be explicitly
249 * preceded by start(), since it's done internally.
250 *
251 * \return 0 on success, otherwise negative error code
252 */
253 int start();
254
255 /**
256 * \brief Stop the ALSA PCM port
257 *
258 * Stops the ALSA PCM playback port. It's mostly needed to stop hostless
259 * ports that don't use write() but instead run without CPU intervention.
260 * Regular PCM write through write() method doesn't need to be explicitly
261 * stopped, but if done, it will cause write() to immediately return.
262 * This behavior can be desired to unblock write() calls.
263 *
264 * \return 0 on success, otherwise negative error code
265 */
266 int stop();
267
218 /** Default number of periods for the tinyalsa config of the playback port */ 268 /** Default number of periods for the tinyalsa config of the playback port */
219 static const uint32_t kDefaultNumPeriods = 4; 269 static const uint32_t kDefaultNumPeriods = 4;
220 270
diff --git a/audio/utils/include/tiaudioutils/NullPcm.h b/audio/utils/include/tiaudioutils/NullPcm.h
index 8995759..977faaa 100644
--- a/audio/utils/include/tiaudioutils/NullPcm.h
+++ b/audio/utils/include/tiaudioutils/NullPcm.h
@@ -118,6 +118,26 @@ class NullInPort : public PcmInPort {
118 */ 118 */
119 int read(void *buffer, size_t frames); 119 int read(void *buffer, size_t frames);
120 120
121 /**
122 * \brief Start the null PCM port
123 *
124 * Starts the null PCM capture port. No meaningful action is performed
125 * by this method.
126 *
127 * \return 0 on success, otherwise negative error code
128 */
129 int start() { return 0; }
130
131 /**
132 * \brief Stop the null PCM port
133 *
134 * Stops the null PCM capture port. No meaningful action is performed
135 * by this method.
136 *
137 * \return 0 on success, otherwise negative error code
138 */
139 int stop() { return 0; }
140
121 private: 141 private:
122 NullInPort(const NullInPort &port); 142 NullInPort(const NullInPort &port);
123 NullInPort& operator=(const NullInPort &port); 143 NullInPort& operator=(const NullInPort &port);
@@ -215,6 +235,26 @@ class NullOutPort : public PcmOutPort {
215 */ 235 */
216 int write(const void *buffer, size_t frames); 236 int write(const void *buffer, size_t frames);
217 237
238 /**
239 * \brief Start the null PCM port
240 *
241 * Starts the null PCM playback port. No meaningful action is performed
242 * by this method.
243 *
244 * \return 0 on success, otherwise negative error code
245 */
246 int start() { return 0; }
247
248 /**
249 * \brief Stop the null PCM port
250 *
251 * Stops the null PCM playback port. No meaningful action is performed
252 * by this method.
253 *
254 * \return 0 on success, otherwise negative error code
255 */
256 int stop() { return 0; }
257
218 private: 258 private:
219 NullOutPort(const NullOutPort &port); 259 NullOutPort(const NullOutPort &port);
220 NullOutPort& operator=(const NullOutPort &port); 260 NullOutPort& operator=(const NullOutPort &port);
diff --git a/audio/utils/include/tiaudioutils/Pcm.h b/audio/utils/include/tiaudioutils/Pcm.h
index a086d36..7d3ecd8 100644
--- a/audio/utils/include/tiaudioutils/Pcm.h
+++ b/audio/utils/include/tiaudioutils/Pcm.h
@@ -312,6 +312,26 @@ class PcmPort {
312 * \return true if port is open, false otherwise 312 * \return true if port is open, false otherwise
313 */ 313 */
314 virtual bool isOpen() const = 0; 314 virtual bool isOpen() const = 0;
315
316 /**
317 * \brief Start the PCM port
318 *
319 * Starts the PCM port. It's mostly needed to start hostless ports that
320 * run without CPU intervention.
321 *
322 * \return 0 on success, otherwise negative error code
323 */
324 virtual int start() = 0;
325
326 /**
327 * \brief Stop the PCM port
328 *
329 * Stops the PCM capture port. It's mostly needed to stop hostless that
330 * run without CPU intervention.
331 *
332 * \return 0 on success, otherwise negative error code
333 */
334 virtual int stop() = 0;
315}; 335};
316 336
317/** 337/**
diff --git a/audio/utils/src/ALSAPcm.cpp b/audio/utils/src/ALSAPcm.cpp
index 37d6833..cea2199 100644
--- a/audio/utils/src/ALSAPcm.cpp
+++ b/audio/utils/src/ALSAPcm.cpp
@@ -115,6 +115,32 @@ int ALSAInPort::read(void *buffer, size_t frames)
115 return frames; 115 return frames;
116} 116}
117 117
118int ALSAInPort::start()
119{
120 AutoMutex lock(mLock);
121
122 if (!mPcm || !pcm_is_ready(mPcm)) {
123 ALOGE("ALSAInPort: port hw:%u,%u is closed, cannot start", mCardId, mPortId);
124 return -EAGAIN;
125 }
126
127 return pcm_start(mPcm);
128}
129
130int ALSAInPort::stop()
131{
132 /*
133 * mLock is not acquired here because stop() is mostly needed to break
134 * blocked reads which runs with mLock held
135 */
136 if (!mPcm || !pcm_is_ready(mPcm)) {
137 ALOGE("ALSAInPort: port hw:%u,%u is closed, cannot stop", mCardId, mPortId);
138 return -EAGAIN;
139 }
140
141 return pcm_stop(mPcm);
142}
143
118/* ---------------------------------------------------------------------------------------- */ 144/* ---------------------------------------------------------------------------------------- */
119 145
120ALSAOutPort::ALSAOutPort(uint32_t card, uint32_t port, uint32_t period_count) 146ALSAOutPort::ALSAOutPort(uint32_t card, uint32_t port, uint32_t period_count)
@@ -207,4 +233,30 @@ int ALSAOutPort::write(const void *buffer, size_t frames)
207 return frames; 233 return frames;
208} 234}
209 235
236int ALSAOutPort::start()
237{
238 AutoMutex lock(mLock);
239
240 if (!mPcm || !pcm_is_ready(mPcm)) {
241 ALOGE("ALSAOutPort: port hw:%u,%u is closed, cannot start", mCardId, mPortId);
242 return -EAGAIN;
243 }
244
245 return pcm_start(mPcm);
246}
247
248int ALSAOutPort::stop()
249{
250 /*
251 * mLock is not acquired here because stop() is mostly needed to break
252 * blocked writes which runs with mLock held
253 */
254 if (!mPcm || !pcm_is_ready(mPcm)) {
255 ALOGE("ALSAOutPort: port hw:%u,%u is closed, cannot stop", mCardId, mPortId);
256 return -EAGAIN;
257 }
258
259 return pcm_stop(mPcm);
260}
261
210} /* namespace tiaudioutils */ 262} /* namespace tiaudioutils */