blob: c619ad7c31108a21a77706f3c6d8e7dde932e28c [file] [log] [blame]
Glenn Kasten99e53b82012-01-19 08:59:58 -08001/*
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08002**
3** Copyright 2007, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18
19//#define LOG_NDEBUG 0
20#define LOG_TAG "AudioTrack"
21
22#include <stdint.h>
23#include <sys/types.h>
24#include <limits.h>
25
26#include <sched.h>
27#include <sys/resource.h>
28
29#include <private/media/AudioTrackShared.h>
30
31#include <media/AudioSystem.h>
32#include <media/AudioTrack.h>
33
34#include <utils/Log.h>
Mathias Agopian75624082009-05-19 19:08:10 -070035#include <binder/Parcel.h>
36#include <binder/IPCThreadState.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080037#include <utils/Timers.h>
Eric Laurent38ccae22011-03-28 18:37:07 -070038#include <utils/Atomic.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080039
Dima Zavinfce7a472011-04-19 22:30:36 -070040#include <cutils/bitops.h>
Glenn Kastenf6b16782011-12-15 09:51:17 -080041#include <cutils/compiler.h>
Dima Zavinfce7a472011-04-19 22:30:36 -070042
Dima Zavin64760242011-05-11 14:15:23 -070043#include <system/audio.h>
Dima Zavin7394a4f2011-06-13 18:16:26 -070044#include <system/audio_policy.h>
Dima Zavinfce7a472011-04-19 22:30:36 -070045
Glenn Kasten511754b2012-01-11 09:52:19 -080046#include <audio_utils/primitives.h>
47
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080048namespace android {
Chia-chi Yeh33005a92010-06-16 06:33:13 +080049// ---------------------------------------------------------------------------
50
51// static
52status_t AudioTrack::getMinFrameCount(
53 int* frameCount,
Glenn Kastenfff6d712012-01-12 16:38:12 -080054 audio_stream_type_t streamType,
Chia-chi Yeh33005a92010-06-16 06:33:13 +080055 uint32_t sampleRate)
56{
57 int afSampleRate;
58 if (AudioSystem::getOutputSamplingRate(&afSampleRate, streamType) != NO_ERROR) {
59 return NO_INIT;
60 }
61 int afFrameCount;
62 if (AudioSystem::getOutputFrameCount(&afFrameCount, streamType) != NO_ERROR) {
63 return NO_INIT;
64 }
65 uint32_t afLatency;
66 if (AudioSystem::getOutputLatency(&afLatency, streamType) != NO_ERROR) {
67 return NO_INIT;
68 }
69
70 // Ensure that buffer depth covers at least audio hardware latency
71 uint32_t minBufCount = afLatency / ((1000 * afFrameCount) / afSampleRate);
72 if (minBufCount < 2) minBufCount = 2;
73
74 *frameCount = (sampleRate == 0) ? afFrameCount * minBufCount :
Glenn Kastene53b9ea2012-03-12 16:29:55 -070075 afFrameCount * minBufCount * sampleRate / afSampleRate;
Chia-chi Yeh33005a92010-06-16 06:33:13 +080076 return NO_ERROR;
77}
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080078
79// ---------------------------------------------------------------------------
80
81AudioTrack::AudioTrack()
Glenn Kasten87913512011-06-22 16:15:25 -070082 : mStatus(NO_INIT),
John Grossman4ff14ba2012-02-08 16:37:41 -080083 mIsTimed(false),
84 mPreviousPriority(ANDROID_PRIORITY_NORMAL),
85 mPreviousSchedulingGroup(ANDROID_TGROUP_DEFAULT)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080086{
87}
88
89AudioTrack::AudioTrack(
Glenn Kastenfff6d712012-01-12 16:38:12 -080090 audio_stream_type_t streamType,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080091 uint32_t sampleRate,
Glenn Kastene1c39622012-01-04 09:36:37 -080092 audio_format_t format,
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -070093 int channelMask,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080094 int frameCount,
Glenn Kasten18868c52012-03-07 09:15:37 -080095 audio_policy_output_flags_t flags,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080096 callback_t cbf,
97 void* user,
Eric Laurentbe916aa2010-06-01 23:49:17 -070098 int notificationFrames,
99 int sessionId)
Glenn Kasten87913512011-06-22 16:15:25 -0700100 : mStatus(NO_INIT),
John Grossman4ff14ba2012-02-08 16:37:41 -0800101 mIsTimed(false),
102 mPreviousPriority(ANDROID_PRIORITY_NORMAL),
103 mPreviousSchedulingGroup(ANDROID_TGROUP_DEFAULT)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800104{
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700105 mStatus = set(streamType, sampleRate, format, channelMask,
Eric Laurenta514bdb2010-06-21 09:27:30 -0700106 frameCount, flags, cbf, user, notificationFrames,
Glenn Kasten17a736c2012-02-14 08:52:15 -0800107 0 /*sharedBuffer*/, false /*threadCanCallJava*/, sessionId);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800108}
109
Glenn Kasten17a736c2012-02-14 08:52:15 -0800110// DEPRECATED
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800111AudioTrack::AudioTrack(
Andreas Huberc8139852012-01-18 10:51:55 -0800112 int streamType,
113 uint32_t sampleRate,
114 int format,
115 int channelMask,
116 int frameCount,
117 uint32_t flags,
118 callback_t cbf,
119 void* user,
120 int notificationFrames,
121 int sessionId)
122 : mStatus(NO_INIT),
Glenn Kasten18868c52012-03-07 09:15:37 -0800123 mIsTimed(false),
Andreas Huberc8139852012-01-18 10:51:55 -0800124 mPreviousPriority(ANDROID_PRIORITY_NORMAL), mPreviousSchedulingGroup(ANDROID_TGROUP_DEFAULT)
125{
126 mStatus = set((audio_stream_type_t)streamType, sampleRate, (audio_format_t)format, channelMask,
Glenn Kasten18868c52012-03-07 09:15:37 -0800127 frameCount, (audio_policy_output_flags_t)flags, cbf, user, notificationFrames,
Glenn Kasten17a736c2012-02-14 08:52:15 -0800128 0 /*sharedBuffer*/, false /*threadCanCallJava*/, sessionId);
Andreas Huberc8139852012-01-18 10:51:55 -0800129}
130
131AudioTrack::AudioTrack(
Glenn Kastenfff6d712012-01-12 16:38:12 -0800132 audio_stream_type_t streamType,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800133 uint32_t sampleRate,
Glenn Kastene1c39622012-01-04 09:36:37 -0800134 audio_format_t format,
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700135 int channelMask,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800136 const sp<IMemory>& sharedBuffer,
Glenn Kasten18868c52012-03-07 09:15:37 -0800137 audio_policy_output_flags_t flags,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800138 callback_t cbf,
139 void* user,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700140 int notificationFrames,
141 int sessionId)
Glenn Kasten87913512011-06-22 16:15:25 -0700142 : mStatus(NO_INIT),
John Grossman4ff14ba2012-02-08 16:37:41 -0800143 mIsTimed(false),
144 mPreviousPriority(ANDROID_PRIORITY_NORMAL),
145 mPreviousSchedulingGroup(ANDROID_TGROUP_DEFAULT)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800146{
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700147 mStatus = set(streamType, sampleRate, format, channelMask,
Glenn Kasten17a736c2012-02-14 08:52:15 -0800148 0 /*frameCount*/, flags, cbf, user, notificationFrames,
149 sharedBuffer, false /*threadCanCallJava*/, sessionId);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800150}
151
152AudioTrack::~AudioTrack()
153{
Steve Block3856b092011-10-20 11:56:00 +0100154 ALOGV_IF(mSharedBuffer != 0, "Destructor sharedBuffer: %p", mSharedBuffer->pointer());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800155
156 if (mStatus == NO_ERROR) {
157 // Make sure that callback function exits in the case where
158 // it is looping on buffer full condition in obtainBuffer().
159 // Otherwise the callback thread will never exit.
160 stop();
161 if (mAudioTrackThread != 0) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800162 mAudioTrackThread->requestExitAndWait();
163 mAudioTrackThread.clear();
164 }
165 mAudioTrack.clear();
166 IPCThreadState::self()->flushCommands();
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700167 AudioSystem::releaseAudioSessionId(mSessionId);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800168 }
169}
170
171status_t AudioTrack::set(
Glenn Kastenfff6d712012-01-12 16:38:12 -0800172 audio_stream_type_t streamType,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800173 uint32_t sampleRate,
Glenn Kastene1c39622012-01-04 09:36:37 -0800174 audio_format_t format,
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700175 int channelMask,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800176 int frameCount,
Glenn Kasten18868c52012-03-07 09:15:37 -0800177 audio_policy_output_flags_t flags,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800178 callback_t cbf,
179 void* user,
180 int notificationFrames,
181 const sp<IMemory>& sharedBuffer,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700182 bool threadCanCallJava,
183 int sessionId)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800184{
185
Steve Block3856b092011-10-20 11:56:00 +0100186 ALOGV_IF(sharedBuffer != 0, "sharedBuffer: %p, size: %d", sharedBuffer->pointer(), sharedBuffer->size());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800187
Eric Laurent1703cdf2011-03-07 14:52:59 -0800188 AutoMutex lock(mLock);
Eric Laurent1dd70b92009-04-21 07:56:33 -0700189 if (mAudioTrack != 0) {
Steve Block29357bc2012-01-06 19:20:56 +0000190 ALOGE("Track already in use");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800191 return INVALID_OPERATION;
192 }
193
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800194 int afSampleRate;
195 if (AudioSystem::getOutputSamplingRate(&afSampleRate, streamType) != NO_ERROR) {
196 return NO_INIT;
197 }
Glenn Kastenea7939a2012-03-14 12:56:26 -0700198
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800199 uint32_t afLatency;
200 if (AudioSystem::getOutputLatency(&afLatency, streamType) != NO_ERROR) {
201 return NO_INIT;
202 }
203
204 // handle default values first.
Dima Zavinfce7a472011-04-19 22:30:36 -0700205 if (streamType == AUDIO_STREAM_DEFAULT) {
206 streamType = AUDIO_STREAM_MUSIC;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800207 }
Glenn Kastenea7939a2012-03-14 12:56:26 -0700208
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800209 if (sampleRate == 0) {
210 sampleRate = afSampleRate;
211 }
Glenn Kastenea7939a2012-03-14 12:56:26 -0700212
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800213 // these below should probably come from the audioFlinger too...
Glenn Kastene1c39622012-01-04 09:36:37 -0800214 if (format == AUDIO_FORMAT_DEFAULT) {
Dima Zavinfce7a472011-04-19 22:30:36 -0700215 format = AUDIO_FORMAT_PCM_16_BIT;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800216 }
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700217 if (channelMask == 0) {
218 channelMask = AUDIO_CHANNEL_OUT_STEREO;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800219 }
220
221 // validate parameters
Dima Zavinfce7a472011-04-19 22:30:36 -0700222 if (!audio_is_valid_format(format)) {
Steve Block29357bc2012-01-06 19:20:56 +0000223 ALOGE("Invalid format");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800224 return BAD_VALUE;
225 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700226
227 // force direct flag if format is not linear PCM
Dima Zavinfce7a472011-04-19 22:30:36 -0700228 if (!audio_is_linear_pcm(format)) {
Glenn Kasten4a4a0952012-03-19 11:38:14 -0700229 flags = (audio_policy_output_flags_t)
230 ((flags | AUDIO_POLICY_OUTPUT_FLAG_DIRECT) & ~AUDIO_POLICY_OUTPUT_FLAG_FAST);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700231 }
232
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700233 if (!audio_is_output_channel(channelMask)) {
Steve Block29357bc2012-01-06 19:20:56 +0000234 ALOGE("Invalid channel mask");
Eric Laurentc2f1f072009-07-17 12:17:14 -0700235 return BAD_VALUE;
236 }
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700237 uint32_t channelCount = popcount(channelMask);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700238
Dima Zavinfce7a472011-04-19 22:30:36 -0700239 audio_io_handle_t output = AudioSystem::getOutput(
Glenn Kastenfff6d712012-01-12 16:38:12 -0800240 streamType,
Glenn Kastene1c39622012-01-04 09:36:37 -0800241 sampleRate, format, channelMask,
Glenn Kasten18868c52012-03-07 09:15:37 -0800242 flags);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700243
244 if (output == 0) {
Steve Block29357bc2012-01-06 19:20:56 +0000245 ALOGE("Could not get audio output for stream type %d", streamType);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800246 return BAD_VALUE;
247 }
248
Eric Laurent34f1d8e2009-11-04 08:27:26 -0800249 mVolume[LEFT] = 1.0f;
250 mVolume[RIGHT] = 1.0f;
Glenn Kasten05632a52012-01-03 14:22:33 -0800251 mSendLevel = 0.0f;
Eric Laurentd1b449a2010-05-14 03:26:45 -0700252 mFrameCount = frameCount;
253 mNotificationFramesReq = notificationFrames;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700254 mSessionId = sessionId;
Eric Laurent2beeb502010-07-16 07:43:46 -0700255 mAuxEffectId = 0;
Glenn Kasten4a4a0952012-03-19 11:38:14 -0700256 mCbf = cbf;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700257
Eric Laurent34f1d8e2009-11-04 08:27:26 -0800258 // create the IAudioTrack
Eric Laurent1703cdf2011-03-07 14:52:59 -0800259 status_t status = createTrack_l(streamType,
260 sampleRate,
Glenn Kastene1c39622012-01-04 09:36:37 -0800261 format,
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700262 (uint32_t)channelMask,
Eric Laurent1703cdf2011-03-07 14:52:59 -0800263 frameCount,
264 flags,
265 sharedBuffer,
Glenn Kasten291f4d52012-03-19 12:16:56 -0700266 output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800267
Eric Laurent34f1d8e2009-11-04 08:27:26 -0800268 if (status != NO_ERROR) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800269 return status;
270 }
Eric Laurent34f1d8e2009-11-04 08:27:26 -0800271
Glenn Kastena0d68332012-01-27 16:47:15 -0800272 if (cbf != NULL) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800273 mAudioTrackThread = new AudioTrackThread(*this, threadCanCallJava);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800274 }
275
276 mStatus = NO_ERROR;
277
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800278 mStreamType = streamType;
Glenn Kastene1c39622012-01-04 09:36:37 -0800279 mFormat = format;
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700280 mChannelMask = (uint32_t)channelMask;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800281 mChannelCount = channelCount;
282 mSharedBuffer = sharedBuffer;
283 mMuted = false;
Glenn Kasten9a2aaf92012-01-03 09:42:47 -0800284 mActive = false;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800285 mUserData = user;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800286 mLoopCount = 0;
287 mMarkerPosition = 0;
Jean-Michel Trivi2c22aeb2009-03-24 18:11:07 -0700288 mMarkerReached = false;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800289 mNewPosition = 0;
290 mUpdatePeriod = 0;
Jean-Michel Trivicd075942011-08-25 16:47:23 -0700291 mFlushed = false;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700292 mFlags = flags;
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700293 AudioSystem::acquireAudioSessionId(mSessionId);
Eric Laurentcfe2ba62011-09-13 15:04:17 -0700294 mRestoreStatus = NO_ERROR;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800295 return NO_ERROR;
296}
297
298status_t AudioTrack::initCheck() const
299{
300 return mStatus;
301}
302
303// -------------------------------------------------------------------------
304
305uint32_t AudioTrack::latency() const
306{
307 return mLatency;
308}
309
Glenn Kastenfff6d712012-01-12 16:38:12 -0800310audio_stream_type_t AudioTrack::streamType() const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800311{
312 return mStreamType;
313}
314
Glenn Kastene1c39622012-01-04 09:36:37 -0800315audio_format_t AudioTrack::format() const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800316{
317 return mFormat;
318}
319
320int AudioTrack::channelCount() const
321{
322 return mChannelCount;
323}
324
325uint32_t AudioTrack::frameCount() const
326{
Eric Laurentd1b449a2010-05-14 03:26:45 -0700327 return mCblk->frameCount;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800328}
329
Glenn Kastenb9980652012-01-11 09:48:27 -0800330size_t AudioTrack::frameSize() const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800331{
Dima Zavinfce7a472011-04-19 22:30:36 -0700332 if (audio_is_linear_pcm(mFormat)) {
Eric Laurent671a6362011-06-16 21:30:45 -0700333 return channelCount()*audio_bytes_per_sample(mFormat);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700334 } else {
335 return sizeof(uint8_t);
336 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800337}
338
339sp<IMemory>& AudioTrack::sharedBuffer()
340{
341 return mSharedBuffer;
342}
343
344// -------------------------------------------------------------------------
345
346void AudioTrack::start()
347{
348 sp<AudioTrackThread> t = mAudioTrackThread;
Glenn Kastend0965dd2011-06-22 16:18:04 -0700349 status_t status = NO_ERROR;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800350
Steve Block3856b092011-10-20 11:56:00 +0100351 ALOGV("start %p", this);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800352 if (t != 0) {
353 if (t->exitPending()) {
354 if (t->requestExitAndWait() == WOULD_BLOCK) {
Steve Block29357bc2012-01-06 19:20:56 +0000355 ALOGE("AudioTrack::start called from thread");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800356 return;
357 }
358 }
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700359 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800360
Eric Laurentf5aafb22010-11-18 08:40:16 -0800361 AutoMutex lock(mLock);
Eric Laurent1703cdf2011-03-07 14:52:59 -0800362 // acquire a strong reference on the IMemory and IAudioTrack so that they cannot be destroyed
363 // while we are accessing the cblk
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700364 sp<IAudioTrack> audioTrack = mAudioTrack;
365 sp<IMemory> iMem = mCblkMemory;
Eric Laurent1703cdf2011-03-07 14:52:59 -0800366 audio_track_cblk_t* cblk = mCblk;
367
Glenn Kasten9a2aaf92012-01-03 09:42:47 -0800368 if (!mActive) {
Jean-Michel Trivicd075942011-08-25 16:47:23 -0700369 mFlushed = false;
Glenn Kasten9a2aaf92012-01-03 09:42:47 -0800370 mActive = true;
Eric Laurent1703cdf2011-03-07 14:52:59 -0800371 mNewPosition = cblk->server + mUpdatePeriod;
Eric Laurent33797ea2011-03-17 09:36:51 -0700372 cblk->lock.lock();
Eric Laurent1703cdf2011-03-07 14:52:59 -0800373 cblk->bufferTimeoutMs = MAX_STARTUP_TIMEOUT_MS;
374 cblk->waitTimeMs = 0;
Eric Laurent38ccae22011-03-28 18:37:07 -0700375 android_atomic_and(~CBLK_DISABLED_ON, &cblk->flags);
Glenn Kasten6dbc1352012-02-02 10:56:47 -0800376 pid_t tid;
Eric Laurent2b584242009-11-09 23:32:22 -0800377 if (t != 0) {
Glenn Kasten480b4682012-02-28 12:30:08 -0800378 t->run("AudioTrack", ANDROID_PRIORITY_AUDIO);
Glenn Kasten6dbc1352012-02-02 10:56:47 -0800379 tid = t->getTid(); // pid_t is unknown until run()
380 ALOGV("getTid=%d", tid);
381 if (tid == -1) {
382 tid = 0;
383 }
Eric Laurent2b584242009-11-09 23:32:22 -0800384 } else {
Glenn Kasten87913512011-06-22 16:15:25 -0700385 mPreviousPriority = getpriority(PRIO_PROCESS, 0);
386 mPreviousSchedulingGroup = androidGetThreadSchedulingGroup(0);
387 androidSetThreadPriority(0, ANDROID_PRIORITY_AUDIO);
Glenn Kasten6dbc1352012-02-02 10:56:47 -0800388 tid = 0; // not gettid()
Eric Laurent2b584242009-11-09 23:32:22 -0800389 }
390
Steve Block3856b092011-10-20 11:56:00 +0100391 ALOGV("start %p before lock cblk %p", this, mCblk);
Eric Laurent1703cdf2011-03-07 14:52:59 -0800392 if (!(cblk->flags & CBLK_INVALID_MSK)) {
393 cblk->lock.unlock();
Glenn Kasten6dbc1352012-02-02 10:56:47 -0800394 ALOGV("mAudioTrack->start(tid=%d)", tid);
395 status = mAudioTrack->start(tid);
Eric Laurent1703cdf2011-03-07 14:52:59 -0800396 cblk->lock.lock();
397 if (status == DEAD_OBJECT) {
Eric Laurent38ccae22011-03-28 18:37:07 -0700398 android_atomic_or(CBLK_INVALID_ON, &cblk->flags);
Eric Laurent6100d2d2009-11-19 09:00:56 -0800399 }
Eric Laurent2b584242009-11-09 23:32:22 -0800400 }
Eric Laurent1703cdf2011-03-07 14:52:59 -0800401 if (cblk->flags & CBLK_INVALID_MSK) {
402 status = restoreTrack_l(cblk, true);
403 }
404 cblk->lock.unlock();
Eric Laurent2b584242009-11-09 23:32:22 -0800405 if (status != NO_ERROR) {
Steve Block3856b092011-10-20 11:56:00 +0100406 ALOGV("start() failed");
Glenn Kasten9a2aaf92012-01-03 09:42:47 -0800407 mActive = false;
Eric Laurent2b584242009-11-09 23:32:22 -0800408 if (t != 0) {
409 t->requestExit();
410 } else {
Glenn Kasten87913512011-06-22 16:15:25 -0700411 setpriority(PRIO_PROCESS, 0, mPreviousPriority);
412 androidSetThreadSchedulingGroup(0, mPreviousSchedulingGroup);
Eric Laurent2b584242009-11-09 23:32:22 -0800413 }
Eric Laurent34f1d8e2009-11-04 08:27:26 -0800414 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800415 }
416
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800417}
418
419void AudioTrack::stop()
420{
421 sp<AudioTrackThread> t = mAudioTrackThread;
422
Steve Block3856b092011-10-20 11:56:00 +0100423 ALOGV("stop %p", this);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800424
Eric Laurentf5aafb22010-11-18 08:40:16 -0800425 AutoMutex lock(mLock);
Glenn Kasten9a2aaf92012-01-03 09:42:47 -0800426 if (mActive) {
427 mActive = false;
Eric Laurent1dd70b92009-04-21 07:56:33 -0700428 mCblk->cv.signal();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800429 mAudioTrack->stop();
430 // Cancel loops (If we are in the middle of a loop, playback
431 // would not stop until loopCount reaches 0).
Eric Laurent1703cdf2011-03-07 14:52:59 -0800432 setLoop_l(0, 0, 0);
Jean-Michel Trivi2c22aeb2009-03-24 18:11:07 -0700433 // the playback head position will reset to 0, so if a marker is set, we need
434 // to activate it again
435 mMarkerReached = false;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800436 // Force flush if a shared buffer is used otherwise audioflinger
437 // will not stop before end of buffer is reached.
438 if (mSharedBuffer != 0) {
Eric Laurent1703cdf2011-03-07 14:52:59 -0800439 flush_l();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800440 }
441 if (t != 0) {
442 t->requestExit();
443 } else {
Glenn Kasten87913512011-06-22 16:15:25 -0700444 setpriority(PRIO_PROCESS, 0, mPreviousPriority);
445 androidSetThreadSchedulingGroup(0, mPreviousSchedulingGroup);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800446 }
447 }
448
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800449}
450
451bool AudioTrack::stopped() const
452{
Glenn Kasten9a2aaf92012-01-03 09:42:47 -0800453 AutoMutex lock(mLock);
454 return stopped_l();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800455}
456
457void AudioTrack::flush()
458{
Eric Laurent1703cdf2011-03-07 14:52:59 -0800459 AutoMutex lock(mLock);
460 flush_l();
461}
462
463// must be called with mLock held
464void AudioTrack::flush_l()
465{
Steve Block3856b092011-10-20 11:56:00 +0100466 ALOGV("flush");
Eric Laurentc2f1f072009-07-17 12:17:14 -0700467
Jean-Michel Trivi2c22aeb2009-03-24 18:11:07 -0700468 // clear playback marker and periodic update counter
469 mMarkerPosition = 0;
470 mMarkerReached = false;
471 mUpdatePeriod = 0;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700472
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800473 if (!mActive) {
Jean-Michel Trivicd075942011-08-25 16:47:23 -0700474 mFlushed = true;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800475 mAudioTrack->flush();
476 // Release AudioTrack callback thread in case it was waiting for new buffers
477 // in AudioTrack::obtainBuffer()
478 mCblk->cv.signal();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800479 }
480}
481
482void AudioTrack::pause()
483{
Steve Block3856b092011-10-20 11:56:00 +0100484 ALOGV("pause");
Eric Laurentf5aafb22010-11-18 08:40:16 -0800485 AutoMutex lock(mLock);
Glenn Kasten9a2aaf92012-01-03 09:42:47 -0800486 if (mActive) {
487 mActive = false;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800488 mAudioTrack->pause();
489 }
490}
491
492void AudioTrack::mute(bool e)
493{
494 mAudioTrack->mute(e);
495 mMuted = e;
496}
497
498bool AudioTrack::muted() const
499{
500 return mMuted;
501}
502
Eric Laurentbe916aa2010-06-01 23:49:17 -0700503status_t AudioTrack::setVolume(float left, float right)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800504{
Glenn Kastenf0c49502011-11-30 09:46:04 -0800505 if (left < 0.0f || left > 1.0f || right < 0.0f || right > 1.0f) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700506 return BAD_VALUE;
507 }
508
Eric Laurent1703cdf2011-03-07 14:52:59 -0800509 AutoMutex lock(mLock);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800510 mVolume[LEFT] = left;
511 mVolume[RIGHT] = right;
512
Glenn Kasten83d86532012-01-17 14:39:34 -0800513 mCblk->setVolumeLR((uint32_t(uint16_t(right * 0x1000)) << 16) | uint16_t(left * 0x1000));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700514
515 return NO_ERROR;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800516}
517
Glenn Kastena5224f32012-01-04 12:41:44 -0800518void AudioTrack::getVolume(float* left, float* right) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800519{
Eric Laurentbe916aa2010-06-01 23:49:17 -0700520 if (left != NULL) {
521 *left = mVolume[LEFT];
522 }
523 if (right != NULL) {
524 *right = mVolume[RIGHT];
525 }
526}
527
Eric Laurent2beeb502010-07-16 07:43:46 -0700528status_t AudioTrack::setAuxEffectSendLevel(float level)
Eric Laurentbe916aa2010-06-01 23:49:17 -0700529{
Steve Block3856b092011-10-20 11:56:00 +0100530 ALOGV("setAuxEffectSendLevel(%f)", level);
Glenn Kasten05632a52012-01-03 14:22:33 -0800531 if (level < 0.0f || level > 1.0f) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700532 return BAD_VALUE;
533 }
Eric Laurent1703cdf2011-03-07 14:52:59 -0800534 AutoMutex lock(mLock);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700535
536 mSendLevel = level;
537
Glenn Kasten05632a52012-01-03 14:22:33 -0800538 mCblk->setSendLevel(level);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700539
540 return NO_ERROR;
541}
542
Glenn Kastena5224f32012-01-04 12:41:44 -0800543void AudioTrack::getAuxEffectSendLevel(float* level) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700544{
545 if (level != NULL) {
546 *level = mSendLevel;
547 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800548}
549
Eric Laurent57326622009-07-07 07:10:45 -0700550status_t AudioTrack::setSampleRate(int rate)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800551{
552 int afSamplingRate;
553
John Grossman4ff14ba2012-02-08 16:37:41 -0800554 if (mIsTimed) {
555 return INVALID_OPERATION;
556 }
557
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800558 if (AudioSystem::getOutputSamplingRate(&afSamplingRate, mStreamType) != NO_ERROR) {
Eric Laurent57326622009-07-07 07:10:45 -0700559 return NO_INIT;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800560 }
561 // Resampler implementation limits input sampling rate to 2 x output sampling rate.
Eric Laurent57326622009-07-07 07:10:45 -0700562 if (rate <= 0 || rate > afSamplingRate*2 ) return BAD_VALUE;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800563
Eric Laurent1703cdf2011-03-07 14:52:59 -0800564 AutoMutex lock(mLock);
Eric Laurent57326622009-07-07 07:10:45 -0700565 mCblk->sampleRate = rate;
566 return NO_ERROR;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800567}
568
Glenn Kastena5224f32012-01-04 12:41:44 -0800569uint32_t AudioTrack::getSampleRate() const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800570{
John Grossman4ff14ba2012-02-08 16:37:41 -0800571 if (mIsTimed) {
572 return INVALID_OPERATION;
573 }
574
Eric Laurent1703cdf2011-03-07 14:52:59 -0800575 AutoMutex lock(mLock);
Eric Laurent57326622009-07-07 07:10:45 -0700576 return mCblk->sampleRate;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800577}
578
579status_t AudioTrack::setLoop(uint32_t loopStart, uint32_t loopEnd, int loopCount)
580{
Eric Laurent1703cdf2011-03-07 14:52:59 -0800581 AutoMutex lock(mLock);
582 return setLoop_l(loopStart, loopEnd, loopCount);
583}
584
585// must be called with mLock held
586status_t AudioTrack::setLoop_l(uint32_t loopStart, uint32_t loopEnd, int loopCount)
587{
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800588 audio_track_cblk_t* cblk = mCblk;
589
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800590 Mutex::Autolock _l(cblk->lock);
591
592 if (loopCount == 0) {
593 cblk->loopStart = UINT_MAX;
594 cblk->loopEnd = UINT_MAX;
595 cblk->loopCount = 0;
596 mLoopCount = 0;
597 return NO_ERROR;
598 }
599
John Grossman4ff14ba2012-02-08 16:37:41 -0800600 if (mIsTimed) {
601 return INVALID_OPERATION;
602 }
603
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800604 if (loopStart >= loopEnd ||
Eric Laurent9b7d9502011-03-21 11:49:00 -0700605 loopEnd - loopStart > cblk->frameCount ||
606 cblk->server > loopStart) {
Steve Block29357bc2012-01-06 19:20:56 +0000607 ALOGE("setLoop invalid value: loopStart %d, loopEnd %d, loopCount %d, framecount %d, user %d", loopStart, loopEnd, loopCount, cblk->frameCount, cblk->user);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800608 return BAD_VALUE;
609 }
610
Eric Laurent9b7d9502011-03-21 11:49:00 -0700611 if ((mSharedBuffer != 0) && (loopEnd > cblk->frameCount)) {
Steve Block29357bc2012-01-06 19:20:56 +0000612 ALOGE("setLoop invalid value: loop markers beyond data: loopStart %d, loopEnd %d, framecount %d",
Eric Laurentd1b449a2010-05-14 03:26:45 -0700613 loopStart, loopEnd, cblk->frameCount);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800614 return BAD_VALUE;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700615 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800616
617 cblk->loopStart = loopStart;
618 cblk->loopEnd = loopEnd;
619 cblk->loopCount = loopCount;
620 mLoopCount = loopCount;
621
622 return NO_ERROR;
623}
624
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800625status_t AudioTrack::setMarkerPosition(uint32_t marker)
626{
Glenn Kastena0d68332012-01-27 16:47:15 -0800627 if (mCbf == NULL) return INVALID_OPERATION;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800628
629 mMarkerPosition = marker;
Jean-Michel Trivi2c22aeb2009-03-24 18:11:07 -0700630 mMarkerReached = false;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800631
632 return NO_ERROR;
633}
634
Glenn Kastena5224f32012-01-04 12:41:44 -0800635status_t AudioTrack::getMarkerPosition(uint32_t *marker) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800636{
Glenn Kastena0d68332012-01-27 16:47:15 -0800637 if (marker == NULL) return BAD_VALUE;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800638
639 *marker = mMarkerPosition;
640
641 return NO_ERROR;
642}
643
644status_t AudioTrack::setPositionUpdatePeriod(uint32_t updatePeriod)
645{
Glenn Kastena0d68332012-01-27 16:47:15 -0800646 if (mCbf == NULL) return INVALID_OPERATION;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800647
648 uint32_t curPosition;
649 getPosition(&curPosition);
650 mNewPosition = curPosition + updatePeriod;
651 mUpdatePeriod = updatePeriod;
652
653 return NO_ERROR;
654}
655
Glenn Kastena5224f32012-01-04 12:41:44 -0800656status_t AudioTrack::getPositionUpdatePeriod(uint32_t *updatePeriod) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800657{
Glenn Kastena0d68332012-01-27 16:47:15 -0800658 if (updatePeriod == NULL) return BAD_VALUE;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800659
660 *updatePeriod = mUpdatePeriod;
661
662 return NO_ERROR;
663}
664
665status_t AudioTrack::setPosition(uint32_t position)
666{
John Grossman4ff14ba2012-02-08 16:37:41 -0800667 if (mIsTimed) return INVALID_OPERATION;
668
Eric Laurent1703cdf2011-03-07 14:52:59 -0800669 AutoMutex lock(mLock);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800670
Glenn Kasten9a2aaf92012-01-03 09:42:47 -0800671 if (!stopped_l()) return INVALID_OPERATION;
672
673 Mutex::Autolock _l(mCblk->lock);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800674
675 if (position > mCblk->user) return BAD_VALUE;
676
677 mCblk->server = position;
Eric Laurent38ccae22011-03-28 18:37:07 -0700678 android_atomic_or(CBLK_FORCEREADY_ON, &mCblk->flags);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700679
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800680 return NO_ERROR;
681}
682
683status_t AudioTrack::getPosition(uint32_t *position)
684{
Glenn Kastena0d68332012-01-27 16:47:15 -0800685 if (position == NULL) return BAD_VALUE;
Eric Laurent1703cdf2011-03-07 14:52:59 -0800686 AutoMutex lock(mLock);
Jean-Michel Trivicd075942011-08-25 16:47:23 -0700687 *position = mFlushed ? 0 : mCblk->server;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800688
689 return NO_ERROR;
690}
691
692status_t AudioTrack::reload()
693{
Eric Laurent1703cdf2011-03-07 14:52:59 -0800694 AutoMutex lock(mLock);
695
Glenn Kasten9a2aaf92012-01-03 09:42:47 -0800696 if (!stopped_l()) return INVALID_OPERATION;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700697
Eric Laurent1703cdf2011-03-07 14:52:59 -0800698 flush_l();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800699
Eric Laurentd1b449a2010-05-14 03:26:45 -0700700 mCblk->stepUser(mCblk->frameCount);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800701
702 return NO_ERROR;
703}
704
Eric Laurentc2f1f072009-07-17 12:17:14 -0700705audio_io_handle_t AudioTrack::getOutput()
706{
Eric Laurent1703cdf2011-03-07 14:52:59 -0800707 AutoMutex lock(mLock);
708 return getOutput_l();
709}
710
711// must be called with mLock held
712audio_io_handle_t AudioTrack::getOutput_l()
713{
Glenn Kastenfff6d712012-01-12 16:38:12 -0800714 return AudioSystem::getOutput(mStreamType,
Glenn Kasten18868c52012-03-07 09:15:37 -0800715 mCblk->sampleRate, mFormat, mChannelMask, mFlags);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700716}
717
Glenn Kastena5224f32012-01-04 12:41:44 -0800718int AudioTrack::getSessionId() const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700719{
720 return mSessionId;
721}
722
723status_t AudioTrack::attachAuxEffect(int effectId)
724{
Steve Block3856b092011-10-20 11:56:00 +0100725 ALOGV("attachAuxEffect(%d)", effectId);
Eric Laurent2beeb502010-07-16 07:43:46 -0700726 status_t status = mAudioTrack->attachAuxEffect(effectId);
727 if (status == NO_ERROR) {
728 mAuxEffectId = effectId;
729 }
730 return status;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700731}
732
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800733// -------------------------------------------------------------------------
734
Eric Laurent1703cdf2011-03-07 14:52:59 -0800735// must be called with mLock held
736status_t AudioTrack::createTrack_l(
Glenn Kastenfff6d712012-01-12 16:38:12 -0800737 audio_stream_type_t streamType,
Eric Laurent34f1d8e2009-11-04 08:27:26 -0800738 uint32_t sampleRate,
Glenn Kastene1c39622012-01-04 09:36:37 -0800739 audio_format_t format,
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700740 uint32_t channelMask,
Eric Laurent34f1d8e2009-11-04 08:27:26 -0800741 int frameCount,
Glenn Kasten18868c52012-03-07 09:15:37 -0800742 audio_policy_output_flags_t flags,
Eric Laurent34f1d8e2009-11-04 08:27:26 -0800743 const sp<IMemory>& sharedBuffer,
Glenn Kasten291f4d52012-03-19 12:16:56 -0700744 audio_io_handle_t output)
Eric Laurent34f1d8e2009-11-04 08:27:26 -0800745{
746 status_t status;
747 const sp<IAudioFlinger>& audioFlinger = AudioSystem::get_audio_flinger();
748 if (audioFlinger == 0) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700749 ALOGE("Could not get audioflinger");
750 return NO_INIT;
Eric Laurent34f1d8e2009-11-04 08:27:26 -0800751 }
752
Eric Laurentd1b449a2010-05-14 03:26:45 -0700753 int afSampleRate;
754 if (AudioSystem::getOutputSamplingRate(&afSampleRate, streamType) != NO_ERROR) {
755 return NO_INIT;
756 }
757 int afFrameCount;
758 if (AudioSystem::getOutputFrameCount(&afFrameCount, streamType) != NO_ERROR) {
759 return NO_INIT;
760 }
761 uint32_t afLatency;
762 if (AudioSystem::getOutputLatency(&afLatency, streamType) != NO_ERROR) {
763 return NO_INIT;
764 }
765
Glenn Kasten4a4a0952012-03-19 11:38:14 -0700766 // Client decides whether the track is TIMED (see below), but can only express a preference
767 // for FAST. Server will perform additional tests.
768 if ((flags & AUDIO_POLICY_OUTPUT_FLAG_FAST) && !(
769 // either of these use cases:
770 // use case 1: shared buffer
771 (sharedBuffer != 0) ||
772 // use case 2: callback handler
773 (mCbf != NULL))) {
774 ALOGW("AUDIO_POLICY_OUTPUT_FLAG_FAST denied");
775 flags = (audio_policy_output_flags_t) (flags & ~AUDIO_POLICY_OUTPUT_FLAG_FAST);
776 }
777
Eric Laurentd1b449a2010-05-14 03:26:45 -0700778 mNotificationFramesAct = mNotificationFramesReq;
Dima Zavinfce7a472011-04-19 22:30:36 -0700779 if (!audio_is_linear_pcm(format)) {
Eric Laurentd1b449a2010-05-14 03:26:45 -0700780 if (sharedBuffer != 0) {
781 frameCount = sharedBuffer->size();
782 }
783 } else {
784 // Ensure that buffer depth covers at least audio hardware latency
785 uint32_t minBufCount = afLatency / ((1000 * afFrameCount)/afSampleRate);
786 if (minBufCount < 2) minBufCount = 2;
787
788 int minFrameCount = (afFrameCount*sampleRate*minBufCount)/afSampleRate;
789
790 if (sharedBuffer == 0) {
791 if (frameCount == 0) {
792 frameCount = minFrameCount;
793 }
794 if (mNotificationFramesAct == 0) {
795 mNotificationFramesAct = frameCount/2;
796 }
797 // Make sure that application is notified with sufficient margin
798 // before underrun
799 if (mNotificationFramesAct > (uint32_t)frameCount/2) {
800 mNotificationFramesAct = frameCount/2;
801 }
Glenn Kasten4a4a0952012-03-19 11:38:14 -0700802 if (frameCount < minFrameCount && !(flags & AUDIO_POLICY_OUTPUT_FLAG_FAST)) {
Glenn Kasten291f4d52012-03-19 12:16:56 -0700803 // not ALOGW because it happens all the time when playing key clicks over A2DP
804 ALOGV("Minimum buffer size corrected from %d to %d",
Eric Laurentd8d61852012-03-05 17:06:40 -0800805 frameCount, minFrameCount);
806 frameCount = minFrameCount;
Eric Laurentd1b449a2010-05-14 03:26:45 -0700807 }
808 } else {
Glenn Kasten99e53b82012-01-19 08:59:58 -0800809 // Ensure that buffer alignment matches channelCount
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700810 int channelCount = popcount(channelMask);
Eric Laurentd1b449a2010-05-14 03:26:45 -0700811 if (((uint32_t)sharedBuffer->pointer() & (channelCount | 1)) != 0) {
Steve Block29357bc2012-01-06 19:20:56 +0000812 ALOGE("Invalid buffer alignement: address %p, channelCount %d", sharedBuffer->pointer(), channelCount);
Eric Laurentd1b449a2010-05-14 03:26:45 -0700813 return BAD_VALUE;
814 }
815 frameCount = sharedBuffer->size()/channelCount/sizeof(int16_t);
816 }
817 }
818
Glenn Kastena075db42012-03-06 11:22:44 -0800819 IAudioFlinger::track_flags_t trackFlags = IAudioFlinger::TRACK_DEFAULT;
820 if (mIsTimed) {
821 trackFlags |= IAudioFlinger::TRACK_TIMED;
822 }
Glenn Kasten4a4a0952012-03-19 11:38:14 -0700823 if (flags & AUDIO_POLICY_OUTPUT_FLAG_FAST) {
824 trackFlags |= IAudioFlinger::TRACK_FAST;
825 }
826
Eric Laurent34f1d8e2009-11-04 08:27:26 -0800827 sp<IAudioTrack> track = audioFlinger->createTrack(getpid(),
828 streamType,
829 sampleRate,
830 format,
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700831 channelMask,
Eric Laurent34f1d8e2009-11-04 08:27:26 -0800832 frameCount,
Glenn Kastena075db42012-03-06 11:22:44 -0800833 trackFlags,
Eric Laurent34f1d8e2009-11-04 08:27:26 -0800834 sharedBuffer,
835 output,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700836 &mSessionId,
Eric Laurent34f1d8e2009-11-04 08:27:26 -0800837 &status);
838
839 if (track == 0) {
Steve Block29357bc2012-01-06 19:20:56 +0000840 ALOGE("AudioFlinger could not create track, status: %d", status);
Eric Laurent34f1d8e2009-11-04 08:27:26 -0800841 return status;
842 }
843 sp<IMemory> cblk = track->getCblk();
844 if (cblk == 0) {
Steve Block29357bc2012-01-06 19:20:56 +0000845 ALOGE("Could not get control block");
Eric Laurent34f1d8e2009-11-04 08:27:26 -0800846 return NO_INIT;
847 }
Eric Laurent34f1d8e2009-11-04 08:27:26 -0800848 mAudioTrack = track;
Eric Laurent34f1d8e2009-11-04 08:27:26 -0800849 mCblkMemory = cblk;
850 mCblk = static_cast<audio_track_cblk_t*>(cblk->pointer());
Eric Laurent38ccae22011-03-28 18:37:07 -0700851 android_atomic_or(CBLK_DIRECTION_OUT, &mCblk->flags);
Eric Laurent34f1d8e2009-11-04 08:27:26 -0800852 if (sharedBuffer == 0) {
853 mCblk->buffers = (char*)mCblk + sizeof(audio_track_cblk_t);
854 } else {
855 mCblk->buffers = sharedBuffer->pointer();
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700856 // Force buffer full condition as data is already present in shared memory
Eric Laurentd1b449a2010-05-14 03:26:45 -0700857 mCblk->stepUser(mCblk->frameCount);
Eric Laurent34f1d8e2009-11-04 08:27:26 -0800858 }
859
Glenn Kasten83d86532012-01-17 14:39:34 -0800860 mCblk->setVolumeLR((uint32_t(uint16_t(mVolume[RIGHT] * 0x1000)) << 16) | uint16_t(mVolume[LEFT] * 0x1000));
Glenn Kasten05632a52012-01-03 14:22:33 -0800861 mCblk->setSendLevel(mSendLevel);
Eric Laurent2beeb502010-07-16 07:43:46 -0700862 mAudioTrack->attachAuxEffect(mAuxEffectId);
Eric Laurent6100d2d2009-11-19 09:00:56 -0800863 mCblk->bufferTimeoutMs = MAX_STARTUP_TIMEOUT_MS;
864 mCblk->waitTimeMs = 0;
Eric Laurentd1b449a2010-05-14 03:26:45 -0700865 mRemainingFrames = mNotificationFramesAct;
866 mLatency = afLatency + (1000*mCblk->frameCount) / sampleRate;
Eric Laurent34f1d8e2009-11-04 08:27:26 -0800867 return NO_ERROR;
868}
869
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800870status_t AudioTrack::obtainBuffer(Buffer* audioBuffer, int32_t waitCount)
871{
Eric Laurent1703cdf2011-03-07 14:52:59 -0800872 AutoMutex lock(mLock);
Glenn Kasten9a2aaf92012-01-03 09:42:47 -0800873 bool active;
Glenn Kastend0965dd2011-06-22 16:18:04 -0700874 status_t result = NO_ERROR;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800875 audio_track_cblk_t* cblk = mCblk;
876 uint32_t framesReq = audioBuffer->frameCount;
Eric Laurent1dd70b92009-04-21 07:56:33 -0700877 uint32_t waitTimeMs = (waitCount < 0) ? cblk->bufferTimeoutMs : WAIT_PERIOD_MS;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800878
879 audioBuffer->frameCount = 0;
880 audioBuffer->size = 0;
881
882 uint32_t framesAvail = cblk->framesAvailable();
883
Eric Laurent9b7d9502011-03-21 11:49:00 -0700884 cblk->lock.lock();
885 if (cblk->flags & CBLK_INVALID_MSK) {
886 goto create_new_track;
887 }
888 cblk->lock.unlock();
889
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800890 if (framesAvail == 0) {
Eric Laurent34f1d8e2009-11-04 08:27:26 -0800891 cblk->lock.lock();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800892 goto start_loop_here;
893 while (framesAvail == 0) {
894 active = mActive;
Glenn Kastenf6b16782011-12-15 09:51:17 -0800895 if (CC_UNLIKELY(!active)) {
Steve Block3856b092011-10-20 11:56:00 +0100896 ALOGV("Not active and NO_MORE_BUFFERS");
Eric Laurent34f1d8e2009-11-04 08:27:26 -0800897 cblk->lock.unlock();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800898 return NO_MORE_BUFFERS;
899 }
Glenn Kastenf6b16782011-12-15 09:51:17 -0800900 if (CC_UNLIKELY(!waitCount)) {
Eric Laurent34f1d8e2009-11-04 08:27:26 -0800901 cblk->lock.unlock();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800902 return WOULD_BLOCK;
Eric Laurent34f1d8e2009-11-04 08:27:26 -0800903 }
Eric Laurentd1b449a2010-05-14 03:26:45 -0700904 if (!(cblk->flags & CBLK_INVALID_MSK)) {
Eric Laurent1703cdf2011-03-07 14:52:59 -0800905 mLock.unlock();
Eric Laurentd1b449a2010-05-14 03:26:45 -0700906 result = cblk->cv.waitRelative(cblk->lock, milliseconds(waitTimeMs));
Eric Laurentd1b449a2010-05-14 03:26:45 -0700907 cblk->lock.unlock();
Eric Laurent1703cdf2011-03-07 14:52:59 -0800908 mLock.lock();
Glenn Kasten9a2aaf92012-01-03 09:42:47 -0800909 if (!mActive) {
Eric Laurent1703cdf2011-03-07 14:52:59 -0800910 return status_t(STOPPED);
911 }
912 cblk->lock.lock();
913 }
914
915 if (cblk->flags & CBLK_INVALID_MSK) {
Eric Laurentd1b449a2010-05-14 03:26:45 -0700916 goto create_new_track;
917 }
Glenn Kastenf6b16782011-12-15 09:51:17 -0800918 if (CC_UNLIKELY(result != NO_ERROR)) {
Eric Laurent1dd70b92009-04-21 07:56:33 -0700919 cblk->waitTimeMs += waitTimeMs;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800920 if (cblk->waitTimeMs >= cblk->bufferTimeoutMs) {
921 // timing out when a loop has been set and we have already written upto loop end
922 // is a normal condition: no need to wake AudioFlinger up.
923 if (cblk->user < cblk->loopEnd) {
Steve Block5ff1dd52012-01-05 23:22:43 +0000924 ALOGW( "obtainBuffer timed out (is the CPU pegged?) %p "
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800925 "user=%08x, server=%08x", this, cblk->user, cblk->server);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700926 //unlock cblk mutex before calling mAudioTrack->start() (see issue #1617140)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800927 cblk->lock.unlock();
Glenn Kasten6dbc1352012-02-02 10:56:47 -0800928 result = mAudioTrack->start(0); // callback thread hasn't changed
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800929 cblk->lock.lock();
Eric Laurent1703cdf2011-03-07 14:52:59 -0800930 if (result == DEAD_OBJECT) {
Eric Laurent38ccae22011-03-28 18:37:07 -0700931 android_atomic_or(CBLK_INVALID_ON, &cblk->flags);
Eric Laurent1703cdf2011-03-07 14:52:59 -0800932create_new_track:
933 result = restoreTrack_l(cblk, false);
934 }
935 if (result != NO_ERROR) {
Steve Block5ff1dd52012-01-05 23:22:43 +0000936 ALOGW("obtainBuffer create Track error %d", result);
Eric Laurent1703cdf2011-03-07 14:52:59 -0800937 cblk->lock.unlock();
938 return result;
939 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800940 }
941 cblk->waitTimeMs = 0;
942 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700943
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800944 if (--waitCount == 0) {
Eric Laurent34f1d8e2009-11-04 08:27:26 -0800945 cblk->lock.unlock();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800946 return TIMED_OUT;
947 }
948 }
949 // read the server count again
950 start_loop_here:
951 framesAvail = cblk->framesAvailable_l();
952 }
Eric Laurent34f1d8e2009-11-04 08:27:26 -0800953 cblk->lock.unlock();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800954 }
955
Eric Laurent44d98482010-09-30 16:12:31 -0700956 // restart track if it was disabled by audioflinger due to previous underrun
Eric Laurent1703cdf2011-03-07 14:52:59 -0800957 if (mActive && (cblk->flags & CBLK_DISABLED_MSK)) {
Eric Laurent38ccae22011-03-28 18:37:07 -0700958 android_atomic_and(~CBLK_DISABLED_ON, &cblk->flags);
Steve Block5ff1dd52012-01-05 23:22:43 +0000959 ALOGW("obtainBuffer() track %p disabled, restarting", this);
Glenn Kasten6dbc1352012-02-02 10:56:47 -0800960 mAudioTrack->start(0); // callback thread hasn't changed
Eric Laurent44d98482010-09-30 16:12:31 -0700961 }
962
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800963 cblk->waitTimeMs = 0;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700964
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800965 if (framesReq > framesAvail) {
966 framesReq = framesAvail;
967 }
968
969 uint32_t u = cblk->user;
970 uint32_t bufferEnd = cblk->userBase + cblk->frameCount;
971
Marco Nelissena1472d92012-03-30 14:36:54 -0700972 if (framesReq > bufferEnd - u) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800973 framesReq = bufferEnd - u;
974 }
975
Eric Laurentc2f1f072009-07-17 12:17:14 -0700976 audioBuffer->flags = mMuted ? Buffer::MUTE : 0;
977 audioBuffer->channelCount = mChannelCount;
978 audioBuffer->frameCount = framesReq;
979 audioBuffer->size = framesReq * cblk->frameSize;
Dima Zavinfce7a472011-04-19 22:30:36 -0700980 if (audio_is_linear_pcm(mFormat)) {
981 audioBuffer->format = AUDIO_FORMAT_PCM_16_BIT;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700982 } else {
983 audioBuffer->format = mFormat;
984 }
985 audioBuffer->raw = (int8_t *)cblk->buffer(u);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800986 active = mActive;
987 return active ? status_t(NO_ERROR) : status_t(STOPPED);
988}
989
990void AudioTrack::releaseBuffer(Buffer* audioBuffer)
991{
Eric Laurent1703cdf2011-03-07 14:52:59 -0800992 AutoMutex lock(mLock);
993 mCblk->stepUser(audioBuffer->frameCount);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800994}
995
996// -------------------------------------------------------------------------
997
998ssize_t AudioTrack::write(const void* buffer, size_t userSize)
999{
1000
1001 if (mSharedBuffer != 0) return INVALID_OPERATION;
John Grossman4ff14ba2012-02-08 16:37:41 -08001002 if (mIsTimed) return INVALID_OPERATION;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001003
1004 if (ssize_t(userSize) < 0) {
Glenn Kasten99e53b82012-01-19 08:59:58 -08001005 // Sanity-check: user is most-likely passing an error code, and it would
1006 // make the return value ambiguous (actualSize vs error).
Steve Block29357bc2012-01-06 19:20:56 +00001007 ALOGE("AudioTrack::write(buffer=%p, size=%u (%d)",
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001008 buffer, userSize, userSize);
1009 return BAD_VALUE;
1010 }
1011
Steve Block3856b092011-10-20 11:56:00 +01001012 ALOGV("write %p: %d bytes, mActive=%d", this, userSize, mActive);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001013
Eric Laurent1703cdf2011-03-07 14:52:59 -08001014 // acquire a strong reference on the IMemory and IAudioTrack so that they cannot be destroyed
1015 // while we are accessing the cblk
1016 mLock.lock();
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001017 sp<IAudioTrack> audioTrack = mAudioTrack;
1018 sp<IMemory> iMem = mCblkMemory;
Eric Laurent1703cdf2011-03-07 14:52:59 -08001019 mLock.unlock();
1020
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001021 ssize_t written = 0;
1022 const int8_t *src = (const int8_t *)buffer;
1023 Buffer audioBuffer;
Glenn Kastenb9980652012-01-11 09:48:27 -08001024 size_t frameSz = frameSize();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001025
1026 do {
Eric Laurent33797ea2011-03-17 09:36:51 -07001027 audioBuffer.frameCount = userSize/frameSz;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001028
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001029 status_t err = obtainBuffer(&audioBuffer, -1);
1030 if (err < 0) {
1031 // out of buffers, return #bytes written
1032 if (err == status_t(NO_MORE_BUFFERS))
1033 break;
1034 return ssize_t(err);
1035 }
1036
1037 size_t toWrite;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001038
Dima Zavinfce7a472011-04-19 22:30:36 -07001039 if (mFormat == AUDIO_FORMAT_PCM_8_BIT && !(mFlags & AUDIO_POLICY_OUTPUT_FLAG_DIRECT)) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001040 // Divide capacity by 2 to take expansion into account
1041 toWrite = audioBuffer.size>>1;
Glenn Kasten511754b2012-01-11 09:52:19 -08001042 memcpy_to_i16_from_u8(audioBuffer.i16, (const uint8_t *) src, toWrite);
Eric Laurent33025262009-08-04 10:42:26 -07001043 } else {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001044 toWrite = audioBuffer.size;
1045 memcpy(audioBuffer.i8, src, toWrite);
1046 src += toWrite;
1047 }
1048 userSize -= toWrite;
1049 written += toWrite;
1050
1051 releaseBuffer(&audioBuffer);
Eric Laurent33797ea2011-03-17 09:36:51 -07001052 } while (userSize >= frameSz);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001053
1054 return written;
1055}
1056
1057// -------------------------------------------------------------------------
1058
John Grossman4ff14ba2012-02-08 16:37:41 -08001059TimedAudioTrack::TimedAudioTrack() {
1060 mIsTimed = true;
1061}
1062
1063status_t TimedAudioTrack::allocateTimedBuffer(size_t size, sp<IMemory>* buffer)
1064{
1065 status_t result = UNKNOWN_ERROR;
1066
1067 // If the track is not invalid already, try to allocate a buffer. alloc
1068 // fails indicating that the server is dead, flag the track as invalid so
1069 // we can attempt to restore in in just a bit.
1070 if (!(mCblk->flags & CBLK_INVALID_MSK)) {
1071 result = mAudioTrack->allocateTimedBuffer(size, buffer);
1072 if (result == DEAD_OBJECT) {
1073 android_atomic_or(CBLK_INVALID_ON, &mCblk->flags);
1074 }
1075 }
1076
1077 // If the track is invalid at this point, attempt to restore it. and try the
1078 // allocation one more time.
1079 if (mCblk->flags & CBLK_INVALID_MSK) {
1080 mCblk->lock.lock();
1081 result = restoreTrack_l(mCblk, false);
1082 mCblk->lock.unlock();
1083
1084 if (result == OK)
1085 result = mAudioTrack->allocateTimedBuffer(size, buffer);
1086 }
1087
1088 return result;
1089}
1090
1091status_t TimedAudioTrack::queueTimedBuffer(const sp<IMemory>& buffer,
1092 int64_t pts)
1093{
1094 // restart track if it was disabled by audioflinger due to previous underrun
1095 if (mActive && (mCblk->flags & CBLK_DISABLED_MSK)) {
1096 android_atomic_and(~CBLK_DISABLED_ON, &mCblk->flags);
1097 ALOGW("queueTimedBuffer() track %p disabled, restarting", this);
1098 mAudioTrack->start(0);
1099 }
1100
1101 return mAudioTrack->queueTimedBuffer(buffer, pts);
1102}
1103
1104status_t TimedAudioTrack::setMediaTimeTransform(const LinearTransform& xform,
1105 TargetTimeline target)
1106{
1107 return mAudioTrack->setMediaTimeTransform(xform, target);
1108}
1109
1110// -------------------------------------------------------------------------
1111
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001112bool AudioTrack::processAudioBuffer(const sp<AudioTrackThread>& thread)
1113{
1114 Buffer audioBuffer;
1115 uint32_t frames;
1116 size_t writtenSize;
1117
Eric Laurent1703cdf2011-03-07 14:52:59 -08001118 mLock.lock();
1119 // acquire a strong reference on the IMemory and IAudioTrack so that they cannot be destroyed
1120 // while we are accessing the cblk
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001121 sp<IAudioTrack> audioTrack = mAudioTrack;
1122 sp<IMemory> iMem = mCblkMemory;
Eric Laurent1703cdf2011-03-07 14:52:59 -08001123 audio_track_cblk_t* cblk = mCblk;
Glenn Kasten9a2aaf92012-01-03 09:42:47 -08001124 bool active = mActive;
Eric Laurent1703cdf2011-03-07 14:52:59 -08001125 mLock.unlock();
1126
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001127 // Manage underrun callback
Glenn Kasten9a2aaf92012-01-03 09:42:47 -08001128 if (active && (cblk->framesAvailable() == cblk->frameCount)) {
Steve Block3856b092011-10-20 11:56:00 +01001129 ALOGV("Underrun user: %x, server: %x, flags %04x", cblk->user, cblk->server, cblk->flags);
Eric Laurent38ccae22011-03-28 18:37:07 -07001130 if (!(android_atomic_or(CBLK_UNDERRUN_ON, &cblk->flags) & CBLK_UNDERRUN_MSK)) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001131 mCbf(EVENT_UNDERRUN, mUserData, 0);
Eric Laurent1703cdf2011-03-07 14:52:59 -08001132 if (cblk->server == cblk->frameCount) {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001133 mCbf(EVENT_BUFFER_END, mUserData, 0);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001134 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001135 if (mSharedBuffer != 0) return false;
1136 }
1137 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001138
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001139 // Manage loop end callback
Eric Laurent1703cdf2011-03-07 14:52:59 -08001140 while (mLoopCount > cblk->loopCount) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001141 int loopCount = -1;
1142 mLoopCount--;
1143 if (mLoopCount >= 0) loopCount = mLoopCount;
1144
1145 mCbf(EVENT_LOOP_END, mUserData, (void *)&loopCount);
1146 }
1147
1148 // Manage marker callback
Jean-Michel Trivi2c22aeb2009-03-24 18:11:07 -07001149 if (!mMarkerReached && (mMarkerPosition > 0)) {
Eric Laurent1703cdf2011-03-07 14:52:59 -08001150 if (cblk->server >= mMarkerPosition) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001151 mCbf(EVENT_MARKER, mUserData, (void *)&mMarkerPosition);
Jean-Michel Trivi2c22aeb2009-03-24 18:11:07 -07001152 mMarkerReached = true;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001153 }
1154 }
1155
1156 // Manage new position callback
Eric Laurentc2f1f072009-07-17 12:17:14 -07001157 if (mUpdatePeriod > 0) {
Eric Laurent1703cdf2011-03-07 14:52:59 -08001158 while (cblk->server >= mNewPosition) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001159 mCbf(EVENT_NEW_POS, mUserData, (void *)&mNewPosition);
1160 mNewPosition += mUpdatePeriod;
1161 }
1162 }
1163
1164 // If Shared buffer is used, no data is requested from client.
1165 if (mSharedBuffer != 0) {
1166 frames = 0;
1167 } else {
1168 frames = mRemainingFrames;
1169 }
1170
Glenn Kasten99e53b82012-01-19 08:59:58 -08001171 // See description of waitCount parameter at declaration of obtainBuffer().
1172 // The logic below prevents us from being stuck below at obtainBuffer()
1173 // not being able to handle timed events (position, markers, loops).
Eric Laurent2267ba12011-09-07 11:13:23 -07001174 int32_t waitCount = -1;
1175 if (mUpdatePeriod || (!mMarkerReached && mMarkerPosition) || mLoopCount) {
1176 waitCount = 1;
1177 }
1178
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001179 do {
1180
1181 audioBuffer.frameCount = frames;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001182
Eric Laurent2267ba12011-09-07 11:13:23 -07001183 status_t err = obtainBuffer(&audioBuffer, waitCount);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001184 if (err < NO_ERROR) {
1185 if (err != TIMED_OUT) {
Steve Block29357bc2012-01-06 19:20:56 +00001186 ALOGE_IF(err != status_t(NO_MORE_BUFFERS), "Error obtaining an audio buffer, giving up.");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001187 return false;
1188 }
1189 break;
1190 }
1191 if (err == status_t(STOPPED)) return false;
1192
1193 // Divide buffer size by 2 to take into account the expansion
1194 // due to 8 to 16 bit conversion: the callback must fill only half
1195 // of the destination buffer
Dima Zavinfce7a472011-04-19 22:30:36 -07001196 if (mFormat == AUDIO_FORMAT_PCM_8_BIT && !(mFlags & AUDIO_POLICY_OUTPUT_FLAG_DIRECT)) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001197 audioBuffer.size >>= 1;
1198 }
1199
1200 size_t reqSize = audioBuffer.size;
1201 mCbf(EVENT_MORE_DATA, mUserData, &audioBuffer);
1202 writtenSize = audioBuffer.size;
1203
1204 // Sanity check on returned size
The Android Open Source Project8555d082009-03-05 14:34:35 -08001205 if (ssize_t(writtenSize) <= 0) {
1206 // The callback is done filling buffers
1207 // Keep this thread going to handle timed events and
1208 // still try to get more data in intervals of WAIT_PERIOD_MS
1209 // but don't just loop and block the CPU, so wait
1210 usleep(WAIT_PERIOD_MS*1000);
1211 break;
1212 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001213 if (writtenSize > reqSize) writtenSize = reqSize;
1214
Dima Zavinfce7a472011-04-19 22:30:36 -07001215 if (mFormat == AUDIO_FORMAT_PCM_8_BIT && !(mFlags & AUDIO_POLICY_OUTPUT_FLAG_DIRECT)) {
Glenn Kasten511754b2012-01-11 09:52:19 -08001216 // 8 to 16 bit conversion, note that source and destination are the same address
1217 memcpy_to_i16_from_u8(audioBuffer.i16, (const uint8_t *) audioBuffer.i8, writtenSize);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001218 writtenSize <<= 1;
1219 }
1220
1221 audioBuffer.size = writtenSize;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001222 // NOTE: mCblk->frameSize is not equal to AudioTrack::frameSize() for
Glenn Kastenb9980652012-01-11 09:48:27 -08001223 // 8 bit PCM data: in this case, mCblk->frameSize is based on a sample size of
Eric Laurentc2f1f072009-07-17 12:17:14 -07001224 // 16 bit.
1225 audioBuffer.frameCount = writtenSize/mCblk->frameSize;
1226
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001227 frames -= audioBuffer.frameCount;
1228
1229 releaseBuffer(&audioBuffer);
1230 }
1231 while (frames);
1232
1233 if (frames == 0) {
Eric Laurentd1b449a2010-05-14 03:26:45 -07001234 mRemainingFrames = mNotificationFramesAct;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001235 } else {
1236 mRemainingFrames = frames;
1237 }
1238 return true;
1239}
1240
Eric Laurent1703cdf2011-03-07 14:52:59 -08001241// must be called with mLock and cblk.lock held. Callers must also hold strong references on
1242// the IAudioTrack and IMemory in case they are recreated here.
1243// If the IAudioTrack is successfully restored, the cblk pointer is updated
1244status_t AudioTrack::restoreTrack_l(audio_track_cblk_t*& cblk, bool fromStart)
1245{
1246 status_t result;
1247
Eric Laurent38ccae22011-03-28 18:37:07 -07001248 if (!(android_atomic_or(CBLK_RESTORING_ON, &cblk->flags) & CBLK_RESTORING_MSK)) {
Steve Block5ff1dd52012-01-05 23:22:43 +00001249 ALOGW("dead IAudioTrack, creating a new one from %s TID %d",
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001250 fromStart ? "start()" : "obtainBuffer()", gettid());
Eric Laurent1703cdf2011-03-07 14:52:59 -08001251
Eric Laurent1703cdf2011-03-07 14:52:59 -08001252 // signal old cblk condition so that other threads waiting for available buffers stop
1253 // waiting now
1254 cblk->cv.broadcast();
1255 cblk->lock.unlock();
1256
Eric Laurent9f6530f2011-08-30 10:18:54 -07001257 // refresh the audio configuration cache in this process to make sure we get new
1258 // output parameters in getOutput_l() and createTrack_l()
1259 AudioSystem::clearAudioConfigCache();
1260
Eric Laurent1703cdf2011-03-07 14:52:59 -08001261 // if the new IAudioTrack is created, createTrack_l() will modify the
1262 // following member variables: mAudioTrack, mCblkMemory and mCblk.
1263 // It will also delete the strong references on previous IAudioTrack and IMemory
1264 result = createTrack_l(mStreamType,
1265 cblk->sampleRate,
1266 mFormat,
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -07001267 mChannelMask,
Eric Laurent1703cdf2011-03-07 14:52:59 -08001268 mFrameCount,
1269 mFlags,
1270 mSharedBuffer,
Glenn Kasten291f4d52012-03-19 12:16:56 -07001271 getOutput_l());
Eric Laurent1703cdf2011-03-07 14:52:59 -08001272
1273 if (result == NO_ERROR) {
Eric Laurent408b8dc2011-09-06 12:36:15 -07001274 uint32_t user = cblk->user;
1275 uint32_t server = cblk->server;
Eric Laurent9b7d9502011-03-21 11:49:00 -07001276 // restore write index and set other indexes to reflect empty buffer status
Eric Laurent408b8dc2011-09-06 12:36:15 -07001277 mCblk->user = user;
1278 mCblk->server = user;
1279 mCblk->userBase = user;
1280 mCblk->serverBase = user;
Eric Laurent9b7d9502011-03-21 11:49:00 -07001281 // restore loop: this is not guaranteed to succeed if new frame count is not
1282 // compatible with loop length
1283 setLoop_l(cblk->loopStart, cblk->loopEnd, cblk->loopCount);
Eric Laurent1703cdf2011-03-07 14:52:59 -08001284 if (!fromStart) {
1285 mCblk->bufferTimeoutMs = MAX_RUN_TIMEOUT_MS;
Eric Laurent408b8dc2011-09-06 12:36:15 -07001286 // Make sure that a client relying on callback events indicating underrun or
1287 // the actual amount of audio frames played (e.g SoundPool) receives them.
1288 if (mSharedBuffer == 0) {
1289 uint32_t frames = 0;
1290 if (user > server) {
1291 frames = ((user - server) > mCblk->frameCount) ?
1292 mCblk->frameCount : (user - server);
1293 memset(mCblk->buffers, 0, frames * mCblk->frameSize);
1294 }
1295 // restart playback even if buffer is not completely filled.
1296 android_atomic_or(CBLK_FORCEREADY_ON, &mCblk->flags);
1297 // stepUser() clears CBLK_UNDERRUN_ON flag enabling underrun callbacks to
1298 // the client
1299 mCblk->stepUser(frames);
1300 }
Eric Laurent1703cdf2011-03-07 14:52:59 -08001301 }
Eric Laurent9b7d9502011-03-21 11:49:00 -07001302 if (mActive) {
Glenn Kasten6dbc1352012-02-02 10:56:47 -08001303 result = mAudioTrack->start(0); // callback thread hasn't changed
Steve Block5ff1dd52012-01-05 23:22:43 +00001304 ALOGW_IF(result != NO_ERROR, "restoreTrack_l() start() failed status %d", result);
Eric Laurent9b7d9502011-03-21 11:49:00 -07001305 }
Eric Laurent1703cdf2011-03-07 14:52:59 -08001306 if (fromStart && result == NO_ERROR) {
1307 mNewPosition = mCblk->server + mUpdatePeriod;
1308 }
1309 }
1310 if (result != NO_ERROR) {
Eric Laurentcfe2ba62011-09-13 15:04:17 -07001311 android_atomic_and(~CBLK_RESTORING_ON, &cblk->flags);
Steve Block5ff1dd52012-01-05 23:22:43 +00001312 ALOGW_IF(result != NO_ERROR, "restoreTrack_l() failed status %d", result);
Eric Laurent1703cdf2011-03-07 14:52:59 -08001313 }
Eric Laurentcfe2ba62011-09-13 15:04:17 -07001314 mRestoreStatus = result;
Eric Laurent1703cdf2011-03-07 14:52:59 -08001315 // signal old cblk condition for other threads waiting for restore completion
Eric Laurent38ccae22011-03-28 18:37:07 -07001316 android_atomic_or(CBLK_RESTORED_ON, &cblk->flags);
Eric Laurent1703cdf2011-03-07 14:52:59 -08001317 cblk->cv.broadcast();
Eric Laurent1703cdf2011-03-07 14:52:59 -08001318 } else {
1319 if (!(cblk->flags & CBLK_RESTORED_MSK)) {
Steve Block5ff1dd52012-01-05 23:22:43 +00001320 ALOGW("dead IAudioTrack, waiting for a new one TID %d", gettid());
Eric Laurent1703cdf2011-03-07 14:52:59 -08001321 mLock.unlock();
1322 result = cblk->cv.waitRelative(cblk->lock, milliseconds(RESTORE_TIMEOUT_MS));
Eric Laurentcfe2ba62011-09-13 15:04:17 -07001323 if (result == NO_ERROR) {
1324 result = mRestoreStatus;
1325 }
Eric Laurent1703cdf2011-03-07 14:52:59 -08001326 cblk->lock.unlock();
1327 mLock.lock();
1328 } else {
Steve Block5ff1dd52012-01-05 23:22:43 +00001329 ALOGW("dead IAudioTrack, already restored TID %d", gettid());
Eric Laurentcfe2ba62011-09-13 15:04:17 -07001330 result = mRestoreStatus;
Eric Laurent1703cdf2011-03-07 14:52:59 -08001331 cblk->lock.unlock();
1332 }
Eric Laurent1703cdf2011-03-07 14:52:59 -08001333 }
Steve Block3856b092011-10-20 11:56:00 +01001334 ALOGV("restoreTrack_l() status %d mActive %d cblk %p, old cblk %p flags %08x old flags %08x",
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001335 result, mActive, mCblk, cblk, mCblk->flags, cblk->flags);
Eric Laurent1703cdf2011-03-07 14:52:59 -08001336
1337 if (result == NO_ERROR) {
1338 // from now on we switch to the newly created cblk
1339 cblk = mCblk;
1340 }
1341 cblk->lock.lock();
1342
Steve Block5ff1dd52012-01-05 23:22:43 +00001343 ALOGW_IF(result != NO_ERROR, "restoreTrack_l() error %d TID %d", result, gettid());
Eric Laurent1703cdf2011-03-07 14:52:59 -08001344
1345 return result;
1346}
1347
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001348status_t AudioTrack::dump(int fd, const Vector<String16>& args) const
1349{
1350
1351 const size_t SIZE = 256;
1352 char buffer[SIZE];
1353 String8 result;
1354
1355 result.append(" AudioTrack::dump\n");
1356 snprintf(buffer, 255, " stream type(%d), left - right volume(%f, %f)\n", mStreamType, mVolume[0], mVolume[1]);
1357 result.append(buffer);
Eric Laurentd1b449a2010-05-14 03:26:45 -07001358 snprintf(buffer, 255, " format(%d), channel count(%d), frame count(%d)\n", mFormat, mChannelCount, mCblk->frameCount);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001359 result.append(buffer);
Eric Laurent57326622009-07-07 07:10:45 -07001360 snprintf(buffer, 255, " sample rate(%d), status(%d), muted(%d)\n", (mCblk == 0) ? 0 : mCblk->sampleRate, mStatus, mMuted);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001361 result.append(buffer);
1362 snprintf(buffer, 255, " active(%d), latency (%d)\n", mActive, mLatency);
1363 result.append(buffer);
1364 ::write(fd, result.string(), result.size());
1365 return NO_ERROR;
1366}
1367
1368// =========================================================================
1369
1370AudioTrack::AudioTrackThread::AudioTrackThread(AudioTrack& receiver, bool bCanCallJava)
1371 : Thread(bCanCallJava), mReceiver(receiver)
1372{
1373}
1374
1375bool AudioTrack::AudioTrackThread::threadLoop()
1376{
1377 return mReceiver.processAudioBuffer(this);
1378}
1379
1380status_t AudioTrack::AudioTrackThread::readyToRun()
1381{
1382 return NO_ERROR;
1383}
1384
1385void AudioTrack::AudioTrackThread::onFirstRef()
1386{
1387}
1388
1389// =========================================================================
1390
Eric Laurent38ccae22011-03-28 18:37:07 -07001391
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001392audio_track_cblk_t::audio_track_cblk_t()
Mathias Agopian54b1a052010-03-19 16:14:13 -07001393 : lock(Mutex::SHARED), cv(Condition::SHARED), user(0), server(0),
Glenn Kastena0d68332012-01-27 16:47:15 -08001394 userBase(0), serverBase(0), buffers(NULL), frameCount(0),
Glenn Kasten83d86532012-01-17 14:39:34 -08001395 loopStart(UINT_MAX), loopEnd(UINT_MAX), loopCount(0), mVolumeLR(0x10001000),
Glenn Kasten05632a52012-01-03 14:22:33 -08001396 mSendLevel(0), flags(0)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001397{
1398}
1399
1400uint32_t audio_track_cblk_t::stepUser(uint32_t frameCount)
1401{
Marco Nelissena1472d92012-03-30 14:36:54 -07001402 ALOGV("stepuser %08x %08x %d", user, server, frameCount);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001403
Marco Nelissena1472d92012-03-30 14:36:54 -07001404 uint32_t u = user;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001405 u += frameCount;
1406 // Ensure that user is never ahead of server for AudioRecord
Eric Laurentd1b449a2010-05-14 03:26:45 -07001407 if (flags & CBLK_DIRECTION_MSK) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001408 // If stepServer() has been called once, switch to normal obtainBuffer() timeout period
1409 if (bufferTimeoutMs == MAX_STARTUP_TIMEOUT_MS-1) {
1410 bufferTimeoutMs = MAX_RUN_TIMEOUT_MS;
1411 }
Glenn Kasten90548972011-12-13 11:45:07 -08001412 } else if (u > server) {
Marco Nelissena1472d92012-03-30 14:36:54 -07001413 ALOGW("stepUser occurred after track reset");
Glenn Kasten90548972011-12-13 11:45:07 -08001414 u = server;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001415 }
1416
Marco Nelissena1472d92012-03-30 14:36:54 -07001417 uint32_t fc = this->frameCount;
1418 if (u >= fc) {
1419 // common case, user didn't just wrap
1420 if (u - fc >= userBase ) {
1421 userBase += fc;
1422 }
1423 } else if (u >= userBase + fc) {
1424 // user just wrapped
1425 userBase += fc;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001426 }
1427
Glenn Kasten90548972011-12-13 11:45:07 -08001428 user = u;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001429
1430 // Clear flow control error condition as new data has been written/read to/from buffer.
Eric Laurent33797ea2011-03-17 09:36:51 -07001431 if (flags & CBLK_UNDERRUN_MSK) {
Eric Laurent38ccae22011-03-28 18:37:07 -07001432 android_atomic_and(~CBLK_UNDERRUN_MSK, &flags);
Eric Laurent33797ea2011-03-17 09:36:51 -07001433 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001434
1435 return u;
1436}
1437
1438bool audio_track_cblk_t::stepServer(uint32_t frameCount)
1439{
Marco Nelissena1472d92012-03-30 14:36:54 -07001440 ALOGV("stepserver %08x %08x %d", user, server, frameCount);
1441
Eric Laurent38ccae22011-03-28 18:37:07 -07001442 if (!tryLock()) {
Steve Block5ff1dd52012-01-05 23:22:43 +00001443 ALOGW("stepServer() could not lock cblk");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001444 return false;
1445 }
1446
Glenn Kasten90548972011-12-13 11:45:07 -08001447 uint32_t s = server;
Marco Nelissena1472d92012-03-30 14:36:54 -07001448 bool flushed = (s == user);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001449
1450 s += frameCount;
Eric Laurentd1b449a2010-05-14 03:26:45 -07001451 if (flags & CBLK_DIRECTION_MSK) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001452 // Mark that we have read the first buffer so that next time stepUser() is called
1453 // we switch to normal obtainBuffer() timeout period
1454 if (bufferTimeoutMs == MAX_STARTUP_TIMEOUT_MS) {
Eric Laurent34f1d8e2009-11-04 08:27:26 -08001455 bufferTimeoutMs = MAX_STARTUP_TIMEOUT_MS - 1;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001456 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001457 // It is possible that we receive a flush()
1458 // while the mixer is processing a block: in this case,
1459 // stepServer() is called After the flush() has reset u & s and
1460 // we have s > u
Marco Nelissena1472d92012-03-30 14:36:54 -07001461 if (flushed) {
Steve Block5ff1dd52012-01-05 23:22:43 +00001462 ALOGW("stepServer occurred after track reset");
Glenn Kasten90548972011-12-13 11:45:07 -08001463 s = user;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001464 }
1465 }
1466
1467 if (s >= loopEnd) {
Steve Block5ff1dd52012-01-05 23:22:43 +00001468 ALOGW_IF(s > loopEnd, "stepServer: s %u > loopEnd %u", s, loopEnd);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001469 s = loopStart;
1470 if (--loopCount == 0) {
1471 loopEnd = UINT_MAX;
1472 loopStart = UINT_MAX;
1473 }
1474 }
Marco Nelissena1472d92012-03-30 14:36:54 -07001475
1476 uint32_t fc = this->frameCount;
1477 if (s >= fc) {
1478 // common case, server didn't just wrap
1479 if (s - fc >= serverBase ) {
1480 serverBase += fc;
1481 }
1482 } else if (s >= serverBase + fc) {
1483 // server just wrapped
1484 serverBase += fc;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001485 }
1486
Glenn Kasten90548972011-12-13 11:45:07 -08001487 server = s;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001488
Eric Laurent1703cdf2011-03-07 14:52:59 -08001489 if (!(flags & CBLK_INVALID_MSK)) {
1490 cv.signal();
1491 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001492 lock.unlock();
1493 return true;
1494}
1495
1496void* audio_track_cblk_t::buffer(uint32_t offset) const
1497{
Glenn Kasten90548972011-12-13 11:45:07 -08001498 return (int8_t *)buffers + (offset - userBase) * frameSize;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001499}
1500
1501uint32_t audio_track_cblk_t::framesAvailable()
1502{
1503 Mutex::Autolock _l(lock);
1504 return framesAvailable_l();
1505}
1506
1507uint32_t audio_track_cblk_t::framesAvailable_l()
1508{
Glenn Kasten90548972011-12-13 11:45:07 -08001509 uint32_t u = user;
1510 uint32_t s = server;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001511
Eric Laurentd1b449a2010-05-14 03:26:45 -07001512 if (flags & CBLK_DIRECTION_MSK) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001513 uint32_t limit = (s < loopStart) ? s : loopStart;
1514 return limit + frameCount - u;
1515 } else {
1516 return frameCount + u - s;
1517 }
1518}
1519
1520uint32_t audio_track_cblk_t::framesReady()
1521{
Glenn Kasten90548972011-12-13 11:45:07 -08001522 uint32_t u = user;
1523 uint32_t s = server;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001524
Eric Laurentd1b449a2010-05-14 03:26:45 -07001525 if (flags & CBLK_DIRECTION_MSK) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001526 if (u < loopEnd) {
1527 return u - s;
1528 } else {
Eric Laurent38ccae22011-03-28 18:37:07 -07001529 // do not block on mutex shared with client on AudioFlinger side
1530 if (!tryLock()) {
Steve Block5ff1dd52012-01-05 23:22:43 +00001531 ALOGW("framesReady() could not lock cblk");
Eric Laurent38ccae22011-03-28 18:37:07 -07001532 return 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001533 }
Eric Laurent38ccae22011-03-28 18:37:07 -07001534 uint32_t frames = UINT_MAX;
1535 if (loopCount >= 0) {
1536 frames = (loopEnd - loopStart)*loopCount + u - s;
1537 }
1538 lock.unlock();
1539 return frames;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001540 }
1541 } else {
1542 return s - u;
1543 }
1544}
1545
Eric Laurent38ccae22011-03-28 18:37:07 -07001546bool audio_track_cblk_t::tryLock()
1547{
1548 // the code below simulates lock-with-timeout
1549 // we MUST do this to protect the AudioFlinger server
1550 // as this lock is shared with the client.
1551 status_t err;
1552
1553 err = lock.tryLock();
1554 if (err == -EBUSY) { // just wait a bit
1555 usleep(1000);
1556 err = lock.tryLock();
1557 }
1558 if (err != NO_ERROR) {
1559 // probably, the client just died.
1560 return false;
1561 }
1562 return true;
1563}
1564
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001565// -------------------------------------------------------------------------
1566
1567}; // namespace android