blob: 9d2a733670be9048a79dd7e1e1fbcd23f1647db7 [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>
Glenn Kastenfc7992b2012-08-29 11:10:32 -070022#include <media/ExtendedAudioBufferProvider.h>
23#include <media/nbaio/NBAIO.h>
Glenn Kasten8589ce72017-09-08 17:03:42 -070024#include <media/nblog/NBLog.h>
Glenn Kastenf7160b52014-03-18 17:01:15 -070025#include "FastThreadState.h"
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070026
27namespace android {
28
29struct FastMixerDumpState;
30
31class VolumeProvider {
32public:
Glenn Kastenc56f3422014-03-21 17:53:17 -070033 // The provider implementation is responsible for validating that the return value is in range.
34 virtual gain_minifloat_packed_t getVolumeLR() = 0;
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070035protected:
36 VolumeProvider() { }
37 virtual ~VolumeProvider() { }
38};
39
40// Represents the state of a fast track
41struct FastTrack {
42 FastTrack();
43 /*virtual*/ ~FastTrack();
44
Glenn Kasten288ed212012-04-25 17:52:27 -070045 ExtendedAudioBufferProvider* mBufferProvider; // must be NULL if inactive, or non-NULL if active
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070046 VolumeProvider* mVolumeProvider; // optional; if NULL then full-scale
Glenn Kasten21e8c502012-04-12 09:39:42 -070047 audio_channel_mask_t mChannelMask; // AUDIO_CHANNEL_OUT_MONO or AUDIO_CHANNEL_OUT_STEREO
Andy Hunge8a1ced2014-05-09 15:02:21 -070048 audio_format_t mFormat; // track format
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070049 int mGeneration; // increment when any field is assigned
jiabin245cdd92018-12-07 17:55:15 -080050 bool mHapticPlaybackEnabled = false; // haptic playback is enabled or not
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070051};
52
53// Represents a single state of the fast mixer
Glenn Kastenf7160b52014-03-18 17:01:15 -070054struct FastMixerState : FastThreadState {
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070055 FastMixerState();
56 /*virtual*/ ~FastMixerState();
57
Glenn Kastendc2c50b2016-04-21 08:13:14 -070058 // These are the minimum, maximum, and default values for maximum number of fast tracks
59 static const unsigned kMinFastTracks = 2;
60 static const unsigned kMaxFastTracks = 32;
61 static const unsigned kDefaultFastTracks = 8;
62
63 static unsigned sMaxFastTracks; // Configured maximum number of fast tracks
64 static pthread_once_t sMaxFastTracksOnce; // Protects initializer for sMaxFastTracks
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070065
66 // all pointer fields use raw pointers; objects are owned and ref-counted by the normal mixer
67 FastTrack mFastTracks[kMaxFastTracks];
68 int mFastTracksGen; // increment when any mFastTracks[i].mGeneration is incremented
Glenn Kasten288ed212012-04-25 17:52:27 -070069 unsigned mTrackMask; // bit i is set if and only if mFastTracks[i] is active
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070070 NBAIO_Sink* mOutputSink; // HAL output device, must already be negotiated
71 int mOutputSinkGen; // increment when mOutputSink is assigned
72 size_t mFrameCount; // number of frames per fast mix buffer
jiabin245cdd92018-12-07 17:55:15 -080073 audio_channel_mask_t mSinkChannelMask; // If not AUDIO_CHANNEL_NONE, specifies sink channel
74 // mask when it cannot be directly calculated from
75 // channel count
Glenn Kastenf7160b52014-03-18 17:01:15 -070076
77 // Extends FastThreadState::Command
78 static const Command
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070079 // The following commands also process configuration changes, and can be "or"ed:
80 MIX = 0x8, // mix tracks
81 WRITE = 0x10, // write to output sink
Glenn Kastenf7160b52014-03-18 17:01:15 -070082 MIX_WRITE = 0x18; // mix tracks and write to output sink
83
Glenn Kastend702a562015-03-02 15:51:38 -080084 // never returns NULL; asserts if command is invalid
85 static const char *commandToString(Command command);
Glenn Kastendc2c50b2016-04-21 08:13:14 -070086
87 // initialize sMaxFastTracks
88 static void sMaxFastTracksInit();
89
Glenn Kasten97b5d0d2012-03-23 18:54:19 -070090}; // struct FastMixerState
91
92} // namespace android
93
94#endif // ANDROID_AUDIO_FAST_MIXER_STATE_H