UCL Common Library Reference |
---|
rtcp_app * | (*rtcp_app_callback) () |
(*rtp_callback) () | |
rtp_init () | |
rtp_init_if () | |
rtp_send_bye () | |
rtp_done () | |
rtp_set_option () | |
rtp_get_option () | |
rtp_recv () | |
rtp_send_data () | |
rtp_send_ctrl () | |
rtp_update () | |
rtp_my_ssrc () | |
rtp_add_csrc () | |
rtp_del_csrc () | |
rtp_set_sdes () | |
const | rtp_get_sdes () |
const rtcp_sr * | rtp_get_sr () |
const rtcp_rr * | rtp_get_rr () |
rtp_set_encryption_key () | |
rtp_set_my_ssrc () | |
rtp_get_addr () | |
rtp_get_rx_port () | |
rtp_get_tx_port () | |
rtp_get_ttl () | |
rtp_get_userdata () |
#define | RTP_VERSION |
#define | RTP_MAX_PACKET_LEN |
rtp_packet | |
#define | RTP_PACKET_HEADER_SIZE |
rtcp_sr | |
rtcp_rr | |
enum | rtcp_sdes_type |
rtcp_sdes_item | |
rtcp_app | |
enum | rtp_event_type |
rtp_event | |
enum | rtp_option |
The Real-Time Transport Protocol (RTP) is a protocol for the transport of audio, video, and other real-time data across IP capable networks.
rtcp_app * (*rtcp_app_callback) (struct rtp *session
,,
uint32_t rtp_ts);
int max_size
This callback function crafts an RTCP APP packet to be sent with an RTCP RR.
session | the session pointer (returned by | |
rtp_ts | the current time expressed in units of the media timestamp. | |
max_size | the max allowed size of an APP packet. |
A fully-formed RTCP APP packet as an rtcp_app, or NULL (???) if no APP packet needs to be sent at this time.
void (*rtp_callback) (struct rtp *session
,rtp_event *e
);
Handles RTP events in an application-specific way.
See rtp_event for a description of the possible events and
how rtp_callback()
should handle each.
rtp_t rtp_init (const
,char *addr,
uint16_t rx_port,
uint16_t tx_port,
int ttl,
double rtcp_bwrtp_callback callback
,);
uint8_t *userdata
addr | IP destination of this session (unicast or multicast), as an ASCII string. May be a host name, which will be looked up, or may be an IPv4 dotted quad or IPv6 literal adddress. | |
rx_port | The port to which to bind the UDP socket | |
tx_port | The port to which to send UDP packets | |
ttl | The TTL with which to send multicasts | |
rtcp_bw | The total bandwidth (in units of bytes per second) that is allocated to RTCP. | |
callback | See section on rtp_callback. | |
userdata | Opaque data associated with the session. See
|
rtp_t rtp_init_if (const
,char *addr,
char *iface,
uint16_t rx_port,
uint16_t tx_port,
int ttl,
double rtcp_bwrtp_callback callback
,);
uint8_t *userdata
Creates and initializes an RTP session.
addr | IP destination of this session (unicast or multicast), as an ASCII string. May be a host name, which will be looked up, or may be an IPv4 dotted quad or IPv6 literal adddress. | |
iface | If the destination of the session is multicast, the optional interface to bind to. May be NULL, in which case the default multicast interface as determined by the system will be used. | |
rx_port | The port to which to bind the UDP socket | |
tx_port | The port to which to send UDP packets | |
ttl | The TTL with which to send multicasts | |
rtcp_bw | The total bandwidth (in units of ___) that is allocated to RTCP. | |
callback | See section on rtp_callback. | |
userdata | Opaque data associated with the session. See
|
void rtp_send_bye (struct rtp *session
);
Sends a BYE message on the RTP session, indicating that this participant is leaving the session. The process of sending a BYE may take some time, and this function will block until it is complete. During this time, RTCP events are reported to the application via the callback function (data packets are silently discarded).
void rtp_done (struct rtp *session
);
Free the state associated with the given RTP session. This function does
not send any packets (e.g. an RTCP BYE) - an application which wishes to
exit in a clean manner should call rtp_send_bye()
first.
int rtp_set_option (struct rtp *session
,rtp_option optname
,);
int optval
Sets the value of a session option. See rtp_option for documentation on the options and their legal values.
int rtp_get_option (struct rtp *session
,rtp_option optname
,);
int *optval
Retrieves the value of a session option. See rtp_option for documentation on the options and their legal values.
int rtp_recv (struct rtp *session
,struct timeval *timeout
,);
uint32_t curr_rtp_ts
Receive RTP packets and dispatch them.
session | the session pointer (returned by | |
timeout | the amount of time that | |
curr_rtp_ts | the current time expressed in units of the media timestamp. |
int rtp_send_data (struct rtp *session
,,
uint32_t rtp_ts,
char pt,
int m,
int cc,
uint32_t csrc[],
char *data,
int data_len,
char *extn,
uint16_t extn_len);
uint16_t extn_type
Send an RTP packet. Most media applications will only set the
session
, rtp_ts
, pt
, m
, data
, data_len
arguments.
Mixers and translators typically set additional contributing sources
arguments (cc
, csrc
).
Extensions fields (extn
, extn_len
, extn_type
) are for including
application specific information. When the widest amount of
inter-operability is required these fields should be avoided as
some applications discard packets with extensions they do not
recognize.
session | the session pointer (returned by | |
rtp_ts | The timestamp reflects the sampling instant of the first octet of the RTP data to be sent. The timestamp is expressed in media units. | |
pt | The payload type identifying the format of the data. | |
m | Marker bit, interpretation defined by media profile of payload. | |
cc | Number of contributing sources (excluding local participant) | |
csrc | Array of SSRC identifiers for contributing sources. | |
data | The RTP data to be sent. | |
data_len | The size | |
extn | Extension data (if present). | |
extn_len | size of | |
extn_type | extension type indicator. |
void rtp_send_ctrl (struct rtp *session
,,
uint32_t rtp_tsrtcp_app_callback appcallback
);
Checks RTCP timer and sends RTCP data when nececessary. The interval between RTCP packets is randomized over an interval that depends on the session bandwidth, the number of participants, and whether the local participant is a sender. This function should be called at least once per second, and can be safely called more frequently.
session | the session pointer (returned by | |
rtp_ts | the current time expressed in units of the media timestamp. | |
appcallback | a callback to create an APP RTCP packet, if needed. |
void rtp_update (struct rtp *session
);
Trawls through the internal data structures and performs housekeeping. This function should be called at least once per second. It uses an internal timer to limit the number of passes through the data structures to once per second, it can be safely called more frequently.
int rtp_add_csrc (struct rtp *session
,);
uint32_t csrc
Adds csrc
to list of contributing sources used in SDES items.
Used by mixers and transcoders.
int rtp_del_csrc (struct rtp *session
,);
uint32_t csrc
Removes csrc
from list of contributing sources used in SDES items.
Used by mixers and transcoders.
int rtp_set_sdes (struct rtp *session
,,
uint32_t ssrcrtcp_sdes_type type
,const
,char *value);
int length
Sets session description information associated with participant
ssrc
. Under normal circumstances applications always use the
ssrc
of the local participant, this SDES information is
transmitted in receiver reports. Setting SDES information for
other participants affects the local SDES entries, but are not
transmitted onto the network.
session | the session pointer (returned by | |
ssrc | the SSRC identifier of a participant | |
type | the SDES type represented by | |
value | the SDES description | |
length | the length of the description |
constchar * rtp_get_sdes (struct rtp *session
,,
uint32_t ssrcrtcp_sdes_type type
);
Recovers session description (SDES) information on participant
identified with ssrc
. The SDES information associated with a
source is updated when receiver reports are received. There are
several different types of SDES information, e.g. username,
location, phone, email. These are enumerated by rtcp_sdes_type.
session | the session pointer (returned by | |
ssrc | the SSRC identifier of a participant | |
type | the SDES information to retrieve |
const rtcp_sr * rtp_get_sr (struct rtp *session
,);
uint32_t ssrc
Retrieve the latest sender report made by sender with ssrc
identifier.
const rtcp_rr * rtp_get_rr (struct rtp *session
,,
uint32_t reporter);
uint32_t reportee
Retrieve the latest receiver report on reportee
made by reporter
.
Provides an indication of other receivers reception service.
session | the session pointer (returned by | |
reporter | participant originating receiver report | |
reportee | participant included in receiver report |
int rtp_set_encryption_key (struct rtp *session
,const
);char *passphrase
Converts the user supplied key into a form suitable for use with RTP and install it as the active key. Passing in NULL as the passphrase disables encryption. The passphrase is converted into a DES key as specified in RFC1890, that is:
convert to canonical form
derive an MD5 hash of the canonical form
take the first 56 bits of the MD5 hash
add parity bits to form a 64 bit key
Note that versions of rat prior to 4.1.2 do not convert the passphrase to canonical form before taking the MD5 hash, and so will not be compatible for keys which are non-invarient under this step.
Determine from the user's encryption key which encryption mechanism we're using. Per the RTP RFC, if the key is of the form
string/key
then "string" is the name of the encryption algorithm, and "key" is the key to be used. If no / is present, then the algorithm is assumed to be (the appropriate variant of) DES.
int rtp_set_my_ssrc (struct rtp *session
,);
uint32_t ssrc
This function coerces the local SSRC identifer to be ssrc. For this function to succeed it must be called immediately after rtp_init or rtp_init_if. The intended purpose of this function is to co-ordinate SSRC's between layered sessions, it should not be used otherwise.
char * rtp_get_addr (struct rtp *session
);
The session's destination address, as set when creating the
session with rtp_init()
or rtp_init_if()
.
uint16_t rtp_get_rx_port (struct rtp *session
);
The UDP port to which this session is bound, as set when
creating the session with rtp_init()
or rtp_init_if()
.
uint16_t rtp_get_tx_port (struct rtp *session
);
The UDP port to which RTP packets are transmitted, as set
when creating the session with rtp_init()
or rtp_init_if()
.
uint8_t * rtp_get_userdata (struct rtp *session
);
This function returns the userdata pointer that was passed to the
rtp_init()
or rtp_init_if()
function when creating this session.
typedef struct { /* The following are pointers to the data in the packet as */ /* it came off the wire. The packet it read in such that the */ /* header maps onto the latter part of this struct, and the */ /* fields in this first part of the struct point into it. The */ /* entire packet can be freed by freeing this struct, without */ /* having to free the csrc, data and extn blocks separately. */ /* WARNING: Don't change the size of the first portion of the */ /* struct without changing RTP_PACKET_HEADER_SIZE to match. */ uint32_t *csrc; char *data; int data_len; unsigned char *extn; uint16_t extn_len; /* Size of the extension in 32 bit words minus one */ uint16_t extn_type; /* Extension type field in the RTP packet header */ /* The following map directly onto the RTP packet header... */ #ifdef WORDS_BIGENDIAN unsigned short v:2; /* packet type */ unsigned short p:1; /* padding flag */ unsigned short x:1; /* header extension flag */ unsigned short cc:4; /* CSRC count */ unsigned short m:1; /* marker bit */ unsigned short pt:7; /* payload type */ #else unsigned short cc:4; /* CSRC count */ unsigned short x:1; /* header extension flag */ unsigned short p:1; /* padding flag */ unsigned short v:2; /* packet type */ unsigned short pt:7; /* payload type */ unsigned short m:1; /* marker bit */ #endif uint16_t seq; /* sequence number */ uint32_t ts; /* timestamp */ uint32_t ssrc; /* synchronization source */ /* The csrc list, header extension and data follow, but can't */ /* be represented in the struct. */ } rtp_packet;
The struct begins with pointers to the data in the packet as it came off the wire. The packet is read in such that the header maps onto the latter part of this struct, and the fields in this first part of the struct point into it. The entire packet can be freed by freeing this struct, without having to free the csrc, data and extn blocks separately. WARNING: Don't change the size of the first portion of the struct without changing RTP_PACKET_HEADER_SIZE to match.
#define RTP_PACKET_HEADER_SIZE ((sizeof(char *) * 2) + sizeof(uint32_t *) + (2 * sizeof(int)))
This macro MUST resolve to the offset of the first packet field in the rtp_packet struct, including all padding. If you change rtp_packet, make sure to change this too.
typedef struct { uint32_t ssrc; uint32_t ntp_sec; uint32_t ntp_frac; uint32_t rtp_ts; uint32_t sender_pcount; uint32_t sender_bcount; } rtcp_sr;
typedef struct { uint32_t ssrc; /* The ssrc to which this RR pertains */ #ifdef WORDS_BIGENDIAN uint32_t fract_lost:8; uint32_t total_lost:24; #else uint32_t total_lost:24; uint32_t fract_lost:8; #endif uint32_t last_seq; uint32_t jitter; uint32_t lsr; uint32_t dlsr; } rtcp_rr;
Possible values of Session Description (SDES) identifiers. SDES items are announced via rtp_callback (with RX_SDES events) when they are received. SDES items may be configured and queried with rtp_set_sdes and rtp_get_sdes. The RTP guidelines recommend keeping SDES items constant during an RTP session to avoid confusing end users.
RTCP_SDES_END | Indicates the end of SDES item processing when SDES data is received. Has no meaning with rtp_set_sdes and rtp_get_sdes. | |
RTCP_SDES_CNAME | The canonical name associated with participant. It is algorithmically derived and should never be changed. | |
RTCP_SDES_NAME | The local participant's name, typically displayed in RTP session participant list. The name can take any form, and should remain constant during a session to avoid confusion. | |
RTCP_SDES_EMAIL | The local participant's email address (optional). | |
RTCP_SDES_PHONE | The local participant's telephone number (optional). | |
RTCP_SDES_LOC | The local participant's geographic location (optional). | |
RTCP_SDES_TOOL | The local participant's tool (optional). | |
RTCP_SDES_NOTE | Any additional information the local participant wishes to communicate about themselves (optional). | |
RTCP_SDES_PRIV | Private extension SDES item see RFC1889 for details. |
typedef struct { uint8_t type; /* type of SDES item */ uint8_t length; /* length of SDES item (in bytes) */ char data[1]; /* text, not zero-terminated */ } rtcp_sdes_item;
typedef struct { #ifdef WORDS_BIGENDIAN unsigned short version:2; /* RTP version */ unsigned short p:1; /* padding flag */ unsigned short subtype:5; /* application dependent */ #else unsigned short subtype:5; /* application dependent */ unsigned short p:1; /* padding flag */ unsigned short version:2; /* RTP version */ #endif unsigned short pt:8; /* packet type */ uint16_t length; /* packet length */ uint32_t ssrc; char name[4]; /* four ASCII characters */ char data[1]; /* variable length field */ } rtcp_app;
The possible values for the type field in rtp_event. Each value represents an event in RTP or RTCP processing.
RX_RTP | An RTP data packet was received.
The ssrc field contains the RTP data packet's SSRC.
The data field points to a rtp_packet containing the RTP data packet.
The callback must free the rtp_packet when it's done with it using the | |
RX_SR | An RTCP SR packet was received. The ssrc field contains the SR packet's SSRC. The data field points to an rtcp_sr. | |
RX_RR | An RTCP RR packet was received. The ssrc field contains the RR packet's SSRC. The data field points to an rtcp_rr. | |
RX_SDES | An RTCP SDES packet was received. The ssrc field contains the SDES packet's SSRC. The data field points to an rtcp_sdes_item. | |
RX_BYE | An RTCP BYE packet was received. The ssrc field contains the BYE packet's SSRC. | |
SOURCE_CREATED | A new session participant was heard from. The ssrc field contains the new participant's SSRC. | |
SOURCE_DELETED | A source was deleted from the database. The ssrc field contains the ex-participant's SSRC. | |
RX_RR_EMPTY | An RTCP RR packet with no sources listed was received. The ssrc field contains the RR packet's SSRC. | |
RX_RTCP_START | Called at the start of parsing an RTCP packet. Neither the ssrc nor data fields are valid. | |
RX_RTCP_FINISH | Called at the end of parsing an RTCP packet. Neither the ssrc nor data fields are valid. | |
RR_TIMEOUT | An RR from the given receiver has not been refreshed recently enough. The ssrc field contains the RR packet's SSRC. The data field points to the expiring rtcp_rr. | |
RX_APP | An APP packet was received. The ssrc field contains the APP packet's SSRC. The data field points to an rtcp_app. The callback must free the app packet when it's done with it. |
typedef struct { uint32_t ssrc; rtp_event_type type; void *data; struct timeval *ts; } rtp_event;
The event structure as passed to rtp_callback()
.
The callback type is carried in the type field; see rtp_event_type
for a description of each callback.
Unless otherwise noted, the ssrc field contains the SSRC of the participant
triggering this callback. The data field points to any data contained in
this callback; it must be cast to the appropriate type. The ts field
contains the timestamp of the packet reception that caused this event.
The possible options for a session that affect which RTP packets are passed to the application and when internal state for sources is created.
RTP_OPT_PROMISC | Pass RTP packets to application irrespective of whether a sender report has been received. Normally, participant state is created when a sender report is received and RTP packets that arrive prior to the sender report are discarded. | |
RTP_OPT_WEAK_VALIDATION | Create source state when RTP packets arrive if none exists. This option is set by default. Disabling the option means source state is only created when sender reports are received. | |
RTP_OPT_FILTER_MY_PACKETS | Filter out packets from local participant if they are received. With multicast sessions, packets may be looped back, causing senders packets to be received locally. This may be filtered out with this option. | |
RTP_OPT_REUSE_PACKET_BUFS |
<<< NETUDP | Debug >>> |