FFmpeg
Functions
rtmppkt.c File Reference
#include "libavcodec/bytestream.h"
#include "libavutil/avstring.h"
#include "libavutil/intfloat.h"
#include "avformat.h"
#include "rtmppkt.h"
#include "flv.h"
#include "url.h"

Go to the source code of this file.

Functions

void ff_amf_write_bool (uint8_t **dst, int val)
 Write boolean value in AMF format to buffer. More...
 
void ff_amf_write_number (uint8_t **dst, double val)
 Write number in AMF format to buffer. More...
 
void ff_amf_write_string (uint8_t **dst, const char *str)
 Write string in AMF format to buffer. More...
 
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. More...
 
void ff_amf_write_null (uint8_t **dst)
 Write AMF NULL value to buffer. More...
 
void ff_amf_write_object_start (uint8_t **dst)
 Write marker for AMF object to buffer. More...
 
void ff_amf_write_field_name (uint8_t **dst, const char *str)
 Write string used as field name in AMF object to buffer. More...
 
void ff_amf_write_object_end (uint8_t **dst)
 Write marker for end of AMF object to buffer. More...
 
int ff_amf_read_number (GetByteContext *bc, double *val)
 Read AMF number value. More...
 
int ff_amf_get_string (GetByteContext *bc, uint8_t *str, int strsize, int *length)
 Get AMF string value. More...
 
int ff_amf_read_string (GetByteContext *bc, uint8_t *str, int strsize, int *length)
 Read AMF string value. More...
 
int ff_amf_read_null (GetByteContext *bc)
 Read AMF NULL value. More...
 
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. More...
 
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. More...
 
static int rtmp_packet_read_one_chunk (URLContext *h, RTMPPacket *p, int chunk_size, RTMPPacket **prev_pkt_ptr, int *nb_prev_pkt, uint8_t hdr)
 
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. More...
 
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. More...
 
int ff_rtmp_packet_create (RTMPPacket *pkt, int channel_id, RTMPPacketType type, int timestamp, int size)
 Create new RTMP packet with given attributes. More...
 
void ff_rtmp_packet_destroy (RTMPPacket *pkt)
 Free RTMP packet. More...
 
static int amf_tag_skip (GetByteContext *gb)
 
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. More...
 
static int amf_get_field_value2 (GetByteContext *gb, const uint8_t *name, uint8_t *dst, int dst_size)
 
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. More...
 
int ff_amf_match_string (const uint8_t *data, int size, const char *str)
 Match AMF string with a NULL-terminated string. More...
 

Function Documentation

◆ ff_amf_write_bool()

void ff_amf_write_bool ( uint8_t **  dst,
int  val 
)

Write boolean value in AMF format to buffer.

Parameters
dstpointer to the input buffer (will be modified)
valvalue to write

Definition at line 31 of file rtmppkt.c.

Referenced by gen_connect(), gen_pause(), and rtmp_write_amf_data().

◆ ff_amf_write_number()

void ff_amf_write_number ( uint8_t **  dst,
double  num 
)

◆ ff_amf_write_string()

void ff_amf_write_string ( uint8_t **  dst,
const char *  str 
)

◆ ff_amf_write_string2()

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.

Parameters
dstpointer to the input buffer (will be modified)
str1first string to write, may be null
str2second string to write, may be null

Definition at line 50 of file rtmppkt.c.

Referenced by gen_connect().

◆ ff_amf_write_null()

void ff_amf_write_null ( uint8_t **  dst)

◆ ff_amf_write_object_start()

void ff_amf_write_object_start ( uint8_t **  dst)

Write marker for AMF object to buffer.

Parameters
dstpointer to the input buffer (will be modified)

Definition at line 68 of file rtmppkt.c.

Referenced by gen_connect(), read_connect(), rtmp_write_amf_data(), and write_status().

◆ ff_amf_write_field_name()

void ff_amf_write_field_name ( uint8_t **  dst,
const char *  str 
)

Write string used as field name in AMF object to buffer.

Parameters
dstpointer to the input buffer (will be modified)
strstring to write

Definition at line 73 of file rtmppkt.c.

Referenced by gen_connect(), read_connect(), rtmp_write_amf_data(), and write_status().

◆ ff_amf_write_object_end()

void ff_amf_write_object_end ( uint8_t **  dst)

Write marker for end of AMF object to buffer.

Parameters
dstpointer to the input buffer (will be modified)

Definition at line 79 of file rtmppkt.c.

Referenced by gen_connect(), read_connect(), rtmp_write_amf_data(), and write_status().

◆ ff_amf_read_number()

int ff_amf_read_number ( GetByteContext gbc,
double val 
)

Read AMF number value.

Parameters
[in,out]gbcGetByteContext initialized with AMF-formatted data
[out]valread value
Returns
0 on success or an AVERROR code on failure

Definition at line 87 of file rtmppkt.c.

Referenced by find_tracked_method(), read_connect(), read_number_result(), rtmp_send_packet(), and send_invoke_response().

◆ ff_amf_get_string()

int ff_amf_get_string ( GetByteContext bc,
uint8_t *  str,
int  strsize,
int length 
)

Get AMF string value.

This function behaves the same as ff_amf_read_string except that it does not expect the AMF type prepended to the actual data. Appends a trailing null byte to output string in order to ease later parsing.

Parameters
[in,out]gbcGetByteContext initialized with AMF-formatted data
[out]strread string
[in]strsizebuffer size available to store the read string
[out]lengthread string length
Returns
0 on success or an AVERROR code on failure

Definition at line 97 of file rtmppkt.c.

Referenced by ff_amf_read_string(), and handle_notify().

◆ ff_amf_read_string()

int ff_amf_read_string ( GetByteContext gbc,
uint8_t *  str,
int  strsize,
int length 
)

Read AMF string value.

Appends a trailing null byte to output string in order to ease later parsing.

Parameters
[in,out]gbcGetByteContext initialized with AMF-formatted data
[out]strread string
[in]strsizebuffer size available to store the read string
[out]lengthread string length
Returns
0 on success or an AVERROR code on failure

Definition at line 115 of file rtmppkt.c.

Referenced by handle_notify(), read_connect(), read_number_result(), rtmp_send_packet(), rtmp_write(), and send_invoke_response().

◆ ff_amf_read_null()

int ff_amf_read_null ( GetByteContext gbc)

Read AMF NULL value.

Parameters
[in,out]gbcGetByteContext initialized with AMF-formatted data
Returns
0 on success or an AVERROR code on failure

Definition at line 123 of file rtmppkt.c.

Referenced by read_number_result(), and send_invoke_response().

◆ ff_rtmp_check_alloc_array()

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.

Parameters
prev_pktarray with previously sent packet headers
nb_prev_pktnumber of allocated elements in prev_pkt
channelthe channel number that needs to be allocated

Definition at line 130 of file rtmppkt.c.

Referenced by ff_rtmp_packet_write(), rtmp_packet_read_one_chunk(), and rtmp_write().

◆ ff_rtmp_packet_read()

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.

Parameters
hreader context
ppacket
chunk_sizecurrent chunk size
prev_pktpreviously read packet headers for all channels (may be needed for restoring incomplete packet header)
nb_prev_pktnumber of allocated elements in prev_pkt
Returns
number of bytes read on success, negative value otherwise

Definition at line 151 of file rtmppkt.c.

Referenced by get_packet(), and read_connect().

◆ rtmp_packet_read_one_chunk()

static int rtmp_packet_read_one_chunk ( URLContext h,
RTMPPacket p,
int  chunk_size,
RTMPPacket **  prev_pkt_ptr,
int nb_prev_pkt,
uint8_t  hdr 
)
static

Definition at line 163 of file rtmppkt.c.

Referenced by ff_rtmp_packet_read_internal().

◆ ff_rtmp_packet_read_internal()

int ff_rtmp_packet_read_internal ( URLContext h,
RTMPPacket p,
int  chunk_size,
RTMPPacket **  prev_pkt,
int nb_prev_pkt,
uint8_t  c 
)

Read internal RTMP packet sent by the server.

Parameters
hreader context
ppacket
chunk_sizecurrent chunk size
prev_pktpreviously read packet headers for all channels (may be needed for restoring incomplete packet header)
nb_prev_pktnumber of allocated elements in prev_pkt
cthe first byte already read
Returns
number of bytes read on success, negative value otherwise

Definition at line 290 of file rtmppkt.c.

Referenced by ff_rtmp_packet_read(), and rtmp_write().

◆ ff_rtmp_packet_write()

int ff_rtmp_packet_write ( URLContext h,
RTMPPacket p,
int  chunk_size,
RTMPPacket **  prev_pkt,
int nb_prev_pkt 
)

Send RTMP packet to the server.

Parameters
hreader context
ppacket to send
chunk_sizecurrent chunk size
prev_pktpreviously sent packet headers for all channels (may be used for packet header compressing)
nb_prev_pktnumber of allocated elements in prev_pkt
Returns
number of bytes written on success, negative value otherwise

Definition at line 305 of file rtmppkt.c.

Referenced by handle_chunk_size(), read_connect(), rtmp_send_packet(), send_invoke_response(), write_begin(), and write_status().

◆ ff_rtmp_packet_create()

int ff_rtmp_packet_create ( RTMPPacket pkt,
int  channel_id,
RTMPPacketType  type,
int  timestamp,
int  size 
)

Create new RTMP packet with given attributes.

Parameters
pktpacket
channel_idpacket channel ID
typepacket type
timestamppacket timestamp
sizepacket size
Returns
zero on success, negative value otherwise

Definition at line 408 of file rtmppkt.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(), read_connect(), rtmp_packet_read_one_chunk(), rtmp_write(), send_invoke_response(), write_begin(), and write_status().

◆ ff_rtmp_packet_destroy()

void ff_rtmp_packet_destroy ( RTMPPacket pkt)

◆ amf_tag_skip()

static int amf_tag_skip ( GetByteContext gb)
static

Definition at line 434 of file rtmppkt.c.

Referenced by amf_get_field_value2(), and ff_amf_tag_size().

◆ ff_amf_tag_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.

Parameters
datainput data
data_endinput buffer end
Returns
number of bytes used by first AMF entry

Definition at line 489 of file rtmppkt.c.

Referenced by handle_invoke_status(), and handle_notify().

◆ amf_get_field_value2()

static int amf_get_field_value2 ( GetByteContext gb,
const uint8_t *  name,
uint8_t *  dst,
int  dst_size 
)
static

Definition at line 506 of file rtmppkt.c.

Referenced by ff_amf_get_field_value().

◆ ff_amf_get_field_value()

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.

Parameters
dataAMF object data
data_endinput buffer end
namename of field to retrieve
dstbuffer for storing result
dst_sizeoutput buffer size
Returns
0 if search and retrieval succeeded, negative value otherwise

Definition at line 557 of file rtmppkt.c.

Referenced by handle_invoke_error(), handle_invoke_status(), and read_connect().

◆ ff_amf_match_string()

int ff_amf_match_string ( const uint8_t *  data,
int  size,
const char *  str 
)

Match AMF string with a NULL-terminated string.

Returns
0 if the strings do not match.

Definition at line 689 of file rtmppkt.c.

Referenced by handle_invoke().