当前位置:   article > 正文

RK3568平台(camera篇)安卓hal3适配usb camera_androidhal添加对usb camera的支持

androidhal添加对usb camera的支持

一.RK安卓hal3 camera框架

Camera hal3 在 android 框架中所处的位置如上图, 对上,主要实现 Framework 一整套 API 接口,响应其 控制命令,返回数据与控制参数结果。 对下, 主要是通 V4l2 框架实现与 kernel 的交互。3a 控制则是通 control loop 接口与 camera_engine_isp 交互。 另外,其中一些组件或功能的实现也会调用到其他一些第三方 库, 如 cameraBuffer 相关,会调用到 Galloc 相关库, jpeg 编码则会调用到 Hwjpeg 相关库。

二.Camera hal3 与 Frame work 交互时序 

三.usbcamera调试

首先硬件给usb供电,供电后插上usbcamera可以看到新生成的pid vid。

ls /dev/video*

新生成了video1 video2.

media-ctl -d /dev/media0 -p
  1. 1|console:/ # media-ctl -d /dev/media0 -p
  2. Opening media device /dev/media0
  3. Enumerating entities
  4. Found 4 entities
  5. Enumerating pads and links
  6. Media controller API version 0.0.189
  7. Media device information
  8. ------------------------
  9. driver uvcvideo
  10. model USB2.0 PC CAMERA: USB2.0 PC CAM
  11. serial
  12. bus info usb-fc880000.usb-1.3
  13. hw revision 0x100
  14. driver version 0.0.189
  15. Device topology
  16. - entity 1: USB2.0 PC CAMERA: USB2.0 PC CAM (1 pad, 1 link)
  17. type Node subtype V4L
  18. device node name /dev/video1
  19. pad0: Sink
  20. <- "Processing 2":1 [ENABLED,IMMUTABLE]
  21. - entity 4: USB2.0 PC CAMERA: USB2.0 PC CAM (0 pad, 0 link)
  22. type Node subtype V4L
  23. device node name /dev/video2
  24. - entity 8: Processing 2 (2 pads, 2 links)
  25. type V4L2 subdev subtype Unknown
  26. pad0: Sink
  27. v4l2_subdev_open: Failed to open subdev device node
  28. <- "Input 1":0 [ENABLED,IMMUTABLE]
  29. pad1: Source
  30. v4l2_subdev_open: Failed to open subdev device node
  31. -> "USB2.0 PC CAMERA: USB2.0 PC CAM":0 [ENABLED,IMMUTABLE]
  32. - entity 11: Input 1 (1 pad, 1 link)
  33. type V4L2 subdev subtype Sensor
  34. pad0: Source
  35. v4l2_subdev_open: Failed to open subdev device node
  36. -> "Processing 2":0 [ENABLED,IMMUTABLE]

 查看拓扑图,生成新的video1 video2.

dumpsys media.camera
  1. onsole:/ # dumpsys media.camera
  2. == Service global info: ==
  3. Number of camera devices: 1
  4. Number of normal camera devices: 1
  5. Number of public camera devices visible to API1: 1
  6. Device 0 maps to "101"
  7. Active Camera Clients:
  8. []
  9. Allowed user IDs: 0
  10. == Camera service events log (most recent at top): ==
  11. 02-01 18:52:22 : ADD device 101, reason: (Device added)
  12. 02-01 18:50:29 : REMOVE device 101, reason: (Device status changed from 1 to 0)
  13. 02-01 18:08:37 : DISCONNECT device 101 client for package com.android.camera2 (PID 6195)
  14. 02-01 18:08:37 : CONNECT device 101 client for package com.android.camera2 (PID 6195)
  15. 02-01 18:06:25 : ADD device 101, reason: (Device added)
  16. 02-01 18:06:16 : REMOVE device 101, reason: (Device status changed from 1 to 0)
  17. 02-01 18:03:23 : ADD device 101, reason: (Device added)
  18. 02-01 18:01:26 : REMOVE device 101, reason: (Device status changed from 1 to 0)
  19. 02-01 18:00:53 : DISCONNECT device 101 client for package com.android.camera2 (PID 4701)
  20. 02-01 18:00:53 : CONNECT device 101 client for package com.android.camera2 (PID 4701)
  21. 02-01 18:00:34 : DISCONNECT device 101 client for package com.android.camera2 (PID 3004)
  22. 02-01 18:00:34 : CONNECT device 101 client for package com.android.camera2 (PID 3004)
  23. 02-01 18:00:29 : DISCONNECT device 101 client for package com.android.camera2 (PID 3004)
  24. 02-01 18:00:29 : CONNECT device 101 client for package com.android.camera2 (PID 3004)
  25. 02-01 18:00:04 : ADD device 101, reason: (Device added)
  26. 02-01 18:00:01 : USER_SWITCH previous allowed user IDs: <None>, current allowed user IDs: 0
  27. == Camera device 101 dynamic info: ==
  28. Device 101 is closed, no client instance
  29. == Camera Provider HAL external/0-0 (v2.5, remote) static info: 1 devices: ==
  30. == Camera HAL device device@3.4/external/101 (v3.4) static information: ==
  31. Resource cost: 100
  32. Conflicting devices: None
  33. API1 info:
  34. Has a flash unit: false
  35. Facing: Front
  36. Orientation: 0
  37. API2 camera characteristics:
  38. Dumping camera metadata array: 55 / 55 entries, 2048 / 2048 bytes of extra data.
  39. Version: 1, Flags: 00000000
  40. android.info.supportedHardwareLevel (150000): byte[1]
  41. [EXTERNAL ]
  42. android.colorCorrection.availableAberrationModes (00004): byte[1]
  43. [0 ]
  44. android.control.aeAvailableAntibandingModes (10012): byte[1]
  45. [3 ]
  46. android.control.maxRegions (1001c): int32[3]
  47. [0 0 0 ]
  48. android.control.availableVideoStabilizationModes (1001a): byte[1]
  49. [0 ]
  50. android.control.awbAvailableModes (1001b): byte[1]
  51. [1 ]
  52. android.control.aeAvailableModes (10013): byte[1]
  53. [1 ]
  54. android.control.availableEffects (10018): byte[1]
  55. [0 ]
  56. android.control.availableModes (10026): byte[2]
  57. [0 1 ]
  58. android.edge.availableEdgeModes (30002): byte[1]
  59. [0 ]
  60. android.flash.info.available (50000): byte[1]
  61. [FALSE ]
  62. android.hotPixel.availableHotPixelModes (60001): byte[1]
  63. [0 ]
  64. android.jpeg.availableThumbnailSizes (70007): int32[14]
  65. [0 0 176 144 ]
  66. [240 144 256 144 ]
  67. [240 160 256 154 ]
  68. [240 180 ]
  69. android.jpeg.maxSize (70008): int32[1]
  70. [3145728 ]
  71. android.lens.info.focusDistanceCalibration (90007): byte[1]
  72. [UNCALIBRATED ]
  73. android.lens.info.availableOpticalStabilization (90003): byte[1]
  74. [0 ]
  75. android.lens.facing (80005): byte[1]
  76. [FRONT ]
  77. android.noiseReduction.availableNoiseReductionModes (a0002): byte[1]
  78. [0 ]
  79. android.noiseReduction.mode (a0000): byte[1]
  80. [OFF ]
  81. android.request.partialResultCount (c000b): int32[1]
  82. [1 ]
  83. android.request.pipelineMaxDepth (c000a): byte[1]
  84. [4 ]
  85. android.request.maxNumOutputStreams (c0006): int32[3]
  86. [0 2 1 ]
  87. android.request.maxNumInputStreams (c0008): int32[1]
  88. [0 ]
  89. android.scaler.availableMaxDigitalZoom (d0004): float[1]
  90. [4.00000000 ]
  91. android.scaler.croppingType (d000d): byte[1]
  92. [CENTER_ONLY ]
  93. android.sensor.availableTestPatternModes (e0019): int32[2]
  94. [0 1 ]
  95. android.sensor.info.timestampSource (f0008): byte[1]
  96. [UNKNOWN ]
  97. android.sensor.orientation (e000e): int32[1]
  98. [0 ]
  99. android.shading.availableModes (100002): byte[1]
  100. [0 ]
  101. android.statistics.info.availableFaceDetectModes (120000): byte[1]
  102. [0 ]
  103. android.statistics.info.maxFaceCount (120002): int32[1]
  104. [0 ]
  105. android.statistics.info.availableHotPixelMapModes (120006): byte[1]
  106. [0 ]
  107. android.statistics.info.availableLensShadingMapModes (120007): byte[1]
  108. [0 ]
  109. android.sync.maxLatency (170001): int32[1]
  110. [UNKNOWN ]
  111. android.request.availableRequestKeys (c000d): int32[28]
  112. [3 65536 65537 65538 ]
  113. [65539 65542 65541 65543 ]
  114. [65545 65546 65547 65549 ]
  115. [65550 65551 65552 65553 ]
  116. [262146 458755 458756 458757 ]
  117. [458758 524292 655360 851968 ]
  118. [917528 1114112 1114115 65583 ]
  119. android.request.availableResultKeys (c000e): int32[35]
  120. [3 65536 65537 65538 ]
  121. [65539 65542 65567 65541 ]
  122. [65543 65568 65545 65546 ]
  123. [65547 65570 65549 65550 ]
  124. [65551 65552 65553 262146 ]
  125. [262149 458755 458756 458757 ]
  126. [458758 524292 655360 786441 ]
  127. [851968 917520 1114112 1114115 ]
  128. [1114128 1114126 65583 ]
  129. android.request.availableCharacteristicsKeys (c000f): int32[43]
  130. [4 65554 65555 65556 ]
  131. [65557 65558 65572 65559 ]
  132. [65560 65574 65561 65562 ]
  133. [65563 65573 65564 327680 ]
  134. [1376256 458759 524293 589827 ]
  135. [589831 655362 786444 786440 ]
  136. [786438 786443 786442 851972 ]
  137. [851978 851981 983040 983044 ]
  138. [983046 983050 983048 917518 ]
  139. [1048578 1179648 1179654 1179655 ]
  140. [1179650 1507329 65582 ]
  141. android.control.aeCompensationRange (10015): int32[2]
  142. [0 0 ]
  143. android.control.aeCompensationStep (10016): rational[1]
  144. [(0 / 1) ]
  145. android.control.afAvailableModes (10017): byte[2]
  146. [1 0 ]
  147. android.control.availableSceneModes (10019): byte[1]
  148. [0 ]
  149. android.control.aeLockAvailable (10024): byte[1]
  150. [FALSE ]
  151. android.control.awbLockAvailable (10025): byte[1]
  152. [FALSE ]
  153. android.scaler.availableStreamConfigurations (d000a): int32[72]
  154. [33 160 120 OUTPUT ]
  155. [35 160 120 OUTPUT ]
  156. [34 160 120 OUTPUT ]
  157. [33 176 144 OUTPUT ]
  158. [35 176 144 OUTPUT ]
  159. [34 176 144 OUTPUT ]
  160. [33 320 240 OUTPUT ]
  161. [35 320 240 OUTPUT ]
  162. [34 320 240 OUTPUT ]
  163. [33 352 288 OUTPUT ]
  164. [35 352 288 OUTPUT ]
  165. [34 352 288 OUTPUT ]
  166. [33 640 480 OUTPUT ]
  167. [35 640 480 OUTPUT ]
  168. [34 640 480 OUTPUT ]
  169. [33 800 600 OUTPUT ]
  170. [35 800 600 OUTPUT ]
  171. [34 800 600 OUTPUT ]
  172. android.scaler.availableMinFrameDurations (d000b): int64[72]
  173. [33 160 ]
  174. [120 33333333 ]
  175. [35 160 ]
  176. [120 33333333 ]
  177. [34 160 ]
  178. [120 33333333 ]
  179. [33 176 ]
  180. [144 33333333 ]
  181. [35 176 ]
  182. [144 33333333 ]
  183. [34 176 ]
  184. [144 33333333 ]
  185. [33 320 ]
  186. [240 33333333 ]
  187. [35 320 ]
  188. [240 33333333 ]
  189. [34 320 ]
  190. [240 33333333 ]
  191. [33 352 ]
  192. [288 33333333 ]
  193. [35 352 ]
  194. [288 33333333 ]
  195. [34 352 ]
  196. [288 33333333 ]
  197. [33 640 ]
  198. [480 33333333 ]
  199. [35 640 ]
  200. [480 33333333 ]
  201. [34 640 ]
  202. [480 33333333 ]
  203. [33 800 ]
  204. [600 33333333 ]
  205. [35 800 ]
  206. [600 33333333 ]
  207. [34 800 ]
  208. [600 33333333 ]
  209. android.scaler.availableStallDurations (d000c): int64[72]
  210. [33 160 ]
  211. [120 1000000000 ]
  212. [35 160 ]
  213. [120 0 ]
  214. [34 160 ]
  215. [120 0 ]
  216. [33 176 ]
  217. [144 1000000000 ]
  218. [35 176 ]
  219. [144 0 ]
  220. [34 176 ]
  221. [144 0 ]
  222. [33 320 ]
  223. [240 1000000000 ]

dump出来可以看到生成新的cameraid。

Number of camera devices: 1

Number of normal camera devices: 1

v4l2-ctl -d /dev/video1 --all

 查看video1信息

  1. 130|console:/ # v4l2-ctl -d /dev/video1 --all
  2. Driver Info:
  3. Driver name : uvcvideo
  4. Card type : USB2.0 PC CAMERA: USB2.0 PC CAM
  5. Bus info : usb-fc880000.usb-1.3
  6. Driver version : 5.10.189
  7. Capabilities : 0x84a00001
  8. Video Capture
  9. Metadata Capture
  10. Streaming
  11. Extended Pix Format
  12. Device Capabilities
  13. Device Caps : 0x04200001
  14. Video Capture
  15. Streaming
  16. Extended Pix Format
  17. Media Driver Info:
  18. Driver name : uvcvideo
  19. Model : USB2.0 PC CAMERA: USB2.0 PC CAM
  20. Serial :
  21. Bus info : usb-fc880000.usb-1.3
  22. Media version : 5.10.189
  23. Hardware revision: 0x00000100 (256)
  24. Driver version : 5.10.189
  25. Interface Info:
  26. ID : 0x03000002
  27. Type : V4L Video
  28. Entity Info:
  29. ID : 0x00000001 (1)
  30. Name : USB2.0 PC CAMERA: USB2.0 PC CAM
  31. Function : V4L2 I/O
  32. Pad 0x01000007 : Sink
  33. Link 0x0200000d: from remote pad 0x100000a of entity 'Processing 2': Data, Enabled, Immutable
  34. Priority: 2
  35. Video input : 0 (Input 1: ok)
  36. Format Video Capture:
  37. Width/Height : 640/480
  38. Pixel Format : 'YUYV'
  39. Field : None
  40. Bytes per Line : 1280
  41. Size Image : 614400
  42. Colorspace : Default
  43. Transfer Function : Default (maps to Rec. 709)
  44. YCbCr/HSV Encoding: Default (maps to ITU-R 601)
  45. Quantization : Default (maps to Limited Range)
  46. Flags :
  47. Crop Capability Video Capture:
  48. Bounds : Left 0, Top 0, Width 640, Height 480
  49. Default : Left 0, Top 0, Width 640, Height 480
  50. Pixel Aspect: 1/1
  51. Selection: crop_default, Left 0, Top 0, Width 640, Height 480, Flags:
  52. Selection: crop_bounds, Left 0, Top 0, Width 640, Height 480, Flags:
  53. Streaming Parameters Video Capture:
  54. Capabilities : timeperframe
  55. Frames per second: 30.000 (30/1)
  56. Read buffers : 0
  57. brightness 0x00980900 (int) : min=0 max=255 step=1 default=128 value=128
  58. contrast 0x00980901 (int) : min=0 max=255 step=1 default=135 value=135
  59. saturation 0x00980902 (int) : min=0 max=255 step=1 default=75 value=75
  60. hue 0x00980903 (int) : min=-127 max=127 step=1 default=0 value=0
  61. gamma 0x00980910 (int) : min=1 max=8 step=1 default=4 value=4
  62. power_line_frequency 0x00980918 (menu) : min=0 max=2 default=1 value=1
  63. sharpness 0x0098091b (int) : min=0 max=15 step=1 default=5 value=5
  64. backlight_compensation 0x0098091c (int) : min=1 max=5 step=1 default=1 value=1
v4l2-ctl -d /dev/video1 --list-formats-ext

查看video1支持的格式和分辨率

  1. console:/ # v4l2-ctl -d /dev/video1 --list-formats-ext
  2. ioctl: VIDIOC_ENUM_FMT
  3. Index : 0
  4. Type : Video Capture
  5. Pixel Format: 'YUYV'
  6. Name : YUYV 4:2:2
  7. Size: Discrete 640x480
  8. Interval: Discrete 0.033s (30.000 fps)
  9. Interval: Discrete 0.067s (15.000 fps)
  10. Size: Discrete 352x288
  11. Interval: Discrete 0.033s (30.000 fps)
  12. Interval: Discrete 0.067s (15.000 fps)
  13. Size: Discrete 320x240
  14. Interval: Discrete 0.033s (30.000 fps)
  15. Interval: Discrete 0.067s (15.000 fps)
  16. Size: Discrete 176x144
  17. Interval: Discrete 0.033s (30.000 fps)
  18. Interval: Discrete 0.067s (15.000 fps)
  19. Size: Discrete 160x120
  20. Interval: Discrete 0.033s (30.000 fps)
  21. Interval: Discrete 0.067s (15.000 fps)

分析:此时打开usbcamera的画面是黑屏,查看hal3 camera框架里面适配的分辨率和视频格式是否支持yuvv,最大的分辨率为640*480.

四.代码修改点亮usbcamera

  1. --- a/rk3588_an13/device/rockchip/common/external_camera_config.xml
  2. +++ b/rk3588_an13/device/rockchip/common/external_camera_config.xml
  3. @@ -7,7 +7,8 @@
  4. <!-- See ExternalCameraUtils.cpp for default values of Device configurations below-->
  5. <Device>
  6. <!-- Max JPEG buffer size in bytes-->
  7. - <MaxJpegBufferSize bytes="3145728"/> <!-- 3MB (~= 1080p YUV420) -->
  8. + <!-- MaxJpegBufferSize bytes="3145728"/> --> <!-- 3MB (~= 1080p YUV420) -->
  9. + <MaxJpegBufferSize bytes="13631488"/> <!-- 13MB 1300w pixel (~= 4k YUV420) -->
  10. <!-- Size of v4l2 buffer queue when streaming >= 30fps -->
  11. <!-- Larger value: more request can be cached pipeline (less janky) -->
  12. <!-- Smaller value: use less memory -->
  1. --- a/rk3588_an13/frameworks/av/services/camera/libcameraservice/api1/client2/Parameters.h
  2. +++ b/rk3588_an13/frameworks/av/services/camera/libcameraservice/api1/client2/Parameters.h
  3. @@ -199,11 +199,11 @@ struct Parameters {
  4. // Max preview size allowed
  5. // This is set to a 1:1 value to allow for any aspect ratio that has
  6. // a max long side of 1920 pixels
  7. - static const unsigned int MAX_PREVIEW_WIDTH = 1920;
  8. - static const unsigned int MAX_PREVIEW_HEIGHT = 1920;
  9. + static const unsigned int MAX_PREVIEW_WIDTH = 640;
  10. + static const unsigned int MAX_PREVIEW_HEIGHT = 480;
  11. // Initial max preview/recording size bound
  12. - static const int MAX_INITIAL_PREVIEW_WIDTH = 1920;
  13. - static const int MAX_INITIAL_PREVIEW_HEIGHT = 1080;
  14. + static const int MAX_INITIAL_PREVIEW_WIDTH = 640;
  15. + static const int MAX_INITIAL_PREVIEW_HEIGHT = 480;
  1. --- a/rk3588_an13/hardware/interfaces/camera/device/3.4/default/ExternalCameraDevice.cpp
  2. +++ b/rk3588_an13/hardware/interfaces/camera/device/3.4/default/ExternalCameraDevice.cpp
  3. @@ -52,7 +52,7 @@ constexpr int MAX_RETRY = 5; // Allow retry v4l2 open failures a few times.
  4. constexpr int OPEN_RETRY_SLEEP_US = 100000; // 100ms * MAX_RETRY = 0.5 seconds
  5. static uint Camera_Resolution[][2] = {{320,240},/*{352,288},*/
  6. - {640,480},{800,600},/*{1280,720},{1280,960},{1920,1080},{2048,1536},{2560,1440},{2592,1944},{2592,1456},*/
  7. + {640,480},/*{800,600},{1280,720},{1280,960},{1920,1080},{2048,1536},{2560,1440},{2592,1944},{2592,1456},*/
  8. {0,0}};
  9. } // anonymous namespace
  10. @@ -444,7 +444,8 @@ status_t ExternalCameraDevice::initDefaultCharsKeys(
  11. 256, 144,
  12. 240, 160,
  13. 256, 154,
  14. - 240, 180};
  15. + 240, 180,
  16. + 640, 480};
  17. UPDATE(ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES, jpegAvailableThumbnailSizes,
  18. ARRAY_SIZE(jpegAvailableThumbnailSizes));
  1. --- a/rk3588_an13/hardware/interfaces/camera/device/3.4/default/RgaCropScale.cpp
  2. +++ b/rk3588_an13/hardware/interfaces/camera/device/3.4/default/RgaCropScale.cpp
  3. @@ -38,6 +38,11 @@ namespace camera2 {
  4. #define RGA_ACTIVE_H (2048)
  5. #define RGA_VIRTUAL_H (2048)
  6. +#define RGA_ACTIVE_W (640)
  7. +#define RGA_VIRTUAL_W (640)
  8. +#define RGA_ACTIVE_H (480)
  9. +#define RGA_VIRTUAL_H (480)
  10. +
  11. #endif

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/784502
推荐阅读
相关标签
  

闽ICP备14008679号