1 /*
2 * Common code for the RTP depacketization of MPEG-4 formats.
3 * Copyright (c) 2010 Fabrice Bellard
4 * Romain Degez
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 /**
24 * @file
25 * @brief MPEG-4 / RTP Code
26 * @author Fabrice Bellard
27 * @author Romain Degez
28 */
29
36
37 #define MAX_AAC_HBR_FRAME_SIZE 8191
38
39 /** Structure listing useful vars to parse RTP packet payload */
49
50 /** mpeg 4 AU headers */
65
69 };
70
75
76 /** Range for integer values */
82
83 /* All known fmtp parameters and the corresponding RTPAttrTypeEnum */
84 #define ATTR_NAME_TYPE_INT 0
85 #define ATTR_NAME_TYPE_STR 1
89 {0, INT32_MAX} },
92 {0, 32} }, // SizeLength number of bits used to encode AU-size integer value
95 {0, 32} }, // IndexLength number of bits used to encode AU-Index integer value
98 {0, 32} }, // IndexDeltaLength number of bits to encode AU-Index-delta integer value
101 {INT32_MIN, INT32_MAX} }, // It differs depending on StreamType
104 {0x00, 0x3F} }, // Values from ISO/IEC 14496-1, 'StreamType Values' table
107 {0} },
108 {
NULL, -1, -1, {0} },
109 };
110
112 {
115 }
116
118 {
119 /* decode the hexa encoded parameter */
121
125 return 0;
126 }
127
129 {
130 int au_headers_length, au_header_size,
i;
133
136
137 /* decode the first 2 bytes where the AUHeader sections are stored
138 length in bits */
139 au_headers_length =
AV_RB16(buf);
140
142 return -1;
143
144 data->au_headers_length_bytes = (au_headers_length + 7) / 8;
145
146 /* skip AU headers length section (2 bytes) */
147 buf += 2;
149
150 if (len < data->au_headers_length_bytes)
152
156
157 /* XXX: Wrong if optional additional sections are present (cts, dts etc...) */
158 au_header_size =
data->sizelength +
data->indexlength;
159 if (au_header_size <= 0 || (au_headers_length % au_header_size != 0))
160 return -1;
161
162 data->nb_au_headers = au_headers_length / au_header_size;
163 if (!
data->au_headers ||
data->au_headers_allocated <
data->nb_au_headers) {
166 if (!
data->au_headers)
168 data->au_headers_allocated =
data->nb_au_headers;
169 }
170
171 for (
i = 0;
i <
data->nb_au_headers; ++
i) {
174 }
175
176 return 0;
177 }
178
179
180 /* Follows RFC 3640 */
183 const uint8_t *buf,
int len, uint16_t seq,
185 {
187
188
189 if (!buf) {
190 if (
data->cur_au_index >
data->nb_au_headers) {
193 }
194 if (
data->buf_size -
data->buf_pos <
data->au_headers[
data->cur_au_index].size) {
197 }
201 }
203 data->buf_pos +=
data->au_headers[
data->cur_au_index].size;
205 data->cur_au_index++;
206
207 if (
data->cur_au_index ==
data->nb_au_headers) {
209 return 0;
210 }
211
212 return 1;
213 }
214
217 return -1;
218 }
219
220 buf +=
data->au_headers_length_bytes + 2;
221 len -=
data->au_headers_length_bytes + 2;
222 if (
data->nb_au_headers == 1 && len < data->au_headers[0].size) {
223 /* Packet is fragmented */
224
225 if (!
data->buf_pos) {
229 }
230
231 data->buf_size =
data->au_headers[0].size;
232 data->timestamp = *timestamp;
233 }
234
235 if (
data->timestamp != *timestamp ||
236 data->au_headers[0].size !=
data->buf_size ||
242 }
243
246
249
250 if (
data->buf_pos !=
data->buf_size) {
254 }
255
261 }
263
265
266 return 0;
267 }
268
269 if (len < data->au_headers[0].
size) {
272 }
276 }
278 len -=
data->au_headers[0].size;
279 buf +=
data->au_headers[0].size;
281
282 if (
len > 0 &&
data->nb_au_headers > 1) {
284 memcpy(
data->buf, buf,
data->buf_size);
285 data->cur_au_index = 1;
287 return 1;
288 }
289
290 return 0;
291 }
292
295 const char *attr,
const char *
value)
296 {
299
300 if (!strcmp(attr, "config")) {
302
303 if (res < 0)
304 return res;
305 }
306
308 /* Looking for a known attribute */
312 char *end_ptr =
NULL;
313 long long int val = strtoll(
value, &end_ptr, 10);
314 if (end_ptr ==
value || end_ptr[0] !=
'0円') {
316 "The %s field value is not a valid number: %s\n",
319 }
323 "fmtp field %s should be in range [%d,%d] (provided value: %lld)",
326 }
327
328 *(
int *)((
char *)
data+
334 *(
char **)((
char *)
data+
336 }
337 }
338 }
339 if (!strcmp(attr, "bitrate")) {
341 }
342 }
343 return 0;
344 }
345
348 {
350
351 if (st_index < 0)
352 return 0;
353
356
357 return 0;
358 }
359
367 };
368
378 };