Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2010 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 #include "Configuration.h"
     18 #ifdef ANDROID
     19 #include "android/CallbackProtector.h"
     20 #include "android/android_Effect.h"
     21 #include "android/android_GenericPlayer.h"
     22 #endif
     23 
     24 // Class structures
     25 
     26 
     27 /*typedef*/ struct CAudioPlayer_struct {
     28     IObject mObject;
     29 #ifdef ANDROID
     30 #define INTERFACES_AudioPlayer 30 // see MPH_to_AudioPlayer in MPH_to.c for list of interfaces
     31 #else
     32 #define INTERFACES_AudioPlayer 26 // see MPH_to_AudioPlayer in MPH_to.c for list of interfaces
     33 #endif
     34     SLuint8 mInterfaceStates2[INTERFACES_AudioPlayer - INTERFACES_Default];
     35     IDynamicInterfaceManagement mDynamicInterfaceManagement;
     36     IPlay mPlay;
     37     I3DDoppler m3DDoppler;
     38     I3DGrouping m3DGrouping;
     39     I3DLocation m3DLocation;
     40     I3DSource m3DSource;
     41     IBufferQueue mBufferQueue;
     42     IEffectSend mEffectSend;
     43     IMetadataExtraction mMetadataExtraction;
     44     IMetadataTraversal mMetadataTraversal;
     45     IPrefetchStatus mPrefetchStatus;
     46     IRatePitch mRatePitch;
     47     ISeek mSeek;
     48     IVolume mVolume;
     49     IMuteSolo mMuteSolo;
     50 #ifdef ANDROID
     51     IAndroidEffect mAndroidEffect;
     52     IAndroidEffectSend mAndroidEffectSend;
     53     IAndroidConfiguration mAndroidConfiguration;
     54     IAndroidBufferQueue mAndroidBufferQueue;
     55 #endif
     56     // optional interfaces
     57     I3DMacroscopic m3DMacroscopic;
     58     IBassBoost mBassBoost;
     59     IDynamicSource mDynamicSource;
     60     IEnvironmentalReverb mEnvironmentalReverb;
     61     IEqualizer mEqualizer;
     62     IPitch mPitch;
     63     IPresetReverb mPresetReverb;
     64     IPlaybackRate mPlaybackRate;
     65     IVirtualizer mVirtualizer;
     66     IVisualization mVisualization;
     67     // fields below are per-instance private fields not associated with an interface
     68     DataLocatorFormat mDataSource;
     69     DataLocatorFormat mDataSink;
     70     // cached data for this instance
     71     // Formerly at IMuteSolo
     72     SLuint8 mMuteMask;      // Mask for which channels are muted: bit 0=left, 1=right
     73     SLuint8 mSoloMask;      // Mask for which channels are soloed: bit 0=left, 1=right
     74     SLuint8 mNumChannels;   // initially UNKNOWN_NUMCHANNELS, then const once it is known,
     75                             // range 1 <= x <= FCC_8
     76     // End of former IMuteSolo fields
     77     SLuint32 mSampleRateMilliHz;// initially UNKNOWN_SAMPLERATE, then const once it is known
     78     // Formerly at IEffectSend
     79     /**
     80      * Dry volume modified by effect send interfaces: SLEffectSendItf and SLAndroidEffectSendItf
     81      */
     82     SLmillibel mDirectLevel;
     83     // implementation-specific data for this instance
     84 #ifdef USE_OUTPUTMIXEXT
     85     Track *mTrack;
     86     float mGains[STEREO_CHANNELS];  ///< Computed gain based on volume, mute, solo, stereo position
     87     SLboolean mDestroyRequested;    ///< Mixer to acknowledge application's call to Object::Destroy
     88 #endif
     89 #ifdef USE_SNDFILE
     90     struct SndFile mSndFile;
     91 #endif // USE_SNDFILE
     92 #ifdef ANDROID
     93     enum AndroidObjectType mAndroidObjType;
     94     /** identifies the initialization and preparation state */
     95     enum AndroidObjectState mAndroidObjState;
     96     /** identifies which group of effects ("session") this player belongs to */
     97     audio_session_t mSessionId;
     98     /** identifies the Android stream type playback will occur on */
     99     audio_stream_type_t mStreamType;
    100     // FIXME consolidate the next several variables into one class to avoid placement new
    101     /** plays the PCM data for this player */
    102     android::sp<android::AudioTrack> mAudioTrack;
    103     android::sp<android::CallbackProtector> mCallbackProtector;
    104     android::sp<android::GenericPlayer> mAPlayer;
    105     /** aux effect the AudioTrack will be attached to if aux send enabled */
    106     android::sp<android::AudioEffect> mAuxEffect;
    107     // FIXME all levels below need to be encapsulated in a field of type AndroidAudioLevels
    108     /** send level to aux effect, there's a single aux bus, so there's a single level */
    109     SLmillibel mAuxSendLevel;
    110     /**
    111      * Attenuation factor derived from direct level
    112      */
    113     float mAmplFromDirectLevel;
    114     /** FIXME whether to call AudioTrack::start() at the next safe opportunity */
    115     bool mDeferredStart;
    116 #endif
    117 } /*CAudioPlayer*/;
    118 
    119 
    120 /*typedef*/ struct CAudioRecorder_struct {
    121     // mandated interfaces
    122     IObject mObject;
    123 #ifdef ANDROID
    124 #define INTERFACES_AudioRecorder 14 // see MPH_to_AudioRecorder in MPH_to.c for list of interfaces
    125 #else
    126 #define INTERFACES_AudioRecorder 9  // see MPH_to_AudioRecorder in MPH_to.c for list of interfaces
    127 #endif
    128     SLuint8 mInterfaceStates2[INTERFACES_AudioRecorder - INTERFACES_Default];
    129     IDynamicInterfaceManagement mDynamicInterfaceManagement;
    130     IRecord mRecord;
    131     IAudioEncoder mAudioEncoder;
    132     // optional interfaces
    133     IBassBoost mBassBoost;
    134     IDynamicSource mDynamicSource;
    135     IEqualizer mEqualizer;
    136     IVisualization mVisualization;
    137     IVolume mVolume;
    138 #ifdef ANDROID
    139     IBufferQueue mBufferQueue;
    140     IAndroidConfiguration mAndroidConfiguration;
    141     IAndroidAcousticEchoCancellation  mAcousticEchoCancellation;
    142     IAndroidAutomaticGainControl mAutomaticGainControl;
    143     IAndroidNoiseSuppression mNoiseSuppression;
    144 #endif
    145     // remaining are per-instance private fields not associated with an interface
    146     DataLocatorFormat mDataSource;
    147     DataLocatorFormat mDataSink;
    148     // cached data for this instance
    149     SLuint8 mNumChannels;   // initially UNKNOWN_NUMCHANNELS, then const once it is known,
    150                             // range 1 <= x <= FCC_8
    151     SLuint32 mSampleRateMilliHz;// initially UNKNOWN_SAMPLERATE, then const once it is known
    152     // implementation-specific data for this instance
    153 #ifdef ANDROID
    154     // FIXME consolidate the next several variables into ARecorder class to avoid placement new
    155     enum AndroidObjectType mAndroidObjType;
    156     android::sp<android::AudioRecord> mAudioRecord;
    157     android::sp<android::CallbackProtector> mCallbackProtector;
    158     audio_source_t mRecordSource;
    159 #endif
    160 } /*CAudioRecorder*/;
    161 
    162 
    163 /*typedef*/ struct CEngine_struct {
    164     // mandated implicit interfaces
    165     IObject mObject;
    166 #ifdef ANDROID
    167 #define INTERFACES_Engine 13 // see MPH_to_Engine in MPH_to.c for list of interfaces
    168 #else
    169 #define INTERFACES_Engine 12 // see MPH_to_Engine in MPH_to.c for list of interfaces
    170 #endif
    171     SLuint8 mInterfaceStates2[INTERFACES_Engine - INTERFACES_Default];
    172     IDynamicInterfaceManagement mDynamicInterfaceManagement;
    173     IEngine mEngine;
    174     IEngineCapabilities mEngineCapabilities;
    175     IThreadSync mThreadSync;
    176     // mandated explicit interfaces
    177     IAudioIODeviceCapabilities mAudioIODeviceCapabilities;
    178     IAudioDecoderCapabilities mAudioDecoderCapabilities;
    179     IAudioEncoderCapabilities mAudioEncoderCapabilities;
    180     I3DCommit m3DCommit;
    181     // optional interfaces
    182     IDeviceVolume mDeviceVolume;
    183     // OpenMAX AL mandated implicit interfaces
    184     IXAEngine mXAEngine;
    185 #ifdef ANDROID
    186     IAndroidEffectCapabilities mAndroidEffectCapabilities;
    187 #endif
    188     // OpenMAX AL explicit interfaces
    189     IVideoDecoderCapabilities mVideoDecoderCapabilities;
    190     // remaining are per-instance private fields not associated with an interface
    191     ThreadPool mThreadPool; // for asynchronous operations
    192     pthread_t mSyncThread;
    193 #if defined(ANDROID)
    194     // FIXME number of presets will only be saved in IEqualizer, preset names will not be stored
    195     SLuint32 mEqNumPresets;
    196     char** mEqPresetNames;
    197 #endif
    198 } /*CEngine*/;
    199 
    200 typedef struct {
    201     // mandated interfaces
    202     IObject mObject;
    203 #define INTERFACES_LEDDevice 3 // see MPH_to_LEDDevice in MPH_to.c for list of interfaces
    204     SLuint8 mInterfaceStates2[INTERFACES_LEDDevice - INTERFACES_Default];
    205     IDynamicInterfaceManagement mDynamicInterfaceManagement;
    206     ILEDArray mLEDArray;
    207     // remaining are per-instance private fields not associated with an interface
    208     SLuint32 mDeviceID;
    209 } CLEDDevice;
    210 
    211 typedef struct {
    212     // mandated interfaces
    213     IObject mObject;
    214 #define INTERFACES_Listener 4 // see MPH_to_Listener in MPH_to.c for list of interfaces
    215     SLuint8 mInterfaceStates2[INTERFACES_Listener - INTERFACES_Default];
    216     IDynamicInterfaceManagement mDynamicInterfaceManagement;
    217     I3DDoppler m3DDoppler;
    218     I3DLocation m3DLocation;
    219     // remaining are per-instance private fields not associated with an interface
    220 } CListener;
    221 
    222 typedef struct {
    223     // mandated interfaces
    224     IObject mObject;
    225 #define INTERFACES_MetadataExtractor 5 // see MPH_to_MetadataExtractor in MPH_to.c for list of
    226                                        // interfaces
    227     SLuint8 mInterfaceStates2[INTERFACES_MetadataExtractor - INTERFACES_Default];
    228     IDynamicInterfaceManagement mDynamicInterfaceManagement;
    229     IDynamicSource mDynamicSource;
    230     IMetadataExtraction mMetadataExtraction;
    231     IMetadataTraversal mMetadataTraversal;
    232     // remaining are per-instance private fields not associated with an interface
    233 } CMetadataExtractor;
    234 
    235 typedef struct {
    236     // mandated interfaces
    237     IObject mObject;
    238 
    239 #define INTERFACES_MidiPlayer 29 // see MPH_to_MidiPlayer in MPH_to.c for list of interfaces
    240     SLuint8 mInterfaceStates2[INTERFACES_MidiPlayer - INTERFACES_Default];
    241     IDynamicInterfaceManagement mDynamicInterfaceManagement;
    242     IPlay mPlay;
    243     I3DDoppler m3DDoppler;
    244     I3DGrouping m3DGrouping;
    245     I3DLocation m3DLocation;
    246     I3DSource m3DSource;
    247     IBufferQueue mBufferQueue;
    248     IEffectSend mEffectSend;
    249     IMetadataExtraction mMetadataExtraction;
    250     IMetadataTraversal mMetadataTraversal;
    251     IMIDIMessage mMIDIMessage;
    252     IMIDITime mMIDITime;
    253     IMIDITempo mMIDITempo;
    254     IMIDIMuteSolo mMIDIMuteSolo;
    255     IPrefetchStatus mPrefetchStatus;
    256     ISeek mSeek;
    257     IVolume mVolume;
    258     IMuteSolo mMuteSolo;
    259     // optional interfaces
    260     I3DMacroscopic m3DMacroscopic;
    261     IBassBoost mBassBoost;
    262     IDynamicSource mDynamicSource;
    263     IEnvironmentalReverb mEnvironmentalReverb;
    264     IEqualizer mEqualizer;
    265     IPitch mPitch;
    266     IPresetReverb mPresetReverb;
    267     IPlaybackRate mPlaybackRate;
    268     IVirtualizer mVirtualizer;
    269     IVisualization mVisualization;
    270     // remaining are per-instance private fields not associated with an interface
    271 } CMidiPlayer;
    272 
    273 /*typedef*/ struct COutputMix_struct {
    274     // mandated interfaces
    275     IObject mObject;
    276 #ifdef ANDROID
    277 #define INTERFACES_OutputMix 12 // see MPH_to_OutputMix in MPH_to.c for list of interfaces
    278 #else
    279 #define INTERFACES_OutputMix 11 // see MPH_to_OutputMix in MPH_to.c for list of interfaces
    280 #endif
    281     SLuint8 mInterfaceStates2[INTERFACES_OutputMix - INTERFACES_Default];
    282     IDynamicInterfaceManagement mDynamicInterfaceManagement;
    283     IOutputMix mOutputMix;
    284 #ifdef USE_OUTPUTMIXEXT
    285     IOutputMixExt mOutputMixExt;
    286 #endif
    287     IEnvironmentalReverb mEnvironmentalReverb;
    288     IEqualizer mEqualizer;
    289     IPresetReverb mPresetReverb;
    290     IVirtualizer mVirtualizer;
    291     IVolume mVolume;
    292     // optional interfaces
    293     IBassBoost mBassBoost;
    294     IVisualization mVisualization;
    295 #ifdef ANDROID
    296     IAndroidEffect mAndroidEffect;
    297 #endif
    298     // remaining are per-instance private fields not associated with an interface
    299 } /*COutputMix*/;
    300 
    301 typedef struct {
    302     // mandated interfaces
    303     IObject mObject;
    304 #define INTERFACES_VibraDevice 3 // see MPH_to_VibraDevice in MPH_to.c for list of interfaces
    305     SLuint8 mInterfaceStates2[INTERFACES_VibraDevice - INTERFACES_Default];
    306     IDynamicInterfaceManagement mDynamicInterfaceManagement;
    307     IVibra mVibra;
    308     // remaining are per-instance private fields not associated with an interface
    309     SLuint32 mDeviceID;
    310 } CVibraDevice;
    311 
    312 
    313 typedef struct CMediaPlayer_struct {
    314     IObject mObject;
    315 #ifdef ANDROID
    316 #define INTERFACES_MediaPlayer 8
    317 #else
    318 #define INTERFACES_MediaPlayer 7
    319 #endif
    320     XAuint8 mInterfaceStates2[INTERFACES_MediaPlayer - INTERFACES_Default];
    321     IDynamicInterfaceManagement mDynamicInterfaceManagement;
    322     IDynamicSource mDynamicSource;
    323     IPlay mPlay;
    324     IStreamInformation mStreamInfo;
    325     IVolume mVolume;
    326     ISeek mSeek;
    327     IPrefetchStatus mPrefetchStatus;
    328 #ifdef ANDROID
    329     IAndroidBufferQueue mAndroidBufferQueue;
    330 #endif
    331     // fields below are per-instance private fields not associated with an interface
    332     DataLocatorFormat mDataSource;
    333     DataLocatorFormat mBankSource;
    334     DataLocatorFormat mAudioSink;
    335     DataLocatorFormat mImageVideoSink;
    336     DataLocatorFormat mVibraSink;
    337     DataLocatorFormat mLEDArraySink;
    338     SLuint8 mNumChannels;   // initially UNKNOWN_NUMCHANNELS, then const once it is known,
    339                             // range 1 <= x <= 8 FIXME FCC_8
    340 #ifdef ANDROID
    341     android::sp<android::GenericPlayer> mAVPlayer;
    342     android::sp<android::CallbackProtector> mCallbackProtector;
    343     enum AndroidObjectType mAndroidObjType;
    344     /** identifies the initialization and preparation state */
    345     enum AndroidObjectState mAndroidObjState;
    346     /** identifies which group of effects ("session") this player belongs to */
    347     audio_session_t mSessionId;
    348     /** identifies the Android stream type playback will occur on */
    349     audio_stream_type_t mStreamType;
    350 #endif
    351 } CMediaPlayer;
    352