devices.c revision 262059f71a68edc5e510427c63f5f1623d3672a8
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
21static 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
35const struct AudioInput_id_descriptor AudioInput_id_descriptors[] = {
36    {SL_DEFAULTDEVICEID_AUDIOINPUT, &AudioInputDescriptor_mic},
37    {0, NULL}
38};
39
40static 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
54static 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
68static 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
82const 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
89static const SLLEDDescriptor SLLEDDescriptor_default = {
90    32, // ledCount
91    0,  // primaryLED
92    ~0  // colorMask
93};
94
95const struct LED_id_descriptor LED_id_descriptors[] = {
96    {SL_DEFAULTDEVICEID_LED, &SLLEDDescriptor_default},
97    {0, NULL}
98};
99
100static const SLVibraDescriptor SLVibraDescriptor_default = {
101    SL_BOOLEAN_TRUE, // supportsFrequency
102    SL_BOOLEAN_TRUE, // supportsIntensity
103    20000,           // minFrequency
104    100000           // maxFrequency
105};
106
107const 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
114static 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
126const SLuint32 *Decoder_IDs = Codec_IDs;
127const SLuint32 *Encoder_IDs = Codec_IDs;
128
129static const SLmilliHertz SamplingRates_A[] = {
130    SL_SAMPLINGRATE_8,
131    SL_SAMPLINGRATE_11_025,
132    SL_SAMPLINGRATE_12,
133    SL_SAMPLINGRATE_16,
134    SL_SAMPLINGRATE_22_05,
135    SL_SAMPLINGRATE_24,
136    SL_SAMPLINGRATE_32,
137    SL_SAMPLINGRATE_44_1,
138    SL_SAMPLINGRATE_48
139};
140
141static const SLAudioCodecDescriptor CodecDescriptor_A = {
142    2,                   // maxChannels
143    8,                   // minBitsPerSample
144    16,                  // maxBitsPerSample
145    SL_SAMPLINGRATE_8,   // minSampleRate
146    SL_SAMPLINGRATE_48,  // maxSampleRate
147    SL_BOOLEAN_FALSE,    // isFreqRangeContinuous
148    (SLmilliHertz *) SamplingRates_A,
149                         // pSampleRatesSupported;
150    sizeof(SamplingRates_A) / sizeof(SamplingRates_A[0]),
151                         // numSampleRatesSupported
152    1,                   // minBitRate
153    ~0,                  // maxBitRate
154    SL_BOOLEAN_TRUE,     // isBitrateRangeContinuous
155    NULL,                // pBitratesSupported
156    0,                   // numBitratesSupported
157    SL_AUDIOPROFILE_PCM, // profileSetting
158    0                    // modeSetting
159};
160
161const CodecDescriptor DecoderDescriptors[] = {
162    {SL_AUDIOCODEC_PCM, &CodecDescriptor_A},
163    {SL_AUDIOCODEC_MP3, &CodecDescriptor_A},
164    {SL_AUDIOCODEC_AMR, &CodecDescriptor_A},
165    {SL_AUDIOCODEC_AMRWB, &CodecDescriptor_A},
166    {SL_AUDIOCODEC_AMRWBPLUS, &CodecDescriptor_A},
167    {SL_AUDIOCODEC_AAC, &CodecDescriptor_A},
168    {SL_AUDIOCODEC_WMA, &CodecDescriptor_A},
169    {SL_AUDIOCODEC_REAL, &CodecDescriptor_A},
170    {SL_AUDIOCODEC_VORBIS, &CodecDescriptor_A},
171    {SL_AUDIOCODEC_NULL, NULL}
172};
173
174const CodecDescriptor EncoderDescriptors[] = {
175    {SL_AUDIOCODEC_PCM, &CodecDescriptor_A},
176    {SL_AUDIOCODEC_MP3, &CodecDescriptor_A},
177    {SL_AUDIOCODEC_AMR, &CodecDescriptor_A},
178    {SL_AUDIOCODEC_AMRWB, &CodecDescriptor_A},
179    {SL_AUDIOCODEC_AMRWBPLUS, &CodecDescriptor_A},
180    {SL_AUDIOCODEC_AAC, &CodecDescriptor_A},
181    {SL_AUDIOCODEC_WMA, &CodecDescriptor_A},
182    {SL_AUDIOCODEC_REAL, &CodecDescriptor_A},
183    {SL_AUDIOCODEC_VORBIS, &CodecDescriptor_A},
184    {SL_AUDIOCODEC_NULL, NULL}
185};
186
187
188/** \brief Helper shared by decoder and encoder */
189
190SLresult GetCodecCapabilities(SLuint32 codecId, SLuint32 *pIndex,
191    SLAudioCodecDescriptor *pDescriptor, const CodecDescriptor *codecDescriptors)
192{
193    if (NULL == pIndex) {
194        return SL_RESULT_PARAMETER_INVALID;
195    }
196    const CodecDescriptor *cd = codecDescriptors;
197    SLuint32 index;
198    if (NULL == pDescriptor) {
199        for (index = 0 ; NULL != cd->mDescriptor; ++cd) {
200            if (cd->mCodecID == codecId) {
201                ++index;
202            }
203        }
204        *pIndex = index;
205        return SL_RESULT_SUCCESS;
206    }
207    index = *pIndex;
208    for ( ; NULL != cd->mDescriptor; ++cd) {
209        if (cd->mCodecID == codecId) {
210            if (0 == index) {
211                *pDescriptor = *cd->mDescriptor;
212#if 0   // Temporary workaround for Khronos bug 6331
213                if (0 < pDescriptor->numSampleRatesSupported) {
214                    // The malloc is not in the 1.0.1 specification
215                    SLmilliHertz *temp = (SLmilliHertz *) malloc(sizeof(SLmilliHertz) *
216                        pDescriptor->numSampleRatesSupported);
217                    assert(NULL != temp);
218                    memcpy(temp, pDescriptor->pSampleRatesSupported, sizeof(SLmilliHertz) *
219                        pDescriptor->numSampleRatesSupported);
220                    pDescriptor->pSampleRatesSupported = temp;
221                } else {
222                    pDescriptor->pSampleRatesSupported = NULL;
223                }
224#endif
225                return SL_RESULT_SUCCESS;
226            }
227            --index;
228        }
229    }
230    return SL_RESULT_PARAMETER_INVALID;
231}
232