blob: 920dd5e2fb9eb475aee7b7f890e6191bf9ef0937 [file] [log] [blame]
Glenn Kastena6d984c2010-05-18 18:38:45 -07001/*
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};
Glenn Kasten61ac0ad2010-05-20 08:54:02 -0700111
Glenn Kasten7a79f512010-07-09 11:50:34 -0700112// should build this table from Caps table below
Glenn Kasten61ac0ad2010-05-20 08:54:02 -0700113
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
Glenn Kastendf200f62011-11-11 12:10:41 -0800126const SLuint32 * const Decoder_IDs = Codec_IDs;
127const SLuint32 * const Encoder_IDs = Codec_IDs;
Glenn Kasten61ac0ad2010-05-20 08:54:02 -0700128
Glenn Kastendf200f62011-11-11 12:10:41 -0800129// for ANDROID, must match size and order of kVideoMimeTypes
Jean-Michel Trivi6e7e1742011-07-12 18:19:27 -0700130static 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
Glenn Kastendf200f62011-11-11 12:10:41 -0800143const SLuint32 * const VideoDecoderIds = VideoCodecIds;
Jean-Michel Trivi6e7e1742011-07-12 18:19:27 -0700144
Glenn Kastendf200f62011-11-11 12:10:41 -0800145// for ANDROID, must == kNbVideoMimeTypes
Jean-Michel Trivi6e7e1742011-07-12 18:19:27 -0700146const XAuint32 kMaxVideoDecoders = sizeof(VideoCodecIds) / sizeof(VideoCodecIds[0]);
147
Glenn Kasten61ac0ad2010-05-20 08:54:02 -0700148static 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
160static 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
Glenn Kasten369f3132010-07-23 15:45:09 -0700180const CodecDescriptor DecoderDescriptors[] = {
Glenn Kasten61ac0ad2010-05-20 08:54:02 -0700181 {SL_AUDIOCODEC_PCM, &CodecDescriptor_A},
Glenn Kastena438eb12010-06-29 17:33:26 -0700182 {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},
Glenn Kasten61ac0ad2010-05-20 08:54:02 -0700190 {SL_AUDIOCODEC_NULL, NULL}
191};
192
Glenn Kasten369f3132010-07-23 15:45:09 -0700193const CodecDescriptor EncoderDescriptors[] = {
Glenn Kasten61ac0ad2010-05-20 08:54:02 -0700194 {SL_AUDIOCODEC_PCM, &CodecDescriptor_A},
Glenn Kastena438eb12010-06-29 17:33:26 -0700195 {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},
Glenn Kasten61ac0ad2010-05-20 08:54:02 -0700203 {SL_AUDIOCODEC_NULL, NULL}
204};
Glenn Kasten8db0b102010-11-28 16:33:53 -0800205
206
207/** \brief Helper shared by decoder and encoder */
208
209SLresult 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}