Sylvain Munaut | 0f7e52d | 2010-10-29 11:38:54 +0200 | [diff] [blame] | 1 | /* Formats handling */ |
| 2 | |
| 3 | /* |
| 4 | * This file is part of gapk (GSM Audio Pocket Knife). |
| 5 | * |
| 6 | * gapk is free software: you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation, either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * gapk is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with gapk. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #include <stdio.h> /* for NULL */ |
Sylvain Munaut | 24b7612 | 2010-10-29 22:45:22 +0200 | [diff] [blame^] | 21 | #include <string.h> |
Sylvain Munaut | 0f7e52d | 2010-10-29 11:38:54 +0200 | [diff] [blame] | 22 | |
| 23 | #include <gapk/formats.h> |
| 24 | |
| 25 | /* Extern format descriptors */ |
Sylvain Munaut | 723df06 | 2010-10-29 11:47:06 +0200 | [diff] [blame] | 26 | extern const struct format_desc fmt_amr_efr; |
Sylvain Munaut | 5e380d0 | 2010-10-29 11:41:16 +0200 | [diff] [blame] | 27 | extern const struct format_desc fmt_gsm; |
Sylvain Munaut | f905983 | 2010-10-29 11:44:40 +0200 | [diff] [blame] | 28 | extern const struct format_desc fmt_hr_ref_dec; |
| 29 | extern const struct format_desc fmt_hr_ref_enc; |
Sylvain Munaut | 6c96cc2 | 2010-10-29 11:46:05 +0200 | [diff] [blame] | 30 | extern const struct format_desc fmt_racal_hr; |
| 31 | extern const struct format_desc fmt_racal_fr; |
| 32 | extern const struct format_desc fmt_racal_efr; |
Sylvain Munaut | 5e380d0 | 2010-10-29 11:41:16 +0200 | [diff] [blame] | 33 | |
Sylvain Munaut | 0f7e52d | 2010-10-29 11:38:54 +0200 | [diff] [blame] | 34 | static const struct format_desc *supported_formats[_FMT_MAX] = { |
| 35 | [FMT_INVALID] = NULL, |
Sylvain Munaut | 723df06 | 2010-10-29 11:47:06 +0200 | [diff] [blame] | 36 | [FMT_AMR_EFR] = &fmt_amr_efr, |
Sylvain Munaut | 5e380d0 | 2010-10-29 11:41:16 +0200 | [diff] [blame] | 37 | [FMT_GSM] = &fmt_gsm, |
Sylvain Munaut | f905983 | 2010-10-29 11:44:40 +0200 | [diff] [blame] | 38 | [FMT_HR_REF_DEC] = &fmt_hr_ref_dec, |
| 39 | [FMT_HR_REF_ENC] = &fmt_hr_ref_enc, |
Sylvain Munaut | 6c96cc2 | 2010-10-29 11:46:05 +0200 | [diff] [blame] | 40 | [FMT_RACAL_HR] = &fmt_racal_hr, |
| 41 | [FMT_RACAL_FR] = &fmt_racal_fr, |
| 42 | [FMT_RACAL_EFR] = &fmt_racal_efr, |
Sylvain Munaut | 0f7e52d | 2010-10-29 11:38:54 +0200 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | |
| 46 | const struct format_desc * |
| 47 | fmt_get_from_type(enum format_type type) |
| 48 | { |
| 49 | if (type <= FMT_INVALID || type >= _FMT_MAX) |
| 50 | return NULL; |
| 51 | return supported_formats[type]; |
| 52 | } |
Sylvain Munaut | 24b7612 | 2010-10-29 22:45:22 +0200 | [diff] [blame^] | 53 | |
| 54 | const struct format_desc * |
| 55 | fmt_get_from_name(const char *name) |
| 56 | { |
| 57 | int i; |
| 58 | for (i=FMT_INVALID+1; i<_FMT_MAX; i++) { |
| 59 | const struct format_desc *fmt = supported_formats[i]; |
| 60 | if (!fmt) |
| 61 | continue; |
| 62 | if (!strcmp(fmt->name, name)) |
| 63 | return fmt; |
| 64 | } |
| 65 | return NULL; |
| 66 | } |