blob: 396c797284e255e26c37fe1f0acae44d03f5d0b9 [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_STATE_H
18#define ANDROID_AUDIO_FAST_MIXER_STATE_H
19
Glenn Kastenc56f3422014-03-21 17:53:17 -070020#include <audio_utils/minifloat.h>
Glenn Kasten21e8c502012-04-12 09:39:42 -070021#include <system/audio.h>
jiabin77270b82018-12-18 15:41:29 -080022#include <media/AudioMixer.h>
Glenn Kastenfc7992b2012-08-29 11:10:32 -070023#include <media/ExtendedAudioBufferProvider.h>
24#include <media/nbaio/NBAIO.h>
Glenn Kasten8589ce72017-09-08 17:03:42 -070025#include <media/nblog/NBLog.h>
Glenn Kastenf7160b52014-03-18 17:01:15 -070026#include "FastThreadState.h"
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070027
28namespace android {
29
30struct FastMixerDumpState;
31
32class VolumeProvider {
33public:
Glenn Kastenc56f3422014-03-21 17:53:17 -070034 // The provider implementation is responsible for validating that the return value is in range.
35 virtual gain_minifloat_packed_t getVolumeLR() = 0;
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070036protected:
37 VolumeProvider() { }
38 virtual ~VolumeProvider() { }
39};
40
41// Represents the state of a fast track
42struct FastTrack {
43 FastTrack();
44 /*virtual*/ ~FastTrack();
45
Glenn Kasten288ed212012-04-25 17:52:27 -070046 ExtendedAudioBufferProvider* mBufferProvider; // must be NULL if inactive, or non-NULL if active
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070047 VolumeProvider* mVolumeProvider; // optional; if NULL then full-scale
Glenn Kasten21e8c502012-04-12 09:39:42 -070048 audio_channel_mask_t mChannelMask; // AUDIO_CHANNEL_OUT_MONO or AUDIO_CHANNEL_OUT_STEREO
Andy Hunge8a1ced2014-05-09 15:02:21 -070049 audio_format_t mFormat; // track format
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070050 int mGeneration; // increment when any field is assigned
jiabin245cdd92018-12-07 17:55:15 -080051 bool mHapticPlaybackEnabled = false; // haptic playback is enabled or not
jiabinbf6b0ec2019-02-12 12:30:12 -080052 AudioMixer::haptic_intensity_t mHapticIntensity = AudioMixer::HAPTIC_SCALE_MUTE; // intensity of
jiabin77270b82018-12-18 15:41:29 -080053 // haptic data
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070054};
55
56// Represents a single state of the fast mixer
Glenn Kastenf7160b52014-03-18 17:01:15 -070057struct FastMixerState : FastThreadState {
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070058 FastMixerState();
59 /*virtual*/ ~FastMixerState();
60
Glenn Kastendc2c50b2016-04-21 08:13:14 -070061 // These are the minimum, maximum, and default values for maximum number of fast tracks
62 static const unsigned kMinFastTracks = 2;
63 static const unsigned kMaxFastTracks = 32;
64 static const unsigned kDefaultFastTracks = 8;
65
66 static unsigned sMaxFastTracks; // Configured maximum number of fast tracks
67 static pthread_once_t sMaxFastTracksOnce; // Protects initializer for sMaxFastTracks
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070068
69 // all pointer fields use raw pointers; objects are owned and ref-counted by the normal mixer
70 FastTrack mFastTracks[kMaxFastTracks];
71 int mFastTracksGen; // increment when any mFastTracks[i].mGeneration is incremented
Glenn Kasten288ed212012-04-25 17:52:27 -070072 unsigned mTrackMask; // bit i is set if and only if mFastTracks[i] is active
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070073 NBAIO_Sink* mOutputSink; // HAL output device, must already be negotiated
74 int mOutputSinkGen; // increment when mOutputSink is assigned
75 size_t mFrameCount; // number of frames per fast mix buffer
jiabin245cdd92018-12-07 17:55:15 -080076 audio_channel_mask_t mSinkChannelMask; // If not AUDIO_CHANNEL_NONE, specifies sink channel
77 // mask when it cannot be directly calculated from
78 // channel count
Glenn Kastenf7160b52014-03-18 17:01:15 -070079
80 // Extends FastThreadState::Command
81 static const Command
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070082 // The following commands also process configuration changes, and can be "or"ed:
83 MIX = 0x8, // mix tracks
84 WRITE = 0x10, // write to output sink
Glenn Kastenf7160b52014-03-18 17:01:15 -070085 MIX_WRITE = 0x18; // mix tracks and write to output sink
86
Glenn Kastend702a562015-03-02 15:51:38 -080087 // never returns NULL; asserts if command is invalid
88 static const char *commandToString(Command command);
Glenn Kastendc2c50b2016-04-21 08:13:14 -070089
90 // initialize sMaxFastTracks
91 static void sMaxFastTracksInit();
92
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070093}; // struct FastMixerState
94
95} // namespace android
96
97#endif // ANDROID_AUDIO_FAST_MIXER_STATE_H