如果需要转载,请注明出处,谢谢
文章主要是把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