jrtplib中组播代码发送端和接收端的实现

文章里面主要是把发送端课接收端代码的实现提了出来,和重要函数里的源码贴出来辅助学习,看到网上有人说好久做不出来,建议看看对应加入组播的源码,注意细节,话不多说,代码直接贴出来,各位朋友有意见多多交流。发送端:#include "rtpsession.h"#include "rtpudpv4transmitter.h"#include "rtpipv4address.h"#includ
摘要由CSDN通过智能技术生成


如果需要转载,请注明出处,谢谢

文章主要是把rtp组播的发送端和接收端的代码实现写了出来,最后面有代码的下载地址,看了网上基本没人把jrtp组播这个功能贴出来,于是看了看源码,将其实现,希望能对各位朋友有帮助,话不多说直接贴代码,欢迎交流和评论。



</pre><pre code_snippet_id="1677192" snippet_file_name="blog_20160510_3_3909878" name="code" class="cpp">发送端
#include "rtpsession.h"
#include "rtpudpv4transmitter.h"
#include "rtpipv4address.h"
#include "rtpsessionparams.h"
#include "rtperrors.h"
#include "rtppacket.h"
#ifndef WIN32
	#include <netinet/in.h>
	#include <arpa/inet.h>
#else
	#include <winsock2.h>
	#include<windows.h>
#endif // WIN32
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <string>

using namespace jrtplib;
using namespace std;


void checkerror(int rtperr)
{
	if(rtperr<0)
	{
		cout<<"ERROR:"<<RTPGetErrorString(rtperr)<<endl;
		exit(-1);
	}
}
int main()
{

	#ifdef WIN32
	WSADATA dat;
	WSAStartup(MAKEWORD(2,2),&dat);
	#endif // WIN32

	list<uint32_t> localip;

	RTPSession sess;
	uint16_t portbase=6666,destport=8888;
	uint32_t destip,srcip;
	string ipstr="239.255.0.1";
	string ipsrc="114.212.118.99";
	int status,i,num;
	destip=inet_addr(ipstr.c_str());//将字符串转换为32位网络字节序。
	srcip=inet_addr(ipsrc.c_str());

	if(destip==INADDR_NONE)
	{
		cout<<"bad destip address"<<endl;
		exit(-1);
	}
	destip=ntohl(destip);//将32位网络字节序转换成主机字节序
	srcip=ntohl(srcip);
	localip.push_back(srcip);
	//设置传输参数和会话参数
	RTPUDPv4TransmissionParams transparams;
	RTPSessionParams sessparams;

	// IMPORTANT: The local timestamp unit MUST be set, otherwise
	//            RTCP Sender Report info will be calculated wrong
	// In this case, we'll be sending 10 samples each second, so we'll
	// put the timestamp unit to (1.0/10.0)
	sessparams.SetOwnTimestampUnit(1.0/8000);

	sessparams.SetAcceptOwnPackets(true);
	transparams.SetPortbase(portbase);
	transparams.SetLocalIPList(localip);
	transparams.SetMulticastInterfaceIP(srcip);
	transparams.Set
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值