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