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);
110 stringlen = bytestream2_get_be16(bc);
111 if (stringlen + 1 > strsize)
114 if (readsize != stringlen) {
116 "Unable to read as many bytes as AMF string signaled\n");
118 str[readsize] =
'\0';
119 *length =
FFMIN(stringlen, readsize);
143 if (channel < *nb_prev_pkt)
146 nb_alloc = channel + 16;
153 memset(ptr + *nb_prev_pkt, 0, (nb_alloc - *nb_prev_pkt) *
sizeof(*ptr));
155 *nb_prev_pkt = nb_alloc;
160 int chunk_size,
RTMPPacket **prev_pkt,
int *nb_prev_pkt)
177 int channel_id, timestamp,
size;
186 channel_id = hdr & 0x3F;
188 if (channel_id < 2) {
192 written += channel_id + 1;
193 channel_id =
AV_RL16(buf) + 64;
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;
205 ts_field = prev_pkt[channel_id].
ts_field;
228 if (ts_field == 0xFFFFFF) {
233 timestamp = ts_field;
236 timestamp += prev_pkt[channel_id].
timestamp;
238 if (!prev_pkt[channel_id].read) {
244 prev_pkt[channel_id].
ts_field = ts_field;
245 prev_pkt[channel_id].
timestamp = timestamp;
265 prev_pkt[channel_id].
extra = extra;
268 toread =
FFMIN(size, chunk_size);
286 prev_pkt[channel_id].
read = 0;
297 if (ret > 0 || ret !=
AVERROR(EAGAIN))
309 uint8_t pkt_hdr[16], *p = pkt_hdr;
321 prev_pkt = *prev_pkt_ptr;
332 if (timestamp >= 0xFFFFFF) {
350 bytestream_put_byte(&p, pkt->
channel_id | (mode << 6));
352 bytestream_put_byte(&p, 0 | (mode << 6));
353 bytestream_put_byte(&p, pkt->
channel_id - 64);
355 bytestream_put_byte(&p, 1 | (mode << 6));
356 bytestream_put_le16(&p, pkt->
channel_id - 64);
359 bytestream_put_be24(&p, pkt->
ts_field);
361 bytestream_put_be24(&p, pkt->
size);
362 bytestream_put_byte(&p, pkt->
type);
364 bytestream_put_le32(&p, pkt->
extra);
368 bytestream_put_be32(&p, timestamp);
377 if ((ret =
ffurl_write(h, pkt_hdr, p - pkt_hdr)) < 0)
379 written = p - pkt_hdr + pkt->
size;
380 while (off < pkt->
size) {
381 int towrite =
FFMIN(chunk_size, pkt->
size - off);
385 if (off < pkt->size) {
396 int timestamp,
int size)
428 if (data >= data_end)
430 switch ((type = *data++)) {
439 nb = bytestream_get_be32(&data);
444 int size = bytestream_get_be16(&data);
454 if (t < 0 || t >= data_end - data)
467 int namelen = strlen(name);
473 len = data_end -
data;
476 if (data_end - data < 3)
480 int size = bytestream_get_be16(&data);
486 if (size == namelen && !memcmp(data-size, name, namelen)) {
492 snprintf(dst, dst_size,
"%s", *data ?
"true" :
"false");
495 len = bytestream_get_be16(&data);
504 if (len < 0 || len >= data_end - data)
528 default:
return "unknown";
535 unsigned int size, nb = -1;
540 if (data >= data_end)
542 switch ((type = *data++)) {
552 size = bytestream_get_be16(&data);
554 size = bytestream_get_be32(&data);
556 size =
FFMIN(size,
sizeof(buf) - 1);
557 memcpy(buf, data, size);
567 nb = bytestream_get_be32(&data);
573 size = bytestream_get_be16(&data);
574 size =
FFMIN(size,
sizeof(buf) - 1);
580 memcpy(buf, data, size);
582 if (size >= data_end - data)
589 if (t < 0 || t >= data_end - data)
604 av_log(ctx,
AV_LOG_DEBUG,
"RTMP packet type '%s'(%d) for channel %d, timestamp %d, extra field %d size %d\n",
608 while (src < src_end) {
622 for (i = 0; i < p->
size; i++)
630 int len = strlen(str);
643 if ((size -= 4 + 1) < 0)
645 amf_len = bytestream_get_be32(&data);
647 if ((size -= 2 + 1) < 0)
649 amf_len = bytestream_get_be16(&data);
658 return !memcmp(data, str, len);