www.pudn.com > RTP通用开发库(for Linux).rar > rtcp.h


/*-------------------------------------------------------------------------
 * rtcp.h - RTCP_LENGTH_BYTE 
 *-------------------------------------------------------------------------
 */

#ifndef RTCP_H
#define RTCP_H

#include 
#include 

/* RTCP constants */
#define RTCP_MAXRBLOCKS        31
#define RTCP_MAXREASONLEN      255
#define RTCP_HEADERSZ          4
#define RTCP_BWFRAC	       .05
#define RTCP_MAXPACKETSZ       1024
#define RTCP_RRMAXRBLOCKS      2697	/* Maximum number of report blocks we'll send in 1 CYCLE */
					/* Equal to maximum number that will fit in 1 UDP/IP packet */

/* Types of RTCP messages */
#define RTCP_SR		200
#define RTCP_RR		201
#define	RTCP_SDES	202
#define RTCP_BYE	203
#define RTCP_APP	204

/* Types of RTCP SDES items */
#define RTCP_ITEM_NULL	0
#define RTCP_ITEM_CNAME	1
#define	RTCP_ITEM_NAME	2
#define	RTCP_ITEM_EMAIL	3
#define	RTCP_ITEM_PHONE	4
#define	RTCP_ITEM_LOC	5
#define RTCP_ITEM_TOOL	6
#define	RTCP_ITEM_NOTE	7
#define	RTCP_ITEM_PRIV	8

/* Macros for RTP structure */
#define RTCP_LENGTH_BYTE(prtcp) ((prtcp->rtcp_length + 1) * 4) /* assumes appropriate byte order */

struct rtcp {
#if __BYTE_ORDER == __LITTLE_ENDIAN || defined(_LITTLE_ENDIAN)
  unsigned int  rtcp_count:5;	/* object count			*/
  unsigned int	rtcp_pad:1;	/* padding flag			*/
  unsigned int	rtcp_ver:2;	/* version			*/
#elif __BYTE_ORDER == __BIG_ENDIAN || defined(_BIG_ENDIAN)
  unsigned int	rtcp_ver:2;	/* version			*/
  unsigned int	rtcp_pad:1;	/* padding flag			*/
  unsigned int  rtcp_count:5;	/* object count			*/
#endif
  unsigned char	rtcp_type;	/* Message type			*/
  unsigned short rtcp_length;	/* Message length		*/
  char		rtcp_data[1];	/* Message data			*/
};

/* Struct for receiver report block */
struct rblock {
  unsigned int	rb_ssrc;	/* SSRC to which this rr refers	*/
  unsigned int	rb_fraclost:8;	/* fraction lost		*/
  int		rb_cumlost:24;	/* cumulative packets lost	*/
  unsigned int	rb_hiseq;	/* Extended highest seq recvd	*/
  unsigned int	rb_jitter;	/* Jitter measure		*/
  unsigned int	rb_lastsrts;	/* Middle 32 of last SR NTP	*/
  unsigned int	rb_delay;	/* Delay since lsr		*/
};

/* Struct for receiver report message */
struct rr {
  unsigned int	rr_ssrc;	/* SSRC of sender		*/
  char		rr_rb[1];	/* Pointer to 1st report block	*/
};

/* Struct for sender report message */
struct sr {
  unsigned int	sr_ssrc;	/* SSRC of sender		*/  
  unsigned int	sr_intts;	/* NTP Timestamp (high 32 bits)	*/
  unsigned int	sr_fracts;	/* NTP Timestamp (lo 32 bits)	*/
  unsigned int	sr_rtpts;	/* RTP media timestamp		*/
  unsigned int	sr_packets;	/* Sender's sent packet count	*/
  unsigned int	sr_octets;	/* Sender's sent octet count	*/
  char		sr_rblock[1];	/* First reception report	*/
};

/* Struct for source description message `chunk' */
struct sdchunk {
  unsigned int	sdc_ssrc;	/* SSRC to which chunk refers	*/
  char		sdc_data[1];	/* Beginning of SDES items	*/
};

/* Struct for source description chunk item */
struct sditem {
  unsigned char	sdi_type;	/* Type of SDES item		*/
  unsigned char	sdi_len;	/* Length of item data		*/
  char		sdi_data[1];	/* SDES item data		*/
};

/* Struct for reason in RTCP bye message */
struct byereason {
  unsigned char	bye_length;	/* Length of reason text	*/
  char		bye_reason[1];	/* Reason for leaving.		*/
};

/* Struct for RTCP application-specific message */
struct app {
  unsigned int	app_ssrc;	/* SSRC of sender		*/
  char		app_name[4];	/* Name specififying app	*/
  char		app_data[1];	/* Application-specific data	*/
};

/* API Calls */
int rtcpsendbye(struct session *, char *);
int rtcpsend(struct session *, struct rtcp *, int);
int rtcpheader(struct rtcp *, int, unsigned char, int);
double rtcpcycle(struct session *);
double rtcpinitinterval(struct session *);

/* Internal Calls */
struct sdchunk *rtcpprocesschunk(struct session *, struct sdchunk *);
void rtcpn2h(struct rtcp *);
void rtcph2n(struct rtcp *);
double rtcpinterval(int, int, double, int, int, int *, int);
bool rtcpcycleupdate(struct session *, struct stream *, struct rblock *);
struct sdchunk *rtcpconsumechunk(struct sdchunk *);
bool rtcpcycleupdate(struct session *, struct stream *, struct rblock *);
int rtcprecv(struct session *);
int rtcpcnameadd(struct session *, struct stream *);
int rtcpcnamerem(struct session *, struct stream *);
int rtcpprocess(struct session *, struct rtcp *);
int rtcpsr(struct session *, struct rtcp *);
int rtcprr(struct session *, struct rtcp *);
int rtcpsdes(struct session *, struct rtcp *);
int rtcpbye(struct session *, struct rtcp *);
int rtcpapp(struct session *, struct rtcp *);
void rtcpcyclethreadfcn(struct session *);
void rtcprecvthreadfcn(struct session *);
#endif