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
35
36 #define MAX_AAC_HBR_FRAME_SIZE 8191
37
38 /** Structure listing useful vars to parse RTP packet payload */
47
48 /** mpeg 4 AU headers */
63
67 };
68
73
74 /** Range for integer values */
80
81 /* All known fmtp parameters and the corresponding RTPAttrTypeEnum */
82 #define ATTR_NAME_TYPE_INT 0
83 #define ATTR_NAME_TYPE_STR 1
87 {0, 32} }, // SizeLength number of bits used to encode AU-size integer value
90 {0, 32} }, // IndexLength number of bits used to encode AU-Index integer value
93 {0, 32} }, // IndexDeltaLength number of bits to encode AU-Index-delta integer value
96 {INT32_MIN, INT32_MAX} }, // It differs depending on StreamType
99 {0x00, 0x3F} }, // Values from ISO/IEC 14496-1, 'StreamType Values' table
102 {0} },
103 {
NULL, -1, -1, {0} },
104 };
105
107 {
110 }
111
113 {
114 /* decode the hexa encoded parameter */
116
120 return 0;
121 }
122
124 {
125 int au_headers_length, au_header_size,
i;
127
130
131 /* decode the first 2 bytes where the AUHeader sections are stored
132 length in bits */
133 au_headers_length =
AV_RB16(buf);
134
136 return -1;
137
138 data->au_headers_length_bytes = (au_headers_length + 7) / 8;
139
140 /* skip AU headers length section (2 bytes) */
141 buf += 2;
143
144 if (len < data->au_headers_length_bytes)
146
148
149 /* XXX: Wrong if optional additional sections are present (cts, dts etc...) */
150 au_header_size =
data->sizelength +
data->indexlength;
151 if (au_header_size <= 0 || (au_headers_length % au_header_size != 0))
152 return -1;
153
154 data->nb_au_headers = au_headers_length / au_header_size;
155 if (!
data->au_headers ||
data->au_headers_allocated <
data->nb_au_headers) {
158 if (!
data->au_headers)
160 data->au_headers_allocated =
data->nb_au_headers;
161 }
162
163 for (
i = 0;
i <
data->nb_au_headers; ++
i) {
166 }
167
168 return 0;
169 }
170
171
172 /* Follows RFC 3640 */
175 const uint8_t *buf,
int len, uint16_t seq,
177 {
179
180
181 if (!buf) {
182 if (
data->cur_au_index >
data->nb_au_headers) {
185 }
186 if (
data->buf_size -
data->buf_pos <
data->au_headers[
data->cur_au_index].size) {
189 }
193 }
195 data->buf_pos +=
data->au_headers[
data->cur_au_index].size;
197 data->cur_au_index++;
198
199 if (
data->cur_au_index ==
data->nb_au_headers) {
201 return 0;
202 }
203
204 return 1;
205 }
206
209 return -1;
210 }
211
212 buf +=
data->au_headers_length_bytes + 2;
213 len -=
data->au_headers_length_bytes + 2;
214 if (
data->nb_au_headers == 1 && len < data->au_headers[0].size) {
215 /* Packet is fragmented */
216
217 if (!
data->buf_pos) {
221 }
222
223 data->buf_size =
data->au_headers[0].size;
224 data->timestamp = *timestamp;
225 }
226
227 if (
data->timestamp != *timestamp ||
228 data->au_headers[0].size !=
data->buf_size ||
234 }
235
238
241
242 if (
data->buf_pos !=
data->buf_size) {
246 }
247
253 }
255
257
258 return 0;
259 }
260
261 if (len < data->au_headers[0].
size) {
264 }
268 }
270 len -=
data->au_headers[0].size;
271 buf +=
data->au_headers[0].size;
273
274 if (
len > 0 &&
data->nb_au_headers > 1) {
276 memcpy(
data->buf, buf,
data->buf_size);
277 data->cur_au_index = 1;
279 return 1;
280 }
281
282 return 0;
283 }
284
287 const char *attr,
const char *
value)
288 {
291
292 if (!strcmp(attr, "config")) {
294
295 if (res < 0)
296 return res;
297 }
298
300 /* Looking for a known attribute */
304 char *end_ptr =
NULL;
305 long long int val = strtoll(
value, &end_ptr, 10);
306 if (end_ptr ==
value || end_ptr[0] !=
'0円') {
308 "The %s field value is not a valid number: %s\n",
311 }
315 "fmtp field %s should be in range [%d,%d] (provided value: %lld)",
318 }
319
320 *(
int *)((
char *)
data+
326 *(
char **)((
char *)
data+
328 }
329 }
330 }
331 }
332 return 0;
333 }
334
337 {
338 const char *p;
339
340 if (st_index < 0)
341 return 0;
342
345
346 return 0;
347 }
348
356 };
357
366 };