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 20 #include <system/audio.h> 21 #include <media/ExtendedAudioBufferProvider.h> 22 #include <media/nbaio/NBAIO.h> 23 #include <media/nbaio/NBLog.h> 24 25 namespace android { 26 27 struct FastMixerDumpState; 28 29 class VolumeProvider { 30 public: 31 // Return the track volume in U4_12 format: left in lower half, right in upper half. The 32 // provider implementation is responsible for validating that the return value is in range. 33 virtual uint32_t getVolumeLR() = 0; 34 protected: 35 VolumeProvider() { } 36 virtual ~VolumeProvider() { } 37 }; 38 39 // Represents the state of a fast track 40 struct FastTrack { 41 FastTrack(); 42 /*virtual*/ ~FastTrack(); 43 44 ExtendedAudioBufferProvider* mBufferProvider; // must be NULL if inactive, or non-NULL if active 45 VolumeProvider* mVolumeProvider; // optional; if NULL then full-scale 46 unsigned mSampleRate; // optional; if zero then use mixer sample rate 47 audio_channel_mask_t mChannelMask; // AUDIO_CHANNEL_OUT_MONO or AUDIO_CHANNEL_OUT_STEREO 48 int mGeneration; // increment when any field is assigned 49 }; 50 51 // Represents a single state of the fast mixer 52 struct FastMixerState { 53 FastMixerState(); 54 /*virtual*/ ~FastMixerState(); 55 56 static const unsigned kMaxFastTracks = 8; // must be between 2 and 32 inclusive 57 58 // all pointer fields use raw pointers; objects are owned and ref-counted by the normal mixer 59 FastTrack mFastTracks[kMaxFastTracks]; 60 int mFastTracksGen; // increment when any mFastTracks[i].mGeneration is incremented 61 unsigned mTrackMask; // bit i is set if and only if mFastTracks[i] is active 62 NBAIO_Sink* mOutputSink; // HAL output device, must already be negotiated 63 int mOutputSinkGen; // increment when mOutputSink is assigned 64 size_t mFrameCount; // number of frames per fast mix buffer 65 enum Command { 66 INITIAL = 0, // used only for the initial state 67 HOT_IDLE = 1, // do nothing 68 COLD_IDLE = 2, // wait for the futex 69 IDLE = 3, // either HOT_IDLE or COLD_IDLE 70 EXIT = 4, // exit from thread 71 // The following commands also process configuration changes, and can be "or"ed: 72 MIX = 0x8, // mix tracks 73 WRITE = 0x10, // write to output sink 74 MIX_WRITE = 0x18, // mix tracks and write to output sink 75 } mCommand; 76 int32_t* mColdFutexAddr; // for COLD_IDLE only, pointer to the associated futex 77 unsigned mColdGen; // increment when COLD_IDLE is requested so it's only performed once 78 // This might be a one-time configuration rather than per-state 79 FastMixerDumpState* mDumpState; // if non-NULL, then update dump state periodically 80 NBAIO_Sink* mTeeSink; // if non-NULL, then duplicate write()s to this non-blocking sink 81 NBLog::Writer* mNBLogWriter; // non-blocking logger 82 }; // struct FastMixerState 83 84 } // namespace android 85 86 #endif // ANDROID_AUDIO_FAST_MIXER_STATE_H 87