天天看點

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