Home | History | Annotate | Download | only in src
      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 #include "sles_allinclusive.h"
     18 
     19 /* Device table (change this when you port!) */
     20 
     21 static const SLAudioInputDescriptor AudioInputDescriptor_mic = {
     22     (SLchar *) "mic",            // deviceName
     23     SL_DEVCONNECTION_INTEGRATED, // deviceConnection
     24     SL_DEVSCOPE_ENVIRONMENT,     // deviceScope
     25     SL_DEVLOCATION_HANDSET,      // deviceLocation
     26     SL_BOOLEAN_TRUE,             // isForTelephony
     27     SL_SAMPLINGRATE_44_1,        // minSampleRate
     28     SL_SAMPLINGRATE_44_1,        // maxSampleRate
     29     SL_BOOLEAN_TRUE,             // isFreqRangeContinuous
     30     NULL,                        // samplingRatesSupported
     31     0,                           // numOfSamplingRatesSupported
     32     1                            // maxChannels
     33 };
     34 
     35 const struct AudioInput_id_descriptor AudioInput_id_descriptors[] = {
     36     {SL_DEFAULTDEVICEID_AUDIOINPUT, &AudioInputDescriptor_mic},
     37     {0, NULL}
     38 };
     39 
     40 static const SLAudioOutputDescriptor AudioOutputDescriptor_speaker = {
     41     (SLchar *) "speaker",        // deviceName
     42     SL_DEVCONNECTION_INTEGRATED, // deviceConnection
     43     SL_DEVSCOPE_USER,            // deviceScope
     44     SL_DEVLOCATION_HEADSET,      // deviceLocation
     45     SL_BOOLEAN_TRUE,             // isForTelephony
     46     SL_SAMPLINGRATE_44_1,        // minSamplingRate
     47     SL_SAMPLINGRATE_44_1,        // maxSamplingRate
     48     SL_BOOLEAN_TRUE,             // isFreqRangeContinuous
     49     NULL,                        // samplingRatesSupported
     50     0,                           // numOfSamplingRatesSupported
     51     2                            // maxChannels
     52 };
     53 
     54 static const SLAudioOutputDescriptor AudioOutputDescriptor_headset = {
     55     (SLchar *) "headset",
     56     SL_DEVCONNECTION_ATTACHED_WIRED,
     57     SL_DEVSCOPE_USER,
     58     SL_DEVLOCATION_HEADSET,
     59     SL_BOOLEAN_FALSE,
     60     SL_SAMPLINGRATE_44_1,
     61     SL_SAMPLINGRATE_44_1,
     62     SL_BOOLEAN_TRUE,
     63     NULL,
     64     0,
     65     2
     66 };
     67 
     68 static const SLAudioOutputDescriptor AudioOutputDescriptor_handsfree = {
     69     (SLchar *) "handsfree",
     70     SL_DEVCONNECTION_INTEGRATED,
     71     SL_DEVSCOPE_ENVIRONMENT,
     72     SL_DEVLOCATION_HANDSET,
     73     SL_BOOLEAN_FALSE,
     74     SL_SAMPLINGRATE_44_1,
     75     SL_SAMPLINGRATE_44_1,
     76     SL_BOOLEAN_TRUE,
     77     NULL,
     78     0,
     79     2
     80 };
     81 
     82 const struct AudioOutput_id_descriptor AudioOutput_id_descriptors[] = {
     83     {SL_DEFAULTDEVICEID_AUDIOOUTPUT, &AudioOutputDescriptor_speaker},
     84     {DEVICE_ID_HEADSET, &AudioOutputDescriptor_headset},
     85     {DEVICE_ID_HANDSFREE, &AudioOutputDescriptor_handsfree},
     86     {0, NULL}
     87 };
     88 
     89 static const SLLEDDescriptor SLLEDDescriptor_default = {
     90     32, // ledCount
     91     0,  // primaryLED
     92     ~0  // colorMask
     93 };
     94 
     95 const struct LED_id_descriptor LED_id_descriptors[] = {
     96     {SL_DEFAULTDEVICEID_LED, &SLLEDDescriptor_default},
     97     {0, NULL}
     98 };
     99 
    100 static const SLVibraDescriptor SLVibraDescriptor_default = {
    101     SL_BOOLEAN_TRUE, // supportsFrequency
    102     SL_BOOLEAN_TRUE, // supportsIntensity
    103     20000,           // minFrequency
    104     100000           // maxFrequency
    105 };
    106 
    107 const struct Vibra_id_descriptor Vibra_id_descriptors[] = {
    108     {SL_DEFAULTDEVICEID_VIBRA, &SLVibraDescriptor_default},
    109     {0, NULL}
    110 };
    111 
    112 // should build this table from Caps table below
    113 
    114 static const SLuint32 Codec_IDs[] = {
    115     SL_AUDIOCODEC_PCM,
    116     SL_AUDIOCODEC_MP3,
    117     SL_AUDIOCODEC_AMR,
    118     SL_AUDIOCODEC_AMRWB,
    119     SL_AUDIOCODEC_AMRWBPLUS,
    120     SL_AUDIOCODEC_AAC,
    121     SL_AUDIOCODEC_WMA,
    122     SL_AUDIOCODEC_REAL,
    123     SL_AUDIOCODEC_VORBIS
    124 };
    125 
    126 const SLuint32 *Decoder_IDs = Codec_IDs;
    127 const SLuint32 *Encoder_IDs = Codec_IDs;
    128 
    129 static const SLuint32 VideoCodecIds[] = {
    130         XA_VIDEOCODEC_MPEG2,
    131         XA_VIDEOCODEC_H263,
    132         XA_VIDEOCODEC_MPEG4,
    133         XA_VIDEOCODEC_AVC,
    134 #ifndef ANDROID
    135         XA_VIDEOCODEC_VC1,
    136 #endif
    137 #ifdef ANDROID
    138         XA_ANDROID_VIDEOCODEC_VP8
    139 #endif
    140 };
    141 
    142 const SLuint32 *VideoDecoderIds = VideoCodecIds;
    143 
    144 const XAuint32 kMaxVideoDecoders = sizeof(VideoCodecIds) / sizeof(VideoCodecIds[0]);
    145 
    146 static const SLmilliHertz SamplingRates_A[] = {
    147     SL_SAMPLINGRATE_8,
    148     SL_SAMPLINGRATE_11_025,
    149     SL_SAMPLINGRATE_12,
    150     SL_SAMPLINGRATE_16,
    151     SL_SAMPLINGRATE_22_05,
    152     SL_SAMPLINGRATE_24,
    153     SL_SAMPLINGRATE_32,
    154     SL_SAMPLINGRATE_44_1,
    155     SL_SAMPLINGRATE_48
    156 };
    157 
    158 static const SLAudioCodecDescriptor CodecDescriptor_A = {
    159     2,                   // maxChannels
    160     8,                   // minBitsPerSample
    161     16,                  // maxBitsPerSample
    162     SL_SAMPLINGRATE_8,   // minSampleRate
    163     SL_SAMPLINGRATE_48,  // maxSampleRate
    164     SL_BOOLEAN_FALSE,    // isFreqRangeContinuous
    165     (SLmilliHertz *) SamplingRates_A,
    166                          // pSampleRatesSupported;
    167     sizeof(SamplingRates_A) / sizeof(SamplingRates_A[0]),
    168                          // numSampleRatesSupported
    169     1,                   // minBitRate
    170     ~0,                  // maxBitRate
    171     SL_BOOLEAN_TRUE,     // isBitrateRangeContinuous
    172     NULL,                // pBitratesSupported
    173     0,                   // numBitratesSupported
    174     SL_AUDIOPROFILE_PCM, // profileSetting
    175     0                    // modeSetting
    176 };
    177 
    178 const CodecDescriptor DecoderDescriptors[] = {
    179     {SL_AUDIOCODEC_PCM, &CodecDescriptor_A},
    180     {SL_AUDIOCODEC_MP3, &CodecDescriptor_A},
    181     {SL_AUDIOCODEC_AMR, &CodecDescriptor_A},
    182     {SL_AUDIOCODEC_AMRWB, &CodecDescriptor_A},
    183     {SL_AUDIOCODEC_AMRWBPLUS, &CodecDescriptor_A},
    184     {SL_AUDIOCODEC_AAC, &CodecDescriptor_A},
    185     {SL_AUDIOCODEC_WMA, &CodecDescriptor_A},
    186     {SL_AUDIOCODEC_REAL, &CodecDescriptor_A},
    187     {SL_AUDIOCODEC_VORBIS, &CodecDescriptor_A},
    188     {SL_AUDIOCODEC_NULL, NULL}
    189 };
    190 
    191 const CodecDescriptor EncoderDescriptors[] = {
    192     {SL_AUDIOCODEC_PCM, &CodecDescriptor_A},
    193     {SL_AUDIOCODEC_MP3, &CodecDescriptor_A},
    194     {SL_AUDIOCODEC_AMR, &CodecDescriptor_A},
    195     {SL_AUDIOCODEC_AMRWB, &CodecDescriptor_A},
    196     {SL_AUDIOCODEC_AMRWBPLUS, &CodecDescriptor_A},
    197     {SL_AUDIOCODEC_AAC, &CodecDescriptor_A},
    198     {SL_AUDIOCODEC_WMA, &CodecDescriptor_A},
    199     {SL_AUDIOCODEC_REAL, &CodecDescriptor_A},
    200     {SL_AUDIOCODEC_VORBIS, &CodecDescriptor_A},
    201     {SL_AUDIOCODEC_NULL, NULL}
    202 };
    203 
    204 
    205 /** \brief Helper shared by decoder and encoder */
    206 
    207 SLresult GetCodecCapabilities(SLuint32 codecId, SLuint32 *pIndex,
    208     SLAudioCodecDescriptor *pDescriptor, const CodecDescriptor *codecDescriptors)
    209 {
    210     if (NULL == pIndex) {
    211         return SL_RESULT_PARAMETER_INVALID;
    212     }
    213     const CodecDescriptor *cd = codecDescriptors;
    214     SLuint32 index;
    215     if (NULL == pDescriptor) {
    216         for (index = 0 ; NULL != cd->mDescriptor; ++cd) {
    217             if (cd->mCodecID == codecId) {
    218                 ++index;
    219             }
    220         }
    221         *pIndex = index;
    222         return SL_RESULT_SUCCESS;
    223     }
    224     index = *pIndex;
    225     for ( ; NULL != cd->mDescriptor; ++cd) {
    226         if (cd->mCodecID == codecId) {
    227             if (0 == index) {
    228                 *pDescriptor = *cd->mDescriptor;
    229 #if 0   // Temporary workaround for Khronos bug 6331
    230                 if (0 < pDescriptor->numSampleRatesSupported) {
    231                     // The malloc is not in the 1.0.1 specification
    232                     SLmilliHertz *temp = (SLmilliHertz *) malloc(sizeof(SLmilliHertz) *
    233                         pDescriptor->numSampleRatesSupported);
    234                     assert(NULL != temp);
    235                     memcpy(temp, pDescriptor->pSampleRatesSupported, sizeof(SLmilliHertz) *
    236                         pDescriptor->numSampleRatesSupported);
    237                     pDescriptor->pSampleRatesSupported = temp;
    238                 } else {
    239                     pDescriptor->pSampleRatesSupported = NULL;
    240                 }
    241 #endif
    242                 return SL_RESULT_SUCCESS;
    243             }
    244             --index;
    245         }
    246     }
    247     return SL_RESULT_PARAMETER_INVALID;
    248 }
    249