sles_allinclusive.h revision 6fff2c605cdc46a10037e011d8fb47702ae70c37
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 "OpenSLES.h"
18#include <stddef.h> // offsetof
19#include <stdlib.h> // malloc
20#include <string.h> // memcmp
21#include <stdio.h>  // debugging
22#include <assert.h> // debugging
23#include <pthread.h>
24#include <unistd.h> // usleep
25
26#include "MPH.h"
27#include "MPH_to.h"
28#include "devices.h"
29
30#ifdef USE_SNDFILE
31#include <sndfile.h>
32#endif // USE_SNDFILE
33
34#ifdef USE_SDL
35#include <SDL/SDL_audio.h>
36#endif // USE_SDL
37
38#if defined(USE_ANDROID)
39#include "media/AudioSystem.h"
40#include "media/AudioTrack.h"
41#include "media/mediaplayer.h"
42#include <utils/String8.h>
43#define ANDROID_SL_MILLIBEL_MAX 0
44#endif
45
46#ifdef USE_OUTPUTMIXEXT
47#include "OutputMixExt.h"
48#endif
49
50// Hook functions
51
52typedef void (*VoidHook)(void *self);
53typedef SLresult (*StatusHook)(void *self);
54typedef SLresult (*AsyncHook)(void *self, SLboolean async);
55
56
57// Describes how an interface is related to a given class
58
59#define INTERFACE_IMPLICIT           0
60#define INTERFACE_EXPLICIT           1
61#define INTERFACE_OPTIONAL           2
62#define INTERFACE_DYNAMIC            3
63#define INTERFACE_DYNAMIC_GAME       INTERFACE_DYNAMIC
64#define INTERFACE_DYNAMIC_MUSIC      INTERFACE_DYNAMIC
65#define INTERFACE_DYNAMIC_MUSIC_GAME INTERFACE_DYNAMIC
66#define INTERFACE_EXPLICIT_GAME      INTERFACE_EXPLICIT
67#define INTERFACE_GAME               INTERFACE_OPTIONAL
68#define INTERFACE_GAME_MUSIC         INTERFACE_OPTIONAL
69#define INTERFACE_MUSIC_GAME         INTERFACE_OPTIONAL
70#define INTERFACE_OPTIONAL_DYNAMIC   INTERFACE_DYNAMIC
71#define INTERFACE_PHONE_GAME         INTERFACE_OPTIONAL
72#define INTERFACE_TBD                INTERFACE_IMPLICIT
73
74// Maps an interface ID to its offset within the class that exposes it
75
76struct iid_vtable {
77    unsigned char mMPH;
78    unsigned char mInterface;   // relationship
79    /*size_t*/ unsigned short mOffset;
80};
81
82// Per-class const data shared by all instances of the same class
83
84typedef struct {
85    // needed by all classes (class class, the superclass of all classes)
86    const struct iid_vtable *mInterfaces;
87    SLuint32 mInterfaceCount;
88    const signed char *mMPH_to_index;
89    // FIXME not yet used
90    const char * const mName;
91    size_t mSize;
92    SLuint32 mObjectID;
93    AsyncHook mRealize;
94    AsyncHook mResume;
95    VoidHook mDestroy;
96    // append per-class data here
97} ClassTable;
98
99#ifdef USE_OUTPUTMIXEXT
100
101// Track describes each input to OutputMixer
102// FIXME not for Android
103
104struct Track {
105    const SLDataFormat_PCM *mDfPcm;
106    struct BufferQueue_interface *mBufferQueue;
107    struct Play_interface *mPlay; // mixer examines this track if non-NULL
108    const void *mReader;    // pointer to next frame in BufferHeader.mBuffer
109    SLuint32 mAvail;        // number of available bytes
110};
111
112#endif
113
114// BufferHeader describes each element of a BufferQueue, other than the data
115
116struct BufferHeader {
117    const void *mBuffer;
118    SLuint32 mSize;
119};
120
121#ifdef USE_OUTPUTMIXEXT
122
123// stereo is a frame consisting of a pair of 16-bit PCM samples
124
125typedef struct {
126    short left;
127    short right;
128} stereo;
129
130#endif
131
132#ifdef USE_SNDFILE
133
134struct SndFile {
135    // save URI also?
136    SLchar *mPathname;
137    SNDFILE *mSNDFILE;
138    // These are used when Enqueue returns SL_RESULT_BUFFER_INSUFFICIENT
139    const void *mRetryBuffer;
140    SLuint32 mRetrySize;
141    SLboolean mIs0; // which buffer to use next
142    // FIXME magic numbers
143    short mBuffer0[512];
144    short mBuffer1[512];
145};
146
147#endif // USE_SNDFILE
148
149#ifdef __cplusplus
150#define this this_
151#endif
152
153/* Interface structures */
154
155typedef struct Object_interface {
156    const struct SLObjectItf_ *mItf;
157    // FIXME probably not needed for an Object, as it is always first,
158    // but look for lingering code that assumes it is here before deleting
159    struct Object_interface *mThis;
160    const ClassTable *mClass;
161    volatile SLuint32 mState;
162    slObjectCallback mCallback;
163    void *mContext;
164    unsigned mExposedMask;  // exposed interfaces
165    unsigned mLossOfControlMask;    // interfaces with loss of control enabled
166    SLint32 mPriority;
167    SLboolean mPreemptable;
168    pthread_mutex_t mMutex;
169    pthread_cond_t mCond;
170    // FIXME also an object ID for RPC
171    // FIXME and a human-readable name for debugging
172} IObject;
173
174#include "locks.h"
175
176typedef struct {
177    const struct SL3DCommitItf_ *mItf;
178    IObject *mThis;
179    SLboolean mDeferred;
180    SLuint32 mGeneration;   // incremented each master clock cycle
181} I3DCommit;
182
183// FIXME move
184enum CartesianSphericalActive {
185    CARTESIAN_COMPUTED_SPHERICAL_SET,
186    CARTESIAN_REQUESTED_SPHERICAL_SET,
187    CARTESIAN_UNKNOWN_SPHERICAL_SET,
188    CARTESIAN_SET_SPHERICAL_COMPUTED,   // not in 1.0.1
189    CARTESIAN_SET_SPHERICAL_REQUESTED,  // not in 1.0.1
190    CARTESIAN_SET_SPHERICAL_UNKNOWN
191};
192
193typedef struct {
194    const struct SL3DDopplerItf_ *mItf;
195    IObject *mThis;
196    // The API allows client to specify either Cartesian and spherical velocities.
197    // But an implementation will likely prefer one or the other. So for
198    // maximum portablity, we maintain both units and an indication of which
199    // unit was set most recently. In addition, we keep a flag saying whether
200    // the other unit has been derived yet. It can take significant time
201    // to compute the other unit, so this may be deferred to another thread.
202    // For this reason we also keep an indication of whether the secondary
203    // has been computed yet, and its accuracy.
204    // Though only one unit is primary at a time, a union is inappropriate:
205    // the application might read in both units (not in 1.0.1),
206    // and due to multi-threading concerns.
207    SLVec3D mVelocityCartesian;
208    struct {
209        SLmillidegree mAzimuth;
210        SLmillidegree mElevation;
211        SLmillidegree mSpeed;
212    } mVelocitySpherical;
213    enum CartesianSphericalActive mVelocityActive;
214    SLpermille mDopplerFactor;
215} I3DDoppler;
216
217typedef struct {
218    const struct SL3DGroupingItf_ *mItf;
219    IObject *mThis;
220    SLObjectItf mGroup;
221    // FIXME link to group's set
222} I3DGrouping;
223
224// FIXME move
225enum AnglesVectorsActive {
226    ANGLES_COMPUTED_VECTORS_SET,    // not in 1.0.1
227    ANGLES_REQUESTED_VECTORS_SET,   // not in 1.0.1
228    ANGLES_UNKNOWN_VECTORS_SET,
229    ANGLES_SET_VECTORS_COMPUTED,
230    ANGLES_SET_VECTORS_REQUESTED,
231    ANGLES_SET_VECTORS_UNKNOWN
232};
233
234typedef struct {
235    const struct SL3DLocationItf_ *mItf;
236    IObject *mThis;
237    SLVec3D mLocationCartesian;
238    struct {
239        SLmillidegree mAzimuth;
240        SLmillidegree mElevation;
241        SLmillimeter mDistance;
242    } mLocationSpherical;
243    enum CartesianSphericalActive mLocationActive;
244    struct {
245        SLmillidegree mHeading;
246        SLmillidegree mPitch;
247        SLmillidegree mRoll;
248    } mOrientationAngles;
249    struct {
250        SLVec3D mFront;
251        SLVec3D mAbove;
252        SLVec3D mUp;
253    } mOrientationVectors;
254    enum AnglesVectorsActive mOrientationActive;
255    // Rotations can be slow, so are deferred.
256    SLmillidegree mTheta;
257    SLVec3D mAxis;
258    SLboolean mRotatePending;
259} I3DLocation;
260
261typedef struct {
262    const struct SL3DMacroscopicItf_ *mItf;
263    IObject *mThis;
264    struct {
265        SLmillimeter mWidth;
266        SLmillimeter mHeight;
267        SLmillimeter mDepth;
268    } mSize;
269    struct {
270        SLmillimeter mHeading;
271        SLmillimeter mPitch;
272        SLmillimeter mRoll;
273    } mOrientationAngles;
274    struct {
275        SLVec3D mFront;
276        SLVec3D mUp;
277    } mOrientationVectors;
278    enum AnglesVectorsActive mOrientationActive;
279    // FIXME no longer needed? was for optimization
280    // SLuint32 mGeneration;
281    // Rotations can be slow, so are deferred.
282    SLmillidegree mTheta;
283    SLVec3D mAxis;
284    SLboolean mRotatePending;
285} I3DMacroscopic;
286
287typedef struct {
288    const struct SL3DSourceItf_ *mItf;
289    IObject *mThis;
290    SLboolean mHeadRelative;
291    SLboolean mRolloffMaxDistanceMute;
292    SLmillimeter mMaxDistance;
293    SLmillimeter mMinDistance;
294    SLmillidegree mConeInnerAngle;
295    SLmillidegree mConeOuterAngle;
296    SLmillibel mConeOuterLevel;
297    SLpermille mRolloffFactor;
298    SLpermille mRoomRolloffFactor;
299    SLuint8 mDistanceModel;
300} I3DSource;
301
302typedef struct {
303    const struct SLAudioDecoderCapabilitiesItf_ *mItf;
304    IObject *mThis;
305} IAudioDecoderCapabilities;
306
307typedef struct {
308    const struct SLAudioEncoderItf_ *mItf;
309    IObject *mThis;
310    SLAudioEncoderSettings mSettings;
311} IAudioEncoder;
312
313typedef struct {
314    const struct SLAudioEncoderCapabilitiesItf_ *mItf;
315    IObject *mThis;
316} IAudioEncoderCapabilities;
317
318typedef struct {
319    const struct SLAudioIODeviceCapabilitiesItf_ *mItf;
320    IObject *mThis;
321    slAvailableAudioInputsChangedCallback mAvailableAudioInputsChangedCallback;
322    void *mAvailableAudioInputsChangedContext;
323    slAvailableAudioOutputsChangedCallback mAvailableAudioOutputsChangedCallback;
324    void *mAvailableAudioOutputsChangedContext;
325    slDefaultDeviceIDMapChangedCallback mDefaultDeviceIDMapChangedCallback;
326    void *mDefaultDeviceIDMapChangedContext;
327} IAudioIODeviceCapabilities;
328
329typedef struct {
330    const struct SLBassBoostItf_ *mItf;
331    IObject *mThis;
332    SLboolean mEnabled;
333    SLpermille mStrength;
334} IBassBoost;
335
336typedef struct BufferQueue_interface {
337    const struct SLBufferQueueItf_ *mItf;
338    IObject *mThis;
339    volatile SLBufferQueueState mState;
340    slBufferQueueCallback mCallback;
341    void *mContext;
342    SLuint32 mNumBuffers;
343    struct BufferHeader *mArray;
344    struct BufferHeader *mFront, *mRear;
345    SLuint32 mSizeConsumed;
346    // saves a malloc in the typical case
347#define BUFFER_HEADER_TYPICAL 4
348    struct BufferHeader mTypical[BUFFER_HEADER_TYPICAL+1];
349} IBufferQueue;
350
351typedef struct {
352    const struct SLDeviceVolumeItf_ *mItf;
353    IObject *mThis;
354    SLint32 mVolume[2]; // FIXME Hard-coded for default in/out
355} IDeviceVolume;
356
357typedef struct {
358    const struct SLDynamicInterfaceManagementItf_ *mItf;
359    IObject *mThis;
360    unsigned mAddedMask;    // added interfaces, a subset of exposed interfaces
361    slDynamicInterfaceManagementCallback mCallback;
362    void *mContext;
363} IDynamicInterfaceManagement;
364
365typedef struct {
366    const struct SLDynamicSourceItf_ *mItf;
367    IObject *mThis;
368    SLDataSource *mDataSource;
369} IDynamicSource;
370
371// FIXME Move this elsewhere
372
373#define AUX_ENVIRONMENTALREVERB 0
374#define AUX_PRESETREVERB        1
375#define AUX_MAX                 2
376
377#if 0
378static const unsigned char AUX_to_MPH[AUX_MAX] = {
379    MPH_ENVIRONMENTALREVERB,
380    MPH_PRESETREVERB
381};
382#endif
383
384// private
385
386struct EnableLevel {
387    SLboolean mEnable;
388    SLmillibel mSendLevel;
389};
390
391typedef struct {
392    const struct SLEffectSendItf_ *mItf;
393    IObject *mThis;
394    struct OutputMix_class *mOutputMix;
395    SLmillibel mDirectLevel;
396    struct EnableLevel mEnableLevels[AUX_MAX];
397} IEffectSend;
398
399// private
400
401typedef struct {
402    const struct SLEngineItf_ *mItf;
403    IObject *mThis;
404    SLboolean mLossOfControlGlobal;
405    // FIXME Per-class non-const data such as vector of created objects.
406    // Each engine is its own universe.
407    SLuint32 mInstanceCount;
408    // Vector<Type> instances;
409    // FIXME set of objects
410#define INSTANCE_MAX 32 // FIXME no magic numbers
411    IObject *mInstances[INSTANCE_MAX];
412} IEngine;
413
414typedef struct {
415    const struct SLEngineCapabilitiesItf_ *mItf;
416    IObject *mThis;
417    SLboolean mThreadSafe;
418} IEngineCapabilities;
419
420typedef struct {
421    const struct SLEnvironmentalReverbItf_ *mItf;
422    IObject *mThis;
423    SLEnvironmentalReverbSettings mProperties;
424} IEnvironmentalReverb;
425
426// FIXME move
427struct EqualizerBand {
428    SLmilliHertz mMin;
429    SLmilliHertz mCenter;
430    SLmilliHertz mMax;
431};
432
433typedef struct {
434    const struct SLEqualizerItf_ *mItf;
435    IObject *mThis;
436    SLboolean mEnabled;
437    SLuint16 mPreset;
438    SLmillibel *mLevels;
439    // const
440    SLuint16 mNumPresets;
441    SLuint16 mNumBands;
442    const struct EqualizerBand *mBands;
443    const SLchar * const *mPresetNames;
444    SLmillibel mBandLevelRangeMin;
445    SLmillibel mBandLevelRangeMax;
446} IEqualizer;
447
448typedef struct {
449    const struct SLLEDArrayItf_ *mItf;
450    IObject *mThis;
451    SLuint32 mLightMask;
452    SLHSL *mColor;
453    // const
454    SLuint8 mCount;
455} ILEDArray;
456
457// FIXME sort: MIDI goes here
458
459typedef struct {
460    const struct SLMetadataExtractionItf_ *mItf;
461    IObject *mThis;
462    SLuint32 mKeySize;
463    const void *mKey;
464    SLuint32 mKeyEncoding;
465    const SLchar *mValueLangCountry;
466    SLuint32 mValueEncoding;
467    SLuint8 mFilterMask;
468    /*FIXME*/ int mKeyFilter;
469} IMetadataExtraction;
470
471typedef struct {
472    const struct SLMetadataTraversalItf_ *mItf;
473    IObject *mThis;
474    SLuint32 mIndex;
475    SLuint32 mMode;
476    SLuint32 mCount;
477    SLuint32 mSize;
478} IMetadataTraversal;
479
480typedef struct {
481    const struct SLMIDIMessageItf_ *mItf;
482    IObject *mThis;
483    slMetaEventCallback mMetaEventCallback;
484    void *mMetaEventContext;
485    slMIDIMessageCallback mMessageCallback;
486    void *mMessageContext;
487    SLuint8 mMessageTypes;
488} IMIDIMessage;
489
490typedef struct {
491    const struct SLMIDIMuteSoloItf_ *mItf;
492    IObject *mThis;
493    SLuint16 mChannelMuteMask;
494    SLuint16 mChannelSoloMask;
495    SLuint32 mTrackMuteMask;
496    SLuint32 mTrackSoloMask;
497    // const ?
498    SLuint16 mTrackCount;
499} IMIDIMuteSolo;
500
501typedef struct {
502    const struct SLMIDITempoItf_ *mItf;
503    IObject *mThis;
504    SLuint32 mTicksPerQuarterNote;
505    SLuint32 mMicrosecondsPerQuarterNote;
506} IMIDITempo;
507
508typedef struct {
509    const struct SLMIDITimeItf_ *mItf;
510    IObject *mThis;
511    SLuint32 mDuration;
512    SLuint32 mPosition;
513    SLuint32 mStartTick;
514    SLuint32 mNumTicks;
515} IMIDITime;
516
517typedef struct {
518    const struct SLMuteSoloItf_ *mItf;
519    IObject *mThis;
520    SLuint32 mMuteMask;
521    SLuint32 mSoloMask;
522    // const
523    SLuint8 mNumChannels;
524} IMuteSolo;
525
526typedef struct {
527    const struct SLOutputMixItf_ *mItf;
528    IObject *mThis;
529    slMixDeviceChangeCallback mCallback;
530    void *mContext;
531#ifdef USE_OUTPUTMIXEXT
532    unsigned mActiveMask;   // 1 bit per active track
533    struct Track mTracks[32]; // FIXME magic
534#endif
535} IOutputMix;
536
537#ifdef USE_OUTPUTMIXEXT
538typedef struct {
539    const struct SLOutputMixExtItf_ *mItf;
540    IObject *mThis;
541} IOutputMixExt;
542#endif
543
544typedef struct {
545    const struct SLPitchItf_ *mItf;
546    IObject *mThis;
547    SLpermille mPitch;
548    // const
549    SLpermille mMinPitch;
550    SLpermille mMaxPitch;
551} IPitch;
552
553typedef struct Play_interface {
554    const struct SLPlayItf_ *mItf;
555    IObject *mThis;
556    volatile SLuint32 mState;
557    SLmillisecond mDuration;
558    SLmillisecond mPosition;
559    // unsigned mPositionSamples;  // position in sample units
560    slPlayCallback mCallback;
561    void *mContext;
562    SLuint32 mEventFlags;
563    SLmillisecond mMarkerPosition;
564    SLmillisecond mPositionUpdatePeriod;
565} IPlay;
566
567typedef struct {
568    const struct SLPlaybackRateItf_ *mItf;
569    IObject *mThis;
570    SLpermille mRate;
571    SLuint32 mProperties;
572    // const
573    SLpermille mMinRate;
574    SLpermille mMaxRate;
575    SLpermille mStepSize;
576    SLuint32 mCapabilities;
577} IPlaybackRate;
578
579typedef struct {
580    const struct SLPrefetchStatusItf_ *mItf;
581    IObject *mThis;
582    SLuint32 mStatus;
583    SLpermille mLevel;
584    slPrefetchCallback mCallback;
585    void *mContext;
586    SLuint32 mCallbackEventsMask;
587    SLpermille mFillUpdatePeriod;
588} IPrefetchStatus;
589
590typedef struct {
591    const struct SLPresetReverbItf_ *mItf;
592    IObject *mThis;
593    SLuint16 mPreset;
594} IPresetReverb;
595
596typedef struct {
597    const struct SLRatePitchItf_ *mItf;
598    IObject *mThis;
599    SLpermille mRate;
600    // const
601    SLpermille mMinRate;
602    SLpermille mMaxRate;
603} IRatePitch;
604
605typedef struct {
606    const struct SLRecordItf_ *mItf;
607    IObject *mThis;
608    SLuint32 mState;
609    SLmillisecond mDurationLimit;
610    SLmillisecond mPosition;
611    slRecordCallback mCallback;
612    void *mContext;
613    SLuint32 mCallbackEventsMask;
614    SLmillisecond mMarkerPosition;
615    SLmillisecond mPositionUpdatePeriod;
616} IRecord;
617
618typedef struct {
619    const struct SLSeekItf_ *mItf;
620    IObject *mThis;
621    SLmillisecond mPos;
622    SLboolean mLoopEnabled;
623    SLmillisecond mStartPos;
624    SLmillisecond mEndPos;
625} ISeek;
626
627typedef struct {
628    const struct SLThreadSyncItf_ *mItf;
629    IObject *mThis;
630    SLboolean mInCriticalSection;
631    SLboolean mWaiting;
632    pthread_t mOwner;
633} IThreadSync;
634
635typedef struct {
636    const struct SLVibraItf_ *mItf;
637    IObject *mThis;
638    SLboolean mVibrate;
639    SLmilliHertz mFrequency;
640    SLpermille mIntensity;
641} IVibra;
642
643typedef struct {
644    const struct SLVirtualizerItf_ *mItf;
645    IObject *mThis;
646    SLboolean mEnabled;
647    SLpermille mStrength;
648} IVirtualizer;
649
650typedef struct {
651    const struct SLVisualizationItf_ *mItf;
652    IObject *mThis;
653    slVisualizationCallback mCallback;
654    void *mContext;
655    SLmilliHertz mRate;
656} IVisualization;
657
658typedef struct {
659    const struct SLVolumeItf_ *mItf;
660    IObject *mThis;
661    SLmillibel mLevel;
662    SLboolean mMute;
663    SLboolean mEnableStereoPosition;
664    SLpermille mStereoPosition;
665#ifdef USE_ANDROID
666    /**
667     * Amplification (can be attenuation) factor derived for the VolumeLevel
668     */
669    float mAmplFromVolLevel;
670    /**
671     * Left/right amplification (can be attenuations) factors derived for the StereoPosition
672     */
673    float mAmplFromStereoPos[2];
674    /**
675     * Channel mask for which channels are muted
676     */
677    int mChannelMutes;
678    /**
679     * Channel mask for which channels are solo'ed
680     */
681    int mChannelSolos;
682#endif
683} IVolume;
684
685/* Class structures */
686
687typedef struct {
688    IObject mObject;
689    IDynamicInterfaceManagement mDynamicInterfaceManagement;
690    I3DLocation m3DLocation;
691    I3DDoppler m3DDoppler;
692    I3DSource m3DSource;
693    I3DMacroscopic m3DMacroscopic;
694    // FIXME set of objects
695} C3DGroup;
696
697#ifdef USE_ANDROID
698/*
699 * Used to define the mapping from an OpenSL ES audio player to an Android
700 * media framework object
701 */
702enum AndroidObject_type {
703    INVALID_TYPE     =-1,
704    MEDIAPLAYER      = 0,
705    AUDIOTRACK_PUSH  = 1,
706    AUDIOTRACK_PULL  = 2,
707    NUM_AUDIOPLAYER_MAP_TYPES
708};
709#endif
710
711typedef struct {
712    IObject mObject;
713    IDynamicInterfaceManagement mDynamicInterfaceManagement;
714    IPlay mPlay;
715    I3DDoppler m3DDoppler;
716    I3DGrouping m3DGrouping;
717    I3DLocation m3DLocation;
718    I3DSource m3DSource;
719    IBufferQueue mBufferQueue;
720    IEffectSend mEffectSend;
721    IMuteSolo mMuteSolo;
722    IMetadataExtraction mMetadataExtraction;
723    IMetadataTraversal mMetadataTraversal;
724    IPrefetchStatus mPrefetchStatus;
725    IRatePitch mRatePitch;
726    ISeek mSeek;
727    IVolume mVolume;
728    // optional interfaces
729    I3DMacroscopic m3DMacroscopic;
730    IBassBoost mBassBoost;
731    IDynamicSource mDynamicSource;
732    IEnvironmentalReverb mEnvironmentalReverb;
733    IEqualizer mEqualizer;
734    IPitch mPitch;
735    IPresetReverb mPresetReverb;
736    IPlaybackRate mPlaybackRate;
737    IVirtualizer mVirtualizer;
738    IVisualization mVisualization;
739    // rest of fields are not related to the interfaces
740#ifdef USE_SNDFILE
741    struct SndFile mSndFile;
742#endif // USE_SNDFILE
743#ifdef USE_ANDROID
744    enum AndroidObject_type mAndroidObjType;
745    union {
746        android::AudioTrack *mAudioTrack;
747        android::MediaPlayer *mMediaPlayer;
748    };
749    char* mUri;// FIXME temporary storage before we handle that correctly
750    pthread_t mThread;
751#endif
752} CAudioPlayer;
753
754typedef struct {
755    // mandated interfaces
756    IObject mObject;
757    IDynamicInterfaceManagement mDynamicInterfaceManagement;
758    IRecord mRecord;
759    IAudioEncoder mAudioEncoder;
760    // optional interfaces
761    IBassBoost mBassBoost;
762    IDynamicSource mDynamicSource;
763    IEqualizer mEqualizer;
764    IVisualization mVisualization;
765    IVolume mVolume;
766} CAudioRecorder;
767
768typedef struct {
769    // mandated implicit interfaces
770    IObject mObject;
771    IDynamicInterfaceManagement mDynamicInterfaceManagement;
772    IEngine mEngine;
773    IEngineCapabilities mEngineCapabilities;
774    IThreadSync mThreadSync;
775    // mandated explicit interfaces
776    IAudioIODeviceCapabilities mAudioIODeviceCapabilities;
777    IAudioDecoderCapabilities mAudioDecoderCapabilities;
778    IAudioEncoderCapabilities mAudioEncoderCapabilities;
779    I3DCommit m3DCommit;
780    // optional interfaces
781    IDeviceVolume mDeviceVolume;
782    pthread_t mSyncThread;
783} CEngine;
784
785typedef struct {
786    // mandated interfaces
787    IObject mObject;
788    IDynamicInterfaceManagement mDynamicInterfaceManagement;
789    ILEDArray mLEDArray;
790    SLuint32 mDeviceID;
791} CLEDDevice;
792
793typedef struct {
794    // mandated interfaces
795    IObject mObject;
796    IDynamicInterfaceManagement mDynamicInterfaceManagement;
797    I3DDoppler m3DDoppler;
798    I3DLocation m3DLocation;
799} CListener;
800
801typedef struct {
802    // mandated interfaces
803    IObject mObject;
804    IDynamicInterfaceManagement mDynamicInterfaceManagement;
805    IDynamicSource mDynamicSource;
806    IMetadataExtraction mMetadataExtraction;
807    IMetadataTraversal mMetadataTraversal;
808} CMetadataExtractor;
809
810typedef struct {
811    // mandated interfaces
812    IObject mObject;
813    IDynamicInterfaceManagement mDynamicInterfaceManagement;
814    IPlay mPlay;
815    I3DDoppler m3DDoppler;
816    I3DGrouping m3DGrouping;
817    I3DLocation m3DLocation;
818    I3DSource m3DSource;
819    IBufferQueue mBufferQueue;
820    IEffectSend mEffectSend;
821    IMuteSolo mMuteSolo;
822    IMetadataExtraction mMetadataExtraction;
823    IMetadataTraversal mMetadataTraversal;
824    IMIDIMessage mMIDIMessage;
825    IMIDITime mMIDITime;
826    IMIDITempo mMIDITempo;
827    IMIDIMuteSolo mMIDIMuteSolo;
828    IPrefetchStatus mPrefetchStatus;
829    ISeek mSeek;
830    IVolume mVolume;
831    // optional interfaces
832    I3DMacroscopic m3DMacroscopic;
833    IBassBoost mBassBoost;
834    IDynamicSource mDynamicSource;
835    IEnvironmentalReverb mEnvironmentalReverb;
836    IEqualizer mEqualizer;
837    IPitch mPitch;
838    IPresetReverb mPresetReverb;
839    IPlaybackRate mPlaybackRate;
840    IVirtualizer mVirtualizer;
841    IVisualization mVisualization;
842} CMidiPlayer;
843
844typedef struct OutputMix_class {
845    // mandated interfaces
846    IObject mObject;
847    IDynamicInterfaceManagement mDynamicInterfaceManagement;
848    IOutputMix mOutputMix;
849#ifdef USE_OUTPUTMIXEXT
850    IOutputMixExt mOutputMixExt;
851#endif
852    IEnvironmentalReverb mEnvironmentalReverb;
853    IEqualizer mEqualizer;
854    IPresetReverb mPresetReverb;
855    IVirtualizer mVirtualizer;
856    IVolume mVolume;
857    // optional interfaces
858    IBassBoost mBassBoost;
859    IVisualization mVisualization;
860} COutputMix;
861
862typedef struct {
863    // mandated interfaces
864    IObject mObject;
865    IDynamicInterfaceManagement mDynamicInterfaceManagement;
866    IVibra mVibra;
867    //
868    SLuint32 mDeviceID;
869} CVibraDevice;
870
871struct MPH_init {
872    // unsigned char mMPH;
873    VoidHook mInit;
874    VoidHook mDeinit;
875};
876
877extern /*static*/ int IID_to_MPH(const SLInterfaceID iid);
878extern /*static*/ const struct MPH_init MPH_init_table[MPH_MAX];
879extern SLresult checkInterfaces(const ClassTable *class__,
880    SLuint32 numInterfaces, const SLInterfaceID *pInterfaceIds,
881    const SLboolean *pInterfaceRequired, unsigned *pExposedMask);
882extern IObject *construct(const ClassTable *class__,
883    unsigned exposedMask, SLEngineItf engine);
884extern const ClassTable *objectIDtoClass(SLuint32 objectID);
885extern const struct SLInterfaceID_ SL_IID_array[MPH_MAX];
886extern SLuint32 IObjectToObjectID(IObject *object);
887
888// Map an interface to it's "object ID" (which is really a class ID)
889
890#define InterfaceToObjectID(this) IObjectToObjectID((this)->mThis)
891