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