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