赞
踩
RK3566 + Android 11
UVC:
USB video class(又称为USB video device class or UVC)就是USB device class视频产品在不需要安装任何的驱动程序下即插即用,包括摄像头、数字摄影机、模拟视频转换器、电视卡及静态视频相机。
测试代码:
Camera cam = Camera.open(CAMERA_ID);
Camera.Parameters param = cam.getParameters();
List<Camera.Size> sizes = param.getSupportedPreviewSizes();
打印出来后显示支持的预览分辨率如下:
D startPreview support preview 640x360
D startPreview support preview 640x480
D startPreview support preview 960x540
D startPreview support preview 800x600
D startPreview support preview 1280x720
D startPreview support preview 1280x960
D startPreview support preview 1920x1080
D startPreview support preview 1600x1200
然而,把摄像头接入到PC上,不管是LINUX还是WINDOWS,会发现实际支持的最大预览分辨率是:3840x2160
缺少的分辨率哪去了?
摄像头部分的架构比较复杂,整理几个相关的源码目录:
# SDK 接口
> frameworks/base/core/java/android/hardware/Camera.java
> frameworks/base/core/jni/android_hardware_Camera.cpp
# 上层 Camera 服务
> frameworks/av/camera/
# HAL层
> hardware/rockchip/camera
> hardware/interfaces/camera/
# 配置文件,对应USB和CSI之类的摄像头配置
# 包含了支持分辨率,闪光灯等等的一些特性。
> device/rockchip/common/external_camera_config.xml
> hardware/rockchip/camera/etc/camera/
烧录到主板后相关的一些文件目录
> rk3568_r:/ # ll /vendor/etc/camera/ total 948 -rw-r--r-- 1 root root 3044 2023-04-18 09:55 README.txt -rw-r--r-- 1 root root 152818 2023-04-18 09:55 camera3_profiles.xml -rw-r--r-- 1 root root 166244 2023-04-18 09:55 camera3_profiles_default.xml -rw-r--r-- 1 root root 14744 2023-04-18 09:55 camera3_profiles_rk1126.xml -rw-r--r-- 1 root root 48811 2023-04-18 09:55 camera3_profiles_rk3126c.xml -rw-r--r-- 1 root root 64987 2023-04-18 09:55 camera3_profiles_rk3288.xml -rw-r--r-- 1 root root 61800 2023-04-18 09:55 camera3_profiles_rk3326.xml -rw-r--r-- 1 root root 98549 2023-04-18 09:55 camera3_profiles_rk3368.xml -rw-r--r-- 1 root root 64766 2023-04-18 09:55 camera3_profiles_rk3399.xml -rw-r--r-- 1 root root 26451 2023-04-18 09:55 camera3_profiles_rk3399_1608.xml -rw-r--r-- 1 root root 77820 2023-04-18 09:55 camera3_profiles_rk3399pro.xml -rw-r--r-- 1 root root 152818 2023-04-18 09:55 camera3_profiles_rk356x.xml -rw-r--r-- 1 root root 2875 2023-04-18 09:55 graph_descriptor.xml -rw-r--r-- 1 root root 145 2023-04-18 09:55 reset_camera.sh drwxr-xr-x 2 root shell 4096 2023-04-18 09:55 rkisp1 drwxr-xr-x 2 root shell 4096 2023-04-18 09:55 rkisp2 # UVC 的配置 > /vendor/etc/external_camera_config.xml
先用v4l2 工具看下基本信息
## 当前的设备列表 rk3566:/ # ll /dev/video* crw-rw---- 1 media camera 81, 0 2023-04-14 09:44 /dev/video0 crw-rw---- 1 media camera 81, 1 2023-04-14 09:44 /dev/video1 crw-rw---- 1 media camera 81, 10 2023-04-14 09:44 /dev/video10 crw-rw---- 1 media camera 81, 11 2023-04-14 09:44 /dev/video11 crw-rw---- 1 media camera 81, 12 2023-04-14 09:44 /dev/video12 crw-rw---- 1 media camera 81, 13 2023-04-14 09:44 /dev/video13 crw-rw---- 1 media camera 81, 14 2023-04-14 09:44 /dev/video14 crw-rw---- 1 media camera 81, 15 2023-04-14 09:44 /dev/video15 crw-rw---- 1 media camera 81, 2 2023-04-14 09:44 /dev/video2 crw-rw---- 1 media camera 81, 3 2023-04-14 09:44 /dev/video3 crw-rw---- 1 media camera 81, 4 2023-04-14 09:44 /dev/video4 crw-rw---- 1 media camera 81, 5 2023-04-14 09:44 /dev/video5 crw-rw---- 1 media camera 81, 6 2023-04-14 09:44 /dev/video6 crw-rw---- 1 media camera 81, 7 2023-04-14 09:44 /dev/video7 crw-rw---- 1 media camera 81, 8 2023-04-14 09:44 /dev/video8 crw-rw---- 1 media camera 81, 9 2023-04-14 09:44 /dev/video9 # 设备信息 rk3566_r:/ # v4l2-ctl --list-devices rkisp-statistics (platform: rkisp): /dev/video12 /dev/video13 rkcif (platform:rkcif_mipi_lvds): /dev/video0 /dev/video1 /dev/video2 /dev/video3 /dev/video4 rkisp_mainpath (platform:rkisp-vir0): /dev/video5 /dev/video6 /dev/video7 /dev/video8 /dev/video9 /dev/video10 /dev/video11 UC40A Audio: UC40A Video (usb-xhci-hcd.1.auto-1.3): /dev/video14 /dev/video15 # 查看指定设备信息 rk3566_r:/ # v4l2-ctl -D -d /dev/video15 Driver Info: Driver name : uvcvideo Card type : UC40A Audio: UC40A Video Bus info : usb-xhci-hcd.1.auto-1.3 Driver version : 4.19.193 Capabilities : 0x84a00001 Video Capture Metadata Capture Streaming Extended Pix Format Device Capabilities Device Caps : 0x04a00000 Metadata Capture Streaming Extended Pix Format Media Driver Info: Driver name : uvcvideo Model : UC40A Audio: UC40A Video Serial : 01.00.00 Bus info : usb-xhci-hcd.1.auto-1.3 Media version : 4.19.193 Hardware revision: 0x00000902 (2306) Driver version : 4.19.193 Interface Info: ID : 0x03000005 Type : V4L Video Entity Info: ID : 0x00000004 (4) Name : UC40A Audio: UC40A Video Function : V4L2 I/O # 设备支持格式 rk3566_r:/ # v4l2-ctl -d /dev/video14 --list-formats ioctl: VIDIOC_ENUM_FMT Index : 0 Type : Video Capture Pixel Format: 'MJPG' (compressed) Name : Motion-JPEG Index : 1 Type : Video Capture Pixel Format: 'YUYV' Name : YUYV 4:2:2 # 设备支持分辨率 rk3566_r:/ # v4l2-ctl -d /dev/video14 --list-framesizes=YUYV ioctl: VIDIOC_ENUM_FRAMESIZES Size: Discrete 2048x1536 Size: Discrete 640x480 Size: Discrete 3840x2160 Size: Discrete 2592x1944 Size: Discrete 2688x1512 Size: Discrete 1920x1080 Size: Discrete 1600x1200 Size: Discrete 1280x960 Size: Discrete 1280x720 Size: Discrete 960x540 Size: Discrete 800x600 Size: Discrete 640x360
结论:硬件及驱动到HAL都是正常
忽略中间漫长的排查过程, 直奔主题:
预览的限制主要存在于HAL和framework层, 至少RK的SDK是这样的,其他平台请勿对号入座。
/vendor/etc/external_camera_config.xml 中的 FpsList
注释:List of maximum fps for various output sizes
解决的方法是增加对应缺少的分辨率,如:<Limit width=“3840” height=“2160” fpsBound=“30.0” />
<ExternalCamera> <Provider> <ignore> <!-- Internal video devices to be ignored by external camera HAL --> <!-- <id>0</id> --> <!-- No leading/trailing spaces --> </ignore> </Provider> <!-- See ExternalCameraUtils.cpp for default values of Device configurations below--> <Device> <!-- Max JPEG buffer size in bytes--> <MaxJpegBufferSize bytes="24883200"/> <!-- 3MB (~= 1080p YUV420) --> <!-- Size of v4l2 buffer queue when streaming >= 30fps --> <!-- Larger value: more request can be cached pipeline (less janky) --> <!-- Smaller value: use less memory --> <NumVideoBuffers count="4"/> <!-- Size of v4l2 buffer queue when streaming < 30fps --> <NumStillBuffers count="2"/> <!-- List of maximum fps for various output sizes --> <!-- Any image size smaller than the size listed in Limit row will report fps (as minimum frame duration) up to the fpsBound value. --> <FpsList> <!-- width/height must be increasing, fpsBound must be decreasing--> <Limit width="176" height="144" fpsBound="60.0" /> <Limit width="176" height="144" fpsBound="30.0" /> <Limit width="176" height="144" fpsBound="20.0" /> <Limit width="176" height="144" fpsBound="15.0" /> <Limit width="320" height="240" fpsBound="60.0" /> <Limit width="320" height="240" fpsBound="30.0" /> <Limit width="320" height="240" fpsBound="20.0" /> <Limit width="320" height="240" fpsBound="15.0" /> <Limit width="352" height="288" fpsBound="30.0" /> <Limit width="352" height="288" fpsBound="20.0" /> <Limit width="352" height="288" fpsBound="15.0" /> <Limit width="640" height="480" fpsBound="60.0" /> <Limit width="640" height="480" fpsBound="30.0" /> <Limit width="640" height="480" fpsBound="20.0" /> <Limit width="640" height="480" fpsBound="15.0" /> <Limit width="640" height="480" fpsBound="10.0" /> <Limit width="800" height="600" fpsBound="30.0" /> <Limit width="800" height="600" fpsBound="20.0" /> <Limit width="800" height="600" fpsBound="15.0" /> <Limit width="1024" height="768" fpsBound="30.0" /> <Limit width="1024" height="768" fpsBound="20.0" /> <Limit width="1024" height="768" fpsBound="15.0" /> <Limit width="1024" height="768" fpsBound="10.0" /> <Limit width="1280" height="720" fpsBound="60.0" /> <Limit width="1280" height="720" fpsBound="30.0" /> <Limit width="1280" height="720" fpsBound="20.0" /> <Limit width="1280" height="720" fpsBound="15.0" /> <Limit width="1280" height="720" fpsBound="10.0" /> <Limit width="1280" height="800" fpsBound="30.0" /> <Limit width="1280" height="800" fpsBound="20.0" /> <Limit width="1280" height="800" fpsBound="15.0" /> <Limit width="1280" height="960" fpsBound="30.0" /> <Limit width="1280" height="960" fpsBound="20.0" /> <Limit width="1280" height="960" fpsBound="15.0" /> <Limit width="1280" height="1024" fpsBound="30.0" /> <Limit width="1280" height="1024" fpsBound="20.0" /> <Limit width="1280" height="1024" fpsBound="15.0" /> <Limit width="1600" height="1200" fpsBound="30.0" /> <Limit width="1600" height="1200" fpsBound="15.0" /> <Limit width="1920" height="1080" fpsBound="30.0" /> <Limit width="1920" height="1080" fpsBound="15.0" /> <Limit width="2048" height="1536" fpsBound="30.0" /> <Limit width="2592" height="1944" fpsBound="30.0" /> <Limit width="2592" height="1944" fpsBound="15.0" /> <Limit width="2592" height="1944" fpsBound="10.0" /> <Limit width="2592" height="1944" fpsBound="5.0" /> <Limit width="2688" height="1512" fpsBound="30.0" /> <Limit width="3840" height="2160" fpsBound="30.0" /> <!-- image size larger than the last entry will not be supported--> </FpsList> <!-- orientation --> <Orientation degree="90"/> </Device> </ExternalCamera>
hardware/interfaces/camera/device/3.4/default/RgaCropScale.cpp
diff --git a/hardware/interfaces/camera/device/3.4/default/RgaCropScale.cpp b/hardware/interfaces/camera/device/3.4/default/RgaCropScale.cpp index 23d018fb6d..4829d1d664 100644 --- a/hardware/interfaces/camera/device/3.4/default/RgaCropScale.cpp +++ b/hardware/interfaces/camera/device/3.4/default/RgaCropScale.cpp @@ -21,21 +21,21 @@ namespace android { namespace camera2 { -#if (defined(TARGET_RK32) || defined(TARGET_RK3368)) +//#if (defined(TARGET_RK32) || defined(TARGET_RK3368)) #define RGA_VER (2.0) #define RGA_ACTIVE_W (4096) #define RGA_VIRTUAL_W (4096) #define RGA_ACTIVE_H (4096) #define RGA_VIRTUAL_H (4096) -#else -#define RGA_VER (1.0) -#define RGA_ACTIVE_W (2048) -#define RGA_VIRTUAL_W (4096) -#define RGA_ACTIVE_H (2048) -#define RGA_VIRTUAL_H (2048) +//#else +//#define RGA_VER (1.0) +//#define RGA_ACTIVE_W (2048) +//#define RGA_VIRTUAL_W (4096) +//#define RGA_ACTIVE_H (2048) +//#define RGA_VIRTUAL_H (2048) -#endif +//#endif
这部分不修改会导致以下问题:
and...ternal-service E (dst_width > RGA_VIRTUAL_W) || (dst_height > RGA_VIRTUAL_H), switch to arm and...ternal-service I uid=1047(cameraserver) ExtCamOut identical 2 lines and...ternal-service E (dst_width > RGA_VIRTUAL_W) || (dst_height > RGA_VIRTUAL_H), switch to arm com...d.quickpreview I Background concurrent copying GC freed 306(35KB) AllocSpace objects, 3(35MB) LOS objects, 48% free, 25MB/49MB, paused 862us total 143.804ms and...ternal-service E (dst_width > RGA_VIRTUAL_W) || (dst_height > RGA_VIRTUAL_H), switch to arm and...ternal-service E (dst_width > RGA_VIRTUAL_W) || (dst_height > RGA_VIRTUAL_H), switch to arm and...er@2.1-service I [File] : hardware/rockchip/libgralloc/bifrost/src/core/mali_gralloc_formats.cpp; [Line] : 1858; [Func] : rk_gralloc_select_format; AFBC IS disabled for fb_target_layer. and...ternal-service E (dst_width > RGA_VIRTUAL_W) || (dst_height > RGA_VIRTUAL_H), switch to arm and...ternal-service I uid=1047(cameraserver) ExtCamOut identical 2 lines and...ternal-service E (dst_width > RGA_VIRTUAL_W) || (dst_height > RGA_VIRTUAL_H), switch to arm and...ternal-service D @debugShowFPS(1171): Camera 2176 Frames, 30.105 FPS and...ternal-service E (dst_width > RGA_VIRTUAL_W) || (dst_height > RGA_VIRTUAL_H), switch to arm and...ternal-service I uid=1047(cameraserver) ExtCamOut identical 2 lines and...ternal-service E (dst_width > RGA_VIRTUAL_W) || (dst_height > RGA_VIRTUAL_H), switch to arm and...er@2.1-service I [File] : hardware/rockchip/libgralloc/bifrost/src/core/mali_gralloc_formats.cpp; [Line] : 1858; [Func] : rk_gralloc_select_format; AFBC IS disabled for fb_target_layer. and...ternal-service E (dst_width > RGA_VIRTUAL_W) || (dst_height > RGA_VIRTUAL_H), switch to arm and...ternal-service I uid=1047(cameraserver) ExtCamOut identical 4 lines and...ternal-service E (dst_width > RGA_VIRTUAL_W) || (dst_height > RGA_VIRTUAL_H), switch to arm and...er@2.1-service I [File] : hardware/rockchip/libgralloc/bifrost/src/core/mali_gralloc_formats.cpp; [Line] : 1858; [Func] : rk_gralloc_select_format; AFBC IS disabled for fb_target_layer.
frameworks/av/services/camera/libcameraservice/api1/client2/Parameters.h
上层接口解除1080P的限制.
diff --git a/frameworks/av/services/camera/libcameraservice/api1/client2/Parameters.h b/frameworks/av/services/camera/libcameraservice/api1/client2/Parameters.h index 3a709c9791..2ee332a8c8 100644 --- a/frameworks/av/services/camera/libcameraservice/api1/client2/Parameters.h +++ b/frameworks/av/services/camera/libcameraservice/api1/client2/Parameters.h @@ -199,11 +199,11 @@ struct Parameters { // Max preview size allowed // This is set to a 1:1 value to allow for any aspect ratio that has // a max long side of 1920 pixels - static const unsigned int MAX_PREVIEW_WIDTH = 1920; - static const unsigned int MAX_PREVIEW_HEIGHT = 1920; + static const unsigned int MAX_PREVIEW_WIDTH = 3840; + static const unsigned int MAX_PREVIEW_HEIGHT = 2160; // Initial max preview/recording size bound - static const int MAX_INITIAL_PREVIEW_WIDTH = 1920; - static const int MAX_INITIAL_PREVIEW_HEIGHT = 1080; + static const int MAX_INITIAL_PREVIEW_WIDTH = 3840; + static const int MAX_INITIAL_PREVIEW_HEIGHT = 2160; // Aspect ratio tolerance static const CONSTEXPR float ASPECT_RATIO_TOLERANCE = 0.001; // Threshold for slow jpeg mode
编译验证
# 编译
mmm hardware/interfaces/camera/device/3.4/default/
# push 到主板
#adb push out/target/product/rk3566_r/vendor/lib64/hw/camera.rk30board.so /vendor/lib64/hw/
#adb push out/target/product/rk3566_r/vendor/lib/hw/camera.rk30board.so /vendor/lib/hw/
adb push out/target/product/rk3566_r/vendor/lib/camera.device@3.4-external-impl.so /vendor/lib/
adb push out/target/product/rk3566_r/vendor/lib64/camera.device@3.4-external-impl.so /vendor/lib64/
# 编译
mmm /disk4/anson/rk3568_a11/frameworks/av/services/camera/libcameraservice/:libcameraservice
adb push out/target/product/rk3566_r/system/lib/libcameraservice.so /system/lib/
adb push out/target/product/rk3566_r/system/lib64/libcameraservice.so /system/lib64/
小插曲
RK的Linux 烧录工具
# 低版本可以烧录 system.img
# -s system.img
# 新版本的SDK中,烧录super.img
Linux_Upgrade_Tool_v1.65/upgrade_tool DI -super super.img
# 烧录完整固件
Linux_Upgrade_Tool_v1.65/upgrade_tool UF update.img
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。