blob: fde8c2b8fdd2650bd87e44f363cf734e06d49a9e [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;
Andy Hung1258c1a2014-05-23 21:22:17 -070064
65 // mSinkBuffer audio format is stored in format.mFormat.
66 void* mSinkBuffer; // used for mixer output format translation
67 // if sink format is different than mixer output.
68 size_t mSinkBufferSize;
Andy Hung9a592762014-07-21 21:56:01 -070069 uint32_t mSinkChannelCount;
70 audio_channel_mask_t mSinkChannelMask;
Andy Hung1258c1a2014-05-23 21:22:17 -070071 void* mMixerBuffer; // mixer output buffer.
72 size_t mMixerBufferSize;
73 audio_format_t mMixerBufferFormat; // mixer output format: AUDIO_FORMAT_PCM_(16_BIT|FLOAT).
74
Andy Hung45d68d32014-05-23 21:13:31 -070075 enum {UNDEFINED, MIXED, ZEROED} mMixerBufferState;
Glenn Kasten22340022014-04-07 12:04:41 -070076 NBAIO_Format format;
77 unsigned sampleRate;
78 int fastTracksGen;
79 FastMixerDumpState dummyDumpState;
80 uint32_t totalNativeFramesWritten; // copied to dumpState->mFramesWritten
81
82 // next 2 fields are valid only when timestampStatus == NO_ERROR
83 AudioTimestamp timestamp;
84 uint32_t nativeFramesWrittenButNotPresented;
85
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070086}; // class FastMixer
87
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070088} // namespace android
89
90#endif // ANDROID_AUDIO_FAST_MIXER_H