rtcpheader.c

来自「linux环境下用纯c写的RTP协议的通用开发库」· C语言 代码 · 共 61 行

C
61
字号
/*------------------------------------------------------------------------- * rtcpheader.c - rtcpheader *------------------------------------------------------------------------- */#include <rtp.h>#include <rtcp.h>/*------------------------------------------------------------------------ * rtcpheader - fill in an RTCP header in machine byte order and pad * for 32-bit alignment if necessary. Rtcpheader assumes that the caller  * has allocated the correct amount of memory to round up so that the * message is 32-bit aligned. *------------------------------------------------------------------------ */intrtcpheader(struct rtcp *prtcp, int count, unsigned char type, int bytelength){  	int		pad, i;  	if (count > (1 << 5) - 1)		return ERROR;	if (bytelength > 1 << 18)		return ERROR;	prtcp->rtcp_ver = RTP_CURRVERS;	prtcp->rtcp_count = count;	prtcp->rtcp_type = type;  	/*	 * RTCP acket length represented in 4-octet units minus one.	 */ 	prtcp->rtcp_length = (bytelength / 4) - 1;	/*	 * Determine if the packet must be padded so that it is	 * 32-bit aligned.	 */	pad = (bytelength % 4 > 0 ? 4 - (bytelength % 4) : 0);	if (pad > 0) {		prtcp->rtcp_length++;		prtcp->rtcp_pad = TRUE;		for (i = 0; i < pad - 1; i++) {			*((char *) prtcp + bytelength + i) = 0;      		}				/* 		 * The last byte of a padded RTCP packet		 * indicates the number of padding bytes		 * present.		 */		*((char *) prtcp + bytelength + pad - 1) = pad;	}	else		prtcp->rtcp_pad = FALSE;    	return OK;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?