blob: 60182fe44e76e45639975ad4362d13dada0a0f88 [file] [log] [blame]
Sylvain Munaut0f7e52d2010-10-29 11:38:54 +02001/* 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 Munaut24b76122010-10-29 22:45:22 +020021#include <string.h>
Sylvain Munaut0f7e52d2010-10-29 11:38:54 +020022
23#include <gapk/formats.h>
24
25/* Extern format descriptors */
Sylvain Munaut723df062010-10-29 11:47:06 +020026extern const struct format_desc fmt_amr_efr;
Sylvain Munaut5e380d02010-10-29 11:41:16 +020027extern const struct format_desc fmt_gsm;
Sylvain Munautf9059832010-10-29 11:44:40 +020028extern const struct format_desc fmt_hr_ref_dec;
29extern const struct format_desc fmt_hr_ref_enc;
Sylvain Munaut6c96cc22010-10-29 11:46:05 +020030extern const struct format_desc fmt_racal_hr;
31extern const struct format_desc fmt_racal_fr;
32extern const struct format_desc fmt_racal_efr;
Sylvain Munaut456758c2010-11-11 22:58:20 +010033extern const struct format_desc fmt_rawpcm_s16le;
Sylvain Munautb1525d62011-02-25 16:58:36 +010034extern const struct format_desc fmt_ti_hr;
Sylvain Munautcfaec3a2011-02-25 15:31:54 +010035extern const struct format_desc fmt_ti_fr;
Sylvain Munaute2c57192011-02-25 18:12:25 +010036extern const struct format_desc fmt_ti_efr;
Harald Welte8b01f0c2017-05-28 11:04:26 +020037extern const struct format_desc fmt_amr_opencore;
38extern const struct format_desc fmt_rtp_amr;
Harald Weltef62e7a42017-05-28 13:46:47 +020039extern const struct format_desc fmt_rtp_efr;
Harald Weltedc3589a2017-05-28 14:09:00 +020040extern const struct format_desc fmt_rtp_hr_etsi;
Harald Welte848db7b2017-05-28 14:17:05 +020041extern const struct format_desc fmt_rtp_hr_ietf;
Sylvain Munaut5e380d02010-10-29 11:41:16 +020042
Sylvain Munaut0f7e52d2010-10-29 11:38:54 +020043static const struct format_desc *supported_formats[_FMT_MAX] = {
44 [FMT_INVALID] = NULL,
Sylvain Munaut723df062010-10-29 11:47:06 +020045 [FMT_AMR_EFR] = &fmt_amr_efr,
Sylvain Munaut5e380d02010-10-29 11:41:16 +020046 [FMT_GSM] = &fmt_gsm,
Sylvain Munautf9059832010-10-29 11:44:40 +020047 [FMT_HR_REF_DEC] = &fmt_hr_ref_dec,
48 [FMT_HR_REF_ENC] = &fmt_hr_ref_enc,
Sylvain Munaut6c96cc22010-10-29 11:46:05 +020049 [FMT_RACAL_HR] = &fmt_racal_hr,
50 [FMT_RACAL_FR] = &fmt_racal_fr,
51 [FMT_RACAL_EFR] = &fmt_racal_efr,
Sylvain Munaut456758c2010-11-11 22:58:20 +010052 [FMT_RAWPCM_S16LE] = &fmt_rawpcm_s16le,
Sylvain Munautb1525d62011-02-25 16:58:36 +010053 [FMT_TI_HR] = &fmt_ti_hr,
Sylvain Munautcfaec3a2011-02-25 15:31:54 +010054 [FMT_TI_FR] = &fmt_ti_fr,
Sylvain Munaute2c57192011-02-25 18:12:25 +010055 [FMT_TI_EFR] = &fmt_ti_efr,
Harald Welte8b01f0c2017-05-28 11:04:26 +020056 [FMT_AMR_OPENCORE] = &fmt_amr_opencore,
57 [FMT_RTP_AMR] = &fmt_rtp_amr,
Harald Weltef62e7a42017-05-28 13:46:47 +020058 [FMT_RTP_EFR] = &fmt_rtp_efr,
Harald Weltedc3589a2017-05-28 14:09:00 +020059 [FMT_RTP_HR_ETSI] = &fmt_rtp_hr_etsi,
Harald Welte848db7b2017-05-28 14:17:05 +020060 [FMT_RTP_HR_IETF] = &fmt_rtp_hr_ietf,
Sylvain Munaut0f7e52d2010-10-29 11:38:54 +020061};
62
63
64const struct format_desc *
65fmt_get_from_type(enum format_type type)
66{
67 if (type <= FMT_INVALID || type >= _FMT_MAX)
68 return NULL;
69 return supported_formats[type];
70}
Sylvain Munaut24b76122010-10-29 22:45:22 +020071
72const struct format_desc *
73fmt_get_from_name(const char *name)
74{
75 int i;
76 for (i=FMT_INVALID+1; i<_FMT_MAX; i++) {
77 const struct format_desc *fmt = supported_formats[i];
78 if (!fmt)
79 continue;
80 if (!strcmp(fmt->name, name))
81 return fmt;
82 }
83 return NULL;
84}