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 | 456758c | 2010-11-11 22:58:20 +0100 | [diff] [blame] | 33 | extern const struct format_desc fmt_rawpcm_s16le; |
Sylvain Munaut | b1525d6 | 2011-02-25 16:58:36 +0100 | [diff] [blame^] | 34 | extern const struct format_desc fmt_ti_hr; |
Sylvain Munaut | cfaec3a | 2011-02-25 15:31:54 +0100 | [diff] [blame] | 35 | extern const struct format_desc fmt_ti_fr; |
Sylvain Munaut | 5e380d0 | 2010-10-29 11:41:16 +0200 | [diff] [blame] | 36 | |
Sylvain Munaut | 0f7e52d | 2010-10-29 11:38:54 +0200 | [diff] [blame] | 37 | static const struct format_desc *supported_formats[_FMT_MAX] = { |
| 38 | [FMT_INVALID] = NULL, |
Sylvain Munaut | 723df06 | 2010-10-29 11:47:06 +0200 | [diff] [blame] | 39 | [FMT_AMR_EFR] = &fmt_amr_efr, |
Sylvain Munaut | 5e380d0 | 2010-10-29 11:41:16 +0200 | [diff] [blame] | 40 | [FMT_GSM] = &fmt_gsm, |
Sylvain Munaut | f905983 | 2010-10-29 11:44:40 +0200 | [diff] [blame] | 41 | [FMT_HR_REF_DEC] = &fmt_hr_ref_dec, |
| 42 | [FMT_HR_REF_ENC] = &fmt_hr_ref_enc, |
Sylvain Munaut | 6c96cc2 | 2010-10-29 11:46:05 +0200 | [diff] [blame] | 43 | [FMT_RACAL_HR] = &fmt_racal_hr, |
| 44 | [FMT_RACAL_FR] = &fmt_racal_fr, |
| 45 | [FMT_RACAL_EFR] = &fmt_racal_efr, |
Sylvain Munaut | 456758c | 2010-11-11 22:58:20 +0100 | [diff] [blame] | 46 | [FMT_RAWPCM_S16LE] = &fmt_rawpcm_s16le, |
Sylvain Munaut | b1525d6 | 2011-02-25 16:58:36 +0100 | [diff] [blame^] | 47 | [FMT_TI_HR] = &fmt_ti_hr, |
Sylvain Munaut | cfaec3a | 2011-02-25 15:31:54 +0100 | [diff] [blame] | 48 | [FMT_TI_FR] = &fmt_ti_fr, |
Sylvain Munaut | 0f7e52d | 2010-10-29 11:38:54 +0200 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | |
| 52 | const struct format_desc * |
| 53 | fmt_get_from_type(enum format_type type) |
| 54 | { |
| 55 | if (type <= FMT_INVALID || type >= _FMT_MAX) |
| 56 | return NULL; |
| 57 | return supported_formats[type]; |
| 58 | } |
Sylvain Munaut | 24b7612 | 2010-10-29 22:45:22 +0200 | [diff] [blame] | 59 | |
| 60 | const struct format_desc * |
| 61 | fmt_get_from_name(const char *name) |
| 62 | { |
| 63 | int i; |
| 64 | for (i=FMT_INVALID+1; i<_FMT_MAX; i++) { |
| 65 | const struct format_desc *fmt = supported_formats[i]; |
| 66 | if (!fmt) |
| 67 | continue; |
| 68 | if (!strcmp(fmt->name, name)) |
| 69 | return fmt; |
| 70 | } |
| 71 | return NULL; |
| 72 | } |