classes.h revision 6e7e174807fc639c49125ced8962aa369370fbf0
1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifdef ANDROID
18#include "android/AudioTrackProxy.h"
19#include "android/CallbackProtector.h"
20#include "android/android_Effect.h"
21#include "android/android_GenericPlayer.h"
22#endif
23
24// Class structures
25
26
27/*typedef*/ struct CAudioPlayer_struct {
28    IObject mObject;
29#ifdef ANDROID
30#define INTERFACES_AudioPlayer 30 // see MPH_to_AudioPlayer in MPH_to.c for list of interfaces
31#else
32#define INTERFACES_AudioPlayer 26 // see MPH_to_AudioPlayer in MPH_to.c for list of interfaces
33#endif
34    SLuint8 mInterfaceStates2[INTERFACES_AudioPlayer - INTERFACES_Default];
35    IDynamicInterfaceManagement mDynamicInterfaceManagement;
36    IPlay mPlay;
37    I3DDoppler m3DDoppler;
38    I3DGrouping m3DGrouping;
39    I3DLocation m3DLocation;
40    I3DSource m3DSource;
41    IBufferQueue mBufferQueue;
42    IEffectSend mEffectSend;
43    IMetadataExtraction mMetadataExtraction;
44    IMetadataTraversal mMetadataTraversal;
45    IPrefetchStatus mPrefetchStatus;
46    IRatePitch mRatePitch;
47    ISeek mSeek;
48    IVolume mVolume;
49    IMuteSolo mMuteSolo;
50#ifdef ANDROID
51    IAndroidEffect mAndroidEffect;
52    IAndroidEffectSend mAndroidEffectSend;
53    IAndroidConfiguration mAndroidConfiguration;
54    IAndroidBufferQueue mAndroidBufferQueue;
55#endif
56    // optional interfaces
57    I3DMacroscopic m3DMacroscopic;
58    IBassBoost mBassBoost;
59    IDynamicSource mDynamicSource;
60    IEnvironmentalReverb mEnvironmentalReverb;
61    IEqualizer mEqualizer;
62    IPitch mPitch;
63    IPresetReverb mPresetReverb;
64    IPlaybackRate mPlaybackRate;
65    IVirtualizer mVirtualizer;
66    IVisualization mVisualization;
67    // fields below are per-instance private fields not associated with an interface
68    DataLocatorFormat mDataSource;
69    DataLocatorFormat mDataSink;
70    // cached data for this instance
71    SLuint8 /*SLboolean*/ mMute;
72    // Formerly at IMuteSolo
73    SLuint8 mMuteMask;      // Mask for which channels are muted: bit 0=left, 1=right
74    SLuint8 mSoloMask;      // Mask for which channels are soloed: bit 0=left, 1=right
75    SLuint8 mNumChannels;   // initially UNKNOWN_NUMCHANNELS, then const once it is known,
76                            // range 1 <= x <= 8
77    SLuint32 mSampleRateMilliHz;// initially UNKNOWN_SAMPLERATE, then const once it is known
78    // Formerly at IEffectSend
79    /**
80     * Dry volume modified by effect send interfaces: SLEffectSendItf and SLAndroidEffectSendItf
81     */
82    SLmillibel mDirectLevel;
83    // implementation-specific data for this instance
84#ifdef USE_OUTPUTMIXEXT
85    Track *mTrack;
86    float mGains[STEREO_CHANNELS];  ///< Computed gain based on volume, mute, solo, stereo position
87    SLboolean mDestroyRequested;    ///< Mixer to acknowledge application's call to Object::Destroy
88#endif
89#ifdef USE_SNDFILE
90    struct SndFile mSndFile;
91#endif // USE_SNDFILE
92#ifdef ANDROID
93    android::Mutex          *mpLock;
94    enum AndroidObjectType mAndroidObjType;
95    /** identifies the initialization and preparation state */
96    enum AndroidObjectState mAndroidObjState;
97    /** identifies which group of effects ("session") this player belongs to */
98    int mSessionId;
99    /** identifies the Android stream type playback will occur on */
100    int mStreamType;
101    // FIXME consolidate the next several variables into one class to avoid placement new
102    /** plays the PCM data for this player */
103    android::sp<android::AudioTrackProxy> mAudioTrack;
104    android::sp<android::CallbackProtector> mCallbackProtector;
105    android::sp<android::GenericPlayer> mAPlayer;
106    /** aux effect the AudioTrack will be attached to if aux send enabled */
107    android::sp<android::AudioEffect> mAuxEffect;
108    // FIXME all levels below need to be encapsulated in a field of type AndroidAudioLevels
109    /** send level to aux effect, there's a single aux bus, so there's a single level */
110    SLmillibel mAuxSendLevel;
111    /**
112     * Amplification (can be attenuation) factor derived for the VolumeLevel
113     */
114    float mAmplFromVolLevel;
115    /**
116     * Left/right amplification (can be attenuations) factors derived for the StereoPosition
117     */
118    float mAmplFromStereoPos[STEREO_CHANNELS];
119    /**
120     * Attenuation factor derived from direct level
121     */
122    float mAmplFromDirectLevel;
123    /** whether to call AudioTrack::start() at the next safe opportunity */
124    bool mDeferredStart;
125#endif
126} /*CAudioPlayer*/;
127
128
129/*typedef*/ struct CAudioRecorder_struct {
130    // mandated interfaces
131    IObject mObject;
132#ifdef ANDROID
133#define INTERFACES_AudioRecorder 11 // see MPH_to_AudioRecorder in MPH_to.c for list of interfaces
134#else
135#define INTERFACES_AudioRecorder 9  // see MPH_to_AudioRecorder in MPH_to.c for list of interfaces
136#endif
137    SLuint8 mInterfaceStates2[INTERFACES_AudioRecorder - INTERFACES_Default];
138    IDynamicInterfaceManagement mDynamicInterfaceManagement;
139    IRecord mRecord;
140    IAudioEncoder mAudioEncoder;
141    // optional interfaces
142    IBassBoost mBassBoost;
143    IDynamicSource mDynamicSource;
144    IEqualizer mEqualizer;
145    IVisualization mVisualization;
146    IVolume mVolume;
147#ifdef ANDROID
148    IBufferQueue mBufferQueue;
149    IAndroidConfiguration mAndroidConfiguration;
150#endif
151    // remaining are per-instance private fields not associated with an interface
152    DataLocatorFormat mDataSource;
153    DataLocatorFormat mDataSink;
154    // cached data for this instance
155    SLuint8 mNumChannels;   // initially UNKNOWN_NUMCHANNELS, then const once it is known,
156                            // range 1 <= x <= 8
157    SLuint32 mSampleRateMilliHz;// initially UNKNOWN_SAMPLERATE, then const once it is known
158    // implementation-specific data for this instance
159#ifdef ANDROID
160    enum AndroidObjectType mAndroidObjType;
161    android::AudioRecord *mAudioRecord; //FIXME candidate to be encapsulated in a ARecorder subclass
162    int mRecordSource;                  //FIXME candidate to be encapsulated in a ARecorder subclass
163#endif
164} /*CAudioRecorder*/;
165
166
167/*typedef*/ struct CEngine_struct {
168    // mandated implicit interfaces
169    IObject mObject;
170#ifdef ANDROID
171#define INTERFACES_Engine 13 // see MPH_to_Engine in MPH_to.c for list of interfaces
172#else
173#define INTERFACES_Engine 12 // see MPH_to_Engine in MPH_to.c for list of interfaces
174#endif
175    SLuint8 mInterfaceStates2[INTERFACES_Engine - INTERFACES_Default];
176    IDynamicInterfaceManagement mDynamicInterfaceManagement;
177    IEngine mEngine;
178    IEngineCapabilities mEngineCapabilities;
179    IThreadSync mThreadSync;
180    // mandated explicit interfaces
181    IAudioIODeviceCapabilities mAudioIODeviceCapabilities;
182    IAudioDecoderCapabilities mAudioDecoderCapabilities;
183    IAudioEncoderCapabilities mAudioEncoderCapabilities;
184    I3DCommit m3DCommit;
185    // optional interfaces
186    IDeviceVolume mDeviceVolume;
187    // OpenMAX AL mandated implicit interfaces
188    IXAEngine mXAEngine;
189#ifdef ANDROID
190    IAndroidEffectCapabilities mAndroidEffectCapabilities;
191#endif
192    // OpenMAX AL explicit interfaces
193    IVideoDecoderCapabilities mVideoDecoderCapabilities;
194    // remaining are per-instance private fields not associated with an interface
195    ThreadPool mThreadPool; // for asynchronous operations
196    pthread_t mSyncThread;
197#if defined(ANDROID)
198    // FIXME number of presets will only be saved in IEqualizer, preset names will not be stored
199    SLuint32 mEqNumPresets;
200    char** mEqPresetNames;
201#endif
202} /*CEngine*/;
203
204typedef struct {
205    // mandated interfaces
206    IObject mObject;
207#define INTERFACES_LEDDevice 3 // see MPH_to_LEDDevice in MPH_to.c for list of interfaces
208    SLuint8 mInterfaceStates2[INTERFACES_LEDDevice - INTERFACES_Default];
209    IDynamicInterfaceManagement mDynamicInterfaceManagement;
210    ILEDArray mLEDArray;
211    // remaining are per-instance private fields not associated with an interface
212    SLuint32 mDeviceID;
213} CLEDDevice;
214
215typedef struct {
216    // mandated interfaces
217    IObject mObject;
218#define INTERFACES_Listener 4 // see MPH_to_Listener in MPH_to.c for list of interfaces
219    SLuint8 mInterfaceStates2[INTERFACES_Listener - INTERFACES_Default];
220    IDynamicInterfaceManagement mDynamicInterfaceManagement;
221    I3DDoppler m3DDoppler;
222    I3DLocation m3DLocation;
223    // remaining are per-instance private fields not associated with an interface
224} CListener;
225
226typedef struct {
227    // mandated interfaces
228    IObject mObject;
229#define INTERFACES_MetadataExtractor 5 // see MPH_to_MetadataExtractor in MPH_to.c for list of
230                                       // interfaces
231    SLuint8 mInterfaceStates2[INTERFACES_MetadataExtractor - INTERFACES_Default];
232    IDynamicInterfaceManagement mDynamicInterfaceManagement;
233    IDynamicSource mDynamicSource;
234    IMetadataExtraction mMetadataExtraction;
235    IMetadataTraversal mMetadataTraversal;
236    // remaining are per-instance private fields not associated with an interface
237} CMetadataExtractor;
238
239typedef struct {
240    // mandated interfaces
241    IObject mObject;
242
243#define INTERFACES_MidiPlayer 29 // see MPH_to_MidiPlayer in MPH_to.c for list of interfaces
244    SLuint8 mInterfaceStates2[INTERFACES_MidiPlayer - INTERFACES_Default];
245    IDynamicInterfaceManagement mDynamicInterfaceManagement;
246    IPlay mPlay;
247    I3DDoppler m3DDoppler;
248    I3DGrouping m3DGrouping;
249    I3DLocation m3DLocation;
250    I3DSource m3DSource;
251    IBufferQueue mBufferQueue;
252    IEffectSend mEffectSend;
253    IMetadataExtraction mMetadataExtraction;
254    IMetadataTraversal mMetadataTraversal;
255    IMIDIMessage mMIDIMessage;
256    IMIDITime mMIDITime;
257    IMIDITempo mMIDITempo;
258    IMIDIMuteSolo mMIDIMuteSolo;
259    IPrefetchStatus mPrefetchStatus;
260    ISeek mSeek;
261    IVolume mVolume;
262    IMuteSolo mMuteSolo;
263    // optional interfaces
264    I3DMacroscopic m3DMacroscopic;
265    IBassBoost mBassBoost;
266    IDynamicSource mDynamicSource;
267    IEnvironmentalReverb mEnvironmentalReverb;
268    IEqualizer mEqualizer;
269    IPitch mPitch;
270    IPresetReverb mPresetReverb;
271    IPlaybackRate mPlaybackRate;
272    IVirtualizer mVirtualizer;
273    IVisualization mVisualization;
274    // remaining are per-instance private fields not associated with an interface
275} CMidiPlayer;
276
277/*typedef*/ struct COutputMix_struct {
278    // mandated interfaces
279    IObject mObject;
280#ifdef ANDROID
281#define INTERFACES_OutputMix 12 // see MPH_to_OutputMix in MPH_to.c for list of interfaces
282#else
283#define INTERFACES_OutputMix 11 // see MPH_to_OutputMix in MPH_to.c for list of interfaces
284#endif
285    SLuint8 mInterfaceStates2[INTERFACES_OutputMix - INTERFACES_Default];
286    IDynamicInterfaceManagement mDynamicInterfaceManagement;
287    IOutputMix mOutputMix;
288#ifdef USE_OUTPUTMIXEXT
289    IOutputMixExt mOutputMixExt;
290#endif
291    IEnvironmentalReverb mEnvironmentalReverb;
292    IEqualizer mEqualizer;
293    IPresetReverb mPresetReverb;
294    IVirtualizer mVirtualizer;
295    IVolume mVolume;
296    // optional interfaces
297    IBassBoost mBassBoost;
298    IVisualization mVisualization;
299#ifdef ANDROID
300    IAndroidEffect mAndroidEffect;
301#endif
302    // remaining are per-instance private fields not associated with an interface
303} /*COutputMix*/;
304
305typedef struct {
306    // mandated interfaces
307    IObject mObject;
308#define INTERFACES_VibraDevice 3 // see MPH_to_VibraDevice in MPH_to.c for list of interfaces
309    SLuint8 mInterfaceStates2[INTERFACES_VibraDevice - INTERFACES_Default];
310    IDynamicInterfaceManagement mDynamicInterfaceManagement;
311    IVibra mVibra;
312    // remaining are per-instance private fields not associated with an interface
313    SLuint32 mDeviceID;
314} CVibraDevice;
315
316
317typedef struct CMediaPlayer_struct {
318    IObject mObject;
319#ifdef ANDROID
320#define INTERFACES_MediaPlayer 7
321#else
322#define INTERFACES_MediaPlayer 6
323#endif
324    XAuint8 mInterfaceStates2[INTERFACES_MediaPlayer - INTERFACES_Default];
325    IDynamicInterfaceManagement mDynamicInterfaceManagement;
326    IDynamicSource mDynamicSource;
327    IPlay mPlay;
328    IStreamInformation mStreamInfo;
329    IVolume mVolume;
330    ISeek mSeek;
331#ifdef ANDROID
332    IAndroidBufferQueue mAndroidBufferQueue;
333#endif
334    // fields below are per-instance private fields not associated with an interface
335    DataLocatorFormat mDataSource;
336    DataLocatorFormat mBankSource;
337    DataLocatorFormat mAudioSink;
338    DataLocatorFormat mImageVideoSink;
339    DataLocatorFormat mVibraSink;
340    DataLocatorFormat mLEDArraySink;
341    /**
342     * Dry volume modified by effect send interfaces: SLEffectSendItf and SLAndroidEffectSendItf
343     */
344    SLmillibel mDirectLevel;
345#ifdef ANDROID
346    android::sp<android::GenericPlayer> mAVPlayer;
347    enum AndroidObjectType mAndroidObjType;
348    /** identifies the initialization and preparation state */
349    enum AndroidObjectState mAndroidObjState;
350    /** identifies which group of effects ("session") this player belongs to */
351    int mSessionId;
352    /** identifies the Android stream type playback will occur on */
353    int mStreamType;
354#endif
355} CMediaPlayer;
356