rtcpcname.c

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

C
96
字号
/*------------------------------------------------------------------------- * rtcpcname.c - rtcpcnameadd, rtcpcnamerem *------------------------------------------------------------------------- */#include <rtp.h>#include <rtcp.h>#include <util.h>#include <hash.h>#include <string.h>#include <stdlib.h>#include <strings.h>/*------------------------------------------------------------------------ * rtcpnameadd - insert a stream * in a list of streams with same cname *------------------------------------------------------------------------ */intrtcpcnameadd(struct session *psn, struct stream *pstm){	struct stream		*first;	struct cnamelist	*pcnl;	if (pthread_mutex_lock(&psn->sn_cnamemutex) != 0)		return ERROR;	/*	 * Lookup the list for the cname pstm->stm_cname.	 */	pcnl = (struct cnamelist  *) htget(psn->sn_cnames, (unsigned int) pstm->stm_cname);	if (pcnl != NULL) {		/*		 * Insert pstm into the list of struct stream *'s		 * for cname pstm->stm_cname.		 */		first = pcnl->cn_stream;		pstm->stm_cnamenext = first->stm_cnamenext;		first->stm_cnamenext = pstm;		pstm->stm_cnameprev = first;		if (pstm->stm_cnamenext != NULL)			pstm->stm_cnamenext->stm_cnameprev = pstm;	} else {		/*		 * If the list does not exist, create it.		 */		pcnl = malloc(sizeof(struct cnamelist));		memset(pcnl, 0, sizeof(struct cnamelist));    		pcnl->cn_stream = pstm;		pstm->stm_cnamenext = NULL;		pstm->stm_cnameprev = NULL;		htadd(psn->sn_cnames, (unsigned int) strdup(pstm->stm_cname), pcnl);	}	pthread_mutex_unlock(&psn->sn_cnamemutex);	return OK;}/*------------------------------------------------------------------------ * rtcpnamerem - remove a stream * from a list of streams with same cname *------------------------------------------------------------------------ */intrtcpcnamerem(struct session *psn, struct stream *pstm){	/*	 * Adjust pointers in the next and previous 	 * nodes in the threading.	 */	if (pthread_mutex_lock(&psn->sn_cnamemutex) != 0)		return ERROR;	if (pstm->stm_cnamenext != NULL)		pstm->stm_cnamenext->stm_cnameprev = pstm->stm_cnameprev;	if (pstm->stm_cnameprev != NULL)		pstm->stm_cnameprev->stm_cnamenext = pstm->stm_cnamenext;	/*	 * Check if the last source in the list was removed.	 * If the list is empty, delete the cname from the 	 * cname hashtable.	 */	if (pstm->stm_cnameprev == NULL &&	    pstm->stm_cnamenext == NULL)		htdel(psn->sn_cnames, (unsigned int) pstm->stm_cname);  	pthread_mutex_unlock(&psn->sn_cnamemutex);  	return OK;  }

⌨️ 快捷键说明

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