Platform: rk3399
OS: Android 7.1
Kernel: v4.4.83
有些Sensor的分辨率中并没有640x480的支持,而在camera初始化的时候是写死的。
CameraUSBAdapter.cpp:
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());
//默认是VGA分辨率。
params.setPreviewSize(640,480);
......
}
可以改成支持的分辨率,比如将它修改成了sensor最大支持分辨率:
diff --git a/hardware/rockchip/camera/CameraHal/CameraUSBAdapter.cpp b/hardware/rockchip/camera/CameraHal/CameraUSBAdapter.cpp
index b544bfa..7553976 100755
--- a/hardware/rockchip/camera/CameraHal/CameraUSBAdapter.cpp
+++ b/hardware/rockchip/camera/CameraHal/CameraUSBAdapter.cpp
@@ -144,7 +144,7 @@ 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());
- params.setPreviewSize(640,480);
+ params.setPreviewSize(mCamDriverFrmWidthMax,mCamDriverFrmHeightMax);
/*picture size setting*/
params.set(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES, parameterString.string());
setPreviewSize实质上是将分辨率映射到“KEY_PREVIEW_SIZE”去。
void CameraParameters::setPreviewSize(int width, int height)
{
char str[32];
sprintf(str, "%dx%d", width, height);
set(KEY_PREVIEW_SIZE, str);
}
Camera app在打开sensor的时候会获取setting:
getSettings -> new AndroidCameraSettings
AndroidCameraSettings extends CameraSettings {
......
// Preview
Camera.Size paramPreviewSize = params.getPreviewSize();
setPreviewSize(new Size(paramPreviewSize.width, paramPreviewSize.height));
......
}
getPreviewSize就是从KEY_PREVIEW_SIZE获取value.
AndroidCameraSettings.java:
public Size getPreviewSize() {
String pair = get(KEY_PREVIEW_SIZE);
return strToSize(pair);
}
setPreviewSize设置当前preview size:
public boolean setPreviewSize(Size previewSize) {
if (mSizesLocked) {
Log.w(TAG, "Attempt to change preview size while locked");
return false;
}
mCurrentPreviewSize = new Size(previewSize);
return true;
}
然后Camera app通过getCurrentPreviewSize()来获取当前preview size.
public Size getCurrentPreviewSize() {
return new Size(mCurrentPreviewSize);
}