• 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 #ifndef OPENSL_ES_ANDROID_H_
18 #define OPENSL_ES_ANDROID_H_
19 
20 #include "OpenSLES_AndroidConfiguration.h"
21 #include "OpenSLES_AndroidMetadata.h"
22 #include <jni.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /*---------------------------------------------------------------------------*/
29 /* Android common types                                                      */
30 /*---------------------------------------------------------------------------*/
31 
32 typedef sl_int64_t             SLAint64;          /* 64 bit signed integer   */
33 
34 typedef sl_uint64_t            SLAuint64;         /* 64 bit unsigned integer */
35 
36 /*---------------------------------------------------------------------------*/
37 /* Android PCM Data Format                                                   */
38 /*---------------------------------------------------------------------------*/
39 
40 /* The following pcm representations and data formats map to those in OpenSLES 1.1 */
41 #define SL_ANDROID_PCM_REPRESENTATION_SIGNED_INT       ((SLuint32) 0x00000001)
42 #define SL_ANDROID_PCM_REPRESENTATION_UNSIGNED_INT     ((SLuint32) 0x00000002)
43 #define SL_ANDROID_PCM_REPRESENTATION_FLOAT            ((SLuint32) 0x00000003)
44 
45 #define SL_ANDROID_DATAFORMAT_PCM_EX    ((SLuint32) 0x00000004)
46 
47 typedef struct SLAndroidDataFormat_PCM_EX_ {
48     SLuint32         formatType;
49     SLuint32         numChannels;
50     SLuint32         sampleRate;
51     SLuint32         bitsPerSample;
52     SLuint32         containerSize;
53     SLuint32         channelMask;
54     SLuint32         endianness;
55     SLuint32         representation;
56 } SLAndroidDataFormat_PCM_EX;
57 
58 #define SL_ANDROID_SPEAKER_NON_POSITIONAL       ((SLuint32) 0x80000000)
59 
60 // Make an indexed channel mask from a bitfield.
61 //
62 // Each bit in the bitfield corresponds to a channel index,
63 // from least-significant bit (channel 0) up to the bit
64 // corresponding to the maximum channel count (currently FCC_8).
65 // A '1' in the bitfield indicates that the channel should be
66 // included in the stream, while a '0' indicates that it
67 // should be excluded. For instance, a bitfield of 0x0A (binary 00001010)
68 // would define a stream that contains channels 1 and 3. (The corresponding
69 // indexed mask, after setting the SL_ANDROID_NON_POSITIONAL bit,
70 // would be 0x8000000A.)
71 #define SL_ANDROID_MAKE_INDEXED_CHANNEL_MASK(bitfield) \
72         ((bitfield) | SL_ANDROID_SPEAKER_NON_POSITIONAL)
73 
74 // Specifying SL_ANDROID_SPEAKER_USE_DEFAULT as a channel mask in
75 // SLAndroidDataFormat_PCM_EX causes OpenSL ES to assign a default
76 // channel mask based on the number of channels requested. This
77 // value cannot be combined with SL_ANDROID_SPEAKER_NON_POSITIONAL.
78 #define SL_ANDROID_SPEAKER_USE_DEFAULT ((SLuint32)0)
79 
80 /*---------------------------------------------------------------------------*/
81 /* Android Effect interface                                                  */
82 /*---------------------------------------------------------------------------*/
83 
84 extern SL_API const SLInterfaceID SL_IID_ANDROIDEFFECT;
85 
86 /** Android Effect interface methods */
87 
88 struct SLAndroidEffectItf_;
89 typedef const struct SLAndroidEffectItf_ * const * SLAndroidEffectItf;
90 
91 struct SLAndroidEffectItf_ {
92 
93     SLresult (*CreateEffect) (SLAndroidEffectItf self,
94             SLInterfaceID effectImplementationId);
95 
96     SLresult (*ReleaseEffect) (SLAndroidEffectItf self,
97             SLInterfaceID effectImplementationId);
98 
99     SLresult (*SetEnabled) (SLAndroidEffectItf self,
100             SLInterfaceID effectImplementationId,
101             SLboolean enabled);
102 
103     SLresult (*IsEnabled) (SLAndroidEffectItf self,
104             SLInterfaceID effectImplementationId,
105             SLboolean *pEnabled);
106 
107     SLresult (*SendCommand) (SLAndroidEffectItf self,
108             SLInterfaceID effectImplementationId,
109             SLuint32 command,
110             SLuint32 commandSize,
111             void *pCommandData,
112             SLuint32 *replySize,
113             void *pReplyData);
114 };
115 
116 
117 /*---------------------------------------------------------------------------*/
118 /* Android Effect Send interface                                             */
119 /*---------------------------------------------------------------------------*/
120 
121 extern SL_API const SLInterfaceID SL_IID_ANDROIDEFFECTSEND;
122 
123 /** Android Effect Send interface methods */
124 
125 struct SLAndroidEffectSendItf_;
126 typedef const struct SLAndroidEffectSendItf_ * const * SLAndroidEffectSendItf;
127 
128 struct SLAndroidEffectSendItf_ {
129     SLresult (*EnableEffectSend) (
130         SLAndroidEffectSendItf self,
131         SLInterfaceID effectImplementationId,
132         SLboolean enable,
133         SLmillibel initialLevel
134     );
135     SLresult (*IsEnabled) (
136         SLAndroidEffectSendItf self,
137         SLInterfaceID effectImplementationId,
138         SLboolean *pEnable
139     );
140     SLresult (*SetDirectLevel) (
141         SLAndroidEffectSendItf self,
142         SLmillibel directLevel
143     );
144     SLresult (*GetDirectLevel) (
145         SLAndroidEffectSendItf self,
146         SLmillibel *pDirectLevel
147     );
148     SLresult (*SetSendLevel) (
149         SLAndroidEffectSendItf self,
150         SLInterfaceID effectImplementationId,
151         SLmillibel sendLevel
152     );
153     SLresult (*GetSendLevel)(
154         SLAndroidEffectSendItf self,
155         SLInterfaceID effectImplementationId,
156         SLmillibel *pSendLevel
157     );
158 };
159 
160 
161 /*---------------------------------------------------------------------------*/
162 /* Android Effect Capabilities interface                                     */
163 /*---------------------------------------------------------------------------*/
164 
165 extern SL_API const SLInterfaceID SL_IID_ANDROIDEFFECTCAPABILITIES;
166 
167 /** Android Effect Capabilities interface methods */
168 
169 struct SLAndroidEffectCapabilitiesItf_;
170 typedef const struct SLAndroidEffectCapabilitiesItf_ * const * SLAndroidEffectCapabilitiesItf;
171 
172 struct SLAndroidEffectCapabilitiesItf_ {
173 
174     SLresult (*QueryNumEffects) (SLAndroidEffectCapabilitiesItf self,
175             SLuint32 *pNumSupportedEffects);
176 
177 
178     SLresult (*QueryEffect) (SLAndroidEffectCapabilitiesItf self,
179             SLuint32 index,
180             SLInterfaceID *pEffectType,
181             SLInterfaceID *pEffectImplementation,
182             SLchar *pName,
183             SLuint16 *pNameSize);
184 };
185 
186 
187 /*---------------------------------------------------------------------------*/
188 /* Android Configuration interface                                           */
189 /*---------------------------------------------------------------------------*/
190 extern SL_API const SLInterfaceID SL_IID_ANDROIDCONFIGURATION;
191 
192 /** Android Configuration interface methods */
193 
194 struct SLAndroidConfigurationItf_;
195 typedef const struct SLAndroidConfigurationItf_ * const * SLAndroidConfigurationItf;
196 
197 /*
198  * Java Proxy Type IDs
199  */
200 #define SL_ANDROID_JAVA_PROXY_ROUTING   0x0001
201 
202 struct SLAndroidConfigurationItf_ {
203 
204     SLresult (*SetConfiguration) (SLAndroidConfigurationItf self,
205             const SLchar *configKey,
206             const void *pConfigValue,
207             SLuint32 valueSize);
208 
209     SLresult (*GetConfiguration) (SLAndroidConfigurationItf self,
210            const SLchar *configKey,
211            SLuint32 *pValueSize,
212            void *pConfigValue
213        );
214 
215     SLresult (*AcquireJavaProxy) (SLAndroidConfigurationItf self,
216             SLuint32 proxyType,
217             jobject *pProxyObj);
218 
219     SLresult (*ReleaseJavaProxy) (SLAndroidConfigurationItf self,
220             SLuint32 proxyType);
221 };
222 
223 
224 /*---------------------------------------------------------------------------*/
225 /* Android Simple Buffer Queue Interface                                     */
226 /*---------------------------------------------------------------------------*/
227 
228 extern SL_API const SLInterfaceID SL_IID_ANDROIDSIMPLEBUFFERQUEUE;
229 
230 struct SLAndroidSimpleBufferQueueItf_;
231 typedef const struct SLAndroidSimpleBufferQueueItf_ * const * SLAndroidSimpleBufferQueueItf;
232 
233 typedef void (SLAPIENTRY *slAndroidSimpleBufferQueueCallback)(
234 	SLAndroidSimpleBufferQueueItf caller,
235 	void *pContext
236 );
237 
238 /** Android simple buffer queue state **/
239 
240 typedef struct SLAndroidSimpleBufferQueueState_ {
241 	SLuint32	count;
242 	SLuint32	index;
243 } SLAndroidSimpleBufferQueueState;
244 
245 
246 struct SLAndroidSimpleBufferQueueItf_ {
247 	SLresult (*Enqueue) (
248 		SLAndroidSimpleBufferQueueItf self,
249 		const void *pBuffer,
250 		SLuint32 size
251 	);
252 	SLresult (*Clear) (
253 		SLAndroidSimpleBufferQueueItf self
254 	);
255 	SLresult (*GetState) (
256 		SLAndroidSimpleBufferQueueItf self,
257 		SLAndroidSimpleBufferQueueState *pState
258 	);
259 	SLresult (*RegisterCallback) (
260 		SLAndroidSimpleBufferQueueItf self,
261 		slAndroidSimpleBufferQueueCallback callback,
262 		void* pContext
263 	);
264 };
265 
266 
267 /*---------------------------------------------------------------------------*/
268 /* Android Buffer Queue Interface                                            */
269 /*---------------------------------------------------------------------------*/
270 
271 extern SL_API const SLInterfaceID SL_IID_ANDROIDBUFFERQUEUESOURCE;
272 
273 struct SLAndroidBufferQueueItf_;
274 typedef const struct SLAndroidBufferQueueItf_ * const * SLAndroidBufferQueueItf;
275 
276 #define SL_ANDROID_ITEMKEY_NONE             ((SLuint32) 0x00000000)
277 #define SL_ANDROID_ITEMKEY_EOS              ((SLuint32) 0x00000001)
278 #define SL_ANDROID_ITEMKEY_DISCONTINUITY    ((SLuint32) 0x00000002)
279 #define SL_ANDROID_ITEMKEY_BUFFERQUEUEEVENT ((SLuint32) 0x00000003)
280 #define SL_ANDROID_ITEMKEY_FORMAT_CHANGE    ((SLuint32) 0x00000004)
281 
282 #define SL_ANDROIDBUFFERQUEUEEVENT_NONE        ((SLuint32) 0x00000000)
283 #define SL_ANDROIDBUFFERQUEUEEVENT_PROCESSED   ((SLuint32) 0x00000001)
284 #if 0   // reserved for future use
285 #define SL_ANDROIDBUFFERQUEUEEVENT_UNREALIZED  ((SLuint32) 0x00000002)
286 #define SL_ANDROIDBUFFERQUEUEEVENT_CLEARED     ((SLuint32) 0x00000004)
287 #define SL_ANDROIDBUFFERQUEUEEVENT_STOPPED     ((SLuint32) 0x00000008)
288 #define SL_ANDROIDBUFFERQUEUEEVENT_ERROR       ((SLuint32) 0x00000010)
289 #define SL_ANDROIDBUFFERQUEUEEVENT_CONTENT_END ((SLuint32) 0x00000020)
290 #endif
291 
292 typedef struct SLAndroidBufferItem_ {
293     SLuint32 itemKey;  // identifies the item
294     SLuint32 itemSize;
295     SLuint8  itemData[0];
296 } SLAndroidBufferItem;
297 
298 typedef SLresult (SLAPIENTRY *slAndroidBufferQueueCallback)(
299     SLAndroidBufferQueueItf caller,/* input */
300     void *pCallbackContext,        /* input */
301     void *pBufferContext,          /* input */
302     void *pBufferData,             /* input */
303     SLuint32 dataSize,             /* input */
304     SLuint32 dataUsed,             /* input */
305     const SLAndroidBufferItem *pItems,/* input */
306     SLuint32 itemsLength           /* input */
307 );
308 
309 typedef struct SLAndroidBufferQueueState_ {
310     SLuint32    count;
311     SLuint32    index;
312 } SLAndroidBufferQueueState;
313 
314 struct SLAndroidBufferQueueItf_ {
315     SLresult (*RegisterCallback) (
316         SLAndroidBufferQueueItf self,
317         slAndroidBufferQueueCallback callback,
318         void* pCallbackContext
319     );
320 
321     SLresult (*Clear) (
322         SLAndroidBufferQueueItf self
323     );
324 
325     SLresult (*Enqueue) (
326         SLAndroidBufferQueueItf self,
327         void *pBufferContext,
328         void *pData,
329         SLuint32 dataLength,
330         const SLAndroidBufferItem *pItems,
331         SLuint32 itemsLength
332     );
333 
334     SLresult (*GetState) (
335         SLAndroidBufferQueueItf self,
336         SLAndroidBufferQueueState *pState
337     );
338 
339     SLresult (*SetCallbackEventsMask) (
340             SLAndroidBufferQueueItf self,
341             SLuint32 eventFlags
342     );
343 
344     SLresult (*GetCallbackEventsMask) (
345             SLAndroidBufferQueueItf self,
346             SLuint32 *pEventFlags
347     );
348 };
349 
350 
351 /*---------------------------------------------------------------------------*/
352 /* Android File Descriptor Data Locator                                      */
353 /*---------------------------------------------------------------------------*/
354 
355 /** Addendum to Data locator macros  */
356 #define SL_DATALOCATOR_ANDROIDFD                ((SLuint32) 0x800007BC)
357 
358 #define SL_DATALOCATOR_ANDROIDFD_USE_FILE_SIZE ((SLAint64) 0xFFFFFFFFFFFFFFFFll)
359 
360 /** File Descriptor-based data locator definition, locatorType must be SL_DATALOCATOR_ANDROIDFD */
361 typedef struct SLDataLocator_AndroidFD_ {
362     SLuint32        locatorType;
363     SLint32         fd;
364     SLAint64        offset;
365     SLAint64        length;
366 } SLDataLocator_AndroidFD;
367 
368 
369 /*---------------------------------------------------------------------------*/
370 /* Android Android Simple Buffer Queue Data Locator                          */
371 /*---------------------------------------------------------------------------*/
372 
373 /** Addendum to Data locator macros  */
374 #define SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE ((SLuint32) 0x800007BD)
375 
376 /** BufferQueue-based data locator definition where locatorType must be SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE*/
377 typedef struct SLDataLocator_AndroidSimpleBufferQueue {
378 	SLuint32	locatorType;
379 	SLuint32	numBuffers;
380 } SLDataLocator_AndroidSimpleBufferQueue;
381 
382 
383 /*---------------------------------------------------------------------------*/
384 /* Android Buffer Queue Data Locator                                         */
385 /*---------------------------------------------------------------------------*/
386 
387 /** Addendum to Data locator macros  */
388 #define SL_DATALOCATOR_ANDROIDBUFFERQUEUE       ((SLuint32) 0x800007BE)
389 
390 /** Android Buffer Queue-based data locator definition,
391  *  locatorType must be SL_DATALOCATOR_ANDROIDBUFFERQUEUE */
392 typedef struct SLDataLocator_AndroidBufferQueue_ {
393     SLuint32    locatorType;
394     SLuint32    numBuffers;
395 } SLDataLocator_AndroidBufferQueue;
396 
397 /**
398  * MIME types required for data in Android Buffer Queues
399  */
400 #define SL_ANDROID_MIME_AACADTS            ((SLchar *) "audio/vnd.android.aac-adts")
401 
402 /*---------------------------------------------------------------------------*/
403 /* Acoustic Echo Cancellation (AEC) Interface                                */
404 /* --------------------------------------------------------------------------*/
405 extern SL_API const SLInterfaceID SL_IID_ANDROIDACOUSTICECHOCANCELLATION;
406 
407 struct SLAndroidAcousticEchoCancellationItf_;
408 typedef const struct SLAndroidAcousticEchoCancellationItf_ * const *
409         SLAndroidAcousticEchoCancellationItf;
410 
411 struct SLAndroidAcousticEchoCancellationItf_ {
412     SLresult (*SetEnabled)(
413         SLAndroidAcousticEchoCancellationItf self,
414         SLboolean enabled
415     );
416     SLresult (*IsEnabled)(
417         SLAndroidAcousticEchoCancellationItf self,
418         SLboolean *pEnabled
419     );
420 };
421 
422 /*---------------------------------------------------------------------------*/
423 /* Automatic Gain Control (ACC) Interface                                    */
424 /* --------------------------------------------------------------------------*/
425 extern SL_API const SLInterfaceID SL_IID_ANDROIDAUTOMATICGAINCONTROL;
426 
427 struct SLAndroidAutomaticGainControlItf_;
428 typedef const struct SLAndroidAutomaticGainControlItf_ * const * SLAndroidAutomaticGainControlItf;
429 
430 struct SLAndroidAutomaticGainControlItf_ {
431     SLresult (*SetEnabled)(
432         SLAndroidAutomaticGainControlItf self,
433         SLboolean enabled
434     );
435     SLresult (*IsEnabled)(
436         SLAndroidAutomaticGainControlItf self,
437         SLboolean *pEnabled
438     );
439 };
440 
441 /*---------------------------------------------------------------------------*/
442 /* Noise Suppression Interface                                               */
443 /* --------------------------------------------------------------------------*/
444 extern SL_API const SLInterfaceID SL_IID_ANDROIDNOISESUPPRESSION;
445 
446 struct SLAndroidNoiseSuppressionItf_;
447 typedef const struct SLAndroidNoiseSuppressionItf_ * const * SLAndroidNoiseSuppressionItf;
448 
449 struct SLAndroidNoiseSuppressionItf_ {
450     SLresult (*SetEnabled)(
451         SLAndroidNoiseSuppressionItf self,
452         SLboolean enabled
453     );
454     SLresult (*IsEnabled)(
455         SLAndroidNoiseSuppressionItf self,
456         SLboolean *pEnabled
457     );
458 };
459 
460 #ifdef __cplusplus
461 }
462 #endif /* __cplusplus */
463 
464 #endif /* OPENSL_ES_ANDROID_H_ */
465