Home | History | Annotate | Download | only in ut
      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 
     30 typedef 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 
     43 static 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     _(ANDROIDACOUSTICECHOCANCELLATION),
     98     _(ANDROIDAUTOMATICGAINCONTROL),
     99     _(ANDROIDNOISESUPPRESSION)
    100 #endif
    101 };
    102 
    103 
    104 /** \brief Print an interface ID in human-readable format */
    105 
    106 void slesutPrintIID(SLInterfaceID iid)
    107 {
    108     Pair *p;
    109     const Pair *end = &pairs[sizeof(pairs)/sizeof(pairs[0])];
    110     for (p = pairs; p != end; ++p) {
    111         if (!memcmp(*p->iid, iid, sizeof(struct SLInterfaceID_))) {
    112             printf("SL_IID_%s = ", p->name);
    113             break;
    114         }
    115     }
    116     printf(
    117         "{ 0x%08X, 0x%04X, 0x%04X, 0x%04X, { 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X } }\n",
    118         (unsigned) iid->time_low, iid->time_mid, iid->time_hi_and_version, iid->clock_seq,
    119         iid->node[0], iid->node[1], iid->node[2], iid->node[3], iid->node[4], iid->node[5]);
    120 }
    121 
    122 
    123 /** \brief Print an array of interface IDs in human-readable format,
    124  *  including whether they are required or optional
    125  */
    126 
    127 void slesutPrintIIDs(SLInterfaceID *pInterfaceIds, SLboolean *pInterfaceRequired,
    128     unsigned numInterfaces)
    129 {
    130     unsigned i;
    131     for (i = 0; i < numInterfaces; ++i) {
    132         printf("interfaces[%u]=", i);
    133         slesutPrintIID(pInterfaceIds[i]);
    134         printf(" %s\n", (unsigned) pInterfaceRequired[i] ? "required" : "optional");
    135     }
    136 }
    137 
    138 
    139 /** \brief Convert an object ID to a string or NULL. */
    140 
    141 const char *slesutObjectIDToString(SLuint32 objectID)
    142 {
    143     static const char * const objectIDstrings[10] = {
    144         "SL_OBJECTID_ENGINE",
    145         "SL_OBJECTID_LEDDEVICE",
    146         "SL_OBJECTID_VIBRADEVICE",
    147         "SL_OBJECTID_AUDIOPLAYER",
    148         "SL_OBJECTID_AUDIORECORDER",
    149         "SL_OBJECTID_MIDIPLAYER",
    150         "SL_OBJECTID_LISTENER",
    151         "SL_OBJECTID_3DGROUP",
    152         "SL_OBJECTID_OUTPUTMIX",
    153         "SL_OBJECTID_METADATAEXTRACTOR"
    154     };
    155     return (0x1001 <= objectID) && (objectID <= 0x100A) ? objectIDstrings[objectID - 0x1001] : NULL;
    156 }
    157