Home | History | Annotate | Download | only in audioflinger
      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 <audio_utils/minifloat.h>
     21 #include <system/audio.h>
     22 #include <media/ExtendedAudioBufferProvider.h>
     23 #include <media/nbaio/NBAIO.h>
     24 #include <media/nbaio/NBLog.h>
     25 #include "FastThreadState.h"
     26 
     27 namespace android {
     28 
     29 struct FastMixerDumpState;
     30 
     31 class VolumeProvider {
     32 public:
     33     // The provider implementation is responsible for validating that the return value is in range.
     34     virtual gain_minifloat_packed_t getVolumeLR() = 0;
     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 
     45     ExtendedAudioBufferProvider* mBufferProvider; // must be NULL if inactive, or non-NULL if active
     46     VolumeProvider*         mVolumeProvider; // optional; if NULL then full-scale
     47     audio_channel_mask_t    mChannelMask;    // AUDIO_CHANNEL_OUT_MONO or AUDIO_CHANNEL_OUT_STEREO
     48     audio_format_t          mFormat;         // track format
     49     int                     mGeneration;     // increment when any field is assigned
     50 };
     51 
     52 // Represents a single state of the fast mixer
     53 struct FastMixerState : FastThreadState {
     54                 FastMixerState();
     55     /*virtual*/ ~FastMixerState();
     56 
     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
     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
     68     unsigned    mTrackMask;     // bit i is set if and only if mFastTracks[i] is active
     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
     72 
     73     // Extends FastThreadState::Command
     74     static const Command
     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
     78         MIX_WRITE = 0x18;       // mix tracks and write to output sink
     79 
     80     // This might be a one-time configuration rather than per-state
     81     NBAIO_Sink* mTeeSink;       // if non-NULL, then duplicate write()s to this non-blocking sink
     82 
     83     // never returns NULL; asserts if command is invalid
     84     static const char *commandToString(Command command);
     85 
     86     // initialize sMaxFastTracks
     87     static void sMaxFastTracksInit();
     88 
     89 };  // struct FastMixerState
     90 
     91 }   // namespace android
     92 
     93 #endif  // ANDROID_AUDIO_FAST_MIXER_STATE_H
     94