FFmpeg
|
#include "config_components.h"
#include "libavcodec/bytestream.h"
#include "libavutil/avstring.h"
#include "libavutil/base64.h"
#include "libavutil/intfloat.h"
#include "libavutil/lfg.h"
#include "libavutil/md5.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/random_seed.h"
#include "avformat.h"
#include "internal.h"
#include "network.h"
#include "flv.h"
#include "rtmp.h"
#include "rtmpcrypt.h"
#include "rtmppkt.h"
#include "url.h"
#include "version.h"
Go to the source code of this file.
Data Structures | |
struct | TrackedMethod |
struct | RTMPContext |
protocol handler context More... | |
Macros | |
#define | APP_MAX_LENGTH 1024 |
#define | TCURL_MAX_LENGTH 1024 |
#define | FLASHVER_MAX_LENGTH 64 |
#define | RTMP_PKTDATA_DEFAULT_SIZE 4096 |
#define | RTMP_HEADER 11 |
#define | PLAYER_KEY_OPEN_PART_LEN 30 |
length of partial key used for first client digest signing More... | |
#define | SERVER_KEY_OPEN_PART_LEN 36 |
length of partial key used for first server digest signing More... | |
#define | RTMP_CTRL_ABORT_MESSAGE (2) |
#define | OFFSET(x) offsetof(RTMPContext, x) |
#define | DEC AV_OPT_FLAG_DECODING_PARAM |
#define | ENC AV_OPT_FLAG_ENCODING_PARAM |
#define | RTMP_PROTOCOL_0(flavor) |
#define | RTMP_PROTOCOL_1(flavor) |
#define | RTMP_PROTOCOL_2(flavor, enabled) RTMP_PROTOCOL_ ## enabled(flavor) |
#define | RTMP_PROTOCOL_3(flavor, config) RTMP_PROTOCOL_2(flavor, config) |
#define | RTMP_PROTOCOL(flavor, uppercase) RTMP_PROTOCOL_3(flavor, CONFIG_ ## uppercase ## _PROTOCOL) |
Enumerations | |
enum | ClientState { STATE_START, STATE_HANDSHAKED, STATE_FCPUBLISH, STATE_PLAYING, STATE_SEEKING, STATE_PUBLISHING, STATE_RECEIVING, STATE_SENDING, STATE_STOPPED } |
RTMP protocol handler state. More... | |
Functions | |
static int | handle_chunk_size (URLContext *s, RTMPPacket *pkt) |
static int | handle_window_ack_size (URLContext *s, RTMPPacket *pkt) |
static int | handle_set_peer_bw (URLContext *s, RTMPPacket *pkt) |
static int | add_tracked_method (RTMPContext *rt, const char *name, int id) |
static void | del_tracked_method (RTMPContext *rt, int index) |
static int | find_tracked_method (URLContext *s, RTMPPacket *pkt, int offset, char **tracked_method) |
static void | free_tracked_methods (RTMPContext *rt) |
static int | rtmp_send_packet (RTMPContext *rt, RTMPPacket *pkt, int track) |
static int | rtmp_write_amf_data (URLContext *s, char *param, uint8_t **p) |
static int | gen_connect (URLContext *s, RTMPContext *rt) |
Generate 'connect' call and send it to the server. More... | |
static int | read_connect (URLContext *s, RTMPContext *rt) |
static int | gen_release_stream (URLContext *s, RTMPContext *rt) |
Generate 'releaseStream' call and send it to the server. More... | |
static int | gen_fcpublish_stream (URLContext *s, RTMPContext *rt) |
Generate 'FCPublish' call and send it to the server. More... | |
static int | gen_fcunpublish_stream (URLContext *s, RTMPContext *rt) |
Generate 'FCUnpublish' call and send it to the server. More... | |
static int | gen_create_stream (URLContext *s, RTMPContext *rt) |
Generate 'createStream' call and send it to the server. More... | |
static int | gen_delete_stream (URLContext *s, RTMPContext *rt) |
Generate 'deleteStream' call and send it to the server. More... | |
static int | gen_get_stream_length (URLContext *s, RTMPContext *rt) |
Generate 'getStreamLength' call and send it to the server. More... | |
static int | gen_buffer_time (URLContext *s, RTMPContext *rt) |
Generate client buffer time and send it to the server. More... | |
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. More... | |
static int | gen_seek (URLContext *s, RTMPContext *rt, int64_t timestamp) |
static int | gen_pause (URLContext *s, RTMPContext *rt, int pause, uint32_t timestamp) |
Generate a pause packet that either pauses or unpauses the current stream. More... | |
static int | gen_publish (URLContext *s, RTMPContext *rt) |
Generate 'publish' call and send it to the server. More... | |
static int | gen_pong (URLContext *s, RTMPContext *rt, RTMPPacket *ppkt) |
Generate ping reply and send it to the server. More... | |
static int | gen_swf_verification (URLContext *s, RTMPContext *rt) |
Generate SWF verification message and send it to the server. More... | |
static int | gen_window_ack_size (URLContext *s, RTMPContext *rt) |
Generate window acknowledgement size message and send it to the server. More... | |
static int | gen_check_bw (URLContext *s, RTMPContext *rt) |
Generate check bandwidth message and send it to the server. More... | |
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. More... | |
static int | gen_fcsubscribe_stream (URLContext *s, RTMPContext *rt, const char *subscribe) |
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 packet. More... | |
static int | rtmp_validate_digest (uint8_t *buf, int off) |
Verify that the received server response has the expected digest value. More... | |
static int | rtmp_calc_swf_verification (URLContext *s, RTMPContext *rt, uint8_t *buf) |
static int | rtmp_calc_swfhash (URLContext *s) |
static int | rtmp_handshake (URLContext *s, RTMPContext *rt) |
Perform handshake with the server by means of exchanging pseudorandom data signed with HMAC-SHA2 digest. More... | |
static int | rtmp_receive_hs_packet (RTMPContext *rt, uint32_t *first_int, uint32_t *second_int, char *arraydata, int size) |
static int | rtmp_send_hs_packet (RTMPContext *rt, uint32_t first_int, uint32_t second_int, char *arraydata, int size) |
static int | rtmp_server_handshake (URLContext *s, RTMPContext *rt) |
rtmp handshake server side More... | |
static int | handle_user_control (URLContext *s, RTMPPacket *pkt) |
static int | do_adobe_auth (RTMPContext *rt, const char *user, const char *salt, const char *opaque, const char *challenge) |
static int | do_llnw_auth (RTMPContext *rt, const char *user, const char *nonce) |
static int | handle_connect_error (URLContext *s, const char *desc) |
static int | handle_invoke_error (URLContext *s, RTMPPacket *pkt) |
static int | write_begin (URLContext *s) |
static int | write_status (URLContext *s, RTMPPacket *pkt, const char *status, const char *description, const char *details) |
static int | send_invoke_response (URLContext *s, RTMPPacket *pkt) |
static int | read_number_result (RTMPPacket *pkt, double *number) |
Read the AMF_NUMBER response ("_result") to a function call (e.g. More... | |
static int | handle_invoke_result (URLContext *s, RTMPPacket *pkt) |
static int | handle_invoke_status (URLContext *s, RTMPPacket *pkt) |
static int | handle_invoke (URLContext *s, RTMPPacket *pkt) |
static int | update_offset (RTMPContext *rt, int size) |
static int | append_flv_data (RTMPContext *rt, RTMPPacket *pkt, int skip) |
static int | handle_notify (URLContext *s, RTMPPacket *pkt) |
static int | rtmp_parse_result (URLContext *s, RTMPContext *rt, RTMPPacket *pkt) |
Parse received packet and possibly perform some action depending on the packet contents. More... | |
static int | handle_metadata (RTMPContext *rt, RTMPPacket *pkt) |
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). More... | |
static int | rtmp_close (URLContext *h) |
static int | inject_fake_duration_metadata (RTMPContext *rt) |
Insert a fake onMetadata packet into the FLV stream to notify the FLV demuxer about the duration of the stream. More... | |
static int | rtmp_open (URLContext *s, const char *uri, int flags, AVDictionary **opts) |
Open RTMP connection and verify that the stream can be played. More... | |
static int | rtmp_read (URLContext *s, uint8_t *buf, int size) |
static int64_t | rtmp_seek (void *opaque, int stream_index, int64_t timestamp, int flags) |
static int | rtmp_pause (void *opaque, int pause) |
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. More... | |
static const uint8_t | rtmp_server_key [] |
Key used for RTMP server digest signing. More... | |
static const AVOption | rtmp_options [] |
RTMP protocol
Definition in file rtmpproto.c.
#define APP_MAX_LENGTH 1024 |
Definition at line 54 of file rtmpproto.c.
#define TCURL_MAX_LENGTH 1024 |
Definition at line 55 of file rtmpproto.c.
#define FLASHVER_MAX_LENGTH 64 |
Definition at line 56 of file rtmpproto.c.
#define RTMP_PKTDATA_DEFAULT_SIZE 4096 |
Definition at line 57 of file rtmpproto.c.
#define RTMP_HEADER 11 |
Definition at line 58 of file rtmpproto.c.
#define PLAYER_KEY_OPEN_PART_LEN 30 |
length of partial key used for first client digest signing
Definition at line 139 of file rtmpproto.c.
#define SERVER_KEY_OPEN_PART_LEN 36 |
length of partial key used for first server digest signing
Definition at line 150 of file rtmpproto.c.
#define RTMP_CTRL_ABORT_MESSAGE (2) |
Definition at line 451 of file rtmpproto.c.
#define OFFSET | ( | x | ) | offsetof(RTMPContext, x) |
Definition at line 3140 of file rtmpproto.c.
#define DEC AV_OPT_FLAG_DECODING_PARAM |
Definition at line 3141 of file rtmpproto.c.
#define ENC AV_OPT_FLAG_ENCODING_PARAM |
Definition at line 3142 of file rtmpproto.c.
#define RTMP_PROTOCOL_0 | ( | flavor | ) |
Definition at line 3170 of file rtmpproto.c.
#define RTMP_PROTOCOL_1 | ( | flavor | ) |
Definition at line 3171 of file rtmpproto.c.
#define RTMP_PROTOCOL_2 | ( | flavor, | |
enabled | |||
) | RTMP_PROTOCOL_ ## enabled(flavor) |
Definition at line 3191 of file rtmpproto.c.
#define RTMP_PROTOCOL_3 | ( | flavor, | |
config | |||
) | RTMP_PROTOCOL_2(flavor, config) |
Definition at line 3193 of file rtmpproto.c.
#define RTMP_PROTOCOL | ( | flavor, | |
uppercase | |||
) | RTMP_PROTOCOL_3(flavor, CONFIG_ ## uppercase ## _PROTOCOL) |
Definition at line 3195 of file rtmpproto.c.
enum ClientState |
RTMP protocol handler state.
Definition at line 61 of file rtmpproto.c.
|
static |
Definition at line 1535 of file rtmpproto.c.
Referenced by read_connect(), and rtmp_parse_result().
|
static |
Definition at line 1622 of file rtmpproto.c.
Referenced by read_connect(), and rtmp_parse_result().
|
static |
Definition at line 1595 of file rtmpproto.c.
Referenced by read_connect(), and rtmp_parse_result().
|
static |
Definition at line 166 of file rtmpproto.c.
Referenced by rtmp_send_packet().
|
static |
Definition at line 189 of file rtmpproto.c.
Referenced by find_tracked_method().
|
static |
Definition at line 196 of file rtmpproto.c.
Referenced by handle_invoke_error(), and handle_invoke_result().
|
static |
Definition at line 221 of file rtmpproto.c.
Referenced by rtmp_close(), and rtmp_open().
|
static |
Definition at line 232 of file rtmpproto.c.
Referenced by gen_buffer_time(), gen_bytes_read(), gen_check_bw(), gen_connect(), gen_create_stream(), gen_delete_stream(), gen_fcpublish_stream(), gen_fcsubscribe_stream(), gen_fcunpublish_stream(), gen_get_stream_length(), gen_pause(), gen_play(), gen_pong(), gen_publish(), gen_release_stream(), gen_seek(), gen_swf_verification(), gen_window_ack_size(), and rtmp_write().
|
static |
Definition at line 260 of file rtmpproto.c.
Referenced by gen_connect().
|
static |
Generate 'connect' call and send it to the server.
Definition at line 323 of file rtmpproto.c.
Referenced by rtmp_open().
|
static |
Definition at line 453 of file rtmpproto.c.
Referenced by rtmp_open().
|
static |
Generate 'releaseStream' call and send it to the server.
It should make the server release some channel for media streams.
Definition at line 641 of file rtmpproto.c.
Referenced by handle_invoke_result().
|
static |
Generate 'FCPublish' call and send it to the server.
It should make the server prepare for receiving media streams.
Definition at line 665 of file rtmpproto.c.
Referenced by handle_invoke_result().
|
static |
Generate 'FCUnpublish' call and send it to the server.
It should make the server destroy stream.
Definition at line 689 of file rtmpproto.c.
Referenced by rtmp_close().
|
static |
Generate 'createStream' call and send it to the server.
It should make the server allocate some channel for media streams.
Definition at line 713 of file rtmpproto.c.
Referenced by handle_invoke_result().
|
static |
Generate 'deleteStream' call and send it to the server.
It should make the server remove some channel for media streams.
Definition at line 738 of file rtmpproto.c.
Referenced by rtmp_close().
|
static |
Generate 'getStreamLength' call and send it to the server.
If the server knows the duration of the selected stream, it will reply with the duration in seconds.
Definition at line 764 of file rtmpproto.c.
Referenced by handle_invoke_result().
|
static |
Generate client buffer time and send it to the server.
Definition at line 786 of file rtmpproto.c.
Referenced by handle_invoke_result().
|
static |
Generate 'play' call and send it to the server, then ping the server to start actual playing.
Definition at line 808 of file rtmpproto.c.
Referenced by handle_invoke_result().
|
static |
Definition at line 832 of file rtmpproto.c.
Referenced by rtmp_seek().
|
static |
Generate a pause packet that either pauses or unpauses the current stream.
Definition at line 858 of file rtmpproto.c.
Referenced by rtmp_pause().
|
static |
Generate 'publish' call and send it to the server.
Definition at line 885 of file rtmpproto.c.
Referenced by handle_invoke_result().
|
static |
Generate ping reply and send it to the server.
Definition at line 912 of file rtmpproto.c.
Referenced by handle_user_control().
|
static |
Generate SWF verification message and send it to the server.
Definition at line 938 of file rtmpproto.c.
Referenced by handle_user_control().
|
static |
Generate window acknowledgement size message and send it to the server.
Definition at line 959 of file rtmpproto.c.
Referenced by handle_invoke_result().
|
static |
Generate check bandwidth message and send it to the server.
Definition at line 978 of file rtmpproto.c.
Referenced by handle_invoke().
|
static |
Generate report on bytes read so far and send it to the server.
Definition at line 999 of file rtmpproto.c.
Referenced by get_packet().
|
static |
Definition at line 1015 of file rtmpproto.c.
Referenced by handle_invoke_result().
|
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) |
encrypted | use an encrypted connection (RTMPE) |
Definition at line 1043 of file rtmpproto.c.
Referenced by rtmp_handshake().
|
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 1068 of file rtmpproto.c.
Referenced by rtmp_handshake().
|
static |
Definition at line 1086 of file rtmpproto.c.
Referenced by rtmp_handshake().
|
static |
Definition at line 1154 of file rtmpproto.c.
Referenced by rtmp_open().
|
static |
Perform handshake with the server by means of exchanging pseudorandom data signed with HMAC-SHA2 digest.
Definition at line 1241 of file rtmpproto.c.
Referenced by rtmp_open().
|
static |
Definition at line 1420 of file rtmpproto.c.
Referenced by rtmp_server_handshake().
|
static |
Definition at line 1441 of file rtmpproto.c.
Referenced by rtmp_server_handshake().
|
static |
|
static |
Definition at line 1568 of file rtmpproto.c.
Referenced by rtmp_parse_result().
|
static |
Definition at line 1648 of file rtmpproto.c.
Referenced by handle_connect_error().
|
static |
Definition at line 1687 of file rtmpproto.c.
Referenced by handle_connect_error().
|
static |
Definition at line 1744 of file rtmpproto.c.
Referenced by handle_invoke_error().
|
static |
Definition at line 1835 of file rtmpproto.c.
Referenced by handle_invoke().
|
static |
Definition at line 1874 of file rtmpproto.c.
Referenced by send_invoke_response().
|
static |
Definition at line 1900 of file rtmpproto.c.
Referenced by send_invoke_response().
|
static |
Definition at line 1942 of file rtmpproto.c.
Referenced by handle_invoke().
|
static |
Read the AMF_NUMBER response ("_result") to a function call (e.g.
createStream()). This response should be made up of the AMF_STRING "result", a NULL object and then the response encoded as AMF_NUMBER. On a successful response, we will return set the value to number (otherwise number will not be changed).
Definition at line 2060 of file rtmpproto.c.
Referenced by handle_invoke_result().
|
static |
Definition at line 2090 of file rtmpproto.c.
Referenced by handle_invoke().
|
static |
Definition at line 2162 of file rtmpproto.c.
Referenced by handle_invoke().
|
static |
Definition at line 2199 of file rtmpproto.c.
Referenced by rtmp_parse_result().
|
static |
Definition at line 2230 of file rtmpproto.c.
Referenced by append_flv_data(), and handle_metadata().
|
static |
Definition at line 2249 of file rtmpproto.c.
Referenced by get_packet(), and handle_notify().
|
static |
Definition at line 2282 of file rtmpproto.c.
Referenced by get_packet().
|
static |
Parse received packet and possibly perform some action depending on the packet contents.
Definition at line 2345 of file rtmpproto.c.
Referenced by get_packet(), and rtmp_write().
|
static |
Definition at line 2390 of file rtmpproto.c.
Referenced by get_packet().
|
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 2451 of file rtmpproto.c.
Referenced by rtmp_open(), and rtmp_read().
|
static |
Definition at line 2536 of file rtmpproto.c.
Referenced by rtmp_open().
|
static |
Insert a fake onMetadata packet into the FLV stream to notify the FLV demuxer about the duration of the stream.
This should only be done if there was no real onMetadata packet sent by the server at the start of the stream and if we were able to retrieve a valid duration via a getStreamLength call.
Definition at line 2572 of file rtmpproto.c.
Referenced by rtmp_open().
|
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 2635 of file rtmpproto.c.
|
static |
Definition at line 2936 of file rtmpproto.c.
Definition at line 2963 of file rtmpproto.c.
|
static |
Definition at line 2984 of file rtmpproto.c.
|
static |
Definition at line 2999 of file rtmpproto.c.
|
static |
Client key used for digest signing.
Definition at line 141 of file rtmpproto.c.
Referenced by rtmp_handshake(), and rtmp_handshake_imprint_with_digest().
|
static |
Key used for RTMP server digest signing.
Definition at line 152 of file rtmpproto.c.
Referenced by rtmp_handshake(), and rtmp_validate_digest().
|
static |
Definition at line 3144 of file rtmpproto.c.