123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 |
- #ifndef __RTP_H__
- #define __RTP_H__
- #pragma once
- #include "config.h"
- #include <winpr/wtypes.h>
- #ifndef _WIN32
- #include <sys/time.h>
- #endif
- #ifdef __cplusplus
- extern "C" {
- #endif
- #define IP_UDP_OVERHEAD (20 + 8)
- #define RTP_VERSION 2
- #define RTP_MAX_SDES 255 /* maximum text length for SDES */
- /** Standard RTP static payload types, as defined by RFC 3551. */
- enum rtp_pt
- {
- RTP_PT_PCMU = 0, /**< audio PCMU */
- RTP_PT_G726_32 = 2, /**< audio G726-32 */
- RTP_PT_GSM = 3, /**< audio GSM */
- RTP_PT_G723 = 4, /**< audio G723 */
- RTP_PT_DVI4_8K = 5, /**< audio DVI4 8KHz */
- RTP_PT_DVI4_16K = 6, /**< audio DVI4 16Khz */
- RTP_PT_LPC = 7, /**< audio LPC */
- RTP_PT_PCMA = 8, /**< audio PCMA */
- RTP_PT_G722 = 9, /**< audio G722 */
- RTP_PT_L16_2 = 10, /**< audio 16bit linear 44.1KHz stereo */
- RTP_PT_L16_1 = 11, /**< audio 16bit linear 44.1KHz mono */
- RTP_PT_QCELP = 12, /**< audio QCELP */
- RTP_PT_CN = 13, /**< audio Comfort Noise */
- RTP_PT_MPA = 14, /**< audio MPEG1/MPEG2 elemetr. streams */
- RTP_PT_G728 = 15, /**< audio G728 */
- RTP_PT_DVI4_11K = 16, /**< audio DVI4 11.025KHz mono */
- RTP_PT_DVI4_22K = 17, /**< audio DVI4 22.050KHz mono */
- RTP_PT_G729 = 18, /**< audio G729 */
- RTP_PT_CELB = 25, /**< video/comb Cell-B by Sun (RFC2029) */
- RTP_PT_JPEG = 26, /**< video JPEG */
- RTP_PT_NV = 28, /**< video NV by nv program by Xerox */
- RTP_PT_H261 = 31, /**< video H261 */
- RTP_PT_MPV = 32, /**< video MPEG1 or MPEG2 elementary */
- RTP_PT_MP2T = 33, /**< video MPEG2 transport */
- RTP_PT_H263 = 34, /**< video H263 */
- RTP_PT_DYNAMIC = 96, /**< start of dynamic RTP payload */
- RTP_PT_PCM8 = 102,
- RTP_PT_PCM16 = 103,
- RTP_PT_BV16 = 106,
- RTP_PT_H263P = 107,
- RTP_PT_H264 = 108,
- RTP_PT_MPG4 = 109,
- RTP_PT_VP8 = 110,
- RTP_PT_BV32 = 127,
- };
- /* rtp data header */
- /*
- 0 1 2 3
- 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- |V=2|P|X| CC |M| PT | sequence number |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | timestamp |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | synchronization source (SSRC) identifier |
- +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
- | contributing source (CSRC) identifiers |
- | .... |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- */
- #pragma pack(push, 2)
- typedef struct rtp_hdr {
- unsigned short csrc : 4; /* CSRC identifier count */
- unsigned short x : 1; /* extension */
- unsigned short p : 1; /* padding */
- unsigned short v : 2; /* version */
- unsigned short pt : 7; /* payload type */
- unsigned short m : 1; /* marker */
- unsigned short seq; /* sequence number */
- unsigned int ts; /* time stamp */
- unsigned int ssrc; /* synchronization source (SSRC) id */
- } rtp_hdr;
- #pragma pack(pop)
- typedef enum {
- RTCP_SR = 200,
- RTCP_RR = 201,
- RTCP_SDES = 202,
- RTCP_BYE = 203,
- RTCP_APP = 204,
- RTCP_FIR = 192, /* h261 specific, HW use this to request full intra-frame */
- RTCP_NACK = 193, /* h261 specific */
- RTCP_RTPFB = 205,
- RTCP_PSFB = 206,
- RTCP_XR = 207
- } rtcp_type_t;
- typedef enum {
- RTCP_SDES_END = 0,
- RTCP_SDES_CNAME = 1,
- RTCP_SDES_NAME = 2,
- RTCP_SDES_EMAIL = 3,
- RTCP_SDES_PHONE = 4,
- RTCP_SDES_LOC = 5,
- RTCP_SDES_TOOL = 6,
- RTCP_SDES_NOTE = 7,
- RTCP_SDES_PRIV = 8,
- RTCP_SDES_COUNT = 9
- } rtcp_sdes_type_t;
- /*
- 0 1 2 3
- 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- |V=2|P| MBZ | PT=RTCP_FIR | length |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | SSRC |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- Full INTRA-frame Request (FIR) packet for Hua-wei Open-eye compatibility
- 0 1 2 3
- 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- |V=2|P| MBZ | PT=RTCP_NACK | length |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | SSRC |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | FSN | BLP |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- Negative ACKnowledgements (NACK) packet
- */
- /*
- * RTCP common header word
- */
- typedef struct {
- unsigned short count:5; /* varies by packet type */
- unsigned short p:1; /* padding flag */
- unsigned short version:2; /* protocol version */
- unsigned short pt:8; /* RTCP packet type */
- unsigned short length; /* pkt len in words, w/o this word */
- } rtcp_common_t;
- /* sender info */
- typedef struct {
- unsigned int ssrc; /* sender generating this report */
- unsigned int ntp_sec; /* NTP timestamp */
- unsigned int ntp_frac;
- unsigned int rtp_ts; /* RTP timestamp */
- unsigned int psent; /* packets sent */
- unsigned int osent; /* octets sent */
- }rtcp_sender_info_t;
- /*
- * Reception report block
- */
- typedef struct {
- unsigned int ssrc; /* data source being reported */
- unsigned int fl_cnpl; /* fraction lost since last SR/RR, cumul. no. pkts lost (signed!) */
- unsigned int last_seq; /* extended last seq. no. received */
- unsigned int jitter; /* interarrival jitter */
- unsigned int lsr; /* last SR packet from this source */
- unsigned int dlsr; /* delay since last SR packet */
- } rtcp_rr_t;
- /*
- * SDES item
- */
- #pragma pack(push, 1)
- typedef struct {
- unsigned char type; /* type of item (rtcp_sdes_type_t) */
- unsigned char length; /* length of item (in octets) */
- char data[1]; /* text, not null-terminated */
- } rtcp_sdes_item_t;
- #pragma pack(pop)
- typedef struct {
- unsigned int ssrc;
- rtcp_sdes_item_t item[1]; /* list of SDES items */
- }rtcp_sdes_t;
- /* BYE */
- #pragma pack(push, 1)
- typedef struct {
- unsigned char length;
- char reason[1];
- } rtcp_bye_reason_t;
- #pragma pack(pop)
- typedef struct {
- rtcp_common_t common;
- unsigned int ssrc[1]; /* the bye may contain several ssrc/csrc */
- } rtcp_bye_t;
- typedef struct {
- rtcp_common_t common;
- //huchen delete, sender ssrc in sender_info struct.
- //unsigned int ssrc;
- rtcp_sender_info_t sender_info;
- rtcp_rr_t rb[1];
- } rtcp_sr_t;
- typedef struct {
- rtcp_common_t common;
- unsigned int ssrc;
- char name[4];
- } rtcp_app_t;
- typedef struct {
- rtcp_common_t common;
- unsigned int ssrc;
- }rtcp_fir_t;
- /* RTCP FB packet */
- typedef enum {
- RTCP_RTPFB_NACK = 1,
- RTCP_RTPFB_TMMBR = 3,
- RTCP_RTPFB_TMMBN = 4
- } rtcp_rtpfb_type_t;
- typedef struct _rtcp_fb_header {
- unsigned int packet_sender_ssrc;
- unsigned int media_source_ssrc;
- } rtcp_fb_header_t;
- typedef struct rtcp_fb_tmmbr_fci {
- unsigned int ssrc;
- unsigned int value;
- } rtcp_fb_tmmbr_fci_t;
- typedef struct _RtcpTmmbrInfo {
- char *sent;
- char *received;
- } RtcpTmmbrInfo;
- typedef struct {
- unsigned int peer_ssrc; /* network byte order */
- unsigned int total_rx_bytes;
- unsigned int total_tx_bytes;
- unsigned int total_rx_packets;
- unsigned int total_tx_packets;
- unsigned int total_packet_lost;
- unsigned int rx_packets_since_last_sr;
- unsigned int rx_seq_at_last_sr;
- unsigned short first_seq; /* the first seq we recv */
- unsigned short max_seq;
- unsigned short last_seq; /* last seq */
- unsigned short seq_circles;
- unsigned int inter_jitter; /* interarrival jitter */
- unsigned int transit;
- unsigned int lsr; /* last sr ntp */
- struct timeval lsr_tm; /* local time ticks after receive */
- float rtt;/*last round trip delay calculated*/
- int cum_loss;
- unsigned int fraction_lost;
- unsigned int report_block_last_seq;
- int report_block_last_number_of_packets;
-
- u__int64_t tmmbr_max_bitrate;
- }rtcp_statistics;
- #pragma pack(1)
- /**
- * Declaration for DTMF telephony-events (RFC2833).
- */
- struct rtp_dtmf_event
- {
- unsigned char event; /**< Event type ID. */
- unsigned char e_vol : 6; /**< Event volume. */
- unsigned char p : 1; /* reserved */
- unsigned char e : 1; /* end bit */
- unsigned short duration; /**< Event duration. */
- };
- typedef struct rtp_dtmf_event rtp_dtmf_event;
- #pragma pack()
- /* rtp state */
- typedef struct rtp_state rtp_state;
- int rtp_state_get_tmmbr_wait_send_maxbitrate(rtp_state *rs, u__int64_t *mxtbr);
- TOOLKIT_API int rtp_state_fill_rtp(rtp_state *rs, void *hdr, unsigned int pt, unsigned int mark, unsigned int delta_ts);
- TOOLKIT_API int rtp_state_advance_timestamp(rtp_state *rs, unsigned int delta_ts);
- TOOLKIT_API int rtp_state_set_rtcp_sdes_string(rtp_state *rs,
- rtcp_sdes_type_t type,
- const char *str);
- TOOLKIT_API int rtp_state_rtcp_make_sr(rtp_state *rs, char *buf, size_t buflen);
- TOOLKIT_API int rtp_state_rtcp_make_rr(rtp_state *rs, char *buf, size_t buflen);
- TOOLKIT_API int rtp_state_rtcp_make_h261_fir(rtp_state *rs, char *buf, size_t buflen);
- TOOLKIT_API int rtp_state_rtcp_make_rtcp_fb_tmmbn(rtp_state *rs, char *buf, size_t buflen, unsigned int ssrc);
- TOOLKIT_API int rtp_state_rtcp_make_rtcp_fb_tmmbr(rtp_state *rs, char *buf, size_t buflen, u__int64_t mxtbr, unsigned short measured_overhead);
- /**
- * called when receive a peer's rtp data packet
- */
- TOOLKIT_API int rtp_state_on_recv_rtcp(rtp_state *rs, const void *buf, int len);
- /**
- * called when receive a peer's rtp data packet
- */
- TOOLKIT_API int rtp_state_on_recv_rtp(rtp_state *rs, const void *buf, int len);
- /**
- * called when send rtp data packet out
- */
- TOOLKIT_API int rtp_state_on_send_rtp(rtp_state *rs, int len);
- /**
- * set sdes string, only ascii string less than 255 accepted
- */
- TOOLKIT_API int rtp_state_reset(rtp_state *rs, unsigned int ssrc, unsigned int padding, unsigned int extension);
- TOOLKIT_API rtp_state *rtp_state_create(int rtcp_transmit_interval);
- TOOLKIT_API void rtp_state_destroy(rtp_state *rs);
- TOOLKIT_API int rtp_state_get_stat(rtp_state *rs, rtcp_statistics *stat);
- TOOLKIT_API int rtp_state_need_send_rtcp(rtp_state *state, int update_ticks);
- #ifdef __cplusplus
- } // extern "C" {
- #endif
- #endif //__RTP_H__
|