?? hust_rtprecv.c
字號:
/*------------------------------------------------------------------------- * rtprecv.c - rtprecv *------------------------------------------------------------------------- */#include <ipOS.h>#include <ipHAL.h>#include <ipStack.h>#include <ipEthernet.h>#include "hust_rtp.h"#include "hust_hash.h"#include "hust_event.h"#include "hust_rtplibcommon.h"////#include <unistd.h>/*------------------------------------------------------------------------ * rtprecv - 接收一個rtp包,并將包放到所屬源的stream中 把stream中的rtp包解析成為連續的TS流的操作 將是在stream中積累一定量的連續序列號的rtp包之后 *------------------------------------------------------------------------ */intrtprecv(struct session *psn){ struct rtpln *pln; ////隊列節點上的rtp包 u32_t from; ///rtp包的源地址 int fromlen, len; ///地址長度 struct rtp *prtp; struct stream *pstm; bool head; int rv; pln = (struct rtpln *) bufpoolgetbuf(&psn->sn_bpool); ///獲得固定大小的緩沖區 if (pln == NULL) { rtppostevent(psn, EVENT_NOBUFS, 0, NULL, 0); return ERROR; } ////處理緩沖區用完的情況 fromlen = sizeof(from);/// len = recvfrom(psn->sn_rtpfd, (char *) &pln->rln_rtp, psn->sn_bpool.bp_size - sizeof(struct rtpln), 0, (struct sockaddr *) &from, &fromlen);///用來接收遠程主機指定的soket傳來的數據,數據存放在pln->rln_trp里面 if (len < 1) { bufpoolfreebuf(pln); return ERROR; } ////接收失敗的情況 pln->rln_len = len; /* * Extract source address as RTCP destination for unicast session * if the RTCP destination has not already been learned. */ if (psn->sn_rtcpto== RTP_INADDRUNINITIALIZED) { psn->sn_rtcpto = from; } ////必要時,給rtcp賦目的地址 /* * Get pointer to RTP header. */ prtp = &pln->rln_rtp; ////prtp作為指向rtp頭部的指針 /* * Convert header byte order and check version. */ ////rtpntoh(prtp); ////這里不考慮字節的位的順序問題 if (prtp->rtp_ver != RTP_CURRVERS) { bufpoolfreebuf(pln); return ERROR; } ///檢查版本 /* * Lookup stream by SSRC. */ pstm = rtpgetstream(psn, prtp->rtp_ssrc); /* * Create new stream if newly discovered source. */ if (pstm == NULL) { if ((pstm = rtpnewstream(psn, prtp->rtp_ssrc)) == NULL) { bufpoolfreebuf(pln); return ERROR; } } ///如果是新的源,就要為這個源創建一個stream else { if (RTP_INACTIVE(pstm->stm_inactive)) { rtpreleasestream(psn, pstm); bufpoolfreebuf(pln); return ERROR; } } if (pstm->stm_ip== RTP_INADDRUNINITIALIZED) pstm->stm_ip = from;////stream.stm_ip是數據源的地址 /* * Update stream's statistics and check if stream is still * on probation. */ if (rtpupdate(psn, pstm, prtp) == ERROR) { rtpreleasestream(psn, pstm); bufpoolfreebuf(pln); return ERROR; } /* * Enqueue the packet if stream is ``on''. */ if (pstm->stm_enqueue == TRUE) { /* * Tag packet with *extended* sequence number. */ pln->rln_seq = ((pstm->stm_roll) << 16) | prtp->rtp_seq; ////pthread_mutex_lock(&pstm->stm_queue.rq_mutex); rv = _rtpqinsert(&pstm->stm_queue, pln, &head); ////pthread_mutex_unlock(&pstm->stm_queue.rq_mutex); /* * Post event if packet added at front of queue. * Doing so will notify a thread waiting on an * empty queue. */ if (rv == OK) { rtppostevent(psn, (head == TRUE ? EVENT_RTP_HEAD : EVENT_RTP), pstm->stm_ssrc, NULL, 0); rtpreleasestream(psn, pstm); return OK; } else { /* * Free packet and return error if * enqueue operation failed. */ rtpreleasestream(psn, pstm); bufpoolfreebuf(pln); return ERROR; } } rtpreleasestream(psn, pstm); /* * Post an RTP-packet-received event. */ rtppostevent(psn, EVENT_RTP, prtp->rtp_ssrc, NULL, 0); bufpoolfreebuf(pln); return OK;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -