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