blob: 06a68fb0f1eb63ed1f39f40be16d919b92528157 [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
Glenn Kastene4a7ce22015-03-03 11:23:17 -080051 // FIXME these former local variables need comments
52 static const FastMixerState sInitial;
53
54 FastMixerState mPreIdle; // copy of state before we went into idle
55 long mSlopNs; // accumulated time we've woken up too early (> 0) or too late (< 0)
56 int mFastTrackNames[FastMixerState::kMaxFastTracks];
57 // handles used by mixer to identify tracks
58 int mGenerations[FastMixerState::kMaxFastTracks];
59 // last observed mFastTracks[i].mGeneration
60 NBAIO_Sink* mOutputSink;
61 int mOutputSinkGen;
62 AudioMixer* mMixer;
Andy Hung1258c1a2014-05-23 21:22:17 -070063
64 // mSinkBuffer audio format is stored in format.mFormat.
Glenn Kastene4a7ce22015-03-03 11:23:17 -080065 void* mSinkBuffer; // used for mixer output format translation
Andy Hung1258c1a2014-05-23 21:22:17 -070066 // if sink format is different than mixer output.
Glenn Kastene4a7ce22015-03-03 11:23:17 -080067 size_t mSinkBufferSize;
68 uint32_t mSinkChannelCount;
Andy Hung9a592762014-07-21 21:56:01 -070069 audio_channel_mask_t mSinkChannelMask;
Glenn Kastene4a7ce22015-03-03 11:23:17 -080070 void* mMixerBuffer; // mixer output buffer.
71 size_t mMixerBufferSize;
72 audio_format_t mMixerBufferFormat; // mixer output format: AUDIO_FORMAT_PCM_(16_BIT|FLOAT).
Andy Hung1258c1a2014-05-23 21:22:17 -070073
Andy Hung45d68d32014-05-23 21:13:31 -070074 enum {UNDEFINED, MIXED, ZEROED} mMixerBufferState;
Glenn Kastene4a7ce22015-03-03 11:23:17 -080075 NBAIO_Format mFormat;
76 unsigned mSampleRate;
77 int mFastTracksGen;
78 FastMixerDumpState mDummyFastMixerDumpState;
79 uint32_t mTotalNativeFramesWritten; // copied to dumpState->mFramesWritten
Glenn Kasten22340022014-04-07 12:04:41 -070080
81 // next 2 fields are valid only when timestampStatus == NO_ERROR
Glenn Kastene4a7ce22015-03-03 11:23:17 -080082 AudioTimestamp mTimestamp;
83 uint32_t mNativeFramesWrittenButNotPresented;
Glenn Kasten22340022014-04-07 12:04:41 -070084
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070085}; // class FastMixer
86
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070087} // namespace android
88
89#endif // ANDROID_AUDIO_FAST_MIXER_H