From 0f4de0eb23b8f0b8c0c4d0585dd55295cefeec0f Mon Sep 17 00:00:00 2001 From: chen0088 Date: Thu, 4 Jan 2024 16:19:17 +0800 Subject: [PATCH] fix:modify camera format Signed-off-by: chen0088 --- .../cameraoperator/handler/include/dcamera_handler.h | 1 + .../cameraoperator/handler/src/dcamera_handler.cpp | 11 ++++++++++- .../handler/src/dcamera_handler_common.cpp | 9 +++++++++ .../common/dcamerahandler/dcamera_handler_test.cpp | 8 ++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/services/cameraservice/cameraoperator/handler/include/dcamera_handler.h b/services/cameraservice/cameraoperator/handler/include/dcamera_handler.h index 09feb347..e052b831 100644 --- a/services/cameraservice/cameraoperator/handler/include/dcamera_handler.h +++ b/services/cameraservice/cameraoperator/handler/include/dcamera_handler.h @@ -49,6 +49,7 @@ private: ~DCameraHandler(); private: + const uint32_t INVALID_FORMAT = -1; int32_t CreateDHItem(sptr& info, DHItem& item); int32_t CreateAVCodecList(Json::Value& root); std::string GetCameraPosition(CameraStandard::CameraPosition position); diff --git a/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp b/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp index 8505f8e0..6cdcc387 100644 --- a/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp +++ b/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp @@ -238,6 +238,9 @@ void DCameraHandler::ConfigFormatAndResolution(const DCStreamType type, Json::Va CameraStandard::CameraFormat format = profile.GetCameraFormat(); CameraStandard::Size picSize = profile.GetSize(); int32_t dformat = CovertToDcameraFormat(format); + if (dformat == INVALID_FORMAT) { + continue; + } formatSet.insert(dformat); DHLOGI("width: %d, height: %d, format: %d", picSize.width, picSize.height, dformat); std::string formatName = std::to_string(dformat); @@ -265,7 +268,7 @@ void DCameraHandler::ConfigFormatAndResolution(const DCStreamType type, Json::Va int32_t DCameraHandler::CovertToDcameraFormat(CameraStandard::CameraFormat format) { DHLOGI("format: %d", format); - int32_t ret = -1; + int32_t ret = INVALID_FORMAT; switch (format) { case CameraStandard::CameraFormat::CAMERA_FORMAT_RGBA_8888: ret = camera_format_t::OHOS_CAMERA_FORMAT_RGBA_8888; @@ -279,6 +282,12 @@ int32_t DCameraHandler::CovertToDcameraFormat(CameraStandard::CameraFormat forma case CameraStandard::CameraFormat::CAMERA_FORMAT_JPEG: ret = camera_format_t::OHOS_CAMERA_FORMAT_JPEG; break; + case CameraStandard::CameraFormat::CAMERA_FORMAT_YCBCR_P010: + ret = camera_format_t::OHOS_CAMERA_FORMAT_YCBCR_P010; + break; + case CameraStandard::CameraFormat::CAMERA_FORMAT_YCRCB_P010: + ret = camera_format_t::OHOS_CAMERA_FORMAT_YCRCB_P010; + break; default: DHLOGE("invalid camera format"); break; diff --git a/services/cameraservice/cameraoperator/handler/src/dcamera_handler_common.cpp b/services/cameraservice/cameraoperator/handler/src/dcamera_handler_common.cpp index 8505f8e0..5c798073 100644 --- a/services/cameraservice/cameraoperator/handler/src/dcamera_handler_common.cpp +++ b/services/cameraservice/cameraoperator/handler/src/dcamera_handler_common.cpp @@ -238,6 +238,9 @@ void DCameraHandler::ConfigFormatAndResolution(const DCStreamType type, Json::Va CameraStandard::CameraFormat format = profile.GetCameraFormat(); CameraStandard::Size picSize = profile.GetSize(); int32_t dformat = CovertToDcameraFormat(format); + if (dformat == INVALID_FORMAT) { + continue; + } formatSet.insert(dformat); DHLOGI("width: %d, height: %d, format: %d", picSize.width, picSize.height, dformat); std::string formatName = std::to_string(dformat); @@ -279,6 +282,12 @@ int32_t DCameraHandler::CovertToDcameraFormat(CameraStandard::CameraFormat forma case CameraStandard::CameraFormat::CAMERA_FORMAT_JPEG: ret = camera_format_t::OHOS_CAMERA_FORMAT_JPEG; break; + case CameraStandard::CameraFormat::CAMERA_FORMAT_YCBCR_P010: + ret = camera_format_t::OHOS_CAMERA_FORMAT_YCBCR_P010; + break; + case CameraStandard::CameraFormat::CAMERA_FORMAT_YCRCB_P010: + ret = camera_format_t::OHOS_CAMERA_FORMAT_YCRCB_P010; + break; default: DHLOGE("invalid camera format"); break; diff --git a/services/cameraservice/cameraoperator/handler/test/unittest/common/dcamerahandler/dcamera_handler_test.cpp b/services/cameraservice/cameraoperator/handler/test/unittest/common/dcamerahandler/dcamera_handler_test.cpp index bee53ae3..9d7bb3a3 100644 --- a/services/cameraservice/cameraoperator/handler/test/unittest/common/dcamerahandler/dcamera_handler_test.cpp +++ b/services/cameraservice/cameraoperator/handler/test/unittest/common/dcamerahandler/dcamera_handler_test.cpp @@ -219,6 +219,14 @@ HWTEST_F(DCameraHandlerTest, dcamera_handler_test_007, TestSize.Level1) ret = DCameraHandler::GetInstance().CovertToDcameraFormat( CameraStandard::CameraFormat::CAMERA_FORMAT_JPEG); EXPECT_EQ(ret, OHOS_CAMERA_FORMAT_JPEG); + + ret = DCameraHandler::GetInstance().CovertToDcameraFormat( + CameraStandard::CameraFormat::CAMERA_FORMAT_YCBCR_P010); + EXPECT_EQ(ret, OHOS_CAMERA_FORMAT_YCBCR_P010); + + ret = DCameraHandler::GetInstance().CovertToDcameraFormat( + CameraStandard::CameraFormat::CAMERA_FORMAT_YCRCB_P010); + EXPECT_EQ(ret, OHOS_CAMERA_FORMAT_YCRCB_P010); } /** -- Gitee