全面认识海思SDK及嵌入式层开发(4)

一、mpp的部署研究和实战

海思MPP参考学习:https://blog.csdn.net/flaoter/article/details/92402685

  海思提供的媒体处理软件平台(Media Process Platform,简称 MPP),可支持应用软件快速开发。该平台对应用软件屏蔽了芯片相关的复杂的底层处理,并对应用软件直接提供MPI(MPP Program Interface)接口完成相应功能。该平台支持应用软件快速开发以下功能:输入视频捕获、 H.265/H.264/JPEG 编码、 H.265/H.264/JPEG 解码、 视频输出显示、视频图像前处理(包括去噪、增强、锐化)、 图像拼接、 图像几何矫正、智能、音频捕获及输出、音频编解码等功能。

1、mpp的文件结构详解

在这里插入图片描述
(1)ko
在这里插入图片描述
.ko海思预先编译好的一些模块文件,并非完全开源。我们来分析下load3518e文件:
在这里插入图片描述
将所有的模块先全部卸载,再全部装载,确保可以正常工作。默认支持一些的sensor,每种sensor在工作之前,都要进行一定的初始化。
在这里插入图片描述
在这里插入图片描述

# load3518e文件开头部分
SNS_TYPE=ar0230             # sensor type

mem_total=64;               # 64M, total mem
mem_start=0x80000000;       # phy mem start

os_mem_size=32;             # 32M, os mem
mmz_start=0x82000000;       # mmz start addr
mmz_size=32M;               # 32M, mmz size

# load3518e文件中间部分
insert_ko()
{
	# sys config
	sys_config;

	# driver load
	# mmz.ko内存管理模块,从芯片内部自带的64M内存中分出一部分用于mpp,即mmz
	# $mmz_start,$mmz_size是mpp所用内存的范围
	insmod mmz.ko mmz=anonymous,0,$mmz_start,$mmz_size anony=1 || report_error
	insmod hi_media.ko
	insmod hi3518e_base.ko

	insmod hi3518e_sys.ko vi_vpss_online=$b_arg_online sensor=$SNS_TYPE
	if [[ $? -ne 0 ]]; then 
		exit;
	fi  

	insmod hi3518e_tde.ko
	insmod hi3518e_region.ko
	insmod hi3518e_vgs.ko

	insert_isp;
	insmod hi3518e_viu.ko detect_err_frame=10;
	insmod hi3518e_vpss.ko rfr_frame_comp=1;
	insmod hi3518e_vou.ko
	#insmod hi3518e_vou.ko transparentTransmit=1 #enable transparentTransmit
	insmod hifb.ko video="hifb:vram0_size:1620"     # default pal

	insmod hi3518e_rc.ko
	insmod hi3518e_venc.ko 
	insmod hi3518e_chnl.ko ChnlLowPower=1
	insmod hi3518e_h264e.ko
	insmod hi3518e_jpege.ko
	insmod hi3518e_ive.ko save_power=0;
#	insmod hi3518e_ive.ko	
	insmod extdrv/sensor_i2c.ko
	echo "==== Your input Sensor type is $SNS_TYPE ===="
	insmod extdrv/pwm.ko
	insmod extdrv/piris.ko

	#insert_sns > /dev/null
	insert_sns
	insert_audio

	insmod hi_mipi.ko
	echo "==== Your input Sensor type is $SNS_TYPE ===="
}

(2)lib
静态库、动态库文件,我们不一定全都会用到,将来为了节约根文件系统的空间,可以适当删除。

(3)sample
官方提供的示例代码

(4)Makefile.param:Makefile的参数文件

(5)其他几个文件夹,tools文件夹包含一些工具代码。exdrv文件夹包含一些外部设备的驱动(hi3518e芯片外部对接并使用的设备)。ko文件夹中包含内部设备的驱动。
在这里插入图片描述
我们重点关注ko和lib文件夹,因为其需要我们进行部署。

2、开发板启动挂载主机

(1)在profile文件的末尾添加设置网卡IP地址

ifconfig lo 127.0.0.1                                                           
ifconfig eth0 192.168.1.10 

(2)开发板启动后挂载主机nfs服务器

sudo showmount -e # 查看nfs服务器设置的挂载目录
mount -t nfs -o nolock 192.168.1.141:/home/aston/rootfs /mnt

3、部署ko文件

ubuntu端执行:
cp ko lib ~/rootfs/ -rf

开发板端执行:
cp /mnt/ko / -rf
cp /mnt/lib/* /usr/lib/ -rf

修改profile文件,末尾添加:
cd /ko
./load3518e -i -sensor ar0130 -osmem 32 -total 64
cd /mnt

-i:执行insert_ko()函数 
-sensor:指定那个sensor
-osmem:操作系统占用的内存
-total:芯片内部内置的SDRAM大小
mmz = total-osmem

在这里插入图片描述

4、部署lib文件

SDRAM范围:80000000-83FFFFFF
linux内存:0x80000000-0x81FFFFFF	
MMZ内存:0x82000000-0x83FFFFFF

上边3中已经进行过了,我们不需要再次操作了:
Ubuntu中:
cp ko lib ~/rootfs/ -rf

开发板中:
cp /mnt/lib/* /usr/lib/ -rf

二、sample的编译和测试

在这里插入图片描述
每个文件夹是一个分支,演示一个不同的功能,sample/venc/sample_venc.c实现了将视频采集并编码成一个H.264的码流,并将其保存在本地,可以使用VLC播放器查看。其他文件夹中的文件编译时都会用到common文件夹中的文件。

1、sample的编译

(1)sample结构简单浏览
(2)Makefile研究
(3)编译得到sample_venc

我们可以参考阅读:sample/readme文件了解如何去编译。

2. Compilation and Makefile
   1) Compilation dependency descriptions
   The compilation of the sample programs depends on MPP header files in /mpp/include and library files in mpp/lib.
   
   2) Makefile descriptions    
   A Makefile is available on each service sample demo module (such as the vio and venc). The Makefile quotes the Makefile.param file in the sample directory, and this file quotes the Makefile.param file in the mpp directory.
   mpp -- Makefile.param                 # Defines the variables required by the MPP compilation.
    |---sample---Makefile.param          # Defines the variables required by the sample compilation.
          |--- vio/venc/...---Makefile   # Sample compilation script

   Run the make command on each service sample demo module to compile the module; run the make clean command to delete the executable files and target files after compilation; run the make cleanstream command to delete stream files generated after some of the sample programs run. 

   Run the make command in the sample directory to compile various service sample demo programs; run the make clean command to delete the executable files and target files after all service sample demo programs are compiled; run the make cleanall command to delete stream files generated after all service sample demo programs run.

3. Running Descriptions of Sample Programs
   1) Sample program running depends on the media driver. Before running a sample demo program, execute the load3518e script in the mpp/ko to load a specified module.
   
   2) Note that the corresponding sensor library must be selected. The default sensor is Sony IMX122. If you want to select other sensors, modify the Makefile.param file. For example, if you select Sony IMX104, you should modify the Makefile.param file as follows:
   		#SENSOR_TYPE ?= APTINA_AR0130_DC_720P_30FPS
	 	SENSOR_TYPE ?= SONY_IMX122_DC_1080P_30FPS		

有道翻译翻译的比较蹩脚,凑活看:
2. 编译和Makefile
1)编译依赖描述
样例程序的编译依赖于/ MPP /include中的MPP头文件和MPP /lib中的库文件。
   
2) Makefile的描述
每个服务示例演示模块(例如vio和venc)上都有一个Makefile。Makefile引用Makefile。param文件,该文件引用Makefile。MPP目录下的Param文件。
mpp——Makefile。param #定义MPP编译所需的变量。
| -样品- Makefile。param #定义示例编译所需的变量。
          |--- vio venc /…——Makefile #示例编译脚本

在每个服务样例演示模块上运行make命令编译模块;运行make clean命令删除编译后的可执行文件和目标文件;执行make cleanstream命令删除部分样例程序运行后生成的流文件。

在sample目录下运行make命令,编译各种服务样例演示程序;在所有服务样例演示程序编译完成后,运行make clean命令删除可执行文件和目标文件;执行命令make cleanall,删除所有服务样例演示程序运行后生成的流文件。

3.示例程序的运行描述
1)样例程序的运行取决于媒体驱动程序。在运行示例演示程序之前,请执行mpp/ko中的load3518e脚本来加载指定的模块。
   
2)注意必须选择相应的传感器库。默认的传感器是索尼IMX122。如果要选择其他传感器,请修改Makefile的参数文件。例如,如果您选择Sony IMX104,那么您应该修改Makefile。参数文件如下:
# SENSOR_TYPE ? = APTINA_AR0130_DC_720P_30FPS
SENSOR_TYPE ? = SONY_IMX122_DC_1080P_30FPS 
修改sample目录下的Makefile.param:vi Makefile.param

在这里插入图片描述

cd venc
make
cp sample_venc ~/rootfs/ -f

在这里插入图片描述
动态链接生成的一个程序。

2、sample的部署和测试

(1)nfs方式运行sample
(2)得到录像文件xx.h264
(3)导出xx.h264到windows下用vlc播放器播放验证

./sample_venc 0
c
连续按两次ENTER键结束程序运行

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
得到了三个通道的视频,这三个视频内容是一样的,只不过格式和参数有区别。把这几个码流放到Windows中使用VLC播放器进行查看。

3、镜像重新制作

(1)在编译目录的osdev/pub/下找到rootfs_uclibc.tgz,解压开

(2)按照本篇文章验证成功的部署步骤部署整个rootfs

  部署ko、lib,修改/etc/profile文件

(3)将解压后的根文件系统修改完成后,手工制作rootfs.jffs2镜像,再烧录测试即可

osdrv/pub/bin/pc/mkfs.jffs2 -d osdrv/pub/rootfs_uclibc -l -e 0x10000 -o osdrv/pub/rootfs_uclibc_64k.jffs2

4、最后的总结

(1)第1季结束,主要内容是海思SDK的熟悉和编译、部署实战
(2)目录要多翻,简单pdf文档要多看,概念要不断熟悉,熟能生巧,面试时也方便充经验
(3)重实战,不要只看文章不动手

注:本资料大部分由朱老师物联网大讲堂课程笔记整理而来并且引用了部分他人博客的内容,如有侵权,联系删除!水平有限,如有错误,欢迎各位在评论区交流。

  • 5
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小嵌同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值