树莓派H264异构编解码(decodes and encodes h264 using the GPU on raspberry pi)-配置交叉编译环境

故事:七月,去年,一个坑,我挖的。填坑,现在。

场白:Just do it。

简述:标题已经看清楚了,不用再多赘述。然而项目最终目的是,使用树莓派GPU在树莓派上完成H264异构实时编码,并且通过TCP、802.11n协议,将码流实时传输到Android移动端,然后再使用Android的GPU完成实时的解码,就是这么简单。

一、各模块组件

clavesScreenShot_20160228_171459

各个模块如上图所示。

1、Vmware Player 虚拟机网卡设置

clavesScreenShot_20160228_165912

为了让虚拟机中的Ubuntu系统与树莓派、手机等设备处于同一子网,固将Vmware Play中网络适配器设置为“桥接模式”,并且设置桥接设配器为PC机网线网卡。

2、确认Ubuntu、树莓派处于同一子网

ifconfig

clavesScreenShot_20160228_170330

clavesScreenShot_20160228_170404

如上图所示,Ubuntu和Raspberry 处于192.168.100.* 同一子网中。

3、在路由器DHCP中绑定MAC IP地址

clavesScreenShot_20160228_170754

一、树莓派Raspbian内核编译

为什么想要编译内核?

因为我觉得提前编译内核能为以后省略不少麻烦,而且编译内核也很快。

参考链接:https://www.raspberrypi.org/documentation/linux/kernel/building.md

Tip1: 我的开发板是Raspberry 2B,性能还不错,所以就直接在开发板上完成内核编译的。

Tip2:由于树莓派CPU是多核的,因此在编译的时候可以使用-j4指令,便于发挥多核优势。

例如:

make -j4 zImage modules dtbs

二、交叉编译环境搭建

1、NFS网络存储

优势:NFS可以使UNIX机器共享网络存储空间,并且能够实时同步。

在Ubuntu和Raspberry之间搭建NFS网络存储,可以很方便的完成源代码、可执行文件共享,而不用频繁使用FTP传输。

1.1 Ubuntu 安装NFS server 软件

sudo apt-get install portmap
sudo apt-get install nfs-kernel-server

1.2 Raspberry 安装NFS client 软件

sudo apt-get install nfs-common

1.3 Ubuntu 配置并开启NFS服务

创建共享文件夹:

mkdir /home/clave/projects

编辑配置文件:

sudo vim /etc/exports

在文件末尾添加:

/home/clave/projects *(rw,sync,no_root_squash,no_subtree_check)
  • 表示允许所有IP段
  • rw权限是可擦写
  • sync代表数据会同步写入到内存与硬盘

开启NFS server服务:

sudo /etc/init.d/portmap restart
sudo /etc/init.d/nfs-kernel-server restart

1.4 Raspberry 挂载网络磁盘

创建同步文件夹:

mkdir /home/pi/projects

挂载网络磁盘:

sudo mount -t nfs 192.168.100.110:/home/clave/projects/ /home/pi/projects

1.5检测是否可以同步

成功同步

2、在Ubuntu上搭建交叉编译环境

2.1下载必要工具

sudo apt-get install build-essential git

2.2创建交叉编译工具所在文件夹

mkdir $HOME/pitools

进入:

cd $HOME/pitools

克隆交叉工具链:

git clone git://github.com/raspberrypi/tools.git

2.3 本地环境变量配置

交叉工具链中有多种交叉编译工具,由于Ubuntu为32位,且Raspberry Pi系统为Raspbian,所以我选择“gcc-linaro-arm-linux-gnueabihf-raspbian”这个工具。

在/.bashrc文件中加入gcc交叉工具链目录

sudo vim ~/.bashrc

在最后一行加入:

export PATH=$PATH:$HOME/pitools/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin

更新环境变量:

source ~/.bashrc

2.4 交叉编译工具测试:

arm-linux-gnueabihf-gcc -v

如果输出交叉编译工具版本号,则配置成功。

三、Ubuntu 开发IDE Qt creator 配置

个人比较喜欢Qt creator这款IDE。跨平台、易设置、UI友好、配色不错。

3.1 安装Qt creator :

arm-linux-gnueabihf-gcc -v

3.2 打开Qt creator 并添加Raspberry。

菜单:Tools->Options

添加交叉编译工具,如图:

clavesScreenShot_20160228_174558

添加Raspberrry设备,如图:

clavesScreenShot_20160228_174726

为Raspberry添加编译工具:

clavesScreenShot_20160228_174806

3.3 创建项目:

clavesScreenShot_20160228_175106

clavesScreenShot_20160228_175203

clavesScreenShot_20160228_175239

CMakeLists.txt 末尾添加:

SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_C_COMPILER /home/clave/pitools/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER /home/clave/pitools/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++)



编译:clavesScreenShot_20160228_175431

在Raspberry尝试运行:

clavesScreenShot_20160228_175557

即,成功运行~