blob: 24a6dfe5163b9bbfc1173894f29dc195f39fb73c [file] [log] [blame]
Glenn Kasten97b5d0d2012-03-23 18:54:19 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Glenn Kastena3d26282012-11-30 07:57:43 -080017// <IMPORTANT_WARNING>
18// Design rules for threadLoop() are given in the comments at section "Fast mixer thread" of
19// StateQueue.h. In particular, avoid library and system calls except at well-known points.
20// The design rules are only for threadLoop(), and don't apply to FastMixerDumpState methods.
21// </IMPORTANT_WARNING>
22
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070023#define LOG_TAG "FastMixer"
Glenn Kasten7f5d3352013-02-15 23:55:04 +000024//#define LOG_NDEBUG 0
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070025
Alex Rayb3a83642012-11-30 19:42:28 -080026#define ATRACE_TAG ATRACE_TAG_AUDIO
Alex Ray371eb972012-11-30 11:11:54 -080027
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070028#include <sys/atomics.h>
29#include <time.h>
30#include <utils/Log.h>
Glenn Kastend8e6fd32012-05-07 11:07:57 -070031#include <utils/Trace.h>
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070032#include <system/audio.h>
33#ifdef FAST_MIXER_STATISTICS
34#include <cpustats/CentralTendencyStatistics.h>
Glenn Kasten0a14c4c2012-06-13 14:58:49 -070035#ifdef CPU_FREQUENCY_STATISTICS
Glenn Kasten42d45cf2012-05-02 10:34:47 -070036#include <cpustats/ThreadCpuUsage.h>
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070037#endif
Glenn Kasten0a14c4c2012-06-13 14:58:49 -070038#endif
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070039#include "AudioMixer.h"
40#include "FastMixer.h"
41
42#define FAST_HOT_IDLE_NS 1000000L // 1 ms: time to sleep while hot idling
43#define FAST_DEFAULT_NS 999999999L // ~1 sec: default time to sleep
Glenn Kasteneb157162012-06-13 14:59:07 -070044#define MIN_WARMUP_CYCLES 2 // minimum number of loop cycles to wait for warmup
Glenn Kasten288ed212012-04-25 17:52:27 -070045#define MAX_WARMUP_CYCLES 10 // maximum number of loop cycles to wait for warmup
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070046
47namespace android {
48
49// Fast mixer thread
50bool FastMixer::threadLoop()
51{
52 static const FastMixerState initial;
53 const FastMixerState *previous = &initial, *current = &initial;
54 FastMixerState preIdle; // copy of state before we went into idle
55 struct timespec oldTs = {0, 0};
56 bool oldTsValid = false;
57 long slopNs = 0; // accumulated time we've woken up too early (> 0) or too late (< 0)
58 long sleepNs = -1; // -1: busy wait, 0: sched_yield, > 0: nanosleep
59 int fastTrackNames[FastMixerState::kMaxFastTracks]; // handles used by mixer to identify tracks
60 int generations[FastMixerState::kMaxFastTracks]; // last observed mFastTracks[i].mGeneration
61 unsigned i;
62 for (i = 0; i < FastMixerState::kMaxFastTracks; ++i) {
63 fastTrackNames[i] = -1;
64 generations[i] = 0;
65 }
66 NBAIO_Sink *outputSink = NULL;
67 int outputSinkGen = 0;
68 AudioMixer* mixer = NULL;
69 short *mixBuffer = NULL;
70 enum {UNDEFINED, MIXED, ZEROED} mixBufferState = UNDEFINED;
71 NBAIO_Format format = Format_Invalid;
72 unsigned sampleRate = 0;
73 int fastTracksGen = 0;
74 long periodNs = 0; // expected period; the time required to render one mix buffer
Glenn Kasten288ed212012-04-25 17:52:27 -070075 long underrunNs = 0; // underrun likely when write cycle is greater than this value
76 long overrunNs = 0; // overrun likely when write cycle is less than this value
Glenn Kasten972af222012-06-13 17:14:03 -070077 long forceNs = 0; // if overrun detected, force the write cycle to take this much time
Glenn Kasten288ed212012-04-25 17:52:27 -070078 long warmupNs = 0; // warmup complete when write cycle is greater than to this value
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070079 FastMixerDumpState dummyDumpState, *dumpState = &dummyDumpState;
80 bool ignoreNextOverrun = true; // used to ignore initial overrun and first after an underrun
81#ifdef FAST_MIXER_STATISTICS
Glenn Kasten42d45cf2012-05-02 10:34:47 -070082 struct timespec oldLoad = {0, 0}; // previous value of clock_gettime(CLOCK_THREAD_CPUTIME_ID)
83 bool oldLoadValid = false; // whether oldLoad is valid
84 uint32_t bounds = 0;
85 bool full = false; // whether we have collected at least kSamplingN samples
Glenn Kasten0a14c4c2012-06-13 14:58:49 -070086#ifdef CPU_FREQUENCY_STATISTICS
Glenn Kasten42d45cf2012-05-02 10:34:47 -070087 ThreadCpuUsage tcu; // for reading the current CPU clock frequency in kHz
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070088#endif
Glenn Kasten0a14c4c2012-06-13 14:58:49 -070089#endif
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070090 unsigned coldGen = 0; // last observed mColdGen
Glenn Kasten288ed212012-04-25 17:52:27 -070091 bool isWarm = false; // true means ready to mix, false means wait for warmup before mixing
92 struct timespec measuredWarmupTs = {0, 0}; // how long did it take for warmup to complete
93 uint32_t warmupCycles = 0; // counter of number of loop cycles required to warmup
Glenn Kastenfbae5da2012-05-21 09:17:20 -070094 NBAIO_Sink* teeSink = NULL; // if non-NULL, then duplicate write() to this non-blocking sink
Glenn Kasten9e58b552013-01-18 15:09:48 -080095 NBLog::Writer dummyLogWriter, *logWriter = &dummyLogWriter;
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070096
97 for (;;) {
98
99 // either nanosleep, sched_yield, or busy wait
100 if (sleepNs >= 0) {
101 if (sleepNs > 0) {
102 ALOG_ASSERT(sleepNs < 1000000000);
103 const struct timespec req = {0, sleepNs};
104 nanosleep(&req, NULL);
105 } else {
106 sched_yield();
107 }
108 }
109 // default to long sleep for next cycle
110 sleepNs = FAST_DEFAULT_NS;
111
112 // poll for state change
113 const FastMixerState *next = mSQ.poll();
114 if (next == NULL) {
115 // continue to use the default initial state until a real state is available
116 ALOG_ASSERT(current == &initial && previous == &initial);
117 next = current;
118 }
119
120 FastMixerState::Command command = next->mCommand;
121 if (next != current) {
122
123 // As soon as possible of learning of a new dump area, start using it
124 dumpState = next->mDumpState != NULL ? next->mDumpState : &dummyDumpState;
Glenn Kastenfbae5da2012-05-21 09:17:20 -0700125 teeSink = next->mTeeSink;
Glenn Kasten9e58b552013-01-18 15:09:48 -0800126 logWriter = next->mNBLogWriter != NULL ? next->mNBLogWriter : &dummyLogWriter;
Glenn Kastenab7d72f2013-02-27 09:05:28 -0800127 if (mixer != NULL) {
128 mixer->setLog(logWriter);
129 }
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700130
131 // We want to always have a valid reference to the previous (non-idle) state.
132 // However, the state queue only guarantees access to current and previous states.
133 // So when there is a transition from a non-idle state into an idle state, we make a
134 // copy of the last known non-idle state so it is still available on return from idle.
135 // The possible transitions are:
136 // non-idle -> non-idle update previous from current in-place
137 // non-idle -> idle update previous from copy of current
138 // idle -> idle don't update previous
139 // idle -> non-idle don't update previous
140 if (!(current->mCommand & FastMixerState::IDLE)) {
141 if (command & FastMixerState::IDLE) {
142 preIdle = *current;
143 current = &preIdle;
144 oldTsValid = false;
Glenn Kasten42d45cf2012-05-02 10:34:47 -0700145 oldLoadValid = false;
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700146 ignoreNextOverrun = true;
147 }
148 previous = current;
149 }
150 current = next;
151 }
152#if !LOG_NDEBUG
153 next = NULL; // not referenced again
154#endif
155
156 dumpState->mCommand = command;
157
158 switch (command) {
159 case FastMixerState::INITIAL:
160 case FastMixerState::HOT_IDLE:
161 sleepNs = FAST_HOT_IDLE_NS;
162 continue;
163 case FastMixerState::COLD_IDLE:
164 // only perform a cold idle command once
Glenn Kasten21e8c502012-04-12 09:39:42 -0700165 // FIXME consider checking previous state and only perform if previous != COLD_IDLE
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700166 if (current->mColdGen != coldGen) {
167 int32_t *coldFutexAddr = current->mColdFutexAddr;
168 ALOG_ASSERT(coldFutexAddr != NULL);
169 int32_t old = android_atomic_dec(coldFutexAddr);
170 if (old <= 0) {
171 __futex_syscall4(coldFutexAddr, FUTEX_WAIT_PRIVATE, old - 1, NULL);
172 }
Glenn Kasten288ed212012-04-25 17:52:27 -0700173 // This may be overly conservative; there could be times that the normal mixer
174 // requests such a brief cold idle that it doesn't require resetting this flag.
175 isWarm = false;
176 measuredWarmupTs.tv_sec = 0;
177 measuredWarmupTs.tv_nsec = 0;
178 warmupCycles = 0;
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700179 sleepNs = -1;
180 coldGen = current->mColdGen;
Glenn Kasten42d45cf2012-05-02 10:34:47 -0700181 bounds = 0;
182 full = false;
Glenn Kasten04a4ca42012-06-01 10:49:51 -0700183 oldTsValid = !clock_gettime(CLOCK_MONOTONIC, &oldTs);
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700184 } else {
185 sleepNs = FAST_HOT_IDLE_NS;
186 }
187 continue;
188 case FastMixerState::EXIT:
189 delete mixer;
190 delete[] mixBuffer;
191 return false;
192 case FastMixerState::MIX:
193 case FastMixerState::WRITE:
194 case FastMixerState::MIX_WRITE:
195 break;
196 default:
197 LOG_FATAL("bad command %d", command);
198 }
199
200 // there is a non-idle state available to us; did the state change?
201 size_t frameCount = current->mFrameCount;
202 if (current != previous) {
203
204 // handle state change here, but since we want to diff the state,
205 // we're prepared for previous == &initial the first time through
206 unsigned previousTrackMask;
207
208 // check for change in output HAL configuration
209 NBAIO_Format previousFormat = format;
210 if (current->mOutputSinkGen != outputSinkGen) {
211 outputSink = current->mOutputSink;
212 outputSinkGen = current->mOutputSinkGen;
213 if (outputSink == NULL) {
214 format = Format_Invalid;
215 sampleRate = 0;
216 } else {
217 format = outputSink->format();
218 sampleRate = Format_sampleRate(format);
219 ALOG_ASSERT(Format_channelCount(format) == 2);
220 }
Glenn Kasten21e8c502012-04-12 09:39:42 -0700221 dumpState->mSampleRate = sampleRate;
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700222 }
223
224 if ((format != previousFormat) || (frameCount != previous->mFrameCount)) {
225 // FIXME to avoid priority inversion, don't delete here
226 delete mixer;
227 mixer = NULL;
228 delete[] mixBuffer;
229 mixBuffer = NULL;
230 if (frameCount > 0 && sampleRate > 0) {
231 // FIXME new may block for unbounded time at internal mutex of the heap
232 // implementation; it would be better to have normal mixer allocate for us
233 // to avoid blocking here and to prevent possible priority inversion
234 mixer = new AudioMixer(frameCount, sampleRate, FastMixerState::kMaxFastTracks);
235 mixBuffer = new short[frameCount * 2];
236 periodNs = (frameCount * 1000000000LL) / sampleRate; // 1.00
237 underrunNs = (frameCount * 1750000000LL) / sampleRate; // 1.75
Glenn Kasten0d27c652012-08-07 10:38:59 -0700238 overrunNs = (frameCount * 500000000LL) / sampleRate; // 0.50
239 forceNs = (frameCount * 950000000LL) / sampleRate; // 0.95
Glenn Kasten288ed212012-04-25 17:52:27 -0700240 warmupNs = (frameCount * 500000000LL) / sampleRate; // 0.50
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700241 } else {
242 periodNs = 0;
243 underrunNs = 0;
244 overrunNs = 0;
Glenn Kasten972af222012-06-13 17:14:03 -0700245 forceNs = 0;
246 warmupNs = 0;
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700247 }
248 mixBufferState = UNDEFINED;
249#if !LOG_NDEBUG
250 for (i = 0; i < FastMixerState::kMaxFastTracks; ++i) {
251 fastTrackNames[i] = -1;
252 }
253#endif
254 // we need to reconfigure all active tracks
255 previousTrackMask = 0;
256 fastTracksGen = current->mFastTracksGen - 1;
Glenn Kasten21e8c502012-04-12 09:39:42 -0700257 dumpState->mFrameCount = frameCount;
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700258 } else {
259 previousTrackMask = previous->mTrackMask;
260 }
261
262 // check for change in active track set
263 unsigned currentTrackMask = current->mTrackMask;
Glenn Kasten1295bb4d2012-05-31 07:43:43 -0700264 dumpState->mTrackMask = currentTrackMask;
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700265 if (current->mFastTracksGen != fastTracksGen) {
266 ALOG_ASSERT(mixBuffer != NULL);
267 int name;
268
269 // process removed tracks first to avoid running out of track names
270 unsigned removedTracks = previousTrackMask & ~currentTrackMask;
271 while (removedTracks != 0) {
272 i = __builtin_ctz(removedTracks);
273 removedTracks &= ~(1 << i);
274 const FastTrack* fastTrack = &current->mFastTracks[i];
Glenn Kasten288ed212012-04-25 17:52:27 -0700275 ALOG_ASSERT(fastTrack->mBufferProvider == NULL);
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700276 if (mixer != NULL) {
277 name = fastTrackNames[i];
278 ALOG_ASSERT(name >= 0);
279 mixer->deleteTrackName(name);
280 }
281#if !LOG_NDEBUG
282 fastTrackNames[i] = -1;
283#endif
Glenn Kasten288ed212012-04-25 17:52:27 -0700284 // don't reset track dump state, since other side is ignoring it
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700285 generations[i] = fastTrack->mGeneration;
286 }
287
288 // now process added tracks
289 unsigned addedTracks = currentTrackMask & ~previousTrackMask;
290 while (addedTracks != 0) {
291 i = __builtin_ctz(addedTracks);
292 addedTracks &= ~(1 << i);
293 const FastTrack* fastTrack = &current->mFastTracks[i];
294 AudioBufferProvider *bufferProvider = fastTrack->mBufferProvider;
295 ALOG_ASSERT(bufferProvider != NULL && fastTrackNames[i] == -1);
296 if (mixer != NULL) {
Jean-Michel Trivife3156e2012-09-10 18:58:27 -0700297 // calling getTrackName with default channel mask and a random invalid
298 // sessionId (no effects here)
299 name = mixer->getTrackName(AUDIO_CHANNEL_OUT_STEREO, -555);
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700300 ALOG_ASSERT(name >= 0);
301 fastTrackNames[i] = name;
302 mixer->setBufferProvider(name, bufferProvider);
303 mixer->setParameter(name, AudioMixer::TRACK, AudioMixer::MAIN_BUFFER,
304 (void *) mixBuffer);
305 // newly allocated track names default to full scale volume
Glenn Kasten21e8c502012-04-12 09:39:42 -0700306 if (fastTrack->mSampleRate != 0 && fastTrack->mSampleRate != sampleRate) {
307 mixer->setParameter(name, AudioMixer::RESAMPLE,
308 AudioMixer::SAMPLE_RATE, (void*) fastTrack->mSampleRate);
309 }
310 mixer->setParameter(name, AudioMixer::TRACK, AudioMixer::CHANNEL_MASK,
311 (void *) fastTrack->mChannelMask);
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700312 mixer->enable(name);
313 }
314 generations[i] = fastTrack->mGeneration;
315 }
316
Glenn Kastenab7d72f2013-02-27 09:05:28 -0800317 // finally process (potentially) modified tracks; these use the same slot
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700318 // but may have a different buffer provider or volume provider
319 unsigned modifiedTracks = currentTrackMask & previousTrackMask;
320 while (modifiedTracks != 0) {
321 i = __builtin_ctz(modifiedTracks);
322 modifiedTracks &= ~(1 << i);
323 const FastTrack* fastTrack = &current->mFastTracks[i];
324 if (fastTrack->mGeneration != generations[i]) {
Glenn Kastenab7d72f2013-02-27 09:05:28 -0800325 // this track was actually modified
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700326 AudioBufferProvider *bufferProvider = fastTrack->mBufferProvider;
327 ALOG_ASSERT(bufferProvider != NULL);
328 if (mixer != NULL) {
329 name = fastTrackNames[i];
330 ALOG_ASSERT(name >= 0);
331 mixer->setBufferProvider(name, bufferProvider);
332 if (fastTrack->mVolumeProvider == NULL) {
333 mixer->setParameter(name, AudioMixer::VOLUME, AudioMixer::VOLUME0,
334 (void *)0x1000);
335 mixer->setParameter(name, AudioMixer::VOLUME, AudioMixer::VOLUME1,
336 (void *)0x1000);
337 }
Glenn Kasten21e8c502012-04-12 09:39:42 -0700338 if (fastTrack->mSampleRate != 0 &&
339 fastTrack->mSampleRate != sampleRate) {
340 mixer->setParameter(name, AudioMixer::RESAMPLE,
341 AudioMixer::SAMPLE_RATE, (void*) fastTrack->mSampleRate);
342 } else {
343 mixer->setParameter(name, AudioMixer::RESAMPLE,
344 AudioMixer::REMOVE, NULL);
345 }
346 mixer->setParameter(name, AudioMixer::TRACK, AudioMixer::CHANNEL_MASK,
347 (void *) fastTrack->mChannelMask);
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700348 // already enabled
349 }
350 generations[i] = fastTrack->mGeneration;
351 }
352 }
353
354 fastTracksGen = current->mFastTracksGen;
355
356 dumpState->mNumTracks = popcount(currentTrackMask);
357 }
358
359#if 1 // FIXME shouldn't need this
360 // only process state change once
361 previous = current;
362#endif
363 }
364
365 // do work using current state here
Glenn Kasten288ed212012-04-25 17:52:27 -0700366 if ((command & FastMixerState::MIX) && (mixer != NULL) && isWarm) {
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700367 ALOG_ASSERT(mixBuffer != NULL);
Glenn Kasten288ed212012-04-25 17:52:27 -0700368 // for each track, update volume and check for underrun
369 unsigned currentTrackMask = current->mTrackMask;
370 while (currentTrackMask != 0) {
371 i = __builtin_ctz(currentTrackMask);
372 currentTrackMask &= ~(1 << i);
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700373 const FastTrack* fastTrack = &current->mFastTracks[i];
374 int name = fastTrackNames[i];
375 ALOG_ASSERT(name >= 0);
376 if (fastTrack->mVolumeProvider != NULL) {
377 uint32_t vlr = fastTrack->mVolumeProvider->getVolumeLR();
378 mixer->setParameter(name, AudioMixer::VOLUME, AudioMixer::VOLUME0,
379 (void *)(vlr & 0xFFFF));
380 mixer->setParameter(name, AudioMixer::VOLUME, AudioMixer::VOLUME1,
381 (void *)(vlr >> 16));
382 }
Glenn Kasten288ed212012-04-25 17:52:27 -0700383 // FIXME The current implementation of framesReady() for fast tracks
384 // takes a tryLock, which can block
385 // up to 1 ms. If enough active tracks all blocked in sequence, this would result
386 // in the overall fast mix cycle being delayed. Should use a non-blocking FIFO.
387 size_t framesReady = fastTrack->mBufferProvider->framesReady();
Alex Rayb3a83642012-11-30 19:42:28 -0800388 if (ATRACE_ENABLED()) {
389 // I wish we had formatted trace names
390 char traceName[16];
Glenn Kastenc9b2e202013-02-26 11:32:32 -0800391 strcpy(traceName, "fRdy");
392 traceName[4] = i + (i < 10 ? '0' : 'A' - 10);
393 traceName[5] = '\0';
Alex Rayb3a83642012-11-30 19:42:28 -0800394 ATRACE_INT(traceName, framesReady);
395 }
Glenn Kasten288ed212012-04-25 17:52:27 -0700396 FastTrackDump *ftDump = &dumpState->mTracks[i];
Glenn Kasten09474df2012-05-10 14:48:07 -0700397 FastTrackUnderruns underruns = ftDump->mUnderruns;
Glenn Kasten288ed212012-04-25 17:52:27 -0700398 if (framesReady < frameCount) {
Glenn Kasten288ed212012-04-25 17:52:27 -0700399 if (framesReady == 0) {
Glenn Kasten09474df2012-05-10 14:48:07 -0700400 underruns.mBitFields.mEmpty++;
401 underruns.mBitFields.mMostRecent = UNDERRUN_EMPTY;
Glenn Kasten288ed212012-04-25 17:52:27 -0700402 mixer->disable(name);
403 } else {
404 // allow mixing partial buffer
Glenn Kasten09474df2012-05-10 14:48:07 -0700405 underruns.mBitFields.mPartial++;
406 underruns.mBitFields.mMostRecent = UNDERRUN_PARTIAL;
Glenn Kasten288ed212012-04-25 17:52:27 -0700407 mixer->enable(name);
408 }
Glenn Kasten09474df2012-05-10 14:48:07 -0700409 } else {
410 underruns.mBitFields.mFull++;
411 underruns.mBitFields.mMostRecent = UNDERRUN_FULL;
Glenn Kasten288ed212012-04-25 17:52:27 -0700412 mixer->enable(name);
413 }
Glenn Kasten09474df2012-05-10 14:48:07 -0700414 ftDump->mUnderruns = underruns;
Glenn Kasten1295bb4d2012-05-31 07:43:43 -0700415 ftDump->mFramesReady = framesReady;
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700416 }
John Grossman2c3b2da2012-08-02 17:08:54 -0700417
418 int64_t pts;
419 if (outputSink == NULL || (OK != outputSink->getNextWriteTimestamp(&pts)))
420 pts = AudioBufferProvider::kInvalidPTS;
421
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700422 // process() is CPU-bound
John Grossman2c3b2da2012-08-02 17:08:54 -0700423 mixer->process(pts);
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700424 mixBufferState = MIXED;
425 } else if (mixBufferState == MIXED) {
426 mixBufferState = UNDEFINED;
427 }
Glenn Kasten288ed212012-04-25 17:52:27 -0700428 bool attemptedWrite = false;
429 //bool didFullWrite = false; // dumpsys could display a count of partial writes
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700430 if ((command & FastMixerState::WRITE) && (outputSink != NULL) && (mixBuffer != NULL)) {
431 if (mixBufferState == UNDEFINED) {
432 memset(mixBuffer, 0, frameCount * 2 * sizeof(short));
433 mixBufferState = ZEROED;
434 }
Glenn Kastenfbae5da2012-05-21 09:17:20 -0700435 if (teeSink != NULL) {
436 (void) teeSink->write(mixBuffer, frameCount);
437 }
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700438 // FIXME write() is non-blocking and lock-free for a properly implemented NBAIO sink,
439 // but this code should be modified to handle both non-blocking and blocking sinks
440 dumpState->mWriteSequence++;
Simon Wilson2d590962012-11-29 15:18:50 -0800441 ATRACE_BEGIN("write");
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700442 ssize_t framesWritten = outputSink->write(mixBuffer, frameCount);
Simon Wilson2d590962012-11-29 15:18:50 -0800443 ATRACE_END();
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700444 dumpState->mWriteSequence++;
445 if (framesWritten >= 0) {
Glenn Kastenab7d72f2013-02-27 09:05:28 -0800446 ALOG_ASSERT((size_t) framesWritten <= frameCount);
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700447 dumpState->mFramesWritten += framesWritten;
Glenn Kasten288ed212012-04-25 17:52:27 -0700448 //if ((size_t) framesWritten == frameCount) {
449 // didFullWrite = true;
450 //}
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700451 } else {
452 dumpState->mWriteErrors++;
453 }
Glenn Kasten288ed212012-04-25 17:52:27 -0700454 attemptedWrite = true;
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700455 // FIXME count # of writes blocked excessively, CPU usage, etc. for dump
456 }
457
458 // To be exactly periodic, compute the next sleep time based on current time.
459 // This code doesn't have long-term stability when the sink is non-blocking.
460 // FIXME To avoid drift, use the local audio clock or watch the sink's fill status.
461 struct timespec newTs;
462 int rc = clock_gettime(CLOCK_MONOTONIC, &newTs);
463 if (rc == 0) {
Glenn Kastenab7d72f2013-02-27 09:05:28 -0800464 //logWriter->logTimestamp(newTs);
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700465 if (oldTsValid) {
466 time_t sec = newTs.tv_sec - oldTs.tv_sec;
467 long nsec = newTs.tv_nsec - oldTs.tv_nsec;
Glenn Kasten80b32732012-09-24 11:29:00 -0700468 ALOGE_IF(sec < 0 || (sec == 0 && nsec < 0),
469 "clock_gettime(CLOCK_MONOTONIC) failed: was %ld.%09ld but now %ld.%09ld",
470 oldTs.tv_sec, oldTs.tv_nsec, newTs.tv_sec, newTs.tv_nsec);
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700471 if (nsec < 0) {
472 --sec;
473 nsec += 1000000000;
474 }
Glenn Kasten288ed212012-04-25 17:52:27 -0700475 // To avoid an initial underrun on fast tracks after exiting standby,
476 // do not start pulling data from tracks and mixing until warmup is complete.
477 // Warmup is considered complete after the earlier of:
Glenn Kasteneb157162012-06-13 14:59:07 -0700478 // MIN_WARMUP_CYCLES write() attempts and last one blocks for at least warmupNs
Glenn Kasten288ed212012-04-25 17:52:27 -0700479 // MAX_WARMUP_CYCLES write() attempts.
480 // This is overly conservative, but to get better accuracy requires a new HAL API.
481 if (!isWarm && attemptedWrite) {
482 measuredWarmupTs.tv_sec += sec;
483 measuredWarmupTs.tv_nsec += nsec;
484 if (measuredWarmupTs.tv_nsec >= 1000000000) {
485 measuredWarmupTs.tv_sec++;
486 measuredWarmupTs.tv_nsec -= 1000000000;
487 }
488 ++warmupCycles;
Glenn Kasteneb157162012-06-13 14:59:07 -0700489 if ((nsec > warmupNs && warmupCycles >= MIN_WARMUP_CYCLES) ||
Glenn Kasten288ed212012-04-25 17:52:27 -0700490 (warmupCycles >= MAX_WARMUP_CYCLES)) {
491 isWarm = true;
492 dumpState->mMeasuredWarmupTs = measuredWarmupTs;
493 dumpState->mWarmupCycles = warmupCycles;
494 }
495 }
Glenn Kasten972af222012-06-13 17:14:03 -0700496 sleepNs = -1;
497 if (isWarm) {
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700498 if (sec > 0 || nsec > underrunNs) {
Alex Rayb3a83642012-11-30 19:42:28 -0800499 ATRACE_NAME("underrun");
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700500 // FIXME only log occasionally
501 ALOGV("underrun: time since last cycle %d.%03ld sec",
502 (int) sec, nsec / 1000000L);
503 dumpState->mUnderruns++;
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700504 ignoreNextOverrun = true;
505 } else if (nsec < overrunNs) {
506 if (ignoreNextOverrun) {
507 ignoreNextOverrun = false;
508 } else {
509 // FIXME only log occasionally
510 ALOGV("overrun: time since last cycle %d.%03ld sec",
511 (int) sec, nsec / 1000000L);
512 dumpState->mOverruns++;
513 }
Glenn Kasten972af222012-06-13 17:14:03 -0700514 // This forces a minimum cycle time. It:
515 // - compensates for an audio HAL with jitter due to sample rate conversion
516 // - works with a variable buffer depth audio HAL that never pulls at a rate
517 // < than overrunNs per buffer.
518 // - recovers from overrun immediately after underrun
519 // It doesn't work with a non-blocking audio HAL.
520 sleepNs = forceNs - nsec;
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700521 } else {
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700522 ignoreNextOverrun = false;
523 }
Glenn Kasten972af222012-06-13 17:14:03 -0700524 }
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700525#ifdef FAST_MIXER_STATISTICS
Glenn Kasteneb157162012-06-13 14:59:07 -0700526 if (isWarm) {
Glenn Kasten42d45cf2012-05-02 10:34:47 -0700527 // advance the FIFO queue bounds
528 size_t i = bounds & (FastMixerDumpState::kSamplingN - 1);
Glenn Kastene58ccce2012-05-11 15:19:24 -0700529 bounds = (bounds & 0xFFFF0000) | ((bounds + 1) & 0xFFFF);
Glenn Kasten42d45cf2012-05-02 10:34:47 -0700530 if (full) {
531 bounds += 0x10000;
532 } else if (!(bounds & (FastMixerDumpState::kSamplingN - 1))) {
533 full = true;
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700534 }
Glenn Kasten42d45cf2012-05-02 10:34:47 -0700535 // compute the delta value of clock_gettime(CLOCK_MONOTONIC)
536 uint32_t monotonicNs = nsec;
537 if (sec > 0 && sec < 4) {
538 monotonicNs += sec * 1000000000;
539 }
540 // compute the raw CPU load = delta value of clock_gettime(CLOCK_THREAD_CPUTIME_ID)
541 uint32_t loadNs = 0;
542 struct timespec newLoad;
543 rc = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &newLoad);
544 if (rc == 0) {
545 if (oldLoadValid) {
546 sec = newLoad.tv_sec - oldLoad.tv_sec;
547 nsec = newLoad.tv_nsec - oldLoad.tv_nsec;
548 if (nsec < 0) {
549 --sec;
550 nsec += 1000000000;
551 }
552 loadNs = nsec;
553 if (sec > 0 && sec < 4) {
554 loadNs += sec * 1000000000;
555 }
556 } else {
557 // first time through the loop
558 oldLoadValid = true;
559 }
560 oldLoad = newLoad;
561 }
Glenn Kasten0a14c4c2012-06-13 14:58:49 -0700562#ifdef CPU_FREQUENCY_STATISTICS
Glenn Kasten42d45cf2012-05-02 10:34:47 -0700563 // get the absolute value of CPU clock frequency in kHz
564 int cpuNum = sched_getcpu();
565 uint32_t kHz = tcu.getCpukHz(cpuNum);
Glenn Kastenc059bd42012-05-14 17:41:09 -0700566 kHz = (kHz << 4) | (cpuNum & 0xF);
Glenn Kasten0a14c4c2012-06-13 14:58:49 -0700567#endif
Glenn Kasten42d45cf2012-05-02 10:34:47 -0700568 // save values in FIFO queues for dumpsys
569 // these stores #1, #2, #3 are not atomic with respect to each other,
570 // or with respect to store #4 below
571 dumpState->mMonotonicNs[i] = monotonicNs;
572 dumpState->mLoadNs[i] = loadNs;
Glenn Kasten0a14c4c2012-06-13 14:58:49 -0700573#ifdef CPU_FREQUENCY_STATISTICS
Glenn Kasten42d45cf2012-05-02 10:34:47 -0700574 dumpState->mCpukHz[i] = kHz;
Glenn Kasten0a14c4c2012-06-13 14:58:49 -0700575#endif
Glenn Kasten42d45cf2012-05-02 10:34:47 -0700576 // this store #4 is not atomic with respect to stores #1, #2, #3 above, but
577 // the newest open and oldest closed halves are atomic with respect to each other
578 dumpState->mBounds = bounds;
Glenn Kasten99c99d02012-05-14 16:37:13 -0700579 ATRACE_INT("cycle_ms", monotonicNs / 1000000);
580 ATRACE_INT("load_us", loadNs / 1000);
Glenn Kasteneb157162012-06-13 14:59:07 -0700581 }
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700582#endif
583 } else {
584 // first time through the loop
585 oldTsValid = true;
586 sleepNs = periodNs;
587 ignoreNextOverrun = true;
588 }
589 oldTs = newTs;
590 } else {
591 // monotonic clock is broken
592 oldTsValid = false;
593 sleepNs = periodNs;
594 }
595
Glenn Kasten42d45cf2012-05-02 10:34:47 -0700596
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700597 } // for (;;)
598
599 // never return 'true'; Thread::_threadLoop() locks mutex which can result in priority inversion
600}
601
602FastMixerDumpState::FastMixerDumpState() :
603 mCommand(FastMixerState::INITIAL), mWriteSequence(0), mFramesWritten(0),
Glenn Kasten21e8c502012-04-12 09:39:42 -0700604 mNumTracks(0), mWriteErrors(0), mUnderruns(0), mOverruns(0),
Glenn Kasten1295bb4d2012-05-31 07:43:43 -0700605 mSampleRate(0), mFrameCount(0), /* mMeasuredWarmupTs({0, 0}), */ mWarmupCycles(0),
606 mTrackMask(0)
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700607#ifdef FAST_MIXER_STATISTICS
Glenn Kasten42d45cf2012-05-02 10:34:47 -0700608 , mBounds(0)
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700609#endif
610{
Glenn Kasten288ed212012-04-25 17:52:27 -0700611 mMeasuredWarmupTs.tv_sec = 0;
612 mMeasuredWarmupTs.tv_nsec = 0;
Glenn Kasten42d45cf2012-05-02 10:34:47 -0700613 // sample arrays aren't accessed atomically with respect to the bounds,
614 // so clearing reduces chance for dumpsys to read random uninitialized samples
615 memset(&mMonotonicNs, 0, sizeof(mMonotonicNs));
616 memset(&mLoadNs, 0, sizeof(mLoadNs));
Glenn Kasten0a14c4c2012-06-13 14:58:49 -0700617#ifdef CPU_FREQUENCY_STATISTICS
Glenn Kasten42d45cf2012-05-02 10:34:47 -0700618 memset(&mCpukHz, 0, sizeof(mCpukHz));
Glenn Kasten0a14c4c2012-06-13 14:58:49 -0700619#endif
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700620}
621
622FastMixerDumpState::~FastMixerDumpState()
623{
624}
625
Glenn Kasten1ab212cf2012-09-07 12:58:38 -0700626// helper function called by qsort()
627static int compare_uint32_t(const void *pa, const void *pb)
628{
629 uint32_t a = *(const uint32_t *)pa;
630 uint32_t b = *(const uint32_t *)pb;
631 if (a < b) {
632 return -1;
633 } else if (a > b) {
634 return 1;
635 } else {
636 return 0;
637 }
638}
639
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700640void FastMixerDumpState::dump(int fd)
641{
Glenn Kasten868c0ab2012-06-13 14:59:17 -0700642 if (mCommand == FastMixerState::INITIAL) {
643 fdprintf(fd, "FastMixer not initialized\n");
644 return;
645 }
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700646#define COMMAND_MAX 32
647 char string[COMMAND_MAX];
648 switch (mCommand) {
649 case FastMixerState::INITIAL:
650 strcpy(string, "INITIAL");
651 break;
652 case FastMixerState::HOT_IDLE:
653 strcpy(string, "HOT_IDLE");
654 break;
655 case FastMixerState::COLD_IDLE:
656 strcpy(string, "COLD_IDLE");
657 break;
658 case FastMixerState::EXIT:
659 strcpy(string, "EXIT");
660 break;
661 case FastMixerState::MIX:
662 strcpy(string, "MIX");
663 break;
664 case FastMixerState::WRITE:
665 strcpy(string, "WRITE");
666 break;
667 case FastMixerState::MIX_WRITE:
668 strcpy(string, "MIX_WRITE");
669 break;
670 default:
671 snprintf(string, COMMAND_MAX, "%d", mCommand);
672 break;
673 }
Glenn Kasten42d45cf2012-05-02 10:34:47 -0700674 double measuredWarmupMs = (mMeasuredWarmupTs.tv_sec * 1000.0) +
Glenn Kasten288ed212012-04-25 17:52:27 -0700675 (mMeasuredWarmupTs.tv_nsec / 1000000.0);
Glenn Kasten42d45cf2012-05-02 10:34:47 -0700676 double mixPeriodSec = (double) mFrameCount / (double) mSampleRate;
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700677 fdprintf(fd, "FastMixer command=%s writeSequence=%u framesWritten=%u\n"
Glenn Kasten21e8c502012-04-12 09:39:42 -0700678 " numTracks=%u writeErrors=%u underruns=%u overruns=%u\n"
Glenn Kasten42d45cf2012-05-02 10:34:47 -0700679 " sampleRate=%u frameCount=%u measuredWarmup=%.3g ms, warmupCycles=%u\n"
680 " mixPeriod=%.2f ms\n",
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700681 string, mWriteSequence, mFramesWritten,
Glenn Kasten21e8c502012-04-12 09:39:42 -0700682 mNumTracks, mWriteErrors, mUnderruns, mOverruns,
Glenn Kasten42d45cf2012-05-02 10:34:47 -0700683 mSampleRate, mFrameCount, measuredWarmupMs, mWarmupCycles,
684 mixPeriodSec * 1e3);
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700685#ifdef FAST_MIXER_STATISTICS
Glenn Kasten42d45cf2012-05-02 10:34:47 -0700686 // find the interval of valid samples
687 uint32_t bounds = mBounds;
688 uint32_t newestOpen = bounds & 0xFFFF;
689 uint32_t oldestClosed = bounds >> 16;
690 uint32_t n = (newestOpen - oldestClosed) & 0xFFFF;
691 if (n > kSamplingN) {
692 ALOGE("too many samples %u", n);
693 n = kSamplingN;
694 }
695 // statistics for monotonic (wall clock) time, thread raw CPU load in time, CPU clock frequency,
696 // and adjusted CPU load in MHz normalized for CPU clock frequency
Glenn Kasten0a14c4c2012-06-13 14:58:49 -0700697 CentralTendencyStatistics wall, loadNs;
698#ifdef CPU_FREQUENCY_STATISTICS
699 CentralTendencyStatistics kHz, loadMHz;
Glenn Kasten42d45cf2012-05-02 10:34:47 -0700700 uint32_t previousCpukHz = 0;
Glenn Kasten0a14c4c2012-06-13 14:58:49 -0700701#endif
Glenn Kasten1ab212cf2012-09-07 12:58:38 -0700702 // Assuming a normal distribution for cycle times, three standard deviations on either side of
703 // the mean account for 99.73% of the population. So if we take each tail to be 1/1000 of the
704 // sample set, we get 99.8% combined, or close to three standard deviations.
705 static const uint32_t kTailDenominator = 1000;
706 uint32_t *tail = n >= kTailDenominator ? new uint32_t[n] : NULL;
Glenn Kasten42d45cf2012-05-02 10:34:47 -0700707 // loop over all the samples
Glenn Kasten1ab212cf2012-09-07 12:58:38 -0700708 for (uint32_t j = 0; j < n; ++j) {
Glenn Kasten42d45cf2012-05-02 10:34:47 -0700709 size_t i = oldestClosed++ & (kSamplingN - 1);
710 uint32_t wallNs = mMonotonicNs[i];
Glenn Kasten1ab212cf2012-09-07 12:58:38 -0700711 if (tail != NULL) {
712 tail[j] = wallNs;
713 }
Glenn Kasten42d45cf2012-05-02 10:34:47 -0700714 wall.sample(wallNs);
715 uint32_t sampleLoadNs = mLoadNs[i];
Glenn Kasten42d45cf2012-05-02 10:34:47 -0700716 loadNs.sample(sampleLoadNs);
Glenn Kasten0a14c4c2012-06-13 14:58:49 -0700717#ifdef CPU_FREQUENCY_STATISTICS
718 uint32_t sampleCpukHz = mCpukHz[i];
Glenn Kastenc059bd42012-05-14 17:41:09 -0700719 // skip bad kHz samples
720 if ((sampleCpukHz & ~0xF) != 0) {
721 kHz.sample(sampleCpukHz >> 4);
722 if (sampleCpukHz == previousCpukHz) {
723 double megacycles = (double) sampleLoadNs * (double) (sampleCpukHz >> 4) * 1e-12;
724 double adjMHz = megacycles / mixPeriodSec; // _not_ wallNs * 1e9
725 loadMHz.sample(adjMHz);
726 }
Glenn Kasten42d45cf2012-05-02 10:34:47 -0700727 }
728 previousCpukHz = sampleCpukHz;
Glenn Kasten0a14c4c2012-06-13 14:58:49 -0700729#endif
Glenn Kasten42d45cf2012-05-02 10:34:47 -0700730 }
731 fdprintf(fd, "Simple moving statistics over last %.1f seconds:\n", wall.n() * mixPeriodSec);
732 fdprintf(fd, " wall clock time in ms per mix cycle:\n"
733 " mean=%.2f min=%.2f max=%.2f stddev=%.2f\n",
734 wall.mean()*1e-6, wall.minimum()*1e-6, wall.maximum()*1e-6, wall.stddev()*1e-6);
735 fdprintf(fd, " raw CPU load in us per mix cycle:\n"
736 " mean=%.0f min=%.0f max=%.0f stddev=%.0f\n",
737 loadNs.mean()*1e-3, loadNs.minimum()*1e-3, loadNs.maximum()*1e-3,
738 loadNs.stddev()*1e-3);
Glenn Kasten0a14c4c2012-06-13 14:58:49 -0700739#ifdef CPU_FREQUENCY_STATISTICS
Glenn Kasten42d45cf2012-05-02 10:34:47 -0700740 fdprintf(fd, " CPU clock frequency in MHz:\n"
741 " mean=%.0f min=%.0f max=%.0f stddev=%.0f\n",
742 kHz.mean()*1e-3, kHz.minimum()*1e-3, kHz.maximum()*1e-3, kHz.stddev()*1e-3);
743 fdprintf(fd, " adjusted CPU load in MHz (i.e. normalized for CPU clock frequency):\n"
744 " mean=%.1f min=%.1f max=%.1f stddev=%.1f\n",
745 loadMHz.mean(), loadMHz.minimum(), loadMHz.maximum(), loadMHz.stddev());
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700746#endif
Glenn Kasten1ab212cf2012-09-07 12:58:38 -0700747 if (tail != NULL) {
748 qsort(tail, n, sizeof(uint32_t), compare_uint32_t);
749 // assume same number of tail samples on each side, left and right
750 uint32_t count = n / kTailDenominator;
751 CentralTendencyStatistics left, right;
752 for (uint32_t i = 0; i < count; ++i) {
753 left.sample(tail[i]);
754 right.sample(tail[n - (i + 1)]);
755 }
756 fdprintf(fd, "Distribution of mix cycle times in ms for the tails (> ~3 stddev outliers):\n"
757 " left tail: mean=%.2f min=%.2f max=%.2f stddev=%.2f\n"
758 " right tail: mean=%.2f min=%.2f max=%.2f stddev=%.2f\n",
759 left.mean()*1e-6, left.minimum()*1e-6, left.maximum()*1e-6, left.stddev()*1e-6,
760 right.mean()*1e-6, right.minimum()*1e-6, right.maximum()*1e-6,
761 right.stddev()*1e-6);
762 delete[] tail;
763 }
Glenn Kasten0a14c4c2012-06-13 14:58:49 -0700764#endif
Glenn Kasten1295bb4d2012-05-31 07:43:43 -0700765 // The active track mask and track states are updated non-atomically.
766 // So if we relied on isActive to decide whether to display,
767 // then we might display an obsolete track or omit an active track.
768 // Instead we always display all tracks, with an indication
769 // of whether we think the track is active.
770 uint32_t trackMask = mTrackMask;
771 fdprintf(fd, "Fast tracks: kMaxFastTracks=%u activeMask=%#x\n",
772 FastMixerState::kMaxFastTracks, trackMask);
773 fdprintf(fd, "Index Active Full Partial Empty Recent Ready\n");
774 for (uint32_t i = 0; i < FastMixerState::kMaxFastTracks; ++i, trackMask >>= 1) {
775 bool isActive = trackMask & 1;
776 const FastTrackDump *ftDump = &mTracks[i];
777 const FastTrackUnderruns& underruns = ftDump->mUnderruns;
778 const char *mostRecent;
779 switch (underruns.mBitFields.mMostRecent) {
780 case UNDERRUN_FULL:
781 mostRecent = "full";
782 break;
783 case UNDERRUN_PARTIAL:
784 mostRecent = "partial";
785 break;
786 case UNDERRUN_EMPTY:
787 mostRecent = "empty";
788 break;
789 default:
790 mostRecent = "?";
791 break;
792 }
793 fdprintf(fd, "%5u %6s %4u %7u %5u %7s %5u\n", i, isActive ? "yes" : "no",
794 (underruns.mBitFields.mFull) & UNDERRUN_MASK,
795 (underruns.mBitFields.mPartial) & UNDERRUN_MASK,
796 (underruns.mBitFields.mEmpty) & UNDERRUN_MASK,
797 mostRecent, ftDump->mFramesReady);
798 }
Glenn Kasten97b5d0d2012-03-23 18:54:19 -0700799}
800
801} // namespace android