1/*
2 * Copyrightm (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 <strings.h>
18
19#include "AudioCodec.h"
20
21extern AudioCodec *newAlawCodec();
22extern AudioCodec *newUlawCodec();
23extern AudioCodec *newGsmCodec();
24extern AudioCodec *newAmrCodec();
25extern AudioCodec *newGsmEfrCodec();
26
27struct AudioCodecType {
28    const char *name;
29    AudioCodec *(*create)();
30} gAudioCodecTypes[] = {
31    {"PCMA", newAlawCodec},
32    {"PCMU", newUlawCodec},
33    {"GSM", newGsmCodec},
34    {"AMR", newAmrCodec},
35    {"GSM-EFR", newGsmEfrCodec},
36    {NULL, NULL},
37};
38
39AudioCodec *newAudioCodec(const char *codecName)
40{
41    AudioCodecType *type = gAudioCodecTypes;
42    while (type->name != NULL) {
43        if (strcasecmp(codecName, type->name) == 0) {
44            AudioCodec *codec = type->create();
45            codec->name = type->name;
46            return codec;
47        }
48        ++type;
49    }
50    return NULL;
51}
52