34 bytestream_put_byte(dst, val);
46 bytestream_put_be16(dst, strlen(str));
62 bytestream_put_be16(dst, strlen(str));
77 uint8_t hdr,
t, buf[16];
78 int channel_id, timestamp,
size, offset = 0;
86 channel_id = hdr & 0x3F;
92 written += channel_id + 1;
95 size = prev_pkt[channel_id].
size;
96 type = prev_pkt[channel_id].
type;
97 extra = prev_pkt[channel_id].
extra;
101 timestamp = prev_pkt[channel_id].
ts_delta;
123 if (timestamp == 0xFFFFFF) {
130 timestamp += prev_pkt[channel_id].
timestamp;
137 prev_pkt[channel_id].
type = type;
140 prev_pkt[channel_id].
timestamp = timestamp;
141 prev_pkt[channel_id].
extra = extra;
143 int toread =
FFMIN(size, chunk_size);
149 offset += chunk_size;
150 written += chunk_size;
154 if (t != (0xC0 + channel_id))
164 uint8_t pkt_hdr[16], *p = pkt_hdr;
185 bytestream_put_byte(&p, pkt->
channel_id | (mode << 6));
187 bytestream_put_byte(&p, 0 | (mode << 6));
188 bytestream_put_byte(&p, pkt->
channel_id - 64);
190 bytestream_put_byte(&p, 1 | (mode << 6));
191 bytestream_put_le16(&p, pkt->
channel_id - 64);
197 bytestream_put_be24(&p, timestamp >= 0xFFFFFF ? 0xFFFFFF : timestamp);
199 bytestream_put_be24(&p, pkt->
size);
200 bytestream_put_byte(&p, pkt->
type);
202 bytestream_put_le32(&p, pkt->
extra);
204 if (timestamp >= 0xFFFFFF)
205 bytestream_put_be32(&p, timestamp);
220 written = p - pkt_hdr + pkt->
size;
221 while (off < pkt->
size) {
222 int towrite =
FFMIN(chunk_size, pkt->
size - off);
225 if (off < pkt->size) {
235 int timestamp,
int size)
262 const uint8_t *base =
data;
264 if (data >= data_end)
276 int size = bytestream_get_be16(&data);
282 if (data + size >= data_end || data + size < data)
286 if (t < 0 || data + t >= data_end)
297 const uint8_t *
name, uint8_t *dst,
int dst_size)
299 int namelen = strlen(name);
305 len = data_end -
data;
308 if (data_end - data < 3)
312 int size = bytestream_get_be16(&data);
315 if (data + size >= data_end || data + size < data)
318 if (size == namelen && !memcmp(data-size, name, namelen)) {
324 snprintf(dst, dst_size,
"%s", *data ?
"true" :
"false");
327 len = bytestream_get_be16(&data);
336 if (len < 0 || data + len >= data_end || data + len < data)
360 default:
return "unknown";
369 if (data >= data_end)
381 size = bytestream_get_be16(&data);
383 size = bytestream_get_be32(&data);
385 size =
FFMIN(size, 1023);
386 memcpy(buf, data, size);
398 int size = bytestream_get_be16(&data);
400 memcpy(buf, data, size);
407 if (data + size >= data_end || data + size < data)
413 if (t < 0 || data + t >= data_end)
428 av_log(ctx,
AV_LOG_DEBUG,
"RTMP packet type '%s'(%d) for channel %d, timestamp %d, extra field %d size %d\n",
432 while (src < src_end) {
446 for (i = 0; i < p->
size; i++)
454 int len = strlen(str);
467 if ((size -= 4 + 1) < 0)
469 amf_len = bytestream_get_be32(&data);
471 if ((size -= 2 + 1) < 0)
473 amf_len = bytestream_get_be16(&data);
482 return !memcmp(data, str, len);
int ff_amf_match_string(const uint8_t *data, int size, const char *str)
Match AMF string with a NULL-terminated string.
AV_WL32 AV_WL24 AV_WL16 AV_WB32 AV_WB24 AV_RB16
AV_WL32 AV_WL24 AV_WL16 AV_RB32
int ffurl_write(URLContext *h, const unsigned char *buf, int size)
Write size bytes from buf to the resource accessed by h.
void ff_amf_write_field_name(uint8_t **dst, const char *str)
Write string used as field name in AMF object to buffer.
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.
static av_always_inline uint64_t av_double2int(double f)
Reinterpret a double as a 64-bit integer.
int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p, int chunk_size, RTMPPacket *prev_pkt)
Read RTMP packet sent by the server.
RTMPPacketType type
packet payload type
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static av_always_inline double av_int2double(uint64_t i)
Reinterpret a 64-bit integer as a double.
static void ff_amf_tag_contents(void *ctx, const uint8_t *data, const uint8_t *data_end)
uint32_t extra
probably an additional channel ID used during streaming data
uint32_t ts_delta
timestamp increment to the previous one in milliseconds (latter only for media packets) ...
void ff_amf_write_string(uint8_t **dst, const char *str)
Write string in AMF format to buffer.
void ff_rtmp_packet_dump(void *ctx, RTMPPacket *p)
Print information and contents of RTMP packet.
void ff_amf_write_object_end(uint8_t **dst)
Write marker for end of AMF object to buffer.
int size
packet payload size
void ff_amf_write_bool(uint8_t **dst, int val)
Write boolean value in AMF format to buffer.
void av_log(void *avcl, int level, const char *fmt,...)
packet has 12-byte header
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
void ff_rtmp_packet_destroy(RTMPPacket *pkt)
Free RTMP packet.
RTMPPacketType
known RTMP packet types
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.
int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt, int chunk_size, RTMPPacket *prev_pkt)
Send RTMP packet to the server.
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int ff_rtmp_packet_create(RTMPPacket *pkt, int channel_id, RTMPPacketType type, int timestamp, int size)
Create new RTMP packet with given attributes.
int channel_id
RTMP channel ID (nothing to do with audio/video channels though)
void ff_amf_write_null(uint8_t **dst)
Write AMF NULL value to buffer.
uint32_t timestamp
packet full timestamp
AV_WL32 AV_WL24 AV_WL16 AV_WB32 AV_RB24
uint8_t * data
packet payload
static const char * rtmp_packet_type(int type)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
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...
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
packet is really a next chunk of a packet
void ff_amf_write_number(uint8_t **dst, double val)
Write number in AMF format to buffer.
void ff_amf_write_object_start(uint8_t **dst)
Write marker for AMF object to buffer.
structure for holding RTMP packets
unbuffered private I/O API
invoke some stream action
int ffurl_read(URLContext *h, unsigned char *buf, int size)
Read up to size bytes from the resource accessed by h, and store the read bytes in buf...