Harald Welte | 8b01f0c | 2017-05-28 11:04:26 +0200 | [diff] [blame^] | 1 | /* AMR RTP Payload according to RFC4867. Only one codec frame per RTP */ |
| 2 | /* (C) 2017 by Harald Welte <laforge@gnumonks.org> */ |
| 3 | |
| 4 | /* |
| 5 | * This file is part of gapk (GSM Audio Pocket Knife). |
| 6 | * |
| 7 | * gapk is free software: you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation, either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * gapk is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with gapk. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | #include <stdint.h> |
| 22 | #include <string.h> |
| 23 | |
| 24 | #include <osmocom/codec/codec.h> |
| 25 | |
| 26 | #include <gapk/codecs.h> |
| 27 | #include <gapk/formats.h> |
| 28 | #include <gapk/utils.h> |
| 29 | |
| 30 | /* conversion function: RTP payload -> canonical format */ |
| 31 | static int |
| 32 | rtp_amr_from_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len) |
| 33 | { |
| 34 | /* add Payload Header according to RFC4867 4.4.1 */ |
| 35 | dst[0] = 0xf0; /* no request */ |
| 36 | memcpy(dst+1, src, src_len); |
| 37 | |
| 38 | return src_len+1; |
| 39 | } |
| 40 | |
| 41 | /* conversion function: canonical format -> RTP payload */ |
| 42 | static int |
| 43 | rtp_amr_to_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len) |
| 44 | { |
| 45 | /* skip Payload Header according to RFC4867 4.4.1 */ |
| 46 | memcpy(dst, src+1, src_len-1); |
| 47 | |
| 48 | return src_len-1; |
| 49 | } |
| 50 | |
| 51 | const struct format_desc fmt_rtp_amr = { |
| 52 | .type = FMT_RTP_AMR, |
| 53 | .codec_type = CODEC_AMR, |
| 54 | .name = "rtp-amr", |
| 55 | .description = "RTP payload for AMR according to RFC4867", |
| 56 | |
| 57 | .frame_len = 0, |
| 58 | .conv_from_canon = rtp_amr_from_canon, |
| 59 | .conv_to_canon = rtp_amr_to_canon, |
| 60 | }; |