#include "libavcodec/bytestream.h"
#include "libavutil/avstring.h"
#include "libavutil/intfloat.h"
#include "libavutil/lfg.h"
#include "libavutil/opt.h"
#include "libavutil/sha.h"
#include "avformat.h"
#include "internal.h"
#include "network.h"
#include "flv.h"
#include "rtmp.h"
#include "rtmppkt.h"
#include "url.h"
Go to the source code of this file.
Data Structures | |
struct | RTMPContext |
protocol handler context More... | |
Defines | |
#define | APP_MAX_LENGTH 128 |
#define | PLAYPATH_MAX_LENGTH 256 |
#define | TCURL_MAX_LENGTH 512 |
#define | FLASHVER_MAX_LENGTH 64 |
#define | PLAYER_KEY_OPEN_PART_LEN 30 |
length of partial key used for first client digest signing | |
#define | SERVER_KEY_OPEN_PART_LEN 36 |
length of partial key used for first server digest signing | |
#define | HMAC_IPAD_VAL 0x36 |
#define | HMAC_OPAD_VAL 0x5C |
#define | OFFSET(x) offsetof(RTMPContext, x) |
#define | DEC AV_OPT_FLAG_DECODING_PARAM |
#define | ENC AV_OPT_FLAG_ENCODING_PARAM |
Enumerations | |
enum | ClientState { STATE_START, STATE_HANDSHAKED, STATE_RELEASING, STATE_FCPUBLISH, STATE_CONNECTING, STATE_READY, STATE_PLAYING, STATE_PUBLISHING, STATE_STOPPED } |
RTMP protocol handler state. More... | |
Functions | |
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. | |
static int | gen_fcpublish_stream (URLContext *s, RTMPContext *rt) |
Generate 'FCPublish' call and send it to the server. | |
static int | gen_fcunpublish_stream (URLContext *s, RTMPContext *rt) |
Generate 'FCUnpublish' call and send it to the server. | |
static int | gen_create_stream (URLContext *s, RTMPContext *rt) |
Generate 'createStream' call and send it to the server. | |
static int | gen_delete_stream (URLContext *s, RTMPContext *rt) |
Generate 'deleteStream' call and send it to the server. | |
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 int | gen_publish (URLContext *s, RTMPContext *rt) |
Generate 'publish' call and send it to the server. | |
static int | gen_pong (URLContext *s, RTMPContext *rt, RTMPPacket *ppkt) |
Generate ping reply and send it to the server. | |
static int | gen_server_bw (URLContext *s, RTMPContext *rt) |
Generate server bandwidth message and send it to the server. | |
static int | gen_check_bw (URLContext *s, RTMPContext *rt) |
Generate check bandwidth message and send it to the server. | |
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. | |
static int | 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. | |
static int | rtmp_handshake_imprint_with_digest (uint8_t *buf) |
Put HMAC-SHA2 digest of packet data (except for the bytes where this digest will be stored) into that packet. | |
static int | rtmp_validate_digest (uint8_t *buf, int off) |
Verify that the received server response has the expected digest value. | |
static int | rtmp_handshake (URLContext *s, RTMPContext *rt) |
Perform handshake with the server by means of exchanging pseudorandom data signed with HMAC-SHA2 digest. | |
static int | rtmp_parse_result (URLContext *s, RTMPContext *rt, RTMPPacket *pkt) |
Parse received packet and possibly perform some action depending on the packet contents. | |
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 (media data or expected status notification). | |
static int | rtmp_close (URLContext *h) |
static int | rtmp_open (URLContext *s, const char *uri, int flags) |
Open RTMP connection and verify that the stream can be played. | |
static int | rtmp_read (URLContext *s, uint8_t *buf, int size) |
static int | rtmp_write (URLContext *s, const uint8_t *buf, int size) |
Variables | |
static const uint8_t | rtmp_player_key [] |
Client key used for digest signing. | |
static const uint8_t | rtmp_server_key [] |
Key used for RTMP server digest signing. | |
static const AVOption | rtmp_options [] |
static const AVClass | rtmp_class |
URLProtocol | ff_rtmp_protocol |
Definition in file rtmpproto.c.
#define APP_MAX_LENGTH 128 |
#define DEC AV_OPT_FLAG_DECODING_PARAM |
Definition at line 1215 of file rtmpproto.c.
#define ENC AV_OPT_FLAG_ENCODING_PARAM |
Definition at line 1216 of file rtmpproto.c.
#define FLASHVER_MAX_LENGTH 64 |
#define HMAC_IPAD_VAL 0x36 |
#define HMAC_OPAD_VAL 0x5C |
#define OFFSET | ( | x | ) | offsetof(RTMPContext, x) |
Definition at line 1214 of file rtmpproto.c.
#define PLAYER_KEY_OPEN_PART_LEN 30 |
length of partial key used for first client digest signing
Definition at line 92 of file rtmpproto.c.
Referenced by rtmp_handshake_imprint_with_digest().
#define PLAYPATH_MAX_LENGTH 256 |
#define SERVER_KEY_OPEN_PART_LEN 36 |
length of partial key used for first server digest signing
Definition at line 103 of file rtmpproto.c.
Referenced by rtmp_validate_digest().
#define TCURL_MAX_LENGTH 512 |
enum ClientState |
RTMP protocol handler state.
Definition at line 51 of file rtmpproto.c.
static int gen_bytes_read | ( | URLContext * | s, | |
RTMPContext * | rt, | |||
uint32_t | ts | |||
) | [static] |
Generate report on bytes read so far and send it to the server.
Definition at line 458 of file rtmpproto.c.
Referenced by get_packet().
static int gen_check_bw | ( | URLContext * | s, | |
RTMPContext * | rt | |||
) | [static] |
Generate check bandwidth message and send it to the server.
Definition at line 434 of file rtmpproto.c.
Referenced by rtmp_parse_result().
static int gen_connect | ( | URLContext * | s, | |
RTMPContext * | rt | |||
) | [static] |
Generate 'connect' call and send it to the server.
Definition at line 118 of file rtmpproto.c.
Referenced by rtmp_open().
static int gen_create_stream | ( | URLContext * | s, | |
RTMPContext * | rt | |||
) | [static] |
Generate 'createStream' call and send it to the server.
It should make the server allocate some channel for media streams.
Definition at line 261 of file rtmpproto.c.
Referenced by rtmp_parse_result().
static int gen_delete_stream | ( | URLContext * | s, | |
RTMPContext * | rt | |||
) | [static] |
Generate 'deleteStream' call and send it to the server.
It should make the server remove some channel for media streams.
Definition at line 290 of file rtmpproto.c.
Referenced by rtmp_close().
static int gen_fcpublish_stream | ( | URLContext * | s, | |
RTMPContext * | rt | |||
) | [static] |
Generate 'FCPublish' call and send it to the server.
It should make the server preapare for receiving media streams.
Definition at line 207 of file rtmpproto.c.
Referenced by rtmp_parse_result().
static int gen_fcunpublish_stream | ( | URLContext * | s, | |
RTMPContext * | rt | |||
) | [static] |
Generate 'FCUnpublish' call and send it to the server.
It should make the server destroy stream.
Definition at line 234 of file rtmpproto.c.
Referenced by rtmp_close().
static int gen_play | ( | URLContext * | s, | |
RTMPContext * | rt | |||
) | [static] |
Generate 'play' call and send it to the server, then ping the server to start actual playing.
Definition at line 318 of file rtmpproto.c.
Referenced by rtmp_parse_result().
static int gen_pong | ( | URLContext * | s, | |
RTMPContext * | rt, | |||
RTMPPacket * | ppkt | |||
) | [static] |
Generate ping reply and send it to the server.
Definition at line 391 of file rtmpproto.c.
Referenced by rtmp_parse_result().
static int gen_publish | ( | URLContext * | s, | |
RTMPContext * | rt | |||
) | [static] |
Generate 'publish' call and send it to the server.
Definition at line 361 of file rtmpproto.c.
Referenced by rtmp_parse_result().
static int gen_release_stream | ( | URLContext * | s, | |
RTMPContext * | rt | |||
) | [static] |
Generate 'releaseStream' call and send it to the server.
It should make the server release some channel for media streams.
Definition at line 180 of file rtmpproto.c.
Referenced by rtmp_parse_result().
static int gen_server_bw | ( | URLContext * | s, | |
RTMPContext * | rt | |||
) | [static] |
Generate server bandwidth message and send it to the server.
Definition at line 413 of file rtmpproto.c.
Referenced by rtmp_parse_result().
static int get_packet | ( | URLContext * | s, | |
int | for_header | |||
) | [static] |
Interact with the server by receiving and sending RTMP packets until there is some significant data (media data or expected status notification).
s | reading context | |
for_header | non-zero value tells function to work until it gets notification from the server that playing has been started, otherwise function will work until some media data is received (or an error happens) |
Definition at line 838 of file rtmpproto.c.
Referenced by ff_audio_rechunk_interleave(), rtmp_open(), and rtmp_read().
static int rtmp_calc_digest | ( | const uint8_t * | src, | |
int | len, | |||
int | gap, | |||
const uint8_t * | key, | |||
int | keylen, | |||
uint8_t * | dst | |||
) | [static] |
Calculate HMAC-SHA2 digest for RTMP handshake packets.
src | input buffer | |
len | input buffer length (should be 1536) | |
gap | offset in buffer where 32 bytes should not be taken into account when calculating digest (since it will be used to store that digest) | |
key | digest key | |
keylen | digest key length | |
dst | buffer where calculated digest will be stored (32 bytes) |
Definition at line 491 of file rtmpproto.c.
Referenced by rtmp_handshake(), rtmp_handshake_imprint_with_digest(), and rtmp_validate_digest().
static int rtmp_close | ( | URLContext * | h | ) | [static] |
Definition at line 932 of file rtmpproto.c.
static int rtmp_handshake | ( | URLContext * | s, | |
RTMPContext * | rt | |||
) | [static] |
Perform handshake with the server by means of exchanging pseudorandom data signed with HMAC-SHA2 digest.
Definition at line 592 of file rtmpproto.c.
Referenced by rtmp_open().
static int rtmp_handshake_imprint_with_digest | ( | uint8_t * | buf | ) | [static] |
Put HMAC-SHA2 digest of packet data (except for the bytes where this digest will be stored) into that packet.
buf | handshake data (1536 bytes) |
Definition at line 540 of file rtmpproto.c.
Referenced by rtmp_handshake().
static int rtmp_open | ( | URLContext * | s, | |
const char * | uri, | |||
int | flags | |||
) | [static] |
Open RTMP connection and verify that the stream can be played.
URL syntax: rtmp://server[:port][/app][/playpath] where 'app' is first one or two directories in the path (e.g. /ondemand/, /flash/live/, etc.) and 'playpath' is a file name (the rest of the path, may be prefixed with "mp4:")
Definition at line 961 of file rtmpproto.c.
static int rtmp_parse_result | ( | URLContext * | s, | |
RTMPContext * | rt, | |||
RTMPPacket * | pkt | |||
) | [static] |
Parse received packet and possibly perform some action depending on the packet contents.
Definition at line 695 of file rtmpproto.c.
Referenced by get_packet().
static int rtmp_read | ( | URLContext * | s, | |
uint8_t * | buf, | |||
int | size | |||
) | [static] |
Definition at line 1110 of file rtmpproto.c.
static int rtmp_validate_digest | ( | uint8_t * | buf, | |
int | off | |||
) | [static] |
Verify that the received server response has the expected digest value.
buf | handshake data received from the server (1536 bytes) | |
off | position to search digest offset from |
Definition at line 565 of file rtmpproto.c.
Referenced by rtmp_handshake().
static int rtmp_write | ( | URLContext * | s, | |
const uint8_t * | buf, | |||
int | size | |||
) | [static] |
Definition at line 1137 of file rtmpproto.c.
Initial value:
{ .name = "rtmp", .url_open = rtmp_open, .url_read = rtmp_read, .url_write = rtmp_write, .url_close = rtmp_close, .priv_data_size = sizeof(RTMPContext), .flags = URL_PROTOCOL_FLAG_NETWORK, .priv_data_class= &rtmp_class, }
Definition at line 1238 of file rtmpproto.c.
const AVClass rtmp_class [static] |
Initial value:
{ .class_name = "rtmp", .item_name = av_default_item_name, .option = rtmp_options, .version = LIBAVUTIL_VERSION_INT, }
Definition at line 1231 of file rtmpproto.c.
const AVOption rtmp_options[] [static] |
Initial value:
{ {"rtmp_app", "Name of application to connect to on the RTMP server", OFFSET(app), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC}, {"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}, {"rtmp_live", "Specify that the media is a live stream.", OFFSET(live), AV_OPT_TYPE_INT, {-2}, INT_MIN, INT_MAX, DEC, "rtmp_live"}, {"any", "both", 0, AV_OPT_TYPE_CONST, {-2}, 0, 0, DEC, "rtmp_live"}, {"live", "live stream", 0, AV_OPT_TYPE_CONST, {-1}, 0, 0, DEC, "rtmp_live"}, {"recorded", "recorded stream", 0, AV_OPT_TYPE_CONST, {0}, 0, 0, DEC, "rtmp_live"}, {"rtmp_playpath", "Stream identifier to play or to publish", OFFSET(playpath), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC}, {"rtmp_swfurl", "URL of the SWF player. By default no value will be sent", OFFSET(swfurl), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC}, {"rtmp_tcurl", "URL of the target stream. Defaults to rtmp://host[:port]/app.", OFFSET(tcurl), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC}, { NULL }, }
Definition at line 1218 of file rtmpproto.c.
const uint8_t rtmp_player_key[] [static] |
Initial value:
{ 'G', 'e', 'n', 'u', 'i', 'n', 'e', ' ', 'A', 'd', 'o', 'b', 'e', ' ', 'F', 'l', 'a', 's', 'h', ' ', 'P', 'l', 'a', 'y', 'e', 'r', ' ', '0', '0', '1', 0xF0, 0xEE, 0xC2, 0x4A, 0x80, 0x68, 0xBE, 0xE8, 0x2E, 0x00, 0xD0, 0xD1, 0x02, 0x9E, 0x7E, 0x57, 0x6E, 0xEC, 0x5D, 0x2D, 0x29, 0x80, 0x6F, 0xAB, 0x93, 0xB8, 0xE6, 0x36, 0xCF, 0xEB, 0x31, 0xAE }
Definition at line 94 of file rtmpproto.c.
Referenced by rtmp_handshake(), and rtmp_handshake_imprint_with_digest().
const uint8_t rtmp_server_key[] [static] |
Initial value:
{ 'G', 'e', 'n', 'u', 'i', 'n', 'e', ' ', 'A', 'd', 'o', 'b', 'e', ' ', 'F', 'l', 'a', 's', 'h', ' ', 'M', 'e', 'd', 'i', 'a', ' ', 'S', 'e', 'r', 'v', 'e', 'r', ' ', '0', '0', '1', 0xF0, 0xEE, 0xC2, 0x4A, 0x80, 0x68, 0xBE, 0xE8, 0x2E, 0x00, 0xD0, 0xD1, 0x02, 0x9E, 0x7E, 0x57, 0x6E, 0xEC, 0x5D, 0x2D, 0x29, 0x80, 0x6F, 0xAB, 0x93, 0xB8, 0xE6, 0x36, 0xCF, 0xEB, 0x31, 0xAE }
Definition at line 105 of file rtmpproto.c.
Referenced by rtmp_handshake(), and rtmp_validate_digest().