JRTP库与JTHREAD库的编译与移植

来源:互联网 发布:jsp网上商城系统 源码 编辑:程序博客网 时间:2024/05/17 06:43

 

操作环境:

Host OS: Windows 7

VMware Workstation:6.5.1

Guest OS: Fedora 9

Develop Board: MINI2440

Cross-Complier: ARM-Linux-GCC 4.3.2

 

关于jrtp的一些说明:

说明1jrtp有两种数据接收方式:第一种是用jthread库提供的线程自动在后台执行对数据的接收。第二种是用户自己调用RTPSession中的Poll方法。如果采取第一种方法则要安装jthread库,则安装 jthread-1.2.1.tar.gz,而且 jthread-1.2.1必须先与jrtp-3.7.1的安装。因为在jrtp-3.7.1configure中,会查找系统是否有编译了jthread库,如果有,那么编译的jrtp库会开启对jthread的支持。因此如果先编译jrtp在编译jthread,编译出来的jrtp是没有开启对jthread的支持的。如果采用第二种方法,那么可以不用编译jthread库,而直接编译jrtp库。

 

jrtp-3.7.1.tar.gzjthread-1.2.1.tar.gz的下载地址

http://research.edm.uhasselt.be/~jori/page/index.php?n=CS.Jrtplib

 

 

一,编译为PC所用:

PS:./configure –help 可以查看一些可以配置选项

jthread-1.2.1的编译

[root@localhost pc-jrtp]# tar -zxvf jthread-1.2.1.tar.gz

[root@localhost pc-jrtp]# cd jthread-1.2.1

[root@localhost jthread-1.2.1]# ./configure --prefix=/opt/mini2440/pc-jrtp

[root@localhost jthread-1.2.1]# make

[root@localhost jthread-1.2.1]# make install

说明: --prefix=指定编译后的jthread库安装到什么目录

 

执行make install时会出现如下信息:

-----------------------------------------------------------------

Libraries have been installed in:

   /opt/mini2440/pc-jrtp/lib

 

If you ever happen to want to link against installed libraries

in a given directory, LIBDIR, you must either use libtool, and

specify the full pathname of the library, or use the `-LLIBDIR'

flag during linking and do at least one of the following:

   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable

     during execution

   - add LIBDIR to the `LD_RUN_PATH' environment variable

     during linking

   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag

   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

 

See any operating system documentation about shared libraries for

more information, such as the ld(1) and ld.so(8) manual pages.

-----------------------------------------------------------------

这段英文告诉我们编译后的jthread库安装到什么目录下,而且如果使用这个库编译自己的文件应该怎么做。可以参考静态函数库与动态函数库。

 

安装成功后在自己指定目录下有:includelib两个文件夹

include中又有一个jthread的文件夹,里面包含了jthread库的头文件

lib中包含了编译成功的jthread库:包括动态库libjthread-1.2.1.so静态库libjthread.a

 

(2) jrtplib-3.7.1的编译

[root@localhost pc-jrtp]# tar -zxvf jrtplib-3.7.1.tar.gz

[root@localhost pc-jrtp]# cd jrtplib-3.7.1

[root@localhost pc-jrtp]#./configure --prefix=/opt/mini2440/pc-jrtp/ --with-jthread-includes=/opt/mini2440/pc-jrtp/include/jthread LDFLAGS=-L/opt/mini2440/pc-jrtp/lib

说明:

--prefix= --prefix:指定编译后的jrtplib库安装到什么目录。

--with-jthread-includes:指定之前安装的jthread库的头文件安装在什么目录下。如果不需要jthread的支持,这个选项可以不用。

LDFLAGS:为编译时需要连接的动态库的路径。如果不需要jthread库的支持,这个选项不要。

 

configure过程中出现的提示信息:

checking for JThread include files... in "/opt/mini2440/pc-jrtp/include/jthread"

checking JThread version... >= 1.1.0

checking if we can link against jthread and pthread... yes

说明jthread路径正确,配置文件开启了对jthread的支持。

 

接着进行makemake install

[root@localhost jrtplib-3.7.1]# make

[root@localhost jrtplib-3.7.1]# make install

在不修改源文件情况下, make的过程中直接编译可能出现的错误:

Fedora 9make提示的错误:

rtppacket.cpp:311: error: 'memcpy' was not declared in this scope

或者:

Fedora 13make提示的错误:

rtperrors.cpp: In function 'std::string RTPGetErrorString(int)':

rtperrors.cpp:225: error: 'snprintf' was not declared in this scope

为了make成功,需要修改jrtplib-3.7.1源文件rtpdefines.h

添加如下语句:
#include <stdio.h>
#include <stdarg.h>
#include <string.h>

操作如下:

[root@localhost jrtplib-3.7.1]# cd src/

[root@localhost src]# vim rtpdefines.h

// rtpdefines.h

75 #include <stdio.h>

 76 #include <stdarg.h>

 77 #include <string.h>

 78 #if (defined(WIN32) || defined(_WIN32_WCE))

 79         #if (!defined(_WIN32_WCE)) && (defined(_MSC_VER) && _MSC_VER >= 1400 )

 80                 #define RTP_SNPRINTF _snprintf_s

 81         #else

 82                 #define RTP_SNPRINTF _snprintf

 83         #endif

 84 #else

 85         #define RTP_SNPRINTF snprintf

 86 #endif // WIN32 || _WIN32_WCE

重新make后可以成功。

 

make isntall后有如下信息

-----------------------------------------------------------------

Libraries have been installed in:

   /opt/mini2440/pc-jrtp/lib

 

If you ever happen to want to link against installed libraries

in a given directory, LIBDIR, you must either use libtool, and

specify the full pathname of the library, or use the `-LLIBDIR'

flag during linking and do at least one of the following:

   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable

     during execution

   - add LIBDIR to the `LD_RUN_PATH' environment variable

     during linking

   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag

   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

 

See any operating system documentation about shared libraries for

more information, such as the ld(1) and ld.so(8) manual pages.

-----------------------------------------------------------------

这段英文告诉我们编译后的jrtp库安装到什么目录下,而且如果使用这个库编译自己的文件应该怎么做。

 

安装成功后在自己指定目录下有:includelib两个文件夹

include中又有一个jrtplib的文件夹,里面包含了jrtplib库的头文件

lib中包含了编译成功的jrtp库:包括动态库libjrtp-3.7.1.so静态库libjrtp.a

 

 

二,编译为MINI2440(ARM)所用:

步骤与编译为PC所用一样,但是configure的设置过有所不同,现在说明:

(1) 对于jthread

./configure  --prefix=/opt/mini2440/arm-jrtp –host=arm-linux CC=arm-linux-gcc CXX=arm-linux-g++

(2) 对于jrtlib

./configure –prefix=/opt/mini2440/arm-jrtp –host=arm-linux –with-jthread-includes=/opt/mini2440/arm-jrtp/includes CC=arm-linux-gcc CXX=arm-linux LDFLAGS=-L/opt/mini2440/arm-jrtp/lib

然后会看到如下提示信息:

ASSUMING TARGET IS BIG ENDIAN:

  The script detected a cross-compiler on your system. This can mean that

  there really is a cross-compiler installed, or that for some other reason,

  a simple program could not be run. You should check the config.log file

  to verify this.

  Since we are assuming a cross-compiler, we won't be able to actually test

  any program. More important, we cannot test if the system is big or little

  endian.

  For now, big endian is assumed. If this assumption should be wrong, you will

  have to comment the appropriate line in 'rtpconfig_unix.h'

说明configure把目标平台默认为是大端模式。如果需要改变则要修改rtpconfig_ unix.h

 

我们那么应该测试开发板是大端模式还是小端模式:

至于什么是大端模式,什么小端模式,以及为什么要测试请看我博客上的大端模式与小端模式。

 

测试程序:

1 #include

  2 int main(void)

  3 {

  4         int num = 0x1234;

  5         char *p = &num;

  6         if (*p == 0x12){

  7                 printf("Big Endian/n");

  8         }

  9         else{

 10                 printf("Little Endian/n");

 11         }

 12         return 0;

 13  }

保存后用交叉编译器编译生成可执行文件后,放到目标平台上执行。从而判断出目标平台是什么模式。

通过测试下,得知MINI2440默认为小端模式,因此需要修改rtpconfig_ unix.h

文件在:

/opt/mini2440/arm-jrtp/jrtplib-3.7.1/src

修改操作如下:

33 #ifndef RTPCONFIG_UNIX_H

 34

 35 #define RTPCONFIG_UNIX_H

 36

 37 // Don't have

 38

 39 // Don't have

 40

 41 //#define RTP_BIG_ENDIAN // comment this if the target is a little endian system

 42

 43 #define RTP_SOCKLENTYPE_UINT

则是把第41行注释了。注释后则以小段模式来编译。

然后就可以makemake install了。

 

三,最后一步就是测试了:

(1) 首先把编译为PC所用的库文件:libjrtp-3.7.1.solibjthread.so复制到Fedora9 /lib

(2) 把交叉编译后生成的库文件:libjrtp-3.7.1.solibjthread.so复制到开发板上的/lib

(3) 执行/opt/mini2440/pc-jrtp/jrtp-3.7.1/example下的exampl4

[root@localhost examples]# ./example4

Enter local portbase:

9090

 

 

Number of seconds you wish to wait:

500

 

(4) /opt/mini2440/arm-jrtp/jrtp-3.7.1/example目录复制到开发板上并执行exampl1

[root@FriendlyARM download]# ./example1

Enter local portbase:

9090

 

Enter the destination IP address

192.168.0.2

Enter the destination port

9090

 

Number of packets you wish to be sent:

50

 

(5) 如果在PC上出现Got packet则表示可以收到开发板发过来的数据包

Got packet 32390 from SSRC 609572025

Got packet 32391 from SSRC 609572025

…….