rtmppkt.h File Reference
#include "libavcodec/bytestream.h"
#include "avformat.h"
#include "url.h"
Include dependency graph for rtmppkt.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  RTMPPacket
 structure for holding RTMP packets More...
 

Macros

#define RTMP_CHANNELS   65599
 maximum possible number of different RTMP channels More...
 

Typedefs

typedef enum RTMPPacketType RTMPPacketType
 known RTMP packet types More...
 
typedef struct RTMPPacket RTMPPacket
 structure for holding RTMP packets More...
 

Enumerations

enum  RTMPChannel {
  RTMP_NETWORK_CHANNEL = 2, RTMP_SYSTEM_CHANNEL, RTMP_SOURCE_CHANNEL, RTMP_VIDEO_CHANNEL = 8,
  RTMP_AUDIO_CHANNEL
}
 channels used to for RTMP packets with different purposes (i.e. More...
 
enum  RTMPPacketType {
  RTMP_PT_CHUNK_SIZE = 1, RTMP_PT_BYTES_READ = 3, RTMP_PT_PING, RTMP_PT_SERVER_BW,
  RTMP_PT_CLIENT_BW, RTMP_PT_AUDIO = 8, RTMP_PT_VIDEO, RTMP_PT_FLEX_STREAM = 15,
  RTMP_PT_FLEX_OBJECT, RTMP_PT_FLEX_MESSAGE, RTMP_PT_NOTIFY, RTMP_PT_SHARED_OBJ,
  RTMP_PT_INVOKE, RTMP_PT_METADATA = 22
}
 known RTMP packet types More...
 
enum  RTMPPacketSize { RTMP_PS_TWELVEBYTES = 0, RTMP_PS_EIGHTBYTES, RTMP_PS_FOURBYTES, RTMP_PS_ONEBYTE }
 possible RTMP packet header sizes More...
 

Functions

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...
 
int ff_rtmp_packet_read (URLContext *h, RTMPPacket *p, int chunk_size, RTMPPacket *prev_pkt)
 Read RTMP packet sent by the server. More...
 
int ff_rtmp_packet_read_internal (URLContext *h, RTMPPacket *p, int chunk_size, RTMPPacket *prev_pkt, uint8_t c)
 Read internal RTMP packet sent by the server. More...
 
int ff_rtmp_packet_write (URLContext *h, RTMPPacket *p, int chunk_size, RTMPPacket *prev_pkt)
 Send RTMP packet to the server. More...
 
void ff_rtmp_packet_dump (void *ctx, RTMPPacket *p)
 Print information and contents of RTMP packet. More...
 
Functions used to work with the AMF format (which is also used in .flv)
See also
amf_* funcs in libavformat/flvdec.c
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...
 
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...
 
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 num)
 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_bool (GetByteContext *gbc, int *val)
 Read AMF boolean value. More...
 
int ff_amf_read_number (GetByteContext *gbc, double *val)
 Read AMF number value. More...
 
int ff_amf_read_string (GetByteContext *gbc, uint8_t *str, int strsize, int *length)
 Read AMF string value. More...
 
int ff_amf_read_null (GetByteContext *gbc)
 Read AMF NULL value. More...
 

Macro Definition Documentation

#define RTMP_CHANNELS   65599

maximum possible number of different RTMP channels

Definition at line 30 of file rtmppkt.h.

Typedef Documentation

typedef struct RTMPPacket RTMPPacket

structure for holding RTMP packets

known RTMP packet types

Enumeration Type Documentation

channels used to for RTMP packets with different purposes (i.e.

data, network control, remote procedure calls, etc.)

Enumerator
RTMP_NETWORK_CHANNEL 

channel for network-related messages (bandwidth report, ping, etc)

RTMP_SYSTEM_CHANNEL 

channel for sending server control messages

RTMP_SOURCE_CHANNEL 

channel for sending a/v to server

RTMP_VIDEO_CHANNEL 

channel for video data

RTMP_AUDIO_CHANNEL 

channel for audio data

Definition at line 36 of file rtmppkt.h.

possible RTMP packet header sizes

Enumerator
RTMP_PS_TWELVEBYTES 

packet has 12-byte header

RTMP_PS_EIGHTBYTES 

packet has 8-byte header

RTMP_PS_FOURBYTES 

packet has 4-byte header

RTMP_PS_ONEBYTE 

packet is really a next chunk of a packet

Definition at line 67 of file rtmppkt.h.

known RTMP packet types

Enumerator
RTMP_PT_CHUNK_SIZE 

chunk size change

RTMP_PT_BYTES_READ 

number of bytes read

RTMP_PT_PING 

ping

RTMP_PT_SERVER_BW 

server bandwidth

RTMP_PT_CLIENT_BW 

client bandwidth

RTMP_PT_AUDIO 

audio packet

RTMP_PT_VIDEO 

video packet

RTMP_PT_FLEX_STREAM 

Flex shared stream.

RTMP_PT_FLEX_OBJECT 

Flex shared object.

RTMP_PT_FLEX_MESSAGE 

Flex shared message.

RTMP_PT_NOTIFY 

some notification

RTMP_PT_SHARED_OBJ 

shared object

RTMP_PT_INVOKE 

invoke some stream action

RTMP_PT_METADATA 

FLV metadata.

Definition at line 47 of file rtmppkt.h.

Function Documentation

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 373 of file rtmppkt.c.

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

int ff_amf_read_bool ( GetByteContext gbc,
int *  val 
)

Read AMF boolean value.

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

Definition at line 87 of file rtmppkt.c.

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 125 of file rtmppkt.c.

Referenced by send_invoke_response().

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 95 of file rtmppkt.c.

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

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 105 of file rtmppkt.c.

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

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 337 of file rtmppkt.c.

Referenced by ff_amf_get_field_value(), ff_amf_tag_contents(), ff_amf_tag_size(), ff_rtmp_packet_dump(), and handle_invoke_status().

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(), and rtmp_write_amf_data().

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 send_invoke_response().

void ff_amf_write_null ( uint8_t **  dst)

Write AMF NULL value to buffer.

Parameters
dstpointer to the input buffer (will be modified)

Definition at line 63 of file rtmppkt.c.

Referenced by gen_check_bw(), gen_create_stream(), gen_delete_stream(), gen_fcpublish_stream(), gen_fcsubscribe_stream(), gen_fcunpublish_stream(), gen_play(), gen_publish(), gen_release_stream(), read_connect(), rtmp_write_amf_data(), and send_invoke_response().

void ff_amf_write_number ( uint8_t **  dst,
double  num 
)

Write number in AMF format to buffer.

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

Definition at line 37 of file rtmppkt.c.

Referenced by gen_check_bw(), gen_connect(), gen_create_stream(), gen_delete_stream(), gen_fcpublish_stream(), gen_fcsubscribe_stream(), gen_fcunpublish_stream(), gen_play(), gen_publish(), gen_release_stream(), read_connect(), rtmp_write_amf_data(), and send_invoke_response().

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 send_invoke_response().

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 send_invoke_response().

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

Write string in AMF format to buffer.

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

Definition at line 43 of file rtmppkt.c.

Referenced by gen_check_bw(), gen_connect(), gen_create_stream(), gen_delete_stream(), gen_fcpublish_stream(), gen_fcsubscribe_stream(), gen_fcunpublish_stream(), gen_play(), gen_publish(), gen_release_stream(), read_connect(), rtmp_write(), rtmp_write_amf_data(), and send_invoke_response().

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().

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 311 of file rtmppkt.c.

Referenced by ff_rtmp_packet_read_internal(), 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_play(), gen_pong(), gen_publish(), gen_release_stream(), gen_server_bw(), gen_swf_verification(), read_connect(), rtmp_write(), and send_invoke_response().

void ff_rtmp_packet_destroy ( RTMPPacket pkt)

Free RTMP packet.

Parameters
pktpacket

Definition at line 329 of file rtmppkt.c.

Referenced by ff_rtmp_packet_read_internal(), gen_connect(), get_packet(), read_connect(), rtmp_close(), rtmp_send_packet(), rtmp_write(), and send_invoke_response().

void ff_rtmp_packet_dump ( void ctx,
RTMPPacket p 
)

Print information and contents of RTMP packet.

Parameters
ctxoutput context
ppacket to dump

Definition at line 502 of file rtmppkt.c.

Referenced by rtmp_parse_result().

int ff_rtmp_packet_read ( URLContext h,
RTMPPacket p,
int  chunk_size,
RTMPPacket 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)
Returns
number of bytes read on success, negative value otherwise

Definition at line 132 of file rtmppkt.c.

Referenced by get_packet(), and read_connect().

int ff_rtmp_packet_read_internal ( URLContext h,
RTMPPacket p,
int  chunk_size,
RTMPPacket 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)
cthe first byte already read
Returns
number of bytes read on success, negative value otherwise

Definition at line 143 of file rtmppkt.c.

Referenced by ff_rtmp_packet_read(), and rtmp_write().

int ff_rtmp_packet_write ( URLContext h,
RTMPPacket p,
int  chunk_size,
RTMPPacket 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)
Returns
number of bytes written on success, negative value otherwise

Definition at line 234 of file rtmppkt.c.

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