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     SLuint32 mPerformanceMode;
    117 #endif
    118 } /*CAudioPlayer*/;
    119 
    120 
    121 /*typedef*/ struct CAudioRecorder_struct {
    122     // mandated interfaces
    123     IObject mObject;
    124 #ifdef ANDROID
    125 #define INTERFACES_AudioRecorder 14 // see MPH_to_AudioRecorder in MPH_to.c for list of interfaces
    126 #else
    127 #define INTERFACES_AudioRecorder 9  // see MPH_to_AudioRecorder in MPH_to.c for list of interfaces
    128 #endif
    129     SLuint8 mInterfaceStates2[INTERFACES_AudioRecorder - INTERFACES_Default];
    130     IDynamicInterfaceManagement mDynamicInterfaceManagement;
    131     IRecord mRecord;
    132     IAudioEncoder mAudioEncoder;
    133     // optional interfaces
    134     IBassBoost mBassBoost;
    135     IDynamicSource mDynamicSource;
    136     IEqualizer mEqualizer;
    137     IVisualization mVisualization;
    138     IVolume mVolume;
    139 #ifdef ANDROID
    140     IBufferQueue mBufferQueue;
    141     IAndroidConfiguration mAndroidConfiguration;
    142     IAndroidAcousticEchoCancellation  mAcousticEchoCancellation;
    143     IAndroidAutomaticGainControl mAutomaticGainControl;
    144     IAndroidNoiseSuppression mNoiseSuppression;
    145 #endif
    146     // remaining are per-instance private fields not associated with an interface
    147     DataLocatorFormat mDataSource;
    148     DataLocatorFormat mDataSink;
    149     // cached data for this instance
    150     SLuint8 mNumChannels;   // initially UNKNOWN_NUMCHANNELS, then const once it is known,
    151                             // range 1 <= x <= FCC_8
    152     SLuint32 mSampleRateMilliHz;// initially UNKNOWN_SAMPLERATE, then const once it is known
    153     // implementation-specific data for this instance
    154 #ifdef ANDROID
    155     // FIXME consolidate the next several variables into ARecorder class to avoid placement new
    156     enum AndroidObjectType mAndroidObjType;
    157     android::sp<android::AudioRecord> mAudioRecord;
    158     android::sp<android::CallbackProtector> mCallbackProtector;
    159     audio_source_t mRecordSource;
    160     SLuint32 mPerformanceMode;
    161 #endif
    162 } /*CAudioRecorder*/;
    163 
    164 
    165 /*typedef*/ struct CEngine_struct {
    166     // mandated implicit interfaces
    167     IObject mObject;
    168 #ifdef ANDROID
    169 #define INTERFACES_Engine 13 // see MPH_to_Engine in MPH_to.c for list of interfaces
    170 #else
    171 #define INTERFACES_Engine 12 // see MPH_to_Engine in MPH_to.c for list of interfaces
    172 #endif
    173     SLuint8 mInterfaceStates2[INTERFACES_Engine - INTERFACES_Default];
    174     IDynamicInterfaceManagement mDynamicInterfaceManagement;
    175     IEngine mEngine;
    176     IEngineCapabilities mEngineCapabilities;
    177     IThreadSync mThreadSync;
    178     // mandated explicit interfaces
    179     IAudioIODeviceCapabilities mAudioIODeviceCapabilities;
    180     IAudioDecoderCapabilities mAudioDecoderCapabilities;
    181     IAudioEncoderCapabilities mAudioEncoderCapabilities;
    182     I3DCommit m3DCommit;
    183     // optional interfaces
    184     IDeviceVolume mDeviceVolume;
    185     // OpenMAX AL mandated implicit interfaces
    186     IXAEngine mXAEngine;
    187 #ifdef ANDROID
    188     IAndroidEffectCapabilities mAndroidEffectCapabilities;
    189 #endif
    190     // OpenMAX AL explicit interfaces
    191     IVideoDecoderCapabilities mVideoDecoderCapabilities;
    192     // remaining are per-instance private fields not associated with an interface
    193     ThreadPool mThreadPool; // for asynchronous operations
    194     pthread_t mSyncThread;
    195 #if defined(ANDROID)
    196     // FIXME number of presets will only be saved in IEqualizer, preset names will not be stored
    197     SLuint32 mEqNumPresets;
    198     char** mEqPresetNames;
    199 #endif
    200 } /*CEngine*/;
    201 
    202 typedef struct {
    203     // mandated interfaces
    204     IObject mObject;
    205 #define INTERFACES_LEDDevice 3 // see MPH_to_LEDDevice in MPH_to.c for list of interfaces
    206     SLuint8 mInterfaceStates2[INTERFACES_LEDDevice - INTERFACES_Default];
    207     IDynamicInterfaceManagement mDynamicInterfaceManagement;
    208     ILEDArray mLEDArray;
    209     // remaining are per-instance private fields not associated with an interface
    210     SLuint32 mDeviceID;
    211 } CLEDDevice;
    212 
    213 typedef struct {
    214     // mandated interfaces
    215     IObject mObject;
    216 #define INTERFACES_Listener 4 // see MPH_to_Listener in MPH_to.c for list of interfaces
    217     SLuint8 mInterfaceStates2[INTERFACES_Listener - INTERFACES_Default];
    218     IDynamicInterfaceManagement mDynamicInterfaceManagement;
    219     I3DDoppler m3DDoppler;
    220     I3DLocation m3DLocation;
    221     // remaining are per-instance private fields not associated with an interface
    222 } CListener;
    223 
    224 typedef struct {
    225     // mandated interfaces
    226     IObject mObject;
    227 #define INTERFACES_MetadataExtractor 5 // see MPH_to_MetadataExtractor in MPH_to.c for list of
    228                                        // interfaces
    229     SLuint8 mInterfaceStates2[INTERFACES_MetadataExtractor - INTERFACES_Default];
    230     IDynamicInterfaceManagement mDynamicInterfaceManagement;
    231     IDynamicSource mDynamicSource;
    232     IMetadataExtraction mMetadataExtraction;
    233     IMetadataTraversal mMetadataTraversal;
    234     // remaining are per-instance private fields not associated with an interface
    235 } CMetadataExtractor;
    236 
    237 typedef struct {
    238     // mandated interfaces
    239     IObject mObject;
    240 
    241 #define INTERFACES_MidiPlayer 29 // see MPH_to_MidiPlayer in MPH_to.c for list of interfaces
    242     SLuint8 mInterfaceStates2[INTERFACES_MidiPlayer - INTERFACES_Default];
    243     IDynamicInterfaceManagement mDynamicInterfaceManagement;
    244     IPlay mPlay;
    245     I3DDoppler m3DDoppler;
    246     I3DGrouping m3DGrouping;
    247     I3DLocation m3DLocation;
    248     I3DSource m3DSource;
    249     IBufferQueue mBufferQueue;
    250     IEffectSend mEffectSend;
    251     IMetadataExtraction mMetadataExtraction;
    252     IMetadataTraversal mMetadataTraversal;
    253     IMIDIMessage mMIDIMessage;
    254     IMIDITime mMIDITime;
    255     IMIDITempo mMIDITempo;
    256     IMIDIMuteSolo mMIDIMuteSolo;
    257     IPrefetchStatus mPrefetchStatus;
    258     ISeek mSeek;
    259     IVolume mVolume;
    260     IMuteSolo mMuteSolo;
    261     // optional interfaces
    262     I3DMacroscopic m3DMacroscopic;
    263     IBassBoost mBassBoost;
    264     IDynamicSource mDynamicSource;
    265     IEnvironmentalReverb mEnvironmentalReverb;
    266     IEqualizer mEqualizer;
    267     IPitch mPitch;
    268     IPresetReverb mPresetReverb;
    269     IPlaybackRate mPlaybackRate;
    270     IVirtualizer mVirtualizer;
    271     IVisualization mVisualization;
    272     // remaining are per-instance private fields not associated with an interface
    273 } CMidiPlayer;
    274 
    275 /*typedef*/ struct COutputMix_struct {
    276     // mandated interfaces
    277     IObject mObject;
    278 #ifdef ANDROID
    279 #define INTERFACES_OutputMix 12 // see MPH_to_OutputMix in MPH_to.c for list of interfaces
    280 #else
    281 #define INTERFACES_OutputMix 11 // see MPH_to_OutputMix in MPH_to.c for list of interfaces
    282 #endif
    283     SLuint8 mInterfaceStates2[INTERFACES_OutputMix - INTERFACES_Default];
    284     IDynamicInterfaceManagement mDynamicInterfaceManagement;
    285     IOutputMix mOutputMix;
    286 #ifdef USE_OUTPUTMIXEXT
    287     IOutputMixExt mOutputMixExt;
    288 #endif
    289     IEnvironmentalReverb mEnvironmentalReverb;
    290     IEqualizer mEqualizer;
    291     IPresetReverb mPresetReverb;
    292     IVirtualizer mVirtualizer;
    293     IVolume mVolume;
    294     // optional interfaces
    295     IBassBoost mBassBoost;
    296     IVisualization mVisualization;
    297 #ifdef ANDROID
    298     IAndroidEffect mAndroidEffect;
    299 #endif
    300     // remaining are per-instance private fields not associated with an interface
    301 } /*COutputMix*/;
    302 
    303 typedef struct {
    304     // mandated interfaces
    305     IObject mObject;
    306 #define INTERFACES_VibraDevice 3 // see MPH_to_VibraDevice in MPH_to.c for list of interfaces
    307     SLuint8 mInterfaceStates2[INTERFACES_VibraDevice - INTERFACES_Default];
    308     IDynamicInterfaceManagement mDynamicInterfaceManagement;
    309     IVibra mVibra;
    310     // remaining are per-instance private fields not associated with an interface
    311     SLuint32 mDeviceID;
    312 } CVibraDevice;
    313 
    314 
    315 typedef struct CMediaPlayer_struct {
    316     IObject mObject;
    317 #ifdef ANDROID
    318 #define INTERFACES_MediaPlayer 8
    319 #else
    320 #define INTERFACES_MediaPlayer 7
    321 #endif
    322     XAuint8 mInterfaceStates2[INTERFACES_MediaPlayer - INTERFACES_Default];
    323     IDynamicInterfaceManagement mDynamicInterfaceManagement;
    324     IDynamicSource mDynamicSource;
    325     IPlay mPlay;
    326     IStreamInformation mStreamInfo;
    327     IVolume mVolume;
    328     ISeek mSeek;
    329     IPrefetchStatus mPrefetchStatus;
    330 #ifdef ANDROID
    331     IAndroidBufferQueue mAndroidBufferQueue;
    332 #endif
    333     // fields below are per-instance private fields not associated with an interface
    334     DataLocatorFormat mDataSource;
    335     DataLocatorFormat mBankSource;
    336     DataLocatorFormat mAudioSink;
    337     DataLocatorFormat mImageVideoSink;
    338     DataLocatorFormat mVibraSink;
    339     DataLocatorFormat mLEDArraySink;
    340     SLuint8 mNumChannels;   // initially UNKNOWN_NUMCHANNELS, then const once it is known,
    341                             // range 1 <= x <= 8 FIXME FCC_8
    342 #ifdef ANDROID
    343     android::sp<android::GenericPlayer> mAVPlayer;
    344     android::sp<android::CallbackProtector> mCallbackProtector;
    345     enum AndroidObjectType mAndroidObjType;
    346     /** identifies the initialization and preparation state */
    347     enum AndroidObjectState mAndroidObjState;
    348     /** identifies which group of effects ("session") this player belongs to */
    349     audio_session_t mSessionId;
    350     /** identifies the Android stream type playback will occur on */
    351     audio_stream_type_t mStreamType;
    352 #endif
    353 } CMediaPlayer;
    354