28 #include "libavutil/avstring.h"
29 #include "libavutil/base64.h"
30 #include "libavutil/intfloat.h"
31 #include "libavutil/lfg.h"
32 #include "libavutil/md5.h"
33 #include "libavutil/opt.h"
34 #include "libavutil/random_seed.h"
35 #include "libavutil/sha.h"
51 #define APP_MAX_LENGTH 1024
52 #define PLAYPATH_MAX_LENGTH 256
53 #define TCURL_MAX_LENGTH 512
54 #define FLASHVER_MAX_LENGTH 64
55 #define RTMP_PKTDATA_DEFAULT_SIZE 4096
56 #define RTMP_HEADER 11
130 #define PLAYER_KEY_OPEN_PART_LEN 30
133 'G',
'e',
'n',
'u',
'i',
'n',
'e',
' ',
'A',
'd',
'o',
'b',
'e',
' ',
134 'F',
'l',
'a',
's',
'h',
' ',
'P',
'l',
'a',
'y',
'e',
'r',
' ',
'0',
'0',
'1',
136 0xF0, 0xEE, 0xC2, 0x4A, 0x80, 0x68, 0xBE, 0xE8, 0x2E, 0x00, 0xD0, 0xD1, 0x02,
137 0x9E, 0x7E, 0x57, 0x6E, 0xEC, 0x5D, 0x2D, 0x29, 0x80, 0x6F, 0xAB, 0x93, 0xB8,
138 0xE6, 0x36, 0xCF, 0xEB, 0x31, 0xAE
141 #define SERVER_KEY_OPEN_PART_LEN 36
144 'G',
'e',
'n',
'u',
'i',
'n',
'e',
' ',
'A',
'd',
'o',
'b',
'e',
' ',
145 'F',
'l',
'a',
's',
'h',
' ',
'M',
'e',
'd',
'i',
'a',
' ',
146 'S',
'e',
'r',
'v',
'e',
'r',
' ',
'0',
'0',
'1',
148 0xF0, 0xEE, 0xC2, 0x4A, 0x80, 0x68, 0xBE, 0xE8, 0x2E, 0x00, 0xD0, 0xD1, 0x02,
149 0x9E, 0x7E, 0x57, 0x6E, 0xEC, 0x5D, 0x2D, 0x29, 0x80, 0x6F, 0xAB, 0x93, 0xB8,
150 0xE6, 0x36, 0xCF, 0xEB, 0x31, 0xAE
184 char **tracked_method)
260 if (param[0] && param[1] ==
':') {
263 }
else if (param[0] ==
'N' && param[1] && param[2] ==
':') {
266 value = strchr(field,
':');
367 char *param = rt->
conn;
370 while (param != NULL) {
372 param += strspn(param,
" ");
375 sep = strchr(param,
' ');
418 if (strcmp(command,
"connect")) {
429 "app", tmpstr,
sizeof(tmpstr));
432 if (!ret && strcmp(tmpstr, rt->
app))
455 bytestream_put_byte(&p, 2);
469 bytestream_put_be16(&p, 0);
470 bytestream_put_be32(&p, 0);
677 bytestream_put_be16(&p, 3);
771 if (ppkt->
size < 6) {
782 bytestream_put_be16(&p, 7);
803 bytestream_put_be16(&p, 27);
869 const char *subscribe)
876 0, 27 + strlen(subscribe))) < 0)
900 memcpy(hmac_buf, key, keylen);
906 for (i = 0; i < 64; i++)
919 for (i = 0; i < 64; i++)
933 int i, digest_pos = 0;
935 for (i = 0; i < 4; i++)
936 digest_pos += buf[i + off];
937 digest_pos = digest_pos % mod_val + add_val;
988 if (!memcmp(digest, buf + digest_pos, 32))
1001 "Hash of the decompressed SWF file is not 32 bytes long.\n");
1006 bytestream_put_byte(&p, 1);
1007 bytestream_put_byte(&p, 1);
1008 bytestream_put_be32(&p, rt->
swfsize);
1009 bytestream_put_be32(&p, rt->
swfsize);
1018 static int rtmp_uncompress_swfplayer(
uint8_t *in_data, int64_t in_size,
1019 uint8_t **out_data, int64_t *out_size)
1021 z_stream zs = { 0 };
1026 zs.avail_in = in_size;
1027 zs.next_in = in_data;
1028 ret = inflateInit(&zs);
1035 zs.avail_out =
sizeof(tmp_buf);
1036 zs.next_out = tmp_buf;
1038 ret = inflate(&zs, Z_NO_FLUSH);
1039 if (ret != Z_OK && ret != Z_STREAM_END) {
1044 size =
sizeof(tmp_buf) - zs.avail_out;
1045 if (!(ptr =
av_realloc(*out_data, *out_size + size))) {
1051 memcpy(*out_data + *out_size, tmp_buf, size);
1053 }
while (zs.avail_out == 0);
1064 uint8_t *in_data = NULL, *out_data = NULL, *swfdata;
1065 int64_t in_size, out_size;
1096 if (!memcmp(in_data,
"CWS", 3)) {
1103 memcpy(out_data, in_data, 8);
1107 if ((ret = rtmp_uncompress_swfplayer(in_data + 8, in_size - 8,
1108 &out_data, &out_size)) < 0)
1112 "Zlib is required for decompressing the SWF player file.\n");
1125 "Genuine Adobe Flash Player 001", 30,
1160 int server_pos, client_pos;
1211 serverdata[5], serverdata[6], serverdata[7], serverdata[8]);
1213 if (rt->
is_input && serverdata[5] >= 3) {
1245 0, digest, 32, signature);
1253 tosend + 1, type)) < 0)
1275 tosend + RTMP_HANDSHAKE_PACKET_SIZE - 32);
1282 RTMP_HANDSHAKE_PACKET_SIZE - 32, digest,
1288 RTMP_HANDSHAKE_PACKET_SIZE)) < 0)
1301 tosend + 1, 1)) < 0)
1304 if (serverdata[0] == 9) {
1326 uint32_t *second_int,
char *arraydata,
1337 " not following standard\n", (
int)inoutsize);
1341 *first_int =
AV_RB32(arraydata);
1342 *second_int =
AV_RB32(arraydata + 4);
1347 uint32_t second_int,
char *arraydata,
int size)
1351 AV_WB32(arraydata, first_int);
1352 AV_WB32(arraydata + 4, second_int);
1370 uint32_t hs_my_epoch;
1380 if (inoutsize <= 0) {
1385 if (buffer[0] != 3) {
1391 "Unable to write answer - RTMP S0\n");
1403 hs_my_epoch = hs_epoch;
1429 if (temp != hs_my_epoch)
1431 "Erroneous C2 Message epoch does not match up with C1 epoch\n");
1432 if (memcmp(buffer + 8, hs_s1 + 8,
1435 "Erroneous C2 Message random does not match up\n");
1445 if (pkt->
size < 4) {
1447 "Too short chunk size change packet (%d)\n",
1478 if (pkt->
size < 2) {
1486 if ((ret =
gen_pong(s, rt, pkt)) < 0)
1488 }
else if (t == 26) {
1504 if (pkt->
size < 4) {
1506 "Client bandwidth report packet is less than 4 bytes long (%d)\n",
1528 if (pkt->
size < 4) {
1530 "Too short server bandwidth report packet (%d)\n",
1547 const char *opaque,
const char *challenge)
1575 "?authmod=%s&user=%s&challenge=%s&response=%s",
1576 "adobe", user, challenge2, hashstr);
1579 "&opaque=%s", opaque);
1588 char hashstr1[33], hashstr2[33];
1589 const char *realm =
"live";
1590 const char *method =
"publish";
1591 const char *qop =
"auth";
1592 const char *nc =
"00000001";
1608 hashstr1[32] =
'\0';
1614 if (!strchr(rt->
app,
'/'))
1618 hashstr2[32] =
'\0';
1637 "?authmod=%s&user=%s&nonce=%s&cnonce=%s&nc=%s&response=%s",
1638 "llnw", user, nonce, cnonce, nc, hashstr1);
1647 char buf[300], *ptr, authmod[15];
1649 const char *user =
"", *salt =
"", *opaque = NULL,
1650 *challenge = NULL, *cptr = NULL, *nonce = NULL;
1652 if (!(cptr = strstr(desc,
"authmod=adobe")) &&
1653 !(cptr = strstr(desc,
"authmod=llnw"))) {
1655 "Unknown connect error (unsupported authentication method?)\n");
1658 cptr += strlen(
"authmod=");
1659 while (*cptr && *cptr !=
' ' && i <
sizeof(authmod) - 1)
1660 authmod[i++] = *cptr++;
1668 if (strstr(desc,
"?reason=authfailed")) {
1671 }
else if (strstr(desc,
"?reason=nosuchuser")) {
1683 if (strstr(desc,
"code=403 need auth")) {
1685 "?authmod=%s&user=%s", authmod, rt->
username);
1689 if (!(cptr = strstr(desc,
"?reason=needauth"))) {
1698 char *next = strchr(ptr,
'&');
1699 char *
value = strchr(ptr,
'=');
1704 if (!strcmp(ptr,
"user")) {
1706 }
else if (!strcmp(ptr,
"salt")) {
1708 }
else if (!strcmp(ptr,
"opaque")) {
1710 }
else if (!strcmp(ptr,
"challenge")) {
1712 }
else if (!strcmp(ptr,
"nonce")) {
1718 if (!strcmp(authmod,
"adobe")) {
1719 if ((ret =
do_adobe_auth(rt, user, salt, opaque, challenge)) < 0)
1734 char *tracked_method = NULL;
1743 "description", tmpstr,
sizeof(tmpstr))) {
1744 if (tracked_method && (!strcmp(tracked_method,
"_checkbw") ||
1745 !strcmp(tracked_method,
"releaseStream") ||
1746 !strcmp(tracked_method,
"FCSubscribe") ||
1747 !strcmp(tracked_method,
"FCPublish"))) {
1751 }
else if (tracked_method && !strcmp(tracked_method,
"connect")) {
1759 av_log(s, level,
"Server error: %s\n", tmpstr);
1781 bytestream2_put_be16(&pbc, 0);
1793 const char *status,
const char *filename)
1797 char statusmsg[128];
1820 snprintf(statusmsg,
sizeof(statusmsg),
1821 "%s is now published", filename);
1865 if (!strcmp(command,
"FCPublish") ||
1866 !strcmp(command,
"publish")) {
1868 sizeof(filename), &stringlen);
1874 "Unable to find / in url %s, bad format\n",
1879 if (strcmp(pchar, filename))
1881 " %s\n", filename, pchar);
1886 if (!strcmp(command,
"FCPublish")) {
1895 }
else if (!strcmp(command,
"publish")) {
1903 }
else if (!strcmp(command,
"play")) {
1921 if (!strcmp(command,
"createStream")) {
1941 char *tracked_method = NULL;
1947 if (!tracked_method) {
1952 if (!strcmp(tracked_method,
"connect")) {
1973 }
else if (rt->
live == -1) {
1978 }
else if (!strcmp(tracked_method,
"createStream")) {
1980 if (pkt->
data[10] || pkt->
data[19] != 5 || pkt->
data[20]) {
2010 for (i = 0; i < 2; i++) {
2018 if (!t && !strcmp(tmpstr,
"error")) {
2020 "description", tmpstr,
sizeof(tmpstr));
2021 if (t || !tmpstr[0])
2023 tmpstr,
sizeof(tmpstr));
2032 if (!t && !strcmp(tmpstr,
"NetStream.Play.UnpublishNotify")) rt->
state =
STATE_STOPPED;
2086 return old_flv_size;
2091 int old_flv_size,
ret;
2094 const int size = pkt->
size - skip;
2105 bytestream2_put_byte(&pbc, pkt->
type);
2106 bytestream2_put_be24(&pbc, size);
2107 bytestream2_put_be24(&pbc, ts);
2108 bytestream2_put_byte(&pbc, ts >> 24);
2109 bytestream2_put_be24(&pbc, 0);
2111 bytestream2_put_be32(&pbc, 0);
2120 char statusmsg[128];
2121 int stringlen,
ret, skip = 0;
2130 if (!strcmp(commandbuffer,
"@setDataFrame")) {
2133 sizeof(statusmsg), &stringlen);
2155 switch (pkt->
type) {
2157 av_dlog(s,
"received bytes read report\n");
2198 uint32_t ts, cts, pts = 0;
2214 type = bytestream_get_byte(&next);
2215 size = bytestream_get_be24(&next);
2216 cts = bytestream_get_be24(&next);
2217 cts |= bytestream_get_byte(&next) << 24;
2222 if (size + 3 + 4 > pkt->
data + pkt->
size - next)
2224 bytestream_put_byte(&p, type);
2225 bytestream_put_be24(&p, size);
2226 bytestream_put_be24(&p, ts);
2227 bytestream_put_byte(&p, ts >> 24);
2228 memcpy(p, next, size + 3 + 4);
2229 next += size + 3 + 4;
2234 "RTMP_PT_METADATA packet\n");
2345 for (i = 0; i < 2; i++) {
2369 char proto[8], hostname[256], path[1024], auth[100], *fname;
2382 hostname,
sizeof(hostname), &port,
2385 if (strchr(path,
' ')) {
2387 "Detected librtmp style URL parameters, these aren't supported "
2388 "by the libavformat internal RTMP handler currently enabled. "
2389 "See the documentation for the correct way to pass parameters.\n");
2393 char *ptr = strchr(auth,
':');
2401 if (rt->
listen && strcmp(proto,
"rtmp")) {
2406 if (!strcmp(proto,
"rtmpt") || !strcmp(proto,
"rtmpts")) {
2407 if (!strcmp(proto,
"rtmpts"))
2411 ff_url_join(buf,
sizeof(buf),
"ffrtmphttp", NULL, hostname, port, NULL);
2412 }
else if (!strcmp(proto,
"rtmps")) {
2416 ff_url_join(buf,
sizeof(buf),
"tls", NULL, hostname, port, NULL);
2417 }
else if (!strcmp(proto,
"rtmpe") || (!strcmp(proto,
"rtmpte"))) {
2418 if (!strcmp(proto,
"rtmpte"))
2419 av_dict_set(&opts,
"ffrtmpcrypt_tunneling",
"1", 1);
2422 ff_url_join(buf,
sizeof(buf),
"ffrtmpcrypt", NULL, hostname, port, NULL);
2429 ff_url_join(buf,
sizeof(buf),
"tcp", NULL, hostname, port,
2430 "?listen&listen_timeout=%d",
2433 ff_url_join(buf,
sizeof(buf),
"tcp", NULL, hostname, port, NULL);
2468 if (!strncmp(path,
"/ondemand/", 10)) {
2470 memcpy(rt->
app,
"ondemand", 9);
2472 char *next = *path ? path + 1 : path;
2473 char *p = strchr(next,
'/');
2479 char *
c = strchr(p + 1,
':');
2480 fname = strchr(p + 1,
'/');
2481 if (!fname || (c && c < fname)) {
2502 int len = strlen(fname);
2510 if (!strchr(fname,
':') && len >= 4 &&
2511 (!strcmp(fname + len - 4,
".f4v") ||
2512 !strcmp(fname + len - 4,
".mp4"))) {
2514 }
else if (len >= 4 && !strcmp(fname + len - 4,
".flv")) {
2515 fname[len - 4] =
'\0';
2529 port,
"/%s", rt->
app);
2565 }
while (ret ==
AVERROR(EAGAIN));
2575 for (i = 0; i < 2; i++)
2610 int orig_size =
size;
2616 if (data_left >= size) {
2621 if (data_left > 0) {
2640 "Seek on stream index %d at timestamp %"PRId64
" with flags %08x\n",
2641 stream_index, timestamp, flags);
2642 if ((ret =
gen_seek(s, rt, timestamp)) < 0) {
2644 "Unable to send seek command on stream index %d at timestamp "
2645 "%"PRId64
" with flags %08x\n",
2646 stream_index, timestamp, flags);
2657 int size_temp =
size;
2658 int pktsize, pkttype;
2683 pkttype = bytestream_get_byte(&header);
2684 pktsize = bytestream_get_be24(&header);
2685 ts = bytestream_get_be24(&header);
2686 ts |= bytestream_get_byte(&header) << 24;
2687 bytestream_get_be24(&header);
2707 pkttype, ts, pktsize)) < 0)
2737 }
while (buf_temp - buf < size);
2755 }
else if (ret < 0) {
2757 }
else if (ret == 1) {
2775 #define OFFSET(x) offsetof(RTMPContext, x)
2776 #define DEC AV_OPT_FLAG_DECODING_PARAM
2777 #define ENC AV_OPT_FLAG_ENCODING_PARAM
2781 {
"rtmp_buffer",
"Set buffer time in milliseconds. The default is 3000.",
OFFSET(client_buffer_time),
AV_OPT_TYPE_INT, {.i64 = 3000}, 0, INT_MAX,
DEC|
ENC},
2783 {
"rtmp_flashver",
"Version of the Flash plugin used to run the SWF player.",
OFFSET(flashver),
AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0,
DEC|
ENC},
2784 {
"rtmp_flush_interval",
"Number of packets flushed in the same request (RTMPT only).",
OFFSET(flush_interval),
AV_OPT_TYPE_INT, {.i64 = 10}, 0, INT_MAX,
ENC},
2785 {
"rtmp_live",
"Specify that the media is a live stream.",
OFFSET(live),
AV_OPT_TYPE_INT, {.i64 = -2}, INT_MIN, INT_MAX,
DEC,
"rtmp_live"},
2789 {
"rtmp_pageurl",
"URL of the web page in which the media was embedded. By default no value will be sent.",
OFFSET(pageurl),
AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0,
DEC},
2791 {
"rtmp_subscribe",
"Name of live stream to subscribe to. Defaults to rtmp_playpath.",
OFFSET(subscribe),
AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0,
DEC},
2793 {
"rtmp_swfsize",
"Size of the decompressed SWF file, required for SWFVerification.",
OFFSET(swfsize),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX,
DEC},
2795 {
"rtmp_swfverify",
"URL to player swf file, compute hash/size automatically.",
OFFSET(swfverify),
AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0,
DEC},
2796 {
"rtmp_tcurl",
"URL of the target stream. Defaults to proto://host[:port]/app.",
OFFSET(tcurl),
AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0,
DEC|
ENC},
2797 {
"rtmp_listen",
"Listen for incoming rtmp connections",
OFFSET(listen),
AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX,
DEC,
"rtmp_listen" },
2798 {
"listen",
"Listen for incoming rtmp connections",
OFFSET(listen),
AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX,
DEC,
"rtmp_listen" },
2799 {
"timeout",
"Maximum timeout (in seconds) to wait for incoming connections. -1 is infinite. Implies -rtmp_listen 1",
OFFSET(listen_timeout),
AV_OPT_TYPE_INT, {.i64 = -1}, INT_MIN, INT_MAX,
DEC,
"rtmp_listen" },
2803 #define RTMP_PROTOCOL(flavor) \
2804 static const AVClass flavor##_class = { \
2805 .class_name = #flavor, \
2806 .item_name = av_default_item_name, \
2807 .option = rtmp_options, \
2808 .version = LIBAVUTIL_VERSION_INT, \
2811 URLProtocol ff_##flavor##_protocol = { \
2813 .url_open = rtmp_open, \
2814 .url_read = rtmp_read, \
2815 .url_read_seek = rtmp_seek, \
2816 .url_write = rtmp_write, \
2817 .url_close = rtmp_close, \
2818 .priv_data_size = sizeof(RTMPContext), \
2819 .flags = URL_PROTOCOL_FLAG_NETWORK, \
2820 .priv_data_class= &flavor##_class, \
static int gen_bytes_read(URLContext *s, RTMPContext *rt, uint32_t ts)
Generate report on bytes read so far and send it to the server.
void av_sha_final(struct AVSHA *context, uint8_t *digest)
Finish hashing and output digest value.
void av_url_split(char *proto, int proto_size, char *authorization, int authorization_size, char *hostname, int hostname_size, int *port_ptr, char *path, int path_size, const char *url)
Split a URL string into components.
static int gen_swf_verification(URLContext *s, RTMPContext *rt)
Generate SWF verification message and send it to the server.
int ff_amf_match_string(const uint8_t *data, int size, const char *str)
Match AMF string with a NULL-terminated string.
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.
static int rtmp_read(URLContext *s, uint8_t *buf, int size)
int live
0: recorded, -1: live, -2: both
int ff_amf_read_null(GetByteContext *bc)
Read AMF NULL value.
uint8_t flv_header[RTMP_HEADER]
partial incoming flv packet header
void av_sha_update(struct AVSHA *context, const uint8_t *data, unsigned int len)
Update hash value.
static int rtmp_write(URLContext *s, const uint8_t *buf, int size)
static int handle_invoke_error(URLContext *s, RTMPPacket *pkt)
static int handle_invoke(URLContext *s, RTMPPacket *pkt)
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.
int av_sha_init(struct AVSHA *context, int bits)
Initialize SHA-1 or SHA-2 hashing.
#define AV_LOG_WARNING
Something somehow does not look correct.
static int gen_check_bw(URLContext *s, RTMPContext *rt)
Generate check bandwidth message and send it to the server.
static const uint8_t rtmp_server_key[]
Key used for RTMP server digest signing.
char * av_strdup(const char *s) av_malloc_attrib
Duplicate the string s.
static struct AVHashContext * hash
int ffurl_write(URLContext *h, const unsigned char *buf, int size)
Write size bytes from buf to the resource accessed by h.
#define RTMPS_DEFAULT_PORT
int is_streamed
true if streamed (no seek possible), default = false
static int gen_fcsubscribe_stream(URLContext *s, RTMPContext *rt, const char *subscribe)
void ff_amf_write_field_name(uint8_t **dst, const char *str)
Write string used as field name in AMF object to buffer.
int flv_header_bytes
number of initialized bytes in flv_header
AVIOInterruptCB interrupt_callback
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
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.
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
static int gen_create_stream(URLContext *s, RTMPContext *rt)
Generate 'createStream' call and send it to the server.
char * av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size)
Encode data to base64 and null-terminate.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int size, int search_flags)
URLContext * stream
TCP stream used in interactions with RTMP server.
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
int in_chunk_size
size of the chunks incoming RTMP packets are divided into
int skip_bytes
number of bytes to skip from the input FLV stream in the next write call
uint32_t last_bytes_read
number of bytes read last reported to server
static int rtmp_server_handshake(URLContext *s, RTMPContext *rt)
rtmp handshake server side
void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, int len)
Update hash value.
RTMPPacketType type
packet payload type
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
if((e=av_dict_get(options,"", NULL, AV_DICT_IGNORE_SUFFIX)))
int flv_nb_packets
number of flv packets published
static const char signature[]
static int append_flv_data(RTMPContext *rt, RTMPPacket *pkt, int skip)
#define RTMP_DEFAULT_PORT
uint32_t extra
probably an additional channel ID used during streaming data
ClientState state
current state
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
static const uint8_t offset[511][2]
static int gen_fcunpublish_stream(URLContext *s, RTMPContext *rt)
Generate 'FCUnpublish' call and send it to the server.
#define RTMP_PKTDATA_DEFAULT_SIZE
TrackedMethod * tracked_methods
tracked methods buffer
double strtod(const char *, char **)
void ff_amf_write_string(uint8_t **dst, const char *str)
Write string in AMF format to buffer.
static int rtmp_write_amf_data(URLContext *s, char *param, uint8_t **p)
int av_reallocp(void *ptr, size_t size)
Allocate or reallocate a block of memory.
int ff_rtmpe_compute_secret_key(URLContext *h, const uint8_t *serverdata, const uint8_t *clientdata, int type)
Compute the shared secret key and initialize the RC4 encryption.
void ff_rtmp_packet_dump(void *ctx, RTMPPacket *p)
Print information and contents of RTMP packet.
int nb_invokes
keeps track of invoke messages
int out_chunk_size
size of the chunks outgoing RTMP packets are divided into
int flv_size
current buffer size
#define AV_LOG_VERBOSE
Detailed information.
int listen_timeout
listen timeout to wait for new connections
int flush_interval
number of packets flushed in the same request (RTMPT only)
static void copy(LZOContext *c, int cnt)
Copies bytes from input to output buffer with checking.
char * swfverify
URL to player swf file, compute hash/size automatically.
static int rtmp_handshake(URLContext *s, RTMPContext *rt)
Perform handshake with the server by means of exchanging pseudorandom data signed with HMAC-SHA2 dige...
int encrypted
use an encrypted connection (RTMPE only)
int ff_rtmpe_gen_pub_key(URLContext *h, uint8_t *buf)
Initialize the Diffie-Hellmann context and generate the public key.
void ff_amf_write_object_end(uint8_t **dst)
Write marker for end of AMF object to buffer.
char * conn
append arbitrary AMF data to the Connect message
received a play command (for output)
static void del_tracked_method(RTMPContext *rt, int index)
int ff_rtmp_calc_digest_pos(const uint8_t *buf, int off, int mod_val, int add_val)
Calculate digest position for RTMP handshake packets.
static int rtmp_validate_digest(uint8_t *buf, int off)
Verify that the received server response has the expected digest value.
int size
packet payload size
static int gen_seek(URLContext *s, RTMPContext *rt, int64_t timestamp)
void ff_amf_write_bool(uint8_t **dst, int val)
Write boolean value in AMF format to buffer.
static int do_adobe_auth(RTMPContext *rt, const char *user, const char *salt, const char *opaque, const char *challenge)
static int rtmp_handshake_imprint_with_digest(uint8_t *buf, int encrypted)
Put HMAC-SHA2 digest of packet data (except for the bytes where this digest will be stored) into that...
static int write_status(URLContext *s, RTMPPacket *pkt, const char *status, const char *filename)
static int handle_client_bw(URLContext *s, RTMPPacket *pkt)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
char * pageurl
url of the web page
client has started the seek operation. Back on STATE_PLAYING when the time comes
static int rtmp_send_packet(RTMPContext *rt, RTMPPacket *pkt, int track)
char * flashver
version of the flash plugin
struct AVMD5 * av_md5_alloc(void)
Allocate an AVMD5 context.
static int handle_invoke_status(URLContext *s, RTMPPacket *pkt)
ClientState
RTMP protocol handler state.
char * swfurl
url of the swf player
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define PLAYER_KEY_OPEN_PART_LEN
length of partial key used for first client digest signing
void av_dict_free(AVDictionary **m)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
static int gen_fcpublish_stream(URLContext *s, RTMPContext *rt)
Generate 'FCPublish' call and send it to the server.
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
static int gen_delete_stream(URLContext *s, RTMPContext *rt)
Generate 'deleteStream' call and send it to the server.
char * playpath
stream identifier to play (with possible "mp4:" prefix)
client has not done anything yet
static void free_tracked_methods(RTMPContext *rt)
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.
int tracked_methods_size
size of the tracked methods buffer
#define RTMP_PROTOCOL(flavor)
client has performed handshake
static int gen_play(URLContext *s, RTMPContext *rt)
Generate 'play' call and send it to the server, then ping the server to start actual playing...
static av_always_inline void bytestream2_skip_p(PutByteContext *p, unsigned int size)
#define PLAYPATH_MAX_LENGTH
int swfhash_len
length of the SHA256 hash
#define CONFIG_FFRTMPCRYPT_PROTOCOL
static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt)
Parse received packet and possibly perform some action depending on the packet contents.
#define AV_BASE64_SIZE(x)
Calculate the output size needed to base64-encode x bytes to a null-terminated string.
void * av_realloc(void *ptr, size_t size) 1(2)
Allocate or reallocate a block of memory.
client has started sending multimedia data to server (for output)
void ff_rtmp_packet_destroy(RTMPPacket *pkt)
Free RTMP packet.
static int gen_publish(URLContext *s, RTMPContext *rt)
Generate 'publish' call and send it to the server.
client has started receiving multimedia data from server
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int client_buffer_time
client buffer time in ms
client FCPublishing stream (for output)
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.
static int rtmp_close(URLContext *h)
int nb_streamid
The next stream id to return on createStream calls.
#define RTMP_CLIENT_PLATFORM
emulated Flash client version - 9.0.124.2 on Linux
static int gen_pong(URLContext *s, RTMPContext *rt, RTMPPacket *ppkt)
Generate ping reply and send it to the server.
static int add_tracked_method(RTMPContext *rt, const char *name, int id)
int is_input
input/output flag
static const uint8_t rtmp_player_key[]
Client key used for digest signing.
received a publish command (for input)
static int rtmp_send_hs_packet(RTMPContext *rt, uint32_t first_int, uint32_t second_int, char *arraydata, int size)
static int64_t rtmp_seek(URLContext *s, int stream_index, int64_t timestamp, int flags)
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.
static av_always_inline unsigned int bytestream_get_buffer(const uint8_t **b, uint8_t *dst, unsigned int size)
static int gen_buffer_time(URLContext *s, RTMPContext *rt)
Generate client buffer time and send it to the server.
static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p, const uint8_t *src, unsigned int size)
the broadcast has been stopped
char * swfhash
SHA256 hash of the decompressed SWF file (32 bytes)
char swfverification[42]
hash of the SWF verification
int nb_tracked_methods
number of tracked methods
offset must point to a pointer immediately followed by an int for the length
int ff_url_join(char *str, int size, const char *proto, const char *authorization, const char *hostname, int port, const char *fmt,...)
static int do_llnw_auth(RTMPContext *rt, const char *user, const char *nonce)
int flv_off
number of bytes read from current buffer
void av_lfg_init(AVLFG *c, unsigned int seed)
static int handle_chunk_size(URLContext *s, RTMPPacket *pkt)
uint32_t bytes_read
number of bytes read from server
static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
void av_md5_init(struct AVMD5 *ctx)
Initialize MD5 hashing.
char * subscribe
name of live stream to subscribe
void ff_rtmpe_encrypt_sig(URLContext *h, uint8_t *sig, const uint8_t *digest, int type)
Encrypt the signature.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
channel for sending server control messages
static int gen_connect(URLContext *s, RTMPContext *rt)
Generate 'connect' call and send it to the server.
static int gen_release_stream(URLContext *s, RTMPContext *rt)
Generate 'releaseStream' call and send it to the server.
Describe the class of an AVClass context structure.
static int write_begin(URLContext *s)
static int find_tracked_method(URLContext *s, RTMPPacket *pkt, int offset, char **tracked_method)
int ff_rtmp_packet_create(RTMPPacket *pkt, int channel_id, RTMPPacketType type, int timestamp, int size)
Create new RTMP packet with given attributes.
int ff_rtmpe_update_keystream(URLContext *h)
Update the keystream and set RC4 keys for encryption.
int ff_amf_read_number(GetByteContext *bc, double *val)
Read AMF number value.
static int handle_notify(URLContext *s, RTMPPacket *pkt)
int channel_id
RTMP channel ID (nothing to do with audio/video channels though)
RTMPPacket out_pkt
rtmp packet, created from flv a/v or metadata (for output)
char * tcurl
url of the target stream
static int handle_connect_error(URLContext *s, const char *desc)
void av_md5_final(struct AVMD5 *ctx, uint8_t *dst)
Finish hashing and output digest value.
int listen
listen mode flag
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes...
static int rtmp_receive_hs_packet(RTMPContext *rt, uint32_t *first_int, uint32_t *second_int, char *arraydata, int size)
int ffurl_close(URLContext *h)
#define SERVER_KEY_OPEN_PART_LEN
length of partial key used for first server digest signing
channel for network-related messages (bandwidth report, ping, etc)
static int gen_server_bw(URLContext *s, RTMPContext *rt)
Generate server bandwidth message and send it to the server.
static int handle_metadata(RTMPContext *rt, RTMPPacket *pkt)
void ff_amf_write_null(uint8_t **dst)
Write AMF NULL value to buffer.
uint32_t timestamp
packet full timestamp
#define RTMP_HANDSHAKE_PACKET_SIZE
#define FLASHVER_MAX_LENGTH
uint8_t * data
packet payload
static int rtmp_open(URLContext *s, const char *uri, int flags)
Open RTMP connection and verify that the stream can be played.
int stream_id
ID assigned by the server for the stream.
static av_always_inline double av_int2double(uint64_t i)
Reinterpret a 64-bit integer as a double.
RTMPPacket * prev_pkt[2]
packet history used when reading and sending packets ([0] for reading, [1] for writing) ...
int64_t ffurl_seek(URLContext *h, int64_t pos, int whence)
Change the position that will be used by the next read/write operation on the resource accessed by h...
char * app
name of application
int ffurl_open(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create an URLContext for accessing to the resource indicated by url, and open it. ...
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 int rtmp_calc_swfhash(URLContext *s)
char * filename
specified URL
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.
int ff_rtmp_calc_digest(const uint8_t *src, int len, int gap, const uint8_t *key, int keylen, uint8_t *dst)
Calculate HMAC-SHA2 digest for RTMP handshake packets.
int ff_amf_read_string(GetByteContext *bc, uint8_t *str, int strsize, int *length)
Read AMF string value.
static int send_invoke_response(URLContext *s, RTMPPacket *pkt)
void ff_amf_write_number(uint8_t **dst, double val)
Write number in AMF format to buffer.
static const AVOption rtmp_options[]
#define AVERROR_INVALIDDATA
static int get_packet(URLContext *s, int for_header)
Interact with the server by receiving and sending RTMP packets until there is some significant data (...
static int handle_invoke_result(URLContext *s, RTMPPacket *pkt)
uint8_t * flv_data
buffer with data for demuxer
static int read_connect(URLContext *s, RTMPContext *rt)
static int handle_server_bw(URLContext *s, RTMPPacket *pkt)
void ff_amf_write_object_start(uint8_t **dst)
Write marker for AMF object to buffer.
int max_packet_size
if non zero, the stream is packetized with this max packet size
int swfsize
size of the decompressed SWF file
int nb_prev_pkt[2]
number of elements in prev_pkt
structure for holding RTMP packets
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.
static int update_offset(RTMPContext *rt, int size)
unbuffered private I/O API
invoke some stream action
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
static int handle_ping(URLContext *s, RTMPPacket *pkt)
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...
uint32_t client_report_size
number of bytes after which client should report to server
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...) av_printf_format(3
Append output to a string, according to a format.
int server_bw
server bandwidth
static int rtmp_calc_swf_verification(URLContext *s, RTMPContext *rt, uint8_t *buf)
struct AVSHA * av_sha_alloc(void)
Allocate an AVSHA context.