summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMisael Lopez Cruz2014-01-20 13:10:20 -0600
committerMisael Lopez Cruz2014-01-22 11:18:36 -0600
commit00efe94be54a29b25da12d9b3afc3e89499addb2 (patch)
tree3adbaaa8dae319e663b5192c882dbc4e7c3ce1a9
parente926655ecbaf438e054ba1f2452be3b9768efe51 (diff)
downloaddevice-ti-common-open-00efe94be54a29b25da12d9b3afc3e89499addb2.tar.gz
device-ti-common-open-00efe94be54a29b25da12d9b3afc3e89499addb2.tar.xz
device-ti-common-open-00efe94be54a29b25da12d9b3afc3e89499addb2.zip
audio: utils: Add PCM port name
Add PCM port name methods in order to provide more context in info/debug messages and for the PCM reader/writer thread names. Change-Id: I3609a8c9308b562468655d4f693ab4baccd4873f Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com>
-rw-r--r--audio/utils/include/tiaudioutils/ALSAPcm.h20
-rw-r--r--audio/utils/include/tiaudioutils/Base.h14
-rw-r--r--audio/utils/include/tiaudioutils/NullPcm.h20
-rw-r--r--audio/utils/include/tiaudioutils/Pcm.h9
-rw-r--r--audio/utils/src/ALSAPcm.cpp55
-rw-r--r--audio/utils/src/Base.cpp32
-rw-r--r--audio/utils/src/NullPcm.cpp4
-rw-r--r--audio/utils/src/Stream.cpp118
8 files changed, 189 insertions, 83 deletions
diff --git a/audio/utils/include/tiaudioutils/ALSAPcm.h b/audio/utils/include/tiaudioutils/ALSAPcm.h
index 030db84..88b2b71 100644
--- a/audio/utils/include/tiaudioutils/ALSAPcm.h
+++ b/audio/utils/include/tiaudioutils/ALSAPcm.h
@@ -80,6 +80,15 @@ class ALSAInPort : public PcmInPort {
80 uint32_t getPortId() const { return mPortId; } 80 uint32_t getPortId() const { return mPortId; }
81 81
82 /** 82 /**
83 * \brief Get the port name
84 *
85 * Gets the name of the ALSA capture port: hw:<CARD>,<DEVICE>.
86 *
87 * \return The name of the PCM port
88 */
89 const char* getName() const { return mName.c_str(); }
90
91 /**
83 * \brief Open the PCM port for capture 92 * \brief Open the PCM port for capture
84 * 93 *
85 * Opens the ALSA PCM port for capture with the given parameters. 94 * Opens the ALSA PCM port for capture with the given parameters.
@@ -151,6 +160,7 @@ class ALSAInPort : public PcmInPort {
151 protected: 160 protected:
152 uint32_t mCardId; /**< Id of the ALSA card */ 161 uint32_t mCardId; /**< Id of the ALSA card */
153 uint32_t mPortId; /**< Id of the ALSA PCM device */ 162 uint32_t mPortId; /**< Id of the ALSA PCM device */
163 string mName; /**< Name of the ALSA PCM port */
154 uint32_t mPeriodCount; /**< Period count of this port */ 164 uint32_t mPeriodCount; /**< Period count of this port */
155 struct pcm *mPcm; /**< tinyalsa pcm handle */ 165 struct pcm *mPcm; /**< tinyalsa pcm handle */
156 mutable Mutex mLock; /**< Synchronize PCM port use */ 166 mutable Mutex mLock; /**< Synchronize PCM port use */
@@ -203,6 +213,15 @@ class ALSAOutPort : public PcmOutPort {
203 uint32_t getPortId() const { return mPortId; } 213 uint32_t getPortId() const { return mPortId; }
204 214
205 /** 215 /**
216 * \brief Get the port name
217 *
218 * Gets the name of the ALSA playback port: hw:<CARD>,<DEVICE>.
219 *
220 * \return The name of the PCM port
221 */
222 const char* getName() const { return mName.c_str(); }
223
224 /**
206 * \brief Open the PCM port for playback 225 * \brief Open the PCM port for playback
207 * 226 *
208 * Opens the ALSA PCM port for playback with the given parameters. 227 * Opens the ALSA PCM port for playback with the given parameters.
@@ -275,6 +294,7 @@ class ALSAOutPort : public PcmOutPort {
275 protected: 294 protected:
276 uint32_t mCardId; /**< Id of the ALSA card */ 295 uint32_t mCardId; /**< Id of the ALSA card */
277 uint32_t mPortId; /**< Id of the ALSA PCM device */ 296 uint32_t mPortId; /**< Id of the ALSA PCM device */
297 string mName; /**< Name of the ALSA PCM port */
278 uint32_t mPeriodCount; /**< Period count of this port */ 298 uint32_t mPeriodCount; /**< Period count of this port */
279 struct pcm *mPcm; /**< tinyalsa pcm handle */ 299 struct pcm *mPcm; /**< tinyalsa pcm handle */
280 mutable Mutex mLock; /**< Synchronize PCM port use */ 300 mutable Mutex mLock; /**< Synchronize PCM port use */
diff --git a/audio/utils/include/tiaudioutils/Base.h b/audio/utils/include/tiaudioutils/Base.h
index dc2a6f1..720355d 100644
--- a/audio/utils/include/tiaudioutils/Base.h
+++ b/audio/utils/include/tiaudioutils/Base.h
@@ -208,10 +208,20 @@ class ThreadBase {
208 * 208 *
209 * Get the name of the thread. 209 * Get the name of the thread.
210 * 210 *
211 * \return Thread name as a C-style char pointer 211 * \return Thread name as a C-style string
212 */ 212 */
213 const char *name() const { return mName.c_str(); } 213 const char *name() const { return mName.c_str(); }
214 214
215 /**
216 * \brief Set the thread name
217 *
218 * Set the name of the thread.
219 *
220 * \param newname New name of the thread
221 * \return 0 on success, otherwise negative error code
222 */
223 int setName(string newname);
224
215 friend void* threadWrapper(void *me); 225 friend void* threadWrapper(void *me);
216 226
217 private: 227 private:
@@ -233,6 +243,8 @@ class ThreadBase {
233 volatile bool mRunning; /**< Running status of the thread */ 243 volatile bool mRunning; /**< Running status of the thread */
234 mutable Mutex mMutex; 244 mutable Mutex mMutex;
235 245
246 static const int mNameMaxLength = 16; /* Max length of the thread name */
247
236 protected: 248 protected:
237 /** 249 /**
238 * \brief Implementation-specific thread function 250 * \brief Implementation-specific thread function
diff --git a/audio/utils/include/tiaudioutils/NullPcm.h b/audio/utils/include/tiaudioutils/NullPcm.h
index 977faaa..0998a72 100644
--- a/audio/utils/include/tiaudioutils/NullPcm.h
+++ b/audio/utils/include/tiaudioutils/NullPcm.h
@@ -77,6 +77,15 @@ class NullInPort : public PcmInPort {
77 uint32_t getPortId() const { return 0; } 77 uint32_t getPortId() const { return 0; }
78 78
79 /** 79 /**
80 * \brief Get the port name
81 *
82 * Gets the name of the null capture port.
83 *
84 * \return The name of the PCM port
85 */
86 const char* getName() const { return mName.c_str(); }
87
88 /**
80 * \brief Open the null port for capture 89 * \brief Open the null port for capture
81 * 90 *
82 * Opens the null PCM port for capture with the given parameters. There is 91 * Opens the null PCM port for capture with the given parameters. There is
@@ -144,6 +153,7 @@ class NullInPort : public PcmInPort {
144 153
145 protected: 154 protected:
146 bool mOpen; /**< State of the port: open or closed */ 155 bool mOpen; /**< State of the port: open or closed */
156 string mName; /**< Name of the null PCM port */
147 PcmParams mParams; /**< PCM params of the port */ 157 PcmParams mParams; /**< PCM params of the port */
148 Mutex mLock; /**< Synchronize PCM port use */ 158 Mutex mLock; /**< Synchronize PCM port use */
149}; 159};
@@ -195,6 +205,15 @@ class NullOutPort : public PcmOutPort {
195 uint32_t getPortId() const { return 0; } 205 uint32_t getPortId() const { return 0; }
196 206
197 /** 207 /**
208 * \brief Get the port name
209 *
210 * Gets the name of the null playback port.
211 *
212 * \return The name of the PCM port
213 */
214 const char* getName() const { return mName.c_str(); }
215
216 /**
198 * \brief Open the null port for playback 217 * \brief Open the null port for playback
199 * 218 *
200 * Opens the null PCM port for playback with the given parameters. There is 219 * Opens the null PCM port for playback with the given parameters. There is
@@ -261,6 +280,7 @@ class NullOutPort : public PcmOutPort {
261 280
262 protected: 281 protected:
263 bool mOpen; /**< State of the port: open or closed */ 282 bool mOpen; /**< State of the port: open or closed */
283 string mName; /**< Name of the null PCM port */
264 PcmParams mParams; /**< PCM params of the port */ 284 PcmParams mParams; /**< PCM params of the port */
265 Mutex mLock; /**< Synchronize PCM port use */ 285 Mutex mLock; /**< Synchronize PCM port use */
266}; 286};
diff --git a/audio/utils/include/tiaudioutils/Pcm.h b/audio/utils/include/tiaudioutils/Pcm.h
index 7d3ecd8..0bc50d2 100644
--- a/audio/utils/include/tiaudioutils/Pcm.h
+++ b/audio/utils/include/tiaudioutils/Pcm.h
@@ -288,6 +288,15 @@ class PcmPort {
288 virtual uint32_t getPortId() const = 0; 288 virtual uint32_t getPortId() const = 0;
289 289
290 /** 290 /**
291 * \brief Get the port name
292 *
293 * Get the name of the PCM port.
294 *
295 * \return The name of the PCM port
296 */
297 virtual const char* getName() const = 0;
298
299 /**
291 * \brief Open the PCM port 300 * \brief Open the PCM port
292 * 301 *
293 * Opens a PCM port with the requested PCM parameters. 302 * Opens a PCM port with the requested PCM parameters.
diff --git a/audio/utils/src/ALSAPcm.cpp b/audio/utils/src/ALSAPcm.cpp
index cea2199..adbed03 100644
--- a/audio/utils/src/ALSAPcm.cpp
+++ b/audio/utils/src/ALSAPcm.cpp
@@ -17,6 +17,7 @@
17// #define LOG_NDEBUG 0 17// #define LOG_NDEBUG 0
18// #define VERY_VERBOSE_LOGGING 18// #define VERY_VERBOSE_LOGGING
19 19
20#include <sstream>
20#include <errno.h> 21#include <errno.h>
21#include <tinyalsa/asoundlib.h> 22#include <tinyalsa/asoundlib.h>
22 23
@@ -28,6 +29,9 @@ namespace tiaudioutils {
28ALSAInPort::ALSAInPort(uint32_t card, uint32_t port, uint32_t period_count) 29ALSAInPort::ALSAInPort(uint32_t card, uint32_t port, uint32_t period_count)
29 : mCardId(card), mPortId(port), mPeriodCount(period_count), mPcm(NULL) 30 : mCardId(card), mPortId(port), mPeriodCount(period_count), mPcm(NULL)
30{ 31{
32 std::stringstream s;
33 s << "hw:" << mCardId << "," << mPortId;
34 mName = s.str();
31} 35}
32 36
33ALSAInPort::~ALSAInPort() 37ALSAInPort::~ALSAInPort()
@@ -55,18 +59,19 @@ int ALSAInPort::open(const PcmParams &params)
55 uint32_t periodSize = config.period_size; 59 uint32_t periodSize = config.period_size;
56 uint32_t periodCount = config.period_count; 60 uint32_t periodCount = config.period_count;
57 61
58 ALOGI("ALSAInPort: open capture port hw:%u,%u", mCardId, mPortId); 62 ALOGI("ALSAInPort: %s: open capture port", getName());
59 63
60 mPcm = pcm_open(mCardId, mPortId, PCM_IN, &config); 64 mPcm = pcm_open(mCardId, mPortId, PCM_IN, &config);
61 if (!pcm_is_ready(mPcm)) { 65 if (!pcm_is_ready(mPcm)) {
62 ALOGE("ALSAInPort: failed to open capture port hw:%u,%u: %s", 66 ALOGE("ALSAInPort: %s: failed to open capture port %s",
63 mCardId, mPortId, pcm_get_error(mPcm)); 67 getName(), pcm_get_error(mPcm));
64 return -ENODEV; 68 return -ENODEV;
65 } 69 }
66 70
67 if ((periodSize != config.period_size) || (periodCount != config.period_count)) { 71 if ((periodSize != config.period_size) || (periodCount != config.period_count)) {
68 ALOGW("ALSAInPort: params were updated period_size=%u->%u periods=%u->%u", 72 ALOGW("ALSAInPort: %s: params were updated period_size=%u->%u periods=%u->%u",
69 periodSize, config.period_size, periodCount, config.period_count); 73 getName(), periodSize, config.period_size,
74 periodCount, config.period_count);
70 } 75 }
71 76
72 return 0; 77 return 0;
@@ -74,7 +79,7 @@ int ALSAInPort::open(const PcmParams &params)
74 79
75void ALSAInPort::close() 80void ALSAInPort::close()
76{ 81{
77 ALOGI("ALSAInPort: close capture port hw:%u,%u", mCardId, mPortId); 82 ALOGI("ALSAInPort: %s: close capture port", getName());
78 83
79 AutoMutex lock(mLock); 84 AutoMutex lock(mLock);
80 if (mPcm && pcm_is_ready(mPcm)) { 85 if (mPcm && pcm_is_ready(mPcm)) {
@@ -98,17 +103,18 @@ int ALSAInPort::read(void *buffer, size_t frames)
98 AutoMutex lock(mLock); 103 AutoMutex lock(mLock);
99 104
100 if (!mPcm || !pcm_is_ready(mPcm)) { 105 if (!mPcm || !pcm_is_ready(mPcm)) {
101 ALOGE("ALSAInPort: port hw:%u,%u is closed, cannot read", mCardId, mPortId); 106 ALOGE("ALSAInPort: %s: port is closed, cannot read", getName());
102 return -EAGAIN; 107 return -EAGAIN;
103 } 108 }
104 109
105 uint32_t bytes = pcm_frames_to_bytes(mPcm, frames); 110 uint32_t bytes = pcm_frames_to_bytes(mPcm, frames);
106 111
107 ALOGVV("ALSAInPort: read %u frames (%u bytes) buffer %p", frames, bytes, buffer); 112 ALOGVV("ALSAInPort: %s: read %u frames (%u bytes) buffer %p",
113 getName(), frames, bytes, buffer);
108 114
109 int ret = pcm_read(mPcm, buffer, bytes); 115 int ret = pcm_read(mPcm, buffer, bytes);
110 if (ret) { 116 if (ret) {
111 ALOGE("ALSAInPort: failed to read %d", ret); 117 ALOGE("ALSAInPort: %s: failed to read %d", getName(), ret);
112 return ret; 118 return ret;
113 } 119 }
114 120
@@ -120,7 +126,7 @@ int ALSAInPort::start()
120 AutoMutex lock(mLock); 126 AutoMutex lock(mLock);
121 127
122 if (!mPcm || !pcm_is_ready(mPcm)) { 128 if (!mPcm || !pcm_is_ready(mPcm)) {
123 ALOGE("ALSAInPort: port hw:%u,%u is closed, cannot start", mCardId, mPortId); 129 ALOGE("ALSAInPort: %s: port is closed, cannot start", getName());
124 return -EAGAIN; 130 return -EAGAIN;
125 } 131 }
126 132
@@ -134,7 +140,7 @@ int ALSAInPort::stop()
134 * blocked reads which runs with mLock held 140 * blocked reads which runs with mLock held
135 */ 141 */
136 if (!mPcm || !pcm_is_ready(mPcm)) { 142 if (!mPcm || !pcm_is_ready(mPcm)) {
137 ALOGE("ALSAInPort: port hw:%u,%u is closed, cannot stop", mCardId, mPortId); 143 ALOGE("ALSAInPort: %s: port is closed, cannot stop", getName());
138 return -EAGAIN; 144 return -EAGAIN;
139 } 145 }
140 146
@@ -146,6 +152,9 @@ int ALSAInPort::stop()
146ALSAOutPort::ALSAOutPort(uint32_t card, uint32_t port, uint32_t period_count) 152ALSAOutPort::ALSAOutPort(uint32_t card, uint32_t port, uint32_t period_count)
147 : mCardId(card), mPortId(port), mPeriodCount(period_count), mPcm(NULL) 153 : mCardId(card), mPortId(port), mPeriodCount(period_count), mPcm(NULL)
148{ 154{
155 std::stringstream s;
156 s << "hw:" << mCardId << "," << mPortId;
157 mName = s.str();
149} 158}
150 159
151ALSAOutPort::~ALSAOutPort() 160ALSAOutPort::~ALSAOutPort()
@@ -173,18 +182,19 @@ int ALSAOutPort::open(const PcmParams &params)
173 uint32_t periodSize = config.period_size; 182 uint32_t periodSize = config.period_size;
174 uint32_t periodCount = config.period_count; 183 uint32_t periodCount = config.period_count;
175 184
176 ALOGI("ALSAOutPort: open playback port hw:%u,%u", mCardId, mPortId); 185 ALOGI("ALSAOutPort: %s: open playback port", getName());
177 186
178 mPcm = pcm_open(mCardId, mPortId, PCM_OUT, &config); 187 mPcm = pcm_open(mCardId, mPortId, PCM_OUT, &config);
179 if (!pcm_is_ready(mPcm)) { 188 if (!pcm_is_ready(mPcm)) {
180 ALOGE("ALSAOutPort: failed to open playback port hw:%u,%u: %s", 189 ALOGE("ALSAOutPort: %s: failed to open playback port %s",
181 mCardId, mPortId, pcm_get_error(mPcm)); 190 getName(), pcm_get_error(mPcm));
182 return -ENODEV; 191 return -ENODEV;
183 } 192 }
184 193
185 if ((periodSize != config.period_size) || (periodCount != config.period_count)) { 194 if ((periodSize != config.period_size) || (periodCount != config.period_count)) {
186 ALOGW("ALSAOutPort: params were updated period_size=%u->%u periods=%u->%u", 195 ALOGW("ALSAOutPort: %s: params were updated period_size=%u->%u periods=%u->%u",
187 periodSize, config.period_size, periodCount, config.period_count); 196 getName(), periodSize, config.period_size,
197 periodCount, config.period_count);
188 } 198 }
189 199
190 return 0; 200 return 0;
@@ -192,7 +202,7 @@ int ALSAOutPort::open(const PcmParams &params)
192 202
193void ALSAOutPort::close() 203void ALSAOutPort::close()
194{ 204{
195 ALOGI("ALSAOutPort: close playback port hw:%u,%u", mCardId, mPortId); 205 ALOGI("ALSAOutPort: %s: close playback port", getName());
196 206
197 AutoMutex lock(mLock); 207 AutoMutex lock(mLock);
198 if (mPcm && pcm_is_ready(mPcm)) { 208 if (mPcm && pcm_is_ready(mPcm)) {
@@ -216,17 +226,18 @@ int ALSAOutPort::write(const void *buffer, size_t frames)
216 AutoMutex lock(mLock); 226 AutoMutex lock(mLock);
217 227
218 if (!mPcm || !pcm_is_ready(mPcm)) { 228 if (!mPcm || !pcm_is_ready(mPcm)) {
219 ALOGE("ALSAOutPort: port hw:%u,%u is closed, cannot write", mCardId, mPortId); 229 ALOGE("ALSAOutPort: %s: port is closed, cannot write", getName());
220 return -EAGAIN; 230 return -EAGAIN;
221 } 231 }
222 232
223 uint32_t bytes = pcm_frames_to_bytes(mPcm, frames); 233 uint32_t bytes = pcm_frames_to_bytes(mPcm, frames);
224 234
225 ALOGVV("ALSAOutPort: write %u frames (%u bytes) buffer %p", frames, bytes, buffer); 235 ALOGVV("ALSAOutPort: %s: write %u frames (%u bytes) buffer %p",
236 getName(), frames, bytes, buffer);
226 237
227 int ret = pcm_write(mPcm, buffer, bytes); 238 int ret = pcm_write(mPcm, buffer, bytes);
228 if (ret) { 239 if (ret) {
229 ALOGE("ALSAOutPort: failed to write %d", ret); 240 ALOGE("ALSAOutPort: %s: failed to write %d", getName(), ret);
230 return ret; 241 return ret;
231 } 242 }
232 243
@@ -238,7 +249,7 @@ int ALSAOutPort::start()
238 AutoMutex lock(mLock); 249 AutoMutex lock(mLock);
239 250
240 if (!mPcm || !pcm_is_ready(mPcm)) { 251 if (!mPcm || !pcm_is_ready(mPcm)) {
241 ALOGE("ALSAOutPort: port hw:%u,%u is closed, cannot start", mCardId, mPortId); 252 ALOGE("ALSAOutPort: %s: port is closed, cannot start", getName());
242 return -EAGAIN; 253 return -EAGAIN;
243 } 254 }
244 255
@@ -252,7 +263,7 @@ int ALSAOutPort::stop()
252 * blocked writes which runs with mLock held 263 * blocked writes which runs with mLock held
253 */ 264 */
254 if (!mPcm || !pcm_is_ready(mPcm)) { 265 if (!mPcm || !pcm_is_ready(mPcm)) {
255 ALOGE("ALSAOutPort: port hw:%u,%u is closed, cannot stop", mCardId, mPortId); 266 ALOGE("ALSAOutPort: %s: port is closed, cannot stop", getName());
256 return -EAGAIN; 267 return -EAGAIN;
257 } 268 }
258 269
diff --git a/audio/utils/src/Base.cpp b/audio/utils/src/Base.cpp
index 97263f8..8a86270 100644
--- a/audio/utils/src/Base.cpp
+++ b/audio/utils/src/Base.cpp
@@ -108,12 +108,12 @@ ThreadBase::ThreadBase()
108} 108}
109 109
110ThreadBase::ThreadBase(const string &name) 110ThreadBase::ThreadBase(const string &name)
111 : mName("Thread " + name), mRunning(false) 111 : mName(name), mRunning(false)
112{ 112{
113} 113}
114 114
115ThreadBase::ThreadBase(const char *name) 115ThreadBase::ThreadBase(const char *name)
116 : mName("Thread "), mRunning(false) 116 : mName(""), mRunning(false)
117{ 117{
118 if (name) 118 if (name)
119 mName += name; 119 mName += name;
@@ -134,16 +134,19 @@ int ThreadBase::run()
134{ 134{
135 AutoMutex lock(mMutex); 135 AutoMutex lock(mMutex);
136 136
137 ALOGI("%s is starting", name()); 137 ALOGI("Thread %s is starting", name());
138 mRunning = true;
138 int ret = pthread_create(&mThread, NULL, threadWrapper, this); 139 int ret = pthread_create(&mThread, NULL, threadWrapper, this);
139 if (ret) { 140 if (ret) {
140 ALOGE("%s: failed to create pthread %d", name(), ret); 141 ALOGE("Thread %s: failed to create pthread %d", name(), ret);
141 return ret; 142 return ret;
142 } 143 }
143 144
144 mRunning = true; 145 ret = pthread_setname_np(mThread, mName.substr(0, mNameMaxLength - 1).c_str());
146 if (ret)
147 ALOGE("Thread %s: failed to set thread name %d", name(), ret);
145 148
146 return 0; 149 return ret;
147} 150}
148 151
149int ThreadBase::stop() 152int ThreadBase::stop()
@@ -151,7 +154,7 @@ int ThreadBase::stop()
151 AutoMutex lock(mMutex); 154 AutoMutex lock(mMutex);
152 void *res; 155 void *res;
153 156
154 ALOGI("%s is exiting", name()); 157 ALOGI("Thread %s is exiting", name());
155 mRunning = false; 158 mRunning = false;
156 pthread_join(mThread, &res); 159 pthread_join(mThread, &res);
157 160
@@ -164,6 +167,21 @@ bool ThreadBase::isRunning() const
164 return mRunning; 167 return mRunning;
165} 168}
166 169
170int ThreadBase::setName(string newname)
171{
172 AutoMutex lock(mMutex);
173 int ret = 0;
174
175 mName = newname;
176 if (mRunning) {
177 ret = pthread_setname_np(mThread, mName.substr(0, mNameMaxLength - 1).c_str());
178 if (ret)
179 ALOGE("Thread %s: failed to set new name %d", name(), ret);
180 }
181
182 return ret;
183}
184
167int ThreadBase::_threadLoop() 185int ThreadBase::_threadLoop()
168{ 186{
169 int ret = 0; 187 int ret = 0;
diff --git a/audio/utils/src/NullPcm.cpp b/audio/utils/src/NullPcm.cpp
index 3e0a0b0..3718771 100644
--- a/audio/utils/src/NullPcm.cpp
+++ b/audio/utils/src/NullPcm.cpp
@@ -25,7 +25,7 @@
25namespace tiaudioutils { 25namespace tiaudioutils {
26 26
27NullInPort::NullInPort() 27NullInPort::NullInPort()
28 : mOpen(false) 28 : mOpen(false), mName("NullIn")
29{ 29{
30} 30}
31 31
@@ -61,7 +61,7 @@ int NullInPort::read(void *buffer, size_t frames)
61/* ---------------------------------------------------------------------------------------- */ 61/* ---------------------------------------------------------------------------------------- */
62 62
63NullOutPort::NullOutPort() 63NullOutPort::NullOutPort()
64 : mOpen(false) 64 : mOpen(false), mName("NullOut")
65{ 65{
66} 66}
67 67
diff --git a/audio/utils/src/Stream.cpp b/audio/utils/src/Stream.cpp
index 402c3f7..bfac418 100644
--- a/audio/utils/src/Stream.cpp
+++ b/audio/utils/src/Stream.cpp
@@ -624,6 +624,9 @@ PcmReader::PcmReader(PcmInPort *port, const PcmParams &params)
624 mUnMerge(params), 624 mUnMerge(params),
625 mUsers(0) 625 mUsers(0)
626{ 626{
627 if (mPort)
628 setName(string("Reader-") + port->getName());
629
627 mBuffer.i8 = new int8_t[mParams.bufferSize()]; 630 mBuffer.i8 = new int8_t[mParams.bufferSize()];
628 mBuffer.frameCount = mParams.frameCount; 631 mBuffer.frameCount = mParams.frameCount;
629} 632}
@@ -655,17 +658,17 @@ bool PcmReader::initCheck() const
655 } 658 }
656 659
657 if (!mParams.isValid() || !mParams.frameCount) { 660 if (!mParams.isValid() || !mParams.frameCount) {
658 ALOGE("PcmReader: params are not valid"); 661 ALOGE("PcmReader: %s: params are not valid", mPort->getName());
659 return false; 662 return false;
660 } 663 }
661 664
662 if (mBuffer.raw == NULL) { 665 if (mBuffer.raw == NULL) {
663 ALOGE("PcmReader: intermediate buffer allocation failed"); 666 ALOGE("PcmReader: %s: intermediate buffer allocation failed", mPort->getName());
664 return false; 667 return false;
665 } 668 }
666 669
667 if (!mUnMerge.initCheck()) { 670 if (!mUnMerge.initCheck()) {
668 ALOGE("PcmReader: un-merge failed to initialize"); 671 ALOGE("PcmReader: %s: un-merge failed to initialize", mPort->getName());
669 return false; 672 return false;
670 } 673 }
671 674
@@ -675,22 +678,23 @@ bool PcmReader::initCheck() const
675int PcmReader::registerStream(sp<InStream>& stream) 678int PcmReader::registerStream(sp<InStream>& stream)
676{ 679{
677 if (stream == NULL) { 680 if (stream == NULL) {
678 ALOGE("PcmReader: stream is invalid, cannot register"); 681 ALOGE("PcmReader: %s: stream is invalid, cannot register", mPort->getName());
679 return -EINVAL; 682 return -EINVAL;
680 } 683 }
681 684
682 const PcmParams &outParams = stream->getParams(); 685 const PcmParams &outParams = stream->getParams();
683 if (!outParams.isValid() || !outParams.frameCount) { 686 if (!outParams.isValid() || !outParams.frameCount) {
684 ALOGE("PcmReader: stream has invalid params"); 687 ALOGE("PcmReader: %s: stream has invalid params", mPort->getName());
685 return -EINVAL; 688 return -EINVAL;
686 } 689 }
687 690
688 ALOGI("PcmReader: register stream %p src 0x%04x dst 0x%04x", 691 ALOGI("PcmReader: %s: register stream %p src 0x%04x dst 0x%04x",
689 stream.get(), stream->mMap.getSrcMask(), stream->mMap.getDstMask()); 692 mPort->getName(), stream.get(),
693 stream->mMap.getSrcMask(), stream->mMap.getDstMask());
690 694
691 AutoMutex lock(mLock); 695 AutoMutex lock(mLock);
692 if (mStreams.find(stream) != mStreams.end()) { 696 if (mStreams.find(stream) != mStreams.end()) {
693 ALOGE("PcmReader: stream is already registered"); 697 ALOGE("PcmReader: %s: stream is already registered", mPort->getName());
694 return -EINVAL; 698 return -EINVAL;
695 } 699 }
696 700
@@ -703,19 +707,20 @@ int PcmReader::registerStream(sp<InStream>& stream)
703 if ((mParams.sampleRate != outParams.sampleRate) && (outParams.sampleBits == 16)) { 707 if ((mParams.sampleRate != outParams.sampleRate) && (outParams.sampleBits == 16)) {
704 int ret = attachResampler(stream.get()); 708 int ret = attachResampler(stream.get());
705 if (ret) { 709 if (ret) {
706 ALOGE("PcmReader: failed to create and attached resampler"); 710 ALOGE("PcmReader: %s: failed to create and attached resampler",
711 mPort->getName());
707 return ret; 712 return ret;
708 } 713 }
709 } else if ((mParams.sampleBits != outParams.sampleBits) || 714 } else if ((mParams.sampleBits != outParams.sampleBits) ||
710 (mParams.sampleRate != outParams.sampleRate)) { 715 (mParams.sampleRate != outParams.sampleRate)) {
711 /* Channels of the reader and stream are different if un-merge is used */ 716 /* Channels of the reader and stream are different if un-merge is used */
712 ALOGE("PcmReader: reader doesn't support stream's params"); 717 ALOGE("PcmReader: %s: reader doesn't support stream's params", mPort->getName());
713 return -EINVAL; 718 return -EINVAL;
714 } 719 }
715 720
716 int ret = mUnMerge.registerStream(stream); 721 int ret = mUnMerge.registerStream(stream);
717 if (ret) { 722 if (ret) {
718 ALOGE("PcmReader: failed to register stream %d", ret); 723 ALOGE("PcmReader: %s: failed to register stream %d", mPort->getName(), ret);
719 detachResampler(stream.get()); 724 detachResampler(stream.get());
720 return ret; 725 return ret;
721 } 726 }
@@ -730,18 +735,19 @@ int PcmReader::registerStream(sp<InStream>& stream)
730void PcmReader::unregisterStream(sp<InStream>& stream) 735void PcmReader::unregisterStream(sp<InStream>& stream)
731{ 736{
732 if (stream == NULL) { 737 if (stream == NULL) {
733 ALOGE("PcmReader: stream is invalid, cannot unregister"); 738 ALOGE("PcmReader: %s: stream is invalid, cannot unregister", mPort->getName());
734 return; 739 return;
735 } 740 }
736 741
737 if (stream->isStarted()) { 742 if (stream->isStarted()) {
738 ALOGE("PcmReader: stream %p is not stopped, cannot unregister", 743 ALOGE("PcmReader: %s: stream %p is not stopped, cannot unregister",
739 stream.get()); 744 mPort->getName(), stream.get());
740 return; 745 return;
741 } 746 }
742 747
743 ALOGI("PcmReader: unregister stream %p src 0x%04x dst 0x%04x", 748 ALOGI("PcmReader: %s: unregister stream %p src 0x%04x dst 0x%04x",
744 stream.get(), stream->mMap.getSrcMask(), stream->mMap.getDstMask()); 749 mPort->getName(), stream.get(),
750 stream->mMap.getSrcMask(), stream->mMap.getDstMask());
745 751
746 AutoMutex lock(mLock); 752 AutoMutex lock(mLock);
747 if (mStreams.find(stream) != mStreams.end()) { 753 if (mStreams.find(stream) != mStreams.end()) {
@@ -750,7 +756,8 @@ void PcmReader::unregisterStream(sp<InStream>& stream)
750 stream->mReader = NULL; 756 stream->mReader = NULL;
751 mStreams.erase(stream); 757 mStreams.erase(stream);
752 } else { 758 } else {
753 ALOGE("PcmReader: stream is not registered or already unregistered"); 759 ALOGE("PcmReader: %s: stream is not registered or already unregistered",
760 mPort->getName());
754 } 761 }
755} 762}
756 763
@@ -764,21 +771,21 @@ int PcmReader::open()
764{ 771{
765 AutoMutex lock(mLock); 772 AutoMutex lock(mLock);
766 773
767 ALOGV("PcmReader: users %d->%d", mUsers, mUsers+1); 774 ALOGV("PcmReader: %s: users %d->%d", mPort->getName(), mUsers, mUsers+1);
768 if (mUsers++) 775 if (mUsers++)
769 return 0; 776 return 0;
770 777
771 ALOGV("PcmReader: open PCM port and start reader thread"); 778 ALOGV("PcmReader: %s: open PCM port and start reader thread", mPort->getName());
772 int ret = mPort->open(mParams); 779 int ret = mPort->open(mParams);
773 if (ret) { 780 if (ret) {
774 ALOGE("PcmReader: failed to open PCM port %d", ret); 781 ALOGE("PcmReader: %s: failed to open PCM port %d", mPort->getName(), ret);
775 return ret; 782 return ret;
776 } 783 }
777 784
778 /* Start the reader thread */ 785 /* Start the reader thread */
779 ret = run(); 786 ret = run();
780 if (ret) 787 if (ret)
781 ALOGE("PcmReader: failed to start reader thread %d", ret); 788 ALOGE("PcmReader: %s: failed to start reader thread %d", mPort->getName(), ret);
782 789
783 return ret; 790 return ret;
784} 791}
@@ -787,12 +794,12 @@ void PcmReader::close()
787{ 794{
788 AutoMutex lock(mLock); 795 AutoMutex lock(mLock);
789 796
790 ALOGV("PcmReader: users %d->%d", mUsers, mUsers-1); 797 ALOGV("PcmReader: %s: users %d->%d", mPort->getName(), mUsers, mUsers-1);
791 ALOG_ASSERT(mUsers); 798 ALOG_ASSERT(mUsers);
792 if (--mUsers) 799 if (--mUsers)
793 return; 800 return;
794 801
795 ALOGV("PcmReader: stop reader thread and close PCM port"); 802 ALOGV("PcmReader: %s: stop reader thread and close PCM port", mPort->getName());
796 stop(); 803 stop();
797 mPort->close(); 804 mPort->close();
798} 805}
@@ -801,7 +808,7 @@ int PcmReader::threadFunc()
801{ 808{
802 int ret = mPort->read(mBuffer.raw, mParams.frameCount); 809 int ret = mPort->read(mBuffer.raw, mParams.frameCount);
803 if (ret < 0) { 810 if (ret < 0) {
804 ALOGE("PcmReader: failed to read PCM data %d", ret); 811 ALOGE("PcmReader: %s: failed to read PCM data %d", mPort->getName(), ret);
805 /* 812 /*
806 * Set frameCount to 0, this will result in an error being returned to 813 * Set frameCount to 0, this will result in an error being returned to
807 * the buffer adaptor read call after the unmerge process call 814 * the buffer adaptor read call after the unmerge process call
@@ -810,7 +817,8 @@ int PcmReader::threadFunc()
810 } 817 }
811 else { 818 else {
812 if (ret != (int)mBuffer.frameCount) { 819 if (ret != (int)mBuffer.frameCount) {
813 ALOGW("PcmReader: read fewer PCM frames than requested %d", ret); 820 ALOGW("PcmReader: %s: read fewer PCM frames than requested %d",
821 mPort->getName(), ret);
814 } 822 }
815 /* Set the frame count to the actual amount read */ 823 /* Set the frame count to the actual amount read */
816 mBuffer.frameCount = (size_t)ret; 824 mBuffer.frameCount = (size_t)ret;
@@ -818,7 +826,7 @@ int PcmReader::threadFunc()
818 826
819 ret = mUnMerge.process(mBuffer); 827 ret = mUnMerge.process(mBuffer);
820 if (ret) { 828 if (ret) {
821 ALOGE("PcmReader: unmerge failed %d", ret); 829 ALOGE("PcmReader: %s: unmerge failed %d", mPort->getName(), ret);
822 } 830 }
823 831
824 return 0; 832 return 0;
@@ -868,6 +876,9 @@ PcmWriter::PcmWriter(PcmOutPort *port, const PcmParams &params)
868 mMerge(params), 876 mMerge(params),
869 mUsers(0) 877 mUsers(0)
870{ 878{
879 if (mPort)
880 setName(string("Writer-") + port->getName());
881
871 mBuffer.i8 = new int8_t[mParams.bufferSize()]; 882 mBuffer.i8 = new int8_t[mParams.bufferSize()];
872 mBuffer.frameCount = mParams.frameCount; 883 mBuffer.frameCount = mParams.frameCount;
873} 884}
@@ -899,17 +910,17 @@ bool PcmWriter::initCheck() const
899 } 910 }
900 911
901 if (!mParams.isValid() || !mParams.frameCount) { 912 if (!mParams.isValid() || !mParams.frameCount) {
902 ALOGE("PcmWriter: params are not valid"); 913 ALOGE("PcmWriter: %s: params are not valid", mPort->getName());
903 return false; 914 return false;
904 } 915 }
905 916
906 if (mBuffer.raw == NULL) { 917 if (mBuffer.raw == NULL) {
907 ALOGE("PcmWriter: intermediate buffer allocation failed"); 918 ALOGE("PcmWriter: %s: intermediate buffer allocation failed", mPort->getName());
908 return false; 919 return false;
909 } 920 }
910 921
911 if (!mMerge.initCheck()) { 922 if (!mMerge.initCheck()) {
912 ALOGE("PcmWriter: merge failed to initialize"); 923 ALOGE("PcmWriter: %s: merge failed to initialize", mPort->getName());
913 return false; 924 return false;
914 } 925 }
915 926
@@ -919,22 +930,23 @@ bool PcmWriter::initCheck() const
919int PcmWriter::registerStream(sp<OutStream>& stream) 930int PcmWriter::registerStream(sp<OutStream>& stream)
920{ 931{
921 if (stream == NULL) { 932 if (stream == NULL) {
922 ALOGE("PcmWriter: stream is invalid, cannot register"); 933 ALOGE("PcmWriter: %s: stream is invalid, cannot register", mPort->getName());
923 return -EINVAL; 934 return -EINVAL;
924 } 935 }
925 936
926 const PcmParams &inParams = stream->getParams(); 937 const PcmParams &inParams = stream->getParams();
927 if (!inParams.isValid() || !inParams.frameCount) { 938 if (!inParams.isValid() || !inParams.frameCount) {
928 ALOGE("PcmWriter: stream has invalid params"); 939 ALOGE("PcmWriter: %s: stream has invalid params", mPort->getName());
929 return -EINVAL; 940 return -EINVAL;
930 } 941 }
931 942
932 ALOGI("PcmWriter: register stream %p src 0x%04x dst 0x%04x", 943 ALOGI("PcmWriter: %s: register stream %p src 0x%04x dst 0x%04x",
933 stream.get(), stream->mMap.getSrcMask(), stream->mMap.getDstMask()); 944 mPort->getName(), stream.get(),
945 stream->mMap.getSrcMask(), stream->mMap.getDstMask());
934 946
935 AutoMutex lock(mLock); 947 AutoMutex lock(mLock);
936 if (mStreams.find(stream) != mStreams.end()) { 948 if (mStreams.find(stream) != mStreams.end()) {
937 ALOGE("PcmWriter: stream is already registered"); 949 ALOGE("PcmWriter: %s: stream is already registered", mPort->getName());
938 return -EINVAL; 950 return -EINVAL;
939 } 951 }
940 952
@@ -947,19 +959,20 @@ int PcmWriter::registerStream(sp<OutStream>& stream)
947 if ((mParams.sampleRate != inParams.sampleRate) && (inParams.sampleBits == 16)) { 959 if ((mParams.sampleRate != inParams.sampleRate) && (inParams.sampleBits == 16)) {
948 int ret = attachResampler(stream.get()); 960 int ret = attachResampler(stream.get());
949 if (ret) { 961 if (ret) {
950 ALOGE("PcmWriter: failed to create and attached resampler"); 962 ALOGE("PcmWriter: %s: failed to create and attached resampler",
963 mPort->getName());
951 return ret; 964 return ret;
952 } 965 }
953 } else if ((mParams.sampleBits != inParams.sampleBits) || 966 } else if ((mParams.sampleBits != inParams.sampleBits) ||
954 (mParams.sampleRate != inParams.sampleRate)) { 967 (mParams.sampleRate != inParams.sampleRate)) {
955 /* Channels of the writer and stream are different if merge is used */ 968 /* Channels of the writer and stream are different if merge is used */
956 ALOGE("PcmWriter: writer doesn't support stream's params"); 969 ALOGE("PcmWriter: %s: writer doesn't support stream's params", mPort->getName());
957 return -EINVAL; 970 return -EINVAL;
958 } 971 }
959 972
960 int ret = mMerge.registerStream(stream); 973 int ret = mMerge.registerStream(stream);
961 if (ret) { 974 if (ret) {
962 ALOGE("PcmWriter: failed to register stream %d", ret); 975 ALOGE("PcmWriter: %s: failed to register stream %d", mPort->getName(), ret);
963 detachResampler(stream.get()); 976 detachResampler(stream.get());
964 return ret; 977 return ret;
965 } 978 }
@@ -974,18 +987,19 @@ int PcmWriter::registerStream(sp<OutStream>& stream)
974void PcmWriter::unregisterStream(sp<OutStream>& stream) 987void PcmWriter::unregisterStream(sp<OutStream>& stream)
975{ 988{
976 if (stream == NULL) { 989 if (stream == NULL) {
977 ALOGE("PcmWriter: stream is invalid, cannot unregister"); 990 ALOGE("PcmWriter: %s: stream is invalid, cannot unregister", mPort->getName());
978 return; 991 return;
979 } 992 }
980 993
981 if (stream->isStarted()) { 994 if (stream->isStarted()) {
982 ALOGE("PcmWriter: stream %p is not stopped, cannot unregister", 995 ALOGE("PcmWriter: %s: stream %p is not stopped, cannot unregister",
983 stream.get()); 996 mPort->getName(), stream.get());
984 return; 997 return;
985 } 998 }
986 999
987 ALOGI("PcmWriter: unregister stream %p src 0x%04x dst 0x%04x", 1000 ALOGI("PcmWriter: %s: unregister stream %p src 0x%04x dst 0x%04x",
988 stream.get(), stream->mMap.getSrcMask(), stream->mMap.getDstMask()); 1001 mPort->getName(), stream.get(),
1002 stream->mMap.getSrcMask(), stream->mMap.getDstMask());
989 1003
990 AutoMutex lock(mLock); 1004 AutoMutex lock(mLock);
991 if (mStreams.find(stream) != mStreams.end()) { 1005 if (mStreams.find(stream) != mStreams.end()) {
@@ -994,7 +1008,8 @@ void PcmWriter::unregisterStream(sp<OutStream>& stream)
994 stream->mWriter = NULL; 1008 stream->mWriter = NULL;
995 mStreams.erase(stream); 1009 mStreams.erase(stream);
996 } else { 1010 } else {
997 ALOGE("PcmWriter: stream is not registered or already unregistered"); 1011 ALOGE("PcmWriter: %s: stream is not registered or already unregistered",
1012 mPort->getName());
998 } 1013 }
999} 1014}
1000 1015
@@ -1008,21 +1023,21 @@ int PcmWriter::open()
1008{ 1023{
1009 AutoMutex lock(mLock); 1024 AutoMutex lock(mLock);
1010 1025
1011 ALOGV("PcmWriter: users %d->%d", mUsers, mUsers+1); 1026 ALOGV("PcmWriter: %s: users %d->%d", mPort->getName(), mUsers, mUsers+1);
1012 if (mUsers++) 1027 if (mUsers++)
1013 return 0; 1028 return 0;
1014 1029
1015 ALOGV("PcmWriter: open PCM port and start writer thread"); 1030 ALOGV("PcmWriter: %s: open PCM port and start writer thread", mPort->getName());
1016 int ret = mPort->open(mParams); 1031 int ret = mPort->open(mParams);
1017 if (ret) { 1032 if (ret) {
1018 ALOGE("PcmWriter: failed to open PCM port %d", ret); 1033 ALOGE("PcmWriter: %s: failed to open PCM port %d", mPort->getName(), ret);
1019 return ret; 1034 return ret;
1020 } 1035 }
1021 1036
1022 /* Start the writer thread */ 1037 /* Start the writer thread */
1023 ret = run(); 1038 ret = run();
1024 if (ret) 1039 if (ret)
1025 ALOGE("PcmWriter: failed to start writer thread %d", ret); 1040 ALOGE("PcmWriter: %s: failed to start writer thread %d", mPort->getName(), ret);
1026 1041
1027 return ret; 1042 return ret;
1028} 1043}
@@ -1031,12 +1046,12 @@ void PcmWriter::close()
1031{ 1046{
1032 AutoMutex lock(mLock); 1047 AutoMutex lock(mLock);
1033 1048
1034 ALOGV("PcmWriter: users %d->%d", mUsers, mUsers-1); 1049 ALOGV("PcmWriter: %s: users %d->%d", mPort->getName(), mUsers, mUsers-1);
1035 ALOG_ASSERT(mUsers); 1050 ALOG_ASSERT(mUsers);
1036 if (--mUsers) 1051 if (--mUsers)
1037 return; 1052 return;
1038 1053
1039 ALOGV("PcmWriter: stop writer thread and close PCM port"); 1054 ALOGV("PcmWriter: %s: stop writer thread and close PCM port", mPort->getName());
1040 stop(); 1055 stop();
1041 mPort->close(); 1056 mPort->close();
1042} 1057}
@@ -1045,12 +1060,13 @@ int PcmWriter::threadFunc()
1045{ 1060{
1046 int ret = mMerge.process(mBuffer); 1061 int ret = mMerge.process(mBuffer);
1047 if (ret) { 1062 if (ret) {
1048 ALOGE("PcmWriter: error processing data from provider %d", ret); 1063 ALOGE("PcmWriter: %s: error processing data from provider %d",
1064 mPort->getName(), ret);
1049 } 1065 }
1050 1066
1051 ret = mPort->write(mBuffer.raw, mBuffer.frameCount); 1067 ret = mPort->write(mBuffer.raw, mBuffer.frameCount);
1052 if (ret < 0) { 1068 if (ret < 0) {
1053 ALOGE("PcmWriter: failed to write PCM data %d", ret); 1069 ALOGE("PcmWriter: %s: failed to write PCM data %d", mPort->getName(), ret);
1054 /* 1070 /*
1055 * mPort->write errors will not propagate to the user through the buffer 1071 * mPort->write errors will not propagate to the user through the buffer
1056 * adaptor. So, perform the sleep here to lessen the number of errors. 1072 * adaptor. So, perform the sleep here to lessen the number of errors.