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
2021e8c50bd13ebe44f3088e26c9c6df0e163c469cGlenn Kasten#include <system/audio.h>
212dd4bdd715f586d4d30cf90cc6fc2bbfbce60fe0Glenn Kasten#include <media/ExtendedAudioBufferProvider.h>
222dd4bdd715f586d4d30cf90cc6fc2bbfbce60fe0Glenn Kasten#include <media/nbaio/NBAIO.h>
2397b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten
2497b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kastennamespace android {
2597b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten
2697b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kastenstruct FastMixerDumpState;
2797b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten
2897b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kastenclass VolumeProvider {
2997b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kastenpublic:
3097b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten    // Return the track volume in U4_12 format: left in lower half, right in upper half. The
3197b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten    // provider implementation is responsible for validating that the return value is in range.
3297b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten    virtual uint32_t getVolumeLR() = 0;
3397b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kastenprotected:
3497b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten    VolumeProvider() { }
3597b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten    virtual ~VolumeProvider() { }
3697b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten};
3797b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten
3897b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten// Represents the state of a fast track
3997b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kastenstruct FastTrack {
4097b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten    FastTrack();
4197b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten    /*virtual*/ ~FastTrack();
4297b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten
43288ed2103d96f3aabd7e6bea3c080ab6db164049Glenn Kasten    ExtendedAudioBufferProvider* mBufferProvider; // must be NULL if inactive, or non-NULL if active
4497b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten    VolumeProvider*         mVolumeProvider; // optional; if NULL then full-scale
4521e8c50bd13ebe44f3088e26c9c6df0e163c469cGlenn Kasten    unsigned                mSampleRate;     // optional; if zero then use mixer sample rate
4621e8c50bd13ebe44f3088e26c9c6df0e163c469cGlenn Kasten    audio_channel_mask_t    mChannelMask;    // AUDIO_CHANNEL_OUT_MONO or AUDIO_CHANNEL_OUT_STEREO
4797b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten    int                     mGeneration;     // increment when any field is assigned
4897b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten};
4997b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten
5097b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten// Represents a single state of the fast mixer
5197b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kastenstruct FastMixerState {
5297b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten                FastMixerState();
5397b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten    /*virtual*/ ~FastMixerState();
5497b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten
5597b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten    static const unsigned kMaxFastTracks = 8;   // must be between 2 and 32 inclusive
5697b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten
5797b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten    // all pointer fields use raw pointers; objects are owned and ref-counted by the normal mixer
5897b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten    FastTrack   mFastTracks[kMaxFastTracks];
5997b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten    int         mFastTracksGen; // increment when any mFastTracks[i].mGeneration is incremented
60288ed2103d96f3aabd7e6bea3c080ab6db164049Glenn Kasten    unsigned    mTrackMask;     // bit i is set if and only if mFastTracks[i] is active
6197b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten    NBAIO_Sink* mOutputSink;    // HAL output device, must already be negotiated
6297b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten    int         mOutputSinkGen; // increment when mOutputSink is assigned
6397b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten    size_t      mFrameCount;    // number of frames per fast mix buffer
6497b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten    enum Command {
6597b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten        INITIAL = 0,            // used only for the initial state
6697b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten        HOT_IDLE = 1,           // do nothing
6797b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten        COLD_IDLE = 2,          // wait for the futex
6897b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten        IDLE = 3,               // either HOT_IDLE or COLD_IDLE
6997b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten        EXIT = 4,               // exit from thread
7097b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten        // The following commands also process configuration changes, and can be "or"ed:
7197b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten        MIX = 0x8,              // mix tracks
7297b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten        WRITE = 0x10,           // write to output sink
7397b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten        MIX_WRITE = 0x18,       // mix tracks and write to output sink
7497b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten    } mCommand;
7597b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten    int32_t*    mColdFutexAddr; // for COLD_IDLE only, pointer to the associated futex
7697b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten    unsigned    mColdGen;       // increment when COLD_IDLE is requested so it's only performed once
7797b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten    // This might be a one-time configuration rather than per-state
7897b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten    FastMixerDumpState* mDumpState; // if non-NULL, then update dump state periodically
79fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten    NBAIO_Sink* mTeeSink;       // if non-NULL, then duplicate write()s to this non-blocking sink
8097b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten};  // struct FastMixerState
8197b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten
8297b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten}   // namespace android
8397b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten
8497b5d0d5b5ef766eb5dd680d05a5d199662d4ae0Glenn Kasten#endif  // ANDROID_AUDIO_FAST_MIXER_STATE_H
85