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 */
48
49 /** mpeg 4 AU headers */
64
68 };
69
74
75 /** Range for integer values */
81
82 /* All known fmtp parameters and the corresponding RTPAttrTypeEnum */
83 #define ATTR_NAME_TYPE_INT 0
84 #define ATTR_NAME_TYPE_STR 1
88 {0, 32} }, // SizeLength number of bits used to encode AU-size integer value
91 {0, 32} }, // IndexLength number of bits used to encode AU-Index integer value
94 {0, 32} }, // IndexDeltaLength number of bits to encode AU-Index-delta integer value
97 {INT32_MIN, INT32_MAX} }, // It differs depending on StreamType
100 {0x00, 0x3F} }, // Values from ISO/IEC 14496-1, 'StreamType Values' table
103 {0} },
104 {
NULL, -1, -1, {0} },
105 };
106
108 {
111 }
112
114 {
115 /* decode the hexa encoded parameter */
117
121 return 0;
122 }
123
125 {
126 int au_headers_length, au_header_size,
i;
129
132
133 /* decode the first 2 bytes where the AUHeader sections are stored
134 length in bits */
135 au_headers_length =
AV_RB16(buf);
136
138 return -1;
139
140 data->au_headers_length_bytes = (au_headers_length + 7) / 8;
141
142 /* skip AU headers length section (2 bytes) */
143 buf += 2;
145
146 if (len < data->au_headers_length_bytes)
148
152
153 /* XXX: Wrong if optional additional sections are present (cts, dts etc...) */
154 au_header_size =
data->sizelength +
data->indexlength;
155 if (au_header_size <= 0 || (au_headers_length % au_header_size != 0))
156 return -1;
157
158 data->nb_au_headers = au_headers_length / au_header_size;
159 if (!
data->au_headers ||
data->au_headers_allocated <
data->nb_au_headers) {
162 if (!
data->au_headers)
164 data->au_headers_allocated =
data->nb_au_headers;
165 }
166
167 for (
i = 0;
i <
data->nb_au_headers; ++
i) {
170 }
171
172 return 0;
173 }
174
175
176 /* Follows RFC 3640 */
179 const uint8_t *buf,
int len, uint16_t seq,
181 {
183
184
185 if (!buf) {
186 if (
data->cur_au_index >
data->nb_au_headers) {
189 }
190 if (
data->buf_size -
data->buf_pos <
data->au_headers[
data->cur_au_index].size) {
193 }
197 }
199 data->buf_pos +=
data->au_headers[
data->cur_au_index].size;
201 data->cur_au_index++;
202
203 if (
data->cur_au_index ==
data->nb_au_headers) {
205 return 0;
206 }
207
208 return 1;
209 }
210
213 return -1;
214 }
215
216 buf +=
data->au_headers_length_bytes + 2;
217 len -=
data->au_headers_length_bytes + 2;
218 if (
data->nb_au_headers == 1 && len < data->au_headers[0].size) {
219 /* Packet is fragmented */
220
221 if (!
data->buf_pos) {
225 }
226
227 data->buf_size =
data->au_headers[0].size;
228 data->timestamp = *timestamp;
229 }
230
231 if (
data->timestamp != *timestamp ||
232 data->au_headers[0].size !=
data->buf_size ||
238 }
239
242
245
246 if (
data->buf_pos !=
data->buf_size) {
250 }
251
257 }
259
261
262 return 0;
263 }
264
265 if (len < data->au_headers[0].
size) {
268 }
272 }
274 len -=
data->au_headers[0].size;
275 buf +=
data->au_headers[0].size;
277
278 if (
len > 0 &&
data->nb_au_headers > 1) {
280 memcpy(
data->buf, buf,
data->buf_size);
281 data->cur_au_index = 1;
283 return 1;
284 }
285
286 return 0;
287 }
288
291 const char *attr,
const char *
value)
292 {
295
296 if (!strcmp(attr, "config")) {
298
299 if (res < 0)
300 return res;
301 }
302
304 /* Looking for a known attribute */
308 char *end_ptr =
NULL;
309 long long int val = strtoll(
value, &end_ptr, 10);
310 if (end_ptr ==
value || end_ptr[0] !=
'0円') {
312 "The %s field value is not a valid number: %s\n",
315 }
319 "fmtp field %s should be in range [%d,%d] (provided value: %lld)",
322 }
323
324 *(
int *)((
char *)
data+
330 *(
char **)((
char *)
data+
332 }
333 }
334 }
335 }
336 return 0;
337 }
338
341 {
342 const char *p;
343
344 if (st_index < 0)
345 return 0;
346
349
350 return 0;
351 }
352
360 };
361
370 };