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;
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;
329 bytestream_put_byte(&p, pkt->
channel_id | (mode << 6));
331 bytestream_put_byte(&p, 0 | (mode << 6));
332 bytestream_put_byte(&p, pkt->
channel_id - 64);
334 bytestream_put_byte(&p, 1 | (mode << 6));
335 bytestream_put_le16(&p, pkt->
channel_id - 64);
341 bytestream_put_be24(&p, timestamp >= 0xFFFFFF ? 0xFFFFFF : timestamp);
343 bytestream_put_be24(&p, pkt->
size);
344 bytestream_put_byte(&p, pkt->
type);
346 bytestream_put_le32(&p, pkt->
extra);
348 if (timestamp >= 0xFFFFFF)
349 bytestream_put_be32(&p, timestamp);
363 if ((ret =
ffurl_write(h, pkt_hdr, p - pkt_hdr)) < 0)
365 written = p - pkt_hdr + pkt->
size;
366 while (off < pkt->
size) {
367 int towrite =
FFMIN(chunk_size, pkt->
size - off);
371 if (off < pkt->size) {
382 int timestamp,
int size)
414 if (data >= data_end)
416 switch ((type = *data++)) {
425 nb = bytestream_get_be32(&data);
430 int size = bytestream_get_be16(&data);
440 if (t < 0 || t >= data_end - data)
453 int namelen = strlen(name);
459 len = data_end -
data;
462 if (data_end - data < 3)
466 int size = bytestream_get_be16(&data);
472 if (size == namelen && !memcmp(data-size, name, namelen)) {
478 snprintf(dst, dst_size,
"%s", *data ?
"true" :
"false");
481 len = bytestream_get_be16(&data);
490 if (len < 0 || len >= data_end - data)
514 default:
return "unknown";
521 unsigned int size, nb = -1;
526 if (data >= data_end)
528 switch ((type = *data++)) {
538 size = bytestream_get_be16(&data);
540 size = bytestream_get_be32(&data);
542 size =
FFMIN(size,
sizeof(buf) - 1);
543 memcpy(buf, data, size);
553 nb = bytestream_get_be32(&data);
559 size = bytestream_get_be16(&data);
560 size =
FFMIN(size,
sizeof(buf) - 1);
566 memcpy(buf, data, size);
568 if (size >= data_end - data)
575 if (t < 0 || t >= data_end - data)
590 av_log(ctx,
AV_LOG_DEBUG,
"RTMP packet type '%s'(%d) for channel %d, timestamp %d, extra field %d size %d\n",
594 while (src < src_end) {
608 for (i = 0; i < p->
size; i++)
616 int len = strlen(str);
629 if ((size -= 4 + 1) < 0)
631 amf_len = bytestream_get_be32(&data);
633 if ((size -= 2 + 1) < 0)
635 amf_len = bytestream_get_be16(&data);
644 return !memcmp(data, str, len);