Chia-chi Yeh | 4c5d28c | 2010-08-06 14:12:05 +0800 | [diff] [blame] | 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 <string.h> |
| 18 | |
| 19 | #include "AudioCodec.h" |
| 20 | |
Chia-chi Yeh | 78c11b3 | 2010-09-29 05:46:19 +0800 | [diff] [blame] | 21 | extern AudioCodec *newAlawCodec(); |
| 22 | extern AudioCodec *newUlawCodec(); |
Chia-chi Yeh | a6f950c | 2010-09-29 10:36:52 +0800 | [diff] [blame] | 23 | extern AudioCodec *newGsmCodec(); |
Chia-chi Yeh | f88fc1f | 2010-09-30 08:51:59 +0800 | [diff] [blame] | 24 | extern AudioCodec *newAmrCodec(); |
Chia-chi Yeh | f4ae942 | 2010-09-30 03:04:06 +0800 | [diff] [blame] | 25 | extern AudioCodec *newGsmEfrCodec(); |
Chia-chi Yeh | 4c5d28c | 2010-08-06 14:12:05 +0800 | [diff] [blame] | 26 | |
| 27 | struct AudioCodecType { |
| 28 | const char *name; |
| 29 | AudioCodec *(*create)(); |
| 30 | } gAudioCodecTypes[] = { |
| 31 | {"PCMA", newAlawCodec}, |
| 32 | {"PCMU", newUlawCodec}, |
Chia-chi Yeh | a6f950c | 2010-09-29 10:36:52 +0800 | [diff] [blame] | 33 | {"GSM", newGsmCodec}, |
Chia-chi Yeh | f88fc1f | 2010-09-30 08:51:59 +0800 | [diff] [blame] | 34 | {"AMR", newAmrCodec}, |
Chia-chi Yeh | f4ae942 | 2010-09-30 03:04:06 +0800 | [diff] [blame] | 35 | {"GSM-EFR", newGsmEfrCodec}, |
Chia-chi Yeh | 4c5d28c | 2010-08-06 14:12:05 +0800 | [diff] [blame] | 36 | {NULL, NULL}, |
| 37 | }; |
| 38 | |
Chia-chi Yeh | 4c5d28c | 2010-08-06 14:12:05 +0800 | [diff] [blame] | 39 | AudioCodec *newAudioCodec(const char *codecName) |
| 40 | { |
| 41 | AudioCodecType *type = gAudioCodecTypes; |
| 42 | while (type->name != NULL) { |
Chia-chi Yeh | 4033a67 | 2010-09-16 18:36:45 +0800 | [diff] [blame] | 43 | if (strcasecmp(codecName, type->name) == 0) { |
| 44 | AudioCodec *codec = type->create(); |
| 45 | codec->name = type->name; |
| 46 | return codec; |
Chia-chi Yeh | 4c5d28c | 2010-08-06 14:12:05 +0800 | [diff] [blame] | 47 | } |
| 48 | ++type; |
| 49 | } |
| 50 | return NULL; |
| 51 | } |