197b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten/* 297b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten * Copyright (C) 2012 The Android Open Source Project 397b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten * 497b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten * Licensed under the Apache License, Version 2.0 (the "License"); 597b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten * you may not use this file except in compliance with the License. 697b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten * You may obtain a copy of the License at 797b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten * 897b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten * http://www.apache.org/licenses/LICENSE-2.0 997b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten * 1097b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten * Unless required by applicable law or agreed to in writing, software 1197b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten * distributed under the License is distributed on an "AS IS" BASIS, 1297b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1397b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten * See the License for the specific language governing permissions and 1497b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten * limitations under the License. 1597b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten */ 1697b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten 1797b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten#ifndef ANDROID_AUDIO_FAST_MIXER_STATE_H 1897b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten#define ANDROID_AUDIO_FAST_MIXER_STATE_H 1997b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten 20c56f3426099a3cf2d07ccff8886050c7fbce140fGlenn Kasten#include <audio_utils/minifloat.h> 2121e8c50bd13ebe44f3088e26c9c6df0e163c469cGlenn Kasten#include <system/audio.h> 22fc7992bd8220824f1404c0c54ac516d9e28b58c2Glenn Kasten#include <media/ExtendedAudioBufferProvider.h> 23fc7992bd8220824f1404c0c54ac516d9e28b58c2Glenn Kasten#include <media/nbaio/NBAIO.h> 248589ce7045fd4f5520aabbc773f00c7136925fd7Glenn Kasten#include <media/nblog/NBLog.h> 25f7160b5dc3091fd9624f25d534c6848ee831b706Glenn Kasten#include "FastThreadState.h" 2697b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten 2797b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kastennamespace android { 2897b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten 2997b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kastenstruct FastMixerDumpState; 3097b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten 3197b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kastenclass VolumeProvider { 3297b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kastenpublic: 33c56f3426099a3cf2d07ccff8886050c7fbce140fGlenn Kasten // The provider implementation is responsible for validating that the return value is in range. 34c56f3426099a3cf2d07ccff8886050c7fbce140fGlenn Kasten virtual gain_minifloat_packed_t getVolumeLR() = 0; 3597b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kastenprotected: 3697b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten VolumeProvider() { } 3797b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten virtual ~VolumeProvider() { } 3897b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten}; 3997b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten 4097b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten// Represents the state of a fast track 4197b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kastenstruct FastTrack { 4297b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten FastTrack(); 4397b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten /*virtual*/ ~FastTrack(); 4497b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten 45288ed2103d96f3aabd7e6bea3c080ab6db164049Glenn Kasten ExtendedAudioBufferProvider* mBufferProvider; // must be NULL if inactive, or non-NULL if active 4697b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten VolumeProvider* mVolumeProvider; // optional; if NULL then full-scale 4721e8c50bd13ebe44f3088e26c9c6df0e163c469cGlenn Kasten audio_channel_mask_t mChannelMask; // AUDIO_CHANNEL_OUT_MONO or AUDIO_CHANNEL_OUT_STEREO 48e8a1ced4da17dc6c07803dc2af8060f62a8389c1Andy Hung audio_format_t mFormat; // track format 4997b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten int mGeneration; // increment when any field is assigned 5097b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten}; 5197b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten 5297b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten// Represents a single state of the fast mixer 53f7160b5dc3091fd9624f25d534c6848ee831b706Glenn Kastenstruct FastMixerState : FastThreadState { 5497b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten FastMixerState(); 5597b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten /*virtual*/ ~FastMixerState(); 5697b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten 57dc2c50bad491d2c0c8a2efc0e24491076701c63cGlenn Kasten // These are the minimum, maximum, and default values for maximum number of fast tracks 58dc2c50bad491d2c0c8a2efc0e24491076701c63cGlenn Kasten static const unsigned kMinFastTracks = 2; 59dc2c50bad491d2c0c8a2efc0e24491076701c63cGlenn Kasten static const unsigned kMaxFastTracks = 32; 60dc2c50bad491d2c0c8a2efc0e24491076701c63cGlenn Kasten static const unsigned kDefaultFastTracks = 8; 61dc2c50bad491d2c0c8a2efc0e24491076701c63cGlenn Kasten 62dc2c50bad491d2c0c8a2efc0e24491076701c63cGlenn Kasten static unsigned sMaxFastTracks; // Configured maximum number of fast tracks 63dc2c50bad491d2c0c8a2efc0e24491076701c63cGlenn Kasten static pthread_once_t sMaxFastTracksOnce; // Protects initializer for sMaxFastTracks 6497b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten 6597b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten // all pointer fields use raw pointers; objects are owned and ref-counted by the normal mixer 6697b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten FastTrack mFastTracks[kMaxFastTracks]; 6797b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten int mFastTracksGen; // increment when any mFastTracks[i].mGeneration is incremented 68288ed2103d96f3aabd7e6bea3c080ab6db164049Glenn Kasten unsigned mTrackMask; // bit i is set if and only if mFastTracks[i] is active 6997b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten NBAIO_Sink* mOutputSink; // HAL output device, must already be negotiated 7097b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten int mOutputSinkGen; // increment when mOutputSink is assigned 7197b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten size_t mFrameCount; // number of frames per fast mix buffer 72f7160b5dc3091fd9624f25d534c6848ee831b706Glenn Kasten 73f7160b5dc3091fd9624f25d534c6848ee831b706Glenn Kasten // Extends FastThreadState::Command 74f7160b5dc3091fd9624f25d534c6848ee831b706Glenn Kasten static const Command 7597b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten // The following commands also process configuration changes, and can be "or"ed: 7697b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten MIX = 0x8, // mix tracks 7797b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten WRITE = 0x10, // write to output sink 78f7160b5dc3091fd9624f25d534c6848ee831b706Glenn Kasten MIX_WRITE = 0x18; // mix tracks and write to output sink 79f7160b5dc3091fd9624f25d534c6848ee831b706Glenn Kasten 8097b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten // This might be a one-time configuration rather than per-state 81fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten NBAIO_Sink* mTeeSink; // if non-NULL, then duplicate write()s to this non-blocking sink 82d702a568cb62e5aebe048147350bb3c76f9386baGlenn Kasten 83d702a568cb62e5aebe048147350bb3c76f9386baGlenn Kasten // never returns NULL; asserts if command is invalid 84d702a568cb62e5aebe048147350bb3c76f9386baGlenn Kasten static const char *commandToString(Command command); 85dc2c50bad491d2c0c8a2efc0e24491076701c63cGlenn Kasten 86dc2c50bad491d2c0c8a2efc0e24491076701c63cGlenn Kasten // initialize sMaxFastTracks 87dc2c50bad491d2c0c8a2efc0e24491076701c63cGlenn Kasten static void sMaxFastTracksInit(); 88dc2c50bad491d2c0c8a2efc0e24491076701c63cGlenn Kasten 8997b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten}; // struct FastMixerState 9097b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten 9197b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten} // namespace android 9297b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten 9397b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten#endif // ANDROID_AUDIO_FAST_MIXER_STATE_H 94