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