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     (SLuint32) ~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 * const Decoder_IDs = Codec_IDs;
    127 const SLuint32 * const Encoder_IDs = Codec_IDs;
    128 
    129 // for ANDROID, must match size and order of kVideoMimeTypes
    130 static const SLuint32 VideoCodecIds[] = {
    131         XA_VIDEOCODEC_MPEG2,
    132         XA_VIDEOCODEC_H263,
    133         XA_VIDEOCODEC_MPEG4,
    134         XA_VIDEOCODEC_AVC,
    135 #ifndef ANDROID
    136         XA_VIDEOCODEC_VC1,
    137 #endif
    138 #ifdef ANDROID
    139         XA_ANDROID_VIDEOCODEC_VP8
    140 #endif
    141 };
    142 
    143 const SLuint32 * const VideoDecoderIds = VideoCodecIds;
    144 
    145 static const SLmilliHertz SamplingRates_A[] = {
    146     SL_SAMPLINGRATE_8,
    147     SL_SAMPLINGRATE_11_025,
    148     SL_SAMPLINGRATE_12,
    149     SL_SAMPLINGRATE_16,
    150     SL_SAMPLINGRATE_22_05,
    151     SL_SAMPLINGRATE_24,
    152     SL_SAMPLINGRATE_32,
    153     SL_SAMPLINGRATE_44_1,
    154     SL_SAMPLINGRATE_48
    155 };
    156 
    157 static const SLAudioCodecDescriptor CodecDescriptor_A = {
    158     2,                   // maxChannels
    159     8,                   // minBitsPerSample
    160     16,                  // maxBitsPerSample
    161     SL_SAMPLINGRATE_8,   // minSampleRate
    162     SL_SAMPLINGRATE_48,  // maxSampleRate
    163     SL_BOOLEAN_FALSE,    // isFreqRangeContinuous
    164     (SLmilliHertz *) SamplingRates_A,
    165                          // pSampleRatesSupported;
    166     sizeof(SamplingRates_A) / sizeof(SamplingRates_A[0]),
    167                          // numSampleRatesSupported
    168     1,                   // minBitRate
    169     (SLuint32) ~0,       // maxBitRate
    170     SL_BOOLEAN_TRUE,     // isBitrateRangeContinuous
    171     NULL,                // pBitratesSupported
    172     0,                   // numBitratesSupported
    173     SL_AUDIOPROFILE_PCM, // profileSetting
    174     0                    // modeSetting
    175 };
    176 
    177 const CodecDescriptor DecoderDescriptors[] = {
    178     {SL_AUDIOCODEC_PCM, &CodecDescriptor_A},
    179     {SL_AUDIOCODEC_MP3, &CodecDescriptor_A},
    180     {SL_AUDIOCODEC_AMR, &CodecDescriptor_A},
    181     {SL_AUDIOCODEC_AMRWB, &CodecDescriptor_A},
    182     {SL_AUDIOCODEC_AMRWBPLUS, &CodecDescriptor_A},
    183     {SL_AUDIOCODEC_AAC, &CodecDescriptor_A},
    184     {SL_AUDIOCODEC_WMA, &CodecDescriptor_A},
    185     {SL_AUDIOCODEC_REAL, &CodecDescriptor_A},
    186     {SL_AUDIOCODEC_VORBIS, &CodecDescriptor_A},
    187     {SL_AUDIOCODEC_NULL, NULL}
    188 };
    189 
    190 const CodecDescriptor EncoderDescriptors[] = {
    191     {SL_AUDIOCODEC_PCM, &CodecDescriptor_A},
    192     {SL_AUDIOCODEC_MP3, &CodecDescriptor_A},
    193     {SL_AUDIOCODEC_AMR, &CodecDescriptor_A},
    194     {SL_AUDIOCODEC_AMRWB, &CodecDescriptor_A},
    195     {SL_AUDIOCODEC_AMRWBPLUS, &CodecDescriptor_A},
    196     {SL_AUDIOCODEC_AAC, &CodecDescriptor_A},
    197     {SL_AUDIOCODEC_WMA, &CodecDescriptor_A},
    198     {SL_AUDIOCODEC_REAL, &CodecDescriptor_A},
    199     {SL_AUDIOCODEC_VORBIS, &CodecDescriptor_A},
    200     {SL_AUDIOCODEC_NULL, NULL}
    201 };
    202 
    203 
    204 /** \brief Helper shared by decoder and encoder */
    205 
    206 SLresult GetCodecCapabilities(SLuint32 codecId, SLuint32 *pIndex,
    207     SLAudioCodecDescriptor *pDescriptor, const CodecDescriptor *codecDescriptors)
    208 {
    209     if (NULL == pIndex) {
    210         return SL_RESULT_PARAMETER_INVALID;
    211     }
    212     const CodecDescriptor *cd = codecDescriptors;
    213     SLuint32 index;
    214     if (NULL == pDescriptor) {
    215         for (index = 0 ; NULL != cd->mDescriptor; ++cd) {
    216             if (cd->mCodecID == codecId) {
    217                 ++index;
    218             }
    219         }
    220         *pIndex = index;
    221         return SL_RESULT_SUCCESS;
    222     }
    223     index = *pIndex;
    224     for ( ; NULL != cd->mDescriptor; ++cd) {
    225         if (cd->mCodecID == codecId) {
    226             if (0 == index) {
    227                 *pDescriptor = *cd->mDescriptor;
    228 #if 0   // Temporary workaround for Khronos bug 6331
    229                 if (0 < pDescriptor->numSampleRatesSupported) {
    230                     // The malloc is not in the 1.0.1 specification
    231                     SLmilliHertz *temp = (SLmilliHertz *) malloc(sizeof(SLmilliHertz) *
    232                         pDescriptor->numSampleRatesSupported);
    233                     assert(NULL != temp);
    234                     memcpy(temp, pDescriptor->pSampleRatesSupported, sizeof(SLmilliHertz) *
    235                         pDescriptor->numSampleRatesSupported);
    236                     pDescriptor->pSampleRatesSupported = temp;
    237                 } else {
    238                     pDescriptor->pSampleRatesSupported = NULL;
    239                 }
    240 #endif
    241                 return SL_RESULT_SUCCESS;
    242             }
    243             --index;
    244         }
    245     }
    246     return SL_RESULT_PARAMETER_INVALID;
    247 }
    248