RV1106G2 双目杂记

内容分享5天前发布
0 0 0

1、lunch

Z:Precision_LandingRV1106_RV1103_LINUX_IPCprojectcfgBoardConfig_IPCBoardConfig-SPI_NOR-NONE-RV1106_IPC38_DEMO_V10-IPC.mk

/home/wzh/work/Precision_Landing/RV1106_RV1103_LINUX_IPC/project/cfg/BoardConfig_IPC/BoardConfig-SPI_NOR-NONE-RV1106_IPC38_DEMO_V10-IPC.mk

2、telnet

root solokey

3、USB无法烧录

换根短的线就ok了

4、sensor驱动

在sysdrv/source/kernel/drivers/media/i2c/mis20s11.c

5、DPHY与CPHY

RV1106G2 双目杂记


6、media-ctl和v4l2-ctl工具在RV1105平台怎么编译出来调试使用?

直接解压media/libv4l/下的v4l-utils-1.16.5-arm-rockchip830-linux-uclibcgnueabihf.tar.bz2然后拷贝到对应目录

    cp -f /home/wzh/work/Precision_Landing/RV1106_RV1103_LINUX_IPC/media/libv4l/v4l-utils-1.16.5-arm-rockchip830-linux-uclibcgnueabihf/root/usr/bin/* ../../../../output/out/oem/usr/bin/
    cp -rf /home/wzh/work/Precision_Landing/RV1106_RV1103_LINUX_IPC/media/libv4l/v4l-utils-1.16.5-arm-rockchip830-linux-uclibcgnueabihf/root/usr/lib/* ../../../../output/out/oem/usr/lib/

7、使用nc命令在机器和Windows之间传输文件

机器端:   nc 192.168.144.234 8210 < /tmp/isp_yuv32.nv12 
windows端:nc -l -p 8210 > isp_yuv32.nv12 

8、media-ctl -p -d /dev/media0



# media-ctl -p -d /dev/media0
Media controller API version 5.10.160
​
Media device information
------------------------
driver          rkcif
model           rkcif-mipi-lvds
serial          
bus info        
hw revision     0x0
driver version  5.10.160
​
Device topology
- entity 1: stream_cif_mipi_id0 (1 pad, 11 links)
            type Node subtype V4L flags 0
            device node name /dev/video0
        pad0: Sink
                <- "rockchip-mipi-csi2":1 [ENABLED]
                <- "rockchip-mipi-csi2":2 []
                <- "rockchip-mipi-csi2":3 []
                <- "rockchip-mipi-csi2":4 []
                <- "rockchip-mipi-csi2":5 []
                <- "rockchip-mipi-csi2":6 []
                <- "rockchip-mipi-csi2":7 []
                <- "rockchip-mipi-csi2":8 []
                <- "rockchip-mipi-csi2":9 []
                <- "rockchip-mipi-csi2":10 []
                <- "rockchip-mipi-csi2":11 []
​
- entity 5: stream_cif_mipi_id1 (1 pad, 11 links)
            type Node subtype V4L flags 0
            device node name /dev/video1
        pad0: Sink
                <- "rockchip-mipi-csi2":1 []
                <- "rockchip-mipi-csi2":2 [ENABLED]
                <- "rockchip-mipi-csi2":3 []
                <- "rockchip-mipi-csi2":4 []
                <- "rockchip-mipi-csi2":5 []
                <- "rockchip-mipi-csi2":6 []
                <- "rockchip-mipi-csi2":7 []
                <- "rockchip-mipi-csi2":8 []
                <- "rockchip-mipi-csi2":9 []
                <- "rockchip-mipi-csi2":10 []
                <- "rockchip-mipi-csi2":11 []
​
- entity 9: stream_cif_mipi_id2 (1 pad, 11 links)
            type Node subtype V4L flags 0
            device node name /dev/video2
        pad0: Sink
                <- "rockchip-mipi-csi2":1 []
                <- "rockchip-mipi-csi2":2 []
                <- "rockchip-mipi-csi2":3 [ENABLED]
                <- "rockchip-mipi-csi2":4 []
                <- "rockchip-mipi-csi2":5 []
                <- "rockchip-mipi-csi2":6 []
                <- "rockchip-mipi-csi2":7 []
                <- "rockchip-mipi-csi2":8 []
                <- "rockchip-mipi-csi2":9 []
                <- "rockchip-mipi-csi2":10 []
                <- "rockchip-mipi-csi2":11 []
​
- entity 13: stream_cif_mipi_id3 (1 pad, 11 links)
             type Node subtype V4L flags 0
             device node name /dev/video3
        pad0: Sink
                <- "rockchip-mipi-csi2":1 []
                <- "rockchip-mipi-csi2":2 []
                <- "rockchip-mipi-csi2":3 []
                <- "rockchip-mipi-csi2":4 [ENABLED]
                <- "rockchip-mipi-csi2":5 []
                <- "rockchip-mipi-csi2":6 []
                <- "rockchip-mipi-csi2":7 []
                <- "rockchip-mipi-csi2":8 []
                <- "rockchip-mipi-csi2":9 []
                <- "rockchip-mipi-csi2":10 []
                <- "rockchip-mipi-csi2":11 []
​
- entity 17: rkcif_scale_ch0 (1 pad, 11 links)
             type Node subtype V4L flags 0
             device node name /dev/video4
        pad0: Sink
                <- "rockchip-mipi-csi2":1 []
                <- "rockchip-mipi-csi2":2 []
                <- "rockchip-mipi-csi2":3 []
                <- "rockchip-mipi-csi2":4 []
                <- "rockchip-mipi-csi2":5 [ENABLED]
                <- "rockchip-mipi-csi2":6 []
                <- "rockchip-mipi-csi2":7 []
                <- "rockchip-mipi-csi2":8 []
                <- "rockchip-mipi-csi2":9 []
                <- "rockchip-mipi-csi2":10 []
                <- "rockchip-mipi-csi2":11 []
​
- entity 21: rkcif_scale_ch1 (1 pad, 11 links)
             type Node subtype V4L flags 0
             device node name /dev/video5
        pad0: Sink
                <- "rockchip-mipi-csi2":1 []
                <- "rockchip-mipi-csi2":2 []
                <- "rockchip-mipi-csi2":3 []
                <- "rockchip-mipi-csi2":4 []
                <- "rockchip-mipi-csi2":5 []
                <- "rockchip-mipi-csi2":6 [ENABLED]
                <- "rockchip-mipi-csi2":7 []
                <- "rockchip-mipi-csi2":8 []
                <- "rockchip-mipi-csi2":9 []
                <- "rockchip-mipi-csi2":10 []
                <- "rockchip-mipi-csi2":11 []
​
- entity 25: rkcif_scale_ch2 (1 pad, 11 links)
             type Node subtype V4L flags 0
             device node name /dev/video6
        pad0: Sink
                <- "rockchip-mipi-csi2":1 []
                <- "rockchip-mipi-csi2":2 []
                <- "rockchip-mipi-csi2":3 []
                <- "rockchip-mipi-csi2":4 []
                <- "rockchip-mipi-csi2":5 []
                <- "rockchip-mipi-csi2":6 []
                <- "rockchip-mipi-csi2":7 [ENABLED]
                <- "rockchip-mipi-csi2":8 []
                <- "rockchip-mipi-csi2":9 []
                <- "rockchip-mipi-csi2":10 []
                <- "rockchip-mipi-csi2":11 []
​
- entity 29: rkcif_scale_ch3 (1 pad, 11 links)
             type Node subtype V4L flags 0
             device node name /dev/video7
        pad0: Sink
                <- "rockchip-mipi-csi2":1 []
                <- "rockchip-mipi-csi2":2 []
                <- "rockchip-mipi-csi2":3 []
                <- "rockchip-mipi-csi2":4 []
                <- "rockchip-mipi-csi2":5 []
                <- "rockchip-mipi-csi2":6 []
                <- "rockchip-mipi-csi2":7 []
                <- "rockchip-mipi-csi2":8 [ENABLED]
                <- "rockchip-mipi-csi2":9 []
                <- "rockchip-mipi-csi2":10 []
                <- "rockchip-mipi-csi2":11 []
​
- entity 33: rkcif_tools_id0 (1 pad, 11 links)
             type Node subtype V4L flags 0
             device node name /dev/video8
        pad0: Sink
                <- "rockchip-mipi-csi2":1 []
                <- "rockchip-mipi-csi2":2 []
                <- "rockchip-mipi-csi2":3 []
                <- "rockchip-mipi-csi2":4 []
                <- "rockchip-mipi-csi2":5 []
                <- "rockchip-mipi-csi2":6 []
                <- "rockchip-mipi-csi2":7 []
                <- "rockchip-mipi-csi2":8 []
                <- "rockchip-mipi-csi2":9 [ENABLED]
                <- "rockchip-mipi-csi2":10 []
                <- "rockchip-mipi-csi2":11 []
​
- entity 37: rkcif_tools_id1 (1 pad, 11 links)
             type Node subtype V4L flags 0
             device node name /dev/video9
        pad0: Sink
                <- "rockchip-mipi-csi2":1 []
                <- "rockchip-mipi-csi2":2 []
                <- "rockchip-mipi-csi2":3 []
                <- "rockchip-mipi-csi2":4 []
                <- "rockchip-mipi-csi2":5 []
                <- "rockchip-mipi-csi2":6 []
                <- "rockchip-mipi-csi2":7 []
                <- "rockchip-mipi-csi2":8 []
                <- "rockchip-mipi-csi2":9 []
                <- "rockchip-mipi-csi2":10 [ENABLED]
                <- "rockchip-mipi-csi2":11 []
​
- entity 41: rkcif_tools_id2 (1 pad, 11 links)
             type Node subtype V4L flags 0
             device node name /dev/video10
        pad0: Sink
                <- "rockchip-mipi-csi2":1 []
                <- "rockchip-mipi-csi2":2 []
                <- "rockchip-mipi-csi2":3 []
                <- "rockchip-mipi-csi2":4 []
                <- "rockchip-mipi-csi2":5 []
                <- "rockchip-mipi-csi2":6 []
                <- "rockchip-mipi-csi2":7 []
                <- "rockchip-mipi-csi2":8 []
                <- "rockchip-mipi-csi2":9 []
                <- "rockchip-mipi-csi2":10 []
                <- "rockchip-mipi-csi2":11 [ENABLED]
​
- entity 45: rockchip-mipi-csi2 (12 pads, 122 links)
             type V4L2 subdev subtype Unknown flags 0
             device node name /dev/v4l-subdev0
        pad0: Sink
                [fmt:SGRBG12_1X12/1920x1080 field:none
                 crop.bounds:(0,0)/1920x1080
                 crop:(0,0)/1920x1080]
                <- "rockchip-csi2-dphy1":1 [ENABLED]
        pad1: Source
                -> "stream_cif_mipi_id0":0 [ENABLED]
                -> "stream_cif_mipi_id1":0 []
                -> "stream_cif_mipi_id2":0 []
                -> "stream_cif_mipi_id3":0 []
                -> "rkcif_scale_ch0":0 []
                -> "rkcif_scale_ch1":0 []
                -> "rkcif_scale_ch2":0 []
                -> "rkcif_scale_ch3":0 []
                -> "rkcif_tools_id0":0 []
                -> "rkcif_tools_id1":0 []
                -> "rkcif_tools_id2":0 []
        pad2: Source
                -> "stream_cif_mipi_id0":0 []
                -> "stream_cif_mipi_id1":0 [ENABLED]
                -> "stream_cif_mipi_id2":0 []
                -> "stream_cif_mipi_id3":0 []
                -> "rkcif_scale_ch0":0 []
                -> "rkcif_scale_ch1":0 []
                -> "rkcif_scale_ch2":0 []
                -> "rkcif_scale_ch3":0 []
                -> "rkcif_tools_id0":0 []
                -> "rkcif_tools_id1":0 []
                -> "rkcif_tools_id2":0 []
        pad3: Source
                -> "stream_cif_mipi_id0":0 []
                -> "stream_cif_mipi_id1":0 []
                -> "stream_cif_mipi_id2":0 [ENABLED]
                -> "stream_cif_mipi_id3":0 []
                -> "rkcif_scale_ch0":0 []
                -> "rkcif_scale_ch1":0 []
                -> "rkcif_scale_ch2":0 []
                -> "rkcif_scale_ch3":0 []
                -> "rkcif_tools_id0":0 []
                -> "rkcif_tools_id1":0 []
                -> "rkcif_tools_id2":0 []
        pad4: Source
                -> "stream_cif_mipi_id0":0 []
                -> "stream_cif_mipi_id1":0 []
                -> "stream_cif_mipi_id2":0 []
                -> "stream_cif_mipi_id3":0 [ENABLED]
                -> "rkcif_scale_ch0":0 []
                -> "rkcif_scale_ch1":0 []
                -> "rkcif_scale_ch2":0 []
                -> "rkcif_scale_ch3":0 []
                -> "rkcif_tools_id0":0 []
                -> "rkcif_tools_id1":0 []
                -> "rkcif_tools_id2":0 []
        pad5: Source
                -> "stream_cif_mipi_id0":0 []
                -> "stream_cif_mipi_id1":0 []
                -> "stream_cif_mipi_id2":0 []
                -> "stream_cif_mipi_id3":0 []
                -> "rkcif_scale_ch0":0 [ENABLED]
                -> "rkcif_scale_ch1":0 []
                -> "rkcif_scale_ch2":0 []
                -> "rkcif_scale_ch3":0 []
                -> "rkcif_tools_id0":0 []
                -> "rkcif_tools_id1":0 []
                -> "rkcif_tools_id2":0 []
        pad6: Source
                -> "stream_cif_mipi_id0":0 []
                -> "stream_cif_mipi_id1":0 []
                -> "stream_cif_mipi_id2":0 []
                -> "stream_cif_mipi_id3":0 []
                -> "rkcif_scale_ch0":0 []
                -> "rkcif_scale_ch1":0 [ENABLED]
                -> "rkcif_scale_ch2":0 []
                -> "rkcif_scale_ch3":0 []
                -> "rkcif_tools_id0":0 []
                -> "rkcif_tools_id1":0 []
                -> "rkcif_tools_id2":0 []
        pad7: Source
                -> "stream_cif_mipi_id0":0 []
                -> "stream_cif_mipi_id1":0 []
                -> "stream_cif_mipi_id2":0 []
                -> "stream_cif_mipi_id3":0 []
                -> "rkcif_scale_ch0":0 []
                -> "rkcif_scale_ch1":0 []
                -> "rkcif_scale_ch2":0 [ENABLED]
                -> "rkcif_scale_ch3":0 []
                -> "rkcif_tools_id0":0 []
                -> "rkcif_tools_id1":0 []
                -> "rkcif_tools_id2":0 []
        pad8: Source
                -> "stream_cif_mipi_id0":0 []
                -> "stream_cif_mipi_id1":0 []
                -> "stream_cif_mipi_id2":0 []
                -> "stream_cif_mipi_id3":0 []
                -> "rkcif_scale_ch0":0 []
                -> "rkcif_scale_ch1":0 []
                -> "rkcif_scale_ch2":0 []
                -> "rkcif_scale_ch3":0 [ENABLED]
                -> "rkcif_tools_id0":0 []
                -> "rkcif_tools_id1":0 []
                -> "rkcif_tools_id2":0 []
        pad9: Source
                -> "stream_cif_mipi_id0":0 []
                -> "stream_cif_mipi_id1":0 []
                -> "stream_cif_mipi_id2":0 []
                -> "stream_cif_mipi_id3":0 []
                -> "rkcif_scale_ch0":0 []
                -> "rkcif_scale_ch1":0 []
                -> "rkcif_scale_ch2":0 []
                -> "rkcif_scale_ch3":0 []
                -> "rkcif_tools_id0":0 [ENABLED]
                -> "rkcif_tools_id1":0 []
                -> "rkcif_tools_id2":0 []
        pad10: Source
                -> "stream_cif_mipi_id0":0 []
                -> "stream_cif_mipi_id1":0 []
                -> "stream_cif_mipi_id2":0 []
                -> "stream_cif_mipi_id3":0 []
                -> "rkcif_scale_ch0":0 []
                -> "rkcif_scale_ch1":0 []
                -> "rkcif_scale_ch2":0 []
                -> "rkcif_scale_ch3":0 []
                -> "rkcif_tools_id0":0 []
                -> "rkcif_tools_id1":0 [ENABLED]
                -> "rkcif_tools_id2":0 []
        pad11: Source
                -> "stream_cif_mipi_id0":0 []
                -> "stream_cif_mipi_id1":0 []
                -> "stream_cif_mipi_id2":0 []
                -> "stream_cif_mipi_id3":0 []
                -> "rkcif_scale_ch0":0 []
                -> "rkcif_scale_ch1":0 []
                -> "rkcif_scale_ch2":0 []
                -> "rkcif_scale_ch3":0 []
                -> "rkcif_tools_id0":0 []
                -> "rkcif_tools_id1":0 []
                -> "rkcif_tools_id2":0 [ENABLED]
​
- entity 58: rockchip-csi2-dphy1 (2 pads, 2 links)
             type V4L2 subdev subtype Unknown flags 0
             device node name /dev/v4l-subdev1
        pad0: Sink
                [fmt:SGRBG12_1X12/1920x1080@10000/300000 field:none]
                <- "m00_b_mis20s10 4-0030":0 [ENABLED]
        pad1: Source
                -> "rockchip-mipi-csi2":0 [ENABLED]
​
- entity 63: m00_b_mis20s10 4-0030 (1 pad, 1 link)
             type V4L2 subdev subtype Sensor flags 0
             device node name /dev/v4l-subdev2
        pad0: Source
                [fmt:SGRBG12_1X12/1920x1080@10000/300000 field:none]
                -> "rockchip-csi2-dphy1":0 [ENABLED]
​
# 

9、原理图



sensor0用i2c4:
 
/omit-if-no-ref/
        i2c4m2_xfer: i2c4m2-xfer {
            rockchip,pins =
                /* i2c4_scl_m2 */
                <3 RK_PC7 3 &pcfg_pull_none_smt>,
                /* i2c4_sda_m2 */
                <3 RK_PD0 3 &pcfg_pull_none_smt>;
        };
sensor1用i2c1:
 
    /omit-if-no-ref/
    i2c1m1_xfer: i2c1m1-xfer {
        rockchip,pins =
            /* i2c1_scl_m1 */
            <2 RK_PB0 2 &pcfg_pull_none_smt>,
            /* i2c1_sda_m1 */
            <2 RK_PB1 2 &pcfg_pull_none_smt>;
    };

10、使用i2cdetect查看sensor是否在线



 
# i2cdetect -y 4
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
# 
# 
# i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
# 

sensor2做主机可以检测到

11、开机启动脚本

Z:Precision_LandingRV1106_RV1103_LINUX_IPCprojectapp
kipc
kipcsrc
v1106_ipcRkLunch.sh

12、拓补结构

RV1106G2 双目杂记

MIPI-csi调试_mipidcphy0-CSDN博客

RV1106G2 双目杂记

RV1106G2 双目杂记

13、v4l2-ctl命令

抓YUV需要先跑rkaiq_3A_server & (跑命令前需要有对应的josn文件,没有对应的文件可以看后面章节怎么修

改一个出来)

然后 v4l2-ctl -d /dev/video22 –set-fmt-video=width=2688,height=1520,pixelformat=NV12 –stream

mmap=3 –stream-skip=30 –stream-to=/mnt/output.yuv –stream-count=1 –stream-poll

这样可以拿isp处理好效果的yuv文件。

可以用7yuv yuview等软件看图



# v4l2-ctl -d /dev/video11 --list-formats
[  193.506346] stream_cif_mipi_id0: open video, entity use_countt 1
ioctl: VIDIOC_ENUM_FMT
[  193.510661] stream_cif_mipi_id0: close video, entity use_count 0
        Type: Video Capture Multiplanar
​
        [0]: 'RG12' (12-bit Bayer RGRG/GBGB)
        [1]: 'BA12' (12-bit Bayer GRGR/BGBG)
        [2]: 'GB12' (12-bit Bayer GBGB/RGRG)
        [3]: 'BG12' (12-bit Bayer BGBG/GRGR)
        [4]: 'Y12 ' (12-bit Greyscale)
# 
# 抓取 Sensor0 的 RAW Bayer 数据



v4l2-ctl -d /dev/video0 
    --set-fmt-video=width=1920,height=1080,pixelformat=RG12 
    --stream-mmap 
    --stream-count=1 
    --stream-to=/tmp/sensor0_frame.raw


# 
# v4l2-ctl -d /dev/video22 --set-fmt-video=width=1920,height=1080,pixelformat=NV12 --stream-mmap --stream-count=1 --stream-to=/tmp/isp_yuv.nv12
[   26.057063] stream_cif_mipi_id0: s_power 1, entity use_count 1
[   26.066436] rkisp_hw ffa00000.rkisp: set isp clk = 198000000Hz
[   26.077134] rkcif-mipi-lvds: stream[0] start streaming
[   26.077250] rockchip-mipi-csi2 mipi0-csi2: stream on, src_sd: 421a7573, sd_name:rockchip-csi2-dphy1
[   26.077265] rockchip-mipi-csi2 mipi0-csi2: stream ON
[   26.077316] rockchip-csi2-dphy1: dphy1, data_rate_mbps 445
[   26.077350] rockchip-csi2-dphy csi2-dphy1: csi2_dphy_s_stream stream on:1, dphy1, ret 0
<[   26.316362] rkcif-mipi-lvds: stream[0] start stopping, total mode 0x2, cur 0x2
[   26.349646] rockchip-mipi-csi2 mipi0-csi2: stream off, src_sd: 421a7573, sd_name:rockchip-csi2-dphy1
[   26.349666] rockchip-mipi-csi2 mipi0-csi2: stream OFF
​
[   26.349693] rockchip-csi2-dphy csi2-dphy1: csi2_dphy_s_stream_stop stream stop, dphy1
# [   26.349711] rockchip-csi2-dphy csi2-dphy1: csi2_dphy_s_stream stream on:0, dphy1, ret 0
[   26.357063] rkcif-mipi-lvds: stream[0] stopping finished, dma_en 0x0
[   26.357079] rkcif-mipi-lvds: stream[0] start stopping, total mode 0x0, cur 0x2
[   26.357087] rkcif-mipi-lvds: stream[0] stopping finished, dma_en 0x0
[   26.361244] stream_cif_mipi_id0: s_power 0, entity use_count 0
​
# 
# 列出所有视频设备
v4l2-ctl --list-devices
# 检查 video22 设备能力(摄像头0主路径)
v4l2-ctl -d /dev/video22 --all
​
# 检查 video32 设备能力(摄像头1主路径)
v4l2-ctl -d /dev/video32 --all
​
查看路径
#  grep -H '' /sys/class/video4linux/video*/name
/sys/class/video4linux/video0/name:stream_cif_mipi_id0
/sys/class/video4linux/video1/name:stream_cif_mipi_id1
/sys/class/video4linux/video10/name:rkcif_tools_id2
/sys/class/video4linux/video11/name:stream_cif_mipi_id0
/sys/class/video4linux/video12/name:stream_cif_mipi_id1
/sys/class/video4linux/video13/name:stream_cif_mipi_id2
/sys/class/video4linux/video14/name:stream_cif_mipi_id3
/sys/class/video4linux/video15/name:rkcif_scale_ch0
/sys/class/video4linux/video16/name:rkcif_scale_ch1
/sys/class/video4linux/video17/name:rkcif_scale_ch2
/sys/class/video4linux/video18/name:rkcif_scale_ch3
/sys/class/video4linux/video19/name:rkcif_tools_id0
/sys/class/video4linux/video2/name:stream_cif_mipi_id2
/sys/class/video4linux/video20/name:rkcif_tools_id1
/sys/class/video4linux/video21/name:rkcif_tools_id2
/sys/class/video4linux/video22/name:rkisp_mainpath
/sys/class/video4linux/video23/name:rkisp_selfpath
/sys/class/video4linux/video24/name:rkisp_bypasspath
/sys/class/video4linux/video25/name:rkisp_mainpath_4x4sampling
/sys/class/video4linux/video26/name:rkisp_bypasspath_4x4sampling
/sys/class/video4linux/video27/name:rkisp_lumapath
/sys/class/video4linux/video28/name:rkisp_rawrd0_m
/sys/class/video4linux/video29/name:rkisp_rawrd2_s
/sys/class/video4linux/video3/name:stream_cif_mipi_id3
/sys/class/video4linux/video30/name:rkisp-statistics
/sys/class/video4linux/video31/name:rkisp-input-params
/sys/class/video4linux/video32/name:rkisp_mainpath
/sys/class/video4linux/video33/name:rkisp_selfpath
/sys/class/video4linux/video34/name:rkisp_bypasspath
/sys/class/video4linux/video35/name:rkisp_mainpath_4x4sampling
/sys/class/video4linux/video36/name:rkisp_bypasspath_4x4sampling
/sys/class/video4linux/video37/name:rkisp_lumapath
/sys/class/video4linux/video38/name:rkisp_rawrd0_m
/sys/class/video4linux/video39/name:rkisp_rawrd2_s
/sys/class/video4linux/video4/name:rkcif_scale_ch0
/sys/class/video4linux/video40/name:rkisp-statistics
/sys/class/video4linux/video41/name:rkisp-input-params
/sys/class/video4linux/video5/name:rkcif_scale_ch1
/sys/class/video4linux/video6/name:rkcif_scale_ch2
/sys/class/video4linux/video7/name:rkcif_scale_ch3
/sys/class/video4linux/video8/name:rkcif_tools_id0
/sys/class/video4linux/video9/name:rkcif_tools_id1
# 

14、iq文件路径

XCORE:E:access /etc/iqfiles/mis20s11_CMK-OT2115-PC1_30IRC-F16.json && /etc/iqfiles/mis20s11_CMK-OT2115-PC1_30IRC-F16.bin failed!
# ls -ll /etc/iqfiles
lrwxrwxrwx    1 1000     1000            24 /etc/iqfiles -> ../oem/usr/share/iqfiles

15、脚本rv1106-spi_nor-post.sh

project/cfg/BoardConfig_IPC/rv1106-spi_nor-post.sh

16、BoardConfig.mk添加配置拷⻉对应的Sensor IQ效果⽂件

export RK_CAMERA_SENSOR_IQFILES="sc530ai_CMK-OT2115-PC1_30IRC-F16.json"

iq文件则放在下面路径,编译后会自动拷贝到output/out/oem/usr/share/iqfiles/

media/isp/release_camera_engine_rkaiq_rv1106_arm-rockchip830-linux-uclibcgnueabihf/isp_iqfiles/mis20s1_CMK-OT2115-PC1_30IRC-F16.json

17、查看ISP是否工作

下面是rkisp-vir0正常工作 , rkisp-vir1异常



# cat /proc/rkisp-vir0
rkisp-vir0 Version:v02.05.00
clk_isp_core 198000000
aclk_isp   198000000
hclk_isp   148500000
clk_isp_core_vicap 0
Interrupt  Cnt:16032 ErrCnt:0
Input      rkcif-mipi-lvds Format:SGRBG12_1X12 Size:1920x1080@30fps Offset(0,0)
Isp Read   mode:frame1 (frame:8015 rate:99ms state:idle time:11ms frameloss:0) cnt(total:8015 X1:8015 X2:-1 X3:-1) rd_bufcnt:0
           hw link:2 idle:1 vir(mode:1 index:0)
Output     rkisp_mainpath Format:NV12 Size:1920x1080 Dcrop(0,0|1920x1080) (frame:8015 rate:100ms delay:44ms frameloss:0 bufcnt:2)
Output     rkisp_selfpath Format:NV12 Size:720x576 Dcrop(0,0|1920x1080) (frame:8015 rate:100ms delay:44ms frameloss:0 bufcnt:2)
ISP2ENC    offline warp:0
MIR_FLIP   mirror:0 flip(mp:0 sp:0 bp:0 mpds:0 bpds:0)
BAYNR      ON(0x10001)
GIC        ON(0x1)
CAC        OFF(0x0)
VSM        OFF(0x0)
SDG        OFF(0x6397)
AWBGAIN    ON(0x6397) (gain0:0x01000100 0x01000100 gain1:0x1110111 0x23401fa)
CMSK       OFF(0x0)
DPCC0      ON(0x5)
DPCC1      ON(0x5)
BLS        ON(0x31)
LSC        OFF(0x0)
DEBAYER    ON(0x101)
CCM        ON(0x1)
GAMMA_OUT  ON(0x5)
CPROC      ON(0xf)
IE         OFF(0x0) (effect: BLACKWHITE)
HDRDRC     ON(0x1)
HDRMGE     OFF(0x0)
BAY3D      ON(0x2001 0x289) bypass:0 bwsaving:1 mode:(lo4x8 sram)
YNR        ON(0x4001001)
CNR        ON(0x11)
SHARP      ON(0x21)
DHAZ       ON(0x16110011)
3DLUT      ON(0x1)
LDCH       OFF(0x0)
CSM        FULL(0x6397), y_offs:0x0 c_offs:0x80
           coeff Y:0x26 0x4b 0xf CB:0x1ea 0x1d6 0x40 CR:0x40 0x1ca 0x1f6
GAIN       ON(0x111011)
RAWAF      OFF(0x11007e)
RAWAWB     ON(0x1332e887)
RAWAE0     ON(0x3)
RAWAE1     ON(0xf5)
RAWAE3     ON(0xf5)
RAWHIST0   ON(0x501)
RAWHIST1   ON(0x20000501)
RAWHIST3   ON(0x20000501)
BigMode    ON(0x30000008)
OB         ON(0x100)
DEBUG1     space full status group (0xfccfffff)
           ibuf2:0xf ibuf1:0xc ibuf0:0xc mpfbc_infifo:0xf
           r1fifo:0xf r0fifo:0xf outfifo:0xf lafifo:0xf
DEBUG2     0x0
           bay3d_fifo_full iir:0 cur:0
           module outform vertical counter:0, out frame counter:0
           isp output line counter:0
DEBUG3     isp pipeline group (0x55555455)
           mge(0 1) rawnr(0 1) bay3d(0 1) tmo(0 1)
           gic(0 1) dbr(0 1) debayer(0 1) dhaz(0 1)
           lut3d(0 1) ldch(0 1) ynr(0 1) shp(0 0)
           cgc(0 1) cac(0 1) isp_out(0 1) isp_in(0 1)
DEBUG4     isp pipeline group (0x5)
           expd(0 1) ynr(0 1)
Monitor    OFF Cnt:0
​
Debug      mode:0x0
# 
# 
# cat /proc/rkisp-vir1
rkisp-vir1 Version:v02.05.00
clk_isp_core 198000000
aclk_isp   198000000
hclk_isp   148500000
clk_isp_core_vicap 0
Interrupt  Cnt:2 ErrCnt:0
Input      rkcif-mipi-lvds1 Format:SGRBG12_1X12 Size:1920x1080@30fps Offset(0,0)
# 
# 
# 

选择video22 取出isp流

            ctx->vi[i].s32DevId = 0; //sensor0
            ctx->vi[i].u32PipeId = 0;
            ctx->vi[i].s32ChnId = 0; //0是选择isp的video22节点 1是选择isp的video23节点

选择video32 取出isp流

            ctx->vi[i].s32DevId = 1; //sensor1
            ctx->vi[i].u32PipeId = 1;
            ctx->vi[i].s32ChnId = 0; //选择video32  如果是1则选择video33

RV1106G2 双目杂记

18、调试命令

1、查看vi 信息 dumpsys vi



# dumpsys vi
-------------------------------------------------------------------------------
DUMP OF SERVICE vi:
---------------------- vi module_param ----------------------------
vi_max_chn_num      
6                   
 
---------------------- vi chn attr ----------------------------
pipe  chn  width  height  max_width max_height  compress_mode  memory_type buf_type  pix_format    buf_cnt   buf_size  entity_name       
0     0    1920   1080    0         0           0              DMA         0         image:nv12    2         3133440   rkisp_mainpath    
 
           depth  src_frm_rate   dst_frm_rate   mirror  flip    cap_type  libv4l2  
           0      -1             -1             0       0       1         Used     
0     1    720    576     0         0           0              DMA         0         image:nv12    2         622080    rkisp_selfpath    
 
           depth  src_frm_rate   dst_frm_rate   mirror  flip    cap_type  libv4l2  
           0      -1             -1             0       0       1         Used     
 
1     0    1920   1080    0         0           0              DMA         0         image:nv12    2         3133440   rkisp_mainpath    
 
           depth  src_frm_rate   dst_frm_rate   mirror  flip    cap_type  libv4l2  
           0      -1             -1             0       0       1         Used     
1     1    720    576     0         0           0              DMA         0         image:nv12    2         622080    rkisp_selfpath    
 
           depth  src_frm_rate   dst_frm_rate   mirror  flip    cap_type  libv4l2  
           0      -1             -1             0       0       1         Used     
 
 
---------------------- vi chn query state ----------------------------
pipe  chn   width     height    enabled   in-lost  out-lost framerate vbfail    freeze    
0     0     1920      1080      1         0        2        0         0         0         
0     1     720       576       1         0        2        0         0         0         
1     0     1920      1080      1         0        2        0         0         0         
1     1     720       576       1         0        2        0         0         0         
 
---------------------- vi chn get buf state ----------------------------
pipe  chn   pts                     delay_us  get_cnt  release_cnt  commit_cnt  refs                
0     0     0                       459712996 0        0            0           0 0 0 0 0 0 0 0 
0     1     0                       459713048 0        0            0           0 0 0 0 0 0 0 0 
1     0     0                       459713100 0        0            0           0 0 0 0 0 0 0 0 
1     1     0                       459713139 0        0            0           0 0 0 0 0 0 0 0 
 
 
-------------------------------------------------------------------------------
END DUMP OF SERVICE vi:
# dumpsys vi
-------------------------------------------------------------------------------
DUMP OF SERVICE vi:
---------------------- vi module_param ----------------------------
vi_max_chn_num      
6                   
 
---------------------- vi chn attr ----------------------------
pipe  chn  width  height  max_width max_height  compress_mode  memory_type buf_type  pix_format    buf_cnt   buf_size  entity_name       
0     0    1920   1080    0         0           0              DMA         0         image:nv12    2         3133440   rkisp_mainpath    
 
           depth  src_frm_rate   dst_frm_rate   mirror  flip    cap_type  libv4l2  
           0      -1             -1             0       0       1         Used     
0     1    720    576     0         0           0              DMA         0         image:nv12    2         622080    rkisp_selfpath    
 
           depth  src_frm_rate   dst_frm_rate   mirror  flip    cap_type  libv4l2  
           0      -1             -1             0       0       1         Used     
 
1     0    1920   1080    0         0           0              DMA         0         image:nv12    2         3133440   rkisp_mainpath    
 
           depth  src_frm_rate   dst_frm_rate   mirror  flip    cap_type  libv4l2  
           0      -1             -1             0       0       1         Used     
1     1    720    576     0         0           0              DMA         0         image:nv12    2         622080    rkisp_selfpath    
 
           depth  src_frm_rate   dst_frm_rate   mirror  flip    cap_type  libv4l2  
           0      -1             -1             0       0       1         Used     
 
 
---------------------- vi chn query state ----------------------------
pipe  chn   width     height    enabled   in-lost  out-lost framerate vbfail    freeze    
0     0     1920      1080      1         0        2        0         0         0         
0     1     720       576       1         0        2        0         0         0         
1     0     1920      1080      1         0        2        0         0         0         
1     1     720       576       1         0        2        0         0         0         
 
---------------------- vi chn get buf state ----------------------------
pipe  chn   pts                     delay_us  get_cnt  release_cnt  commit_cnt  refs                
0     0     0                       460901056 0        0            0           0 0 0 0 0 0 0 0 
0     1     0                       460901114 0        0            0           0 0 0 0 0 0 0 0 
1     0     0                       460901171 0        0            0           0 0 0 0 0 0 0 0 
1     1     0                       460901215 0        0            0           0 0 0 0 0 0 0 0 
 
 
-------------------------------------------------------------------------------
END DUMP OF SERVICE vi:
# dumpsys vi
-------------------------------------------------------------------------------
DUMP OF SERVICE vi:
---------------------- vi module_param ----------------------------
vi_max_chn_num      
6                   
 
---------------------- vi chn attr ----------------------------
pipe  chn  width  height  max_width max_height  compress_mode  memory_type buf_type  pix_format    buf_cnt   buf_size  entity_name       
0     0    1920   1080    0         0           0              DMA         0         image:nv12    2         3133440   rkisp_mainpath    
 
           depth  src_frm_rate   dst_frm_rate   mirror  flip    cap_type  libv4l2  
           0      -1             -1             0       0       1         Used     
0     1    720    576     0         0           0              DMA         0         image:nv12    2         622080    rkisp_selfpath    
 
           depth  src_frm_rate   dst_frm_rate   mirror  flip    cap_type  libv4l2  
           0      -1             -1             0       0       1         Used     
 
1     0    1920   1080    0         0           0              DMA         0         image:nv12    2         3133440   rkisp_mainpath    
 
           depth  src_frm_rate   dst_frm_rate   mirror  flip    cap_type  libv4l2  
           0      -1             -1             0       0       1         Used     
1     1    720    576     0         0           0              DMA         0         image:nv12    2         622080    rkisp_selfpath    
 
           depth  src_frm_rate   dst_frm_rate   mirror  flip    cap_type  libv4l2  
           0      -1             -1             0       0       1         Used     
 
 
---------------------- vi chn query state ----------------------------
pipe  chn   width     height    enabled   in-lost  out-lost framerate vbfail    freeze    
0     0     1920      1080      1         0        2        0         0         0         
0     1     720       576       1         0        2        0         0         0         
1     0     1920      1080      1         0        2        0         0         0         
1     1     720       576       1         0        2        0         0         0         
 
---------------------- vi chn get buf state ----------------------------
pipe  chn   pts                     delay_us  get_cnt  release_cnt  commit_cnt  refs                
0     0     0                       461901144 0        0            0           0 0 0 0 0 0 0 0 
0     1     0                       461901213 0        0            0           0 0 0 0 0 0 0 0 
1     0     0                       461901264 0        0            0           0 0 0 0 0 0 0 0 
1     1     0                       461901309 0        0            0           0 0 0 0 0 0 0 0 
 
 
-------------------------------------------------------------------------------
END DUMP OF SERVICE vi:
# 

2、查看venc信息 dumpsys venc



# dumpsys venc
-------------------------------------------------------------------------------
DUMP OF SERVICE venc:
---------------------- venc module_param ----------------------------
venc_max_chn_num    buf_cache  frm_buf_cyc  264_one_pkt  265_one_pkt  jpeg_one_pkt  
64                  0          0            one          one          one           
​
---------------------- venc chn attr ----------------------------
id  width   height  vir_w   vir_h   codec_type  pix_format        buf_count  buf_size  rc_mode   gop_mode  gop     vir_idr_len  
0   1920    1080    1920    1080    12          image:nv12        3          3110400   H265CBR   NORMALP   50      0            
1   720     576     720     576     12          image:nv12        3          622080    H265CBR   NORMALP   50      0            
2   1920    1080    1920    1080    12          image:nv12        3          3110400   H265CBR   NORMALP   50      0            
3   720     576     720     576     12          image:nv12        3          622080    H265CBR   NORMALP   50      0            
​
---------------------- venc chn query stat ----------------------------
id  left_pics      left_strm_bytes     left_strm_frms      cur_packs      left_recv_pics      
0   0              0                   0                   0              0                   
1   0              0                   0                   0              0                   
2   0              0                   0                   0              0                   
3   0              0                   0                   0              0                   
​
---------------------- venc chn rc info1 ----------------------------
id  start_qp  step_qp  max_qp  min_qp  max_i_qp  min_i_qp  delt_ip_qp  max_reenc_times  qfactor  qf_min  qf_max  
0   26        0        51      10      51        10        0           0                0        0       0       
1   26        0        51      10      51        10        0           0                0        0       0       
2   26        0        51      10      51        10        0           0                0        0       0       
3   26        0        51      10      51        10        0           0                0        0       0       
​
---------------------- venc chn rc info2 ----------------------------
id  stat_time  set_min_bps set_avg_bps set_max_bps get_min_bps get_avg_bps get_max_bps 
0   3          3840000     4096000     4352000     0           0           0           
1   3          3840000     4096000     4352000     0           0           0           
2   3          3840000     4096000     4352000     0           0           0           
3   3          3840000     4096000     4352000     0           0           0           
​
---------------------- venc chn roi info ----------------------------
id  index     is_intra  abs_qp    qp        x         y         width     height    
​
---------------------- venc chn dump status ----------------------------
id  in_fps    out_fps   seq         snap_set  attach  attach_cnt  attach_size  fail_strm_cnt  
0   0.00      0.00      13108       -1        N       0           0            0              
1   0.00      0.00      13108       -1        N       0           0            0              
2   0.00      0.00      13101       -1        N       0           0            0              
3   0.00      0.00      13103       -1        N       0           0            0              
​
---------------------- venc chn param ----------------------------
id  crop_mode  src_x  src_y  src_w  src_h  dst_x  dst_y  dst_w  dst_y  fps_en  src_fps_set dst_fps_set 
0   none       0      0      0      0      0      0      0      0      1           30/1         30/1     
1   none       0      0      0      0      0      0      0      0      1           30/1         30/1     
2   none       0      0      0      0      0      0      0      0      1           30/1         30/1     
3   none       0      0      0      0      0      0      0      0      1           30/1         30/1     
​
---------------------- venc chn frame dump info1 ----------------------------
id  width   height  vir_w   vir_h   hor_w   ver_h   format            afbc_mode    eos   pts                     delay_us        lost  
0   1920    1080    0       0       1920    1080    image:nv12        0x0          0     0                       481687756       0     
1   720     576     0       0       720     576     image:nv12        0x0          0     0                       481687961       0     
2   1920    1080    0       0       1920    1080    image:nv12        0x0          0     0                       481688084       0     
3   720     576     0       0       720     576     image:nv12        0x0          0     0                       481688214       0     
​
---------------------- venc chn frame dump info2 ----------------------------
id  rect_x  rect_y  rect_w  rect_h  
0   0       0       0       0       
1   0       0       0       0       
2   0       0       0       0       
3   0       0       0       0       
​
---------------------- venc chn dump base config ----------------------------
id  rotation  mirror      
0   0         none        
1   0         none        
2   0         none        
3   0         none        
​
---------------------- venc chn dump jpeg config ----------------------------
id  qfactor  y_qt_sum   cb_qt_sum  cr_qt_sum  mcu_per_ecs  
​
---------------------- venc chn dump mjpeg config ----------------------------
id  y_qt_sum   cb_qt_sum  cr_qt_sum  mcu_per_ecs  
​
---------------------- venc chn dump h264 config ----------------------------
id  intra_pred  tran_mode  chroma_qp  entropy  cabac_init  dblk_dis  dblk_a  dblk_b  full_range  
​
---------------------- venc chn dump h265 config ----------------------------
id  cb_qp  cr_qp  scaling_list  dblk_dis  dblk_a  dblk_b  sao_luma  sao_cr  pu_sis_en  full_range  
0   -6     -6     0             0         0       0       1         1       1          Y           
1   -6     -6     0             0         0       0       1         1       1          Y           
2   -6     -6     0             0         0       0       1         1       1          Y           
3   -6     -6     0             0         0       0       1         1       1          Y           
​
---------------------- venc chn dump rc adv param ----------------------------
id  clear_stat  
0   1           
1   1           
2   1           
3   1           
​
---------------------- venc chn dump super frm ----------------------------
id  super_frm_mode  rc_priority  Iframe_bits_thr  Pframe_bits_thr  
0   0               0            0                0                
1   0               0            0                0                
2   0               0            0                0                
3   0               0            0                0                
​
---------------------- venc chn dump frm lost ----------------------------
id  frm_lost_open  frm_lost_bps_thr  frm_lost_mode  enc_frm_gaps  
0   0              0                 0              0             
1   0              0                 0              0             
2   0              0                 0              0             
3   0              0                 0              0             
​
---------------------- venc chn dump intra refresh ----------------------------
id  refresh_en  refresh_mode  refresh_num  req_i_qp  
0   0           0             0            0         
1   0           0             0            0         
2   0           0             0            0         
3   0           0             0            0         
​
---------------------- venc chn dump hierarchical qp ----------------------------
id  hier_qp_en  hier_qp_delta       hier_frame_num      
0   0           0    0    0    0    0    0    0    0    
1   0           0    0    0    0    0    0    0    0    
2   0           0    0    0    0    0    0    0    0    
3   0           0    0    0    0    0    0    0    0    
​
---------------------- venc chn dump de breath effect ----------------------------
id  de_breath_en  strength0  strength1  
0   0             0          0          
1   0             0          0          
2   0             0          0          
3   0             0          0          
​
---------------------- venc chn dump slice split ----------------------------
id  enable  mode  size  
0   N       0     0     
1   N       0     0     
2   N       0     0     
3   N       0     0     
​
​
-------------------------------------------------------------------------------
END DUMP OF SERVICE venc:
3、查看 vi节点创建 与 绑定 cat /dev/mpi/vlog
# cat /dev/mpi/vlog 
[mb    ][inf][        2.13156 ] {valloc_probe      :0661} rk dma heap addr = 00000000 size = 0
[venc  ][inf][        2.15651 ] {venc_probe        :2597} create thread ef13913e
​
[sys   ][inf][        2.21044 ] {vmcu_probe        :0409} open fp = 4d82b271
[sys   ][inf][        2.21605 ] {vmcu_probe        :0419} size = 4448, pos = 4448
[sys   ][inf][        2.22373 ] {vmcu_probe        :0461} log buf = b8ab9040, len = 8192
[cmpi  ][inf][       44.456938] {vlog_set_level    :0148} mod = 24, level = 4
[vi    ][inf][       44.461600] {vi_open           :0922} --------- vi open ----------
[avs   ][inf][       44.461626] {avs_dev_open      :0678} --------- avs dev open ----------
[cmpi  ][inf][       44.461646] {vrga_open         :0608} --------- vrga open ----------
[aiisp ][inf][       44.461673] {aiisp_dev_open    :0604} --------- aiisp dev open ----------
[vi    ][inf][       44.488665] {vi_open           :0922} --------- vi open ----------
[vi    ][inf][       44.497588] {vvi_node_create   :0177} vi_pri_data pipeId: 0 chnId:0--->>>
[vi    ][inf][       44.497611] {vvi_node_create   :0186} >>>>>> videv 0: 3f8a372b, driver: rkisp-vir0
[vi    ][inf][       44.497625] {vvi_node_create   :0194} width = 1920, height = 1080, max_res_width = 0, max_res_height = 0, enAllocBufType = 0
[vi    ][inf][       44.497670] {vvi_node_create   :0202}  vvi dev:0, chn:0 node create success
[vi    ][inf][       44.501905] {vvi_node_create   :0224} vvi_node_create chn:0 pool create bufcnt:2
[vi    ][inf][       44.501926] {vvi_node_create   :0248} chn:0 depth: 0
[vi    ][inf][       44.501934] {vvi_node_create   :0253} vvi_node_create done
[vi    ][inf][       44.507513] {vvi_node_start    :0411} stWindow = 0, 0, 0, 0, stMaxsize = 0, 0
[vi    ][inf][       44.508292] {vvi_node_start    :0432} vvi_node_start done
[vi    ][inf][       44.535286] {vi_open           :0922} --------- vi open ----------
[vi    ][inf][       44.665735] {vvi_node_create   :0177} vi_pri_data pipeId: 0 chnId:1--->>>
[vi    ][inf][       44.665757] {vvi_node_create   :0186} >>>>>> videv 0: 3f8a372b, driver: rkisp-vir0
[vi    ][inf][       44.665772] {vvi_node_create   :0194} width = 720, height = 576, max_res_width = 0, max_res_height = 0, enAllocBufType = 0
[vi    ][inf][       44.665817] {vvi_node_create   :0202}  vvi dev:0, chn:1 node create success
[vi    ][inf][       44.666755] {vvi_node_create   :0224} vvi_node_create chn:1 pool create bufcnt:2
[vi    ][inf][       44.666770] {vvi_node_create   :0248} chn:1 depth: 0
[vi    ][inf][       44.666779] {vvi_node_create   :0253} vvi_node_create done
[vi    ][inf][       44.673485] {vvi_node_start    :0411} stWindow = 0, 0, 0, 0, stMaxsize = 0, 0
[vi    ][inf][       44.673797] {vvi_node_start    :0432} vvi_node_start done
[vi    ][inf][       44.678229] {vi_open           :0922} --------- vi open ----------
[vi    ][inf][       44.683876] {vvi_node_create   :0177} vi_pri_data pipeId: 1 chnId:0--->>>
[vi    ][inf][       44.683897] {vvi_node_create   :0186} >>>>>> videv 1: f199d889, driver: rkisp-vir1
[vi    ][inf][       44.683913] {vvi_node_create   :0194} width = 1920, height = 1080, max_res_width = 0, max_res_height = 0, enAllocBufType = 0
[vi    ][inf][       44.683962] {vvi_node_create   :0202}  vvi dev:1, chn:0 node create success
[vi    ][inf][       44.688177] {vvi_node_create   :0224} vvi_node_create chn:0 pool create bufcnt:2
[vi    ][inf][       44.688195] {vvi_node_create   :0248} chn:0 depth: 0
[vi    ][inf][       44.688205] {vvi_node_create   :0253} vvi_node_create done
[vi    ][inf][       44.693288] {vvi_node_start    :0411} stWindow = 0, 0, 0, 0, stMaxsize = 0, 0
[vi    ][inf][       44.694116] {vvi_node_start    :0432} vvi_node_start done
[vi    ][inf][       44.706551] {vi_open           :0922} --------- vi open ----------
[vi    ][inf][       44.713432] {vvi_node_create   :0177} vi_pri_data pipeId: 1 chnId:1--->>>
[vi    ][inf][       44.713455] {vvi_node_create   :0186} >>>>>> videv 1: f199d889, driver: rkisp-vir1
[vi    ][inf][       44.713478] {vvi_node_create   :0194} width = 720, height = 576, max_res_width = 0, max_res_height = 0, enAllocBufType = 0
[vi    ][inf][       44.713537] {vvi_node_create   :0202}  vvi dev:1, chn:1 node create success
[vi    ][inf][       44.714465] {vvi_node_create   :0224} vvi_node_create chn:1 pool create bufcnt:2
[vi    ][inf][       44.714480] {vvi_node_create   :0248} chn:1 depth: 0
[vi    ][inf][       44.714488] {vvi_node_create   :0253} vvi_node_create done
[vi    ][inf][       44.721314] {vvi_node_start    :0411} stWindow = 0, 0, 0, 0, stMaxsize = 0, 0
[vi    ][inf][       44.721652] {vvi_node_start    :0432} vvi_node_start done
[cmpi  ][inf][       44.728546] {vsys_bind         :0300} SRC mod,dev,chn(8-0-0) bind DEST mod,dev,chn(4-0-0) success!
[cmpi  ][inf][       44.728583] {vsys_bind         :0300} SRC mod,dev,chn(8-0-1) bind DEST mod,dev,chn(4-0-1) success!
[cmpi  ][inf][       44.728598] {vsys_bind         :0300} SRC mod,dev,chn(8-1-0) bind DEST mod,dev,chn(4-0-2) success!
[cmpi  ][inf][       44.728646] {vsys_bind         :0300} SRC mod,dev,chn(8-1-1) bind DEST mod,dev,chn(4-0-3) success!

4、查看mipi输入帧率# cat /proc/rkcif-mipi-lvds1 | grep fps

# cat /proc/rkcif-mipi-lvds1 | grep fps
        fps:30

5、查看isp工作状态

cat /proc/rkisp-vir0
cat /proc/rkisp-vir1

19、V4L2取流demo



/*
 *  V4L2 video capture example
 *
 * Copyright (C) 2022 Rockchip Electronics Co., Ltd.
 * Authors: 
 */
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
 
#include <getopt.h>             /* getopt_long() */
 
#include <fcntl.h>              /* low-level i/o */
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <linux/videodev2.h>
 
#define CLEAR(x) memset(&(x), 0, sizeof(x))
 
#define FMT_NUM_PLANES 1
 
enum io_method {
        IO_METHOD_READ,
        IO_METHOD_MMAP,
        IO_METHOD_USERPTR,
};
 
struct buffer {
        void   *start;
        size_t  length;
};
 
static char            *dev_name;
static char            *streamfile_name;
static enum io_method   io = IO_METHOD_MMAP;
static int              fd = -1;
struct buffer          *buffers;
static unsigned int     n_buffers;
static int              out_buf;
// static int              force_format;
static int              frame_count = 10;
static int width = 1920;
static int height = 1080;
static int format = V4L2_PIX_FMT_NV12;
 
static void errno_exit(const char *s)
{
        fprintf(stderr, "%s error %d, %s
", s, errno, strerror(errno));
        exit(EXIT_FAILURE);
}
 
static int xioctl(int fh, int request, void *arg)
{
        int r;
 
        do {
                r = ioctl(fh, request, arg);
        } while (-1 == r && EINTR == errno);
 
        return r;
}
 
static void process_image(const void *p, int size)
{
        // if (out_buf)
        //         fwrite(p, size, 1, stdout);
 
        fflush(stderr);
        fprintf(stderr, ">");
        // fflush(stdout);
        char file_name[64] = {0};
    FILE *fp = NULL;
        // snprintf(file_name, sizeof(file_name),
        //      "/data/dump_%dx%d.yuv", width, height);
        snprintf(file_name, sizeof(file_name),
             "%s", streamfile_name);
        fp = fopen(file_name, "ab+");
        if (fp == NULL) {
                printf("fopen yuv file %s failed!
", file_name);
                return;
        }
    // printf("size %d 
", size);
        fwrite(p, size, 1, fp);
    // printf("Write success YUV data to %s",file_name);
        fflush(fp);
}
 
static int read_frame(void)
{
        struct v4l2_buffer buf;
    struct v4l2_plane planes[FMT_NUM_PLANES];
        unsigned int i;
    int bytesused;
        
        switch (io) {
        case IO_METHOD_READ:
                if (-1 == read(fd, buffers[0].start, buffers[0].length)) {
                        switch (errno) {
                        case EAGAIN:
                                return 0;
 
                        case EIO:
                                /* Could ignore EIO, see spec. */
 
                                /* fall through */
 
                        default:
                                errno_exit("read");
                        }
                }
 
                process_image(buffers[0].start, buffers[0].length);
                break;
 
        case IO_METHOD_MMAP:
                CLEAR(buf);
 
                buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
                buf.memory = V4L2_MEMORY_MMAP;
                // struct v4l2_plane planes[FMT_NUM_PLANES];
        memset(planes, 0, sizeof(struct v4l2_plane)*FMT_NUM_PLANES);
            if (V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE == buf.type) {
                buf.m.planes = planes;
                    buf.length = FMT_NUM_PLANES;
        }
                if (-1 == xioctl(fd, VIDIOC_DQBUF, &buf)) {
                        switch (errno) {
                        case EAGAIN:
                                return 0;
 
                        case EIO:
                                /* Could ignore EIO, see spec. */
 
                                /* fall through */
 
                        default:
                                errno_exit("VIDIOC_DQBUF");
                        }
                }
            if (V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE == buf.type)
                bytesused = buf.m.planes[0].bytesused;
            else
                bytesused = buf.bytesused;
                assert(buf.index < n_buffers);
 
                process_image(buffers[buf.index].start, bytesused);
 
                if (-1 == xioctl(fd, VIDIOC_QBUF, &buf))
                        errno_exit("VIDIOC_QBUF");
                break;
 
        case IO_METHOD_USERPTR:
                CLEAR(buf);
 
                buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
                buf.memory = V4L2_MEMORY_USERPTR;
 
                if (-1 == xioctl(fd, VIDIOC_DQBUF, &buf)) {
                        switch (errno) {
                        case EAGAIN:
                                return 0;
 
                        case EIO:
                                /* Could ignore EIO, see spec. */
 
                                /* fall through */
 
                        default:
                                errno_exit("VIDIOC_DQBUF");
                        }
                }
            if (V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE == buf.type)
                bytesused = buf.m.planes[0].bytesused;
            else
                bytesused = buf.bytesused;
                for (i = 0; i < n_buffers; ++i)
                        if (buf.m.userptr == (unsigned long)buffers[i].start
                            && buf.length == buffers[i].length)
                                break;
 
                assert(i < n_buffers);
 
                process_image((void *)buf.m.userptr, bytesused);
 
                if (-1 == xioctl(fd, VIDIOC_QBUF, &buf))
                        errno_exit("VIDIOC_QBUF");
                break;
 
        }
 
        return 1;
}
 
static void mainloop(void)
{
        unsigned int count;
 
        count = frame_count;
 
        while (count-- > 0) {
                for (;;) {
                        fd_set fds;
                        struct timeval tv;
                        int r;
 
                        FD_ZERO(&fds);
                        FD_SET(fd, &fds);
 
                        /* Timeout. */
                        tv.tv_sec = 2;
                        tv.tv_usec = 0;
 
                        r = select(fd + 1, &fds, NULL, NULL, &tv);
 
                        if (-1 == r) {
                                if (EINTR == errno)
                                        continue;
                                errno_exit("select");
                        }
 
                        if (0 == r) {
                                fprintf(stderr, "select timeout
");
                                exit(EXIT_FAILURE);
                        }
 
                        if (read_frame())
                                break;
                        /* EAGAIN - continue select loop. */
                }
        }
}
 
static void stop_capturing(void)
{
        enum v4l2_buf_type type;
 
        switch (io) {
        case IO_METHOD_READ:
                /* Nothing to do. */
                break;
 
        case IO_METHOD_MMAP:
        case IO_METHOD_USERPTR:
                type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
                if (-1 == xioctl(fd, VIDIOC_STREAMOFF, &type))
                        errno_exit("VIDIOC_STREAMOFF");
                break;
        }
}
 
static void start_capturing(void)
{
        unsigned int i;
        enum v4l2_buf_type type;
 
        switch (io) {
        case IO_METHOD_READ:
                /* Nothing to do. */
                break;
 
        case IO_METHOD_MMAP:
                for (i = 0; i < n_buffers; ++i) {
                        struct v4l2_buffer buf;
 
                        CLEAR(buf);
                        buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
                        buf.memory = V4L2_MEMORY_MMAP;
                        buf.index = i;
                if (V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE == buf.type) {
                    struct v4l2_plane planes[FMT_NUM_PLANES];
 
                        buf.m.planes = planes;
                        buf.length = FMT_NUM_PLANES;
            }
                        if (-1 == xioctl(fd, VIDIOC_QBUF, &buf))
                                errno_exit("VIDIOC_QBUF");
                }
                type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
                if (-1 == xioctl(fd, VIDIOC_STREAMON, &type))
                        errno_exit("VIDIOC_STREAMON");
                break;
 
        case IO_METHOD_USERPTR:
                for (i = 0; i < n_buffers; ++i) {
                        struct v4l2_buffer buf;
 
                        CLEAR(buf);
                        buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
                        buf.memory = V4L2_MEMORY_USERPTR;
                        buf.index = i;
                        buf.m.userptr = (unsigned long)buffers[i].start;
                        buf.length = buffers[i].length;
 
                        if (-1 == xioctl(fd, VIDIOC_QBUF, &buf))
                                errno_exit("VIDIOC_QBUF");
                }
                type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
                if (-1 == xioctl(fd, VIDIOC_STREAMON, &type))
                        errno_exit("VIDIOC_STREAMON");
                break;
        }
}
 
static void uninit_device(void)
{
        unsigned int i;
 
        switch (io) {
        case IO_METHOD_READ:
                free(buffers[0].start);
                break;
 
        case IO_METHOD_MMAP:
                for (i = 0; i < n_buffers; ++i)
                        if (-1 == munmap(buffers[i].start, buffers[i].length))
                                errno_exit("munmap");
                break;
 
        case IO_METHOD_USERPTR:
                for (i = 0; i < n_buffers; ++i)
                        free(buffers[i].start);
                break;
        }
 
        free(buffers);
}
 
static void init_read(unsigned int buffer_size)
{
        buffers = calloc(1, sizeof(*buffers));
 
        if (!buffers) {
                fprintf(stderr, "Out of memory
");
                exit(EXIT_FAILURE);
        }
 
        buffers[0].length = buffer_size;
        buffers[0].start = malloc(buffer_size);
 
        if (!buffers[0].start) {
                fprintf(stderr, "Out of memory
");
                exit(EXIT_FAILURE);
        }
}
 
static void init_mmap(void)
{
        struct v4l2_requestbuffers req;
 
        CLEAR(req);
 
        req.count = 4;
        req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
        req.memory = V4L2_MEMORY_MMAP;
 
        if (-1 == xioctl(fd, VIDIOC_REQBUFS, &req)) {
                if (EINVAL == errno) {
                        fprintf(stderr, "%s does not support "
                                 "memory mappingn", dev_name);
                        exit(EXIT_FAILURE);
                } else {
                        errno_exit("VIDIOC_REQBUFS");
                }
        }
 
        if (req.count < 2) {
                fprintf(stderr, "Insufficient buffer memory on %s
",
                         dev_name);
                exit(EXIT_FAILURE);
        }
 
        buffers = calloc(req.count, sizeof(*buffers));
 
        if (!buffers) {
                fprintf(stderr, "Out of memory
");
                exit(EXIT_FAILURE);
        }
 
        for (n_buffers = 0; n_buffers < req.count; ++n_buffers) {
                struct v4l2_buffer buf;
        struct v4l2_plane planes[FMT_NUM_PLANES];
                CLEAR(buf);
            CLEAR(planes);
                buf.type        = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
                buf.memory      = V4L2_MEMORY_MMAP;
                buf.index       = n_buffers;
                if (V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE == buf.type) {
                        buf.m.planes = planes;
                        buf.length = FMT_NUM_PLANES;
                }
                if (-1 == xioctl(fd, VIDIOC_QUERYBUF, &buf))
                        errno_exit("VIDIOC_QUERYBUF");
 
                buffers[n_buffers].length = buf.m.planes[0].length;
                buffers[n_buffers].start =
                        mmap(NULL /* start anywhere */,
                              buf.m.planes[0].length,
                              PROT_READ | PROT_WRITE /* required */,
                              MAP_SHARED /* recommended */,
                              fd, buf.m.planes[0].m.mem_offset);
 
                if (MAP_FAILED == buffers[n_buffers].start)
                        errno_exit("mmap");
        }
}
 
static void init_userp(unsigned int buffer_size)
{
        struct v4l2_requestbuffers req;
 
        CLEAR(req);
 
        req.count  = 4;
        req.type   = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
        req.memory = V4L2_MEMORY_USERPTR;
 
        if (-1 == xioctl(fd, VIDIOC_REQBUFS, &req)) {
                if (EINVAL == errno) {
                        fprintf(stderr, "%s does not support "
                                 "user pointer i/on", dev_name);
                        exit(EXIT_FAILURE);
                } else {
                        errno_exit("VIDIOC_REQBUFS");
                }
        }
 
        buffers = calloc(4, sizeof(*buffers));
 
        if (!buffers) {
                fprintf(stderr, "Out of memory
");
                exit(EXIT_FAILURE);
        }
 
        for (n_buffers = 0; n_buffers < 4; ++n_buffers) {
                buffers[n_buffers].length = buffer_size;
                buffers[n_buffers].start = malloc(buffer_size);
 
                if (!buffers[n_buffers].start) {
                        fprintf(stderr, "Out of memory
");
                        exit(EXIT_FAILURE);
                }
        }
}
 
static void init_device(void)
{
        struct v4l2_capability cap;
        struct v4l2_cropcap cropcap;
        struct v4l2_crop crop;
        struct v4l2_format fmt;
        unsigned int min;
 
        if (-1 == xioctl(fd, VIDIOC_QUERYCAP, &cap)) {
                if (EINVAL == errno) {
                        fprintf(stderr, "%s is no V4L2 device
",
                                 dev_name);
                        exit(EXIT_FAILURE);
                } else {
                        errno_exit("VIDIOC_QUERYCAP");
                }
        }
 
        if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) &&
        !(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE_MPLANE)) {
                fprintf(stderr, "%s is no video capture device
",
                         dev_name);
                exit(EXIT_FAILURE);
        }
 
        switch (io) {
        case IO_METHOD_READ:
                if (!(cap.capabilities & V4L2_CAP_READWRITE)) {
                        fprintf(stderr, "%s does not support read i/o
",
                                 dev_name);
                        exit(EXIT_FAILURE);
                }
                break;
 
        case IO_METHOD_MMAP:
        case IO_METHOD_USERPTR:
                if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
                        fprintf(stderr, "%s does not support streaming i/o
",
                                 dev_name);
                        exit(EXIT_FAILURE);
                }
                break;
        }
 
 
        /* Select video input, video standard and tune here. */
 
 
        CLEAR(cropcap);
 
        cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
 
        if (0 == xioctl(fd, VIDIOC_CROPCAP, &cropcap)) {
                crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
                crop.c = cropcap.defrect; /* reset to default */
 
                if (-1 == xioctl(fd, VIDIOC_S_CROP, &crop)) {
                        switch (errno) {
                        case EINVAL:
                                /* Cropping not supported. */
                                break;
                        default:
                                /* Errors ignored. */
                                break;
                        }
                }
        } else {
                /* Errors ignored. */
        }
 
 
        CLEAR(fmt);
 
        fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
        // if (force_format) {
                fmt.fmt.pix.width       = width;
                fmt.fmt.pix.height      = height;
                fmt.fmt.pix.pixelformat = format;
                fmt.fmt.pix.field       = V4L2_FIELD_NONE;
 
                if (-1 == xioctl(fd, VIDIOC_S_FMT, &fmt))
                        errno_exit("VIDIOC_S_FMT");
 
                /* Note VIDIOC_S_FMT may change width and height. */
        // } else {
        //         /* Preserve original settings as set by v4l2-ctl for example */
        //         if (-1 == xioctl(fd, VIDIOC_G_FMT, &fmt))
        //                 errno_exit("VIDIOC_G_FMT");
        // }
        //fjw
        // width = fmt.fmt.pix.width;
        // height = fmt.fmt.pix.height;
        /* Buggy driver paranoia. */
        min = fmt.fmt.pix.width * 2;
        if (fmt.fmt.pix.bytesperline < min)
                fmt.fmt.pix.bytesperline = min;
        min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height;
        if (fmt.fmt.pix.sizeimage < min)
                fmt.fmt.pix.sizeimage = min;
 
        switch (io) {
        case IO_METHOD_READ:
                init_read(fmt.fmt.pix.sizeimage);
                break;
 
        case IO_METHOD_MMAP:
                init_mmap();
                break;
 
        case IO_METHOD_USERPTR:
                init_userp(fmt.fmt.pix.sizeimage);
                break;
        }
}
 
static void close_device(void)
{
        if (-1 == close(fd))
                errno_exit("close");
 
        fd = -1;
}
 
static void open_device(void)
{
        struct stat st;
 
        if (-1 == stat(dev_name, &st)) {
                fprintf(stderr, "Cannot identify '%s': %d, %s
",
                         dev_name, errno, strerror(errno));
                exit(EXIT_FAILURE);
        }
 
        if (!S_ISCHR(st.st_mode)) {
                fprintf(stderr, "%s is no devicen", dev_name);
                exit(EXIT_FAILURE);
        }
 
        fd = open(dev_name, O_RDWR /* required */ | O_NONBLOCK, 0);
 
        if (-1 == fd) {
                fprintf(stderr, "Cannot open '%s': %d, %s
",
                         dev_name, errno, strerror(errno));
                exit(EXIT_FAILURE);
        }
}
 
static void usage(FILE *fp, int argc, char **argv)
{
        fprintf(fp,
                 "Usage: %s [options]

"
                 "argc: %d"
                 "Version 1.3
"
                 "Options:
"
                 "-d | --device name   Video device name [%s]
"
                 "-p | --help          Print this message
"
                 "-w | --width         width of image
"
                 "-h | --height        height of image
"
                 "-m | --mmap          Use memory mapped buffers [default]
"
                 "-r | --read          Use read() calls
"
                 "-u | --userp         Use application allocated buffers
"
                 "-a | --dma           Use application allocated dma buffers
"
                 "-o | --output        Outputs stream to stdout
"
                 "-f | --format        Force format to YUYV
"
                 "-t | --stream-to     stream-to file default /data/dump_out.yuv
"
                 "-c | --count         Number of frames to grab [%i]
"
                 "-b | --test         test
"
                 "",
                 argv[0], argc, dev_name, frame_count);
}
 
static const char short_options[] = "d:pw:h:mruaof:t:c:b";
 
static const struct option
long_options[] = {
        { "device", required_argument, NULL, 'd' },
        { "help",   no_argument,       NULL, 'p' },
        { "width",   required_argument,       NULL, 'w' },
        { "height",   required_argument,       NULL, 'h' },
        { "mmap",   no_argument,       NULL, 'm' },
        { "read",   no_argument,       NULL, 'r' },
        { "userp",  no_argument,       NULL, 'u' },
        { "dma",  no_argument,       NULL, 'a' },
        { "output", no_argument,       NULL, 'o' },
        { "format", required_argument,       NULL, 'f' },
        { "stream-to", required_argument,       NULL, 't' },
        { "count",  required_argument, NULL, 'c' },
        { "test",  no_argument, NULL, 'b' },
        { 0, 0, 0, 0 }
};
 
int main(int argc, char **argv)
{
        dev_name = "/dev/video0";
        streamfile_name = "/tmp/dump_out.yuv";
        // stdout = fopen("out.yuv", "wb");
 
        for (;;) {
                int idx;
                int c;
 
                c = getopt_long(argc, argv,
                                short_options, long_options, &idx);
 
                if (-1 == c)
                        break;
 
                switch (c) {
                case 0: /* getopt_long() flag */
                        break;
 
                case 'd':
                        dev_name = optarg;
                        break;
 
                case 'p':
                        usage(stdout, argc, argv);
                        exit(EXIT_SUCCESS);
 
                case 'w':
                        width = strtol(optarg, NULL, 0);
                        break;
                case 'h':
                        height = strtol(optarg, NULL, 0);
                        break;
                case 'm':
                        io = IO_METHOD_MMAP;
                        break;
 
                case 'r':
                        io = IO_METHOD_READ;
                        break;
 
                case 'u':
                        io = IO_METHOD_USERPTR;
                        break;
 
                case 'o':
                        out_buf++;
                        break;
 
                case 'f':
                        // force_format++;
                        format = v4l2_fourcc(optarg[0], optarg[1], optarg[2], optarg[3]);
                        break;
                case 't':
                        streamfile_name = optarg;
                        break;
                case 'c':
                        errno = 0;
                        frame_count = strtol(optarg, NULL, 0);
                        if (errno)
                                errno_exit(optarg);
                        break;
                default:
                        usage(stderr, argc, argv);
                        exit(EXIT_FAILURE);
                }
        }
 
        open_device();
        init_device();
        start_capturing();
        mainloop();
        stop_capturing();
        uninit_device();
        close_device();
        fprintf(stderr, "
");
        return 0;
}

20、修改simple_vi_get_frame,取流从第二个sensor取



--- a/media/samples/simple_test/simple_vi_get_frame.c
+++ b/media/samples/simple_test/simple_vi_get_frame.c
@@ -46,9 +46,10 @@ RK_U64 TEST_COMM_GetNowUs() {
 static void *GetMediaBuffer0(void *arg) {
        printf("========%s========
", __func__);
        int loopCount = 0;
+       int loopFailCnt = 0;
        int s32Ret;
-       RK_S32 waitTime = 1000;
-       int pipeId = 0;
+       RK_S32 waitTime = 3000;
+       int pipeId = 1;
        int channelId = 0;
        channelId = *(int *)arg;
        VIDEO_FRAME_INFO_S stViFrame;
@@ -82,6 +83,10 @@ static void *GetMediaBuffer0(void *arg) {
                        loopCount++;
                } else {
                        RK_LOGE("RK_MPI_VI_GetChnFrame timeout %x", s32Ret);
+                       if (loopFailCnt ++ > 100 ) {
+                               quit = true;
+                               break;
+                       }
                }
 
                if ((g_s32FrameCnt >= 0) && (loopCount > g_s32FrameCnt)) {
@@ -97,7 +102,7 @@ static void *GetMediaBuffer0(void *arg) {
 int vi_dev_init() {
        printf("%s
", __func__);
        int ret = 0;
-       int devId = 0;
+       int devId = 1;
        int pipeId = devId;
 
        VI_DEV_ATTR_S stDevAttr;
@@ -149,13 +154,13 @@ int vi_chn_init(int channelId, int width, int height) {
        vi_chn_attr.stIspOpt.u32BufCount = buf_cnt;
        vi_chn_attr.stIspOpt.enMemoryType =
            VI_V4L2_MEMORY_TYPE_DMABUF; // VI_V4L2_MEMORY_TYPE_MMAP;
-       vi_chn_attr.stSize.u32Width = 1280;
-       vi_chn_attr.stSize.u32Height = 720;
+       vi_chn_attr.stSize.u32Width = width;
+       vi_chn_attr.stSize.u32Height = height;
        vi_chn_attr.enPixelFormat = RK_FMT_YUV420SP;
        vi_chn_attr.enCompressMode = COMPRESS_MODE_NONE; // COMPRESS_AFBC_16x16;
        vi_chn_attr.u32Depth = 2; //0, get fail, 1 - u32BufCount, can get, if bind to other device, must be < u32BufCount
-       ret = RK_MPI_VI_SetChnAttr(0, channelId, &vi_chn_attr);
-       ret |= RK_MPI_VI_EnableChn(0, channelId);
+       ret = RK_MPI_VI_SetChnAttr(1, channelId, &vi_chn_attr);
+       ret |= RK_MPI_VI_EnableChn(1, channelId);
        if (ret) {
                printf("ERROR: create VI error! ret=%d
", ret);
                return ret;
wzh@wzh-virtual-machine:~/work/Precision_Landing/RV1106_RV1103_LINUX_IPC$ 

21、rv1106修改kernel isp部分,解决双目第二路无法出图



Author: wzh <wzh@skydroid.onaliyun.com>
Date:   Mon Nov 3 14:42:43 2025 +0800
​
    修改kernel isp部分,解决双目第二路无法出图
​
diff --git a/sysdrv/source/kernel/drivers/media/platform/rockchip/isp/isp_rockit.c b/sysdrv/source/kernel/drivers/media/platform/rockchip/isp/isp_rockit.c
old mode 100644
new mode 100755
index 1666d7480..9f3d45679
--- a/sysdrv/source/kernel/drivers/media/platform/rockchip/isp/isp_rockit.c
+++ b/sysdrv/source/kernel/drivers/media/platform/rockchip/isp/isp_rockit.c
@@ -39,10 +39,12 @@ static struct rkisp_stream *rkisp_rockit_get_stream(struct rockit_cfg *input_roc
                return NULL;
        }
 
+       
        for (i = 0; i < rockit_cfg->isp_num; i++) {
                if (!strcmp(rockit_cfg->rkisp_dev_cfg[i].isp_name,
                            input_rockit_cfg->current_name)) {
                        ispdev = rockit_cfg->rkisp_dev_cfg[i].isp_dev;
+
                        break;
                }
        }
@@ -52,6 +54,8 @@ static struct rkisp_stream *rkisp_rockit_get_stream(struct rockit_cfg *input_roc
                return NULL;
        }
 
+       input_rockit_cfg->nick_id = input_rockit_cfg->nick_id % 6;
+
        switch (input_rockit_cfg->nick_id) {
        case 0:
                stream = &ispdev->cap_dev.stream[RKISP_STREAM_MP];
@@ -97,7 +101,12 @@ int rkisp_rockit_buf_queue(struct rockit_cfg *input_rockit_cfg)
 
        stream = rkisp_rockit_get_stream(input_rockit_cfg);
        if (!stream || stream->id >= ROCKIT_STREAM_NUM_MAX) {
-               pr_err("inval stream");
+               if (!stream) {
+                       pr_err("can not find stream");
+               } else if (stream->id >= ROCKIT_STREAM_NUM_MAX) {
+                       pr_err("invalid stream id");
+               }
+               pr_err("11111 inval stream");
                return -EINVAL;
        }
 
wzh@wzh-virtual-machine:~/work/Precision_Landing/RV1106_RV1103_LINUX_IPC$ 
wzh@wzh-virtual-machine:~/work/Precision_Landing/RV1106_RV1103_LINUX_IPC$ 
wzh@wzh-virtual-machine:~/work/Precision_Landing/RV1106_RV1103_LINUX_IPC$ 

22、双路出RTSP,双路出vpss,格式为RGB888,320X180



//双目取流RKAIQ_GRP
#if 1
#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/poll.h>
#include <time.h>
#include <unistd.h>
 
#ifdef RV1126_RV1109
#include <rk_aiq_user_api_camgroup.h>
#include <rk_aiq_user_api_imgproc.h>
#include <rk_aiq_user_api_sysctl.h>
#else
#include <rk_aiq_user_api2_camgroup.h>
#include <rk_aiq_user_api2_imgproc.h>
#include <rk_aiq_user_api2_sysctl.h>
#endif
 
#include "rk_debug.h"
#include "rk_defines.h"
#include "rk_mpi_adec.h"
#include "rk_mpi_aenc.h"
#include "rk_mpi_ai.h"
#include "rk_mpi_ao.h"
#include "rk_mpi_avs.h"
#include "rk_mpi_cal.h"
#include "rk_mpi_ivs.h"
#include "rk_mpi_mb.h"
#include "rk_mpi_rgn.h"
#include "rk_mpi_sys.h"
#include "rk_mpi_tde.h"
#include "rk_mpi_vdec.h"
#include "rk_mpi_venc.h"
#include "rk_mpi_vi.h"
#include "rk_mpi_vo.h"
#include "rk_mpi_vpss.h"
#include "rtsp_demo.h"
#include "sample_comm.h"
#include <stdatomic.h>
 
pthread_mutex_t g_rtsp_mutex = PTHREAD_MUTEX_INITIALIZER;
static rtsp_demo_handle g_rtsplive = NULL;
static rtsp_session_handle g_rtsp_session_0, g_rtsp_session_1, g_rtsp_session_2,
    g_rtsp_session_3;
typedef struct _rkMpiCtx {
	SAMPLE_VI_CTX_S vi[4]; // camera 0: 0,1; camera 1: 2,3
	SAMPLE_VENC_CTX_S venc[4];
} SAMPLE_MPI_CTX_S;
 
typedef struct VPSS_YUV_REGION_T
{
	uint16_t  X0;
	uint16_t  Y0;
	uint16_t  X1;
	uint16_t  Y1;
	uint16_t  width;
	uint16_t  height;
	uint16_t  cut_x;
	uint16_t  cut_y;
	uint16_t  offset_bak;
	uint16_t  X0_bak;
	uint16_t  y0_bak;
	uint16_t  X1_bak;
	uint16_t  y1_bak;
	uint16_t  first_offset;
	pthread_mutex_t mutex;
}VPSS_YUV_REGION;
VPSS_YUV_REGION g_yuv_region;
 
static RK_S32 g_s32FrameCnt = -1;
static bool quit = false;
 
//#define RKAIQ_GRP
#define MAX_AIQ_CTX 8
static rk_aiq_sys_ctx_t *g_aiq_ctx[MAX_AIQ_CTX];
static rk_aiq_camgroup_ctx_t *g_aiq_camgroup_ctx[MAX_AIQ_CTX];
rk_aiq_working_mode_t g_WDRMode[MAX_AIQ_CTX];
 
static atomic_int g_sof_cnt = 0;
static atomic_bool g_should_quit = false;
 
static void sigterm_handler(int sig) {
	fprintf(stderr, "signal %d
", sig);
	quit = true;
}
 
RK_U64 TEST_COMM_GetNowUs() {
	struct timespec time = {0, 0};
	clock_gettime(CLOCK_MONOTONIC, &time);
	return (RK_U64)time.tv_sec * 1000000 + (RK_U64)time.tv_nsec / 1000; /* microseconds */
}
 
VPSS_GRP VpssGrp = 0;
VPSS_CHN VpssChn = VPSS_CHN0;
VPSS_GRP VpssGrp2 = 1;
VPSS_CHN VpssChn2 = VPSS_CHN0;
VIDEO_FRAME_INFO_S g_pstVideoFrame;
VIDEO_FRAME_INFO_S g_pstVideoFrame2;
 
int sensor0_vpss_init(int vpss_width, int vpss_height)
{
	VPSS_CROP_INFO_S stCropInfo;
	RK_S32 s32Ret = RK_SUCCESS;
	VPSS_GRP_ATTR_S stGrpVpssAttr;
	VPSS_CHN_ATTR_S stVpssChnAttr;
	MPP_CHN_S stViChn;
	MPP_CHN_S stVpssChn;
	stGrpVpssAttr.u32MaxW = vpss_width;
	stGrpVpssAttr.u32MaxH = vpss_height;
	stGrpVpssAttr.enPixelFormat = RK_FMT_YUV422_YUYV;
	stGrpVpssAttr.enCompressMode = COMPRESS_MODE_NONE;
	stGrpVpssAttr.stFrameRate.s32SrcFrameRate = -1;
	stGrpVpssAttr.stFrameRate.s32DstFrameRate = -1;
	s32Ret = RK_MPI_VPSS_CreateGrp(VpssGrp, &stGrpVpssAttr);
	if (s32Ret != RK_SUCCESS)
	{
		RK_LOGE("RK_MPI_VPSS_SetChnAttr fail s32Ret:%d",s32Ret);
		return s32Ret;
	}
    if (pthread_mutex_init(&g_yuv_region.mutex, NULL) != 0)
	{
        printf("&yuv_region.mutex init fail
");
        return 1;
    }
   
	memset(&stVpssChnAttr, 0, sizeof(VPSS_CHN_ATTR_S));
	stVpssChnAttr.enChnMode = VPSS_CHN_MODE_USER;
	stVpssChnAttr.u32Width = vpss_width;
	stVpssChnAttr.u32Height = vpss_height;
	stVpssChnAttr.enVideoFormat = VIDEO_FORMAT_LINEAR;
	stVpssChnAttr.enPixelFormat = RK_FMT_RGB888;
	stVpssChnAttr.enDynamicRange = DYNAMIC_RANGE_SDR8;
	stVpssChnAttr.enCompressMode = COMPRESS_MODE_NONE;
	stVpssChnAttr.stFrameRate.s32SrcFrameRate = -1;
	stVpssChnAttr.stFrameRate.s32DstFrameRate = -1;
	stVpssChnAttr.bMirror = RK_FALSE;
	stVpssChnAttr.bFlip = RK_FALSE;
	stVpssChnAttr.u32Depth = 5;
	stVpssChnAttr.u32FrameBufCnt = 5;
	s32Ret = RK_MPI_VPSS_SetChnAttr(VpssGrp, VpssChn, &stVpssChnAttr);
	if (s32Ret != RK_SUCCESS)
	{
		RK_LOGE("RK_MPI_VPSS_SetChnAttr fail s32Ret:%d",s32Ret);
		return s32Ret;
	}
	s32Ret = RK_MPI_VPSS_GetChnAttr(VpssGrp, VpssChn, &stVpssChnAttr);
	if (s32Ret != RK_SUCCESS)
	{
		RK_LOGE("RK_MPI_VPSS_GetChnAttr fail s32Ret:%d",s32Ret);
		return s32Ret;
	}
	
	s32Ret = RK_MPI_VPSS_EnableChn(VpssGrp, VpssChn);
	if (s32Ret != RK_SUCCESS)
	{
		RK_LOGE("RK_MPI_VPSS_EnableChn fail s32Ret:%d",s32Ret);
		return s32Ret;
	}
 
	
	s32Ret = RK_MPI_VPSS_StartGrp(VpssGrp);
	if (s32Ret != RK_SUCCESS)
	{	
		RK_LOGE("RK_MPI_VPSS_StartGrp fail s32Ret:%d",s32Ret);
		return s32Ret;
	}
	// bind vi to vpss
	stViChn.enModId    = RK_ID_VI;
	stViChn.s32DevId   = 0;
	stViChn.s32ChnId   = 0;
	stVpssChn.enModId  = RK_ID_VPSS;
	stVpssChn.s32DevId = VpssGrp;
	stVpssChn.s32ChnId = VpssChn;
 
	RK_LOGE("vi to vpss ch %d vpss group %d", stVpssChn.s32ChnId , stVpssChn.s32DevId);
	s32Ret = RK_MPI_SYS_Bind(&stViChn, &stVpssChn);
	if (RK_SUCCESS!= s32Ret)
	{		
		RK_LOGE("RK_MPI_SYS_Bind fail s32Ret:%d",s32Ret);
		return s32Ret;
	}
}
 
 
static int sensor0_get_yuv_frame(void **pdata, int *data_len) 
{
	int i = 1;
	FILE *fp;
	RK_S32 s32Ret = RK_SUCCESS;
	PIC_BUF_ATTR_S stPicBufAttr;
	MB_PIC_CAL_S stMbPicCalResult;
	VPSS_GRP iVpssGrp = 0;
	VPSS_CHN iVpssChn = VPSS_CHN0;
	
	memset(&g_pstVideoFrame,0,sizeof(VIDEO_FRAME_INFO_S));
	//RK_LOGE("wzh get_yuv_frame");
	
	s32Ret = RK_MPI_VPSS_GetChnFrame(VpssGrp, VpssChn, &g_pstVideoFrame, -1);
	if (RK_SUCCESS!= s32Ret)
	{		
		RK_LOGE("RK_MPI_VPSS_GetChnFrame fail s32Ret:%x",s32Ret);
		return s32Ret;
	}
	stPicBufAttr.u32Width = g_pstVideoFrame.stVFrame.u32VirWidth;
	stPicBufAttr.u32Height = g_pstVideoFrame.stVFrame.u32VirHeight;
	stPicBufAttr.enPixelFormat = g_pstVideoFrame.stVFrame.enPixelFormat;
	stPicBufAttr.enCompMode = g_pstVideoFrame.stVFrame.enCompressMode;
	s32Ret = RK_MPI_CAL_VGS_GetPicBufferSize(&stPicBufAttr, &stMbPicCalResult);
	if (s32Ret != RK_SUCCESS) {
		RK_LOGE("RK_MPI_CAL_VGS_GetPicBufferSize failed. err=0x%x", s32Ret);
		return s32Ret;
	}
 
	RK_MPI_SYS_MmzFlushCache(g_pstVideoFrame.stVFrame.pMbBlk, RK_TRUE);
 
	*pdata = RK_MPI_MB_Handle2VirAddr(g_pstVideoFrame.stVFrame.pMbBlk);
 
	*data_len = stMbPicCalResult.u32MBSize;
	
	return s32Ret;
}
 
static int sensor0_free_vpss_frame()
{	
	RK_S32 s32Ret = RK_SUCCESS;
	s32Ret = RK_MPI_VPSS_ReleaseChnFrame(VpssGrp, VpssChn,&g_pstVideoFrame);
	if (RK_SUCCESS!= s32Ret)
	{		
		RK_LOGE("RK_MPI_VPSS_GetChnFrame fail s32Ret:%x",s32Ret);
		return s32Ret;
	}
	
	return s32Ret;
}
 
static void *vpss_get_frame_loop0(void *arg) 
{
	int i = 1;
	FILE *fp;
	RK_S32 s32Ret = RK_SUCCESS;
	PIC_BUF_ATTR_S stPicBufAttr;
	MB_PIC_CAL_S stMbPicCalResult;
	static int cnt = 0;
	RK_LOGE("wzh vpss_get_frame_loop0");
	
	void *data = NULL;
	RK_U32 data_len = 0;
	char yuv_name[64] = {0};
	//printf("get vpss yuv
");
	sprintf(yuv_name,"/tmp/sen%d.yuv",0);
    
	while(!quit)
	{
		sensor0_get_yuv_frame(&data, &data_len);
		//RK_LOGE("22vpss_get_frame_loop0 data_len:%d",data_len);
		
		if (cnt++ >= 150) {
			cnt = 0;
			fp = fopen(yuv_name,"wb");
			if (fp == NULL) {
				RK_LOGE("Failed to open file %s", yuv_name);
				return NULL;
			}
			fwrite(data, 1, data_len, fp);
			fflush(fp);
			fclose(fp);
			printf("150 save yuv done
");
		}
		
		sensor0_free_vpss_frame();
		//usleep(1000*100);
	}
}
 
int sensor0_vpss_uninit()
{
	RK_S32 s32Ret = RK_SUCCESS;
#if 1
		s32Ret = RK_MPI_VPSS_StopGrp(VpssGrp);
		if (s32Ret != RK_SUCCESS) {
			return s32Ret;
		}
		for (RK_S32 i = 0; i < VPSS_MAX_CHN_NUM; i++) {
			s32Ret = RK_MPI_VPSS_DisableChn(VpssGrp, VpssChn);
			if (s32Ret != RK_SUCCESS) {
				return s32Ret;
			}
		}
		s32Ret = RK_MPI_VPSS_DestroyGrp(VpssGrp);
		if (s32Ret != RK_SUCCESS) {
			return s32Ret;
		}
#endif
	return s32Ret;
}
 
int sensor1_vpss_init(int vpss_width, int vpss_height)
{
	VPSS_CROP_INFO_S stCropInfo;
	RK_S32 s32Ret = RK_SUCCESS;
	VPSS_GRP_ATTR_S stGrpVpssAttr;
	VPSS_CHN_ATTR_S stVpssChnAttr;
	MPP_CHN_S stViChn;
	MPP_CHN_S stVpssChn;
	stGrpVpssAttr.u32MaxW = vpss_width;
	stGrpVpssAttr.u32MaxH = vpss_height;
	stGrpVpssAttr.enPixelFormat = RK_FMT_YUV422_YUYV;
	stGrpVpssAttr.enCompressMode = COMPRESS_MODE_NONE;
	stGrpVpssAttr.stFrameRate.s32SrcFrameRate = -1;
	stGrpVpssAttr.stFrameRate.s32DstFrameRate = -1;
	s32Ret = RK_MPI_VPSS_CreateGrp(VpssGrp2, &stGrpVpssAttr);
	if (s32Ret != RK_SUCCESS)
	{
		RK_LOGE("RK_MPI_VPSS_SetChnAttr fail s32Ret:%d",s32Ret);
		return s32Ret;
	}
    if (pthread_mutex_init(&g_yuv_region.mutex, NULL) != 0)
	{
        printf("&yuv_region.mutex init fail
");
        return 1;
    }
   
	memset(&stVpssChnAttr, 0, sizeof(VPSS_CHN_ATTR_S));
	stVpssChnAttr.enChnMode = VPSS_CHN_MODE_USER;
	stVpssChnAttr.u32Width = vpss_width;
	stVpssChnAttr.u32Height = vpss_height;
	stVpssChnAttr.enVideoFormat = VIDEO_FORMAT_LINEAR;
	stVpssChnAttr.enPixelFormat = RK_FMT_RGB888;
	stVpssChnAttr.enDynamicRange = DYNAMIC_RANGE_SDR8;
	stVpssChnAttr.enCompressMode = COMPRESS_MODE_NONE;
	stVpssChnAttr.stFrameRate.s32SrcFrameRate = -1;
	stVpssChnAttr.stFrameRate.s32DstFrameRate = -1;
	stVpssChnAttr.bMirror = RK_FALSE;
	stVpssChnAttr.bFlip = RK_FALSE;
	stVpssChnAttr.u32Depth = 5;
	stVpssChnAttr.u32FrameBufCnt = 5;
	s32Ret = RK_MPI_VPSS_SetChnAttr(VpssGrp2, VpssChn2, &stVpssChnAttr);
	if (s32Ret != RK_SUCCESS)
	{
		RK_LOGE("RK_MPI_VPSS_SetChnAttr fail s32Ret:%d",s32Ret);
		return s32Ret;
	}
	s32Ret = RK_MPI_VPSS_GetChnAttr(VpssGrp2, VpssChn2, &stVpssChnAttr);
	if (s32Ret != RK_SUCCESS)
	{
		RK_LOGE("RK_MPI_VPSS_GetChnAttr fail s32Ret:%d",s32Ret);
		return s32Ret;
	}
	
	s32Ret = RK_MPI_VPSS_EnableChn(VpssGrp2, VpssChn2);
	if (s32Ret != RK_SUCCESS)
	{
		RK_LOGE("RK_MPI_VPSS_EnableChn fail s32Ret:%d",s32Ret);
		return s32Ret;
	}
 
	
	s32Ret = RK_MPI_VPSS_StartGrp(VpssGrp2);
	if (s32Ret != RK_SUCCESS)
	{	
		RK_LOGE("RK_MPI_VPSS_StartGrp fail s32Ret:%d",s32Ret);
		return s32Ret;
	}
	// bind vi to vpss
	stViChn.enModId    = RK_ID_VI;
	stViChn.s32DevId   = 1;
	stViChn.s32ChnId   = 0;
	stVpssChn.enModId  = RK_ID_VPSS;
	stVpssChn.s32DevId = VpssGrp2;
	stVpssChn.s32ChnId = VpssChn2;
 
	RK_LOGE("vi to vpss ch %d vpss group %d", stVpssChn.s32ChnId , stVpssChn.s32DevId);
	s32Ret = RK_MPI_SYS_Bind(&stViChn, &stVpssChn);
	if (RK_SUCCESS!= s32Ret)
	{		
		RK_LOGE("RK_MPI_SYS_Bind fail s32Ret:%d",s32Ret);
		return s32Ret;
	}
}
 
 
 
static int sensor1_get_yuv_frame(void **pdata, int *data_len) 
{
	int i = 1;
	FILE *fp;
	RK_S32 s32Ret = RK_SUCCESS;
	PIC_BUF_ATTR_S stPicBufAttr;
	MB_PIC_CAL_S stMbPicCalResult;
	VPSS_GRP iVpssGrp = 0;
	VPSS_CHN iVpssChn = VPSS_CHN0;
	
	memset(&g_pstVideoFrame2,0,sizeof(VIDEO_FRAME_INFO_S));
	//RK_LOGE("wzh get_yuv_frame");
	
	s32Ret = RK_MPI_VPSS_GetChnFrame(VpssGrp, VpssChn, &g_pstVideoFrame2, -1);
	if (RK_SUCCESS!= s32Ret)
	{		
		RK_LOGE("RK_MPI_VPSS_GetChnFrame fail s32Ret:%x",s32Ret);
		return s32Ret;
	}
	stPicBufAttr.u32Width = g_pstVideoFrame2.stVFrame.u32VirWidth;
	stPicBufAttr.u32Height = g_pstVideoFrame2.stVFrame.u32VirHeight;
	stPicBufAttr.enPixelFormat = g_pstVideoFrame2.stVFrame.enPixelFormat;
	stPicBufAttr.enCompMode = g_pstVideoFrame2.stVFrame.enCompressMode;
	s32Ret = RK_MPI_CAL_VGS_GetPicBufferSize(&stPicBufAttr, &stMbPicCalResult);
	if (s32Ret != RK_SUCCESS) {
		RK_LOGE("RK_MPI_CAL_VGS_GetPicBufferSize failed. err=0x%x", s32Ret);
		return s32Ret;
	}
 
	RK_MPI_SYS_MmzFlushCache(g_pstVideoFrame2.stVFrame.pMbBlk, RK_TRUE);
 
	*pdata = RK_MPI_MB_Handle2VirAddr(g_pstVideoFrame2.stVFrame.pMbBlk);
 
	*data_len = stMbPicCalResult.u32MBSize;
	
	return s32Ret;
}
 
static int sensor1_free_vpss_frame()
{	
	RK_S32 s32Ret = RK_SUCCESS;
	s32Ret = RK_MPI_VPSS_ReleaseChnFrame(VpssGrp2, VpssChn2,&g_pstVideoFrame2);
	if (RK_SUCCESS!= s32Ret)
	{		
		RK_LOGE("RK_MPI_VPSS_GetChnFrame fail s32Ret:%x",s32Ret);
		return s32Ret;
	}
	
	return s32Ret;
}
 
static void *vpss_get_frame_loop1(void *arg) 
{
	int i = 1;
	FILE *fp;
	RK_S32 s32Ret = RK_SUCCESS;
	PIC_BUF_ATTR_S stPicBufAttr;
	MB_PIC_CAL_S stMbPicCalResult;
	static int cnt = 0;
	RK_LOGE("wzh vpss_get_frame_loop1");
	
	void *data = NULL;
	RK_U32 data_len = 0;
	char yuv_name[64] = {0};
	//printf("get vpss yuv
");
	sprintf(yuv_name,"/tmp/sen%d.yuv",1);
    
	while(!quit)
	{
		sensor1_get_yuv_frame(&data, &data_len);
		//RK_LOGE("22vpss_get_frame_loop0 data_len:%d",data_len);
		
		if (cnt++ >= 150) {
			cnt = 0;
			fp = fopen(yuv_name,"wb");
			if (fp == NULL) {
				RK_LOGE("Failed to open file %s", yuv_name);
				return NULL;
			}
			fwrite(data, 1, data_len, fp);
			fflush(fp);
			fclose(fp);
			printf("150 save yuv done
");
		}
		
		sensor1_free_vpss_frame();
		//usleep(1000*100);
	}
}
 
int sensor1_vpss_uninit()
{
	RK_S32 s32Ret = RK_SUCCESS;
#if 1
		s32Ret = RK_MPI_VPSS_StopGrp(VpssGrp2);
		if (s32Ret != RK_SUCCESS) {
			return s32Ret;
		}
		for (RK_S32 i = 0; i < VPSS_MAX_CHN_NUM; i++) {
			s32Ret = RK_MPI_VPSS_DisableChn(VpssGrp2, VpssChn2);
			if (s32Ret != RK_SUCCESS) {
				return s32Ret;
			}
		}
		s32Ret = RK_MPI_VPSS_DestroyGrp(VpssGrp2);
		if (s32Ret != RK_SUCCESS) {
			return s32Ret;
		}
#endif
	return s32Ret;
}
static void *GetMediaBuffer0(void *arg) {
	printf("========%s========
", __func__);
	int loopCount = 0;
	int s32Ret;
	RK_S32 waitTime = 10000;
	int pipeId = 0;
	int channelId = 1;
	//channelId = *(int *)arg;
	VIDEO_FRAME_INFO_S stViFrame;
	VI_CHN_STATUS_S stChnStatus;
 
	while (!quit) {
		s32Ret = RK_MPI_VI_GetChnFrame(pipeId, channelId, &stViFrame, waitTime);
		if (s32Ret == RK_SUCCESS) {
			RK_U64 nowUs = TEST_COMM_GetNowUs();
			void *data = RK_MPI_MB_Handle2VirAddr(stViFrame.stVFrame.pMbBlk);
			RK_LOGD("RK_MPI_VI_GetChnFrame ok:data %p loop:%d seq:%d pts:%lld ms len=%llu",
			    data, loopCount, stViFrame.stVFrame.u32TimeRef,
			    stViFrame.stVFrame.u64PTS / 1000, stViFrame.stVFrame.u64PrivateData);
			// 6.get the channel status
			s32Ret = RK_MPI_VI_QueryChnStatus(pipeId, channelId, &stChnStatus);
			RK_LOGD("RK_MPI_VI_QueryChnStatus ret %x, w:%d,h:%d,enable:%d,"
			        "current frame id:%d,input lost:%d,output lost:%d,"
			        "framerate:%d,vbfail:%d delay=%lldus",
			        s32Ret, stChnStatus.stSize.u32Width, stChnStatus.stSize.u32Height,
			        stChnStatus.bEnable, stChnStatus.u32CurFrameID,
			        stChnStatus.u32InputLostFrame, stChnStatus.u32OutputLostFrame,
			        stChnStatus.u32FrameRate, stChnStatus.u32VbFail,
			        nowUs - stViFrame.stVFrame.u64PTS);
 
			// 7.release the frame
			s32Ret = RK_MPI_VI_ReleaseChnFrame(pipeId, channelId, &stViFrame);
			if (s32Ret != RK_SUCCESS) {
				RK_LOGE("RK_MPI_VI_ReleaseChnFrame fail %x", s32Ret);
			}
			loopCount++;
		} else {
			RK_LOGE("RK_MPI_VI_GetChnFrame timeout %x", s32Ret);
		}
 
		if ((g_s32FrameCnt >= 0) && (loopCount > g_s32FrameCnt)) {
			quit = true;
			break;
		}
	}
 
	return NULL;
}
 
static void *GetMediaBuffer1(void *arg) {
	printf("========%s========
", __func__);
	int loopCount = 0;
	int s32Ret;
	RK_S32 waitTime = 10000;
	int pipeId = 1;
	int channelId = 1;
	//channelId = *(int *)arg;
	VIDEO_FRAME_INFO_S stViFrame;
	VI_CHN_STATUS_S stChnStatus;
 
	while (!quit) {
		s32Ret = RK_MPI_VI_GetChnFrame(pipeId, channelId, &stViFrame, waitTime);
		if (s32Ret == RK_SUCCESS) {
			RK_U64 nowUs = TEST_COMM_GetNowUs();
			void *data = RK_MPI_MB_Handle2VirAddr(stViFrame.stVFrame.pMbBlk);
			RK_LOGD(
			    "RK_MPI_VI_GetChnFrame1 ok:data %p loop:%d seq:%d pts:%lld ms len=%llu",
			    data, loopCount, stViFrame.stVFrame.u32TimeRef,
			    stViFrame.stVFrame.u64PTS / 1000, stViFrame.stVFrame.u64PrivateData);
			// 6.get the channel status
			s32Ret = RK_MPI_VI_QueryChnStatus(pipeId, channelId, &stChnStatus);
			RK_LOGD("RK_MPI_VI_QueryChnStatus1 ret %x, w:%d,h:%d,enable:%d,"
			        "current frame id:%d,input lost:%d,output lost:%d,"
			        "framerate:%d,vbfail:%d delay=%lldus",
			        s32Ret, stChnStatus.stSize.u32Width, stChnStatus.stSize.u32Height,
			        stChnStatus.bEnable, stChnStatus.u32CurFrameID,
			        stChnStatus.u32InputLostFrame, stChnStatus.u32OutputLostFrame,
			        stChnStatus.u32FrameRate, stChnStatus.u32VbFail,
			        nowUs - stViFrame.stVFrame.u64PTS);
 
			// 7.release the frame
			s32Ret = RK_MPI_VI_ReleaseChnFrame(pipeId, channelId, &stViFrame);
			if (s32Ret != RK_SUCCESS) {
				RK_LOGE("RK_MPI_VI_ReleaseChnFrame fail %x", s32Ret);
			}
			loopCount++;
		} else {
			RK_LOGE("RK_MPI_VI_GetChnFrame1 timeout %x", s32Ret);
		}
 
		if ((g_s32FrameCnt >= 0) && (loopCount > g_s32FrameCnt)) {
			quit = true;
			break;
		}
	}
 
	return NULL;
}
 
 
// demo板dev默认都是0,根据不同的channel 来选择不同的vi节点
int vi_dev_init0() {
	printf("%s
", __func__);
	int ret = 0;
	int devId = 0;
	int pipeId = devId;
 
	VI_DEV_ATTR_S stDevAttr;
	VI_DEV_BIND_PIPE_S stBindPipe;
	memset(&stDevAttr, 0, sizeof(stDevAttr));
	memset(&stBindPipe, 0, sizeof(stBindPipe));
	// 0. get dev config status
	ret = RK_MPI_VI_GetDevAttr(devId, &stDevAttr);
	if (ret == RK_ERR_VI_NOT_CONFIG) {
		// 0-1.config dev
		ret = RK_MPI_VI_SetDevAttr(devId, &stDevAttr);
		if (ret != RK_SUCCESS) {
			printf("RK_MPI_VI_SetDevAttr %x
", ret);
			return -1;
		}
	} else {
		printf("RK_MPI_VI_SetDevAttr already
");
	}
	// 1.get dev enable status
	ret = RK_MPI_VI_GetDevIsEnable(devId);
	if (ret != RK_SUCCESS) {
		// 1-2.enable dev
		ret = RK_MPI_VI_EnableDev(devId);
		if (ret != RK_SUCCESS) {
			printf("RK_MPI_VI_EnableDev %x
", ret);
			return -1;
		}
		// 1-3.bind dev/pipe
		stBindPipe.u32Num = pipeId;
		stBindPipe.PipeId[0] = pipeId;
		ret = RK_MPI_VI_SetDevBindPipe(devId, &stBindPipe);
		if (ret != RK_SUCCESS) {
			printf("RK_MPI_VI_SetDevBindPipe %x
", ret);
			return -1;
		}
	} else {
		printf("RK_MPI_VI_EnableDev already
");
	}
 
	return 0;
}
 
int vi_chn_init0(int channelId, int width, int height) {
	int ret;
	int buf_cnt = 2;
	// VI init
	VI_CHN_ATTR_S vi_chn_attr;
	memset(&vi_chn_attr, 0, sizeof(vi_chn_attr));
	vi_chn_attr.stIspOpt.u32BufCount = buf_cnt;
	vi_chn_attr.stIspOpt.enMemoryType =
	    VI_V4L2_MEMORY_TYPE_DMABUF; // VI_V4L2_MEMORY_TYPE_MMAP;
	vi_chn_attr.stSize.u32Width = width;
	vi_chn_attr.stSize.u32Height = height;
	vi_chn_attr.enPixelFormat = RK_FMT_YUV420SP;
	vi_chn_attr.enCompressMode = COMPRESS_MODE_NONE; // COMPRESS_AFBC_16x16;
	vi_chn_attr.u32Depth = 2;
	ret = RK_MPI_VI_SetChnAttr(0, channelId, &vi_chn_attr);
	ret |= RK_MPI_VI_EnableChn(0, channelId);
	if (ret) {
		printf("ERROR: create VI error! ret=%d
", ret);
		return ret;
	}
 
	return ret;
}
 
int vi_dev_init1() {
	printf("%s
", __func__);
	int ret = 0;
	int devId = 1;
	int pipeId = devId;
 
	VI_DEV_ATTR_S stDevAttr;
	VI_DEV_BIND_PIPE_S stBindPipe;
	memset(&stDevAttr, 0, sizeof(stDevAttr));
	memset(&stBindPipe, 0, sizeof(stBindPipe));
	// 0. get dev config status
	ret = RK_MPI_VI_GetDevAttr(devId, &stDevAttr);
	if (ret == RK_ERR_VI_NOT_CONFIG) {
		// 0-1.config dev
		ret = RK_MPI_VI_SetDevAttr(devId, &stDevAttr);
		if (ret != RK_SUCCESS) {
			printf("RK_MPI_VI_SetDevAttr %x
", ret);
			return -1;
		}
	} else {
		printf("RK_MPI_VI_SetDevAttr already
");
	}
	// 1.get dev enable status
	ret = RK_MPI_VI_GetDevIsEnable(devId);
	if (ret != RK_SUCCESS) {
		// 1-2.enable dev
		ret = RK_MPI_VI_EnableDev(devId);
		if (ret != RK_SUCCESS) {
			printf("RK_MPI_VI_EnableDev %x
", ret);
			return -1;
		}
		// 1-3.bind dev/pipe
		stBindPipe.u32Num = pipeId;
		stBindPipe.PipeId[0] = pipeId;
		ret = RK_MPI_VI_SetDevBindPipe(devId, &stBindPipe);
		if (ret != RK_SUCCESS) {
			printf("RK_MPI_VI_SetDevBindPipe %x
", ret);
			return -1;
		}
	} else {
		printf("RK_MPI_VI_EnableDev already
");
	}
 
	return 0;
}
 
int vi_chn_init1(int channelId, int width, int height) {
	int ret;
	int buf_cnt = 2;
	// VI init
	VI_CHN_ATTR_S vi_chn_attr;
	memset(&vi_chn_attr, 0, sizeof(vi_chn_attr));
	vi_chn_attr.stIspOpt.u32BufCount = buf_cnt;
	vi_chn_attr.stIspOpt.enMemoryType =
	    VI_V4L2_MEMORY_TYPE_DMABUF; // VI_V4L2_MEMORY_TYPE_MMAP;
	vi_chn_attr.stSize.u32Width = width;
	vi_chn_attr.stSize.u32Height = height;
	vi_chn_attr.enPixelFormat = RK_FMT_YUV420SP;
	vi_chn_attr.enCompressMode = COMPRESS_MODE_NONE; // COMPRESS_AFBC_16x16;
	vi_chn_attr.u32Depth = 2;
	ret = RK_MPI_VI_SetChnAttr(1, channelId, &vi_chn_attr);
	ret |= RK_MPI_VI_EnableChn(1, channelId);
	if (ret) {
		printf("ERROR: create VI error! ret=%d
", ret);
		return ret;
	}
 
	return ret;
}
 
static int isp_get_ldch_mesh_size(uint16_t *meshdata) {
	int file_size = 0;
	if (!meshdata) {
		printf("meshdata is null 
");
		return -1;
	}
	unsigned short hpic, vpic, hsize, vsize, hstep, vstep = 0;
	hpic = (unsigned short)meshdata[0];
	vpic = (unsigned short)meshdata[1];
	hsize = (unsigned short)meshdata[2];
	vsize = (unsigned short)meshdata[3];
	hstep = (unsigned short)meshdata[4];
	vstep = (unsigned short)meshdata[5];
	printf("----------lut info: [%d-%d-%d-%d-%d-%d]
", hpic, vpic, hsize, vsize, hstep,
	       vstep);
	file_size = hsize * vsize * sizeof(unsigned short) + 12;
 
	return file_size;
}
 
XCamReturn SIMPLE_COMM_ISP_CamGroup_setMeshToLdch(int CamGrpId, uint8_t SetLdchMode,
                                                  uint16_t **LdchMesh) {
	XCamReturn ret = XCAM_RETURN_NO_ERROR;
	rk_aiq_sys_ctx_t *aiq_ctx = NULL;
	rk_aiq_camgroup_camInfos_t camInfos;
	rk_aiq_ldch_v21_attrib_t ldchAttr;
	memset(&camInfos, 0, sizeof(camInfos));
	if (SetLdchMode != RK_GET_LDCH_BY_FILE && SetLdchMode != RK_GET_LDCH_BY_BUFF) {
		printf("this Ldch mode:%d, if want to set ldch, 1: read file set ldch, 2: read "
		       "buff set ldch
",
		       SetLdchMode);
		return -1;
	}
	if (rk_aiq_uapi2_camgroup_getCamInfos(g_aiq_camgroup_ctx[CamGrpId], &camInfos) ==
	    XCAM_RETURN_NO_ERROR) {
		for (int i = 0; i < camInfos.valid_sns_num; i++) {
			aiq_ctx = rk_aiq_uapi2_camgroup_getAiqCtxBySnsNm(g_aiq_camgroup_ctx[CamGrpId],
			                                                 camInfos.sns_ent_nm[i]);
			if (!aiq_ctx) {
				printf("rk_aiq_uapi2_camgroup_getAiqCtxBySnsNm return aiq_ctx is Null
");
				return -1;
			}
			printf("aiq_ctx sns name: %s, camPhyId %d
", camInfos.sns_ent_nm[i],
			       camInfos.sns_camPhyId[i]);
			memset(&ldchAttr, 0, sizeof(rk_aiq_ldch_v21_attrib_t));
 
			ret = rk_aiq_user_api2_aldch_v21_GetAttrib(aiq_ctx, &ldchAttr);
			if (ret == XCAM_RETURN_NO_ERROR) {
				if (SetLdchMode == RK_GET_LDCH_BY_BUFF) {
					ldchAttr.update_lut_mode =
					    RK_AIQ_LDCH_UPDATE_LUT_FROM_EXTERNAL_BUFFER;
					ldchAttr.en = true;
					ldchAttr.lut.update_flag = true;
					ldchAttr.lut.u.buffer.addr = LdchMesh[i];
					ldchAttr.lut.u.buffer.size = isp_get_ldch_mesh_size(LdchMesh[i]);
				} else {
					char *pLastWord = NULL;
					pLastWord = strrchr(LdchMesh[i], '/');
					if (!pLastWord) {
						printf("---- error !!! the: %s path isn't to be parsed!!!!
",
						       (char *)LdchMesh[i]);
						return -1;
					}
					ldchAttr.en = true;
					ldchAttr.lut.update_flag = true;
					ldchAttr.update_lut_mode = RK_AIQ_LDCH_UPDATE_LUT_FROM_EXTERNAL_FILE;
					memcpy(ldchAttr.lut.u.file.config_file_dir, (char *)LdchMesh[i],
					       (pLastWord - (char *)LdchMesh[i]) + 1);
					sprintf(ldchAttr.lut.u.file.mesh_file_name, "%s", (pLastWord + 1));
					printf("lut file_dir: %s, mesh_file: %s
",
					       ldchAttr.lut.u.file.config_file_dir,
					       ldchAttr.lut.u.file.mesh_file_name);
				}
				ret = rk_aiq_user_api2_aldch_v21_SetAttrib(aiq_ctx, &ldchAttr);
				if (ret != XCAM_RETURN_NO_ERROR) {
					printf("Failed to set ldch attrib : %d
", ret);
					return ret;
				}
			}
		}
	}
	return ret;
}
 
RK_S32 SIMPLE_COMM_ISP_CamGroup_Init(RK_S32 CamGroupId, rk_aiq_working_mode_t WDRMode,
                                     bool MultiCam, int OpenLdch, void *LdchMesh[],
                                     rk_aiq_camgroup_instance_cfg_t *pCamGroupCfg) {
	int i, ret;
	char sensor_name_array[MAX_AIQ_CTX][128];
	rk_aiq_static_info_t aiq_static_info;
 
	if (CamGroupId >= MAX_AIQ_CTX) {
		printf("%s : CamId is over %d
", __FUNCTION__, MAX_AIQ_CTX);
		return -1;
	}
 
	for (i = 0; i < pCamGroupCfg->sns_num; i++) {
		ret = rk_aiq_uapi2_sysctl_enumStaticMetasByPhyId(i, &aiq_static_info);
		if (ret != 0) {
			printf("rk_aiq_uapi2_sysctl_enumStaticMetasByPhyId failure 
");
			return -1;
		}
 
		printf("CamGroupId:%d, cam_id: %d, sensor_name is %s, iqfiles is %s
",
		       CamGroupId, i, aiq_static_info.sensor_info.sensor_name,
		       pCamGroupCfg->config_file_dir);
		memcpy(sensor_name_array[i], aiq_static_info.sensor_info.sensor_name,
		       strlen(aiq_static_info.sensor_info.sensor_name) + 1);
		pCamGroupCfg->sns_ent_nm_array[i] = sensor_name_array[i];
		printf("pCamGroupCfg->sns_ent_nm_array[%d] is %s
", i,
		       pCamGroupCfg->sns_ent_nm_array[i]);
		ret = rk_aiq_uapi2_sysctl_preInit_devBufCnt(
		    aiq_static_info.sensor_info.sensor_name, "rkraw_rx", 2);
		if (ret != 0) {
			printf("rk_aiq_uapi2_sysctl_preInit_devBufCnt failure
");
			return -1;
		}
	}
 
	g_aiq_camgroup_ctx[CamGroupId] = rk_aiq_uapi2_camgroup_create(pCamGroupCfg);
	if (!g_aiq_camgroup_ctx[CamGroupId]) {
		printf("create camgroup ctx error!
");
		return -1;
	}
	/* set LDCH must before <camgroup prepare>*/
	if (OpenLdch) {
		SIMPLE_COMM_ISP_CamGroup_setMeshToLdch(CamGroupId, OpenLdch, LdchMesh);
	}
 
	ret = rk_aiq_uapi2_camgroup_prepare(g_aiq_camgroup_ctx[CamGroupId], WDRMode);
 
	ret |= rk_aiq_uapi2_camgroup_start(g_aiq_camgroup_ctx[CamGroupId]);
	if (ret != 0) {
		printf("rk_aiq_uapi2_camgroup_prepare / start failure 
");
		return -1;
	}
	printf("rk_aiq_uapi2_camgroup_start over
");
 
	return ret;
}
 
 
RK_S32 SIMPLE_COMM_ISP_CamGroup_Stop(RK_S32 CamGroupId) {
	if (CamGroupId >= MAX_AIQ_CTX || !g_aiq_camgroup_ctx[CamGroupId]) {
		printf("%s : CamId is over 3 or not init
", __FUNCTION__);
		return -1;
	}
	printf("rk_aiq_uapi2_camgroup_stop enter
");
	rk_aiq_uapi2_camgroup_stop(g_aiq_camgroup_ctx[CamGroupId]);
	printf("rk_aiq_uapi2_camgroup_destroy enter
");
	rk_aiq_uapi2_camgroup_destroy(g_aiq_camgroup_ctx[CamGroupId]);
	printf("rk_aiq_uapi2_camgroup_destroy exit
");
	g_aiq_camgroup_ctx[CamGroupId] = NULL;
 
	return 0;
}
 
static RK_CHAR optstr[] = "?::a::w:h:c:I:o:m:d:";
static void print_usage(const RK_CHAR *name) {
	printf("usage example:
");
	printf("	%s -I 0 -w 1920 -h 1080 -o 1
", name);
	printf("	-a | --aiq: iq file path, Default:/etc/iqfiles
");
	printf("	-w | --width: VI width, Default:1920
");
	printf("	-h | --heght: VI height, Default:1080
");
	printf("	-c | --frame_cnt: frame number of output, Default:-1
");
	printf("	-I | --camid: camera ctx id, Default 0. "
	       "0:rkisp_mainpath,1:rkisp_selfpath,2:rkisp_bypasspath
");
	printf("	-d | --hdr_mode: Default:0, 0:normal,1:hdr2
");
	printf("	-m | --multiple sensor: Default:0 
");
	printf("	-o: output path, Default:0  0 or 1 /data/test_0.yuv
");
}
 
/******************************************************************************
 * function : venc thread
 ******************************************************************************/
static void *venc0_get_stream(void *pArgs) {
	printf("#Start %s , arg:%p
", __func__, pArgs);
	SAMPLE_VENC_CTX_S *ctx = (SAMPLE_VENC_CTX_S *)(pArgs);
	RK_S32 s32Ret = RK_FAILURE;
	// char name[256] = {0};
	// FILE *fp = RK_NULL;
	void *pData = RK_NULL;
	RK_S32 loopCount = 0;
 
	while (!quit) {
		s32Ret = SAMPLE_COMM_VENC_GetStream(ctx, &pData);
		if (s32Ret == RK_SUCCESS) {
			RK_LOGD("chn:%d, loopCount:%d wd:%d
", ctx->s32ChnId, loopCount,
			        ctx->stFrame.pstPack->u32Len);
			// exit when complete
			if (ctx->s32loopCount > 0) {
				if (loopCount >= ctx->s32loopCount) {
					SAMPLE_COMM_VENC_ReleaseStream(ctx);
					quit = true;
					break;
				}
			}
 
			PrintStreamDetails(ctx->s32ChnId, ctx->stFrame.pstPack->u32Len);
			pthread_mutex_lock(&g_rtsp_mutex);
			rtsp_tx_video(g_rtsp_session_0, pData, ctx->stFrame.pstPack->u32Len,
			              ctx->stFrame.pstPack->u64PTS);
			rtsp_do_event(g_rtsplive);
			pthread_mutex_unlock(&g_rtsp_mutex);
 
			SAMPLE_COMM_VENC_ReleaseStream(ctx);
			loopCount++;
		}
		usleep(1000);
	}
 
	return RK_NULL;
}
 
static void *venc1_get_stream(void *pArgs) {
	printf("#Start %s , arg:%p
", __func__, pArgs);
	SAMPLE_VENC_CTX_S *ctx = (SAMPLE_VENC_CTX_S *)(pArgs);
	RK_S32 s32Ret = RK_FAILURE;
	// char name[256] = {0};
	// FILE *fp = RK_NULL;
	void *pData = RK_NULL;
	RK_S32 loopCount = 0;
 
	while (!quit) {
		s32Ret = SAMPLE_COMM_VENC_GetStream(ctx, &pData);
		if (s32Ret == RK_SUCCESS) {
			RK_LOGD("chn:%d, loopCount:%d wd:%d
", ctx->s32ChnId, loopCount,
			        ctx->stFrame.pstPack->u32Len);
			// exit when complete
			if (ctx->s32loopCount > 0) {
				if (loopCount >= ctx->s32loopCount) {
					SAMPLE_COMM_VENC_ReleaseStream(ctx);
					quit = true;
					break;
				}
			}
 
			PrintStreamDetails(ctx->s32ChnId, ctx->stFrame.pstPack->u32Len);
			pthread_mutex_lock(&g_rtsp_mutex);
			rtsp_tx_video(g_rtsp_session_1, pData, ctx->stFrame.pstPack->u32Len,
			              ctx->stFrame.pstPack->u64PTS);
			rtsp_do_event(g_rtsplive);
			pthread_mutex_unlock(&g_rtsp_mutex);
 
			SAMPLE_COMM_VENC_ReleaseStream(ctx);
			loopCount++;
		}
		usleep(1000);
	}
 
	return RK_NULL;
}
 
void handle_pipe(int sig) { printf("%s sig = %d
", __func__, sig); }
 
int main(int argc, char *argv[]) {
	RK_S32 s32Ret = RK_FAILURE;
	RK_U32 u32Width = 1920;
	RK_U32 u32Height = 1080;
	RK_U32 subu32Width = 320;
	RK_U32 subu32Height = 180;
	int savefile = 0;
	RK_S32 s32chnlId = 1;
	int c;
	char *iq_dir = NULL;
	//RK_S32 s32CamNum = 2;
	VI_SAVE_FILE_INFO_S stDebugFile;
#if 0 //def RKAIQ_GRP
	int hdr = 0;
	int multi_sensor = RK_FALSE;
#endif
	SAMPLE_MPI_CTX_S *ctx;
	int cam_0_fps = 30;
	int cam_0_enable_hdr = 0;
	int cam_0_video_0_width = 1920;
	int cam_0_video_0_height = 1080;
	int cam_0_video_1_width = 320;
	int cam_0_video_1_height = 180;
	// int cam_0_video_2_width = 896;
	// int cam_0_video_2_height = 512;
 
	int cam_1_fps = 30;
	int cam_1_enable_hdr = 0;
	int cam_1_video_0_width = 1920;
	int cam_1_video_0_height = 1080;
	int cam_1_video_1_width = 320;
	int cam_1_video_1_height = 180;
	int enable_npu = 1;
	int enable_buf_share = 1;
	CODEC_TYPE_E enCodecType = RK_CODEC_TYPE_H265;
	VENC_RC_MODE_E enRcMode = VENC_RC_MODE_H265CBR;
	RK_CHAR *pCodecName = "H265";
	RK_S32 s32CamId = -1;
	MPP_CHN_S vi_chn[6], venc_chn[4];
	RK_CHAR *pOutPathVenc = "/userdata";
	RK_S32 s32CamNum = 4;
	RK_S32 s32loopCnt = -1;
	RK_S32 s32BitRate = 2 * 1024;
	RK_S32 i;
	
	struct sigaction action;
	action.sa_handler = handle_pipe;
	sigemptyset(&action.sa_mask);
	action.sa_flags = 0;
	sigaction(SIGPIPE, &action, NULL);
 
	ctx = (SAMPLE_MPI_CTX_S *)(malloc(sizeof(SAMPLE_MPI_CTX_S)));
	memset(ctx, 0, sizeof(SAMPLE_MPI_CTX_S));
	
	signal(SIGINT, sigterm_handler);
	
	while ((c = getopt(argc, argv, optstr)) != -1) {
		switch (c) {
		case 'a':
			if (optarg)
				iq_dir = optarg;
			else
				iq_dir = "/etc/iqfiles";
			break;
		case 'w':
			u32Width = atoi(optarg);
			break;
		case 'h':
			u32Height = atoi(optarg);
			break;
		case 'I':
			s32chnlId = atoi(optarg);
			break;
		case 'c':
			g_s32FrameCnt = atoi(optarg);
			break;
		case 'o':
			savefile = atoi(optarg);
			break;
#if 0//def RKAIQ_GRP
		case 'd':
			hdr = atoi(optarg);
			break;
		case 'm':
			multi_sensor = atoi(optarg);
			break;
#endif
		case '?':
		default:
			print_usage(argv[0]);
			return 0;
		}
	}
 
	if (iq_dir) {
#if 0 //def RKAIQ_GRP
		printf("#####Aiq xml dirpath: %s

", iq_dir);
		rk_aiq_working_mode_t hdr_mode = RK_AIQ_WORKING_MODE_NORMAL;
		if (hdr == 1)
			hdr_mode = RK_AIQ_WORKING_MODE_ISP_HDR2;
		rk_aiq_camgroup_instance_cfg_t camgroup_cfg;
		memset(&camgroup_cfg, 0, sizeof(camgroup_cfg));
		camgroup_cfg.sns_num = s32CamNum;
		camgroup_cfg.config_file_dir = iq_dir;
		
		s32Ret = SIMPLE_COMM_ISP_CamGroup_Init(0, hdr_mode, multi_sensor, 0,
			                                       RK_NULL, &camgroup_cfg);
		if (s32Ret != RK_SUCCESS) {
			RK_LOGE("SIMPLE_COMM_ISP_CamGroup_Init failure:%#X", s32Ret);
			return RK_FAILURE;
		}
#else //RKAIQ
		RK_BOOL bMultictx = RK_TRUE;
		printf("#Rkaiq XML DirPath: %s
", iq_dir);
		printf("#bMultictx: %d

", bMultictx);
		rk_aiq_working_mode_t hdr_mode_0 = RK_AIQ_WORKING_MODE_NORMAL;
		rk_aiq_working_mode_t hdr_mode_1 = RK_AIQ_WORKING_MODE_NORMAL;
		if (cam_0_enable_hdr)
			hdr_mode_0 = RK_AIQ_WORKING_MODE_ISP_HDR2;
		if (cam_1_enable_hdr)
			hdr_mode_1 = RK_AIQ_WORKING_MODE_ISP_HDR2;
 
		SAMPLE_COMM_ISP_Init(0, hdr_mode_0, bMultictx, iq_dir);
		SAMPLE_COMM_ISP_Run(0);
		SAMPLE_COMM_ISP_SetFrameRate(0, cam_0_fps);
		SAMPLE_COMM_ISP_Init(1, hdr_mode_1, bMultictx, iq_dir);
		SAMPLE_COMM_ISP_Run(1);
		SAMPLE_COMM_ISP_SetFrameRate(1, cam_1_fps);
#endif
	}
 
	printf("88#Resolution: %dx%d
", u32Width, u32Height);
	printf("#Output Path: %d
", savefile);
	printf("#CameraIdx: %d

", s32chnlId);
	printf("#Frame Count to save: %d
", g_s32FrameCnt);
	
	// init rtsp
	g_rtsplive = create_rtsp_demo(554);
	g_rtsp_session_0 = rtsp_new_session(g_rtsplive, "/live/0");
	g_rtsp_session_1 = rtsp_new_session(g_rtsplive, "/live/1");
	//g_rtsp_session_2 = rtsp_new_session(g_rtsplive, "/live/2");
	//g_rtsp_session_3 = rtsp_new_session(g_rtsplive, "/live/3");
	rtsp_set_video(g_rtsp_session_0, RTSP_CODEC_ID_VIDEO_H265, NULL, 0);
	rtsp_set_video(g_rtsp_session_1, RTSP_CODEC_ID_VIDEO_H265, NULL, 0);
	//rtsp_set_video(g_rtsp_session_2, RTSP_CODEC_ID_VIDEO_H265, NULL, 0);
	//rtsp_set_video(g_rtsp_session_3, RTSP_CODEC_ID_VIDEO_H265, NULL, 0);
	rtsp_sync_video_ts(g_rtsp_session_0, rtsp_get_reltime(), rtsp_get_ntptime());
	rtsp_sync_video_ts(g_rtsp_session_1, rtsp_get_reltime(), rtsp_get_ntptime());
	//rtsp_sync_video_ts(g_rtsp_session_2, rtsp_get_reltime(), rtsp_get_ntptime());
	//rtsp_sync_video_ts(g_rtsp_session_3, rtsp_get_reltime(), rtsp_get_ntptime());
	
	if (RK_MPI_SYS_Init() != RK_SUCCESS) {
		RK_LOGE("rk mpi sys init fail!");
		goto __FAILED;
	}
#if 0
	vi_dev_init0();
	vi_chn_init0(s32chnlId, subu32Width, subu32Height);
	vi_dev_init1();
	vi_chn_init1(s32chnlId, subu32Width, subu32Height);
#endif
	for (i = 0; i < s32CamNum; i++) {
		if (i == 0) {
			ctx->vi[i].u32Width = cam_0_video_1_width;
			ctx->vi[i].u32Height = cam_0_video_1_height;
		}
		if (i == 1) {
			ctx->vi[i].u32Width = cam_0_video_0_width;
			ctx->vi[i].u32Height = cam_0_video_0_height;
		}
		if (i == 2) {
			ctx->vi[i].u32Width = cam_1_video_1_width;
			ctx->vi[i].u32Height = cam_1_video_1_height;
		}
		if (i == 3) {
			ctx->vi[i].u32Width = cam_1_video_0_width;
			ctx->vi[i].u32Height = cam_1_video_0_height;
		}
		if (i < 2) {
			ctx->vi[i].s32DevId = 0;
			ctx->vi[i].u32PipeId = 0;
			ctx->vi[i].s32ChnId = i;
		} else {
			ctx->vi[i].s32DevId = 1;
			ctx->vi[i].u32PipeId = 1;
			ctx->vi[i].s32ChnId = i - 2;
		}
		ctx->vi[i].stChnAttr.stIspOpt.u32BufCount = 2;
		ctx->vi[i].stChnAttr.stIspOpt.enMemoryType = VI_V4L2_MEMORY_TYPE_DMABUF;
		ctx->vi[i].stChnAttr.u32Depth = 0;
		ctx->vi[i].stChnAttr.enPixelFormat = RK_FMT_YUV420SP;
		ctx->vi[i].stChnAttr.enCompressMode = COMPRESS_MODE_NONE;
		ctx->vi[i].stChnAttr.stFrameRate.s32SrcFrameRate = -1;
		ctx->vi[i].stChnAttr.stFrameRate.s32DstFrameRate = -1;
 
		SAMPLE_COMM_VI_CreateChn(&ctx->vi[i]);
 
		vi_chn[i].enModId = RK_ID_VI;
		vi_chn[i].s32DevId = ctx->vi[i].s32DevId;
		vi_chn[i].s32ChnId = ctx->vi[i].s32ChnId;
 
		ctx->venc[i].s32ChnId = i;
		if (i == 0) {
			ctx->venc[i].u32Width = cam_0_video_1_width;
			ctx->venc[i].u32Height = cam_0_video_1_height;
			ctx->venc[i].stChnAttr.stVencAttr.u32BufSize =
			    cam_0_video_1_width * cam_0_video_1_height / 4;
			ctx->venc[i].u32Fps = cam_0_fps;
		}
		if (i == 1) {
			ctx->venc[i].u32Width = cam_0_video_0_width;
			ctx->venc[i].u32Height = cam_0_video_0_height;
			ctx->venc[i].stChnAttr.stVencAttr.u32BufSize =
			    cam_0_video_0_width * cam_0_video_0_height / 4;
			ctx->venc[i].u32Fps = cam_0_fps;
		}
		if (i == 2) {
			ctx->venc[i].u32Width = cam_1_video_1_width;
			ctx->venc[i].u32Height = cam_1_video_1_height;
			ctx->venc[i].stChnAttr.stVencAttr.u32BufSize =
			    cam_1_video_1_width * cam_1_video_1_height / 4;
			ctx->venc[i].u32Fps = cam_1_fps;
		}
		if (i == 3) {
			ctx->venc[i].u32Width = cam_1_video_0_width;
			ctx->venc[i].u32Height = cam_1_video_0_height;
			ctx->venc[i].stChnAttr.stVencAttr.u32BufSize =
			    cam_1_video_0_width * cam_1_video_0_height / 4;
			ctx->venc[i].u32Fps = cam_1_fps;
		}
		ctx->venc[i].u32Gop = 60;
		ctx->venc[i].u32BitRate = s32BitRate;
		ctx->venc[i].enCodecType = enCodecType;
		ctx->venc[i].enRcMode = enRcMode;
		if (i == 1)
			ctx->venc[i].getStreamCbFunc = venc0_get_stream;
		if (i == 3)
			ctx->venc[i].getStreamCbFunc = venc1_get_stream;
		ctx->venc[i].s32loopCount = s32loopCnt;
		ctx->venc[i].dstFilePath = pOutPathVenc;
		// H264  66:Baseline  77:Main Profile 100:High Profile
		// H265  0:Main Profile  1:Main 10 Profile
		// MJPEG 0:Baseline
		ctx->venc[i].stChnAttr.stVencAttr.u32Profile = 0;
		ctx->venc[i].stChnAttr.stGopAttr.enGopMode = VENC_GOPMODE_NORMALP;
		ctx->venc[i].enable_buf_share = enable_buf_share;
		if ((i == 1) || (i == 3)) {
			SAMPLE_COMM_VENC_CreateChn(&ctx->venc[i]);
		}
		printf("venc[%d]:u32BufSize:%d
", i,
		       ctx->venc[i].stChnAttr.stVencAttr.u32BufSize);
 
		venc_chn[i].enModId = RK_ID_VENC;
		venc_chn[i].s32DevId = 0;
		venc_chn[i].s32ChnId = ctx->venc[i].s32ChnId;
	}
	SAMPLE_COMM_Bind(&vi_chn[1], &venc_chn[1]);
	SAMPLE_COMM_Bind(&vi_chn[3], &venc_chn[3]);
#if 0
	stDebugFile.bCfg = (RK_BOOL)savefile;
	// memcpy(stDebugFile.aFilePath, "/userdata/", strlen("/data"));
	strcpy(stDebugFile.aFilePath, "/userdata/");
	
	snprintf(stDebugFile.aFileName, sizeof(stDebugFile.aFileName), "test0_%d.yuv",
	         s32chnlId);
	RK_MPI_VI_ChnSaveFile(0, s32chnlId, &stDebugFile);
	
	snprintf(stDebugFile.aFileName, sizeof(stDebugFile.aFileName), "test1_%d.yuv",
	         s32chnlId);
	RK_MPI_VI_ChnSaveFile(1, s32chnlId, &stDebugFile);
	RK_MPI_VI_StartPipe(0);
	RK_MPI_VI_StartPipe(1);
#endif
 
	sensor0_vpss_init(320, 180);
	sensor1_vpss_init(320, 180);
#if 0
	printf("-----------------------------------wzh 1-------------------------------------------
");
	pthread_t main_thread, sub_thread;
	pthread_create(&main_thread, NULL, vpss_get_frame_loop0, &s32chnlId);
	pthread_create(&sub_thread, NULL, vpss_get_frame_loop1, &s32chnlId);
#endif
	while (!quit) {
		usleep(50000);
	}
#if 0
	pthread_join(main_thread, NULL);
	pthread_join(sub_thread, NULL);
#endif	
	for (i = 0; i < s32CamNum; i++) {
		if (ctx->venc[i].getStreamCbFunc) {
			pthread_join(ctx->venc[i].getStreamThread, NULL);
		}
	}
 
	if (g_rtsplive)
		rtsp_del_demo(g_rtsplive);
 
	SAMPLE_COMM_UnBind(&vi_chn[1], &venc_chn[1]);
	SAMPLE_COMM_UnBind(&vi_chn[3], &venc_chn[3]);
	
	sensor0_vpss_uninit();
	sensor1_vpss_uninit();
	
	// Destroy VI[0]
	for (i = 0; i < s32CamNum; i++) {
		if ((i == 1) || (i == 3)) {
			SAMPLE_COMM_VENC_DestroyChn(&ctx->venc[i]);
		}
		SAMPLE_COMM_VI_DestroyChn(&ctx->vi[i]);
	}
	
	s32Ret = RK_MPI_VI_DisableChn(0, s32chnlId);
	s32Ret = RK_MPI_VI_DisableChn(1, s32chnlId);
	RK_LOGE("RK_MPI_VI_DisableChn %x", s32Ret);
 
	s32Ret = RK_MPI_VI_DisableDev(0);
	s32Ret = RK_MPI_VI_DisableDev(1);
	RK_LOGE("RK_MPI_VI_DisableDev %x", s32Ret);
#if 0 // def RKAIQ_GRP
	SIMPLE_COMM_ISP_CamGroup_Stop(0);
#endif
	if (iq_dir) {
#ifdef RKAIQ
		for (int i = 0; i < s32CamNum; i++) {
			SAMPLE_COMM_ISP_Stop(i);
		}
#endif
	}
__FAILED:
	RK_LOGE("test running exit:%d", s32Ret);
	RK_MPI_SYS_Exit();
 
	if (ctx) {
		free(ctx);
		ctx = RK_NULL;
	}
	return 0;
}
 
#endif

23、双目取YUV流demo



//双目取流RKAIQ_GRP
#if 0
#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/poll.h>
#include <time.h>
#include <unistd.h>
 
#ifdef RV1126_RV1109
#include <rk_aiq_user_api_camgroup.h>
#include <rk_aiq_user_api_imgproc.h>
#include <rk_aiq_user_api_sysctl.h>
#else
#include <rk_aiq_user_api2_camgroup.h>
#include <rk_aiq_user_api2_imgproc.h>
#include <rk_aiq_user_api2_sysctl.h>
#endif
 
#include "rk_debug.h"
#include "rk_defines.h"
#include "rk_mpi_adec.h"
#include "rk_mpi_aenc.h"
#include "rk_mpi_ai.h"
#include "rk_mpi_ao.h"
#include "rk_mpi_avs.h"
#include "rk_mpi_cal.h"
#include "rk_mpi_ivs.h"
#include "rk_mpi_mb.h"
#include "rk_mpi_rgn.h"
#include "rk_mpi_sys.h"
#include "rk_mpi_tde.h"
#include "rk_mpi_vdec.h"
#include "rk_mpi_venc.h"
#include "rk_mpi_vi.h"
#include "rk_mpi_vo.h"
#include "rk_mpi_vpss.h"
 
static RK_S32 g_s32FrameCnt = -1;
static bool quit = false;
 
#define RKAIQ_GRP
#define MAX_AIQ_CTX 8
static rk_aiq_sys_ctx_t *g_aiq_ctx[MAX_AIQ_CTX];
static rk_aiq_camgroup_ctx_t *g_aiq_camgroup_ctx[MAX_AIQ_CTX];
rk_aiq_working_mode_t g_WDRMode[MAX_AIQ_CTX];
#include <stdatomic.h>
static atomic_int g_sof_cnt = 0;
static atomic_bool g_should_quit = false;
RK_S32 g_devBufCnt[MAX_AIQ_CTX] = {2, 2, 2, 2, 2, 2, 2, 2};
 
typedef enum rk_GET_LDCH_MODE_E {
	RK_NONE_LDCH = 0,
	RK_GET_LDCH_BY_FILE,
	RK_GET_LDCH_BY_BUFF
} GET_LDCH_MODE_E;
 
 
 
static void sigterm_handler(int sig) {
	fprintf(stderr, "signal %d
", sig);
	quit = true;
}
 
RK_U64 TEST_COMM_GetNowUs() {
	struct timespec time = {0, 0};
	clock_gettime(CLOCK_MONOTONIC, &time);
	return (RK_U64)time.tv_sec * 1000000 + (RK_U64)time.tv_nsec / 1000; /* microseconds */
}
 
static void *GetMediaBuffer0(void *arg) {
	printf("========%s========
", __func__);
	int loopCount = 0;
	int s32Ret;
	RK_S32 waitTime = 10000;
	int pipeId = 0;
	int channelId = 0;
	channelId = *(int *)arg;
	VIDEO_FRAME_INFO_S stViFrame;
	VI_CHN_STATUS_S stChnStatus;
 
	while (!quit) {
		s32Ret = RK_MPI_VI_GetChnFrame(pipeId, channelId, &stViFrame, waitTime);
		if (s32Ret == RK_SUCCESS) {
			RK_U64 nowUs = TEST_COMM_GetNowUs();
			void *data = RK_MPI_MB_Handle2VirAddr(stViFrame.stVFrame.pMbBlk);
			RK_LOGD(
			    "RK_MPI_VI_GetChnFrame ok:data %p loop:%d seq:%d pts:%lld ms len=%llu",
			    data, loopCount, stViFrame.stVFrame.u32TimeRef,
			    stViFrame.stVFrame.u64PTS / 1000, stViFrame.stVFrame.u64PrivateData);
			// 6.get the channel status
			s32Ret = RK_MPI_VI_QueryChnStatus(pipeId, channelId, &stChnStatus);
			RK_LOGD("RK_MPI_VI_QueryChnStatus ret %x, w:%d,h:%d,enable:%d,"
			        "current frame id:%d,input lost:%d,output lost:%d,"
			        "framerate:%d,vbfail:%d delay=%lldus",
			        s32Ret, stChnStatus.stSize.u32Width, stChnStatus.stSize.u32Height,
			        stChnStatus.bEnable, stChnStatus.u32CurFrameID,
			        stChnStatus.u32InputLostFrame, stChnStatus.u32OutputLostFrame,
			        stChnStatus.u32FrameRate, stChnStatus.u32VbFail,
			        nowUs - stViFrame.stVFrame.u64PTS);
 
			// 7.release the frame
			s32Ret = RK_MPI_VI_ReleaseChnFrame(pipeId, channelId, &stViFrame);
			if (s32Ret != RK_SUCCESS) {
				RK_LOGE("RK_MPI_VI_ReleaseChnFrame fail %x", s32Ret);
			}
			loopCount++;
		} else {
			RK_LOGE("RK_MPI_VI_GetChnFrame timeout %x", s32Ret);
		}
 
		if ((g_s32FrameCnt >= 0) && (loopCount > g_s32FrameCnt)) {
			quit = true;
			break;
		}
	}
 
	return NULL;
}
 
static void *GetMediaBuffer1(void *arg) {
	printf("========%s========
", __func__);
	int loopCount = 0;
	int s32Ret;
	RK_S32 waitTime = 10000;
	int pipeId = 1;
	int channelId = 0;
	channelId = *(int *)arg;
	VIDEO_FRAME_INFO_S stViFrame;
	VI_CHN_STATUS_S stChnStatus;
 
	while (!quit) {
		s32Ret = RK_MPI_VI_GetChnFrame(pipeId, channelId, &stViFrame, waitTime);
		if (s32Ret == RK_SUCCESS) {
			RK_U64 nowUs = TEST_COMM_GetNowUs();
			void *data = RK_MPI_MB_Handle2VirAddr(stViFrame.stVFrame.pMbBlk);
			RK_LOGD(
			    "RK_MPI_VI_GetChnFrame1 ok:data %p loop:%d seq:%d pts:%lld ms len=%llu",
			    data, loopCount, stViFrame.stVFrame.u32TimeRef,
			    stViFrame.stVFrame.u64PTS / 1000, stViFrame.stVFrame.u64PrivateData);
			// 6.get the channel status
			s32Ret = RK_MPI_VI_QueryChnStatus(pipeId, channelId, &stChnStatus);
			RK_LOGD("RK_MPI_VI_QueryChnStatus1 ret %x, w:%d,h:%d,enable:%d,"
			        "current frame id:%d,input lost:%d,output lost:%d,"
			        "framerate:%d,vbfail:%d delay=%lldus",
			        s32Ret, stChnStatus.stSize.u32Width, stChnStatus.stSize.u32Height,
			        stChnStatus.bEnable, stChnStatus.u32CurFrameID,
			        stChnStatus.u32InputLostFrame, stChnStatus.u32OutputLostFrame,
			        stChnStatus.u32FrameRate, stChnStatus.u32VbFail,
			        nowUs - stViFrame.stVFrame.u64PTS);
 
			// 7.release the frame
			s32Ret = RK_MPI_VI_ReleaseChnFrame(pipeId, channelId, &stViFrame);
			if (s32Ret != RK_SUCCESS) {
				RK_LOGE("RK_MPI_VI_ReleaseChnFrame fail %x", s32Ret);
			}
			loopCount++;
		} else {
			RK_LOGE("RK_MPI_VI_GetChnFrame1 timeout %x", s32Ret);
		}
 
		if ((g_s32FrameCnt >= 0) && (loopCount > g_s32FrameCnt)) {
			quit = true;
			break;
		}
	}
 
	return NULL;
}
 
 
// demo板dev默认都是0,根据不同的channel 来选择不同的vi节点
int vi_dev_init0() {
	printf("%s
", __func__);
	int ret = 0;
	int devId = 0;
	int pipeId = devId;
 
	VI_DEV_ATTR_S stDevAttr;
	VI_DEV_BIND_PIPE_S stBindPipe;
	memset(&stDevAttr, 0, sizeof(stDevAttr));
	memset(&stBindPipe, 0, sizeof(stBindPipe));
	// 0. get dev config status
	ret = RK_MPI_VI_GetDevAttr(devId, &stDevAttr);
	if (ret == RK_ERR_VI_NOT_CONFIG) {
		// 0-1.config dev
		ret = RK_MPI_VI_SetDevAttr(devId, &stDevAttr);
		if (ret != RK_SUCCESS) {
			printf("RK_MPI_VI_SetDevAttr %x
", ret);
			return -1;
		}
	} else {
		printf("RK_MPI_VI_SetDevAttr already
");
	}
	// 1.get dev enable status
	ret = RK_MPI_VI_GetDevIsEnable(devId);
	if (ret != RK_SUCCESS) {
		// 1-2.enable dev
		ret = RK_MPI_VI_EnableDev(devId);
		if (ret != RK_SUCCESS) {
			printf("RK_MPI_VI_EnableDev %x
", ret);
			return -1;
		}
		// 1-3.bind dev/pipe
		stBindPipe.u32Num = pipeId;
		stBindPipe.PipeId[0] = pipeId;
		ret = RK_MPI_VI_SetDevBindPipe(devId, &stBindPipe);
		if (ret != RK_SUCCESS) {
			printf("RK_MPI_VI_SetDevBindPipe %x
", ret);
			return -1;
		}
	} else {
		printf("RK_MPI_VI_EnableDev already
");
	}
 
	return 0;
}
 
int vi_chn_init0(int channelId, int width, int height) {
	int ret;
	int buf_cnt = 2;
	// VI init
	VI_CHN_ATTR_S vi_chn_attr;
	memset(&vi_chn_attr, 0, sizeof(vi_chn_attr));
	vi_chn_attr.stIspOpt.u32BufCount = buf_cnt;
	vi_chn_attr.stIspOpt.enMemoryType =
	    VI_V4L2_MEMORY_TYPE_DMABUF; // VI_V4L2_MEMORY_TYPE_MMAP;
	vi_chn_attr.stSize.u32Width = width;
	vi_chn_attr.stSize.u32Height = height;
	vi_chn_attr.enPixelFormat = RK_FMT_YUV420SP;
	vi_chn_attr.enCompressMode = COMPRESS_MODE_NONE; // COMPRESS_AFBC_16x16;
	vi_chn_attr.u32Depth = 2;
	ret = RK_MPI_VI_SetChnAttr(0, channelId, &vi_chn_attr);
	ret |= RK_MPI_VI_EnableChn(0, channelId);
	if (ret) {
		printf("ERROR: create VI error! ret=%d
", ret);
		return ret;
	}
 
	return ret;
}
 
int vi_dev_init1() {
	printf("%s
", __func__);
	int ret = 0;
	int devId = 1;
	int pipeId = devId;
 
	VI_DEV_ATTR_S stDevAttr;
	VI_DEV_BIND_PIPE_S stBindPipe;
	memset(&stDevAttr, 0, sizeof(stDevAttr));
	memset(&stBindPipe, 0, sizeof(stBindPipe));
	// 0. get dev config status
	ret = RK_MPI_VI_GetDevAttr(devId, &stDevAttr);
	if (ret == RK_ERR_VI_NOT_CONFIG) {
		// 0-1.config dev
		ret = RK_MPI_VI_SetDevAttr(devId, &stDevAttr);
		if (ret != RK_SUCCESS) {
			printf("RK_MPI_VI_SetDevAttr %x
", ret);
			return -1;
		}
	} else {
		printf("RK_MPI_VI_SetDevAttr already
");
	}
	// 1.get dev enable status
	ret = RK_MPI_VI_GetDevIsEnable(devId);
	if (ret != RK_SUCCESS) {
		// 1-2.enable dev
		ret = RK_MPI_VI_EnableDev(devId);
		if (ret != RK_SUCCESS) {
			printf("RK_MPI_VI_EnableDev %x
", ret);
			return -1;
		}
		// 1-3.bind dev/pipe
		stBindPipe.u32Num = pipeId;
		stBindPipe.PipeId[0] = pipeId;
		ret = RK_MPI_VI_SetDevBindPipe(devId, &stBindPipe);
		if (ret != RK_SUCCESS) {
			printf("RK_MPI_VI_SetDevBindPipe %x
", ret);
			return -1;
		}
	} else {
		printf("RK_MPI_VI_EnableDev already
");
	}
 
	return 0;
}
 
int vi_chn_init1(int channelId, int width, int height) {
	int ret;
	int buf_cnt = 2;
	// VI init
	VI_CHN_ATTR_S vi_chn_attr;
	memset(&vi_chn_attr, 0, sizeof(vi_chn_attr));
	vi_chn_attr.stIspOpt.u32BufCount = buf_cnt;
	vi_chn_attr.stIspOpt.enMemoryType =
	    VI_V4L2_MEMORY_TYPE_DMABUF; // VI_V4L2_MEMORY_TYPE_MMAP;
	vi_chn_attr.stSize.u32Width = width;
	vi_chn_attr.stSize.u32Height = height;
	vi_chn_attr.enPixelFormat = RK_FMT_YUV420SP;
	vi_chn_attr.enCompressMode = COMPRESS_MODE_NONE; // COMPRESS_AFBC_16x16;
	vi_chn_attr.u32Depth = 2;
	ret = RK_MPI_VI_SetChnAttr(1, channelId, &vi_chn_attr);
	ret |= RK_MPI_VI_EnableChn(1, channelId);
	if (ret) {
		printf("ERROR: create VI error! ret=%d
", ret);
		return ret;
	}
 
	return ret;
}
 
static int isp_get_ldch_mesh_size(uint16_t *meshdata) {
	int file_size = 0;
	if (!meshdata) {
		printf("meshdata is null 
");
		return -1;
	}
	unsigned short hpic, vpic, hsize, vsize, hstep, vstep = 0;
	hpic = (unsigned short)meshdata[0];
	vpic = (unsigned short)meshdata[1];
	hsize = (unsigned short)meshdata[2];
	vsize = (unsigned short)meshdata[3];
	hstep = (unsigned short)meshdata[4];
	vstep = (unsigned short)meshdata[5];
	printf("----------lut info: [%d-%d-%d-%d-%d-%d]
", hpic, vpic, hsize, vsize, hstep,
	       vstep);
	file_size = hsize * vsize * sizeof(unsigned short) + 12;
 
	return file_size;
}
 
XCamReturn SIMPLE_COMM_ISP_CamGroup_setMeshToLdch(int CamGrpId, uint8_t SetLdchMode,
                                                  uint16_t **LdchMesh) {
	XCamReturn ret = XCAM_RETURN_NO_ERROR;
	rk_aiq_sys_ctx_t *aiq_ctx = NULL;
	rk_aiq_camgroup_camInfos_t camInfos;
	rk_aiq_ldch_v21_attrib_t ldchAttr;
	memset(&camInfos, 0, sizeof(camInfos));
	if (SetLdchMode != RK_GET_LDCH_BY_FILE && SetLdchMode != RK_GET_LDCH_BY_BUFF) {
		printf("this Ldch mode:%d, if want to set ldch, 1: read file set ldch, 2: read "
		       "buff set ldch
",
		       SetLdchMode);
		return -1;
	}
	if (rk_aiq_uapi2_camgroup_getCamInfos(g_aiq_camgroup_ctx[CamGrpId], &camInfos) ==
	    XCAM_RETURN_NO_ERROR) {
		for (int i = 0; i < camInfos.valid_sns_num; i++) {
			aiq_ctx = rk_aiq_uapi2_camgroup_getAiqCtxBySnsNm(g_aiq_camgroup_ctx[CamGrpId],
			                                                 camInfos.sns_ent_nm[i]);
			if (!aiq_ctx) {
				printf("rk_aiq_uapi2_camgroup_getAiqCtxBySnsNm return aiq_ctx is Null
");
				return -1;
			}
			printf("aiq_ctx sns name: %s, camPhyId %d
", camInfos.sns_ent_nm[i],
			       camInfos.sns_camPhyId[i]);
			memset(&ldchAttr, 0, sizeof(rk_aiq_ldch_v21_attrib_t));
 
			ret = rk_aiq_user_api2_aldch_v21_GetAttrib(aiq_ctx, &ldchAttr);
			if (ret == XCAM_RETURN_NO_ERROR) {
				if (SetLdchMode == RK_GET_LDCH_BY_BUFF) {
					ldchAttr.update_lut_mode =
					    RK_AIQ_LDCH_UPDATE_LUT_FROM_EXTERNAL_BUFFER;
					ldchAttr.en = true;
					ldchAttr.lut.update_flag = true;
					ldchAttr.lut.u.buffer.addr = LdchMesh[i];
					ldchAttr.lut.u.buffer.size = isp_get_ldch_mesh_size(LdchMesh[i]);
				} else {
					char *pLastWord = NULL;
					pLastWord = strrchr(LdchMesh[i], '/');
					if (!pLastWord) {
						printf("---- error !!! the: %s path isn't to be parsed!!!!
",
						       (char *)LdchMesh[i]);
						return -1;
					}
					ldchAttr.en = true;
					ldchAttr.lut.update_flag = true;
					ldchAttr.update_lut_mode = RK_AIQ_LDCH_UPDATE_LUT_FROM_EXTERNAL_FILE;
					memcpy(ldchAttr.lut.u.file.config_file_dir, (char *)LdchMesh[i],
					       (pLastWord - (char *)LdchMesh[i]) + 1);
					sprintf(ldchAttr.lut.u.file.mesh_file_name, "%s", (pLastWord + 1));
					printf("lut file_dir: %s, mesh_file: %s
",
					       ldchAttr.lut.u.file.config_file_dir,
					       ldchAttr.lut.u.file.mesh_file_name);
				}
				ret = rk_aiq_user_api2_aldch_v21_SetAttrib(aiq_ctx, &ldchAttr);
				if (ret != XCAM_RETURN_NO_ERROR) {
					printf("Failed to set ldch attrib : %d
", ret);
					return ret;
				}
			}
		}
	}
	return ret;
}
 
RK_S32 SIMPLE_COMM_ISP_CamGroup_Init(RK_S32 CamGroupId, rk_aiq_working_mode_t WDRMode,
                                     bool MultiCam, int OpenLdch, void *LdchMesh[],
                                     rk_aiq_camgroup_instance_cfg_t *pCamGroupCfg) {
	int i, ret;
	char sensor_name_array[MAX_AIQ_CTX][128];
	rk_aiq_static_info_t aiq_static_info;
 
	if (CamGroupId >= MAX_AIQ_CTX) {
		printf("%s : CamId is over %d
", __FUNCTION__, MAX_AIQ_CTX);
		return -1;
	}
 
	for (i = 0; i < pCamGroupCfg->sns_num; i++) {
		ret = rk_aiq_uapi2_sysctl_enumStaticMetasByPhyId(i, &aiq_static_info);
		if (ret != 0) {
			printf("rk_aiq_uapi2_sysctl_enumStaticMetasByPhyId failure 
");
			return -1;
		}
 
		printf("CamGroupId:%d, cam_id: %d, sensor_name is %s, iqfiles is %s
",
		       CamGroupId, i, aiq_static_info.sensor_info.sensor_name,
		       pCamGroupCfg->config_file_dir);
		memcpy(sensor_name_array[i], aiq_static_info.sensor_info.sensor_name,
		       strlen(aiq_static_info.sensor_info.sensor_name) + 1);
		pCamGroupCfg->sns_ent_nm_array[i] = sensor_name_array[i];
		printf("pCamGroupCfg->sns_ent_nm_array[%d] is %s
", i,
		       pCamGroupCfg->sns_ent_nm_array[i]);
		ret = rk_aiq_uapi2_sysctl_preInit_devBufCnt(
		    aiq_static_info.sensor_info.sensor_name, "rkraw_rx", 2);
		if (ret != 0) {
			printf("rk_aiq_uapi2_sysctl_preInit_devBufCnt failure
");
			return -1;
		}
	}
 
	g_aiq_camgroup_ctx[CamGroupId] = rk_aiq_uapi2_camgroup_create(pCamGroupCfg);
	if (!g_aiq_camgroup_ctx[CamGroupId]) {
		printf("create camgroup ctx error!
");
		return -1;
	}
	/* set LDCH must before <camgroup prepare>*/
	if (OpenLdch) {
		SIMPLE_COMM_ISP_CamGroup_setMeshToLdch(CamGroupId, OpenLdch, LdchMesh);
	}
 
	ret = rk_aiq_uapi2_camgroup_prepare(g_aiq_camgroup_ctx[CamGroupId], WDRMode);
 
	ret |= rk_aiq_uapi2_camgroup_start(g_aiq_camgroup_ctx[CamGroupId]);
	if (ret != 0) {
		printf("rk_aiq_uapi2_camgroup_prepare / start failure 
");
		return -1;
	}
	printf("rk_aiq_uapi2_camgroup_start over
");
 
	return ret;
}
 
 
RK_S32 SIMPLE_COMM_ISP_CamGroup_Stop(RK_S32 CamGroupId) {
	if (CamGroupId >= MAX_AIQ_CTX || !g_aiq_camgroup_ctx[CamGroupId]) {
		printf("%s : CamId is over 3 or not init
", __FUNCTION__);
		return -1;
	}
	printf("rk_aiq_uapi2_camgroup_stop enter
");
	rk_aiq_uapi2_camgroup_stop(g_aiq_camgroup_ctx[CamGroupId]);
	printf("rk_aiq_uapi2_camgroup_destroy enter
");
	rk_aiq_uapi2_camgroup_destroy(g_aiq_camgroup_ctx[CamGroupId]);
	printf("rk_aiq_uapi2_camgroup_destroy exit
");
	g_aiq_camgroup_ctx[CamGroupId] = NULL;
 
	return 0;
}
 
 
 
 
static RK_CHAR optstr[] = "?::a::w:h:c:I:o:m:d:";
static void print_usage(const RK_CHAR *name) {
	printf("usage example:
");
	printf("	%s -I 0 -w 1920 -h 1080 -o 1
", name);
	printf("	-a | --aiq: iq file path, Default:/etc/iqfiles
");
	printf("	-w | --width: VI width, Default:1920
");
	printf("	-h | --heght: VI height, Default:1080
");
	printf("	-c | --frame_cnt: frame number of output, Default:-1
");
	printf("	-I | --camid: camera ctx id, Default 0. "
	       "0:rkisp_mainpath,1:rkisp_selfpath,2:rkisp_bypasspath
");
	printf("	-d | --hdr_mode: Default:0, 0:normal,1:hdr2
");
	printf("	-m | --multiple sensor: Default:0 
");
	printf("	-o: output path, Default:0  0 or 1 /data/test_0.yuv
");
}
 
int main(int argc, char *argv[]) {
	RK_S32 s32Ret = RK_FAILURE;
	RK_U32 u32Width = 1920;
	RK_U32 u32Height = 1080;
	int savefile = 0;
	RK_S32 s32chnlId = 0;
	int c;
	char *iq_dir = NULL;
	RK_S32 s32CamNum = 2;
	VI_SAVE_FILE_INFO_S stDebugFile;
#ifdef RKAIQ_GRP
	int hdr = 0;
	int multi_sensor = RK_FALSE;
#endif
 
	while ((c = getopt(argc, argv, optstr)) != -1) {
		switch (c) {
		case 'a':
			if (optarg)
				iq_dir = optarg;
			else
				iq_dir = "/etc/iqfiles";
			break;
		case 'w':
			u32Width = atoi(optarg);
			break;
		case 'h':
			u32Height = atoi(optarg);
			break;
		case 'I':
			s32chnlId = atoi(optarg);
			break;
		case 'c':
			g_s32FrameCnt = atoi(optarg);
			break;
		case 'o':
			savefile = atoi(optarg);
			break;
#ifdef RKAIQ_GRP
		case 'd':
			hdr = atoi(optarg);
			break;
		case 'm':
			multi_sensor = atoi(optarg);
			break;
#endif
		case '?':
		default:
			print_usage(argv[0]);
			return 0;
		}
	}
 
	if (iq_dir) {
#ifdef RKAIQ_GRP
		printf("#####Aiq xml dirpath: %s

", iq_dir);
		rk_aiq_working_mode_t hdr_mode = RK_AIQ_WORKING_MODE_NORMAL;
		if (hdr == 1)
			hdr_mode = RK_AIQ_WORKING_MODE_ISP_HDR2;
		rk_aiq_camgroup_instance_cfg_t camgroup_cfg;
		memset(&camgroup_cfg, 0, sizeof(camgroup_cfg));
		camgroup_cfg.sns_num = s32CamNum;
		camgroup_cfg.config_file_dir = iq_dir;
		
		s32Ret = SIMPLE_COMM_ISP_CamGroup_Init(0, hdr_mode, multi_sensor, 0,
			                                       RK_NULL, &camgroup_cfg);
		if (s32Ret != RK_SUCCESS) {
			RK_LOGE("SIMPLE_COMM_ISP_CamGroup_Init failure:%#X", s32Ret);
			return RK_FAILURE;
		}
#endif
	}
 
	printf("#Resolution: %dx%d
", u32Width, u32Height);
	printf("#Output Path: %d
", savefile);
	printf("#CameraIdx: %d

", s32chnlId);
	printf("#Frame Count to save: %d
", g_s32FrameCnt);
 
	signal(SIGINT, sigterm_handler);
 
	if (RK_MPI_SYS_Init() != RK_SUCCESS) {
		RK_LOGE("rk mpi sys init fail!");
		goto __FAILED;
	}
 
	vi_dev_init0();
	vi_chn_init0(s32chnlId, u32Width, u32Height);
	vi_dev_init1();
	vi_chn_init1(s32chnlId, u32Width, u32Height);
 
	stDebugFile.bCfg = (RK_BOOL)savefile;
	// memcpy(stDebugFile.aFilePath, "/userdata/", strlen("/data"));
	strcpy(stDebugFile.aFilePath, "/userdata/");
 
	snprintf(stDebugFile.aFileName, sizeof(stDebugFile.aFileName), "test0_%d.yuv",
	         s32chnlId);
	RK_MPI_VI_ChnSaveFile(0, s32chnlId, &stDebugFile);
	
	snprintf(stDebugFile.aFileName, sizeof(stDebugFile.aFileName), "test1_%d.yuv",
	         s32chnlId);
	RK_MPI_VI_ChnSaveFile(1, s32chnlId, &stDebugFile);
 
	RK_MPI_VI_StartPipe(0);
	RK_MPI_VI_StartPipe(1);
 
	pthread_t main_thread, sub_thread;
	pthread_create(&main_thread, NULL, GetMediaBuffer0, &s32chnlId);
	pthread_create(&sub_thread, NULL, GetMediaBuffer1, &s32chnlId);
 
	while (!quit) {
		usleep(50000);
	}
	pthread_join(main_thread, NULL);
	pthread_join(sub_thread, NULL);
	s32Ret = RK_MPI_VI_DisableChn(0, s32chnlId);
	s32Ret = RK_MPI_VI_DisableChn(1, s32chnlId);
	RK_LOGE("RK_MPI_VI_DisableChn %x", s32Ret);
 
	s32Ret = RK_MPI_VI_DisableDev(0);
	s32Ret = RK_MPI_VI_DisableDev(1);
	RK_LOGE("RK_MPI_VI_DisableDev %x", s32Ret);
#ifdef RKAIQ_GRP
	SIMPLE_COMM_ISP_CamGroup_Stop(0);
#endif
__FAILED:
	RK_LOGE("test running exit:%d", s32Ret);
	RK_MPI_SYS_Exit();
 
	return 0;
}
 
#endif

© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
none
暂无评论...