Glenn Kasten | 97b5d0d | 2012-03-23 18:54:19 -0700 | [diff] [blame] | 1 | /* |
| 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 Kasten | c56f342 | 2014-03-21 17:53:17 -0700 | [diff] [blame] | 20 | #include <audio_utils/minifloat.h> |
Glenn Kasten | 21e8c50 | 2012-04-12 09:39:42 -0700 | [diff] [blame] | 21 | #include <system/audio.h> |
Glenn Kasten | fc7992b | 2012-08-29 11:10:32 -0700 | [diff] [blame] | 22 | #include <media/ExtendedAudioBufferProvider.h> |
| 23 | #include <media/nbaio/NBAIO.h> |
Glenn Kasten | 011aa65 | 2013-01-18 15:09:48 -0800 | [diff] [blame] | 24 | #include <media/nbaio/NBLog.h> |
Glenn Kasten | f7160b5 | 2014-03-18 17:01:15 -0700 | [diff] [blame] | 25 | #include "FastThreadState.h" |
Glenn Kasten | 97b5d0d | 2012-03-23 18:54:19 -0700 | [diff] [blame] | 26 | |
| 27 | namespace android { |
| 28 | |
| 29 | struct FastMixerDumpState; |
| 30 | |
| 31 | class VolumeProvider { |
| 32 | public: |
Glenn Kasten | c56f342 | 2014-03-21 17:53:17 -0700 | [diff] [blame] | 33 | // The provider implementation is responsible for validating that the return value is in range. |
| 34 | virtual gain_minifloat_packed_t getVolumeLR() = 0; |
Glenn Kasten | 97b5d0d | 2012-03-23 18:54:19 -0700 | [diff] [blame] | 35 | protected: |
| 36 | VolumeProvider() { } |
| 37 | virtual ~VolumeProvider() { } |
| 38 | }; |
| 39 | |
| 40 | // Represents the state of a fast track |
| 41 | struct FastTrack { |
| 42 | FastTrack(); |
| 43 | /*virtual*/ ~FastTrack(); |
| 44 | |
Glenn Kasten | 288ed21 | 2012-04-25 17:52:27 -0700 | [diff] [blame] | 45 | ExtendedAudioBufferProvider* mBufferProvider; // must be NULL if inactive, or non-NULL if active |
Glenn Kasten | 97b5d0d | 2012-03-23 18:54:19 -0700 | [diff] [blame] | 46 | VolumeProvider* mVolumeProvider; // optional; if NULL then full-scale |
Glenn Kasten | 21e8c50 | 2012-04-12 09:39:42 -0700 | [diff] [blame] | 47 | audio_channel_mask_t mChannelMask; // AUDIO_CHANNEL_OUT_MONO or AUDIO_CHANNEL_OUT_STEREO |
Andy Hung | e8a1ced | 2014-05-09 15:02:21 -0700 | [diff] [blame] | 48 | audio_format_t mFormat; // track format |
Glenn Kasten | 97b5d0d | 2012-03-23 18:54:19 -0700 | [diff] [blame] | 49 | int mGeneration; // increment when any field is assigned |
| 50 | }; |
| 51 | |
| 52 | // Represents a single state of the fast mixer |
Glenn Kasten | f7160b5 | 2014-03-18 17:01:15 -0700 | [diff] [blame] | 53 | struct FastMixerState : FastThreadState { |
Glenn Kasten | 97b5d0d | 2012-03-23 18:54:19 -0700 | [diff] [blame] | 54 | FastMixerState(); |
| 55 | /*virtual*/ ~FastMixerState(); |
| 56 | |
Glenn Kasten | dc2c50b | 2016-04-21 08:13:14 -0700 | [diff] [blame^] | 57 | // These are the minimum, maximum, and default values for maximum number of fast tracks |
| 58 | static const unsigned kMinFastTracks = 2; |
| 59 | static const unsigned kMaxFastTracks = 32; |
| 60 | static const unsigned kDefaultFastTracks = 8; |
| 61 | |
| 62 | static unsigned sMaxFastTracks; // Configured maximum number of fast tracks |
| 63 | static pthread_once_t sMaxFastTracksOnce; // Protects initializer for sMaxFastTracks |
Glenn Kasten | 97b5d0d | 2012-03-23 18:54:19 -0700 | [diff] [blame] | 64 | |
| 65 | // all pointer fields use raw pointers; objects are owned and ref-counted by the normal mixer |
| 66 | FastTrack mFastTracks[kMaxFastTracks]; |
| 67 | int mFastTracksGen; // increment when any mFastTracks[i].mGeneration is incremented |
Glenn Kasten | 288ed21 | 2012-04-25 17:52:27 -0700 | [diff] [blame] | 68 | unsigned mTrackMask; // bit i is set if and only if mFastTracks[i] is active |
Glenn Kasten | 97b5d0d | 2012-03-23 18:54:19 -0700 | [diff] [blame] | 69 | NBAIO_Sink* mOutputSink; // HAL output device, must already be negotiated |
| 70 | int mOutputSinkGen; // increment when mOutputSink is assigned |
| 71 | size_t mFrameCount; // number of frames per fast mix buffer |
Glenn Kasten | f7160b5 | 2014-03-18 17:01:15 -0700 | [diff] [blame] | 72 | |
| 73 | // Extends FastThreadState::Command |
| 74 | static const Command |
Glenn Kasten | 97b5d0d | 2012-03-23 18:54:19 -0700 | [diff] [blame] | 75 | // The following commands also process configuration changes, and can be "or"ed: |
| 76 | MIX = 0x8, // mix tracks |
| 77 | WRITE = 0x10, // write to output sink |
Glenn Kasten | f7160b5 | 2014-03-18 17:01:15 -0700 | [diff] [blame] | 78 | MIX_WRITE = 0x18; // mix tracks and write to output sink |
| 79 | |
Glenn Kasten | 97b5d0d | 2012-03-23 18:54:19 -0700 | [diff] [blame] | 80 | // This might be a one-time configuration rather than per-state |
Glenn Kasten | fbae5da | 2012-05-21 09:17:20 -0700 | [diff] [blame] | 81 | NBAIO_Sink* mTeeSink; // if non-NULL, then duplicate write()s to this non-blocking sink |
Glenn Kasten | d702a56 | 2015-03-02 15:51:38 -0800 | [diff] [blame] | 82 | |
| 83 | // never returns NULL; asserts if command is invalid |
| 84 | static const char *commandToString(Command command); |
Glenn Kasten | dc2c50b | 2016-04-21 08:13:14 -0700 | [diff] [blame^] | 85 | |
| 86 | // initialize sMaxFastTracks |
| 87 | static void sMaxFastTracksInit(); |
| 88 | |
Glenn Kasten | 97b5d0d | 2012-03-23 18:54:19 -0700 | [diff] [blame] | 89 | }; // struct FastMixerState |
| 90 | |
| 91 | } // namespace android |
| 92 | |
| 93 | #endif // ANDROID_AUDIO_FAST_MIXER_STATE_H |