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 /** \file OpenSLESUT.c OpenSL ES Utility Toolkit */
18 
19 #include <SLES/OpenSLES.h>
20 #include <OMXAL/OpenMAXAL.h>
21 #ifdef ANDROID
22 #include <SLES/OpenSLES_Android.h>
23 #include <OMXAL/OpenMAXAL_Android.h>
24 #endif
25 #include "OpenSLESUT.h"
26 #include <stdio.h>
27 #include <string.h>
28 
29 
30 /** \brief Maps an interface ID to its display name */
31 
32 typedef struct
33 {
34     const SLInterfaceID *iid;   ///< The interface ID
35     const char *name;           ///< The display name
36 } Pair;
37 
38 // ## is token concatenation e.g. a##b becomes ab
39 // # is stringize operator to convert a symbol to a string constant e.g. #a becomes "a"
40 
41 #define _(x) { &SL_IID_##x, "SL_IID_" #x }
42 #define _X(x) { (const SLInterfaceID *) &XA_IID_##x, "XA_IID_" #x }
43 
44 /** \brief Array of mappings from interface IDs to display names */
45 
46 static Pair pairs[] = {
47     _(3DCOMMIT),
48     _(3DDOPPLER),
49     _(3DGROUPING),
50     _(3DLOCATION),
51     _(3DMACROSCOPIC),
52     _(3DSOURCE),
53     _(AUDIODECODERCAPABILITIES),
54     _(AUDIOENCODER),
55     _(AUDIOENCODERCAPABILITIES),
56     _(AUDIOIODEVICECAPABILITIES),
57     _(BASSBOOST),
58     _(BUFFERQUEUE),
59     _(DEVICEVOLUME),
60     _(DYNAMICINTERFACEMANAGEMENT),
61     _(DYNAMICSOURCE),
62     _(EFFECTSEND),
63     _(ENGINE),
64     _(ENGINECAPABILITIES),
65     _(ENVIRONMENTALREVERB),
66     _(EQUALIZER),
67     _(LED),
68     _(METADATAEXTRACTION),
69     _(METADATATRAVERSAL),
70     _(MIDIMESSAGE),
71     _(MIDIMUTESOLO),
72     _(MIDITEMPO),
73     _(MIDITIME),
74     _(MUTESOLO),
75     _(NULL),
76     _(OBJECT),
77     _(OUTPUTMIX),
78     _(PITCH),
79     _(PLAY),
80     _(PLAYBACKRATE),
81     _(PREFETCHSTATUS),
82     _(PRESETREVERB),
83     _(RATEPITCH),
84     _(RECORD),
85     _(SEEK),
86     _(THREADSYNC),
87     _(VIBRA),
88     _(VIRTUALIZER),
89     _(VISUALIZATION),
90     _(VOLUME),
91 #if 0 // ifdef USE_OUTPUTMIXEXT
92     _(OUTPUTMIXEXT),
93 #endif
94     _X(ENGINE),
95     _X(VIDEODECODERCAPABILITIES),
96 #ifdef ANDROID
97     _(ANDROIDEFFECT),
98     _(ANDROIDEFFECTCAPABILITIES),
99     _(ANDROIDEFFECTSEND),
100     _(ANDROIDCONFIGURATION),
101     _(ANDROIDSIMPLEBUFFERQUEUE),
102     _(ANDROIDBUFFERQUEUESOURCE),
103     _(ANDROIDACOUSTICECHOCANCELLATION),
104     _(ANDROIDAUTOMATICGAINCONTROL),
105     _(ANDROIDNOISESUPPRESSION)
106 #endif
107 };
108 
109 
110 /** \brief Print an interface ID in human-readable format */
111 
slesutPrintIID(SLInterfaceID iid)112 void slesutPrintIID(SLInterfaceID iid)
113 {
114     Pair *p;
115     const Pair *end = &pairs[sizeof(pairs)/sizeof(pairs[0])];
116     for (p = pairs; p != end; ++p) {
117         if (!memcmp(*p->iid, iid, sizeof(struct SLInterfaceID_))) {
118             printf("SL_IID_%s = ", p->name);
119             break;
120         }
121     }
122     printf(
123         "{ 0x%08X, 0x%04X, 0x%04X, 0x%04X, { 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X } }\n",
124         (unsigned) iid->time_low, iid->time_mid, iid->time_hi_and_version, iid->clock_seq,
125         iid->node[0], iid->node[1], iid->node[2], iid->node[3], iid->node[4], iid->node[5]);
126 }
127 
128 
129 /** \brief Print an array of interface IDs in human-readable format,
130  *  including whether they are required or optional
131  */
132 
slesutPrintIIDs(SLInterfaceID * pInterfaceIds,SLboolean * pInterfaceRequired,unsigned numInterfaces)133 void slesutPrintIIDs(SLInterfaceID *pInterfaceIds, SLboolean *pInterfaceRequired,
134     unsigned numInterfaces)
135 {
136     unsigned i;
137     for (i = 0; i < numInterfaces; ++i) {
138         printf("interfaces[%u]=", i);
139         slesutPrintIID(pInterfaceIds[i]);
140         printf(" %s\n", (unsigned) pInterfaceRequired[i] ? "required" : "optional");
141     }
142 }
143 
144 
145 /** \brief Convert an object ID to a string or NULL. */
146 
slesutObjectIDToString(SLuint32 objectID)147 const char *slesutObjectIDToString(SLuint32 objectID)
148 {
149     static const char * const objectIDstrings[10] = {
150         "SL_OBJECTID_ENGINE",
151         "SL_OBJECTID_LEDDEVICE",
152         "SL_OBJECTID_VIBRADEVICE",
153         "SL_OBJECTID_AUDIOPLAYER",
154         "SL_OBJECTID_AUDIORECORDER",
155         "SL_OBJECTID_MIDIPLAYER",
156         "SL_OBJECTID_LISTENER",
157         "SL_OBJECTID_3DGROUP",
158         "SL_OBJECTID_OUTPUTMIX",
159         "SL_OBJECTID_METADATAEXTRACTOR"
160     };
161     return (0x1001 <= objectID) && (objectID <= 0x100A) ? objectIDstrings[objectID - 0x1001] : NULL;
162 }
163