diff options
author | Harald Welte <laforge@gnumonks.org> | 2017-05-28 13:46:47 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2017-05-28 16:18:09 +0200 |
commit | f62e7a4936d2785f6c7711f5528ebdafd581b572 (patch) | |
tree | 82f0b25eec3cbda7e6bd25bf6ad81d0b84e63c6f /src | |
parent | 526fc6e5e906937c3227b88c238d2a6d7e520434 (diff) |
Add "rtp-efr" format support for RTP payload according to RFC3551 4.5.9
The RTP EFR payload is a bit like the FR payload: one nibble magic
marker, then followed by the actual codec bits. So we need to
add/remove that magic marker and shift the remainder by one nibble.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/fmt_rtp_efr.c | 73 | ||||
-rw-r--r-- | src/formats.c | 2 |
3 files changed, 76 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 07f1d51..c62e4e7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -6,7 +6,7 @@ AM_LDFLAGS=$(LIBOSMOCODEC_LIBS) $(LIBOSMOCORE_LIBS) \ COM_SOURCES = procqueue.c pq_file.c pq_format.c pq_codec.c pq_rtp.c pq_alsa.c \ formats.c fmt_amr.c fmt_gsm.c fmt_hr_ref.c fmt_racal.c \ - fmt_amr_opencore.c fmt_rtp_amr.c fmt_rawpcm.c fmt_ti.c benchmark.c \ + fmt_amr_opencore.c fmt_rtp_amr.c fmt_rtp_efr.c fmt_rawpcm.c fmt_ti.c benchmark.c \ codecs.c codec_pcm.c codec_hr.c codec_fr.c codec_efr.c codec_amr.c bin_PROGRAMS = gapk diff --git a/src/fmt_rtp_efr.c b/src/fmt_rtp_efr.c new file mode 100644 index 0000000..0132e32 --- /dev/null +++ b/src/fmt_rtp_efr.c @@ -0,0 +1,73 @@ +/* EFR RTP Payload according to RFC3551. Only one codec frame per RTP */ +/* (C) 2017 by Harald Welte <laforge@gnumonks.org> */ + +/* + * This file is part of gapk (GSM Audio Pocket Knife). + * + * gapk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gapk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gapk. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdint.h> +#include <assert.h> + +#include <osmocom/codec/codec.h> + +#include <gapk/codecs.h> +#include <gapk/formats.h> +#include <gapk/utils.h> + +#define EFR_LEN 31 +#define EFR_MAGIC 0xc + +/* conversion function: RTP payload -> canonical format */ +static int +rtp_efr_from_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len) +{ + int i; + + /* according to RFC3551 4.5.9 */ + assert(src_len == EFR_CANON_LEN); + + dst[0] = (EFR_MAGIC << 4) | (src[0] >> 4); + for (i=1; i<EFR_LEN; i++) + dst[i] = (src[i-1] << 4) | (src[i] >> 4); + + return EFR_LEN; +} + +/* conversion function: canonical format -> RTP payload */ +static int +rtp_efr_to_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len) +{ + int i; + + assert(src_len == EFR_LEN); + + for (i=0; i<(EFR_LEN-1); i++) + dst[i] = (src[i] << 4) | (src[i+1] >> 4); + dst[EFR_LEN-1] = src[EFR_LEN-1] << 4; + + return EFR_CANON_LEN; +} + +const struct format_desc fmt_rtp_efr = { + .type = FMT_RTP_EFR, + .codec_type = CODEC_EFR, + .name = "rtp-efr", + .description = "RTP payload for EFR according to RFC3551", + + .frame_len = EFR_LEN, + .conv_from_canon = rtp_efr_from_canon, + .conv_to_canon = rtp_efr_to_canon, +}; diff --git a/src/formats.c b/src/formats.c index 0d4c4a0..6b2ee91 100644 --- a/src/formats.c +++ b/src/formats.c @@ -36,6 +36,7 @@ extern const struct format_desc fmt_ti_fr; extern const struct format_desc fmt_ti_efr; extern const struct format_desc fmt_amr_opencore; extern const struct format_desc fmt_rtp_amr; +extern const struct format_desc fmt_rtp_efr; static const struct format_desc *supported_formats[_FMT_MAX] = { [FMT_INVALID] = NULL, @@ -52,6 +53,7 @@ static const struct format_desc *supported_formats[_FMT_MAX] = { [FMT_TI_EFR] = &fmt_ti_efr, [FMT_AMR_OPENCORE] = &fmt_amr_opencore, [FMT_RTP_AMR] = &fmt_rtp_amr, + [FMT_RTP_EFR] = &fmt_rtp_efr, }; |