Home | History | Annotate | Download | only in libopensles
      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 IID_to_MPH.c Interface ID to MPH mapping */
     18 
     19 #include "SLES/OpenSLES.h"
     20 #include "MPH.h"
     21 #include <assert.h>
     22 #include <string.h>
     23 
     24 extern const struct SLInterfaceID_ SL_IID_array[MPH_MAX];
     25 
     26 /** \brief Map SLInterfaceID to its minimal perfect hash (MPH), or -1 if unknown */
     27 
     28 int IID_to_MPH(const SLInterfaceID iid)
     29 {
     30 #define MAX_HASH_VALUE 115
     31   static const unsigned char asso_values[] =
     32     {
     33         5, 116, 116,  61, 116, 116,   7, 116, 116,   7,
     34       116,  12, 116, 116, 116,  46, 116, 116, 116, 116,
     35       116, 116,  56, 116, 116,  36, 116, 116, 116, 116,
     36       116,   7,  20, 116, 116, 116, 116, 116, 116, 116,
     37       116, 116,  41,  20,  36, 116,  21, 116, 116, 116,
     38       116, 116, 116,  26, 116,   2, 116, 116, 116, 116,
     39       116,  51, 116,  51,  55, 116, 116, 116, 116, 116,
     40       116,  16, 116, 116, 116, 116, 116, 116, 116, 116,
     41        21, 116, 116, 116, 116, 116,  26, 116, 116, 116,
     42        11, 116, 116, 116, 116, 116,  40,  11, 116,  60,
     43       116, 116, 116, 116, 116, 116,   6, 116, 116, 116,
     44       116, 116,   1, 116, 116, 116, 116, 116, 116, 116,
     45       116,   1,  55,   6, 116, 116, 116, 116,  45, 116,
     46       116,   1, 116, 116, 116, 116, 116,   1, 116, 116,
     47       116,  60, 116, 116, 116, 116, 116, 116, 116, 116,
     48       116,  55, 116, 116, 116, 116, 116, 116, 116, 116,
     49        10, 116, 116, 116, 116, 116, 116, 116, 116, 116,
     50        45, 116, 116, 116,  40, 116, 116, 116,  55, 116,
     51        40, 116, 116, 116, 116, 116, 116, 116, 116, 116,
     52       116, 116,  15, 116,  35, 116,  45,   5, 116,  50,
     53       116, 116, 116, 116, 116, 116, 116, 116, 116, 116,
     54       116, 116,  40, 116, 116,  50, 116, 116, 116, 116,
     55       116,  25, 116, 116,  15,  35, 116, 116,  10, 116,
     56       116, 116, 116, 116, 116,  10,   0, 116, 116,  15,
     57        30, 116, 116, 116, 116, 116,  55, 116, 116, 116,
     58       116, 116, 116, 116,   0, 116
     59     };
     60     static const signed char hash_to_MPH[] = {
     61         MPH_NULL,
     62         -1,
     63         -1,
     64         -1,
     65         -1,
     66         MPH_OUTPUTMIXEXT,
     67         MPH_3DSOURCE,
     68         MPH_VIRTUALIZER,
     69         -1,
     70         -1,
     71         MPH_DYNAMICSOURCE,
     72         MPH_ENGINECAPABILITIES,
     73         MPH_MIDITEMPO,
     74         -1,
     75         -1,
     76         MPH_RECORD,
     77         MPH_ANDROIDCONFIGURATION,
     78         MPH_EQUALIZER,
     79         -1,
     80         -1,
     81         MPH_VISUALIZATION,
     82         MPH_ANDROIDEFFECTSEND,
     83         MPH_VOLUME,
     84         -1,
     85         -1,
     86         MPH_3DGROUPING,
     87         MPH_MUTESOLO,
     88         MPH_BASSBOOST,
     89         -1,
     90         -1,
     91         MPH_PLAY,
     92         MPH_EFFECTSEND,
     93         -1,
     94         -1,
     95         -1,
     96         MPH_BUFFERQUEUE,
     97         MPH_3DMACROSCOPIC,
     98         -1,
     99         -1,
    100         -1,
    101         MPH_3DLOCATION,
    102         MPH_OBJECT,
    103         -1,
    104         -1,
    105         -1,
    106         MPH_MIDIMESSAGE,
    107         MPH_ANDROIDEFFECTCAPABILITIES,
    108         -1,
    109         -1,
    110         -1,
    111         MPH_SEEK,
    112         MPH_RATEPITCH,
    113         -1,
    114         -1,
    115         -1,
    116         MPH_PITCH,
    117         MPH_PRESETREVERB,
    118         -1,
    119         -1,
    120         -1,
    121         MPH_METADATATRAVERSAL,
    122         MPH_AUDIODECODERCAPABILITIES,
    123         -1,
    124         -1,
    125         -1,
    126         MPH_ENVIRONMENTALREVERB,
    127         MPH_MIDITIME,
    128         -1,
    129         -1,
    130         -1,
    131         MPH_AUDIOIODEVICECAPABILITIES,
    132         MPH_3DCOMMIT,
    133         -1,
    134         -1,
    135         -1,
    136         MPH_DEVICEVOLUME,
    137         MPH_PLAYBACKRATE,
    138         -1,
    139         -1,
    140         -1,
    141         MPH_ANDROIDEFFECT,
    142         MPH_LED,
    143         -1,
    144         -1,
    145         -1,
    146         MPH_3DDOPPLER,
    147         MPH_PREFETCHSTATUS,
    148         -1,
    149         -1,
    150         -1,
    151         MPH_METADATAEXTRACTION,
    152         MPH_ANDROIDSIMPLEBUFFERQUEUE,
    153         -1,
    154         -1,
    155         -1,
    156         MPH_OUTPUTMIX,
    157         MPH_VIBRA,
    158         -1,
    159         -1,
    160         -1,
    161         MPH_ENGINE,
    162         MPH_AUDIOENCODERCAPABILITIES,
    163         -1,
    164         -1,
    165         -1,
    166         MPH_AUDIOENCODER,
    167         MPH_MIDIMUTESOLO,
    168         -1,
    169         -1,
    170         -1,
    171         MPH_THREADSYNC,
    172         -1,
    173         -1,
    174         -1,
    175         -1,
    176         MPH_DYNAMICINTERFACEMANAGEMENT
    177     };
    178     if (&SL_IID_array[0] <= iid && &SL_IID_array[MPH_MAX] > iid)
    179         return iid - &SL_IID_array[0];
    180     if (NULL != iid) {
    181         unsigned key = asso_values[((unsigned char *)iid)[3]] +
    182             asso_values[((unsigned char *)iid)[0]];
    183         if (key <= MAX_HASH_VALUE) {
    184             int MPH = hash_to_MPH[key];
    185             if (MPH >= 0) {
    186                 assert(MPH < MPH_MAX);
    187                 SLInterfaceID trial = &SL_IID_array[MPH];
    188                 if (!memcmp(iid, trial, sizeof(struct SLInterfaceID_)))
    189                     return MPH;
    190             }
    191         }
    192     }
    193     return -1;
    194 }
    195