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