blob: db89ef43397ecf3744e1275b06a6f38e4c5d3860 [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
17#ifndef ANDROID_AUDIO_FAST_MIXER_H
18#define ANDROID_AUDIO_FAST_MIXER_H
19
Elliott Hughesee499292014-05-21 17:55:51 -070020#include <linux/futex.h>
21#include <sys/syscall.h>
Glenn Kasten09474df2012-05-10 14:48:07 -070022#include <utils/Debug.h>
Glenn Kastenf7160b52014-03-18 17:01:15 -070023#include "FastThread.h"
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070024#include <utils/Thread.h>
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070025#include "StateQueue.h"
26#include "FastMixerState.h"
Glenn Kasten22340022014-04-07 12:04:41 -070027#include "FastMixerDumpState.h"
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070028
29namespace android {
30
Glenn Kasten22340022014-04-07 12:04:41 -070031class AudioMixer;
32
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070033typedef StateQueue<FastMixerState> FastMixerStateQueue;
34
Glenn Kastenf7160b52014-03-18 17:01:15 -070035class FastMixer : public FastThread {
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070036
37public:
Glenn Kasten22340022014-04-07 12:04:41 -070038 FastMixer();
39 virtual ~FastMixer();
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070040
Glenn Kasten22340022014-04-07 12:04:41 -070041 FastMixerStateQueue* sq();
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070042
43private:
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070044 FastMixerStateQueue mSQ;
45
Glenn Kasten22340022014-04-07 12:04:41 -070046 // callouts
47 virtual const FastThreadState *poll();
48 virtual void setLog(NBLog::Writer *logWriter);
49 virtual void onIdle();
50 virtual void onExit();
51 virtual bool isSubClassCommand(FastThreadState::Command command);
52 virtual void onStateChange();
53 virtual void onWork();
54
55 // FIXME these former local variables need comments and to be renamed to have "m" prefix
56 static const FastMixerState initial;
57 FastMixerState preIdle; // copy of state before we went into idle
58 long slopNs; // accumulated time we've woken up too early (> 0) or too late (< 0)
59 int fastTrackNames[FastMixerState::kMaxFastTracks]; // handles used by mixer to identify tracks
60 int generations[FastMixerState::kMaxFastTracks]; // last observed mFastTracks[i].mGeneration
61 NBAIO_Sink *outputSink;
62 int outputSinkGen;
63 AudioMixer* mixer;
64 short *mixBuffer;
65 enum {UNDEFINED, MIXED, ZEROED} mixBufferState;
66 NBAIO_Format format;
67 unsigned sampleRate;
68 int fastTracksGen;
69 FastMixerDumpState dummyDumpState;
70 uint32_t totalNativeFramesWritten; // copied to dumpState->mFramesWritten
71
72 // next 2 fields are valid only when timestampStatus == NO_ERROR
73 AudioTimestamp timestamp;
74 uint32_t nativeFramesWrittenButNotPresented;
75
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070076}; // class FastMixer
77
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070078} // namespace android
79
80#endif // ANDROID_AUDIO_FAST_MIXER_H