[RK3288][android7.1] Modify USB camera preview pixel resolution

1. Description

  1. Use a USB camera. Generally, the USB camera provided by the manufacturer will have built-in firmware, which supports multiple resolutions (usually you can directly plug it into the computer to see the quality of the photo and video), as shown in the figure below: You can see from the above
    insert image description herefigure The maximum pixel supported by this camera is 1.9MP (about 2 million pixels), and the maximum video recording supports 720P.
  2. Under the adb shell, the camera information can also be obtained through the command:
rk3288:/ $ dumpsys media.camera
Camera module HAL API version: 0x1
Camera module API version: 0x1
Camera module name: RK29_ICS_CameraHal_Module
Camera module author: RockChip
Number of camera devices: 1
Number of normal camera devices: 1
Active Camera Clients:
[]
Allowed users:
0
Vendor tags left unimplemented.

Prior client events (most recent at top):
  01-01 10:56:49 : DISCONNECT device 0 client for package com.android.camera3 (PID 1959)
  01-01 10:56:35 : CONNECT device 0 client for package com.android.camera3 (PID 1959)
  01-01 09:22:11 : DISCONNECT device 0 client for package com.android.camera3 (PID 1462)
  01-01 09:21:33 : CONNECT device 0 client for package com.android.camera3 (PID 1462)
  01-01 08:00:59 : DISCONNECT device 0 client for package com.android.camera3 (PID 1462)
  01-01 08:00:46 : CONNECT device 0 client for package com.android.camera3 (PID 1462)
  01-01 08:00:17 : DISCONNECT device 0 client for package cameraserver (PID 234)
  01-01 08:00:15 : USER_SWITCH previous allowed users:  , current allowed users: 0

Camera 0 information:
  Facing: BACK
  Orientation: 0
  Resource Cost: 100
  Conflicting Devices: NONE
  Device version: 0x100
  Camera1 API shim is using parameters:
        CameraParameters::dump: mMap.size = 50
        antibanding: off
        antibanding-values: off,50hz,60hz,auto
        exposure-compensation: 0
        exposure-compensation-step: 1
        focal-length: 35
        focus-distances: 0.3,50,Infinity
        focus-mode: fixed
        focus-mode-values: fixed
        horizontal-view-angle: 10
        jpeg-quality: 70
        jpeg-thumbnail-height: 128
        jpeg-thumbnail-quality: 50
        jpeg-thumbnail-size-values: 0x0,160x128
        jpeg-thumbnail-width: 160
        max-exposure-compensation: 3
        max-num-detected-faces-hw: 2
        max-num-detected-faces-sw: 0
        max-num-focus-areas: 0
        max-num-metering-areas: 0
        max-zoom: 40
        min-exposure-compensation: -3
        picture-format: jpeg
        picture-format-values: jpeg
        picture-size: 1600x1200
        picture-size-values: 640x480,320x240,160x120,352x288,176x144,1280x1024,1600x1200
        preferred-preview-size-for-video:
        preview-format: yuv420sp
        preview-format-values: yuv420sp,yuv420p
        preview-fps-range: 5000,30000
        preview-fps-range-values: (5000,30000)
        preview-frame-rate: 30
        preview-frame-rate-values: 30,15,7
        preview-size: 640x480
        preview-size-values: 640x480,320x240,160x120,352x288,176x144,1280x1024,1600x1200
        recording-hint: false
        rk-continous-pic-num: 1
        rk-previwe-h-force: 0
        rk-previwe-w-force: 0
        rotation: 0
        vertical-view-angle: 10
        video-frame-format: yuv420sp
        video-size:
        video-size-values:
        video-snapshot-supported: true
        video-stabilization-supported: false
        whitebalance: auto
        whitebalance-values: auto,incandescent,fluorescent,daylight,cloudy-daylight
        zoom: 0
        zoom-ratios: 100,105,110,115,120,125,130,135,140,145,150,155,160,165,170,175,180,185,190,195,200,205,210,215,220,225,230,235,240,
245,250,255,260,265,270,275,280,285,290,295,300,
        zoom-supported: true
  Device 0 is closed, no client instance

No active camera clients yet.

Camera traces (0):
  No camera traces collected.

Second, the problem phenomenon

But when you open the camera on the Android system, sometimes you will find that the pixels are not clear when taking pictures and video previews, and the resolution does not reach what the camera supports. Normally, the preview resolution is /data/camera/media_profiles.xml ( system/etc/media_profiles_default.xml)taken from the resolution configured in the device.
You can modify the corresponding parameters for direct verification, as follows:

adb root
adb remount
adb shell
busybox vi /data/camera/media_profiles.xml (edit and modify)
:wq (exit)
reboot


Three, the solution

If you need to specify in the source code (the path is /hardware/rockchip/camera/CameraHal/CameraUSBAdapter.cpp), you can modify it as follows:

  1. When taking pictures, modify the default PreviewSize preview resolution and PictureSize photo size, customize the preview resolution by yourself, and set 1600x1200 as the maximum resolution.
diff --git a/hardware/rockchip/camera/CameraHal/CameraUSBAdapter.cpp b/hardware/rockchip/camera/CameraHal/CameraUSBAdapter.cpp
index b565930a68..83a4888fa6 100755
--- a/hardware/rockchip/camera/CameraHal/CameraUSBAdapter.cpp
+++ b/hardware/rockchip/camera/CameraHal/CameraUSBAdapter.cpp
@@ -164,14 +164,14 @@ void CameraUSBAdapter::initDefaultParameters(int camFd)
     params.set(KEY_PREVIEW_W_FORCE,"0");
     params.set(KEY_PREVIEW_H_FORCE,"0");
-    params.set(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES, parameterString.string());
-    if(parameterString.contains("640x480"))
-        params.setPreviewSize(640,480);
+    params.set(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES, "640x480,320x240,160x120,352x288,176x144,1280x1024,1600x1200");
+    if(parameterString.contains("1600x1200"))//如果1600x1200有包含在支持分辨率KEY_SUPPORTED_PREVIEW_SIZES中为真,setPreviewSize为1600x1200;
+        params.setPreviewSize(1600,1200);
     else
         params.setPreviewSize(mCamDriverFrmWidthMax,mCamDriverFrmHeightMax);
     /*picture size setting*/      
-    params.set(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES, parameterString.string());        
-    params.setPictureSize(mCamDriverFrmWidthMax,  mCamDriverFrmHeightMax);        
+    params.set(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES, "640x480,320x240,160x120,352x288,176x144,1280x1024,1600x1200");
+    params.setPictureSize(1600,1200);
     
     /* set framerate */
     struct v4l2_streamparm setfps;
  1. When recording, set the default KEY_SUPPORTED_VIDEO_SIZES, and set 1600x1200 as the maximum preview resolution.

KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO: Set the preferred preview size when recording video
KEY_VIDEO_SIZE: Set the video size of the camera
KEY_SUPPORTED_VIDEO_SIZES: Get a list of video sizes supported by the camera

diff --git a/hardware/rockchip/camera/CameraHal/CameraUSBAdapter.cpp b/hardware/rockchip/camera/CameraHal/CameraUSBAdapter.cpp
index b565930a68..153d88407f 100755
--- a/hardware/rockchip/camera/CameraHal/CameraUSBAdapter.cpp
+++ b/hardware/rockchip/camera/CameraHal/CameraUSBAdapter.cpp
@@ -571,15 +571,15 @@ void CameraUSBAdapter::initDefaultParameters(int camFd)
#if (CONFIG_CAMERA_SETVIDEOSIZE == 0)
     if(false/*mIsCtsTest*/){
    
    
         if(gCamInfos[mCamId].facing_info.facing == CAMERA_FACING_BACK){
    
    
-             //back camera, may need to manually modify based on media_profiles.xml supported.
-             params.set(CameraParameters::KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO,"1920x1080");
-             params.set(CameraParameters::KEY_VIDEO_SIZE,"1920x1080");
-             params.set(CameraParameters::KEY_SUPPORTED_VIDEO_SIZES,"176x144,320x240,352x288,640x480,1280x720,1920x1080");
+             //back camera(后置), may need to manually modify based on media_profiles.xml supported.
+             params.set(CameraParameters::KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO,"1600x1200");
+             params.set(CameraParameters::KEY_VIDEO_SIZE,"1600x1200");
+             params.set(CameraParameters::KEY_SUPPORTED_VIDEO_SIZES,"1600x1200");
         }else{
    
    
-             //front camera
-             params.set(CameraParameters::KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO,"640x480");
-             params.set(CameraParameters::KEY_VIDEO_SIZE,"640x480");
-             params.set(CameraParameters::KEY_SUPPORTED_VIDEO_SIZES,"176x144,320x240,352x288,640x480,1280x720");
+             //front camera(前置)
+             params.set(CameraParameters::KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO,"1600x1200");
+             params.set(CameraParameters::KEY_VIDEO_SIZE,"1600x1200");
+             params.set(CameraParameters::KEY_SUPPORTED_VIDEO_SIZES,"1600x1200");
         }
     } else {
    
    
          params.set(CameraParameters::KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO,"");


The above is the method to set the preview resolution to 1600x1200. If you want to change other resolutions, you can modify the resolution you need to specify through the above method;
Note: Be sure to specify the resolution you need in the resolutions supported by the USB camera!

Guess you like

Origin blog.csdn.net/weixin_45639314/article/details/131803967