⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 udp_recv.c.bak

📁 实现基于ip2022的MPEG2 TS的IP组播接收
💻 BAK
字号:
/*
 *rtprecv.c
 */

#include <ipOS.h>
#include <ipHAL.h>
#include <ipStack.h>
#include <ipEthernet.h>
#include "hust_rtp.h"
#include "hust_rtplibcommon.h"
#include "hust_rtcp.h"
#include "hust_event.h"
#include "hust_hash.h"
#include "hust_linux.h"

struct session *psn;
void udp_rtp_recv(struct udp_socket *udps, struct ip_datalink_instance *link, u32_t src_addr, u16_t src_port, u32_t dest_addr, u32_t spec_dest_addr, u16_t dest_port, u8_t ttl, u8_t tos, u16_t id, struct netbuf *udpnb)
{
	struct rtpln		*pln;
	///struct sockaddr_in	from;
	///int			fromlen, len;
	struct rtp		*prtp;
	struct stream		*pstm;
	bool			head;
	int			rv;
	
	addr_t len=netbuf_get_remaining(udpnb);
	
	
	if(len>1450)len=1450;
	

	if(nb==nb1)//nb1
	{
		netbuf_set_start(nb,nb1_start);
		netbuf_set_end(nb,nb1_end);
		netbuf_set_pos(nb, nb1_start);
		netbuf_fwd_copy(nb, udpnb, len);
		nb=nb2;
	}
	else //nb2
	{
		netbuf_set_start(nb,nb2_start);
		netbuf_set_end(nb,nb2_end);
		netbuf_set_pos(nb,nb2_start);
		netbuf_fwd_copy(nb, udpnb, len);
		nb=nb1;
	}
	
	pln = (struct rtpln *) bufpoolgetbuf(&psn->sn_bpool);
	if (pln ==  NULL) {
		rtppostevent(psn, EVENT_NOBUFS, 0, NULL, 0);
		return ERROR;
	}
	
	netbuf_fwd_read_mem(nb,&pln->rln_rtp,len);
	
	if (len < 1) {
		bufpoolfreebuf(pln);
		return ERROR;
	}
	
	pln->rln_len = len;
	
	if (psn->sn_rtcpto == RTP_INADDRUNINITIALIZED) {
		psn->sn_rtcpto = src_addr;
	}
	
	prtp = &pln->rln_rtp;
	
	if (prtp->rtp_ver != RTP_CURRVERS) {
		bufpoolfreebuf(pln);
		return ERROR;
	}
	
	pstm = rtpgetstream(psn, prtp->rtp_ssrc);
	
	if (pstm == NULL) {
		if ((pstm = rtpnewstream(psn, prtp->rtp_ssrc)) == NULL) {/*产生新的stream*/
			bufpoolfreebuf(pln);
			return ERROR;
		}
	}
	else {
		if (RTP_INACTIVE(pstm->stm_inactive)) {/*收到BYE包或超时*/
			rtpreleasestream(psn, pstm);
			bufpoolfreebuf(pln);
			return ERROR;
		}
	}
  
	if (pstm->stm_ip == RTP_INADDRUNINITIALIZED)
		pstm->stm_ip = src_addr;/*记录流的参与者的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;
		
		rv = _rtpqinsert(&pstm->stm_queue, pln, &head);
		

		/*
		 * 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;	
	///if((bufmem=heap_alloc(len))==NULL)
	///{
	///	return FLASE;
       /// }
	///
	
	
}

void udp_rtcp_recv(struct udp_socket *udps, struct ip_datalink_instance *link, u32_t src_addr, u16_t src_port, u32_t dest_addr, u32_t spec_dest_addr, u16_t dest_port, u8_t ttl, u8_t tos, u16_t id, struct netbuf *udpnb)
{
	struct rtcp		*prtcp, *prtcp2;
	///struct sockaddr_in	from;
	///int			fromlen, len;
	char			rtcpbuf[RTCP_MAXPACKETSZ];
	
	addr_t len=netbuf_get_remaining(udpnb);
	
	
	if(len>1450)len=1450;
	

	if(nb==nb1)//nb1
	{
		netbuf_set_start(nb,nb1_start);
		netbuf_set_end(nb,nb1_end);
		netbuf_set_pos(nb, nb1_start);
		netbuf_fwd_copy(nb, udpnb, len);
		nb=nb2;
	}
	else //nb2
	{
		netbuf_set_start(nb,nb2_start);
		netbuf_set_end(nb,nb2_end);
		netbuf_set_pos(nb,nb2_start);
		netbuf_fwd_copy(nb, udpnb, len);
		nb=nb1;
	}
	
	///if((bufmem=heap_alloc(len))==NULL)
	///{
	///	return FLASE;
       /// }
	///netbuf_fwd_read_mem(nb,p,len);
	
	
}
*/

⌨️ 快捷键说明

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