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 if(!data)
return data;
47 }
48
50 {
52 }
53
58 {
60 int frames;
61 int i;
64
69 } else {
72 }
73
77 }
79
80 /* The AMR RTP packet consists of one header byte, followed
81 * by one TOC byte for each AMR frame in the packet, followed
82 * by the speech data for all the AMR frames.
83 *
84 * The header byte contains only a codec mode request, for
85 * requesting what kind of AMR data the sender wants to
86 * receive. Not used at the moment.
87 */
88
89 /* Count the number of frames in the packet. The highest bit
90 * is set in a TOC byte if there are more frames following.
91 */
92 for (frames = 1; frames < len && (buf[frames] & 0x80); frames++) ;
93
94 if (1 + frames >= len) {
95 /* We hit the end of the packet while counting frames. */
98 }
99
100 speech_data = buf + 1 + frames;
101
102 /* Everything except the codec mode request byte should be output. */
106 }
109
110 for (i = 0; i < frames; i++) {
112 int frame_size = frame_sizes[(toc >> 3) & 0x0f];
113
114 if (speech_data + frame_size > buf + len) {
115 /* Too little speech data */
117 /* Set the unwritten part of the packet to zero. */
118 memset(ptr, 0, pkt->
data + pkt->
size - ptr);
120 return 0;
121 }
122
123 /* Extract the AMR frame mode from the TOC byte */
124 *ptr++ = toc & 0x7C;
125
126 /* Copy the speech data */
127 memcpy(ptr, speech_data, frame_size);
130 }
131
132 if (speech_data < buf + len) {
134 /* Set the unwritten part of the packet to zero. */
135 memset(ptr, 0, pkt->
data + pkt->
size - ptr);
137 }
138
139 return 0;
140 }
141
143 char *attr,
char *
value)
144 {
145 /* Some AMR SDP configurations contain "octet-align", without
146 * the trailing =1. Therefore, if the value is empty,
147 * interpret it as "1".
148 */
149 if (!strcmp(value, "")) {
151 "nonstandard empty value\n", attr);
152 strcpy(value, "1");
153 }
154 if (!strcmp(attr, "octet-align"))
156 else if (!strcmp(attr, "crc"))
157 data->
crc = atoi(value);
158 else if (!strcmp(attr, "interleaving"))
160 else if (!strcmp(attr, "channels"))
162 return 0;
163 }
164
167 {
168 const char *p;
169 int ret;
170
171 if (st_index < 0)
172 return 0;
173
174 /* Parse an fmtp line this one:
175 * a=fmtp:97 octet-align=1; interleaving=0
176 * That is, a normal fmtp: line followed by semicolon & space
177 * separated key/value pairs.
178 */
184 return -1;
185 }
186 return ret;
187 }
188 return 0;
189 }
190
199 };
200
209 };