天天看点

linux下安装jrtplib-3.9.1

http://blog.chinaunix.net/uid-28458801-id-3501888.html

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

下载jrtplib-3.9.1:http://research.edm.uhasselt.be/~jori/page/index.php?n=CS.Jrtplib

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 的关系:

linux下安装jrtplib-3.9.1

2,配置好 jrtplib-3.9.1

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

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

解决方法:

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

linux下安装jrtplib-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)

    否则会出现以下错误:

linux下安装jrtplib-3.9.1

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

解决方法:

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

linux下安装jrtplib-3.9.1

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

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

linux下安装jrtplib-3.9.1

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

/*

   Here's a small IPv4 example: it asks for a portbase and a destination and 

   starts sending packets to that destination.

*/



#include "jrtplib/rtpsession.h"

#include "jrtplib/rtpudpv4transmitter.h"

#include "jrtplib/rtpipv4address.h"

#include "jrtplib/rtpsessionparams.h"

#include "jrtplib/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;

    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);

    status = sess.Create(sessparams,&transparams);    

    checkerror(status);

    

    RTPIPv4Address addr(destip,destport);

    

    status = sess.AddDestination(addr);

    checkerror(status);

    

    for (i = 1 ; i <= num ; i++)

    {

        printf("nSending packet %d/%dn",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;

} 
           

3,使用 jrtplib-3.9.1编译文件

编译 example1.cpp 文件:

linux下安装jrtplib-3.9.1

执行代码如下

linux下安装jrtplib-3.9.1