1 /*
2 * Xiph RTP Protocols
3 * Copyright (c) 2009 Colin McQuillian
4 * Copyright (c) 2010 Josh Allmann
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 Xiph / RTP Code
26 * @author Colin McQuillan <m.niloc@gmail.com>
27 * @author Josh Allmann <joshua.allmann@gmail.com>
28 */
29
35
39
40 /**
41 * RTP/Xiph specific private data.
42 */
44 unsigned ident;
///< 24-bit stream configuration identifier
50 };
51
53 {
55 }
56
58 {
64 }
65 }
66
68 {
72 }
73
76 {
77 if (st_index < 0)
78 return 0;
80 return 0;
81 }
82
83
88 {
89
90 int ident, fragmented, tdt, num_pkts, pkt_len;
91
92 if (!buf) {
97 }
103 }
107 }
113 }
114
115 if (len < 6) {
118 }
119
120 // read xiph rtp headers
122 fragmented = buf[3] >> 6;
123 tdt = (buf[3] >> 4) & 3;
124 num_pkts = buf[3] & 0xf;
126
127 if (pkt_len > len - 6) {
129 "Invalid packet length %d in %d byte packet\n", pkt_len,
130 len);
132 }
133
134 if (ident != data->
ident) {
136 "Unimplemented Xiph SDP configuration change detected\n");
138 }
139
140 if (tdt) {
142 "Unimplemented RTP Xiph packet settings (%d,%d,%d)\n",
143 fragmented, tdt, num_pkts);
145 }
146
147 buf += 6; // move past header bits
148 len -= 6;
149
150 if (fragmented == 0) {
154 }
156 memcpy(pkt->
data, buf, pkt_len);
157 buf += pkt_len;
158 len -= pkt_len;
159 num_pkts--;
160
161 if (num_pkts > 0) {
170 }
171 }
176 return 1;
177 }
178
179 return 0;
180
181 } else if (fragmented == 1) {
182 // start of xiph data fragment
184
185 // end packet has been lost somewhere, so drop buffered data
187
190
193
194 } else {
197 // skip if fragmented timestamp is incorrect;
198 // a start packet has been lost somewhere
202 }
205 "Received packet without a start fragment; dropping.\n");
207 }
208
209 // copy data to fragment buffer
211
212 if (fragmented == 3) {
213 // end of xiph data packet
215 if (ret < 0) {
217 "Error occurred when getting fragment buffer.");
219 }
220
221 return 0;
222 }
223 }
224
226 }
227
228 /**
229 * Length encoding described in RFC5215 section 3.1.1.
230 */
232 {
234 for (; *buf < buf_end; ++*
buf) {
235 n <<= 7;
236 n += **buf & 0x7f;
237 if (!(**buf & 0x80)) {
240 }
241 }
242 return 0;
243 }
244
245 /**
246 * Based off parse_packed_headers in Vorbis RTP
247 */
248 static int
250 const uint8_t * packed_headers_end,
252 {
253
254 unsigned num_packed, num_headers,
length, length1, length2, extradata_alloc;
256
257 if (packed_headers_end - packed_headers < 9) {
259 "Invalid %td byte packed header.",
260 packed_headers_end - packed_headers);
262 }
263
264 num_packed = bytestream_get_be32(&packed_headers);
265 xiph_data->
ident = bytestream_get_be24(&packed_headers);
266 length = bytestream_get_be16(&packed_headers);
267 num_headers =
get_base128(&packed_headers, packed_headers_end);
268 length1 =
get_base128(&packed_headers, packed_headers_end);
269 length2 =
get_base128(&packed_headers, packed_headers_end);
270
271 if (num_packed != 1 || num_headers > 3) {
273 "Unimplemented number of headers: %d packed headers, %d headers\n",
274 num_packed, num_headers);
276 }
277
278 if (packed_headers_end - packed_headers != length ||
279 length1 > length || length2 > length - length1) {
281 "Bad packed header lengths (%d,%d,%td,%d)\n", length1,
282 length2, packed_headers_end - packed_headers, length);
284 }
285
286 /* allocate extra space:
287 * -- length/255 +2 for xiphlacing
288 * -- one for the '2' marker
289 * -- FF_INPUT_BUFFER_PADDING_SIZE required */
291
295 }
297 *ptr++ = 2;
300 memcpy(ptr, packed_headers, length);
303 // clear out remaining parts of the buffer
305
306 return 0;
307 }
308
311 char *attr,
char *
value)
312 {
314 int result = 0;
315
316 if (!strcmp(attr, "sampling")) {
317 if (!strcmp(value, "YCbCr-4:2:0")) {
319 } else if (!strcmp(value, "YCbCr-4:4:2")) {
321 } else if (!strcmp(value, "YCbCr-4:4:4")) {
323 } else {
325 "Unsupported pixel format %s\n", attr);
327 }
328 } else if (!strcmp(attr, "width")) {
329 /* This is an integer between 1 and 1048561
330 * and MUST be in multiples of 16. */
331 codec->
width = atoi(value);
332 return 0;
333 } else if (!strcmp(attr, "height")) {
334 /* This is an integer between 1 and 1048561
335 * and MUST be in multiples of 16. */
336 codec->
height = atoi(value);
337 return 0;
338 } else if (!strcmp(attr, "delivery-method")) {
339 /* Possible values are: inline, in_band, out_band/specific_name. */
341 } else if (!strcmp(attr, "configuration-uri")) {
342 /* NOTE: configuration-uri is supported only under 2 conditions:
343 *--after the delivery-method tag
344 * --with a delivery-method value of out_band */
346 } else if (!strcmp(attr, "configuration")) {
347 /* NOTE: configuration is supported only AFTER the delivery-method tag
348 * The configuration value is a base64 encoded packed header */
349 uint8_t *decoded_packet = NULL;
350 int packet_size;
351 size_t decoded_alloc = strlen(value) / 4 * 3 + 4;
352
353 if (decoded_alloc <= INT_MAX) {
354 decoded_packet =
av_malloc(decoded_alloc);
355 if (decoded_packet) {
356 packet_size =
358
360 (decoded_packet, decoded_packet + packet_size, codec,
361 xiph_data);
362 } else {
364 "Out of memory while decoding SDP configuration.\n");
366 }
367 } else {
370 }
372 }
373 return result;
374 }
375
378 {
379 const char *p;
380
381 if (st_index < 0)
382 return 0;
383
387 }
388
389 return 0;
390 }
391
400 };
401
411 };