diff --git a/aosp_diff/caas_cfc/frameworks/av/0002-check-orientation-in-camera-90deg-case.patch b/aosp_diff/caas_cfc/frameworks/av/0002-check-orientation-in-camera-90deg-case.patch new file mode 100644 index 0000000000..cdf2f39fca --- /dev/null +++ b/aosp_diff/caas_cfc/frameworks/av/0002-check-orientation-in-camera-90deg-case.patch @@ -0,0 +1,108 @@ +From 750a6d205960e2edaaa3e5b7ff8400bbac2daac5 Mon Sep 17 00:00:00 2001 +From: gkdeepa +Date: Wed, 3 Nov 2021 14:11:10 +0530 +Subject: [PATCH] check orientation in camera 90deg case + +Tracked-On: +--- + ...ck-orientation-in-camera-180deg-case.patch | 50 +++++++++++++++++++ + .../api1/client2/Parameters.cpp | 10 ++-- + 2 files changed, 56 insertions(+), 4 deletions(-) + create mode 100644 services/camera/libcameraservice/api1/0001-check-orientation-in-camera-180deg-case.patch + +diff --git a/services/camera/libcameraservice/api1/0001-check-orientation-in-camera-180deg-case.patch b/services/camera/libcameraservice/api1/0001-check-orientation-in-camera-180deg-case.patch +new file mode 100644 +index 0000000000..42b83e5fa1 +--- /dev/null ++++ b/services/camera/libcameraservice/api1/0001-check-orientation-in-camera-180deg-case.patch +@@ -0,0 +1,50 @@ ++From 9aa1a62d7206fdd32ea61eaecea46a58d5915686 Mon Sep 17 00:00:00 2001 ++From: gkdeepa ++Date: Wed, 3 Nov 2021 14:11:10 +0530 ++Subject: [PATCH] check orientation in camera 180deg case ++ ++Tracked-On: ++--- ++ .../camera/libcameraservice/api1/client2/Parameters.cpp | 9 ++++++--- ++ 1 file changed, 6 insertions(+), 3 deletions(-) ++ ++diff --git a/services/camera/libcameraservice/api1/client2/Parameters.cpp b/services/camera/libcameraservice/api1/client2/Parameters.cpp ++index dbc863b3ad..9979610ca0 100644 ++--- a/services/camera/libcameraservice/api1/client2/Parameters.cpp +++++ b/services/camera/libcameraservice/api1/client2/Parameters.cpp ++@@ -16,7 +16,7 @@ ++ ++ #define LOG_TAG "Camera2-Parameters" ++ #define ATRACE_TAG ATRACE_TAG_CAMERA ++-// #define LOG_NDEBUG 0 +++#define LOG_NDEBUG 0 ++ ++ #include ++ #include ++@@ -2828,10 +2828,12 @@ bool Parameters::boolFromString(const char *boolStr) { ++ } ++ ++ int Parameters::degToTransform(int degrees, bool mirror) { +++ ALOGE("degrees and mirror %d %d ",degrees, mirror); ++ if (!mirror) { ++ if (degrees == 0) return 0; ++ else if (degrees == 90) return HAL_TRANSFORM_ROT_90; ++- else if (degrees == 180) return HAL_TRANSFORM_ROT_180; +++ //else if (degrees == 180) return HAL_TRANSFORM_ROT_180; +++ else if (degrees == 180) return 0; ++ else if (degrees == 270) return HAL_TRANSFORM_ROT_270; ++ } else { // Do mirror (horizontal flip) ++ if (degrees == 0) { // FLIP_H and ROT_0 ++@@ -2839,7 +2841,8 @@ int Parameters::degToTransform(int degrees, bool mirror) { ++ } else if (degrees == 90) { // FLIP_H and ROT_90 ++ return HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_ROT_90; ++ } else if (degrees == 180) { // FLIP_H and ROT_180 ++- return HAL_TRANSFORM_FLIP_V; +++ return 0; +++ //return HAL_TRANSFORM_FLIP_V; ++ } else if (degrees == 270) { // FLIP_H and ROT_270 ++ return HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_ROT_90; ++ } ++-- ++2.17.1 ++ +diff --git a/services/camera/libcameraservice/api1/client2/Parameters.cpp b/services/camera/libcameraservice/api1/client2/Parameters.cpp +index dbc863b3ad..487e7cd426 100644 +--- a/services/camera/libcameraservice/api1/client2/Parameters.cpp ++++ b/services/camera/libcameraservice/api1/client2/Parameters.cpp +@@ -16,7 +16,7 @@ + + #define LOG_TAG "Camera2-Parameters" + #define ATRACE_TAG ATRACE_TAG_CAMERA +-// #define LOG_NDEBUG 0 ++#define LOG_NDEBUG 0 + + #include + #include +@@ -2828,18 +2828,20 @@ bool Parameters::boolFromString(const char *boolStr) { + } + + int Parameters::degToTransform(int degrees, bool mirror) { ++ ALOGE("degrees and mirror %d %d ",degrees, mirror); + if (!mirror) { + if (degrees == 0) return 0; +- else if (degrees == 90) return HAL_TRANSFORM_ROT_90; ++ else if (degrees == 90) return HAL_TRANSFORM_ROT_270; + else if (degrees == 180) return HAL_TRANSFORM_ROT_180; + else if (degrees == 270) return HAL_TRANSFORM_ROT_270; + } else { // Do mirror (horizontal flip) + if (degrees == 0) { // FLIP_H and ROT_0 + return HAL_TRANSFORM_FLIP_H; + } else if (degrees == 90) { // FLIP_H and ROT_90 +- return HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_ROT_90; ++ return HAL_TRANSFORM_FLIP_H ; + } else if (degrees == 180) { // FLIP_H and ROT_180 +- return HAL_TRANSFORM_FLIP_V; ++ return 0; ++ //return HAL_TRANSFORM_FLIP_V; + } else if (degrees == 270) { // FLIP_H and ROT_270 + return HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_ROT_90; + } +-- +2.17.1 + diff --git a/aosp_diff/caas_cfc/frameworks/base/0004-WA-for-rotation-framework.patch b/aosp_diff/caas_cfc/frameworks/base/0004-WA-for-rotation-framework.patch new file mode 100644 index 0000000000..ab9c0926ef --- /dev/null +++ b/aosp_diff/caas_cfc/frameworks/base/0004-WA-for-rotation-framework.patch @@ -0,0 +1,114 @@ +From 2713d08ab434c8e16f6d7d1f15fc91efd7e8b119 Mon Sep 17 00:00:00 2001 +From: gkdeepa +Date: Thu, 28 Oct 2021 13:41:35 +0530 +Subject: [PATCH] framework logs and WA + +Tracked-On: +--- + core/jni/android_hardware_Camera.cpp | 33 +++++++++++++++++++++++----- + 1 file changed, 28 insertions(+), 5 deletions(-) + +diff --git a/core/jni/android_hardware_Camera.cpp b/core/jni/android_hardware_Camera.cpp +index bc69735d7453..d46c77396960 100644 +--- a/core/jni/android_hardware_Camera.cpp ++++ b/core/jni/android_hardware_Camera.cpp +@@ -40,7 +40,7 @@ enum { + // Keep up to date with Camera.java + CAMERA_HAL_API_VERSION_NORMAL_CONNECT = -2, + }; +- ++int checkflag=0; + struct fields_t { + jfieldID context; + jfieldID facing; +@@ -544,9 +544,14 @@ static void android_hardware_Camera_getCameraInfo(JNIEnv *env, jobject thiz, + jniThrowRuntimeException(env, "Fail to get camera info"); + return; + } ++ if(checkflag == 1){ ++ if(cameraInfo.facing == 1) ++ env->SetIntField(info_obj, fields.orientation, 270); ++ } ++ else{ ++ env->SetIntField(info_obj, fields.orientation, cameraInfo.orientation); ++ } + env->SetIntField(info_obj, fields.facing, cameraInfo.facing); +- env->SetIntField(info_obj, fields.orientation, cameraInfo.orientation); +- + char value[PROPERTY_VALUE_MAX]; + property_get("ro.camera.sound.forced", value, "0"); + jboolean canDisableShutterSound = (strncmp(value, "0", 2) == 0); +@@ -558,6 +563,7 @@ static void android_hardware_Camera_getCameraInfo(JNIEnv *env, jobject thiz, + static jint android_hardware_Camera_native_setup(JNIEnv *env, jobject thiz, + jobject weak_this, jint cameraId, jint halVersion, jstring clientPackageName) + { ++ + // Convert jstring to String16 + const char16_t *rawClientName = reinterpret_cast( + env->GetStringChars(clientPackageName, NULL)); +@@ -565,13 +571,25 @@ static jint android_hardware_Camera_native_setup(JNIEnv *env, jobject thiz, + String16 clientName(rawClientName, rawClientNameLen); + env->ReleaseStringChars(clientPackageName, + reinterpret_cast(rawClientName)); ++ checkflag=0; ++ //check app orientation ++ const char *nativeString = env->GetStringUTFChars(clientPackageName, NULL); ++ // use your string + ++ if (!strcmp(nativeString, "cn.eeo.classin")) ++ { ++ //only set for classin app ++ checkflag =1; ++ } ++ env->ReleaseStringUTFChars(clientPackageName, nativeString); + sp camera; + if (halVersion == CAMERA_HAL_API_VERSION_NORMAL_CONNECT) { + // Default path: hal version is don't care, do normal camera connect. ++ ALOGE("connect Default path: "); + camera = Camera::connect(cameraId, clientName, + Camera::USE_CALLING_UID, Camera::USE_CALLING_PID); + } else { ++ ALOGE("connect Default path connectLegacy: "); + jint status = Camera::connectLegacy(cameraId, halVersion, clientName, + Camera::USE_CALLING_UID, camera); + if (status != NO_ERROR) { +@@ -580,6 +598,7 @@ static jint android_hardware_Camera_native_setup(JNIEnv *env, jobject thiz, + } + + if (camera == NULL) { ++ ALOGE("camera is null"); + return -EACCES; + } + +@@ -603,7 +622,6 @@ static jint android_hardware_Camera_native_setup(JNIEnv *env, jobject thiz, + + // save context in opaque field + env->SetLongField(thiz, fields.context, (jlong)context.get()); +- + // Update default display orientation in case the sensor is reverse-landscape + CameraInfo cameraInfo; + status_t rc = Camera::getCameraInfo(cameraId, &cameraInfo); +@@ -611,6 +629,12 @@ static jint android_hardware_Camera_native_setup(JNIEnv *env, jobject thiz, + ALOGE("%s: getCameraInfo error: %d", __FUNCTION__, rc); + return rc; + } ++ if(checkflag == 1){ ++ if(cameraInfo.facing == CAMERA_FACING_FRONT) ++ cameraInfo.orientation = 270; ++ } ++ else ++ cameraInfo.orientation = 0; + int defaultOrientation = 0; + switch (cameraInfo.orientation) { + case 0: +@@ -633,7 +657,6 @@ static jint android_hardware_Camera_native_setup(JNIEnv *env, jobject thiz, + break; + } + if (defaultOrientation != 0) { +- ALOGV("Setting default display orientation to %d", defaultOrientation); + rc = camera->sendCommand(CAMERA_CMD_SET_DISPLAY_ORIENTATION, + defaultOrientation, 0); + if (rc != NO_ERROR) { +-- +2.17.1 + diff --git a/aosp_diff/caas_cfc/frameworks/base/0005-WA-camera-rotation.patch b/aosp_diff/caas_cfc/frameworks/base/0005-WA-camera-rotation.patch new file mode 100644 index 0000000000..71d9ad3e9b --- /dev/null +++ b/aosp_diff/caas_cfc/frameworks/base/0005-WA-camera-rotation.patch @@ -0,0 +1,47 @@ +From 453eb2d6b22fc4744156d9ee447d9e3e5fb06766 Mon Sep 17 00:00:00 2001 +From: "Yang, Dong" +Date: Tue, 2 Nov 2021 08:11:27 +0800 +Subject: [PATCH] WA camera rotation + +based on WA patch1, change camera rotation from 270 to 180 for classin +APP + +Tracked-On: +Signed-off-by: Yang, Dong +--- + core/jni/android_hardware_Camera.cpp | 7 +++++-- + 1 file changed, 5 insertions(+), 2 deletions(-) + +diff --git a/core/jni/android_hardware_Camera.cpp b/core/jni/android_hardware_Camera.cpp +index d46c77396960..51dd84f8560f 100644 +--- a/core/jni/android_hardware_Camera.cpp ++++ b/core/jni/android_hardware_Camera.cpp +@@ -545,12 +545,15 @@ static void android_hardware_Camera_getCameraInfo(JNIEnv *env, jobject thiz, + return; + } + if(checkflag == 1){ +- if(cameraInfo.facing == 1) ++ if(cameraInfo.facing == 1) ++ env->SetIntField(info_obj, fields.orientation, 180); ++ else + env->SetIntField(info_obj, fields.orientation, 270); + } + else{ + env->SetIntField(info_obj, fields.orientation, cameraInfo.orientation); + } ++ + env->SetIntField(info_obj, fields.facing, cameraInfo.facing); + char value[PROPERTY_VALUE_MAX]; + property_get("ro.camera.sound.forced", value, "0"); +@@ -631,7 +634,7 @@ static jint android_hardware_Camera_native_setup(JNIEnv *env, jobject thiz, + } + if(checkflag == 1){ + if(cameraInfo.facing == CAMERA_FACING_FRONT) +- cameraInfo.orientation = 270; ++ cameraInfo.orientation = 180; + } + else + cameraInfo.orientation = 0; +-- +2.17.1 + diff --git a/bsp_diff/caas_cfc/vendor/intel/external/project-celadon/camera-vhal/0001-default-vhal-to-1-camera.patch b/bsp_diff/caas_cfc/vendor/intel/external/project-celadon/camera-vhal/0001-default-vhal-to-1-camera.patch new file mode 100644 index 0000000000..44dac60de4 --- /dev/null +++ b/bsp_diff/caas_cfc/vendor/intel/external/project-celadon/camera-vhal/0001-default-vhal-to-1-camera.patch @@ -0,0 +1,85 @@ +From 8ccbbf500a40f220383f5a2b00a0627749510db5 Mon Sep 17 00:00:00 2001 +From: gkdeepa +Date: Sat, 23 Oct 2021 11:00:30 +0530 +Subject: [PATCH] default vhal to 1 camera + +Tracked-On: +--- + include/VirtualCameraFactory.h | 1 - + src/VirtualCameraFactory.cpp | 6 +++--- + src/VirtualFakeCamera3.cpp | 6 +++--- + 3 files changed, 6 insertions(+), 7 deletions(-) + +diff --git a/include/VirtualCameraFactory.h b/include/VirtualCameraFactory.h +index 183ce48..81d26d7 100644 +--- a/include/VirtualCameraFactory.h ++++ b/include/VirtualCameraFactory.h +@@ -107,7 +107,6 @@ public: + * callback. + */ + void getVendorTagOps(vendor_tag_ops_t *ops); +- + public: + /**************************************************************************** + * Camera HAL API callbacks. +diff --git a/src/VirtualCameraFactory.cpp b/src/VirtualCameraFactory.cpp +index 8454fa2..1e30e93 100644 +--- a/src/VirtualCameraFactory.cpp ++++ b/src/VirtualCameraFactory.cpp +@@ -206,7 +206,7 @@ int VirtualCameraFactory::cameraDeviceOpen(int cameraId, hw_device_t **device) { + getVirtualCameraNum()); + return -ENODEV; + } +- ++ ALOGE("Deepa cameraIdcheck is %d",cameraId); + return mVirtualCameras[cameraId]->connectCamera(device); + } + +@@ -311,10 +311,10 @@ void VirtualCameraFactory::createFakeCamera(std::shared_ptr +Date: Tue, 2 Nov 2021 08:20:43 +0800 +Subject: [PATCH] adjust camera image to portrait view + +the input camera image from host is landscape view, but +android is portrait view by default, adjust direction to +portrait view. + +Tracked-On: +Signed-off-by: Yang, Dong +--- + src/CameraSocketServerThread.cpp | 73 ++++++++++++++++++++++++++++++++ + src/VirtualCameraFactory.cpp | 4 +- + 2 files changed, 75 insertions(+), 2 deletions(-) + +diff --git a/src/CameraSocketServerThread.cpp b/src/CameraSocketServerThread.cpp +index 62d4f25..da97a8e 100644 +--- a/src/CameraSocketServerThread.cpp ++++ b/src/CameraSocketServerThread.cpp +@@ -45,6 +45,8 @@ + #include + #include + ++#include ++ + android::ClientVideoBuffer *android::ClientVideoBuffer::ic_instance = 0; + + namespace android { +@@ -125,7 +127,70 @@ void CameraSocketServerThread::clearBuffer(char *buffer, int width, int height) + memset(uv_offset, 0x80, (width * height) / 2); + ALOGVV(LOG_TAG " %s: Exit", __FUNCTION__); + } ++#define CROP_ROTATE ++#ifdef CROP_ROTATE ++static void bufferCropAndRotate(unsigned char * buff, unsigned char * buff_out){ ++// ++// Original frame Cropped frame Rotated frame Upscale frame ++// -------------------- -------- -------------------- ++// | | | | | | --------------- | | | | ++// | | | | | | | | | | | | ++// | | | | =======>> | | =======>> | | =======>> | | | | ++// | | | | | | --------------- | | | | ++// | | | | | | | | | | ++// -------------------- -------- -------------------- ++// 640x480 360x480 480x360 640x480 ++ ALOGI("bufferCropAndRotate"); ++ std::unique_ptr cropped_buffer; ++ ++ int cropped_width = 360; ++ int cropped_height = 480; ++ int margin = (640-360)/2; //140 ++ ++ int rotated_height = cropped_width; ++ int rotated_width = cropped_height; ++ ++ int rotated_y_stride = rotated_width; ++ int rotated_uv_stride = rotated_width / 2; ++ ++ size_t rotated_size = ++ rotated_y_stride * rotated_height + rotated_uv_stride * rotated_height; ++ cropped_buffer.reset(new uint8_t[rotated_size]); ++ uint8_t* rotated_y_plane = cropped_buffer.get(); ++ uint8_t* rotated_u_plane = ++ rotated_y_plane + rotated_y_stride * rotated_height; ++ uint8_t* rotated_v_plane = ++ rotated_u_plane + rotated_uv_stride * rotated_height / 2; ++ libyuv::RotationMode rotation_mode = libyuv::RotationMode::kRotate90; ++ //libyuv::RotationMode rotation_mode = libyuv::RotationMode::kRotate270; ++ ++ int res = libyuv::ConvertToI420( ++ buff, 640*480*3/2, rotated_y_plane, ++ rotated_y_stride, rotated_u_plane, rotated_uv_stride, rotated_v_plane, ++ rotated_uv_stride, margin, 0, 640, ++ 480, cropped_width, cropped_height, rotation_mode, ++ libyuv::FourCC::FOURCC_I420); ++ ++ if(res){ ++ ALOGE("critical ConvertToI420 res:%d ", res); ++ return; ++ } + ++ res = libyuv::I420Scale( ++ rotated_y_plane, rotated_y_stride, rotated_u_plane, rotated_uv_stride, ++ rotated_v_plane, rotated_uv_stride, rotated_width, rotated_height, ++ buff_out, 640, ++ buff_out + 640*480, ++ 640 / 2, ++ buff_out + 640*480*5/4, ++ 640/2, 640, ++ 480, libyuv::FilterMode::kFilterNone); ++ ++ if(res){ ++ ALOGE("critical I420Scale res:%d ", res); ++ } ++} ++#endif + bool CameraSocketServerThread::threadLoop() { + struct sockaddr_un addr_un; + memset(&addr_un, 0, sizeof(addr_un)); +@@ -294,6 +359,7 @@ bool CameraSocketServerThread::threadLoop() { + + ClientVideoBuffer *handle = ClientVideoBuffer::getClientInstance(); + char *fbuffer = (char *)handle->clientBuf[handle->clientRevCount % 1].buffer; ++ char buffer_recv[640*480*3/2]; + + clearBuffer(fbuffer, 640, 480); + +@@ -327,9 +393,16 @@ bool CameraSocketServerThread::threadLoop() { + if(trans_mode == VSOCK) + { + while(size_update != 460800){ ++ #ifdef CROP_ROTATE ++ size = recv(mClientFd, (char *)buffer_recv+size_update, 460800, 0); ++ #else + size = recv(mClientFd, (char *)fbuffer+size_update, 460800, 0); ++ #endif + size_update += size; + if (size_update == 460800){ ++ #ifdef CROP_ROTATE ++ bufferCropAndRotate((uint8_t*)buffer_recv, (uint8_t*)fbuffer); ++ #endif + handle->clientRevCount++; + size_update = 0; + ALOGVV(LOG_TAG +diff --git a/src/VirtualCameraFactory.cpp b/src/VirtualCameraFactory.cpp +index 1e30e93..fc850eb 100644 +--- a/src/VirtualCameraFactory.cpp ++++ b/src/VirtualCameraFactory.cpp +@@ -311,10 +311,10 @@ void VirtualCameraFactory::createFakeCamera(std::shared_ptr +Date: Tue, 2 Nov 2021 13:54:55 +0530 +Subject: [PATCH] JPEG compressor lib inclusion + +Tracked-On: +--- + src/NV21JpegCompressor.cpp | 2 +- + src/jpeg-stub/Compressor.cpp | 2 +- + src/jpeg-stub/JpegStub.cpp | 5 ++--- + 3 files changed, 4 insertions(+), 5 deletions(-) + +diff --git a/src/NV21JpegCompressor.cpp b/src/NV21JpegCompressor.cpp +index 3348959..a320886 100644 +--- a/src/NV21JpegCompressor.cpp ++++ b/src/NV21JpegCompressor.cpp +@@ -45,7 +45,7 @@ typedef void (*GetCompressedImageFunc)(JpegStub *stub, void *buff); + typedef size_t (*GetCompressedSizeFunc)(JpegStub *stub); + + NV21JpegCompressor::NV21JpegCompressor() { +- const char dlName[] = "/system/vendor/lib64/hw/camera.cic_cloud.jpeg.so"; ++ const char dlName[] = "/system/vendor/lib64/hw/camera.celadon.jpeg.so"; + if (!mDl) { + mDl = dlopen(dlName, RTLD_NOW); + } +diff --git a/src/jpeg-stub/Compressor.cpp b/src/jpeg-stub/Compressor.cpp +index 385937c..4d67ac3 100644 +--- a/src/jpeg-stub/Compressor.cpp ++++ b/src/jpeg-stub/Compressor.cpp +@@ -16,7 +16,7 @@ + + #include "Compressor.h" + +-// #define LOG_NDEBUG 0 ++#define LOG_NDEBUG 0 + #define LOG_TAG "VirtualCamera_JPEGStub_Compressor" + #include + #include +diff --git a/src/jpeg-stub/JpegStub.cpp b/src/jpeg-stub/JpegStub.cpp +index d421a87..5c88a5e 100644 +--- a/src/jpeg-stub/JpegStub.cpp ++++ b/src/jpeg-stub/JpegStub.cpp +@@ -16,7 +16,7 @@ + + #include "JpegStub.h" + +-// #define LOG_NDEBUG 0 ++//#define LOG_NDEBUG 0 + #define LOG_TAG "VirtualCamera_JPEGStub" + #include + #include +@@ -36,12 +36,11 @@ extern "C" void JpegStub_cleanup(JpegStub *stub) { + extern "C" int JpegStub_compress(JpegStub *stub, const void *buffer, int width, int height, + int quality, ExifData *exifData) { + Compressor *compressor = reinterpret_cast(stub->mCompressor); +- + if (compressor->compress(reinterpret_cast(buffer), width, height, + quality, exifData)) { + ALOGV("%s: Compressed JPEG: %d[%dx%d] -> %zu bytes", __FUNCTION__, + (width * height * 12) / 8, width, height, compressor->getCompressedData().size()); +- return 0; ++ + } + ALOGE("%s: JPEG compression failed", __FUNCTION__); + return errno ? errno : EINVAL; +-- +2.17.1 + diff --git a/bsp_diff/caas_cfc/vendor/intel/external/project-celadon/camera-vhal/0004-offload-crop-work-from-socket-thread-to-main-thread.patch b/bsp_diff/caas_cfc/vendor/intel/external/project-celadon/camera-vhal/0004-offload-crop-work-from-socket-thread-to-main-thread.patch new file mode 100644 index 0000000000..861d240007 --- /dev/null +++ b/bsp_diff/caas_cfc/vendor/intel/external/project-celadon/camera-vhal/0004-offload-crop-work-from-socket-thread-to-main-thread.patch @@ -0,0 +1,256 @@ +From 62ea9d69849efac7f5aa2ddf64ca1ec110e198ad Mon Sep 17 00:00:00 2001 +From: "Yang, Dong" +Date: Fri, 5 Nov 2021 15:24:03 +0800 +Subject: [PATCH] offload crop work from socket thread to main thread + +to improve stability + +Tracked-On: +Signed-off-by: Yang, Dong +--- + src/CameraSocketServerThread.cpp | 71 ------------------------- + src/fake-pipeline2/Sensor.cpp | 89 ++++++++++++++++++++++++++++++++ + 2 files changed, 89 insertions(+), 71 deletions(-) + +diff --git a/src/CameraSocketServerThread.cpp b/src/CameraSocketServerThread.cpp +index da97a8e..c06fb22 100644 +--- a/src/CameraSocketServerThread.cpp ++++ b/src/CameraSocketServerThread.cpp +@@ -127,70 +127,7 @@ void CameraSocketServerThread::clearBuffer(char *buffer, int width, int height) + memset(uv_offset, 0x80, (width * height) / 2); + ALOGVV(LOG_TAG " %s: Exit", __FUNCTION__); + } +-#define CROP_ROTATE +-#ifdef CROP_ROTATE +-static void bufferCropAndRotate(unsigned char * buff, unsigned char * buff_out){ +-// +-// Original frame Cropped frame Rotated frame Upscale frame +-// -------------------- -------- -------------------- +-// | | | | | | --------------- | | | | +-// | | | | | | | | | | | | +-// | | | | =======>> | | =======>> | | =======>> | | | | +-// | | | | | | --------------- | | | | +-// | | | | | | | | | | +-// -------------------- -------- -------------------- +-// 640x480 360x480 480x360 640x480 +- ALOGI("bufferCropAndRotate"); +- std::unique_ptr cropped_buffer; +- +- int cropped_width = 360; +- int cropped_height = 480; +- int margin = (640-360)/2; //140 +- +- int rotated_height = cropped_width; +- int rotated_width = cropped_height; +- +- int rotated_y_stride = rotated_width; +- int rotated_uv_stride = rotated_width / 2; +- +- size_t rotated_size = +- rotated_y_stride * rotated_height + rotated_uv_stride * rotated_height; +- cropped_buffer.reset(new uint8_t[rotated_size]); +- uint8_t* rotated_y_plane = cropped_buffer.get(); +- uint8_t* rotated_u_plane = +- rotated_y_plane + rotated_y_stride * rotated_height; +- uint8_t* rotated_v_plane = +- rotated_u_plane + rotated_uv_stride * rotated_height / 2; +- libyuv::RotationMode rotation_mode = libyuv::RotationMode::kRotate90; +- //libyuv::RotationMode rotation_mode = libyuv::RotationMode::kRotate270; +- +- int res = libyuv::ConvertToI420( +- buff, 640*480*3/2, rotated_y_plane, +- rotated_y_stride, rotated_u_plane, rotated_uv_stride, rotated_v_plane, +- rotated_uv_stride, margin, 0, 640, +- 480, cropped_width, cropped_height, rotation_mode, +- libyuv::FourCC::FOURCC_I420); +- +- if(res){ +- ALOGE("critical ConvertToI420 res:%d ", res); +- return; +- } + +- res = libyuv::I420Scale( +- rotated_y_plane, rotated_y_stride, rotated_u_plane, rotated_uv_stride, +- rotated_v_plane, rotated_uv_stride, rotated_width, rotated_height, +- buff_out, 640, +- buff_out + 640*480, +- 640 / 2, +- buff_out + 640*480*5/4, +- 640/2, 640, +- 480, libyuv::FilterMode::kFilterNone); +- +- if(res){ +- ALOGE("critical I420Scale res:%d ", res); +- } +-} +-#endif + bool CameraSocketServerThread::threadLoop() { + struct sockaddr_un addr_un; + memset(&addr_un, 0, sizeof(addr_un)); +@@ -359,7 +296,6 @@ bool CameraSocketServerThread::threadLoop() { + + ClientVideoBuffer *handle = ClientVideoBuffer::getClientInstance(); + char *fbuffer = (char *)handle->clientBuf[handle->clientRevCount % 1].buffer; +- char buffer_recv[640*480*3/2]; + + clearBuffer(fbuffer, 640, 480); + +@@ -393,16 +329,9 @@ bool CameraSocketServerThread::threadLoop() { + if(trans_mode == VSOCK) + { + while(size_update != 460800){ +- #ifdef CROP_ROTATE +- size = recv(mClientFd, (char *)buffer_recv+size_update, 460800, 0); +- #else + size = recv(mClientFd, (char *)fbuffer+size_update, 460800, 0); +- #endif + size_update += size; + if (size_update == 460800){ +- #ifdef CROP_ROTATE +- bufferCropAndRotate((uint8_t*)buffer_recv, (uint8_t*)fbuffer); +- #endif + handle->clientRevCount++; + size_update = 0; + ALOGVV(LOG_TAG +diff --git a/src/fake-pipeline2/Sensor.cpp b/src/fake-pipeline2/Sensor.cpp +index 577cd91..3a7d68b 100644 +--- a/src/fake-pipeline2/Sensor.cpp ++++ b/src/fake-pipeline2/Sensor.cpp +@@ -242,6 +242,72 @@ status_t Sensor::readyToRun() { + return OK; + } + ++#define CROP_ROTATE ++#ifdef CROP_ROTATE ++void bufferCropAndRotate(unsigned char * buff, unsigned char * buff_out){ ++// ++// Original frame Cropped frame Rotated frame Upscale frame ++// -------------------- -------- -------------------- ++// | | | | | | --------------- | | | | ++// | | | | | | | | | | | | ++// | | | | =======>> | | =======>> | | =======>> | | | | ++// | | | | | | --------------- | | | | ++// | | | | | | | | | | ++// -------------------- -------- -------------------- ++// 640x480 360x480 480x360 640x480 ++ ALOGI("bufferCropAndRotate"); ++ std::unique_ptr cropped_buffer; ++ ++ int cropped_width = 360; ++ int cropped_height = 480; ++ int margin = (640-360)/2; //140 ++ ++ int rotated_height = cropped_width; ++ int rotated_width = cropped_height; ++ ++ int rotated_y_stride = rotated_width; ++ int rotated_uv_stride = rotated_width / 2; ++ ++ size_t rotated_size = ++ rotated_y_stride * rotated_height + rotated_uv_stride * rotated_height; ++ cropped_buffer.reset(new uint8_t[rotated_size]); ++ uint8_t* rotated_y_plane = cropped_buffer.get(); ++ uint8_t* rotated_u_plane = ++ rotated_y_plane + rotated_y_stride * rotated_height; ++ uint8_t* rotated_v_plane = ++ rotated_u_plane + rotated_uv_stride * rotated_height / 2; ++ libyuv::RotationMode rotation_mode = libyuv::RotationMode::kRotate90; ++ //libyuv::RotationMode rotation_mode = libyuv::RotationMode::kRotate270; ++ ++ int res = libyuv::ConvertToI420( ++ buff, 640*480*3/2, rotated_y_plane, ++ rotated_y_stride, rotated_u_plane, rotated_uv_stride, rotated_v_plane, ++ rotated_uv_stride, margin, 0, 640, ++ 480, cropped_width, cropped_height, rotation_mode, ++ libyuv::FourCC::FOURCC_I420); ++ ++ if(res){ ++ ALOGE("critical ConvertToI420 res:%d ", res); ++ return; ++ } ++ ++ res = libyuv::I420Scale( ++ rotated_y_plane, rotated_y_stride, rotated_u_plane, rotated_uv_stride, ++ rotated_v_plane, rotated_uv_stride, rotated_width, rotated_height, ++ buff_out, 640, ++ buff_out + 640*480, ++ 640 / 2, ++ buff_out + 640*480*5/4, ++ 640/2, 640, ++ 480, libyuv::FilterMode::kFilterNone); ++ ++ if(res){ ++ ALOGE("critical I420Scale res:%d ", res); ++ } ++} ++char buffer_recv[640*480*3/2]; ++#endif ++ + bool Sensor::threadLoop() { + /** + * Sensor capture operation main loop. +@@ -337,6 +403,10 @@ bool Sensor::threadLoop() { + + ClientVideoBuffer *handle = ClientVideoBuffer::getClientInstance(); + handle->clientBuf[handle->clientRevCount % 1].decoded = false; ++ #ifdef CROP_ROTATE ++ char *fbuffer = (char *)handle->clientBuf[handle->clientRevCount % 1].buffer; ++ bufferCropAndRotate((uint8_t*)fbuffer, (uint8_t*)buffer_recv); ++ #endif + + // Might be adding more buffers, so size isn't constant + for (size_t i = 0; i < mNextCapturedBuffers->size(); i++) { +@@ -466,7 +536,11 @@ void Sensor::dump_yuv(uint8_t *img1, size_t img1_size, uint8_t *img2, size_t img + const std::string &filename) { + static size_t count = 0; + ClientVideoBuffer *handle = ClientVideoBuffer::getClientInstance(); ++ #ifdef CROP_ROTATE ++ uint8_t *bufData = (uint8_t *)buffer_recv; ++ #else + uint8_t *bufData = handle->clientBuf[handle->clientRevCount % 1].buffer; ++ #endif + + if (++count == 120) return; + if (filename.empty()) { +@@ -527,7 +601,12 @@ void Sensor::captureRGBA(uint8_t *img, uint32_t gain, uint32_t width, uint32_t h + ALOGVV("%s: E", __FUNCTION__); + + auto *handle = ClientVideoBuffer::getClientInstance(); ++ //uint8_t *bufData = handle->clientBuf[handle->clientRevCount % 1].buffer; ++ #ifdef CROP_ROTATE ++ uint8_t *bufData = (uint8_t *)buffer_recv; ++ #else + uint8_t *bufData = handle->clientBuf[handle->clientRevCount % 1].buffer; ++ #endif + int out_size; + + if (!gIsInFrameI420 && !gIsInFrameH264) { +@@ -774,7 +853,12 @@ void Sensor::captureNV12(uint8_t *img, uint32_t gain, uint32_t width, uint32_t h + ALOGVV(LOG_TAG "%s: E", __FUNCTION__); + + ClientVideoBuffer *handle = ClientVideoBuffer::getClientInstance(); ++ //uint8_t *bufData = handle->clientBuf[handle->clientRevCount % 1].buffer; ++ #ifdef CROP_ROTATE ++ uint8_t *bufData = (uint8_t *)buffer_recv; ++ #else + uint8_t *bufData = handle->clientBuf[handle->clientRevCount % 1].buffer; ++ #endif + + ALOGVV(LOG_TAG " %s: bufData[%p] img[%p] resolution[%d:%d]", + __func__, bufData, img, width, height); +@@ -985,7 +1069,12 @@ void Sensor::captureJPEG(uint8_t *img, uint32_t gain, uint32_t width, uint32_t h + ALOGVV("%s: E", __FUNCTION__); + + ClientVideoBuffer *handle = ClientVideoBuffer::getClientInstance(); ++ //uint8_t *bufData = handle->clientBuf[handle->clientRevCount % 1].buffer; ++ #ifdef CROP_ROTATE ++ uint8_t *bufData = (uint8_t *)buffer_recv; ++ #else + uint8_t *bufData = handle->clientBuf[handle->clientRevCount % 1].buffer; ++ #endif + + int src_size = mSrcWidth * mSrcHeight; + int dstFrameSize = width * height; +-- +2.27.0 +