1 /*
2 * RTP AMR Depacketizer, RFC 3267
3 * Copyright (c) 2010 Martin Storsjo
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg 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 GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
26
28 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0
29 };
31 17, 23, 32, 36, 40, 46, 50, 58, 60, 5, 5, 0, 0, 0, 0, 0
32 };
33
39 };
40
42 {
44 return 0;
45 }
46
49 const uint8_t *buf,
int len, uint16_t seq,
51 {
55 const uint8_t *speech_data;
56 uint8_t *ptr;
57
62 } else {
65 }
66
70 }
72
73 /* The AMR RTP packet consists of one header byte, followed
74 * by one TOC byte for each AMR frame in the packet, followed
75 * by the speech data for all the AMR frames.
76 *
77 * The header byte contains only a codec mode request, for
78 * requesting what kind of AMR data the sender wants to
79 * receive. Not used at the moment.
80 */
81
82 /* Count the number of frames in the packet. The highest bit
83 * is set in a TOC byte if there are more frames following.
84 */
86
88 /* We hit the end of the packet while counting frames. */
91 }
92
93 speech_data = buf + 1 +
frames;
94
95 /* Everything except the codec mode request byte should be output. */
99 }
102
104 uint8_t toc = buf[1 +
i];
106
108 /* Too little speech data */
110 /* Set the unwritten part of the packet to zero. */
113 return 0;
114 }
115
116 /* Extract the AMR frame mode from the TOC byte */
117 *ptr++ = toc & 0x7C;
118
119 /* Copy the speech data */
123 }
124
125 if (speech_data < buf +
len) {
127 /* Set the unwritten part of the packet to zero. */
130 }
131
132 return 0;
133 }
134
137 const char *attr,
const char *
value)
138 {
139 /* Some AMR SDP configurations contain "octet-align", without
140 * the trailing =1. Therefore, if the value is empty,
141 * interpret it as "1".
142 */
143 if (!strcmp(
value,
"")) {
145 "nonstandard empty value\n", attr);
147 }
148 if (!strcmp(attr, "octet-align"))
150 else if (!strcmp(attr, "crc"))
152 else if (!strcmp(attr, "interleaving"))
154 else if (!strcmp(attr, "channels"))
156 return 0;
157 }
158
161 {
162 const char *p;
164
165 if (st_index < 0)
166 return 0;
167
168 /* Parse an fmtp line this one:
169 * a=fmtp:97 octet-align=1; interleaving=0
170 * That is, a normal fmtp: line followed by semicolon & space
171 * separated key/value pairs.
172 */
175 if (!
data->octet_align ||
data->crc ||
176 data->interleaving ||
data->channels != 1) {
178 return -1;
179 }
181 }
182 return 0;
183 }
184
193 };
194
203 };