blob: 7be004abe1ef5bf49b5de615b79df23d165d70dd [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
Glenn Kasten09474df2012-05-10 14:48:07 -070020#include <utils/Debug.h>
Glenn Kasten22340022014-04-07 12:04:41 -070021#if 1 // FIXME move to where used
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070022extern "C" {
23#include "../private/bionic_futex.h"
24}
Glenn Kasten22340022014-04-07 12:04:41 -070025#endif
Glenn Kastenf7160b52014-03-18 17:01:15 -070026#include "FastThread.h"
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070027#include "StateQueue.h"
28#include "FastMixerState.h"
Glenn Kasten22340022014-04-07 12:04:41 -070029#include "FastMixerDumpState.h"
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070030
31namespace android {
32
Glenn Kasten22340022014-04-07 12:04:41 -070033class AudioMixer;
34
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070035typedef StateQueue<FastMixerState> FastMixerStateQueue;
36
Glenn Kastenf7160b52014-03-18 17:01:15 -070037class FastMixer : public FastThread {
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070038
39public:
Glenn Kasten22340022014-04-07 12:04:41 -070040 FastMixer();
41 virtual ~FastMixer();
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070042
Glenn Kasten22340022014-04-07 12:04:41 -070043 FastMixerStateQueue* sq();
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070044
45private:
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070046 FastMixerStateQueue mSQ;
47
Glenn Kasten22340022014-04-07 12:04:41 -070048 // callouts
49 virtual const FastThreadState *poll();
50 virtual void setLog(NBLog::Writer *logWriter);
51 virtual void onIdle();
52 virtual void onExit();
53 virtual bool isSubClassCommand(FastThreadState::Command command);
54 virtual void onStateChange();
55 virtual void onWork();
56
57 // FIXME these former local variables need comments and to be renamed to have "m" prefix
58 static const FastMixerState initial;
59 FastMixerState preIdle; // copy of state before we went into idle
60 long slopNs; // accumulated time we've woken up too early (> 0) or too late (< 0)
61 int fastTrackNames[FastMixerState::kMaxFastTracks]; // handles used by mixer to identify tracks
62 int generations[FastMixerState::kMaxFastTracks]; // last observed mFastTracks[i].mGeneration
63 NBAIO_Sink *outputSink;
64 int outputSinkGen;
65 AudioMixer* mixer;
Andy Hung45d68d32014-05-23 21:13:31 -070066 short *mMixerBuffer;
67 enum {UNDEFINED, MIXED, ZEROED} mMixerBufferState;
Glenn Kasten22340022014-04-07 12:04:41 -070068 NBAIO_Format format;
69 unsigned sampleRate;
70 int fastTracksGen;
71 FastMixerDumpState dummyDumpState;
72 uint32_t totalNativeFramesWritten; // copied to dumpState->mFramesWritten
73
74 // next 2 fields are valid only when timestampStatus == NO_ERROR
75 AudioTimestamp timestamp;
76 uint32_t nativeFramesWrittenButNotPresented;
77
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070078}; // class FastMixer
79
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070080} // namespace android
81
82#endif // ANDROID_AUDIO_FAST_MIXER_H