FFmpeg
Loading...
Searching...
No Matches
rtmppkt.c
Go to the documentation of this file.
1/*
2 * RTMP input format
3 * Copyright (c) 2009 Konstantin Shishkov
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
24#include "libavutil/intfloat.h"
25#include "libavutil/mem.h"
26
27#include "rtmppkt.h"
28#include "flv.h"
29#include "url.h"
30
31#define MAX_DEPTH 16 ///< arbitrary limit to prevent unbounded recursion
32
33void ff_amf_write_bool(uint8_t **dst, int val)
34{
35 bytestream_put_byte(dst, AMF_DATA_TYPE_BOOL);
36 bytestream_put_byte(dst, val);
37}
38
39void ff_amf_write_number(uint8_t **dst, double val)
40{
41 bytestream_put_byte(dst, AMF_DATA_TYPE_NUMBER);
42 bytestream_put_be64(dst, av_double2int(val));
43}
44
45void ff_amf_write_array_start(uint8_t **dst, uint32_t length)
46{
47 bytestream_put_byte(dst, AMF_DATA_TYPE_ARRAY);
48 bytestream_put_be32(dst, length);
49}
50
51void ff_amf_write_string(uint8_t **dst, const char *str)
52{
53 bytestream_put_byte(dst, AMF_DATA_TYPE_STRING);
54 bytestream_put_be16(dst, strlen(str));
55 bytestream_put_buffer(dst, str, strlen(str));
56}
57
58void ff_amf_write_string2(uint8_t **dst, const char *str1, const char *str2)
59{
60 int len1 = 0, len2 = 0;
61 if (str1)
62 len1 = strlen(str1);
63 if (str2)
64 len2 = strlen(str2);
65 bytestream_put_byte(dst, AMF_DATA_TYPE_STRING);
66 bytestream_put_be16(dst, len1 + len2);
67 bytestream_put_buffer(dst, str1, len1);
68 bytestream_put_buffer(dst, str2, len2);
69}
70
71void ff_amf_write_null(uint8_t **dst)
72{
73 bytestream_put_byte(dst, AMF_DATA_TYPE_NULL);
74}
75
77{
78 bytestream_put_byte(dst, AMF_DATA_TYPE_OBJECT);
79}
80
81void ff_amf_write_field_name(uint8_t **dst, const char *str)
82{
83 bytestream_put_be16(dst, strlen(str));
84 bytestream_put_buffer(dst, str, strlen(str));
85}
86
88{
89 /* first two bytes are field name length = 0,
90 * AMF object should end with it and end marker
91 */
92 bytestream_put_be24(dst, AMF_DATA_TYPE_OBJECT_END);
93}
94
96{
97 uint64_t read;
98 if (bytestream2_get_byte(bc) != AMF_DATA_TYPE_NUMBER)
100 read = bytestream2_get_be64(bc);
102 return 0;
103}
104
105int ff_amf_get_string(GetByteContext *bc, uint8_t *str,
106 int strsize, int *length)
107{
108 int stringlen = 0;
109 int readsize;
110 stringlen = bytestream2_get_be16(bc);
111 if (stringlen + 1 > strsize)
112 return AVERROR(EINVAL);
113 readsize = bytestream2_get_buffer(bc, str, stringlen);
114 if (readsize != stringlen) {
116 "Unable to read as many bytes as AMF string signaled\n");
117 }
118 str[readsize] = '\0';
119 *length = FFMIN(stringlen, readsize);
120 return 0;
121}
122
123int ff_amf_read_string(GetByteContext *bc, uint8_t *str,
124 int strsize, int *length)
125{
126 if (bytestream2_get_byte(bc) != AMF_DATA_TYPE_STRING)
127 return AVERROR_INVALIDDATA;
128 return ff_amf_get_string(bc, str, strsize, length);
129}
130
132{
133 if (bytestream2_get_byte(bc) != AMF_DATA_TYPE_NULL)
134 return AVERROR_INVALIDDATA;
135 return 0;
136}
137
138int ff_rtmp_check_alloc_array(RTMPPacket **prev_pkt, int *nb_prev_pkt,
139 int channel)
140{
141 int nb_alloc;
142 RTMPPacket *ptr;
143 if (channel < *nb_prev_pkt)
144 return 0;
145
146 nb_alloc = channel + 16;
147 // This can't use the av_reallocp family of functions, since we
148 // would need to free each element in the array before the array
149 // itself is freed.
150 ptr = av_realloc_array(*prev_pkt, nb_alloc, sizeof(**prev_pkt));
151 if (!ptr)
152 return AVERROR(ENOMEM);
153 memset(ptr + *nb_prev_pkt, 0, (nb_alloc - *nb_prev_pkt) * sizeof(*ptr));
154 *prev_pkt = ptr;
155 *nb_prev_pkt = nb_alloc;
156 return 0;
157}
158
160 int chunk_size, RTMPPacket **prev_pkt, int *nb_prev_pkt)
161{
162 uint8_t hdr;
163
164 if (ffurl_read(h, &hdr, 1) != 1)
165 return AVERROR(EIO);
166
167 return ff_rtmp_packet_read_internal(h, p, chunk_size, prev_pkt,
168 nb_prev_pkt, hdr);
169}
170
172 int chunk_size, RTMPPacket **prev_pkt_ptr,
173 int *nb_prev_pkt, uint8_t hdr)
174{
175
176 uint8_t buf[16];
177 int channel_id, timestamp, size;
178 uint32_t ts_field; // non-extended timestamp or delta field
179 uint32_t extra = 0;
180 enum RTMPPacketType type;
181 int written = 0;
182 int ret, toread;
183 RTMPPacket *prev_pkt;
184
185 written++;
186 channel_id = hdr & 0x3F;
187
188 if (channel_id < 2) { //special case for channel number >= 64
189 buf[1] = 0;
190 if (ffurl_read_complete(h, buf, channel_id + 1) != channel_id + 1)
191 return AVERROR(EIO);
192 written += channel_id + 1;
193 channel_id = AV_RL16(buf) + 64;
194 }
195 if ((ret = ff_rtmp_check_alloc_array(prev_pkt_ptr, nb_prev_pkt,
196 channel_id)) < 0)
197 return ret;
198 prev_pkt = *prev_pkt_ptr;
199 size = prev_pkt[channel_id].size;
200 type = prev_pkt[channel_id].type;
201 extra = prev_pkt[channel_id].extra;
202
203 hdr >>= 6; // header size indicator
204 if (hdr == RTMP_PS_ONEBYTE) {
205 ts_field = prev_pkt[channel_id].ts_field;
206 } else {
207 if (ffurl_read_complete(h, buf, 3) != 3)
208 return AVERROR(EIO);
209 written += 3;
210 ts_field = AV_RB24(buf);
211 if (hdr != RTMP_PS_FOURBYTES) {
212 if (ffurl_read_complete(h, buf, 3) != 3)
213 return AVERROR(EIO);
214 written += 3;
215 size = AV_RB24(buf);
216 if (ffurl_read_complete(h, buf, 1) != 1)
217 return AVERROR(EIO);
218 written++;
219 type = buf[0];
220 if (hdr == RTMP_PS_TWELVEBYTES) {
221 if (ffurl_read_complete(h, buf, 4) != 4)
222 return AVERROR(EIO);
223 written += 4;
224 extra = AV_RL32(buf);
225 }
226 }
227 }
228 if (ts_field == 0xFFFFFF) {
229 if (ffurl_read_complete(h, buf, 4) != 4)
230 return AVERROR(EIO);
231 timestamp = AV_RB32(buf);
232 } else {
233 timestamp = ts_field;
234 }
235 if (hdr != RTMP_PS_TWELVEBYTES)
236 timestamp += prev_pkt[channel_id].timestamp;
237
238 if (prev_pkt[channel_id].read && size != prev_pkt[channel_id].size) {
239 av_log(h, AV_LOG_ERROR, "RTMP packet size mismatch %d != %d\n",
240 size, prev_pkt[channel_id].size);
241 ff_rtmp_packet_destroy(&prev_pkt[channel_id]);
242 prev_pkt[channel_id].read = 0;
243 return AVERROR_INVALIDDATA;
244 }
245
246 if (!prev_pkt[channel_id].read) {
247 if ((ret = ff_rtmp_packet_create(p, channel_id, type, timestamp,
248 size)) < 0)
249 return ret;
250 p->read = written;
251 p->offset = 0;
252 prev_pkt[channel_id].ts_field = ts_field;
253 prev_pkt[channel_id].timestamp = timestamp;
254 } else {
255 // previous packet in this channel hasn't completed reading
256 RTMPPacket *prev = &prev_pkt[channel_id];
257 p->data = prev->data;
258 p->size = prev->size;
259 p->channel_id = prev->channel_id;
260 p->type = prev->type;
261 p->ts_field = prev->ts_field;
262 p->extra = prev->extra;
263 p->offset = prev->offset;
264 p->read = prev->read + written;
265 p->timestamp = prev->timestamp;
266 prev->data = NULL;
267 }
268 p->extra = extra;
269 // save history
270 prev_pkt[channel_id].channel_id = channel_id;
271 prev_pkt[channel_id].type = type;
272 prev_pkt[channel_id].size = size;
273 prev_pkt[channel_id].extra = extra;
274 size = size - p->offset;
275
276 toread = FFMIN(size, chunk_size);
277 if (ffurl_read_complete(h, p->data + p->offset, toread) != toread) {
279 prev_pkt[channel_id].read = 0;
280 return AVERROR(EIO);
281 }
282 size -= toread;
283 p->read += toread;
284 p->offset += toread;
285
286 if (size > 0) {
287 RTMPPacket *prev = &prev_pkt[channel_id];
288 prev->data = p->data;
289 prev->read = p->read;
290 prev->offset = p->offset;
291 p->data = NULL;
292 return AVERROR(EAGAIN);
293 }
294
295 prev_pkt[channel_id].read = 0; // read complete; reset if needed
296 return p->read;
297}
298
300 RTMPPacket **prev_pkt, int *nb_prev_pkt,
301 uint8_t hdr)
302{
303 while (1) {
304 int ret = rtmp_packet_read_one_chunk(h, p, chunk_size, prev_pkt,
305 nb_prev_pkt, hdr);
306 if (ret > 0 || ret != AVERROR(EAGAIN))
307 return ret;
308
309 if (ffurl_read(h, &hdr, 1) != 1)
310 return AVERROR(EIO);
311 }
312}
313
315 int chunk_size, RTMPPacket **prev_pkt_ptr,
316 int *nb_prev_pkt)
317{
318 uint8_t pkt_hdr[18], *p = pkt_hdr;
319 int basic_hdr_size;
321 int off = 0;
322 int written = 0;
323 int ret;
324 RTMPPacket *prev_pkt;
325 int use_delta; // flag if using timestamp delta, not RTMP_PS_TWELVEBYTES
326 uint32_t timestamp; // full 32-bit timestamp or delta value
327
328 if ((ret = ff_rtmp_check_alloc_array(prev_pkt_ptr, nb_prev_pkt,
329 pkt->channel_id)) < 0)
330 return ret;
331 prev_pkt = *prev_pkt_ptr;
332
333 //if channel_id = 0, this is first presentation of prev_pkt, send full hdr.
334 use_delta = prev_pkt[pkt->channel_id].channel_id &&
335 pkt->extra == prev_pkt[pkt->channel_id].extra &&
336 pkt->timestamp >= prev_pkt[pkt->channel_id].timestamp;
337
338 timestamp = pkt->timestamp;
339 if (use_delta) {
340 timestamp -= prev_pkt[pkt->channel_id].timestamp;
341 }
342 if (timestamp >= 0xFFFFFF) {
343 pkt->ts_field = 0xFFFFFF;
344 } else {
345 pkt->ts_field = timestamp;
346 }
347
348 if (use_delta) {
349 if (pkt->type == prev_pkt[pkt->channel_id].type &&
350 pkt->size == prev_pkt[pkt->channel_id].size) {
352 if (pkt->ts_field == prev_pkt[pkt->channel_id].ts_field)
354 } else {
356 }
357 }
358
359 if (pkt->channel_id < 64) {
360 bytestream_put_byte(&p, pkt->channel_id | (mode << 6));
361 } else if (pkt->channel_id < 64 + 256) {
362 bytestream_put_byte(&p, 0 | (mode << 6));
363 bytestream_put_byte(&p, pkt->channel_id - 64);
364 } else {
365 bytestream_put_byte(&p, 1 | (mode << 6));
366 bytestream_put_le16(&p, pkt->channel_id - 64);
367 }
368 basic_hdr_size = p - pkt_hdr;
369 if (mode != RTMP_PS_ONEBYTE) {
370 bytestream_put_be24(&p, pkt->ts_field);
371 if (mode != RTMP_PS_FOURBYTES) {
372 bytestream_put_be24(&p, pkt->size);
373 bytestream_put_byte(&p, pkt->type);
375 bytestream_put_le32(&p, pkt->extra);
376 }
377 }
378 if (pkt->ts_field == 0xFFFFFF)
379 bytestream_put_be32(&p, timestamp);
380 // save history
381 prev_pkt[pkt->channel_id].channel_id = pkt->channel_id;
382 prev_pkt[pkt->channel_id].type = pkt->type;
383 prev_pkt[pkt->channel_id].size = pkt->size;
384 prev_pkt[pkt->channel_id].timestamp = pkt->timestamp;
385 prev_pkt[pkt->channel_id].ts_field = pkt->ts_field;
386 prev_pkt[pkt->channel_id].extra = pkt->extra;
387
388 // FIXME:
389 // Writing packets is currently not optimized to minimize system calls.
390 // Since system calls flush on exit which we cannot change in a system-independant way.
391 // We should fix this behavior and by writing packets in a single or in as few as possible system calls.
392 // Protocols like TCP and RTMP should benefit from this when enabling TCP_NODELAY.
393
394 if ((ret = ffurl_write(h, pkt_hdr, p - pkt_hdr)) < 0)
395 return ret;
396 written = p - pkt_hdr + pkt->size;
397 pkt_hdr[0] |= RTMP_PS_ONEBYTE << 6;
398 while (off < pkt->size) {
399 int towrite = FFMIN(chunk_size, pkt->size - off);
400 if ((ret = ffurl_write(h, pkt->data + off, towrite)) < 0)
401 return ret;
402 off += towrite;
403 if (off < pkt->size) {
404 if ((ret = ffurl_write(h, pkt_hdr, basic_hdr_size)) < 0)
405 return ret;
406 written += basic_hdr_size;
407 if (pkt->ts_field == 0xFFFFFF) {
408 uint8_t ts_header[4];
409 AV_WB32(ts_header, timestamp);
410 if ((ret = ffurl_write(h, ts_header, 4)) < 0)
411 return ret;
412 written += 4;
413 }
414 }
415 }
416 return written;
417}
418
420 int timestamp, int size)
421{
422 if (size) {
423 pkt->data = av_realloc(NULL, size);
424 if (!pkt->data)
425 return AVERROR(ENOMEM);
426 }
427 pkt->size = size;
428 pkt->channel_id = channel_id;
429 pkt->type = type;
430 pkt->timestamp = timestamp;
431 pkt->extra = 0;
432 pkt->ts_field = 0;
433
434 return 0;
435}
436
438{
439 if (!pkt)
440 return;
441 av_freep(&pkt->data);
442 pkt->size = 0;
443}
444
445static int amf_tag_skip(GetByteContext *gb, int depth)
446{
448 unsigned nb = -1;
449
450 if (bytestream2_get_bytes_left(gb) < 1)
451 return -1;
452
453 if (depth > MAX_DEPTH) {
454 av_log(NULL, AV_LOG_ERROR, "amf_tag_skip: exceeded max depth\n");
456 }
457
458 type = bytestream2_get_byte(gb);
459 switch (type) {
461 bytestream2_get_be64(gb);
462 return 0;
464 bytestream2_get_byte(gb);
465 return 0;
467 bytestream2_skip(gb, bytestream2_get_be16(gb));
468 return 0;
470 bytestream2_skip(gb, bytestream2_get_be32(gb));
471 return 0;
473 return 0;
475 bytestream2_skip(gb, 10);
476 return 0;
479 nb = bytestream2_get_be32(gb);
482 while (type != AMF_DATA_TYPE_ARRAY || nb-- > 0) {
483 int t;
484 if (type != AMF_DATA_TYPE_ARRAY) {
485 int size = bytestream2_get_be16(gb);
486 if (!size) {
487 bytestream2_get_byte(gb);
488 break;
489 }
491 return -1;
493 }
494 t = amf_tag_skip(gb, depth + 1);
495 if (t < 0 || bytestream2_get_bytes_left(gb) <= 0)
496 return -1;
497 }
498 return 0;
499 case AMF_DATA_TYPE_OBJECT_END: return 0;
500 default: return -1;
501 }
502}
503
504int ff_amf_tag_size(const uint8_t *data, const uint8_t *data_end)
505{
507 int ret;
508
509 if (data >= data_end)
510 return -1;
511
512 bytestream2_init(&gb, data, data_end - data);
513
514 ret = amf_tag_skip(&gb, 0);
515 if (ret < 0 || bytestream2_get_bytes_left(&gb) <= 0)
516 return -1;
517 av_assert0(bytestream2_tell(&gb) >= 0 && bytestream2_tell(&gb) <= data_end - data);
518 return bytestream2_tell(&gb);
519}
520
522 const uint8_t *name, uint8_t *dst, int dst_size)
523{
524 int namelen = strlen(name);
525 int len;
526
527 while (bytestream2_peek_byte(gb) != AMF_DATA_TYPE_OBJECT && bytestream2_get_bytes_left(gb) > 0) {
528 int ret = amf_tag_skip(gb, 0);
529 if (ret < 0)
530 return -1;
531 }
532 if (bytestream2_get_bytes_left(gb) < 3)
533 return -1;
534 bytestream2_get_byte(gb);
535
536 for (;;) {
537 int size = bytestream2_get_be16(gb);
538 if (!size)
539 break;
541 return -1;
543 if (size == namelen && !memcmp(gb->buffer-size, name, namelen)) {
544 switch (bytestream2_get_byte(gb)) {
546 snprintf(dst, dst_size, "%g", av_int2double(bytestream2_get_be64(gb)));
547 break;
549 snprintf(dst, dst_size, "%s", bytestream2_get_byte(gb) ? "true" : "false");
550 break;
552 len = bytestream2_get_be16(gb);
553 if (dst_size < 1)
554 return -1;
555 if (dst_size < len + 1)
556 len = dst_size - 1;
558 dst[len] = 0;
559 break;
560 default:
561 return -1;
562 }
563 return 0;
564 }
565 len = amf_tag_skip(gb, 0);
566 if (len < 0 || bytestream2_get_bytes_left(gb) <= 0)
567 return -1;
568 }
569 return -1;
570}
571
572int ff_amf_get_field_value(const uint8_t *data, const uint8_t *data_end,
573 const uint8_t *name, uint8_t *dst, int dst_size)
574{
576
577 if (data >= data_end)
578 return -1;
579
580 bytestream2_init(&gb, data, data_end - data);
581
582 return amf_get_field_value2(&gb, name, dst, dst_size);
583}
584
585#ifdef DEBUG
586static const char* rtmp_packet_type(int type)
587{
588 switch (type) {
589 case RTMP_PT_CHUNK_SIZE: return "chunk size";
590 case RTMP_PT_BYTES_READ: return "bytes read";
591 case RTMP_PT_USER_CONTROL: return "user control";
592 case RTMP_PT_WINDOW_ACK_SIZE: return "window acknowledgement size";
593 case RTMP_PT_SET_PEER_BW: return "set peer bandwidth";
594 case RTMP_PT_AUDIO: return "audio packet";
595 case RTMP_PT_VIDEO: return "video packet";
596 case RTMP_PT_FLEX_STREAM: return "Flex shared stream";
597 case RTMP_PT_FLEX_OBJECT: return "Flex shared object";
598 case RTMP_PT_FLEX_MESSAGE: return "Flex shared message";
599 case RTMP_PT_NOTIFY: return "notification";
600 case RTMP_PT_SHARED_OBJ: return "shared object";
601 case RTMP_PT_INVOKE: return "invoke";
602 case RTMP_PT_METADATA: return "metadata";
603 default: return "unknown";
604 }
605}
606
607static void amf_tag_contents(void *ctx, const uint8_t *data,
608 const uint8_t *data_end, int depth)
609{
610 unsigned int size, nb = -1;
611 char buf[1024];
613 int parse_key = 1;
614
615 if (depth > MAX_DEPTH) {
616 av_log(NULL, AV_LOG_ERROR, "amf_tag_contents: exceeded max depth\n");
617 return;
618 }
619
620 if (data >= data_end)
621 return;
622 switch ((type = *data++)) {
624 av_log(ctx, AV_LOG_DEBUG, " number %g\n", av_int2double(AV_RB64(data)));
625 return;
627 av_log(ctx, AV_LOG_DEBUG, " bool %d\n", *data);
628 return;
631 if (type == AMF_DATA_TYPE_STRING) {
632 size = bytestream_get_be16(&data);
633 } else {
634 size = bytestream_get_be32(&data);
635 }
636 size = FFMIN(size, sizeof(buf) - 1);
637 memcpy(buf, data, size);
638 buf[size] = 0;
639 av_log(ctx, AV_LOG_DEBUG, " string '%s'\n", buf);
640 return;
642 av_log(ctx, AV_LOG_DEBUG, " NULL\n");
643 return;
645 parse_key = 0;
648 nb = bytestream_get_be32(&data);
651 av_log(ctx, AV_LOG_DEBUG, " {\n");
652 while (nb-- > 0 || type != AMF_DATA_TYPE_ARRAY) {
653 int t;
654 if (parse_key) {
655 size = bytestream_get_be16(&data);
656 size = FFMIN(size, sizeof(buf) - 1);
657 if (!size) {
658 av_log(ctx, AV_LOG_DEBUG, " }\n");
659 data++;
660 break;
661 }
662 memcpy(buf, data, size);
663 buf[size] = 0;
664 if (size >= data_end - data)
665 return;
666 data += size;
667 av_log(ctx, AV_LOG_DEBUG, " %s: ", buf);
668 }
669 amf_tag_contents(ctx, data, data_end, depth + 1);
670 t = ff_amf_tag_size(data, data_end);
671 if (t < 0 || t >= data_end - data)
672 return;
673 data += t;
674 }
675 return;
677 av_log(ctx, AV_LOG_DEBUG, " }\n");
678 return;
679 default:
680 return;
681 }
682}
683
684void ff_rtmp_packet_dump(void *ctx, RTMPPacket *p)
685{
686 av_log(ctx, AV_LOG_DEBUG, "RTMP packet type '%s'(%d) for channel %d, timestamp %d, extra field %d size %d\n",
687 rtmp_packet_type(p->type), p->type, p->channel_id, p->timestamp, p->extra, p->size);
688 if (p->type == RTMP_PT_INVOKE || p->type == RTMP_PT_NOTIFY) {
689 uint8_t *src = p->data, *src_end = p->data + p->size;
690 while (src < src_end) {
691 int sz;
692 amf_tag_contents(ctx, src, src_end, 0);
693 sz = ff_amf_tag_size(src, src_end);
694 if (sz < 0)
695 break;
696 src += sz;
697 }
698 } else if (p->type == RTMP_PT_WINDOW_ACK_SIZE) {
699 av_log(ctx, AV_LOG_DEBUG, "Window acknowledgement size = %d\n", AV_RB32(p->data));
700 } else if (p->type == RTMP_PT_SET_PEER_BW) {
701 av_log(ctx, AV_LOG_DEBUG, "Set Peer BW = %d\n", AV_RB32(p->data));
702 } else if (p->type != RTMP_PT_AUDIO && p->type != RTMP_PT_VIDEO && p->type != RTMP_PT_METADATA) {
703 int i;
704 for (i = 0; i < p->size; i++)
705 av_log(ctx, AV_LOG_DEBUG, " %02X", p->data[i]);
706 av_log(ctx, AV_LOG_DEBUG, "\n");
707 }
708}
709#endif
710
711int ff_amf_match_string(const uint8_t *data, int size, const char *str)
712{
713 int len = strlen(str);
714 int amf_len, type;
715
716 if (size < 1)
717 return 0;
718
719 type = *data++;
720
723 return 0;
724
726 if ((size -= 4 + 1) < 0)
727 return 0;
728 amf_len = bytestream_get_be32(&data);
729 } else {
730 if ((size -= 2 + 1) < 0)
731 return 0;
732 amf_len = bytestream_get_be16(&data);
733 }
734
735 if (amf_len > size)
736 return 0;
737
738 if (amf_len != len)
739 return 0;
740
741 return !memcmp(data, str, len);
742}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
static double val(void *priv, double ch)
Definition aeval.c:77
static AVFormatContext * ctx
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
int ffurl_read_complete(URLContext *h, unsigned char *buf, int size)
Read as many bytes as possible (up to size), calling the read function multiple times if necessary.
Definition avio.c:633
static uint32_t BS_FUNC read(BSCTX *bc, unsigned int n)
Return n bits from the buffer, n has to be in the 0-32 range.
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
Definition bytestream.h:267
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
Definition bytestream.h:372
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
Definition bytestream.h:158
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition bytestream.h:137
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition bytestream.h:168
static av_always_inline int bytestream2_tell(const GetByteContext *g)
Definition bytestream.h:192
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define NULL
Definition coverity.c:32
static AVPacket * pkt
static int parse_key(DBEContext *s)
Definition dolby_e.c:626
channel
Use these values when setting the channel map with ebur128_set_channel().
Definition ebur128.h:39
int ret
Definition ffplay.c:391
FLV common header.
AMFDataType
Definition flv.h:167
@ AMF_DATA_TYPE_OBJECT_END
Definition flv.h:176
@ AMF_DATA_TYPE_LONG_STRING
Definition flv.h:179
@ AMF_DATA_TYPE_OBJECT
Definition flv.h:171
@ AMF_DATA_TYPE_BOOL
Definition flv.h:169
@ AMF_DATA_TYPE_NUMBER
Definition flv.h:168
@ AMF_DATA_TYPE_MIXEDARRAY
Definition flv.h:175
@ AMF_DATA_TYPE_NULL
Definition flv.h:172
@ AMF_DATA_TYPE_STRING
Definition flv.h:170
@ AMF_DATA_TYPE_ARRAY
Definition flv.h:177
@ AMF_DATA_TYPE_DATE
Definition flv.h:178
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition error.h:64
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition mem.c:318
static av_always_inline uint64_t av_double2int(double f)
Reinterpret a double as a 64-bit integer.
Definition intfloat.h:70
static av_always_inline double av_int2double(uint64_t i)
Reinterpret a 64-bit integer as a double.
Definition intfloat.h:60
#define AV_WB32(p, v)
#define AV_RL32(p)
#define AV_RB32(p)
#define AV_RB64(p)
#define AV_RL16(p)
#define AV_RB24(x)
enum MPFType type
Definition jpegmpfenc.c:55
#define MAX_DEPTH
arbitrary limit to prevent unbounded recursion
Definition flvdec.c:48
Macro definitions for various function/variable attributes.
#define av_fallthrough
Definition attributes.h:67
#define FFMIN(a, b)
Definition macros.h:49
Memory handling functions.
const char data[16]
Definition mxf.c:155
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
#define av_realloc(p, s)
Definition ops_static.c:54
const char * name
Definition qsvenc.c:142
void ff_amf_write_string(uint8_t **dst, const char *str)
Write string in AMF format to buffer.
Definition rtmppkt.c:51
void ff_amf_write_null(uint8_t **dst)
Write AMF NULL value to buffer.
Definition rtmppkt.c:71
void ff_amf_write_number(uint8_t **dst, double val)
Write number in AMF format to buffer.
Definition rtmppkt.c:39
int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p, int chunk_size, RTMPPacket **prev_pkt, int *nb_prev_pkt)
Read RTMP packet sent by the server.
Definition rtmppkt.c:159
static int rtmp_packet_read_one_chunk(URLContext *h, RTMPPacket *p, int chunk_size, RTMPPacket **prev_pkt_ptr, int *nb_prev_pkt, uint8_t hdr)
Definition rtmppkt.c:171
int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt, int chunk_size, RTMPPacket **prev_pkt_ptr, int *nb_prev_pkt)
Send RTMP packet to the server.
Definition rtmppkt.c:314
void ff_amf_write_object_start(uint8_t **dst)
Write marker for AMF object to buffer.
Definition rtmppkt.c:76
void ff_amf_write_string2(uint8_t **dst, const char *str1, const char *str2)
Write a string consisting of two parts in AMF format to a buffer.
Definition rtmppkt.c:58
int ff_amf_get_string(GetByteContext *bc, uint8_t *str, int strsize, int *length)
Get AMF string value.
Definition rtmppkt.c:105
int ff_rtmp_check_alloc_array(RTMPPacket **prev_pkt, int *nb_prev_pkt, int channel)
Enlarge the prev_pkt array to fit the given channel.
Definition rtmppkt.c:138
int ff_rtmp_packet_read_internal(URLContext *h, RTMPPacket *p, int chunk_size, RTMPPacket **prev_pkt, int *nb_prev_pkt, uint8_t hdr)
Read internal RTMP packet sent by the server.
Definition rtmppkt.c:299
int ff_amf_read_null(GetByteContext *bc)
Read AMF NULL value.
Definition rtmppkt.c:131
static int amf_get_field_value2(GetByteContext *gb, const uint8_t *name, uint8_t *dst, int dst_size)
Definition rtmppkt.c:521
void ff_amf_write_array_start(uint8_t **dst, uint32_t length)
Write marker and length for AMF array to buffer.
Definition rtmppkt.c:45
int ff_amf_tag_size(const uint8_t *data, const uint8_t *data_end)
Calculate number of bytes taken by first AMF entry in data.
Definition rtmppkt.c:504
void ff_amf_write_bool(uint8_t **dst, int val)
Write boolean value in AMF format to buffer.
Definition rtmppkt.c:33
int ff_amf_get_field_value(const uint8_t *data, const uint8_t *data_end, const uint8_t *name, uint8_t *dst, int dst_size)
Retrieve value of given AMF object field in string form.
Definition rtmppkt.c:572
int ff_rtmp_packet_create(RTMPPacket *pkt, int channel_id, RTMPPacketType type, int timestamp, int size)
Create new RTMP packet with given attributes.
Definition rtmppkt.c:419
void ff_rtmp_packet_destroy(RTMPPacket *pkt)
Free RTMP packet.
Definition rtmppkt.c:437
int ff_amf_match_string(const uint8_t *data, int size, const char *str)
Match AMF string with a NULL-terminated string.
Definition rtmppkt.c:711
void ff_amf_write_object_end(uint8_t **dst)
Write marker for end of AMF object to buffer.
Definition rtmppkt.c:87
void ff_amf_write_field_name(uint8_t **dst, const char *str)
Write string used as field name in AMF object to buffer.
Definition rtmppkt.c:81
int ff_amf_read_string(GetByteContext *bc, uint8_t *str, int strsize, int *length)
Read AMF string value.
Definition rtmppkt.c:123
static int amf_tag_skip(GetByteContext *gb, int depth)
Definition rtmppkt.c:445
int ff_amf_read_number(GetByteContext *bc, double *val)
Read AMF number value.
Definition rtmppkt.c:95
@ RTMP_PS_TWELVEBYTES
packet has 12-byte header
Definition rtmppkt.h:68
@ RTMP_PS_EIGHTBYTES
packet has 8-byte header
Definition rtmppkt.h:69
@ RTMP_PS_FOURBYTES
packet has 4-byte header
Definition rtmppkt.h:70
@ RTMP_PS_ONEBYTE
packet is really a next chunk of a packet
Definition rtmppkt.h:71
void ff_rtmp_packet_dump(void *ctx, RTMPPacket *p)
Print information and contents of RTMP packet.
RTMPPacketType
known RTMP packet types
Definition rtmppkt.h:47
@ RTMP_PT_FLEX_OBJECT
Flex shared object.
Definition rtmppkt.h:56
@ RTMP_PT_USER_CONTROL
user control
Definition rtmppkt.h:50
@ RTMP_PT_NOTIFY
some notification
Definition rtmppkt.h:58
@ RTMP_PT_SHARED_OBJ
shared object
Definition rtmppkt.h:59
@ RTMP_PT_CHUNK_SIZE
chunk size change
Definition rtmppkt.h:48
@ RTMP_PT_INVOKE
invoke some stream action
Definition rtmppkt.h:60
@ RTMP_PT_BYTES_READ
number of bytes read
Definition rtmppkt.h:49
@ RTMP_PT_SET_PEER_BW
peer bandwidth
Definition rtmppkt.h:52
@ RTMP_PT_WINDOW_ACK_SIZE
window acknowledgement size
Definition rtmppkt.h:51
@ RTMP_PT_VIDEO
video packet
Definition rtmppkt.h:54
@ RTMP_PT_FLEX_STREAM
Flex shared stream.
Definition rtmppkt.h:55
@ RTMP_PT_METADATA
FLV metadata.
Definition rtmppkt.h:61
@ RTMP_PT_AUDIO
audio packet
Definition rtmppkt.h:53
@ RTMP_PT_FLEX_MESSAGE
Flex shared message.
Definition rtmppkt.h:57
const uint8_t * buffer
Definition bytestream.h:34
structure for holding RTMP packets
Definition rtmppkt.h:77
int size
packet payload size
Definition rtmppkt.h:84
uint32_t extra
probably an additional channel ID used during streaming data
Definition rtmppkt.h:82
RTMPPacketType type
packet payload type
Definition rtmppkt.h:79
uint32_t ts_field
24-bit timestamp or increment to the previous one, in milliseconds (latter only for media packets)....
Definition rtmppkt.h:81
uint32_t timestamp
packet full timestamp
Definition rtmppkt.h:80
uint8_t * data
packet payload
Definition rtmppkt.h:83
int channel_id
RTMP channel ID (nothing to do with audio/video channels though)
Definition rtmppkt.h:78
int read
amount read, including headers
Definition rtmppkt.h:86
int offset
amount of data read so far
Definition rtmppkt.h:85
Definition swscale.c:85
#define av_freep(p)
#define av_log(a,...)
#define src
Definition vp8dsp.c:248
int size
unbuffered private I/O API
static int ffurl_write(URLContext *h, const uint8_t *buf, int size)
Write size bytes from buf to the resource accessed by h.
Definition url.h:205
static int ffurl_read(URLContext *h, uint8_t *buf, int size)
Read up to size bytes from the resource accessed by h, and store the read bytes in buf.
Definition url.h:184
int len