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