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