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
34
37
38 /**
39 * RTP/Xiph specific private data.
40 */
42 unsigned ident;
///< 24-bit stream configuration identifier
48 };
49
51 {
53 }
54
56 {
62 }
63 }
64
66 {
70 }
71
74 {
75 if (st_index < 0)
76 return 0;
78 return 0;
79 }
80
81
86 {
87
88 int ident, fragmented, tdt, num_pkts, pkt_len;
89
90 if (!buf) {
95 }
101 }
105 }
111 }
112
113 if (len < 6) {
116 }
117
118 // read xiph rtp headers
120 fragmented = buf[3] >> 6;
121 tdt = (buf[3] >> 4) & 3;
122 num_pkts = buf[3] & 0xf;
124
125 if (pkt_len > len - 6) {
127 "Invalid packet length %d in %d byte packet\n", pkt_len,
128 len);
130 }
131
132 if (ident != data->
ident) {
134 "Unimplemented Xiph SDP configuration change detected\n");
136 }
137
138 if (tdt) {
140 "Unimplemented RTP Xiph packet settings (%d,%d,%d)\n",
141 fragmented, tdt, num_pkts);
143 }
144
145 buf += 6; // move past header bits
146 len -= 6;
147
148 if (fragmented == 0) {
152 }
154 memcpy(pkt->
data, buf, pkt_len);
155 buf += pkt_len;
156 len -= pkt_len;
157 num_pkts--;
158
159 if (num_pkts > 0) {
168 }
169 }
174 return 1;
175 }
176
177 return 0;
178
179 } else if (fragmented == 1) {
180 // start of xiph data fragment
181 int res;
182
183 // end packet has been lost somewhere, so drop buffered data
185
187 return res;
188
191
192 } else {
195 // skip if fragmented timestamp is incorrect;
196 // a start packet has been lost somewhere
200 }
203 "Received packet without a start fragment; dropping.\n");
205 }
206
207 // copy data to fragment buffer
209
210 if (fragmented == 3) {
211 // end of xiph data packet
213 if (ret < 0) {
215 "Error occurred when getting fragment buffer.");
216 return ret;
217 }
218
219 return 0;
220 }
221 }
222
224 }
225
226 /**
227 * Length encoding described in RFC5215 section 3.1.1.
228 */
230 {
231 int n = 0;
232 for (; *buf < buf_end; ++*buf) {
233 n <<= 7;
234 n += **buf & 0x7f;
235 if (!(**buf & 0x80)) {
236 ++*buf;
237 return n;
238 }
239 }
240 return 0;
241 }
242
243 /**
244 * Based off parse_packed_headers in Vorbis RTP
245 */
246 static int
248 const uint8_t * packed_headers_end,
250 {
251
252 unsigned num_packed, num_headers, length, length1, length2, extradata_alloc;
254
255 if (packed_headers_end - packed_headers < 9) {
257 "Invalid %td byte packed header.",
258 packed_headers_end - packed_headers);
260 }
261
262 num_packed = bytestream_get_be32(&packed_headers);
263 xiph_data->
ident = bytestream_get_be24(&packed_headers);
264 length = bytestream_get_be16(&packed_headers);
265 num_headers =
get_base128(&packed_headers, packed_headers_end);
266 length1 =
get_base128(&packed_headers, packed_headers_end);
267 length2 =
get_base128(&packed_headers, packed_headers_end);
268
269 if (num_packed != 1 || num_headers > 3) {
271 "Unimplemented number of headers: %d packed headers, %d headers\n",
272 num_packed, num_headers);
274 }
275
276 if (packed_headers_end - packed_headers != length ||
277 length1 > length || length2 > length - length1) {
279 "Bad packed header lengths (%d,%d,%td,%d)\n", length1,
280 length2, packed_headers_end - packed_headers, length);
282 }
283
284 /* allocate extra space:
285 * -- length/255 +2 for xiphlacing
286 * -- one for the '2' marker
287 * -- FF_INPUT_BUFFER_PADDING_SIZE required */
289
291 if (!ptr) {
294 }
295 *ptr++ = 2;
298 memcpy(ptr, packed_headers, length);
299 ptr += length;
301 // clear out remaining parts of the buffer
303
304 return 0;
305 }
306
309 char *attr,
char *
value)
310 {
312 int result = 0;
313
314 if (!strcmp(attr, "sampling")) {
315 if (!strcmp(value, "YCbCr-4:2:0")) {
317 } else if (!strcmp(value, "YCbCr-4:4:2")) {
319 } else if (!strcmp(value, "YCbCr-4:4:4")) {
321 } else {
323 "Unsupported pixel format %s\n", attr);
325 }
326 } else if (!strcmp(attr, "width")) {
327 /* This is an integer between 1 and 1048561
328 * and MUST be in multiples of 16. */
329 codec->
width = atoi(value);
330 return 0;
331 } else if (!strcmp(attr, "height")) {
332 /* This is an integer between 1 and 1048561
333 * and MUST be in multiples of 16. */
334 codec->
height = atoi(value);
335 return 0;
336 } else if (!strcmp(attr, "delivery-method")) {
337 /* Possible values are: inline, in_band, out_band/specific_name. */
339 } else if (!strcmp(attr, "configuration-uri")) {
340 /* NOTE: configuration-uri is supported only under 2 conditions:
341 *--after the delivery-method tag
342 * --with a delivery-method value of out_band */
344 } else if (!strcmp(attr, "configuration")) {
345 /* NOTE: configuration is supported only AFTER the delivery-method tag
346 * The configuration value is a base64 encoded packed header */
348 int packet_size;
349 size_t decoded_alloc = strlen(value) / 4 * 3 + 4;
350
351 if (decoded_alloc <= INT_MAX) {
352 decoded_packet =
av_malloc(decoded_alloc);
353 if (decoded_packet) {
354 packet_size =
356
358 (decoded_packet, decoded_packet + packet_size, codec,
359 xiph_data);
360 } else {
362 "Out of memory while decoding SDP configuration.\n");
364 }
365 } else {
368 }
370 }
371 return result;
372 }
373
376 {
377 const char *p;
378
379 if (st_index < 0)
380 return 0;
381
385 }
386
387 return 0;
388 }
389
398 };
399
409 };