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
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27#include "OpenSLES.h"
28
29/*---------------------------------------------------------------------------*/
30/* Android common types                                                      */
31/*---------------------------------------------------------------------------*/
32
33typedef sl_int64_t             SLAint64;          /* 64 bit signed integer   */
34
35typedef 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
48typedef 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/*---------------------------------------------------------------------------*/
60/* Android Effect interface                                                  */
61/*---------------------------------------------------------------------------*/
62
63extern SL_API const SLInterfaceID SL_IID_ANDROIDEFFECT;
64
65/** Android Effect interface methods */
66
67struct SLAndroidEffectItf_;
68typedef const struct SLAndroidEffectItf_ * const * SLAndroidEffectItf;
69
70struct SLAndroidEffectItf_ {
71
72    SLresult (*CreateEffect) (SLAndroidEffectItf self,
73            SLInterfaceID effectImplementationId);
74
75    SLresult (*ReleaseEffect) (SLAndroidEffectItf self,
76            SLInterfaceID effectImplementationId);
77
78    SLresult (*SetEnabled) (SLAndroidEffectItf self,
79            SLInterfaceID effectImplementationId,
80            SLboolean enabled);
81
82    SLresult (*IsEnabled) (SLAndroidEffectItf self,
83            SLInterfaceID effectImplementationId,
84            SLboolean *pEnabled);
85
86    SLresult (*SendCommand) (SLAndroidEffectItf self,
87            SLInterfaceID effectImplementationId,
88            SLuint32 command,
89            SLuint32 commandSize,
90            void *pCommandData,
91            SLuint32 *replySize,
92            void *pReplyData);
93};
94
95
96/*---------------------------------------------------------------------------*/
97/* Android Effect Send interface                                             */
98/*---------------------------------------------------------------------------*/
99
100extern SL_API const SLInterfaceID SL_IID_ANDROIDEFFECTSEND;
101
102/** Android Effect Send interface methods */
103
104struct SLAndroidEffectSendItf_;
105typedef const struct SLAndroidEffectSendItf_ * const * SLAndroidEffectSendItf;
106
107struct SLAndroidEffectSendItf_ {
108    SLresult (*EnableEffectSend) (
109        SLAndroidEffectSendItf self,
110        SLInterfaceID effectImplementationId,
111        SLboolean enable,
112        SLmillibel initialLevel
113    );
114    SLresult (*IsEnabled) (
115        SLAndroidEffectSendItf self,
116        SLInterfaceID effectImplementationId,
117        SLboolean *pEnable
118    );
119    SLresult (*SetDirectLevel) (
120        SLAndroidEffectSendItf self,
121        SLmillibel directLevel
122    );
123    SLresult (*GetDirectLevel) (
124        SLAndroidEffectSendItf self,
125        SLmillibel *pDirectLevel
126    );
127    SLresult (*SetSendLevel) (
128        SLAndroidEffectSendItf self,
129        SLInterfaceID effectImplementationId,
130        SLmillibel sendLevel
131    );
132    SLresult (*GetSendLevel)(
133        SLAndroidEffectSendItf self,
134        SLInterfaceID effectImplementationId,
135        SLmillibel *pSendLevel
136    );
137};
138
139
140/*---------------------------------------------------------------------------*/
141/* Android Effect Capabilities interface                                     */
142/*---------------------------------------------------------------------------*/
143
144extern SL_API const SLInterfaceID SL_IID_ANDROIDEFFECTCAPABILITIES;
145
146/** Android Effect Capabilities interface methods */
147
148struct SLAndroidEffectCapabilitiesItf_;
149typedef const struct SLAndroidEffectCapabilitiesItf_ * const * SLAndroidEffectCapabilitiesItf;
150
151struct SLAndroidEffectCapabilitiesItf_ {
152
153    SLresult (*QueryNumEffects) (SLAndroidEffectCapabilitiesItf self,
154            SLuint32 *pNumSupportedEffects);
155
156
157    SLresult (*QueryEffect) (SLAndroidEffectCapabilitiesItf self,
158            SLuint32 index,
159            SLInterfaceID *pEffectType,
160            SLInterfaceID *pEffectImplementation,
161            SLchar *pName,
162            SLuint16 *pNameSize);
163};
164
165
166/*---------------------------------------------------------------------------*/
167/* Android Configuration interface                                           */
168/*---------------------------------------------------------------------------*/
169extern SL_API const SLInterfaceID SL_IID_ANDROIDCONFIGURATION;
170
171/** Android Configuration interface methods */
172
173struct SLAndroidConfigurationItf_;
174typedef const struct SLAndroidConfigurationItf_ * const * SLAndroidConfigurationItf;
175
176struct SLAndroidConfigurationItf_ {
177
178    SLresult (*SetConfiguration) (SLAndroidConfigurationItf self,
179            const SLchar *configKey,
180            const void *pConfigValue,
181            SLuint32 valueSize);
182
183    SLresult (*GetConfiguration) (SLAndroidConfigurationItf self,
184           const SLchar *configKey,
185           SLuint32 *pValueSize,
186           void *pConfigValue
187       );
188};
189
190
191/*---------------------------------------------------------------------------*/
192/* Android Simple Buffer Queue Interface                                     */
193/*---------------------------------------------------------------------------*/
194
195extern SL_API const SLInterfaceID SL_IID_ANDROIDSIMPLEBUFFERQUEUE;
196
197struct SLAndroidSimpleBufferQueueItf_;
198typedef const struct SLAndroidSimpleBufferQueueItf_ * const * SLAndroidSimpleBufferQueueItf;
199
200typedef void (SLAPIENTRY *slAndroidSimpleBufferQueueCallback)(
201	SLAndroidSimpleBufferQueueItf caller,
202	void *pContext
203);
204
205/** Android simple buffer queue state **/
206
207typedef struct SLAndroidSimpleBufferQueueState_ {
208	SLuint32	count;
209	SLuint32	index;
210} SLAndroidSimpleBufferQueueState;
211
212
213struct SLAndroidSimpleBufferQueueItf_ {
214	SLresult (*Enqueue) (
215		SLAndroidSimpleBufferQueueItf self,
216		const void *pBuffer,
217		SLuint32 size
218	);
219	SLresult (*Clear) (
220		SLAndroidSimpleBufferQueueItf self
221	);
222	SLresult (*GetState) (
223		SLAndroidSimpleBufferQueueItf self,
224		SLAndroidSimpleBufferQueueState *pState
225	);
226	SLresult (*RegisterCallback) (
227		SLAndroidSimpleBufferQueueItf self,
228		slAndroidSimpleBufferQueueCallback callback,
229		void* pContext
230	);
231};
232
233
234/*---------------------------------------------------------------------------*/
235/* Android Buffer Queue Interface                                            */
236/*---------------------------------------------------------------------------*/
237
238extern SL_API const SLInterfaceID SL_IID_ANDROIDBUFFERQUEUESOURCE;
239
240struct SLAndroidBufferQueueItf_;
241typedef const struct SLAndroidBufferQueueItf_ * const * SLAndroidBufferQueueItf;
242
243#define SL_ANDROID_ITEMKEY_NONE             ((SLuint32) 0x00000000)
244#define SL_ANDROID_ITEMKEY_EOS              ((SLuint32) 0x00000001)
245#define SL_ANDROID_ITEMKEY_DISCONTINUITY    ((SLuint32) 0x00000002)
246#define SL_ANDROID_ITEMKEY_BUFFERQUEUEEVENT ((SLuint32) 0x00000003)
247#define SL_ANDROID_ITEMKEY_FORMAT_CHANGE    ((SLuint32) 0x00000004)
248
249#define SL_ANDROIDBUFFERQUEUEEVENT_NONE        ((SLuint32) 0x00000000)
250#define SL_ANDROIDBUFFERQUEUEEVENT_PROCESSED   ((SLuint32) 0x00000001)
251#if 0   // reserved for future use
252#define SL_ANDROIDBUFFERQUEUEEVENT_UNREALIZED  ((SLuint32) 0x00000002)
253#define SL_ANDROIDBUFFERQUEUEEVENT_CLEARED     ((SLuint32) 0x00000004)
254#define SL_ANDROIDBUFFERQUEUEEVENT_STOPPED     ((SLuint32) 0x00000008)
255#define SL_ANDROIDBUFFERQUEUEEVENT_ERROR       ((SLuint32) 0x00000010)
256#define SL_ANDROIDBUFFERQUEUEEVENT_CONTENT_END ((SLuint32) 0x00000020)
257#endif
258
259typedef struct SLAndroidBufferItem_ {
260    SLuint32 itemKey;  // identifies the item
261    SLuint32 itemSize;
262    SLuint8  itemData[0];
263} SLAndroidBufferItem;
264
265typedef SLresult (SLAPIENTRY *slAndroidBufferQueueCallback)(
266    SLAndroidBufferQueueItf caller,/* input */
267    void *pCallbackContext,        /* input */
268    void *pBufferContext,          /* input */
269    void *pBufferData,             /* input */
270    SLuint32 dataSize,             /* input */
271    SLuint32 dataUsed,             /* input */
272    const SLAndroidBufferItem *pItems,/* input */
273    SLuint32 itemsLength           /* input */
274);
275
276typedef struct SLAndroidBufferQueueState_ {
277    SLuint32    count;
278    SLuint32    index;
279} SLAndroidBufferQueueState;
280
281struct SLAndroidBufferQueueItf_ {
282    SLresult (*RegisterCallback) (
283        SLAndroidBufferQueueItf self,
284        slAndroidBufferQueueCallback callback,
285        void* pCallbackContext
286    );
287
288    SLresult (*Clear) (
289        SLAndroidBufferQueueItf self
290    );
291
292    SLresult (*Enqueue) (
293        SLAndroidBufferQueueItf self,
294        void *pBufferContext,
295        void *pData,
296        SLuint32 dataLength,
297        const SLAndroidBufferItem *pItems,
298        SLuint32 itemsLength
299    );
300
301    SLresult (*GetState) (
302        SLAndroidBufferQueueItf self,
303        SLAndroidBufferQueueState *pState
304    );
305
306    SLresult (*SetCallbackEventsMask) (
307            SLAndroidBufferQueueItf self,
308            SLuint32 eventFlags
309    );
310
311    SLresult (*GetCallbackEventsMask) (
312            SLAndroidBufferQueueItf self,
313            SLuint32 *pEventFlags
314    );
315};
316
317
318/*---------------------------------------------------------------------------*/
319/* Android File Descriptor Data Locator                                      */
320/*---------------------------------------------------------------------------*/
321
322/** Addendum to Data locator macros  */
323#define SL_DATALOCATOR_ANDROIDFD                ((SLuint32) 0x800007BC)
324
325#define SL_DATALOCATOR_ANDROIDFD_USE_FILE_SIZE ((SLAint64) 0xFFFFFFFFFFFFFFFFll)
326
327/** File Descriptor-based data locator definition, locatorType must be SL_DATALOCATOR_ANDROIDFD */
328typedef struct SLDataLocator_AndroidFD_ {
329    SLuint32        locatorType;
330    SLint32         fd;
331    SLAint64        offset;
332    SLAint64        length;
333} SLDataLocator_AndroidFD;
334
335
336/*---------------------------------------------------------------------------*/
337/* Android Android Simple Buffer Queue Data Locator                          */
338/*---------------------------------------------------------------------------*/
339
340/** Addendum to Data locator macros  */
341#define SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE ((SLuint32) 0x800007BD)
342
343/** BufferQueue-based data locator definition where locatorType must be SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE*/
344typedef struct SLDataLocator_AndroidSimpleBufferQueue {
345	SLuint32	locatorType;
346	SLuint32	numBuffers;
347} SLDataLocator_AndroidSimpleBufferQueue;
348
349
350/*---------------------------------------------------------------------------*/
351/* Android Buffer Queue Data Locator                                         */
352/*---------------------------------------------------------------------------*/
353
354/** Addendum to Data locator macros  */
355#define SL_DATALOCATOR_ANDROIDBUFFERQUEUE       ((SLuint32) 0x800007BE)
356
357/** Android Buffer Queue-based data locator definition,
358 *  locatorType must be SL_DATALOCATOR_ANDROIDBUFFERQUEUE */
359typedef struct SLDataLocator_AndroidBufferQueue_ {
360    SLuint32    locatorType;
361    SLuint32    numBuffers;
362} SLDataLocator_AndroidBufferQueue;
363
364/**
365 * MIME types required for data in Android Buffer Queues
366 */
367#define SL_ANDROID_MIME_AACADTS            ((SLchar *) "audio/vnd.android.aac-adts")
368
369#ifdef __cplusplus
370}
371#endif /* __cplusplus */
372
373#endif /* OPENSL_ES_ANDROID_H_ */
374