RTP实时音视频数据传输,发送端和接收端

本文介绍了使用RTP协议进行实时音视频数据传输的过程,包括发送端和接收端的文件编写,以及编译步骤。通过send.cpp和receive.cpp两个文件,实现了发送和接收功能,并提供了编译指令。
摘要由CSDN通过智能技术生成

1.项目前期工作(配置好环境)

点击打开链接

2.发送端文件编写(见下面的send.cpp)

3.接收端文件编写(见下面的receive.cpp)

4.编译文件

(1)发送端

                      g++ -o send send.cpp -I /usr/local/include/jrtplib3/ -ljrtp

(2)接收端

                      g++ -o receive  receive.cpp -I /usr/local/include/jrtplib3/ -ljrtp

附录:

(1)send.cpp

#include "rtpsession.h"
#include "rtppacket.h"
#include "rtpudpv4transmitter.h"
#include "rtpipv4address.h"
#include "rtpsessionparams.h"
#include "rtperrors.h"
#include "rtpmemorymanager.h"
#ifndef WIN32
	#include <netinet/in.h>
	#include <arpa/inet.h>
#else
	#include <winsock2.h>
#endif // WIN32
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <string>

//
// This function checks if there was a RTP error. If so, it displays an error
// message and exists.
//

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

//
// The main routine
//

#ifdef RTP_SUPPORT_THREAD

class MyMemoryManager : public RTPMemoryManager
{
public:
	MyMemoryManager() 
	{ 
		mutex.Init();
		alloccount = 0; 
		freecount = 0; 
	}
	~MyMemoryManager() 
	{ 
		std::cout << "alloc: " << alloccount << " free: " << freecount << std::endl; 
	}
	void *AllocateBuffer(size_t numbytes, int memtype)
	{
		mutex.Lock();
		void *buf = malloc(numbytes);
		std::cout << "Allocated " << numbytes << " bytes at location " << buf << " (memtype = " << memtype << ")" << std::endl;
		alloccount++;
		mutex.Unlock();
		return buf;
	}

	void FreeBuffer(void *p)
	{
		mutex.Lock();
		std::cout << "Freeing block " << p << std::endl;
		freecount++;
		free(p);
		mutex.Unlock();
	}
private:
	int allocc
  • 1
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值