Rockchip_Developer_Guide_Linux_Software_CN.pdf
Rockchip_Developer_Guide_Buildroot_CN.pdf
buildroot 添加 ffmpeg
diff --git a/buildroot/configs/rockchip/multimedia/ffmpeg.config b/buildroot/configs/rockchip/multimedia/ffmpeg.config
new file mode 100644
index 000000000..34eadb644
--- /dev/null
+++ b/buildroot/configs/rockchip/multimedia/ffmpeg.config
@@ -0,0 +1,2 @@
+BR2_PACKAGE_FFMPEG=y
+BR2_PACKAGE_FFMPEG_SWSCALE=y
diff --git a/buildroot/configs/rockchip_rk3568_defconfig b/buildroot/configs/rockchip_rk3568_defconfig
index 0637322b6..4e44f2449 100644
--- a/buildroot/configs/rockchip_rk3568_defconfig
+++ b/buildroot/configs/rockchip_rk3568_defconfig
@@ -6,6 +6,7 @@
#include "fs/vfat.config"
#include "gpu/gpu.config"
#include "multimedia/audio.config"
+#include "multimedia/ffmpeg.config"
#include "multimedia/camera.config"
#include "multimedia/gst/audio.config"
#include "multimedia/gst/camera.config"
编译
./build.sh buildroot
USB Gadget
Rockchip_Quick_Start_Linux_USB_Gadget_CN.pdf
Rockchip_Trouble_Shooting_Linux4.19_USB_Gadget_UVC_CN.pdf
kernel/arch/arm64/configs/rockchip_linux_defconfig
CONFIG_USB_GADGET=y
CONFIG_USB_GADGET_DEBUG_FILES=y
CONFIG_USB_GADGET_VBUS_DRAW=500
CONFIG_USB_CONFIGFS=y
CONFIG_USB_CONFIGFS_UEVENT=y
CONFIG_USB_CONFIGFS_ACM=y
CONFIG_USB_CONFIGFS_RNDIS=y
CONFIG_USB_CONFIGFS_MASS_STORAGE=y
CONFIG_USB_CONFIGFS_F_FS=y
CONFIG_USB_CONFIGFS_F_UAC1=y
CONFIG_USB_CONFIGFS_F_UAC1_LEGACY=y
CONFIG_USB_CONFIGFS_F_UAC2=y
CONFIG_USB_CONFIGFS_F_MIDI=y
CONFIG_USB_CONFIGFS_F_HID=y
CONFIG_USB_CONFIGFS_F_UVC=y
RKScript中,有三个USB相关文件:
S50usbdevice # /etc/init.d/ 使用时,配合同级目录的.usb_config使用
usbdevice # /usr/bin/
61-usbdevice.rules # /lib/udev/rules.d/
#还有两个相关文件需要用户自建或修改
.usb_config # /etc/init.d/
/tmp/.usb_config # S50usbdevice 自动生成
./buildroot/output/rockchip_rk3568/target/etc/init.d/S50usbdevice.sh
#!/bin/sh
### BEGIN INIT INFO
# Provides: usbdevice
# Required-Start: $local_fs $syslog
# Required-Stop: $local_fs
# Default-Start: S
# Default-Stop: K
# Description: Manage USB device functions
### END INIT INFO
case "$1" in
start|stop|restart)
/sbin/start-stop-daemon -Sbx /usr/bin/usbdevice $1
;;
*)
echo "Usage: [start|stop|restart]" >&2
exit 3
;;
esac
:
.usb_config 支持的配置项
#!/bin/sh
# 启用 ADB 调试功能
usb_adb_en=1
# 启用 USB 音频类 1.0(兼容性好)
usb_uac1_en=0
# 启用 USB 音频类 2.0(高质量音频)
usb_uac2_en=1
# 启用 USB 网络共享功能(RNDIS 协议)
usb_rndis_en=1
# 启用 MTP 模式(媒体文件传输)
usb_mtp_en=1
# 启用 USB 大容量存储(UMS,如 U 盘模式)
usb_ums_en=0
# 启用 USB 串口通信(ACM)
usb_acm_en=1
# 启用 USB 视频类(UVC,支持摄像头)
usb_uvc_en=1
配置USB Gadget UVC
diff --git a/buildroot/board/rockchip/rk3566_rk3568/fs-overlay/etc/init.d/.usb_config b/buildroot/board/rockchip/rk3566_rk3568/fs-overlay/etc/init.d/.usb_config
index 3de3a0bb7..a41345923 100644
--- a/buildroot/board/rockchip/rk3566_rk3568/fs-overlay/etc/init.d/.usb_config
+++ b/buildroot/board/rockchip/rk3566_rk3568/fs-overlay/etc/init.d/.usb_config
@@ -1 +1 @@
-usb_adb_en
+usb_uvc_en
diff --git a/external/rkscript/S50usbdevice.sh b/external/rkscript/S50usbdevice.sh
index 9679d40b9..282d49cdc 100755
--- a/external/rkscript/S50usbdevice.sh
+++ b/external/rkscript/S50usbdevice.sh
@@ -10,7 +10,9 @@
case "$1" in
start|stop|restart)
+ /usr/bin/uvc_config.sh
/sbin/start-stop-daemon -Sbx /usr/bin/usbdevice $1
+ /sbin/start-stop-daemon --start --quiet --background --exec /usr/bin/uvc_app -- 640 480
;;
*)
echo "Usage: [start|stop|restart]" >&2
上述修改配置好后 RK3568 USB 插入后的日志
[ 20.486987] dwc3 fcc00000.dwc3: device reset
[ 20.668248] dwc3 fcc00000.dwc3: device reset
[ 20.865929] android_work: sent uevent USB_STATE=CONNECTED
[ 20.899630] configfs-gadget gadget: uvc: uvc_function_set_alt(0, 0)
[ 20.899709] configfs-gadget gadget: uvc: reset UVC Control
[ 20.899750] configfs-gadget gadget: uvc: uvc_function_set_alt(1, 0)
[ 20.899938] android_work: sent uevent USB_STATE=CONFIGURED
ubuntu lsusb命令显示的 usb 设备(未被识别成UVC摄像头)
Bus 001 Device 017: ID 2207:0005 Fuzhou Rockchip Electronics Company rk3xxx
android端日志
[ 128.409060] usb 7-1: new high-speed USB device number 4 using xhci-hcd
[ 128.551376] usb 7-1: New USB device found, idVendor=2207, idProduct=0005, bcdDevice= 3.10
[ 128.551457] usb 7-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 128.551485] usb 7-1: Product: UVC
[ 128.551508] usb 7-1: Manufacturer: Rockchip
[ 128.551529] usb 7-1: SerialNumber: 2020
[ 128.638262] input: UVC: UVC Camera as /devices/platform/usbdrd/fcc00000.dwc3/xhci-hcd.6.auto/usb7/7-1/7-1:1.0/input/input8
external/rkscript/usbdevice
rockchip-linux-rkscript_usbdevice
external/uvc_app/uvc_config.sh
#!/bin/sh
USB_ROCKCHIP_DIR=/sys/kernel/config/usb_gadget/rockchip/
USB_FUNCTIONS_DIR=${USB_ROCKCHIP_DIR}/functions/
UVC_DIR=${USB_FUNCTIONS_DIR}/uvc.gs6/
UVC_STREAMING_DIR=${UVC_DIR}/streaming/
UVC_CONTROL_DIR=${UVC_DIR}/control/
UVC_U_DIR=${UVC_STREAMING_DIR}/uncompressed/u/
UVC_M_DIR=${UVC_STREAMING_DIR}/mjpeg/m/
UVC_F_DIR=${UVC_STREAMING_DIR}/framebased/f/
configure_uvc_resolution_yuyv()
{
W=$1
H=$2
DIR=${UVC_U_DIR}/${H}p/
mkdir ${DIR}
echo $W > ${DIR}/wWidth
echo $H > ${DIR}/wHeight
echo 333333 > ${DIR}/dwDefaultFrameInterval
echo $((W*H*20)) > ${DIR}/dwMinBitRate
echo $((W*H*20)) > ${DIR}/dwMaxBitRate
echo $((W*H*2)) > ${DIR}/dwMaxVideoFrameBufferSize
echo -e "333333\n666666\n1000000\n2000000" > ${DIR}/dwFrameInterval
}
configure_uvc_resolution_mjpeg()
{
W=$1
H=$2
DIR=${UVC_M_DIR}/${H}p/
mkdir ${DIR}
echo $W > ${DIR}/wWidth
echo $H > ${DIR}/wHeight
echo 333333 > ${DIR}/dwDefaultFrameInterval
echo $((W*H*20)) > ${DIR}/dwMinBitRate
echo $((W*H*20)) > ${DIR}/dwMaxBitRate
echo $((W*H*2)) > ${DIR}/dwMaxVideoFrameBufferSize
echo -e "333333\n666666\n1000000\n2000000" > ${DIR}/dwFrameInterval
}
configure_uvc_resolution_h264()
{
W=$1
H=$2
DIR=${UVC_F_DIR}/${H}p/
mkdir ${DIR}
echo $W > ${DIR}/wWidth
echo $H > ${DIR}/wHeight
echo 333333 > ${DIR}/dwDefaultFrameInterval
echo $((W*H*10)) > ${DIR}/dwMinBitRate
echo $((W*H*10)) > ${DIR}/dwMaxBitRate
#echo $((W*H*2)) > ${DIR}/dwMaxVideoFrameBufferSize
echo -e "333333\n666666\n1000000\n2000000" > ${DIR}/dwFrameInterval
}
/etc/init.d/S10udev stop
umount /sys/kernel/config
mount -t configfs none /sys/kernel/config
mkdir -p ${USB_ROCKCHIP_DIR}
mkdir -p ${USB_ROCKCHIP_DIR}/strings/0x409
mkdir -p ${USB_ROCKCHIP_DIR}/configs/b.1/strings/0x409
echo 0x2207 > ${USB_ROCKCHIP_DIR}/idVendor
echo 0x0310 > ${USB_ROCKCHIP_DIR}/bcdDevice
echo 0x0200 > ${USB_ROCKCHIP_DIR}/bcdUSB
echo "2020" > ${USB_ROCKCHIP_DIR}/strings/0x409/serialnumber
echo "Rockchip" > ${USB_ROCKCHIP_DIR}/strings/0x409/manufacturer
echo "UVC" > ${USB_ROCKCHIP_DIR}/strings/0x409/product
mkdir ${UVC_DIR}
#echo 3072 > ${UVC_DIR}/streaming_maxpacket
#echo 1 > ${UVC_DIR}/streaming_bulk
mkdir ${UVC_CONTROL_DIR}/header/h
ln -s ${UVC_CONTROL_DIR}/header/h ${UVC_CONTROL_DIR}/class/fs/h
ln -s ${UVC_CONTROL_DIR}/header/h ${UVC_CONTROL_DIR}/class/ss/h
##YUYV support config
mkdir ${UVC_U_DIR}
configure_uvc_resolution_yuyv 640 480
configure_uvc_resolution_yuyv 1280 720
##mjpeg support config
mkdir ${UVC_M_DIR}
configure_uvc_resolution_mjpeg 640 480
configure_uvc_resolution_mjpeg 1280 720
configure_uvc_resolution_mjpeg 1920 1080
configure_uvc_resolution_mjpeg 2560 1440
configure_uvc_resolution_mjpeg 2592 1944
## h.264 support config
mkdir ${UVC_F_DIR}
configure_uvc_resolution_h264 640 480
configure_uvc_resolution_h264 1280 720
configure_uvc_resolution_h264 1920 1080
mkdir ${UVC_STREAMING_DIR}/header/h
ln -s ${UVC_U_DIR} ${UVC_STREAMING_DIR}/header/h/u
ln -s ${UVC_M_DIR} ${UVC_STREAMING_DIR}/header/h/m
ln -s ${UVC_F_DIR} ${UVC_STREAMING_DIR}/header/h/f
ln -s ${UVC_STREAMING_DIR}/header/h ${UVC_STREAMING_DIR}/class/fs/h
ln -s ${UVC_STREAMING_DIR}/header/h ${UVC_STREAMING_DIR}/class/hs/h
ln -s ${UVC_STREAMING_DIR}/header/h ${UVC_STREAMING_DIR}/class/ss/h
echo 0x1 > ${USB_ROCKCHIP_DIR}/os_desc/b_vendor_code
echo "MSFT100" > ${USB_ROCKCHIP_DIR}/os_desc/qw_sign
echo 500 > ${USB_ROCKCHIP_DIR}/configs/b.1/MaxPower
ln -s ${USB_ROCKCHIP_DIR}/configs/b.1 ${USB_ROCKCHIP_DIR}/os_desc/b.1
echo 0x0005 > ${USB_ROCKCHIP_DIR}/idProduct
echo "uvc" > ${USB_ROCKCHIP_DIR}/configs/b.1/strings/0x409/configuration
USB_CONFIGS_DIR=${USB_ROCKCHIP_DIR}/configs/b.1
if [ -e ${USB_CONFIGS_DIR}/ffs.adb ]; then
#for rk1808 kernel 4.4
rm -f ${USB_CONFIGS_DIR}/ffs.adb
else
ls ${USB_CONFIGS_DIR} | grep f[0-9] | xargs -I {} rm ${USB_CONFIGS_DIR}/{}
fi
ln -s ${UVC_DIR} ${USB_ROCKCHIP_DIR}/configs/b.1/f1
UDC=`ls /sys/class/udc/| awk '{print $1}'`
echo $UDC > ${USB_ROCKCHIP_DIR}/UDC
打开工具
Ubuntu: guvcview
Windows: Amcap
Android: com.shenyaocn.android.usbdualcamera.apk
Android
默认生成的节点
rk3568_r:/ $ ls /dev/video*
/dev/video0 /dev/video1
dumpsys camera
rk3568_r:/ $ dumpsys media.camera
== Service global info: ==
Number of camera devices: 1
Number of normal camera devices: 1
Number of public camera devices visible to API1: 1
Device 0 maps to "100"
Active Camera Clients:
[]
Allowed user IDs: 0
== Camera service events log (most recent at top): ==
05-24 16:12:15 : ADD device 100, reason: (Device added)
05-24 16:11:52 : USER_SWITCH previous allowed user IDs: <None>, current allowed user IDs: 0
== Camera device 100 dynamic info: ==
Device 100 is closed, no client instance
== Camera Provider HAL external/0 (v2.5, remote) static info: 1 devices: ==
== Camera HAL device device@3.4/external/100 (v3.4) static information: ==
Resource cost: 100
Conflicting devices: None
API1 info:
Has a flash unit: false
Facing: Front
Orientation: 0
API2 camera characteristics:
Dumping camera metadata array: 54 / 54 entries, 1800 / 1800 bytes of extra data.
Version: 1, Flags: 00000000
android.info.supportedHardwareLevel (150000): byte[1]
[EXTERNAL ]
android.colorCorrection.availableAberrationModes (00004): byte[1]
[0 ]
android.control.aeAvailableAntibandingModes (10012): byte[1]
[3 ]
android.control.maxRegions (1001c): int32[3]
[0 0 0 ]
android.control.availableVideoStabilizationModes (1001a): byte[1]
[0 ]
android.control.awbAvailableModes (1001b): byte[1]
[1 ]
android.control.aeAvailableModes (10013): byte[1]
[1 ]
android.control.availableEffects (10018): byte[1]
[0 ]
android.control.availableModes (10026): byte[2]
[0 1 ]
android.edge.availableEdgeModes (30002): byte[1]
[0 ]
android.flash.info.available (50000): byte[1]
[FALSE ]
android.hotPixel.availableHotPixelModes (60001): byte[1]
[0 ]
android.jpeg.availableThumbnailSizes (70007): int32[14]
[0 0 176 144 ]
[240 144 256 144 ]
[240 160 256 154 ]
[240 180 ]
android.jpeg.maxSize (70008): int32[1]
[3145728 ]
android.lens.info.focusDistanceCalibration (90007): byte[1]
[UNCALIBRATED ]
android.lens.info.availableOpticalStabilization (90003): byte[1]
[0 ]
android.lens.facing (80005): byte[1]
[EXTERNAL ]
android.noiseReduction.availableNoiseReductionModes (a0002): byte[1]
[0 ]
android.noiseReduction.mode (a0000): byte[1]
[OFF ]
android.request.partialResultCount (c000b): int32[1]
[1 ]
android.request.pipelineMaxDepth (c000a): byte[1]
[4 ]
android.request.maxNumOutputStreams (c0006): int32[3]
[0 2 1 ]
android.request.maxNumInputStreams (c0008): int32[1]
[0 ]
android.scaler.availableMaxDigitalZoom (d0004): float[1]
[1.00000000 ]
android.scaler.croppingType (d000d): byte[1]
[CENTER_ONLY ]
android.sensor.availableTestPatternModes (e0019): int32[1]
[0 ]
android.sensor.info.timestampSource (f0008): byte[1]
[UNKNOWN ]
android.sensor.orientation (e000e): int32[1]
[0 ]
android.shading.availableModes (100002): byte[1]
[0 ]
android.statistics.info.availableFaceDetectModes (120000): byte[1]
[0 ]
android.statistics.info.maxFaceCount (120002): int32[1]
[0 ]
android.statistics.info.availableHotPixelMapModes (120006): byte[1]
[0 ]
android.statistics.info.availableLensShadingMapModes (120007): byte[1]
[0 ]
android.sync.maxLatency (170001): int32[1]
[UNKNOWN ]
android.request.availableRequestKeys (c000d): int32[28]
[3 65536 65537 65538 ]
[65539 65542 65541 65543 ]
[65545 65546 65547 65549 ]
[65550 65551 65552 65553 ]
[262146 458755 458756 458757 ]
[458758 524292 655360 851968 ]
[917528 1114112 1114115 65583 ]
android.request.availableResultKeys (c000e): int32[35]
[3 65536 65537 65538 ]
[65539 65542 65567 65541 ]
[65543 65568 65545 65546 ]
[65547 65570 65549 65550 ]
[65551 65552 65553 262146 ]
[262149 458755 458756 458757 ]
[458758 524292 655360 786441 ]
[851968 917520 1114112 1114115 ]
[1114128 1114126 65583 ]
android.request.availableCharacteristicsKeys (c000f): int32[43]
[4 65554 65555 65556 ]
[65557 65558 65572 65559 ]
[65560 65574 65561 65562 ]
[65563 65573 65564 327680 ]
[1376256 458759 524293 589827 ]
[589831 655362 786444 786440 ]
[786438 786443 786442 851972 ]
[851978 851981 983040 983044 ]
[983046 983050 983048 917518 ]
[1048578 1179648 1179654 1179655 ]
[1179650 1507329 65582 ]
android.control.aeCompensationRange (10015): int32[2]
[0 0 ]
android.control.aeCompensationStep (10016): rational[1]
[(0 / 1) ]
android.control.afAvailableModes (10017): byte[2]
[1 0 ]
android.control.availableSceneModes (10019): byte[1]
[0 ]
android.control.aeLockAvailable (10024): byte[1]
[FALSE ]
android.control.awbLockAvailable (10025): byte[1]
[FALSE ]
android.scaler.availableStreamConfigurations (d000a): int32[60]
[33 640 480 OUTPUT ]
[35 640 480 OUTPUT ]
[34 640 480 OUTPUT ]
[33 1280 720 OUTPUT ]
[35 1280 720 OUTPUT ]
[34 1280 720 OUTPUT ]
[33 1920 1080 OUTPUT ]
[35 1920 1080 OUTPUT ]
[34 1920 1080 OUTPUT ]
[33 2560 1440 OUTPUT ]
[35 2560 1440 OUTPUT ]
[34 2560 1440 OUTPUT ]
[33 2592 1944 OUTPUT ]
[35 2592 1944 OUTPUT ]
[34 2592 1944 OUTPUT ]
android.scaler.availableMinFrameDurations (d000b): int64[60]
[33 640 ]
[480 200000000 ]
[35 640 ]
[480 200000000 ]
[34 640 ]
[480 200000000 ]
[33 1280 ]
[720 200000000 ]
[35 1280 ]
[720 200000000 ]
[34 1280 ]
[720 200000000 ]
[33 1920 ]
[1080 200000000 ]
[35 1920 ]
[1080 200000000 ]
[34 1920 ]
[1080 200000000 ]
[33 2560 ]
[1440 200000000 ]
[35 2560 ]
[1440 200000000 ]
[34 2560 ]
[1440 200000000 ]
[33 2592 ]
[1944 200000000 ]
[35 2592 ]
[1944 200000000 ]
[34 2592 ]
[1944 200000000 ]
android.scaler.availableStallDurations (d000c): int64[60]
[33 640 ]
[480 1000000000 ]
[35 640 ]
[480 0 ]
[34 640 ]
[480 0 ]
[33 1280 ]
[720 1000000000 ]
[35 1280 ]
[720 0 ]
[34 1280 ]
[720 0 ]
[33 1920 ]
[1080 1000000000 ]
[35 1920 ]
[1080 0 ]
[34 1920 ]
[1080 0 ]
[33 2560 ]
[1440 1000000000 ]
[35 2560 ]
[1440 0 ]
[34 2560 ]
[1440 0 ]
[33 2592 ]
[1944 1000000000 ]
[35 2592 ]
[1944 0 ]
[34 2592 ]
[1944 0 ]
android.control.aeAvailableTargetFpsRanges (10014): int32[2]
[2 5 ]
android.sensor.info.maxFrameDuration (f0004): int64[1]
[500000000 ]
android.sensor.info.preCorrectionActiveArraySize (f000a): int32[4]
[0 0 2592 1944 ]
android.sensor.info.activeArraySize (f0000): int32[4]
[0 0 2592 1944 ]
android.sensor.info.pixelArraySize (f0006): int32[2]
[2592 1944 ]
android.request.availableCapabilities (c000c): byte[1]
[BACKWARD_COMPATIBLE ]
android.scaler.availableRotateAndCropModes (d0010): byte[1]
[0 ]
android.control.zoomRatioRange (1002e): float[2]
[1.00000000 1.00000000 ]
== Camera HAL device device@3.4/external/100 (v3.4) dumpState: ==
No active camera device session instance
== Camera Provider HAL legacy/0 (v2.5, remote) static info: 0 devices: ==
== Vendor tags: ==
Dumping vendor tag descriptors for vendor with id 3854507339
Dumping configured vendor tag descriptors: 10 entries
0x80000000 (privatedata_effective_driver_frame_id) with type 3 (int64) defined in section org.codeaurora.rkcamera3.privatedata
0x80000001 (privatedata_frame_sof_timestamp) with type 3 (int64) defined in section org.codeaurora.rkcamera3.privatedata
0x80000002 (privatedata_stillcap_sync_needed) with type 0 (byte) defined in section org.codeaurora.rkcamera3.privatedata
0x80000003 (privatedata_stillcap_sync_cmd) with type 0 (byte) defined in section org.codeaurora.rkcamera3.privatedata
0x80000004 (privatedata_stillcap_isp_param) with type 0 (byte) defined in section org.codeaurora.rkcamera3.privatedata
0x80010000 (3dnrmode) with type 0 (byte) defined in section com.rockchip.nrfeature
0x80020000 (brightness) with type 0 (byte) defined in section com.rockchip.control.aiq
0x80020001 (contrast) with type 0 (byte) defined in section com.rockchip.control.aiq
0x80020002 (saturation) with type 0 (byte) defined in section com.rockchip.control.aiq
0x80030000 (meanluma) with type 2 (float) defined in section com.rockchip.luma
Dumping vendor tag descriptors for vendor with id 2592128789
Dumping configured vendor tag descriptors: None set
== Camera error traces (0): ==
No camera traces collected.
安卓系统打开相机时的注意事项
S50usbdevice.sh
文件中的分辨率需要在 uvc_config.sh
文件中包含
安卓app打开相机时选择的分辨率需要和 S50usbdevice.sh
文件中配置的一致