34 bytestream_put_byte(dst, val);
46 bytestream_put_be16(dst, strlen(str));
52 int len1 = 0, len2 = 0;
58 bytestream_put_be16(dst, len1 + len2);
75 bytestream_put_be16(dst, strlen(str));
91 *val = bytestream2_get_byte(bc);
100 read = bytestream2_get_be64(bc);
112 stringlen = bytestream2_get_be16(bc);
113 if (stringlen + 1 > strsize)
116 if (readsize != stringlen) {
118 "Unable to read as many bytes as AMF string signaled\n");
120 str[readsize] =
'\0';
121 *length =
FFMIN(stringlen, readsize);
137 if (channel < *nb_prev_pkt)
140 nb_alloc = channel + 16;
147 memset(ptr + *nb_prev_pkt, 0, (nb_alloc - *nb_prev_pkt) *
sizeof(*ptr));
149 *nb_prev_pkt = nb_alloc;
154 int chunk_size,
RTMPPacket **prev_pkt,
int *nb_prev_pkt)
171 int channel_id, timestamp,
size;
179 channel_id = hdr & 0x3F;
181 if (channel_id < 2) {
185 written += channel_id + 1;
186 channel_id =
AV_RL16(buf) + 64;
191 prev_pkt = *prev_pkt_ptr;
192 size = prev_pkt[channel_id].
size;
193 type = prev_pkt[channel_id].
type;
194 extra = prev_pkt[channel_id].
extra;
198 timestamp = prev_pkt[channel_id].
ts_delta;
220 if (timestamp == 0xFFFFFF) {
227 timestamp += prev_pkt[channel_id].
timestamp;
229 if (!prev_pkt[channel_id].read) {
235 prev_pkt[channel_id].
ts_delta = timestamp -
237 prev_pkt[channel_id].
timestamp = timestamp;
255 prev_pkt[channel_id].
type = type;
257 prev_pkt[channel_id].
extra = extra;
260 toread =
FFMIN(size, chunk_size);
277 prev_pkt[channel_id].
read = 0;
288 if (ret > 0 || ret !=
AVERROR(EAGAIN))
300 uint8_t pkt_hdr[16], *p = pkt_hdr;
310 prev_pkt = *prev_pkt_ptr;
328 bytestream_put_byte(&p, pkt->
channel_id | (mode << 6));
330 bytestream_put_byte(&p, 0 | (mode << 6));
331 bytestream_put_byte(&p, pkt->
channel_id - 64);
333 bytestream_put_byte(&p, 1 | (mode << 6));
334 bytestream_put_le16(&p, pkt->
channel_id - 64);
340 bytestream_put_be24(&p, timestamp >= 0xFFFFFF ? 0xFFFFFF : timestamp);
342 bytestream_put_be24(&p, pkt->
size);
343 bytestream_put_byte(&p, pkt->
type);
345 bytestream_put_le32(&p, pkt->
extra);
347 if (timestamp >= 0xFFFFFF)
348 bytestream_put_be32(&p, timestamp);
362 if ((ret =
ffurl_write(h, pkt_hdr, p - pkt_hdr)) < 0)
364 written = p - pkt_hdr + pkt->
size;
365 while (off < pkt->
size) {
366 int towrite =
FFMIN(chunk_size, pkt->
size - off);
370 if (off < pkt->size) {
381 int timestamp,
int size)
413 if (data >= data_end)
415 switch ((type = *data++)) {
424 nb = bytestream_get_be32(&data);
429 int size = bytestream_get_be16(&data);
434 if (size < 0 || size >= data_end - data)
439 if (t < 0 || t >= data_end - data)
452 int namelen = strlen(name);
458 len = data_end -
data;
461 if (data_end - data < 3)
465 int size = bytestream_get_be16(&data);
468 if (size < 0 || size >= data_end - data)
471 if (size == namelen && !memcmp(data-size, name, namelen)) {
477 snprintf(dst, dst_size,
"%s", *data ?
"true" :
"false");
480 len = bytestream_get_be16(&data);
489 if (len < 0 || len >= data_end - data)
513 default:
return "unknown";
520 unsigned int size, nb = -1;
525 if (data >= data_end)
527 switch ((type = *data++)) {
537 size = bytestream_get_be16(&data);
539 size = bytestream_get_be32(&data);
541 size =
FFMIN(size,
sizeof(buf) - 1);
542 memcpy(buf, data, size);
552 nb = bytestream_get_be32(&data);
558 size = bytestream_get_be16(&data);
559 size =
FFMIN(size,
sizeof(buf) - 1);
565 memcpy(buf, data, size);
567 if (size >= data_end - data)
574 if (t < 0 || t >= data_end - data)
589 av_log(ctx,
AV_LOG_DEBUG,
"RTMP packet type '%s'(%d) for channel %d, timestamp %d, extra field %d size %d\n",
593 while (src < src_end) {
607 for (i = 0; i < p->
size; i++)
615 int len = strlen(str);
628 if ((size -= 4 + 1) < 0)
630 amf_len = bytestream_get_be32(&data);
632 if ((size -= 2 + 1) < 0)
634 amf_len = bytestream_get_be16(&data);
643 return !memcmp(data, str, len);