Mtk平台Camera新增差值(二)

news/2024/12/2 18:03:42/

之前介绍了一篇Mtk平台如何在Metadata当中来配置差值Mtk平台Camera新增差值(1),实际功能是可以实现的,但是却无法通过CTS测试的,因为CTS测试会抓取sensor drv的最大输出能力和metadata的最大值来进行比较。

下面将介绍另外一种从Framework来添加的方式。

(1)Framework逻辑添加

(A)CameraDeviceClient.cpp

//frameworks /av/services/camera/libcameraservice/api2/CameraDeviceClient.cpp//add start
#define PIXEL_ARRAY_SIZE 28
static int32_t __unused pixel_width_array[PIXEL_ARRAY_SIZE]  = {2560,960,1280,1280,1600,1920,2832,3456,3264,3840,4032,4000,4608,4928,4160,4864,5184,4608,5376,5664,5312,6080,5696,6544,6944,8000,9216,9792};
static int32_t __unused pixel_height_array[PIXEL_ARRAY_SIZE] =  {1920,720,720,960,1200,1080,2832,3456,2448,2160,2016,3000,2592,2464,3120,2736,2592,3456,3024,2832,3984,3424,4272,3681,3472,6000,5184,4896};
//add endbool CameraDeviceClient::roundBufferDimensionNearest(int32_t width, int32_t height,int32_t format, android_dataspace dataSpace, const CameraMetadata& info,/*out*/int32_t* outWidth, /*out*/int32_t* outHeight) {int32_t bestWidth = -1;int32_t bestHeight = -1;// Iterate through listed stream configurations and find the one with the smallest euclidean// distance from the given dimensions for the given format.for (size_t i = 0; i < streamConfigs.count; i += 4) {int32_t fmt = streamConfigs.data.i32[i];int32_t w = streamConfigs.data.i32[i + 1];int32_t h = streamConfigs.data.i32[i + 2];//add startbool isAddPixel = false;int32_t matchIndex = 0;for(int32_t i=0;i<PIXEL_ARRAY_SIZE;i++){if(width==pixel_width_array[i]&& height ==pixel_height_array[i]){isAddPixel = true;matchIndex = i;break;}}ALOGE("matchIndex: %d  isAddPixel: %d", matchIndex, isAddPixel);//add endif (fmt == format) {if (w == width && h == height) {bestWidth = width;bestHeight = height;break;//add start} else if(isAddPixel){bestWidth = pixel_width_array[matchIndex];bestHeight = pixel_height_array[matchIndex];break;                //add end} else if (w <= ROUNDING_WIDTH_CAP && (bestWidth == -1 ||CameraDeviceClient::euclidDistSquare(w, h, width, height) <CameraDeviceClient::euclidDistSquare(bestWidth, bestHeight, width, height))) {bestWidth = w;bestHeight = h;}}}//...return true;
}

(B)Camera3Device.cpp

//frameworks /av/services/camera/libcameraservice/device3/Camera3Device.cpp//add start
#define PIXEL_ARRAY_SIZE 28
static uint32_t __unused pixel_width_array[PIXEL_ARRAY_SIZE]  = {2560,960,1280,1280,1600,1920,2832,3456,3264, 3840,4032,4000,4608,4928,4160, 4864,5184,4608,5376,5664,5312, 6080,5696,6544,6944,8000,9216,9792};
static uint32_t __unused pixel_height_array[PIXEL_ARRAY_SIZE] = {1920,720,720,960,1200,1080,2832,3456,2448, 2160,2016,3000,2592,2464,3120, 2736,2592,3456,3024,2832,3984, 3424,4272,3681,3472,6000,5184,4896};
//add endssize_t Camera3Device::getJpegBufferSize(uint32_t width, uint32_t height) const {//...maxJpegBufferSize = jpegBufMaxSize.data.i32[0];assert(kMinJpegBufferSize < maxJpegBufferSize);// Calculate final jpeg buffer size for the given resolution.float scaleFactor = ((float) (width * height)) /(maxJpegResolution.width * maxJpegResolution.height);ssize_t jpegBufferSize = scaleFactor * (maxJpegBufferSize - kMinJpegBufferSize) +kMinJpegBufferSize;if (jpegBufferSize > maxJpegBufferSize) {//add start//jpegBufferSize = maxJpegBufferSize;bool isAddPixel = false;for(int32_t i=0;i<PIXEL_ARRAY_SIZE;i++){if(width==pixel_width_array[i]&& height ==pixel_height_array[i]){isAddPixel = true;break;}}if(!isAddPixel){jpegBufferSize = maxJpegBufferSize; }//add end}return jpegBufferSize;
}

(C)CameraManager.java

//frameworks/base/core/java/android/hardware/camera2/CameraManager.javapublic CameraCharacteristics getCameraCharacteristics(@NonNull String cameraId)throws CameraAccessException {CameraCharacteristics characteristics = null;if (CameraManagerGlobal.sCameraServiceDisabled) {throw new IllegalArgumentException("No cameras available on device");}synchronized (mLock) {/** Get the camera characteristics from the camera service directly if it supports it,* otherwise get them from the legacy shim instead.*/ICameraService cameraService = CameraManagerGlobal.get().getCameraService();if (cameraService == null) {throw new CameraAccessException(CameraAccessException.CAMERA_DISCONNECTED,"Camera service is currently unavailable");}try {Size displaySize = getDisplaySize();// First check isHiddenPhysicalCamera to avoid supportsCamera2ApiLocked throwing// exception in case cameraId is a hidden physical camera.if (!isHiddenPhysicalCamera(cameraId) && !supportsCamera2ApiLocked(cameraId)) {// Legacy backwards compatibility path; build static info from the camera// parametersint id = Integer.parseInt(cameraId);String parameters = cameraService.getLegacyParameters(id);CameraInfo info = cameraService.getCameraInfo(id);characteristics = LegacyMetadataMapper.createCharacteristics(parameters, info,id, displaySize);} else {// Normal path: Get the camera characteristics directly from the camera serviceCameraMetadataNative info = cameraService.getCameraCharacteristics(cameraId);try {info.setCameraId(Integer.parseInt(cameraId));} catch (NumberFormatException e) {// For external camera, reaching here is expected.Log.v(TAG, "Failed to parse camera Id " + cameraId + " to integer");}boolean hasConcurrentStreams =CameraManagerGlobal.get().cameraIdHasConcurrentStreamsLocked(cameraId);info.setHasMandatoryConcurrentStreams(hasConcurrentStreams);info.setDisplaySize(displaySize);characteristics = new CameraCharacteristics(info);//add startString pkgName = mContext.getPackageName();String[] addList = mContext.getResources().getStringArray(com.android.internal.R.array.abc_whitelist_for_pixel_add);String[] pixels = null;boolean add = false;if(addList!=null&&addList.length>0){for (String str : addList) {if (pkgName.equalsIgnoreCase(str)) {add = true;break;}}}if(add){if("1".equals(cameraId)){pixels =  mContext.getResources().getStringArray(com.android.internal.R.array.abc_pixels_add_for_sub);}else if("0".equals(cameraId)){pixels =  mContext.getResources().getStringArray(com.android.internal.R.array.abc_pixels_add_for_main);}else if("2".equals(cameraId)){pixels =  mContext.getResources().getStringArray(com.android.internal.R.array.abc_pixels_add_for_id_2);}else if("3".equals(cameraId)){pixels =  mContext.getResources().getStringArray(com.android.internal.R.array.abc_pixels_add_for_id_3);}}characteristics.setAppNameAndSensorId(add,pixels);//add end}} catch (ServiceSpecificException e) {throwAsPublicException(e);} catch (RemoteException e) {// Camera service died - act as if the camera was disconnectedthrow new CameraAccessException(CameraAccessException.CAMERA_DISCONNECTED,"Camera service is currently unavailable", e);}}return characteristics;}

(D)CameraCharacteristics.java

//frameworks/base/core/java/android/hardware/camera2/CameraCharacteristics.java//add start/*** Set add vaule and add pixel values {@link CameraMetadataNative}.* @hide*/public void setAppNameAndSensorId(boolean addPixel,String[] pixels){mProperties.setAppNameAndSensorId(addPixel,pixels);}//add end

(E)CameraMetadataNative.java

//frameworks/base/core/java/android/hardware/camera2/impl/CameraMetadataNative.java//add start
import java.util.Arrays;
//add end//add startprivate boolean mAddPixel;private String[] mPixels = null;
//add end//add startpublic void setAppNameAndSensorId(boolean addPixel,String[] pixels){mAddPixel = addPixel;mPixels = pixels;}
//add endprivate StreamConfigurationMap getStreamConfigurationMap() {StreamConfiguration[] configurations = getBase(CameraCharacteristics.SCALER_AVAILABLE_STREAM_CONFIGURATIONS);//add startif(mAddPixel && mPixels!=null && mPixels.length!=0){int mLength = configurations.length;configurations=Arrays.copyOf(configurations,configurations.length + mPixels.length);for (int i=0;i<mPixels.length;i++) {String[] mPixel = mPixels[i].split("x");int addWidth = Integer.parseInt(mPixel[0]);int addHeight = Integer.parseInt(mPixel[1]);configurations[mLength+i]=new StreamConfiguration(33,addWidth,addHeight,false);}}//add end//...
}

(2)配置文件添加

在CameraManager.java文件中通过配置应用白名单和前后摄差值数组以供程序解析,进而做到代码与配置分离。

<!-- frameworks/base/core/res/res/values/adc_arrays.xml --><!-- add start--><string-array name="adc_whitelist_for_pixel_add" translatable="false"><item>com.mediatek.camera</item><item>com.android.camera</item><item>com.ludashi.benchmark</item><item>com.antutu.ABenchMark</item><item>test.android.camera</item></string-array><!--前摄差值200万,后摄差值500万--><string-array name="abc_pixels_add_for_sub" translatable="false"><item>1920x1080</item><item>1600x1200</item><item>1280x960</item><item>1280x720</item><item>960x720</item></string-array><string-array name="abc_pixels_add_for_main" translatable="false"><item>2560x1920</item><item>1920x1080</item></string-array><string-array name="abc_pixels_add_for_id_2" translatable="false"></string-array><string-array name="abc_pixels_add_for_id_3" translatable="false"></string-array><!-- add end--><!-- add item  <item>4160x3120</item>8 megapixels 3264x2448(4:3) 3840x2160(16:9) 4032x2016(16:9) 2832x2832(1:1)12 megapixels 4000x3000(4:3) 4608x2592(16:9) 4928x2464(18:9) 3456x3456(1:1)13 megapixels 4160x3120(4:3) 4864x2736(16:9) 5184x2592(16:9)16 megapixels 4608x3456(4:3) 5376x3024(16:9) 5664x2832(16:9)21 megapixels 5312x3984(4:3) 6080x3424(16:9)24 megapixels 5696x4272(4:3) 6544x3681(16:9) 6944x3472(18:9)48 megapixels 8000x6000(4:3) 9216x5184(16:9) 9792x4896(18:9)-->

(3)Hal逻辑添加

//vendor/mediatek/proprietary/hardware/mtkcam3/main/hal/device/3.x/device/CameraDevice3SessionImpl.cpp//add start
#define PIXEL_ARRAY_SIZE 28
static uint32_t __unused pixel_width_array[PIXEL_ARRAY_SIZE]  = {2560,960,1280,1280,1600,1920,2832,3456,3264, 3840,4032,4000,4608,4928,4160, 4864,5184,4608,5376,5664,5312, 6080,5696,6544,6944,8000,9216,9792};
static uint32_t __unused pixel_height_array[PIXEL_ARRAY_SIZE] = {1920,720,720,960,1200,1080,2832,3456,2448, 2160,2016,3000,2592,2464,3120, 2736,2592,3456,3024,2832,3984, 3424,4272,3681,3472,6000,5184,4896};
//add endauto
ThisNamespace::
checkStream(const Stream& rStream
)   -> ::android::status_t
{//...switch ( rStream.rotation ){case StreamRotation::ROTATION_0:break;case StreamRotation::ROTATION_90:case StreamRotation::ROTATION_180:case StreamRotation::ROTATION_270:MY_LOGI("%s", toString(rStream).c_str());if ( StreamType::INPUT == rStream.streamType ) {MY_LOGE("input stream cannot support rotation");return -EINVAL;}switch (rStream.format){case HAL_PIXEL_FORMAT_RAW16:case HAL_PIXEL_FORMAT_RAW_OPAQUE:MY_LOGE("raw stream cannot support rotation");return -EINVAL;default:break;}break;default:MY_LOGE("rotation:%d out of bounds - %s", rStream.rotation, toString(rStream).c_str());return -EINVAL;}//...// android.scaler.availableStreamConfigurations// int32 x n x 4sp<AppImageStreamInfo> pInfo = getConfigImageStream(rStream.id);for (MUINT i = 0; i < entryScaler.count(); i += 4 ){int32_t const format = entryScaler.itemAt(i, Type2Type< MINT32 >());if ( (int32_t)rStream.format==format ||(pInfo.get() && pInfo->getOriImgFormat()==format ) ){MUINT32 scalerWidth  = entryScaler.itemAt(i + 1, Type2Type< MINT32 >());MUINT32 scalerHeight = entryScaler.itemAt(i + 2, Type2Type< MINT32 >());if ( ( rStream.width == scalerWidth && rStream.height == scalerHeight ) ||( rStream.rotation&StreamRotation::ROTATION_90 &&rStream.width == scalerHeight && rStream.height == scalerWidth ) ){return OK;}//add startfor(MUINT32 i=0;i<PIXEL_ARRAY_SIZE;i++){if(rStream.width==pixel_width_array[i]&&rStream.height ==pixel_height_array[i]){return OK;}}//add end}}MY_LOGE("unsupported size %dx%d for format 0x%x/rotation:%d - %s",rStream.width, rStream.height, rStream.format, rStream.rotation, toString(rStream).c_str());return -EINVAL;
}

以上添加后,即可不用在Metadata当中配置相关的差值Size了。


http://www.ppmy.cn/news/272680.html

相关文章

CVBS、VGA、HDMI、MIPI等8种视频接口详解

硬件接口&#xff08;hardware interface&#xff09;指的是两个硬件设备之间的连接方式。硬件接口既包括物理上的接口&#xff0c;还包括逻辑上的数据传送协议。 CVBSCVBS英文全称为Composite Video Broadcast Signal 或 Composite Video Blanking and Sync。中文翻译为复合视…

TC358775XBG是一颗将MIPI DSI信号转换成single/ dual -link LVDS的芯片,最高分辨率支持到1920x1200

产品特征&#xff1a; MIPI接口&#xff1a; &#xff08;1&#xff09;、支持1/2/3/4 lane(s) data&#xff0c;Maximum bit rate of 1 Gbps/lane &#xff08;2&#xff09;、支持video mode&#xff08;Non-burst Mode with Sync Pulses、Non-Burst Mode with Sync Events&a…

ubuntu9.10更改屏幕分辨率

此方法针对显示首选项的最大分辨率只有800*600的情况。 第一步&#xff1a;在终端中输入命令&#xff1a;cvt 1024 768 (“1024 768“是根据分辨率来写的&#xff0c;其它的分辨率有&#xff1a;600*480 、800*600 、1024*768、1400x1050、1600x1200、1280x720、1920x1080等&a…

基于i.mx6高清视频采集技术详解

1 概述 本文介绍基于freescale i.MX6 高清视频采集方案的技术详解&#xff0c;高清视频输入可以为HDMI、DVI或者VGA的方式。分辨率支持1600*120060、1920*108060、1280x72060HZ等多种。视频解码芯片采用ADI的ADV7441A。 实现低成本、高性能、高集成度的视频采集产品。 包括硬…

rk3399 调试一款新的摄像头驱动

rk3399 mipi camera Firefly-RK3399 开发板分别带有两个 MIPI&#xff0c;一个 DVP 摄像头接口 rk3399平台可以支持多种不同接口的Camera,如MIPI, DVP, UVC,USB camera 对于DVP,MIPI接口的,是在cam_board.xml文件注册camera&#xff0c;isp控制器接收 对于UVC,USB接口的只要移…

图片处理PIL.Image模块

Image模块是PIL中最重要的模块&#xff0c;它有一个类叫做image&#xff0c;与模块名称相同。Image类有很多函数、方法及属性&#xff0c;接下来将依次对image类的属性、函数和方法进行介绍。 一、Image类的属性 1、 Format 定义&#xff1a;im.format ⇒ string or None 含…

RK平台USB摄像头FAQ

&#xff08;记录android9以后调试所遇到的常见问题&#xff0c;有错请批评指正&#xff09; UVC全称为USB video&#xff08;device&#xff09; class,是微软与另外几家设备厂商联合推出的为usb视频捕获设备定义的协议标准&#xff1b;所以说UVC仅仅是usb规范协议中设备类规范…

机器视觉项目 - 选型总结

一. 面阵相机和镜头选型 已知&#xff1a;被检测物体大小为A*B,要求能够分辨小于C&#xff0c;工作距为D 解答&#xff1a; 1. 计算短边对应的像素数 E B/C&#xff0c;相机长边和短边的像素数都要大于E&#xff1b; 2. 像元尺寸 物体短边尺寸B / 所选相机的短边像素数&…