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