【流媒體】jrtplib—VS2010下RTP开源协议库JRTPLIB3.9.1编译
2016-01-12 14:59
821 查看
【流媒體】jrtplib—VS2010下RTP开源协议库JRTPLIB3.9.1编译
SkySeraph Apr 7th 2012
Email:skyseraph00@163.com一、JRTPLIB简介
老外用C++编写的开源RTP协议库,用来进行实时数据传输,可以运行在Windows、Linux、 FreeBSD、Solaris、Unix和VxWorks 等多种操作系统上,主页为:http://research.edm.uhasselt.be/~jori/page/index.php?n=Main.HomePage
二、相关下载
jrtplib: http://research.edm.uhasselt.be/~jori/page/index.php?n=CS.Jrtplibjthread: http://research.edm.uhasselt.be/~jori/page/index.php?n=CS.Jthread
cmake: http://www.cmake.org/cmake/resources/software.html
三、 编译步骤
1 下载jrtplib和jthread并解压缩。阅读README。
2 编译jthread生成jthread.lib和jthread_d.lib。
① 打开cmake,添加好输入(where..)和输出路径(where to...),完成configure配置(选visual studio 10),配置结果如下图:② 点击generate,生成VS2010工程文件
③ 打开工程文件并编译,在debug和release下分别生成jthread.lib和jthread_d.lib
编译的具体方法为:选择Solution
Explorer里的 Solution jthread,点右键,运行"Rebuild Solution";如编译无错误,再选择INSTALL项目,运行"Build"。
④ 如果编译成功(如下图),会在C:\Program
Files\jthread的include\jthread下生成头文件;在lib下生成lib和cmake文件
温馨提示:在win7下,你必须拥有管理者权限,否则编译不会通过,因为无法在C:\Program
Files创建jthread文件,当然你可以手动创建。
3 编译jrtplib生成jrtplib.lib和jrtplib_d.lib。
① 同2-①,其中configure会稍微麻烦一些,详细配置结果如下:② 点击generate,生成VS2010工程文件
③ 打开工程文件并编译,在debug和release下分别生成jrtplib_d.lib和jrtplib.lib
④ 编译成功(如下图),在C:\Program Files\jrtplib下include\jrtplib3下会生成一堆头文件;在lib下会生成jrtplib_d.lib和jrtplib.lib以及cmake文件
说明:网上提到的一些用VS2008和VC6.0方法中提到了两个细节: 一是要把"jmutex.h"和"jthread.h"两个头文件放入jrtplib/src目录下,二是要把src文件夹下所有头文件中的<jmutex.h>和<jthread.h>语句修改为"jmutex.h"和"jthread.h"。
我在编译时没有处理这两个细节成功了,后续调试出现相应问题相应修改一下即可。
四、 使用实例
1 添加库
①步骤一:方法1. 将编译生成的jrtplib.lib和jthread.lib库拷贝到“*:\Program Files\Microsoft Visual Studio 10.0\VC\lib”下面
方法2. 将编译生成的四个lib库库拷贝到当前工程的cpp文件下
②步骤二:
方法1. [菜单]“项目->属性->配置属性->连接器->输入->附加依赖项”里填写“jrtplib.lib;jthread.lib;WS2_32.lib”
方法2. pragma 方式,在stdafx.h文件中 添加
#ifdef DEBUG #pragma comment(lib, "jrtplib_d.lib") #pragma comment(lib,"jthread_d.lib") #pragma comment(lib,"WS2_32.lib") #else #pragma comment(lib, "jrtplib.lib") #pragma comment(lib,"jthread.lib") #pragma comment(lib,"WS2_32.lib") #endif
2 添加头文件
①步骤一:将所有的.h文件放到一起,如myJRTPLIBHeader里面,再添加include②步骤二:
方法1.“项目->属性->配置属性->C/C++->常规->附加包含目录”
方法2.“工具->选项->项目和解决方案->C++
目录”,选择对应平台,然后添加所需“包括文件”目录(此法VS2010不通)
3 测试代码(sample1)
cpp文件:// jrtplibTest.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" // 头文件 #include "rtpsession.h" #include "rtpudpv4transmitter.h" #include "rtpipv4address.h" #include "rtpsessionparams.h" #include "rtperrors.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> using namespace jrtplib; // // 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 // int main(void) { #ifdef WIN32 WSADATA dat; WSAStartup(MAKEWORD(2,2),&dat); #endif // WIN32 RTPSession sess; uint16_t portbase,destport; uint32_t destip; std::string ipstr; int status,i,num; // First, we'll ask for the necessary information std::cout << "Enter local portbase:" << std::endl; std::cin >> portbase; std::cout << std::endl; std::cout << "Enter the destination IP address" << std::endl; std::cin >> ipstr; // 获得接收端的IP地址和端口号 destip = inet_addr(ipstr.c_str()); if (destip == INADDR_NONE) { std::cerr << "Bad IP address specified" << std::endl; return -1; } // The inet_addr function returns a value in network byte order, but // we need the IP address in host byte order, so we use a call to // ntohl destip = ntohl(destip); std::cout << "Enter the destination port" << std::endl; std::cin >> destport; std::cout << std::endl; std::cout << "Number of packets you wish to be sent:" << std::endl; std::cin >> num; // Now, we'll create a RTP session, set the destination, send some // packets and poll for incoming data. 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/10.0); sessparams.SetAcceptOwnPackets(true); transparams.SetPortbase(portbase); // 创建RTP会话 status = sess.Create(sessparams,&transparams); checkerror(status); RTPIPv4Address addr(destip,destport); // 指定RTP数据接收端 status = sess.AddDestination(addr); checkerror(status); for (i = 1 ; i <= num ; i++) { printf("\nSending packet %d/%d\n",i,num); // send the packet status = sess.SendPacket((void *)"1234567890",10,0,false,10); checkerror(status); sess.BeginDataAccess(); // check incoming packets if (sess.GotoFirstSourceWithData()) { do { RTPPacket *pack; while ((pack = sess.GetNextPacket()) != NULL) { // You can examine the data here printf("Got packet !\n"); // we don't longer need the packet, so // we'll delete it sess.DeletePacket(pack); } } while (sess.GotoNextSourceWithData()); } sess.EndDataAccess(); #ifndef RTP_SUPPORT_THREAD status = sess.Poll(); checkerror(status); #endif // RTP_SUPPORT_THREAD RTPTime::Wait(RTPTime(1,0)); } sess.BYEDestroy(RTPTime(10,0),0,0); #ifdef WIN32 WSACleanup(); #endif // WIN32 return 0; }
4 下载
在VS2010+Win7下编译好的JRTPLIB库及相关头文件下载:(刚传CSDN,现在打不开,等等,明天补上...)补充:下载(猛击)
Ref/Related
1 http://research.edm.uhasselt.be/~jori/page/index.php?n=CS.Jrtplib2 http://research.edm.uhasselt.be/jori/jrtplib/documentation/index.html
3 http://blog.csdn.net/nickche300/article/details/6408099
4 http://blog.csdn.net/sunloverain2/article/details/5398694
5 http://blog.csdn.net/aaronalan/article/details/5153604
from: http://www.cnblogs.com/skyseraph/archive/2012/04/07/2435540.html
作者:skyseraph
出处:http://www.cnblogs.com/skyseraph/
Email/GTalk: zgzhaobo@gmail.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
相关文章推荐
- php 写内容入csv文件乱码解决方法
- PHP分页函数代码(简单实用型)
- 一个经典的PHP文件上传类分享
- PHP 实现用户注册及登陆
- laravel5中间件的使用例子
- 选择了兄弟连,我不会后悔
- 3.php工厂模式
- PHP错误提示的关闭方法
- 让PHP7达到最高性能的几个Tips
- Thinkphp中查询复杂sql查询表达式,如何表达MYSQL中的某字段不为空is not null?
- PHP代码优化的40条建议
- php文件上传后台存储中文乱码问题解决方案
- RTP协议全解(H264码流和PS流)
- phan—php语法静态检查在windows下的配置
- 新 好用的 YII数据库操作常用语句
- PHP运行模式
- PHP5中PDO的简单使用
- Matplotlib绘图库初探
- 阿里云云服务器ECS Windows Server 2012 R2 64位标准版PHP环境搭建
- 细说php完美分页类