blob: 7649db292d04b6ba829b05b41cfc862c9474e14d [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 Kastenf7160b52014-03-18 17:01:15 -070020#include "FastThread.h"
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070021#include "StateQueue.h"
22#include "FastMixerState.h"
Glenn Kasten22340022014-04-07 12:04:41 -070023#include "FastMixerDumpState.h"
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070024
25namespace android {
26
Glenn Kasten22340022014-04-07 12:04:41 -070027class AudioMixer;
28
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070029typedef StateQueue<FastMixerState> FastMixerStateQueue;
30
Glenn Kastenf7160b52014-03-18 17:01:15 -070031class FastMixer : public FastThread {
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070032
33public:
Glenn Kasten22340022014-04-07 12:04:41 -070034 FastMixer();
35 virtual ~FastMixer();
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070036
Glenn Kasten22340022014-04-07 12:04:41 -070037 FastMixerStateQueue* sq();
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070038
39private:
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070040 FastMixerStateQueue mSQ;
41
Glenn Kasten22340022014-04-07 12:04:41 -070042 // callouts
43 virtual const FastThreadState *poll();
44 virtual void setLog(NBLog::Writer *logWriter);
45 virtual void onIdle();
46 virtual void onExit();
47 virtual bool isSubClassCommand(FastThreadState::Command command);
48 virtual void onStateChange();
49 virtual void onWork();
50
51 // FIXME these former local variables need comments and to be renamed to have "m" prefix
52 static const FastMixerState initial;
53 FastMixerState preIdle; // copy of state before we went into idle
54 long slopNs; // accumulated time we've woken up too early (> 0) or too late (< 0)
55 int fastTrackNames[FastMixerState::kMaxFastTracks]; // handles used by mixer to identify tracks
56 int generations[FastMixerState::kMaxFastTracks]; // last observed mFastTracks[i].mGeneration
57 NBAIO_Sink *outputSink;
58 int outputSinkGen;
59 AudioMixer* mixer;
Andy Hung1258c1a2014-05-23 21:22:17 -070060
61 // mSinkBuffer audio format is stored in format.mFormat.
62 void* mSinkBuffer; // used for mixer output format translation
63 // if sink format is different than mixer output.
64 size_t mSinkBufferSize;
Andy Hung9a592762014-07-21 21:56:01 -070065 uint32_t mSinkChannelCount;
66 audio_channel_mask_t mSinkChannelMask;
Andy Hung1258c1a2014-05-23 21:22:17 -070067 void* mMixerBuffer; // mixer output buffer.
68 size_t mMixerBufferSize;
69 audio_format_t mMixerBufferFormat; // mixer output format: AUDIO_FORMAT_PCM_(16_BIT|FLOAT).
70
Andy Hung45d68d32014-05-23 21:13:31 -070071 enum {UNDEFINED, MIXED, ZEROED} mMixerBufferState;
Glenn Kasten22340022014-04-07 12:04:41 -070072 NBAIO_Format format;
73 unsigned sampleRate;
74 int fastTracksGen;
75 FastMixerDumpState dummyDumpState;
76 uint32_t totalNativeFramesWritten; // copied to dumpState->mFramesWritten
77
78 // next 2 fields are valid only when timestampStatus == NO_ERROR
79 AudioTimestamp timestamp;
80 uint32_t nativeFramesWrittenButNotPresented;
81
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070082}; // class FastMixer
83
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070084} // namespace android
85
86#endif // ANDROID_AUDIO_FAST_MIXER_H