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