JRTP库与JTHREAD库的编译与移植

操作环境:

Host OS: Windows xp

VMware Workstation: 8.0.2

Guest OS: ubuntu10.10

Develop Board: TINY6410

Cross-Complier: arm-Linux-g++ 4.5.1

 

关于 jrtp 的一些说明:

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

 

一,编译为 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=/home/linux/Jrtplib-Jthread/target_x86

[root@localhost jthread-1.2.1]# make

[root@localhost jthread-1.2.1]# make install

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

 

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

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

Libraries have been installed in:

   /home/linux/Jrtplib-Jthread/target_x86 

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 库安装到什么目录下,而且如果使用这个库编译自己的文件应该怎么做。可以参考静态函数库与动态函数库。

 

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

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=/home/linux/Jrtplib-Jthread/target_x86 --with-jthread-includes=/home/linux/Jrtplib-Jthread/target_x86/include/jthread CPPFLAGS=-I/home/linux/Jrtplib-Jthread/target_x86/include/jthread LDFLAGS=-L/home/linux/Jrtplib-Jthread/target_x86/lib

说明:

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

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

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

 

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

checking for JThread include files... in /home/linux/Jrtplib-Jthread/target_x86/include/jthread"

checking JThread version... >= 1.1.0

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

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

 

接着进行 make make install

[root@localhost jrtplib-3.7.1]# make

[root@localhost jrtplib-3.7.1]# make install

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

在 ubuntu10.10  make 提示的错误:

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

或者:

 ubuntu10.10 make 提示的错误:

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:

  /home/linux/Jrtplib-Jthread/target_x86/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 库安装到什么目录下,而且如果使用这个库编译自己的文件应该怎么做。

 

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

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

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

 

 

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

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

(1) 对于 jthread

./configure --host=arm-linux --prefix=/home/linux/Jrtplib-Jthread/target_arm CC=arm-linux-gcc CXX=arm-linux-g++

(2) 对于 jrtlib

./configure --prefix=/home/linux/Jrtplib-Jthread/target_arm --host=arm-linux CC=arm-linux-gcc CXX=arm-linux-g++ --with-jthread-includes=/home/linux/Jrtplib-Jthread/target_arm/include/jthread CPPFLAGS=-I/home/linux/Jrtplib-Jthread/target_arm/include/jthread LDFLAGS=-L/home/linux/Jrtplib-Jthread/target_arm/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  }

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

通过测试下,得知 tiny 默认为小端模式,因此需要修改 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 行注释了 。注释后则以小段模式来编译。

然后就可以 make make install 了。

 

修改

遇到了第一个棘手的问题,提示can't retrieve login name,建立不了rtpsession。在rtpsession.cpp中。

后来发现是RTPSession::CreateCNAME这个函数搞得鬼
这个函数会从系统调用里获取loginname,但是一般的板子由于内核和文件系统的原因都没有loginname,所以
前:
if (!gotlogin)
 {
  char *logname = getenv("LOGNAME");
  if (logname == 0)
   return ERR_RTP_SESSION_CANTGETLOGINNAME;//这里return了一个error
  strncpy((char *)buffer,logname,*bufferlength);
 }
后:
if (!gotlogin)
 {
  char *logname = getenv("LOGNAME");
  char myname[] = "root";
  logname = myname;
  if (logname == 0)
   return ERR_RTP_SESSION_CANTGETLOGINNAME;//这里return了一个error
  strncpy((char *)buffer,logname,*bufferlength);
 }
 
 
所以我强制将logname的值设为root,就ok了。

 

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

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

(2) 把交叉编译后生成的库文件 :libjrtp-3.7.1.so libjthread.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

…….

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值