itfstruct.h revision faf90312d2156acbf27c62e114fd180708aa7654
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/* Interface structures */
18
19typedef struct Object_interface {
20    const struct SLObjectItf_ *mItf;    // const
21    // field mThis would be redundant within an IObject, so we substitute mEngine
22    CEngine *mEngine;               // const
23    const ClassTable *mClass;       // const
24    SLuint32 mInstanceID;           // const for debugger and for RPC, 0 means unpublished
25    slObjectCallback mCallback;
26    void *mContext;
27    unsigned mGottenMask;           ///< bit-mask of interfaces exposed or added, then gotten
28    unsigned mLossOfControlMask;    // interfaces with loss of control enabled
29    unsigned mAttributesMask;       // attributes which have changed since last sync
30#if USE_PROFILES & USE_PROFILES_BASE
31    SLint32 mPriority;
32#endif
33    pthread_mutex_t mMutex;
34#ifdef USE_DEBUG
35    pthread_t mOwner;
36    const char *mFile;
37    int mLine;
38#endif
39    pthread_cond_t mCond;
40    SLuint8 mState;                 // really SLuint32, but SLuint8 to save space
41#if USE_PROFILES & USE_PROFILES_BASE
42    SLuint8 mPreemptable;           // really SLboolean, but SLuint8 to save space
43#else
44    SLuint8 mPadding;
45#endif
46    SLuint8 mStrongRefCount;        // number of strong references to this object
47    // (object cannot be destroyed as long as > 0, and referrers _prefer_ it stay in Realized state)
48    // for best alignment, do not add any fields here
49#define INTERFACES_Default 1
50    SLuint8 mInterfaceStates[INTERFACES_Default];    // state of each of interface
51    // do not add any fields here
52} IObject;
53
54#include "locks.h"
55
56typedef struct {
57    const struct SL3DCommitItf_ *mItf;
58    IObject *mThis;
59    SLboolean mDeferred;
60    SLuint32 mGeneration;   // incremented each master clock cycle
61    SLuint32 mWaiting;      // number of threads waiting in Commit
62} I3DCommit;
63
64enum CartesianSphericalActive {
65    CARTESIAN_COMPUTED_SPHERICAL_SET,
66    CARTESIAN_REQUESTED_SPHERICAL_SET,
67    CARTESIAN_UNKNOWN_SPHERICAL_SET,
68    CARTESIAN_SET_SPHERICAL_COMPUTED,   // not in 1.0.1
69    CARTESIAN_SET_SPHERICAL_REQUESTED,  // not in 1.0.1
70    CARTESIAN_SET_SPHERICAL_UNKNOWN
71};
72
73typedef struct {
74    const struct SL3DDopplerItf_ *mItf;
75    IObject *mThis;
76    // The API allows client to specify either Cartesian and spherical velocities.
77    // But an implementation will likely prefer one or the other. So for
78    // maximum portablity, we maintain both units and an indication of which
79    // unit was set most recently. In addition, we keep a flag saying whether
80    // the other unit has been derived yet. It can take significant time
81    // to compute the other unit, so this may be deferred to another thread.
82    // For this reason we also keep an indication of whether the secondary
83    // has been computed yet, and its accuracy.
84    // Though only one unit is primary at a time, a union is inappropriate:
85    // the application might read in both units (not in 1.0.1),
86    // and due to multi-threading concerns.
87    SLVec3D mVelocityCartesian;
88    struct {
89        SLmillidegree mAzimuth;
90        SLmillidegree mElevation;
91        SLmillidegree mSpeed;
92    } mVelocitySpherical;
93    enum CartesianSphericalActive mVelocityActive;
94    SLpermille mDopplerFactor;
95} I3DDoppler;
96
97typedef struct {
98    const struct SL3DGroupingItf_ *mItf;
99    IObject *mThis;
100    C3DGroup *mGroup;   // strong reference to associated group or NULL
101} I3DGrouping;
102
103enum AnglesVectorsActive {
104    ANGLES_COMPUTED_VECTORS_SET,    // not in 1.0.1
105    ANGLES_REQUESTED_VECTORS_SET,   // not in 1.0.1
106    ANGLES_UNKNOWN_VECTORS_SET,
107    ANGLES_SET_VECTORS_COMPUTED,
108    ANGLES_SET_VECTORS_REQUESTED,
109    ANGLES_SET_VECTORS_UNKNOWN
110};
111
112typedef struct {
113    const struct SL3DLocationItf_ *mItf;
114    IObject *mThis;
115    SLVec3D mLocationCartesian;
116    struct {
117        SLmillidegree mAzimuth;
118        SLmillidegree mElevation;
119        SLmillimeter mDistance;
120    } mLocationSpherical;
121    enum CartesianSphericalActive mLocationActive;
122    struct {
123        SLmillidegree mHeading;
124        SLmillidegree mPitch;
125        SLmillidegree mRoll;
126    } mOrientationAngles;
127    struct {
128        SLVec3D mFront;
129        SLVec3D mAbove;
130        SLVec3D mUp;
131    } mOrientationVectors;
132    enum AnglesVectorsActive mOrientationActive;
133    // Rotations can be slow, so are deferred.
134    SLmillidegree mTheta;
135    SLVec3D mAxis;
136    SLboolean mRotatePending;
137} I3DLocation;
138
139typedef struct {
140    const struct SL3DMacroscopicItf_ *mItf;
141    IObject *mThis;
142    struct {
143        SLmillimeter mWidth;
144        SLmillimeter mHeight;
145        SLmillimeter mDepth;
146    } mSize;
147    struct {
148        SLmillimeter mHeading;
149        SLmillimeter mPitch;
150        SLmillimeter mRoll;
151    } mOrientationAngles;
152    struct {
153        SLVec3D mFront;
154        SLVec3D mAbove;
155        SLVec3D mUp;
156    } mOrientationVectors;
157    enum AnglesVectorsActive mOrientationActive;
158    // Rotations can be slow, so are deferred.
159    SLmillidegree mTheta;
160    SLVec3D mAxis;
161    SLboolean mRotatePending;
162} I3DMacroscopic;
163
164typedef struct {
165    const struct SL3DSourceItf_ *mItf;
166    IObject *mThis;
167    SLboolean mHeadRelative;
168    SLboolean mRolloffMaxDistanceMute;
169    SLmillimeter mMaxDistance;
170    SLmillimeter mMinDistance;
171    SLmillidegree mConeInnerAngle;
172    SLmillidegree mConeOuterAngle;
173    SLmillibel mConeOuterLevel;
174    SLpermille mRolloffFactor;
175    SLpermille mRoomRolloffFactor;
176    SLuint8 mDistanceModel;
177} I3DSource;
178
179typedef struct {
180    const struct SLAudioDecoderCapabilitiesItf_ *mItf;
181    IObject *mThis;
182} IAudioDecoderCapabilities;
183
184typedef struct {
185    const struct SLAudioEncoderItf_ *mItf;
186    IObject *mThis;
187    SLAudioEncoderSettings mSettings;
188} IAudioEncoder;
189
190typedef struct {
191    const struct SLAudioEncoderCapabilitiesItf_ *mItf;
192    IObject *mThis;
193} IAudioEncoderCapabilities;
194
195typedef struct {
196    const struct SLAudioIODeviceCapabilitiesItf_ *mItf;
197    IObject *mThis;
198    slAvailableAudioInputsChangedCallback mAvailableAudioInputsChangedCallback;
199    void *mAvailableAudioInputsChangedContext;
200    slAvailableAudioOutputsChangedCallback mAvailableAudioOutputsChangedCallback;
201    void *mAvailableAudioOutputsChangedContext;
202    slDefaultDeviceIDMapChangedCallback mDefaultDeviceIDMapChangedCallback;
203    void *mDefaultDeviceIDMapChangedContext;
204} IAudioIODeviceCapabilities;
205
206typedef struct {
207    const struct SLBassBoostItf_ *mItf;
208    IObject *mThis;
209    SLboolean mEnabled;
210    SLpermille mStrength;
211#if defined(ANDROID)
212    effect_descriptor_t mBassBoostDescriptor;
213    android::sp<android::AudioEffect> mBassBoostEffect;
214#endif
215} IBassBoost;
216
217typedef struct BufferQueue_interface {
218    const struct SLBufferQueueItf_ *mItf;
219    IObject *mThis;
220    SLBufferQueueState mState;
221    slBufferQueueCallback mCallback;
222    void *mContext;
223    // originally SLuint32, but range-checked down to SLuint16
224    SLuint16 mNumBuffers;
225    /*SLboolean*/ SLuint16 mClearRequested;
226    BufferHeader *mArray;
227    BufferHeader *mFront, *mRear;
228#ifdef ANDROID
229    SLuint32 mSizeConsumed;
230#endif
231    // saves a malloc in the typical case
232#define BUFFER_HEADER_TYPICAL 4
233    BufferHeader mTypical[BUFFER_HEADER_TYPICAL+1];
234} IBufferQueue;
235
236#define MAX_DEVICE 2    // hard-coded array size for default in/out
237
238typedef struct {
239    const struct SLDeviceVolumeItf_ *mItf;
240    IObject *mThis;
241    SLint32 mVolume[MAX_DEVICE];
242} IDeviceVolume;
243
244typedef struct {
245    const struct SLDynamicInterfaceManagementItf_ *mItf;
246    IObject *mThis;
247    slDynamicInterfaceManagementCallback mCallback;
248    void *mContext;
249} IDynamicInterfaceManagement;
250
251typedef struct {
252    const struct SLDynamicSourceItf_ *mItf;
253    IObject *mThis;
254    SLDataSource *mDataSource;
255} IDynamicSource;
256
257// private
258
259struct EnableLevel {
260    SLboolean mEnable;
261    SLmillibel mSendLevel;
262};
263
264// indexes into IEffectSend.mEnableLevels
265
266#define AUX_ENVIRONMENTALREVERB 0
267#define AUX_PRESETREVERB        1
268#define AUX_MAX                 2
269
270typedef struct {
271    const struct SLEffectSendItf_ *mItf;
272    IObject *mThis;
273    struct EnableLevel mEnableLevels[AUX_MAX];  // wet enable and volume per effect type
274} IEffectSend;
275
276typedef struct Engine_interface {
277    const struct SLEngineItf_ *mItf;
278    IObject *mThis;
279    SLboolean mLossOfControlGlobal;
280#ifdef USE_SDL
281    COutputMix *mOutputMix; // SDL pulls PCM from an arbitrary IOutputMixExt
282#endif
283    // Each engine is its own universe.
284    SLuint32 mInstanceCount;
285    unsigned mInstanceMask; // 1 bit per active object
286    unsigned mChangedMask;  // objects which have changed since last sync
287#define MAX_INSTANCE 32     // maximum active objects per engine, see mInstanceMask
288    IObject *mInstances[MAX_INSTANCE];
289    SLboolean mShutdown;
290    SLboolean mShutdownAck;
291    // SLuint32 mVersion;      // 0xXXYYZZ where XX=major, YY=minor, ZZ=step
292} IEngine;
293
294typedef struct {
295    const struct SLEngineCapabilitiesItf_ *mItf;
296    IObject *mThis;
297    SLboolean mThreadSafe;
298    // const
299    SLuint32 mMaxIndexLED;
300    SLuint32 mMaxIndexVibra;
301} IEngineCapabilities;
302
303typedef struct {
304    const struct SLEnvironmentalReverbItf_ *mItf;
305    IObject *mThis;
306    SLEnvironmentalReverbSettings mProperties;
307#if defined(ANDROID)
308    effect_descriptor_t mEnvironmentalReverbDescriptor;
309    android::sp<android::AudioEffect> mEnvironmentalReverbEffect;
310#endif
311} IEnvironmentalReverb;
312
313struct EqualizerBand {
314    SLmilliHertz mMin;
315    SLmilliHertz mCenter;
316    SLmilliHertz mMax;
317};
318
319#if defined(ANDROID)
320#define MAX_EQ_BANDS 0
321#else
322#define MAX_EQ_BANDS 4  // compile-time limit, runtime limit may be smaller
323#endif
324
325typedef struct {
326    const struct SLEqualizerItf_ *mItf;
327    IObject *mThis;
328    SLboolean mEnabled;
329    SLuint16 mPreset;
330#if 0 < MAX_EQ_BANDS
331    SLmillibel mLevels[MAX_EQ_BANDS];
332#endif
333    // const to end of struct
334    SLuint16 mNumPresets;
335    SLuint16 mNumBands;
336#if !defined(ANDROID)
337    const struct EqualizerBand *mBands;
338    const struct EqualizerPreset *mPresets;
339#endif
340    SLmillibel mBandLevelRangeMin;
341    SLmillibel mBandLevelRangeMax;
342#if defined(ANDROID)
343    effect_descriptor_t mEqDescriptor;
344    android::sp<android::AudioEffect> mEqEffect;
345#endif
346} IEqualizer;
347
348#define MAX_LED_COUNT 32
349
350typedef struct {
351    const struct SLLEDArrayItf_ *mItf;
352    IObject *mThis;
353    SLuint32 mLightMask;
354    SLHSL mColors[MAX_LED_COUNT];
355    // const
356    SLuint8 mCount;
357} ILEDArray;
358
359typedef struct {
360    const struct SLMetadataExtractionItf_ *mItf;
361    IObject *mThis;
362    SLuint32 mKeySize;
363    const void *mKey;
364    SLuint32 mKeyEncoding;
365    const SLchar *mValueLangCountry;
366    SLuint32 mValueEncoding;
367    SLuint8 mFilterMask;
368    int mKeyFilter;
369} IMetadataExtraction;
370
371typedef struct {
372    const struct SLMetadataTraversalItf_ *mItf;
373    IObject *mThis;
374    SLuint32 mIndex;
375    SLuint32 mMode;
376    SLuint32 mCount;
377    SLuint32 mSize;
378} IMetadataTraversal;
379
380typedef struct {
381    const struct SLMIDIMessageItf_ *mItf;
382    IObject *mThis;
383    slMetaEventCallback mMetaEventCallback;
384    void *mMetaEventContext;
385    slMIDIMessageCallback mMessageCallback;
386    void *mMessageContext;
387    SLuint8 mMessageTypes;
388} IMIDIMessage;
389
390typedef struct {
391    const struct SLMIDIMuteSoloItf_ *mItf;
392    IObject *mThis;
393    SLuint16 mChannelMuteMask;
394    SLuint16 mChannelSoloMask;
395    SLuint32 mTrackMuteMask;
396    SLuint32 mTrackSoloMask;
397    // const
398    SLuint16 mTrackCount;
399} IMIDIMuteSolo;
400
401typedef struct {
402    const struct SLMIDITempoItf_ *mItf;
403    IObject *mThis;
404    SLuint32 mTicksPerQuarterNote;
405    SLuint32 mMicrosecondsPerQuarterNote;
406} IMIDITempo;
407
408typedef struct {
409    const struct SLMIDITimeItf_ *mItf;
410    IObject *mThis;
411    SLuint32 mDuration;
412    SLuint32 mPosition;
413    SLuint32 mStartTick;
414    SLuint32 mNumTicks;
415} IMIDITime;
416
417typedef struct {
418    const struct SLMuteSoloItf_ *mItf;
419    IObject *mThis;
420    // fields that were formerly here are now at CAudioPlayer
421} IMuteSolo;
422
423#define MAX_TRACK 32        // see mActiveMask
424
425typedef struct {
426    const struct SLOutputMixItf_ *mItf;
427    IObject *mThis;
428    slMixDeviceChangeCallback mCallback;
429    void *mContext;
430} IOutputMix;
431
432#ifdef USE_OUTPUTMIXEXT
433typedef struct {
434    const struct SLOutputMixExtItf_ *mItf;
435    IObject *mThis;
436    unsigned mActiveMask;   // 1 bit per active track
437    Track mTracks[MAX_TRACK];
438    SLboolean mDestroyRequested;    ///< Mixer to acknowledge application's call to Object::Destroy
439} IOutputMixExt;
440#endif
441
442typedef struct {
443    const struct SLPitchItf_ *mItf;
444    IObject *mThis;
445    SLpermille mPitch;
446    // const
447    SLpermille mMinPitch;
448    SLpermille mMaxPitch;
449} IPitch;
450
451typedef struct Play_interface {
452    const struct SLPlayItf_ *mItf;
453    IObject *mThis;
454    SLuint32 mState;
455    // next 2 fields are read-only to application
456    SLmillisecond mDuration;
457    SLmillisecond mPosition;
458    slPlayCallback mCallback;
459    void *mContext;
460    SLuint32 mEventFlags;
461    // the ISeek trick of using a distinct value doesn't work here because it's readable by app
462    SLmillisecond mMarkerPosition;
463    SLmillisecond mPositionUpdatePeriod; // Zero means do not do position updates (FIXME ~0)
464#ifdef USE_OUTPUTMIXEXT
465    SLuint32 mFrameUpdatePeriod;         // mPositionUpdatePeriod in frame units
466    SLmillisecond mLastSeekPosition;     // Last known accurate position, set at Seek
467    SLuint32 mFramesSinceLastSeek;       // Frames mixed since last known accurate position
468    SLuint32 mFramesSincePositionUpdate; // Frames mixed since last position update callback
469#endif
470} IPlay;
471
472typedef struct {
473    const struct SLPlaybackRateItf_ *mItf;
474    IObject *mThis;
475    SLpermille mRate;
476    SLuint32 mProperties;
477    // const
478    SLpermille mMinRate;
479    SLpermille mMaxRate;
480    SLpermille mStepSize;
481    SLuint32 mCapabilities;
482} IPlaybackRate;
483
484typedef struct {
485    const struct SLPrefetchStatusItf_ *mItf;
486    IObject *mThis;
487    SLuint32 mStatus;
488    SLpermille mLevel;
489    slPrefetchCallback mCallback;
490    void *mContext;
491    SLuint32 mCallbackEventsMask;
492    SLpermille mFillUpdatePeriod;
493} IPrefetchStatus;
494
495typedef struct {
496    const struct SLPresetReverbItf_ *mItf;
497    IObject *mThis;
498    SLuint16 mPreset;
499#if defined(ANDROID)
500    effect_descriptor_t mPresetReverbDescriptor;
501    android::sp<android::AudioEffect> mPresetReverbEffect;
502#endif
503} IPresetReverb;
504
505typedef struct {
506    const struct SLRatePitchItf_ *mItf;
507    IObject *mThis;
508    SLpermille mRate;
509    // const
510    SLpermille mMinRate;
511    SLpermille mMaxRate;
512} IRatePitch;
513
514typedef struct {
515    const struct SLRecordItf_ *mItf;
516    IObject *mThis;
517    SLuint32 mState;
518    SLmillisecond mDurationLimit;
519    SLmillisecond mPosition;
520    slRecordCallback mCallback;
521    void *mContext;
522    SLuint32 mCallbackEventsMask;
523    SLmillisecond mMarkerPosition;
524    SLmillisecond mPositionUpdatePeriod;
525} IRecord;
526
527typedef struct {
528    const struct SLSeekItf_ *mItf;
529    IObject *mThis;
530    SLmillisecond mPos;     // mPos != SL_TIME_UNKNOWN means pending seek request
531    SLboolean mLoopEnabled;
532    SLmillisecond mStartPos;
533    SLmillisecond mEndPos;
534} ISeek;
535
536typedef struct {
537    const struct SLThreadSyncItf_ *mItf;
538    IObject *mThis;
539    SLboolean mInCriticalSection;
540    SLuint32 mWaiting;  // number of threads waiting
541    pthread_t mOwner;
542} IThreadSync;
543
544typedef struct {
545    const struct SLVibraItf_ *mItf;
546    IObject *mThis;
547    SLboolean mVibrate;
548    SLmilliHertz mFrequency;
549    SLpermille mIntensity;
550} IVibra;
551
552typedef struct {
553    const struct SLVirtualizerItf_ *mItf;
554    IObject *mThis;
555    SLboolean mEnabled;
556    SLpermille mStrength;
557#if defined(ANDROID)
558    effect_descriptor_t mVirtualizerDescriptor;
559    android::sp<android::AudioEffect> mVirtualizerEffect;
560#endif
561} IVirtualizer;
562
563typedef struct {
564    const struct SLVisualizationItf_ *mItf;
565    IObject *mThis;
566    slVisualizationCallback mCallback;
567    void *mContext;
568    SLmilliHertz mRate;
569} IVisualization;
570
571typedef struct /*Volume_interface*/ {
572    const struct SLVolumeItf_ *mItf;
573    IObject *mThis;
574    // Values as specified by the application
575    SLmillibel mLevel;
576    SLpermille mStereoPosition;
577    SLuint8 /*SLboolean*/ mMute;
578    SLuint8 /*SLboolean*/ mEnableStereoPosition;
579} IVolume;
580
581typedef struct {
582    const struct XAEngineItf_ *mItf;
583    IObject *mThis;
584} IXAEngine;
585
586/* Class structures */
587
588/*typedef*/ struct C3DGroup_struct {
589    IObject mObject;
590#define INTERFACES_3DGroup 6 // see MPH_to_3DGroup in MPH_to.c for list of interfaces
591    SLuint8 mInterfaceStates2[INTERFACES_3DGroup - INTERFACES_Default];
592    IDynamicInterfaceManagement mDynamicInterfaceManagement;
593    I3DLocation m3DLocation;
594    I3DDoppler m3DDoppler;
595    I3DSource m3DSource;
596    I3DMacroscopic m3DMacroscopic;
597    // remaining are per-instance private fields not associated with an interface
598    unsigned mMemberMask;   // set of member objects
599} /*C3DGroup*/;
600
601#ifdef ANDROID
602
603// FIXME Move these into the I... section above
604
605typedef struct {
606    const struct SLAndroidEffectItf_ *mItf;
607    IObject *mThis;
608    android::KeyedVector<SLuint32, android::AudioEffect* > *mEffects;
609} IAndroidEffect;
610
611typedef struct {
612    const struct SLAndroidEffectCapabilitiesItf_ *mItf;
613    IObject *mThis;
614    SLuint32 mNumFx;
615    effect_descriptor_t* mFxDescriptors;
616} IAndroidEffectCapabilities;
617
618typedef struct {
619    const struct SLAndroidEffectSendItf_ *mItf;
620    IObject *mThis;
621    // only one send per interface for now (1 bus)
622    SLboolean mEnabled;
623    SLmillibel mSendLevel; //android::KeyedVector<SLuint32, SLmillibel> mSendLevels;
624} IAndroidEffectSend;
625
626typedef struct {
627    const struct SLAndroidConfigurationItf_ *mItf;
628    IObject *mThis;
629} IAndroidConfiguration;
630
631typedef struct {
632    const struct SLAndroidBufferQueueItf_ *mItf;
633    IObject *mThis;
634    slAndroidBufferQueueCallback mCallback;
635    void *mContext;
636} IAndroidBufferQueue;
637
638#endif
639