Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6377597
  • 博文数量: 579
  • 博客积分: 1548
  • 博客等级: 上尉
  • 技术积分: 16634
  • 用 户 组: 普通用户
  • 注册时间: 2012-12-12 15:29
个人简介

http://www.csdn.net/ http://www.arm.com/zh/ https://www.kernel.org/ http://www.linuxpk.com/ http://www.51develop.net/ http://linux.chinaitlab.com/ http://www.embeddedlinux.org.cn http://bbs.pediy.com/

文章分类

全部博文(579)

文章存档

2018年(18)

2015年(91)

2014年(159)

2013年(231)

2012年(80)

分类: LINUX

2013-02-27 12:41:11

当前使用的操作系统 : ubuntu11.10


下载jrtplib-3.9.1:


1,安装 jrtplib-3.9.1

1,解压到某目录下(如:/usr/local/src)

        #cp jrtplib-3.9.1.tar.gz /usr/local/src        //复制 jrtplib-3.9.1.tar.gz 到 /usr/local/src 中

        #ce /usr/local/src                                 //去到 /usr/local/src 目录中

        #tar -xvf jrtplib-3.9.1.tar.gz                    //解压 jrtplib-3.9.1.tar.gz 到当前目录下,即 /usr/local/src

2,使用 cmake 生成 makefile 文件

        #cd jrtplib-3.9.1                                    //进入到 jrtplib-3.9.1 目录中,即 /usr/local/src/jrtplib-3.9.1/ 中

        #cmake CMakeLists.txt                           //cmake通过 CMakeLists.txt 文件生成 makefile 文件

注意:如果系统中没有安装 cmake,则要安装 cmake

        #apt-get install cmake


3,编译安装 jrtplib

        #make                                                   //编译jrtplib

        #make install                                           //安装 jrtplib 到 系统中


至此,系统中会生成以下文件:

        1,生成 /usr/local/include/jrtplib3/ 目录,该目录下是使用 jrtplib 库是要包含的 头文件

        2,在 /usr/local/lib 中,生成 libjrtp.so.3.9.1 库文件,以及 libjrtp.so.3.9.1 库文件的软连接 libjrtp.so.;以及 libjrtp.a 文件。

以下命令可以查看 libjrtp.so.3.9.1 和 libjrtp.so 的关系:


2,配置好 jrtplib-3.9.1

程序要使用 jrtplib 库还要有以下的配置,否则系统找不到对应的头文件和静态库。


1,要 共享链接库,一般来说,Linux默认会在路径为 /lib 和 /usr/lib下的库文件搜索,而上面的库文件在 /usr/local/lib 中。

解决方法:

        执行下面的命令:#ln -s /usr/local/lib/libjrtp.so.3.9.1 /usr/lib

        生成 /usr/local/lib/libjrtp.so.3.9.1 的软连接到 /usr/lib 中,则此时 /usr/lib 会有软连接文件 libjrtp.so.3.9.1,即(/usr/lib/libjrtp.so.3.9.1)


    否则会出现以下错误:


2,要使用头文件Linux默认会在路径为 /usr/include 下中搜索,而当前的头文件则是存放在 /usr/local/inclde/jrtplib3 中

解决方法:

            执行以下命令:#ln -s /usr/local/include/jrtplib3 /usr/include/jrtplib

        生成 /usr/local/include/jrtplib3 的软连接到 /usr/include/jrtplib 中。

如果没有这个链接,会出现以下错误


    接下来还要修改源码中的 include 的,具体源码如下:


点击(此处)折叠或打开

  1. /*
  2.    Here's a small IPv4 example: it asks for a portbase and a destination and
  3.    starts sending packets to that destination.
  4. */

  5. #include "jrtplib/rtpsession.h"
  6. #include "jrtplib/rtpudpv4transmitter.h"
  7. #include "jrtplib/rtpipv4address.h"
  8. #include "jrtplib/rtpsessionparams.h"
  9. #include "jrtplib/rtperrors.h"
  10. #ifndef WIN32
  11.     #include <netinet/in.h>
  12.     #include <arpa/inet.h>
  13. #else
  14.     #include <winsock2.h>
  15. #endif // WIN32
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include <iostream>
  19. #include <string>

  20. using namespace jrtplib;

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

  25. void checkerror(int rtperr)
  26. {
  27.     if (rtperr < 0)
  28.     {
  29.         std::cout << "ERROR: " << RTPGetErrorString(rtperr) << std::endl;
  30.         exit(-1);
  31.     }
  32. }

  33. //
  34. // The main routine
  35. //

  36. int main(void)
  37. {
  38. #ifdef WIN32
  39.     WSADATA dat;
  40.     WSAStartup(MAKEWORD(2,2),&dat);
  41. #endif // WIN32
  42.     
  43.     RTPSession sess;
  44.     uint16_t portbase,destport;
  45.     uint32_t destip;
  46.     std::string ipstr;
  47.     int status,i,num;

  48.         // First, we'll ask for the necessary information
  49.         
  50.     std::cout << "Enter local portbase:" << std::endl;
  51.     std::cin >> portbase;
  52.     std::cout << std::endl;
  53.     
  54.     std::cout << "Enter the destination IP address" << std::endl;
  55.     std::cin >> ipstr;
  56.     destip = inet_addr(ipstr.c_str());
  57.     if (destip == INADDR_NONE)
  58.     {
  59.         std::cerr << "Bad IP address specified" << std::endl;
  60.         return -1;
  61.     }
  62.     
  63.     // The inet_addr function returns a value in network byte order, but
  64.     // we need the IP address in host byte order, so we use a call to
  65.     // ntohl
  66.     destip = ntohl(destip);
  67.     
  68.     std::cout << "Enter the destination port" << std::endl;
  69.     std::cin >> destport;
  70.     
  71.     std::cout << std::endl;
  72.     std::cout << "Number of packets you wish to be sent:" << std::endl;
  73.     std::cin >> num;
  74.     
  75.     // Now, we'll create a RTP session, set the destination, send some
  76.     // packets and poll for incoming data.
  77.     
  78.     RTPUDPv4TransmissionParams transparams;
  79.     RTPSessionParams sessparams;
  80.     
  81.     // IMPORTANT: The local timestamp unit MUST be set, otherwise
  82.     // RTCP Sender Report info will be calculated wrong
  83.     // In this case, we'll be sending 10 samples each second, so we'll
  84.     // put the timestamp unit to (1.0/10.0)
  85.     sessparams.SetOwnTimestampUnit(1.0/10.0);        
  86.     
  87.     sessparams.SetAcceptOwnPackets(true);
  88.     transparams.SetPortbase(portbase);
  89.     status = sess.Create(sessparams,&transparams);    
  90.     checkerror(status);
  91.     
  92.     RTPIPv4Address addr(destip,destport);
  93.     
  94.     status = sess.AddDestination(addr);
  95.     checkerror(status);
  96.     
  97.     for (i = 1 ; i <= num ; i++)
  98.     {
  99.         printf("nSending packet %d/%dn",i,num);
  100.         
  101.         // send the packet
  102.         status = sess.SendPacket((void *)"1234567890",10,0,false,10);
  103.         checkerror(status);
  104.         
  105.         sess.BeginDataAccess();
  106.         
  107.         // check incoming packets
  108.         if (sess.GotoFirstSourceWithData())
  109.         {
  110.             do
  111.             {
  112.                 RTPPacket *pack;
  113.                 
  114.                 while ((pack = sess.GetNextPacket()) != NULL)
  115.                 {
  116.                     // You can examine the data here
  117.                     printf("Got packet !n");
  118.                     
  119.                     // we don't longer need the packet, so
  120.                     // we'll delete it
  121.                     sess.DeletePacket(pack);
  122.                 }
  123.             } while (sess.GotoNextSourceWithData());
  124.         }
  125.         
  126.         sess.EndDataAccess();

  127. #ifndef RTP_SUPPORT_THREAD
  128.         status = sess.Poll();
  129.         checkerror(status);
  130. #endif // RTP_SUPPORT_THREAD
  131.         
  132.         RTPTime::Wait(RTPTime(1,0));
  133.     }
  134.     
  135.     sess.BYEDestroy(RTPTime(10,0),0,0);

  136. #ifdef WIN32
  137.     WSACleanup();
  138. #endif // WIN32
  139.     return 0;
  140. }


3,使用 jrtplib-3.9.1编译文件

编译 example1.cpp 文件:

执行代码如下




阅读(8784) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~