From aba05832a6fb3e72444fc144ef7355a7fb0dc938 Mon Sep 17 00:00:00 2001 From: ForeverMeteor <2675561402@qq.com> Date: Mon, 15 Jul 2024 15:06:59 +0800 Subject: [PATCH 1/7] feature 20240715 camera.ZoomQuery camera.Zoom add 4 new apis Change-Id: I147be23585054ef089aba068210b1481aefb23b6 --- bundle.json | 3 +- frameworks/cj/BUILD.gn | 91 +++++++++++++++++++++++++ frameworks/cj/include/zoom.h | 42 ++++++++++++ frameworks/cj/include/zoom_ffi.h | 34 ++++++++++ frameworks/cj/include/zoom_utils.h | 28 ++++++++ frameworks/cj/include/zoomquery.h | 41 +++++++++++ frameworks/cj/src/zoom.cpp | 105 +++++++++++++++++++++++++++++ frameworks/cj/src/zoom_ffi.cpp | 81 ++++++++++++++++++++++ frameworks/cj/src/zoom_utils.cpp | 8 +++ frameworks/cj/src/zoomquery.cpp | 79 ++++++++++++++++++++++ 10 files changed, 511 insertions(+), 1 deletion(-) create mode 100644 frameworks/cj/BUILD.gn create mode 100644 frameworks/cj/include/zoom.h create mode 100644 frameworks/cj/include/zoom_ffi.h create mode 100644 frameworks/cj/include/zoom_utils.h create mode 100644 frameworks/cj/include/zoomquery.h create mode 100644 frameworks/cj/src/zoom.cpp create mode 100644 frameworks/cj/src/zoom_ffi.cpp create mode 100644 frameworks/cj/src/zoom_utils.cpp create mode 100644 frameworks/cj/src/zoomquery.cpp diff --git a/bundle.json b/bundle.json index 020f16db..0b7dae9d 100644 --- a/bundle.json +++ b/bundle.json @@ -67,7 +67,8 @@ "//foundation/multimedia/camera_framework/interfaces/kits/js/camera_napi:camerapicker_napi", "//foundation/multimedia/camera_framework/interfaces/kits/js/camera_napi:camera_napi", "//foundation/multimedia/camera_framework/interfaces/kits/js/camera_napi:camera_js", - "//foundation/multimedia/camera_framework/interfaces/kits/js/camera_napi:camerapicker_js" + "//foundation/multimedia/camera_framework/interfaces/kits/js/camera_napi:camerapicker_js", + "//foundation/multimedia/camera_framework/frameworks/cj:cj_camera_ffi" ], "service_group": [ "//foundation/multimedia/camera_framework/sa_profile:camera_service_sa_profile", diff --git a/frameworks/cj/BUILD.gn b/frameworks/cj/BUILD.gn new file mode 100644 index 00000000..33f4e899 --- /dev/null +++ b/frameworks/cj/BUILD.gn @@ -0,0 +1,91 @@ +# Copyright (C) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/ohos/ace/ace.gni") +import("./../../multimedia_camera_framework.gni") + +config("camera_ffi_public_config") { + visibility = [ ":*" ] + include_dirs = [ "include" ] +} + +ohos_shared_library("cj_camera_ffi") { + branch_protector_ret = "pac_ret" + + public_configs = [ ":camera_ffi_public_config" ] + include_dirs = [ + "${multimedia_camera_framework_path}/interfaces/inner_api/native/camera/include", + "${multimedia_camera_framework_path}/services/camera_service/include", + "${multimedia_camera_framework_path}/frameworks/native/camera/include", + "${multimedia_camera_framework_path}/services/camera_service/binder/base/include/", + "${multimedia_camera_framework_path}/services/camera_service/binder/client/include", + "${multimedia_camera_framework_path}/services/camera_service/binder/server/include", + "${multimedia_image_framework_path}/interfaces/innerkits/include", + "${multimedia_image_framework_path}/frameworks/cj/include", + ] + + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + cflags = [ "-fPIC" ] + cflags_cc = cflags + + if (!defined(defines)) { + defines = [] + } + + if (!ohos_indep_compiler_enable && !build_ohos_sdk && + product_name != "qemu-arm-linux-min" && + product_name != "rk3568_mini_system") { + deps = [ "${multimedia_camera_framework_path}/frameworks/native/camera:camera_framework" ] + external_deps = [ + "c_utils:utils", + "drivers_interface_camera:libcamera_proxy_1.0", + "drivers_interface_camera:libcamera_proxy_1.1", + "graphic_surface:surface", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "napi:ace_napi", + "napi:cj_bind_ffi", + "napi:cj_bind_native", + ] + sources = [ + "src/camera_manager_ffi.cpp", + "src/zoom_ffi.cpp", + "src/zoom_utils.cpp", + "src/zoom.cpp", + "src/zoomquery.cpp" + ] + } else { + defines += [ "PREVIEWER" ] + #sources = [ "src/cj_image_mock.cpp" ] + external_deps = [ "napi:cj_bind_ffi" ] + } + + if (is_ohos) { + defines += [ "OHOS_PLATFORM" ] + } + + if (is_mingw) { + defines += [ "WINDOWS_PLATFORM" ] + } + + innerapi_tags = [ "platformsdk" ] + + subsystem_name = "multimedia" + part_name = "camera_framework" +} diff --git a/frameworks/cj/include/zoom.h b/frameworks/cj/include/zoom.h new file mode 100644 index 00000000..195fb02c --- /dev/null +++ b/frameworks/cj/include/zoom.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ZOOM_FFI_H +#define ZOOM_FFI_H + +#include "zoomquery.h" + +namespace OHOS { +namespace CameraStandard { + +class __attribute__((visibility("default"))) CjZoom : public OHOS::CameraStandard::CjZoomQuery { + DECL_TYPE(CjZoom, OHOS::FFI::FFIData) +public: + // static void Init(); + // static CjZoom CreateCjZoom(); + explicit CjZoom() = default; + ~CjZoom() override; + + int32_t GetZoomRatio(double& zoomRatio); + int32_t SetZoomRatio(double zoomRatio); + int32_t SetSmoothZoom(double targetZoomRatio, int32_t smoothZoomType); + +private: + sptr cameraSession_; +}; + +} +} +#endif \ No newline at end of file diff --git a/frameworks/cj/include/zoom_ffi.h b/frameworks/cj/include/zoom_ffi.h new file mode 100644 index 00000000..01ca7e81 --- /dev/null +++ b/frameworks/cj/include/zoom_ffi.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ffi_remote_data.h" +#include "cj_common_ffi.h" +#include "camera_log.h" +#include "zoom_utils.h" + +namespace OHOS { +namespace CameraStandard { + +extern "C"{ + FFI_EXPORT int64_t FfiOHOSZoomQueryConstructor(); + FFI_EXPORT int32_t FfiOHOSZoomQueryGetZoomRatioRange(int64_t id, CArrDouble& cArrDouble); + FFI_EXPORT int64_t FfiOHOSZoomConstructor(); + FFI_EXPORT int32_t FfiOHOSZoomGetZoomRaio(int64_t id, double& zoomRatio); + FFI_EXPORT int32_t FfiOHOSZoomSetZoomRaio(int64_t id, double zoomRatio); + FFI_EXPORT int32_t FfiOHOSZoomSetSmoothZoom(int64_t id, double targetZoomRatio, int32_t smoothZoomType); +} + +} +} \ No newline at end of file diff --git a/frameworks/cj/include/zoom_utils.h b/frameworks/cj/include/zoom_utils.h new file mode 100644 index 00000000..c53c22ea --- /dev/null +++ b/frameworks/cj/include/zoom_utils.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "input/camera_manager.h" + +double FloatToDouble(float val); + +struct CArrDouble{ + double* head; + int64_t size; +}; + +struct RetDataCArrDouble{ + int32_t code; + CArrDouble data; +}; \ No newline at end of file diff --git a/frameworks/cj/include/zoomquery.h b/frameworks/cj/include/zoomquery.h new file mode 100644 index 00000000..b21527e4 --- /dev/null +++ b/frameworks/cj/include/zoomquery.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ZOOMQUERY_FFI_H +#define ZOOMQUERY_FFI_H + +#include +#include "zoom_ffi.h" + +namespace OHOS { +namespace CameraStandard { + +class __attribute__((visibility("default"))) CjZoomQuery : public OHOS::FFI::FFIData { + DECL_TYPE(CjZoomQuery, OHOS::FFI::FFIData) +public: + // static void Init(); + // static CjZoomQuery CreateCjZoomQuery(); + explicit CjZoomQuery() = default; + ~CjZoomQuery() override; + + int32_t GetZoomRatioRange(CArrDouble& cArrDouble); + +private: + sptr cameraSession_; +}; + +} +} +#endif \ No newline at end of file diff --git a/frameworks/cj/src/zoom.cpp b/frameworks/cj/src/zoom.cpp new file mode 100644 index 00000000..adbc658d --- /dev/null +++ b/frameworks/cj/src/zoom.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "zoom.h" + +namespace OHOS { +namespace CameraStandard { + +// CjZoom::CjZoom(){ } + +// CjZoom::~CjZoom(){ +// MEDIA_DEBUG_LOG("~CjZoom is called"); +// } + +// void CjZoom::Init(){ +// MEDIA_DEBUG_LOG("Init is called"); +// } + +// CjZoom CjZoom::CreateCjZoom(){ +// MEDIA_DEBUG_LOG("CreateCjZoom is called"); +// CAMERA_SYNC_TRACE; +// // CameraManager::GetInstance()->CreateCaptureSession(&cameraSession_); +// } + +using namespace OHOS::FFI; + +CjZoom::~CjZoom(){ + MEDIA_INFO_LOG("~CjZoom() is called."); +} + +int32_t CjZoom::GetZoomRatio(double& zoomRatio){ + MEDIA_INFO_LOG("GetZoomRatio is called!"); + + if(cameraSession_ == nullptr){ + MEDIA_ERR_LOG("GetZoomRatio call Failed!"); + MEDIA_ERR_LOG("camerasession is nullptr."); + MEDIA_ERR_LOG("RetCode: -1"); + return -1; + } + + float zoomRatioFloat; + int32_t retCode = cameraSession_->GetZoomRatio(zoomRatioFloat); + if (retCode != 0){ + MEDIA_ERR_LOG("GetZoomRatio call Failed!"); + MEDIA_ERR_LOG("RetCode: %{public}d", retCode); + return retCode; + } + zoomRatio = FloatToDouble(zoomRatioFloat); + return retCode; +} + +int32_t CjZoom::SetZoomRatio(double zoomRatio){ + MEDIA_INFO_LOG("SetZoomRatio is called!"); + + if(cameraSession_ == nullptr){ + MEDIA_ERR_LOG("SetZoomRatio call Failed!"); + MEDIA_ERR_LOG("camerasession is nullptr."); + MEDIA_ERR_LOG("RetCode: -1"); + return -1; + } + + cameraSession_->LockForControl(); + int32_t retCode = cameraSession_->SetZoomRatio(zoomRatio); + cameraSession_->UnlockForControl(); + if(retCode != 0){ + MEDIA_ERR_LOG("SetZoomRatio call Failed!"); + MEDIA_ERR_LOG("RetCode: %{public}d", retCode); + } + return retCode; +} + +int32_t CjZoom::SetSmoothZoom(double targetZoomRatio, int32_t smoothZoomType){ + MEDIA_INFO_LOG("SetSmoothZoom is called!"); + + if(cameraSession_ == nullptr){ + MEDIA_ERR_LOG("SetSmoothZoom call Failed!"); + MEDIA_ERR_LOG("camerasession is nullptr."); + MEDIA_ERR_LOG("RetCode: -1"); + return -1; + } + + cameraSession_->LockForControl(); + int32_t retCode = cameraSession_->SetSmoothZoom((float)targetZoomRatio, smoothZoomType); + cameraSession_->UnlockForControl(); + if(retCode != 0){ + MEDIA_ERR_LOG("SetSmoothZoom call Failed!"); + MEDIA_ERR_LOG("RetCode: %{public}d", retCode); + } + return retCode; +} + +} // namespace CameraStandard +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/cj/src/zoom_ffi.cpp b/frameworks/cj/src/zoom_ffi.cpp new file mode 100644 index 00000000..475b8fc5 --- /dev/null +++ b/frameworks/cj/src/zoom_ffi.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "zoom.h" + +using namespace OHOS::FFI; + +namespace OHOS { +namespace CameraStandard { + +extern "C"{ + int64_t FfiOHOSZoomQueryConstructor(){ + auto zoomQuery = FFIData::Create(); + if (zoomQuery == nullptr){ + MEDIA_ERR_LOG("New ZoomQuery Failed!"); + return -1; + } + return zoomQuery->GetID(); + } + + int32_t FfiOHOSZoomQueryGetZoomRatioRange(int64_t id, CArrDouble& cArrDouble){ + auto zoomQuery = FFIData::GetData(id); + if (zoomQuery == nullptr){ //is init? + MEDIA_ERR_LOG("GetZoomRaioRange Failed!"); + return -1; + } + return zoomQuery->GetZoomRatioRange(cArrDouble); + } + + int64_t FfiOHOSZoomConstructor(){ + auto zoom = FFIData::Create(); + if (zoom == nullptr){ + MEDIA_ERR_LOG("New Zoom Failed!"); + return -1; + } + return zoom->GetID(); + } + + int32_t FfiOHOSZoomGetZoomRaio(int64_t id, double& zoomRatio){ + auto zoom = FFIData::GetData(id); + if (zoom == nullptr){ //is init? + MEDIA_ERR_LOG("GetZoomRaio Failed!"); + return -1; + } + return zoom->GetZoomRatio(zoomRatio); + } + + int32_t FfiOHOSZoomSetZoomRaio(int64_t id, double zoomRatio){ + auto zoom = FFIData::GetData(id); + if (zoom == nullptr){ //is init? + MEDIA_ERR_LOG("SetZoomRaio Failed!"); + return -1; + } + return zoom->SetZoomRatio(zoomRatio); + } + + int32_t FfiOHOSZoomSetSmoothZoom(int64_t id, double targetZoomRatio, int32_t smoothZoomType){ + auto zoom = FFIData::GetData(id); + if (zoom == nullptr){ //is init? + MEDIA_ERR_LOG("SetSmoothZoom Failed!"); + return -1; + } + return zoom->SetSmoothZoom(targetZoomRatio, smoothZoomType); + } + +} + +} +} \ No newline at end of file diff --git a/frameworks/cj/src/zoom_utils.cpp b/frameworks/cj/src/zoom_utils.cpp new file mode 100644 index 00000000..06284de7 --- /dev/null +++ b/frameworks/cj/src/zoom_utils.cpp @@ -0,0 +1,8 @@ +#include "zoom_utils.h" + +double FloatToDouble(float val){ + const double precision = 1000000.0; + val *= precision; + double result = static_cast(val / precision); + return result; +} \ No newline at end of file diff --git a/frameworks/cj/src/zoomquery.cpp b/frameworks/cj/src/zoomquery.cpp new file mode 100644 index 00000000..f1f9ad38 --- /dev/null +++ b/frameworks/cj/src/zoomquery.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "zoomquery.h" + +namespace OHOS { +namespace CameraStandard { + +// CjZoomQuery::CjZoomQuery(){ } + +// CjZoomQuery::~CjZoomQuery(){ +// MEDIA_DEBUG_LOG("~CjZoomQuery is called"); +// } + +// void CjZoomQuery::Init(){ +// MEDIA_DEBUG_LOG("Init is called"); +// } + +// CjZoomQuery CjZoomQuery::CreateCjZoomQuery(){ +// MEDIA_DEBUG_LOG("CreateCjZoom is called"); +// CAMERA_SYNC_TRACE; +// // CameraManager::GetInstance()->CreateCaptureSession(&cameraSession_); +// } + +using namespace OHOS::FFI; + +CjZoomQuery::~CjZoomQuery(){ + MEDIA_INFO_LOG("~CjZoomQuery() is called."); +} + +int32_t CjZoomQuery::GetZoomRatioRange(CArrDouble& cArrDouble){ + MEDIA_INFO_LOG("GetZoomRatioRange is called!"); + + if(cameraSession_ == nullptr){ + MEDIA_ERR_LOG("GetZoomRatioRange call Failed!"); + MEDIA_ERR_LOG("camerasession is nullptr."); + MEDIA_ERR_LOG("RetCode: -1"); + return -1; + } + + std::vector vecZoomRatioList; + int32_t retCode = cameraSession_->GetZoomRatioRange(vecZoomRatioList); + + if (retCode != 0){ + MEDIA_ERR_LOG("GetZoomRatioRange call Failed!"); + MEDIA_ERR_LOG("RetCode: %{public}d", retCode); + return retCode; + } + + MEDIA_INFO_LOG("CjZoomQuery::GetZoomRatioRange len = %{public}zu", + vecZoomRatioList.size()); + + if (!vecZoomRatioList.empty()){ + double* retVecZoomRatioList = (double*)malloc(sizeof(double)*vecZoomRatioList.size()); + for (size_t i = 0; i < vecZoomRatioList.size(); ++i){ + retVecZoomRatioList[i] = FloatToDouble(vecZoomRatioList[i]); + } + cArrDouble.head = retVecZoomRatioList; + cArrDouble.size = vecZoomRatioList.size(); + } else { + MEDIA_ERR_LOG("vecSupportedZoomRatioList is empty!"); + } + return retCode; +} + +} // namespace CameraStandard +} // namespace OHOS \ No newline at end of file -- Gitee From 2c936fcdb2010f5002eb987b0f8b55dedbc7557a Mon Sep 17 00:00:00 2001 From: ForeverMeteor <2675561402@qq.com> Date: Tue, 16 Jul 2024 15:21:42 +0800 Subject: [PATCH 2/7] feature 20240716 add autoexposurequery, autoexposure Change-Id: I354b551f947b26f303ca0df00e01452981894722 --- frameworks/cj/BUILD.gn | 7 +- frameworks/cj/include/autoexposure.h | 45 +++++ frameworks/cj/include/autoexposure_ffi.h | 38 +++++ frameworks/cj/include/autoexposurequery.h | 42 +++++ frameworks/cj/include/camera_manager_ffi.h | 36 ++++ .../cj/include/{zoom_utils.h => utils.h} | 0 frameworks/cj/include/zoom_ffi.h | 2 +- frameworks/cj/src/autoexposure.cpp | 161 ++++++++++++++++++ frameworks/cj/src/autoexposure_ffi.cpp | 122 +++++++++++++ frameworks/cj/src/autoexposurequery.cpp | 95 +++++++++++ frameworks/cj/src/camera_manager_ffi.cpp | 22 +++ .../cj/src/{zoom_utils.cpp => utils.cpp} | 2 +- 12 files changed, 568 insertions(+), 4 deletions(-) create mode 100644 frameworks/cj/include/autoexposure.h create mode 100644 frameworks/cj/include/autoexposure_ffi.h create mode 100644 frameworks/cj/include/autoexposurequery.h create mode 100644 frameworks/cj/include/camera_manager_ffi.h rename frameworks/cj/include/{zoom_utils.h => utils.h} (100%) create mode 100644 frameworks/cj/src/autoexposure.cpp create mode 100644 frameworks/cj/src/autoexposure_ffi.cpp create mode 100644 frameworks/cj/src/autoexposurequery.cpp create mode 100644 frameworks/cj/src/camera_manager_ffi.cpp rename frameworks/cj/src/{zoom_utils.cpp => utils.cpp} (87%) diff --git a/frameworks/cj/BUILD.gn b/frameworks/cj/BUILD.gn index 33f4e899..fce3baf0 100644 --- a/frameworks/cj/BUILD.gn +++ b/frameworks/cj/BUILD.gn @@ -65,10 +65,13 @@ ohos_shared_library("cj_camera_ffi") { ] sources = [ "src/camera_manager_ffi.cpp", + "src/utils.cpp", "src/zoom_ffi.cpp", - "src/zoom_utils.cpp", "src/zoom.cpp", - "src/zoomquery.cpp" + "src/zoomquery.cpp", + "src/autoexposure_ffi.cpp", + "src/autoexposure.cpp", + "src/autoexposurequery.cpp" ] } else { defines += [ "PREVIEWER" ] diff --git a/frameworks/cj/include/autoexposure.h b/frameworks/cj/include/autoexposure.h new file mode 100644 index 00000000..4d20f447 --- /dev/null +++ b/frameworks/cj/include/autoexposure.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AUTOEXPOSURE_FFI_H +#define AUTOEXPOSURE_FFI_H + +#include "autoexposurequery.h" + +namespace OHOS { +namespace CameraStandard { + +class __attribute__((visibility("default"))) CjAutoExposure : public OHOS::CameraStandard::CjAutoExposureQuery { + DECL_TYPE(CjAutoExposure, OHOS::FFI::FFIData) +public: + // static void Init(); + // static CjAutoExposure CreateCjAutoExposure(); + explicit CjAutoExposure() = default; + ~CjAutoExposure() override; + + int32_t GetExposureMode(ExposureMode& exposureMode); + int32_t SetExposureMode(ExposureMode exposureMode); + int32_t GetMeteringPoint(Point& exposurePoint); + int32_t SetMeteringPoint(Point exposurePoint); + int32_t SetExposureBias(double exposureValue); + int32_t GetExposureValue(double& exposureValue); + +private: + sptr cameraSession_; +}; + +} +} +#endif \ No newline at end of file diff --git a/frameworks/cj/include/autoexposure_ffi.h b/frameworks/cj/include/autoexposure_ffi.h new file mode 100644 index 00000000..0d3b4d77 --- /dev/null +++ b/frameworks/cj/include/autoexposure_ffi.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ffi_remote_data.h" +#include "cj_common_ffi.h" +#include "camera_log.h" +#include "utils.h" + +namespace OHOS { +namespace CameraStandard { + +extern "C"{ + FFI_EXPORT int64_t FfiOHOSAutoExposureQueryConstructor(); + FFI_EXPORT int32_t FfiOHOSAutoExposureQueryIsExposureModeSupported(int64_t id, int32_t exposureModeInt, bool& isSupported); + FFI_EXPORT int32_t FfiOHOSAutoExposureQueryGetExposureBiasRange(int64_t id, CArrDouble& exposureBiasList); + FFI_EXPORT int64_t FfiOHOSAutoExposureConstructor(); + FFI_EXPORT int32_t FfiOHOSAutoExposureGetExposureMode(int64_t id, int32_t& exposureModeInt); + FFI_EXPORT int32_t FfiOHOSAutoExposureSetExposureMode(int64_t id, int32_t exposureModeInt); + FFI_EXPORT int32_t FfiOHOSAutoExposureGetMeteringPoint(int64_t id, Point& exposurePoint); + FFI_EXPORT int32_t FfiOHOSAutoExposureSetMeteringPoint(int64_t id, Point exposurePoint); + FFI_EXPORT int32_t FfiOHOSAutoExposureSetExposureBias(int64_t id, double exposureValue); + FFI_EXPORT int32_t FfiOHOSAutoExposureGetExposureValue(int64_t id, double& exposureValue); +} + +} +} \ No newline at end of file diff --git a/frameworks/cj/include/autoexposurequery.h b/frameworks/cj/include/autoexposurequery.h new file mode 100644 index 00000000..a9aab0e8 --- /dev/null +++ b/frameworks/cj/include/autoexposurequery.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AUTOEXPOSUREQUREY_FFI_H +#define AUTOEXPOSUREQUREY_FFI_H + +#include "autoexposure_ffi.h" +#include "capture_session.h" + +namespace OHOS { +namespace CameraStandard { + +class __attribute__((visibility("default"))) CjAutoExposureQuery : public OHOS::FFI::FFIData { + DECL_TYPE(CjAutoExposureQuery, OHOS::FFI::FFIData) +public: + // static void Init(); + // static CjAutoExposureQuery CreateCjAutoExposureQuery(); + explicit CjAutoExposureQuery() = default; + ~CjAutoExposureQuery() override; + + int32_t IsExposureModeSupported(ExposureMode exposureMode, bool& isSupported); + int32_t GetExposureBiasRange(CArrDouble& exposureBiasList); + +private: + sptr cameraSession_; +}; + +} +} +#endif \ No newline at end of file diff --git a/frameworks/cj/include/camera_manager_ffi.h b/frameworks/cj/include/camera_manager_ffi.h new file mode 100644 index 00000000..225f45e0 --- /dev/null +++ b/frameworks/cj/include/camera_manager_ffi.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CAMERA_MANAGER_FFI_H +#define CAMERA_MANAGER_FFI_H + +#include "ffi_remote_data.h" +#include "input/camera_manager.h" + +namespace OHOS { +namespace CameraStandard { + +class CjCameraManager : public OHOS::FFI::FFIData { + DECL_TYPE(CjCameraManager, OHOS::FFI::FFIData) +public: + + CjCameraManager(); + ~CjCameraManager() override; +private: + sptr cameraManager_; +}; +} // namespace CameraStandard +} // namespace OHOS +#endif /* CAMERA_MANAGER_FFI_H */ \ No newline at end of file diff --git a/frameworks/cj/include/zoom_utils.h b/frameworks/cj/include/utils.h similarity index 100% rename from frameworks/cj/include/zoom_utils.h rename to frameworks/cj/include/utils.h diff --git a/frameworks/cj/include/zoom_ffi.h b/frameworks/cj/include/zoom_ffi.h index 01ca7e81..71021d67 100644 --- a/frameworks/cj/include/zoom_ffi.h +++ b/frameworks/cj/include/zoom_ffi.h @@ -16,7 +16,7 @@ #include "ffi_remote_data.h" #include "cj_common_ffi.h" #include "camera_log.h" -#include "zoom_utils.h" +#include "utils.h" namespace OHOS { namespace CameraStandard { diff --git a/frameworks/cj/src/autoexposure.cpp b/frameworks/cj/src/autoexposure.cpp new file mode 100644 index 00000000..f5b466c6 --- /dev/null +++ b/frameworks/cj/src/autoexposure.cpp @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "autoexposure.h" + +namespace OHOS { +namespace CameraStandard { + +// void CjAutoExposure::Init(){ +// MEDIA_DEBUG_LOG("Init is called"); +// } + +// CjAutoExposure CjAutoExposure::CreateCjAutoExposure(){ +// MEDIA_DEBUG_LOG("CreateCjAutoExposure is called"); +// CAMERA_SYNC_TRACE; +// // CameraManager::GetInstance()->CreateCaptureSession(&cameraSession_); +// } + +using namespace OHOS::FFI; + +CjAutoExposure::~CjAutoExposure(){ + MEDIA_INFO_LOG("~CjAutoExposure() is called."); +} + +int32_t CjAutoExposure::GetExposureMode(ExposureMode& exposureMode){ + MEDIA_INFO_LOG("GetExposureMode is called!"); + + if(cameraSession_ == nullptr){ + MEDIA_ERR_LOG("GetExposureMode call Failed!"); + MEDIA_ERR_LOG("camerasession is nullptr."); + MEDIA_ERR_LOG("RetCode: -1"); + return -1; + } + + int32_t retCode = cameraSession_->GetExposureMode(exposureMode); + + if (retCode != 0){ + MEDIA_ERR_LOG("GetExposureMode call Failed!"); + MEDIA_ERR_LOG("RetCode: %{public}d", retCode); + } + return retCode; +} + +int32_t CjAutoExposure::SetExposureMode(ExposureMode exposureMode){ + MEDIA_INFO_LOG("SetExposureMode is called!"); + + if(cameraSession_ == nullptr){ + MEDIA_ERR_LOG("SetExposureMode call Failed!"); + MEDIA_ERR_LOG("camerasession is nullptr."); + MEDIA_ERR_LOG("RetCode: -1"); + return -1; + } + + cameraSession_->LockForControl(); + int32_t retCode = cameraSession_->SetExposureMode(exposureMode); + cameraSession_->UnlockForControl(); + + if (retCode != 0){ + MEDIA_ERR_LOG("SetExposureMode call Failed!"); + MEDIA_ERR_LOG("RetCode: %{public}d", retCode); + } + return retCode; +} + +int32_t CjAutoExposure::GetMeteringPoint(Point& exposurePoint){ + MEDIA_INFO_LOG("GetMeteringPoint is called!"); + + if(cameraSession_ == nullptr){ + MEDIA_ERR_LOG("GetMeteringPoint call Failed!"); + MEDIA_ERR_LOG("camerasession is nullptr."); + MEDIA_ERR_LOG("RetCode: -1"); + return -1; + } + + int32_t retCode = cameraSession_->GetMeteringPoint(exposurePoint); + + if (retCode != 0){ + MEDIA_ERR_LOG("GetMeteringPoint call Failed!"); + MEDIA_ERR_LOG("RetCode: %{public}d", retCode); + } + return retCode; +} + +int32_t CjAutoExposure::SetMeteringPoint(Point exposurePoint){ + MEDIA_INFO_LOG("SetMeteringPoint is called!"); + + if(cameraSession_ == nullptr){ + MEDIA_ERR_LOG("SetMeteringPoint call Failed!"); + MEDIA_ERR_LOG("camerasession is nullptr."); + MEDIA_ERR_LOG("RetCode: -1"); + return -1; + } + + cameraSession_->LockForControl(); + int32_t retCode = cameraSession_->SetMeteringPoint(exposurePoint); + cameraSession_->UnlockForControl(); + + if (retCode != 0){ + MEDIA_ERR_LOG("SetMeteringPoint call Failed!"); + MEDIA_ERR_LOG("RetCode: %{public}d", retCode); + } + return retCode; +} + +int32_t CjAutoExposure::SetExposureBias(double exposureValue){ + MEDIA_INFO_LOG("SetExposureBias is called!"); + + if(cameraSession_ == nullptr){ + MEDIA_ERR_LOG("SetExposureBias call Failed!"); + MEDIA_ERR_LOG("camerasession is nullptr."); + MEDIA_ERR_LOG("RetCode: -1"); + return -1; + } + + cameraSession_->LockForControl(); + int32_t retCode = cameraSession_->SetExposureBias((float)exposureValue); + cameraSession_->UnlockForControl(); + + if (retCode != 0){ + MEDIA_ERR_LOG("SetExposureBias call Failed!"); + MEDIA_ERR_LOG("RetCode: %{public}d", retCode); + } + return retCode; +} + +int32_t CjAutoExposure::GetExposureValue(double& exposureValue){ + MEDIA_INFO_LOG("GetExposureValue is called!"); + + if(cameraSession_ == nullptr){ + MEDIA_ERR_LOG("GetExposureValue call Failed!"); + MEDIA_ERR_LOG("camerasession is nullptr."); + MEDIA_ERR_LOG("RetCode: -1"); + return -1; + } + + float exposureValueFloat; + int32_t retCode = cameraSession_->GetExposureValue(exposureValueFloat); + exposureValue = FloatToDouble(exposureValueFloat); + + if (retCode != 0){ + MEDIA_ERR_LOG("GetExposureValue call Failed!"); + MEDIA_ERR_LOG("RetCode: %{public}d", retCode); + } + return retCode; +} + + +} // namespace CameraStandard +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/cj/src/autoexposure_ffi.cpp b/frameworks/cj/src/autoexposure_ffi.cpp new file mode 100644 index 00000000..003432b9 --- /dev/null +++ b/frameworks/cj/src/autoexposure_ffi.cpp @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "autoexposure.h" + +using namespace OHOS::FFI; + +namespace OHOS { +namespace CameraStandard { + +extern "C"{ + // AutoExposureQuery + int64_t FfiOHOSAutoExposureQueryConstructor(){ + auto autoExposureQuery = FFIData::Create(); + if (autoExposureQuery == nullptr){ + MEDIA_ERR_LOG("New AutoExposureQuery Failed!"); + return -1; + } + return autoExposureQuery->GetID(); + } + + int32_t FfiOHOSAutoExposureQueryIsExposureModeSupported(int64_t id, int32_t exposureModeInt, bool& isSupported){ + auto autoExposureQuery = FFIData::GetData(id); + if(autoExposureQuery == nullptr){ //is init? + MEDIA_ERR_LOG("IsExposureModeSupported Failed!"); + return -1; + } + return autoExposureQuery->IsExposureModeSupported(static_cast(exposureModeInt), isSupported); + } + + int32_t FfiOHOSAutoExposureQueryGetExposureBiasRange(int64_t id, CArrDouble& exposureBiasList){ + auto autoExposureQuery = FFIData::GetData(id); + if(autoExposureQuery == nullptr){ //is init? + MEDIA_ERR_LOG("IsExposureModeSupported Failed!"); + return -1; + } + return autoExposureQuery->GetExposureBiasRange(exposureBiasList); + } + + //AutoExposure + int64_t FfiOHOSAutoExposureConstructor(){ + auto autoExposure = FFIData::Create(); + if (autoExposure == nullptr){ + MEDIA_ERR_LOG("New AutoExposure Failed!"); + return -1; + } + return autoExposure->GetID(); + } + + int32_t FfiOHOSAutoExposureGetExposureMode(int64_t id, int32_t& exposureModeInt){ + auto autoExposure = FFIData::GetData(id); + if(autoExposure == nullptr){ //is init? + MEDIA_ERR_LOG("GetExposureMode Failed!"); + return -1; + } + ExposureMode exposureMode; + int32_t retCode = autoExposure->GetExposureMode(exposureMode); + exposureModeInt = static_cast(exposureMode); + return retCode; + } + + int32_t FfiOHOSAutoExposureSetExposureMode(int64_t id, int32_t exposureModeInt){ + auto autoExposure = FFIData::GetData(id); + if(autoExposure == nullptr){ //is init? + MEDIA_ERR_LOG("SetExposureMode Failed!"); + return -1; + } + return autoExposure->SetExposureMode(static_cast(exposureModeInt)); + } + + int32_t FfiOHOSAutoExposureGetMeteringPoint(int64_t id, Point& exposurePoint){ + auto autoExposure = FFIData::GetData(id); + if(autoExposure == nullptr){ //is init? + MEDIA_ERR_LOG("GetMeteringPoint Failed!"); + return -1; + } + return autoExposure->GetMeteringPoint(exposurePoint); + } + + int32_t FfiOHOSAutoExposureSetMeteringPoint(int64_t id, Point exposurePoint){ + auto autoExposure = FFIData::GetData(id); + if(autoExposure == nullptr){ //is init? + MEDIA_ERR_LOG("SetMeteringPoint Failed!"); + return -1; + } + return autoExposure->SetMeteringPoint(exposurePoint); + } + + int32_t FfiOHOSAutoExposureSetExposureBias(int64_t id, double exposureValue){ + auto autoExposure = FFIData::GetData(id); + if(autoExposure == nullptr){ //is init? + MEDIA_ERR_LOG("SetExposureBias Failed!"); + return -1; + } + return autoExposure->SetExposureBias(exposureValue); + } + + int32_t FfiOHOSAutoExposureGetExposureValue(int64_t id, double& exposureValue){ + auto autoExposure = FFIData::GetData(id); + if(autoExposure == nullptr){ //is init? + MEDIA_ERR_LOG("GetExposureValue Failed!"); + return -1; + } + return autoExposure->GetExposureValue(exposureValue); + } + +} + +} +} \ No newline at end of file diff --git a/frameworks/cj/src/autoexposurequery.cpp b/frameworks/cj/src/autoexposurequery.cpp new file mode 100644 index 00000000..3e4aadf4 --- /dev/null +++ b/frameworks/cj/src/autoexposurequery.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "autoexposurequery.h" + +namespace OHOS { +namespace CameraStandard { + +// void CjAutoExposureQuery::Init(){ +// MEDIA_DEBUG_LOG("Init is called"); +// } + +// CjCjAutoExposureQuery CjCjAutoExposureQuery::CreateCjCjAutoExposureQuery(){ +// MEDIA_DEBUG_LOG("CreateCjCjAutoExposureQuery is called"); +// CAMERA_SYNC_TRACE; +// // CameraManager::GetInstance()->CreateCaptureSession(&cameraSession_); +// } + +using namespace OHOS::FFI; + +CjAutoExposureQuery::~CjAutoExposureQuery(){ + MEDIA_INFO_LOG("~CjAutoExposureQuery() is called."); +} + +int32_t CjAutoExposureQuery::IsExposureModeSupported(ExposureMode exposureMode, bool& isSupported){ + MEDIA_INFO_LOG("IsExposureModeSupported is called!"); + + if(cameraSession_ == nullptr){ + MEDIA_ERR_LOG("IsExposureModeSupported call Failed!"); + MEDIA_ERR_LOG("camerasession is nullptr."); + MEDIA_ERR_LOG("RetCode: -1"); + return -1; + } + + int32_t retCode = cameraSession_-> + IsExposureModeSupported(exposureMode, isSupported); + + if (retCode != 0){ + MEDIA_ERR_LOG("IsExposureModeSupported call Failed!"); + MEDIA_ERR_LOG("RetCode: %{public}d", retCode); + } + return retCode; +} + +int32_t CjAutoExposureQuery::GetExposureBiasRange(CArrDouble& exposureBiasList){ + MEDIA_INFO_LOG("GetExposureBiasRange is called!"); + + if(cameraSession_ == nullptr){ + MEDIA_ERR_LOG("GetExposureBiasRange call Failed!"); + MEDIA_ERR_LOG("camerasession is nullptr."); + MEDIA_ERR_LOG("RetCode: -1"); + return -1; + } + + std::vector vecExposureBiasList; + int32_t retCode = cameraSession_->GetExposureBiasRange(vecExposureBiasList); + + if (retCode != 0){ + MEDIA_ERR_LOG("GetExposureBiasRange call Failed!"); + MEDIA_ERR_LOG("RetCode: %{public}d", retCode); + return retCode; + } + + MEDIA_INFO_LOG("CjAutoExposureQuery::GetExposureBiasRange len = %{public}zu", + vecExposureBiasList.size()); + + if(!vecExposureBiasList.empty()){ + double* retVecExposureBiasList = (double*)malloc(sizeof(double)*vecExposureBiasList.size()); + for (size_t i = 0; i < vecExposureBiasList.size(); ++i){ + retVecExposureBiasList[i] = FloatToDouble(vecExposureBiasList[i]); + } + exposureBiasList.head = retVecExposureBiasList; + exposureBiasList.size = vecExposureBiasList.size(); + } else { + MEDIA_ERR_LOG("vecExposureBiasList is empty!"); + } + + return retCode; +} + + +} // namespace CameraStandard +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/cj/src/camera_manager_ffi.cpp b/frameworks/cj/src/camera_manager_ffi.cpp new file mode 100644 index 00000000..410f9fbc --- /dev/null +++ b/frameworks/cj/src/camera_manager_ffi.cpp @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "camera_manager_ffi.h" + +namespace OHOS { +namespace CameraStandard { + +} // namespace CameraStandard +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/cj/src/zoom_utils.cpp b/frameworks/cj/src/utils.cpp similarity index 87% rename from frameworks/cj/src/zoom_utils.cpp rename to frameworks/cj/src/utils.cpp index 06284de7..5975b188 100644 --- a/frameworks/cj/src/zoom_utils.cpp +++ b/frameworks/cj/src/utils.cpp @@ -1,4 +1,4 @@ -#include "zoom_utils.h" +#include "utils.h" double FloatToDouble(float val){ const double precision = 1000000.0; -- Gitee From 276faac3fc5f57386e64af9d33d7459d9cee0fff Mon Sep 17 00:00:00 2001 From: ForeverMeteor <2675561402@qq.com> Date: Tue, 16 Jul 2024 17:08:08 +0800 Subject: [PATCH 3/7] feature 20240716 camera.ColormanagementQuery camera.Colormanagement add 3 new apis Change-Id: Ie664a429fd4ded425661f6f7f6ebe8b31b00266a --- frameworks/cj/BUILD.gn | 5 +- frameworks/cj/include/colormanagement.h | 42 +++++++++++ frameworks/cj/include/colormanagement_ffi.h | 33 ++++++++ frameworks/cj/include/colormanagementquery.h | 42 +++++++++++ frameworks/cj/src/colormanagement.cpp | 79 ++++++++++++++++++++ frameworks/cj/src/colormanagement_ffi.cpp | 78 +++++++++++++++++++ frameworks/cj/src/colormanagementquery.cpp | 69 +++++++++++++++++ 7 files changed, 347 insertions(+), 1 deletion(-) create mode 100644 frameworks/cj/include/colormanagement.h create mode 100644 frameworks/cj/include/colormanagement_ffi.h create mode 100644 frameworks/cj/include/colormanagementquery.h create mode 100644 frameworks/cj/src/colormanagement.cpp create mode 100644 frameworks/cj/src/colormanagement_ffi.cpp create mode 100644 frameworks/cj/src/colormanagementquery.cpp diff --git a/frameworks/cj/BUILD.gn b/frameworks/cj/BUILD.gn index fce3baf0..f5dae1f0 100644 --- a/frameworks/cj/BUILD.gn +++ b/frameworks/cj/BUILD.gn @@ -71,7 +71,10 @@ ohos_shared_library("cj_camera_ffi") { "src/zoomquery.cpp", "src/autoexposure_ffi.cpp", "src/autoexposure.cpp", - "src/autoexposurequery.cpp" + "src/autoexposurequery.cpp", + "src/colormanagement_ffi.cpp", + "src/colormanagement.cpp", + "src/colormanagementquery.cpp" ] } else { defines += [ "PREVIEWER" ] diff --git a/frameworks/cj/include/colormanagement.h b/frameworks/cj/include/colormanagement.h new file mode 100644 index 00000000..7465e2d8 --- /dev/null +++ b/frameworks/cj/include/colormanagement.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef COLORMANAGEMENT_FFI_H +#define COLORMANAGEMENT_FFI_H + +#include "colormanagementquery.h" + +namespace OHOS { +namespace CameraStandard { + +class __attribute__((visibility("default"))) CjColorManagement : public OHOS::CameraStandard::CjColorManagementQuery { + DECL_TYPE(ColorManagement, OHOS::FFI::FFIData) +public: + // static void Init(); + // static CjColorManagement CreateCjColorManagement(); + explicit CjColorManagement() = default; + ~CjColorManagement() override; + + int32_t SetColorSpace(ColorSpace colorSpace); + int32_t GetActiveColorSpace(ColorSpace& colorSpace); + +private: + sptr cameraSession_; +}; + +} +} + +#endif \ No newline at end of file diff --git a/frameworks/cj/include/colormanagement_ffi.h b/frameworks/cj/include/colormanagement_ffi.h new file mode 100644 index 00000000..43f737fa --- /dev/null +++ b/frameworks/cj/include/colormanagement_ffi.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ffi_remote_data.h" +#include "cj_common_ffi.h" +#include "camera_log.h" +#include "utils.h" + +namespace OHOS { +namespace CameraStandard { + +extern "C"{ + FFI_EXPORT int64_t FfiOHOSColorManagementQueryConstructor(); + FFI_EXPORT int32_t FfiOHOSColorManagementQueryGetSupportedColorSpaces(int64_t id, CArrI32& supportedColorSpaces); + FFI_EXPORT int64_t FfiOHOSColorManagementConstructor(); + FFI_EXPORT int32_t FfiOHOSColorManagementSetColorSpace(int64_t id, int32_t colorSpaceInt); + FFI_EXPORT int32_t FfiOHOSColorManagementGetActiveColorSpace(int64_t id, int32_t& colorSpaceInt); +} + +} +} \ No newline at end of file diff --git a/frameworks/cj/include/colormanagementquery.h b/frameworks/cj/include/colormanagementquery.h new file mode 100644 index 00000000..829626b7 --- /dev/null +++ b/frameworks/cj/include/colormanagementquery.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef COLORMANAGEMENTQUERY_FFI_H +#define COLORMANAGEMENTQUERY_FFI_H + +#include "colormanagement_ffi.h" +#include "icapture_session.h" + +namespace OHOS { +namespace CameraStandard { + +class __attribute__((visibility("default"))) CjColorManagementQuery : public OHOS::FFI::FFIData { + DECL_TYPE(ColorManagementQuery, OHOS::FFI::FFIData) +public: + // static void Init(); + // static CjColorManagementQuery CreateCjColorManagementQuery(); + explicit CjColorManagementQuery() = default; + ~CjColorManagementQuery() override; + + int32_t GetSupportedColorSpaces(CArrI32& supportedColorSpaces); + +private: + sptr cameraSession_; +}; + +} +} + +#endif \ No newline at end of file diff --git a/frameworks/cj/src/colormanagement.cpp b/frameworks/cj/src/colormanagement.cpp new file mode 100644 index 00000000..35cff919 --- /dev/null +++ b/frameworks/cj/src/colormanagement.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "colormanagement.h" + +namespace OHOS { +namespace CameraStandard { + +// void CjColorManagement::Init(){ +// MEDIA_DEBUG_LOG("Init is called"); +// } + +// CjColorManagement CjColorManagement::CreateCjColorManagement(){ +// MEDIA_DEBUG_LOG("CreateCjColorManagement is called"); +// CAMERA_SYNC_TRACE; +// // CameraManager::GetInstance()->CreateCaptureSession(&cameraSession_); +// } + +using namespace OHOS::FFI; + +CjColorManagement::~CjColorManagement(){ + MEDIA_INFO_LOG("~CjColorManagement() is called."); +} + +int32_t CjColorManagement::SetColorSpace(ColorSpace colorSpace){ + MEDIA_INFO_LOG("SetColorSpace is called!"); + + if(cameraSession_ == nullptr){ + MEDIA_ERR_LOG("SetColorSpace call Failed!"); + MEDIA_ERR_LOG("camerasession is nullptr."); + MEDIA_ERR_LOG("RetCode: -1"); + return -1; + } + + cameraSession_->LockForControl(); + int32_t retCode = cameraSession_->SetColorSpace(colorSpace); + cameraSession_->UnlockForControl(); + + if (retCode != 0){ + MEDIA_ERR_LOG("SetColorSpace call Failed!"); + MEDIA_ERR_LOG("RetCode: %{public}d", retCode); + } + return retCode; +} + +int32_t CjColorManagement::GetActiveColorSpace(ColorSpace& colorSpace){ + MEDIA_INFO_LOG("GetActiveColorSpace is called!"); + + if(cameraSession_ == nullptr){ + MEDIA_ERR_LOG("GetActiveColorSpace call Failed!"); + MEDIA_ERR_LOG("camerasession is nullptr."); + MEDIA_ERR_LOG("RetCode: -1"); + return -1; + } + + int32_t retCode = cameraSession_->GetActiveColorSpace(colorSpace); + + if (retCode != 0){ + MEDIA_ERR_LOG("GetActiveColorSpace call Failed!"); + MEDIA_ERR_LOG("RetCode: %{public}d", retCode); + } + return retCode; +} + + +} // namespace CameraStandard +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/cj/src/colormanagement_ffi.cpp b/frameworks/cj/src/colormanagement_ffi.cpp new file mode 100644 index 00000000..5e8e40ab --- /dev/null +++ b/frameworks/cj/src/colormanagement_ffi.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "colormanagement.h" + +using namespace OHOS::FFI; + +namespace OHOS { +namespace CameraStandard { + +extern "C"{ + //ColorManagementQuery + int64_t FfiOHOSColorManagementQueryConstructor(){ + auto autoColorManagementQuery = FFIData::Create(); + if (autoColorManagementQuery == nullptr){ + MEDIA_ERR_LOG("New ColorManagementQuery Failed!"); + return -1; + } + return autoColorManagementQuery->GetID(); + } + + int32_t FfiOHOSColorManagementQueryGetSupportedColorSpaces(int64_t id, CArrI32& supportedColorSpaces){ + auto autoColorManagementQuery = FFIData::GetData(id); + if(autoColorManagementQuery == nullptr){ //is init? + MEDIA_ERR_LOG("autoColorManagementQuery Failed!"); + return -1; + } + return autoColorManagementQuery->GetSupportedColorSpaces(supportedColorSpaces); + } + + //ColorManagement + int64_t FfiOHOSColorManagementConstructor(){ + auto autoColorManagement = FFIData::Create(); + if (autoColorManagement == nullptr){ + MEDIA_ERR_LOG("New ColorManagement Failed!"); + return -1; + } + return autoColorManagement->GetID(); + } + + int32_t FfiOHOSColorManagementSetColorSpace(int64_t id, int32_t colorSpaceInt){ + auto autoColorManagement = FFIData::GetData(id); + if(autoColorManagement == nullptr){ //is init? + MEDIA_ERR_LOG("autoColorManagement Failed!"); + return -1; + } + return autoColorManagement->SetColorSpace(static_cast(colorSpaceInt)); + } + + int32_t FfiOHOSColorManagementGetActiveColorSpace(int64_t id, int32_t& colorSpaceInt){ + auto autoColorManagement = FFIData::GetData(id); + if(autoColorManagement == nullptr){ //is init? + MEDIA_ERR_LOG("autoColorManagement Failed!"); + return -1; + } + ColorSpace colorSpace; + int32_t retCode = autoColorManagement->GetActiveColorSpace(colorSpace); + colorSpaceInt = static_cast(colorSpace); + return retCode; + } + + +} + +} +} \ No newline at end of file diff --git a/frameworks/cj/src/colormanagementquery.cpp b/frameworks/cj/src/colormanagementquery.cpp new file mode 100644 index 00000000..d50bfb3f --- /dev/null +++ b/frameworks/cj/src/colormanagementquery.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "colormanagementquery.h" + +namespace OHOS { +namespace CameraStandard { + +// void CjColorManagementQuery::Init(){ +// MEDIA_DEBUG_LOG("Init is called"); +// } + +// CjColorManagementQuery CjColorManagementQuery::CreateCjColorManagementQuery(){ +// MEDIA_DEBUG_LOG("CreateCjColorManagement is called"); +// CAMERA_SYNC_TRACE; +// // CameraManager::GetInstance()->CreateCaptureSession(&cameraSession_); +// } + +using namespace OHOS::FFI; + +CjColorManagementQuery::~CjColorManagementQuery(){ + MEDIA_INFO_LOG("~CjColorManagementQuery() is called."); +} + +int32_t CjColorManagementQuery::GetSupportedColorSpaces(CArrI32& supportedColorSpaces){ + MEDIA_INFO_LOG("GetSupportedColorSpaces is called!"); + + if(cameraSession_ == nullptr){ + MEDIA_ERR_LOG("GetSupportedColorSpaces call Failed!"); + MEDIA_ERR_LOG("camerasession is nullptr."); + MEDIA_ERR_LOG("RetCode: -1"); + return -1; + } + + // 此处native代码中没有返回码 + std::vector colorSpaces = cameraSession_->GetSupportedColorSpaces(); + + if(!colorSpaces.empty()){ + int32_t* retColorSpaces = (int32_t*)malloc(sizeof(int32_t)*colorSpaces.size()); + for (size_t i = 0; i < colorSpaces.size(); ++i){ + retColorSpaces[i] = static_cast(colorSpaces[i]); + } + supportedColorSpaces.head = retColorSpaces; + supportedColorSpaces.size = colorSpaces.size(); + } else { + MEDIA_ERR_LOG("vecExposureBiasList is empty!"); + return -1; // 人为定义 + } + + // native代码中没有返回码 + return 0; +} + + + +} // namespace CameraStandard +} // namespace OHOS \ No newline at end of file -- Gitee From ce297afff706c00f53ccacaa429c57c792b2d1b7 Mon Sep 17 00:00:00 2001 From: ForeverMeteor <2675561402@qq.com> Date: Wed, 24 Jul 2024 16:38:23 +0800 Subject: [PATCH 4/7] =?UTF-8?q?feature=2020240724=20=E5=A2=9E=E5=8A=A0came?= =?UTF-8?q?r=5Foutput=E3=80=81listener=5Fbase=E3=80=81metadata=5Foutput?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=96=87=E4=BB=B6=20**=E6=B3=A8=E6=84=8F?= =?UTF-8?q?=EF=BC=9A=E8=BF=99=E4=BA=9B=E6=96=87=E4=BB=B6=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E4=B8=8E=E5=85=B6=E4=BB=96=E5=90=8C=E4=BA=8B=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E7=9A=84=E5=86=B2=E7=AA=81=EF=BC=8C=E9=9C=80=E8=A6=81=E6=95=B4?= =?UTF-8?q?=E5=90=88=20Change-Id:=20I0c0b10e06ad4de0d38d92404d1137e5a11fae?= =?UTF-8?q?3a5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/cj/BUILD.gn | 4 +- frameworks/cj/include/camera_output_impl.h | 45 ++++++++ frameworks/cj/include/listener_base.h | 53 ++++++++++ frameworks/cj/include/metadata_output_impl.h | 92 ++++++++++++++++ frameworks/cj/src/camera_output_impl.cpp | 26 +++++ frameworks/cj/src/listener_base.tpp | 70 +++++++++++++ frameworks/cj/src/metadata_output_impl.cpp | 104 +++++++++++++++++++ 7 files changed, 393 insertions(+), 1 deletion(-) create mode 100644 frameworks/cj/include/camera_output_impl.h create mode 100644 frameworks/cj/include/listener_base.h create mode 100644 frameworks/cj/include/metadata_output_impl.h create mode 100644 frameworks/cj/src/camera_output_impl.cpp create mode 100644 frameworks/cj/src/listener_base.tpp create mode 100644 frameworks/cj/src/metadata_output_impl.cpp diff --git a/frameworks/cj/BUILD.gn b/frameworks/cj/BUILD.gn index f5dae1f0..617632e8 100644 --- a/frameworks/cj/BUILD.gn +++ b/frameworks/cj/BUILD.gn @@ -74,7 +74,9 @@ ohos_shared_library("cj_camera_ffi") { "src/autoexposurequery.cpp", "src/colormanagement_ffi.cpp", "src/colormanagement.cpp", - "src/colormanagementquery.cpp" + "src/colormanagementquery.cpp", + "src/camera_output_impl.cpp", + "src/metadata_output_impl.cpp", ] } else { defines += [ "PREVIEWER" ] diff --git a/frameworks/cj/include/camera_output_impl.h b/frameworks/cj/include/camera_output_impl.h new file mode 100644 index 00000000..c97c9fd7 --- /dev/null +++ b/frameworks/cj/include/camera_output_impl.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CAMERA_OUTPUT_IMPL_H +#define CAMERA_OUTPUT_IMPL_H + +#include "ffi_remote_data.h" +#include "capture_output.h" + +namespace OHOS { +namespace CameraStandard { + + class CameraOutput : public OHOS::FFI::FFIData { + public: + explicit CameraOutput(); + virtual ~CameraOutput(); + void Release(); + OHOS::FFI::RuntimeType *GetRuntimeType() override { return GetClassType(); } + + private: + sptr cameraoutput_ = nullptr; + friend class OHOS::FFI::RuntimeType; + friend class OHOS::FFI::TypeBase; + static OHOS::FFI::RuntimeType* GetClassType() + { + static OHOS::FFI::RuntimeType runtimeType = + OHOS::FFI::RuntimeType::Create("CameraOutput"); + return &runtimeType; + } + }; + } // namespace CameraStandard +} // namespace OHOS +#endif /* CAMERA_MANAGER_FFI_H */ \ No newline at end of file diff --git a/frameworks/cj/include/listener_base.h b/frameworks/cj/include/listener_base.h new file mode 100644 index 00000000..f06deccb --- /dev/null +++ b/frameworks/cj/include/listener_base.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LISTENER_BASE_H +#define LISTENER_BASE_H + +#include +#include +#include + +namespace OHOS { +namespace CameraStandard { + +template +struct CallbackRef { + std::function ref; + CallbackRef(const std::function ref_) : ref{ ref_ } {} +}; + +template +class ListenerBase { +public: + void SaveCallbackRef(const std::shared_ptr> callback); + + void RemoveCallbackRef(const std::shared_ptr> callback); + + void RemoveAllCallbackRef(); + + void ExecuteCallback(T const... callbackPara) const; + +private: + mutable std::mutex listMutex_ {}; + std::vector>> callbackList; +}; + +} +} + +#include "../src/listener_base.tpp" + +#endif \ No newline at end of file diff --git a/frameworks/cj/include/metadata_output_impl.h b/frameworks/cj/include/metadata_output_impl.h new file mode 100644 index 00000000..58f59cdf --- /dev/null +++ b/frameworks/cj/include/metadata_output_impl.h @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef METADATA_OUTPUT_IMPL_H +#define METADATA_OUTPUT_IMPL_H + +#include "cj_lambda.h" +#include "camera_manager.h" +#include "camera_output_impl.h" +#include "metadata_output.h" +#include "./listener_base.h" + +namespace OHOS { +namespace CameraStandard { +// static const char CAMERA_METADATA_OUTPUT_CJ_CLASS_NAME[] = "MetadataOutput"; + +class CjMetadataOutputCallback: public MetadataObjectCallback, + public ListenerBase>>, public std::enable_shared_from_this { +public: + CjMetadataOutputCallback(); + virtual ~CjMetadataOutputCallback() = default; + void OnMetadataObjectsAvailable(std::vector> metaObjects) const override; +// private: +// void OnMetadataObjectsAvailableCallback(const std::vector> metadataObjList) const; +}; + +class CjMetadataStateCallback: public MetadataStateCallback, + public ListenerBase, public std::enable_shared_from_this { +public: + CjMetadataStateCallback(); + virtual ~CjMetadataStateCallback() = default; + void OnError(const int32_t errorType) const override; +// private: +// void OnErrorCallback(const int32_t errorType) const; +// void OnErrorCallbackAsync(const int32_t errorType) const; +}; + +struct CjMetadataOutputCallbackInfo { + const std::vector> info_; + std::weak_ptr listener_; + CjMetadataOutputCallbackInfo(std::vector> metadataObjList, + std::shared_ptr listener) + : info_(metadataObjList), listener_(listener) {} +}; + +struct CjMetadataStateCallbackInfo { + int32_t errorType_; + std::weak_ptr listener_; + CjMetadataStateCallbackInfo(int32_t errorType, + std::shared_ptr listener) + : errorType_(errorType), listener_(listener) {} +}; + +class CjMetadataOutput : public CameraOutput { +public: + CjMetadataOutput(); + ~CjMetadataOutput() override; + + static int32_t CreateMetadataOutput(); + void SetMetadataObjectTypes(std::vector metadataObjectTypes); + + //@author ChentaoZhang + int32_t Start(); + int32_t Stop(); + void On(std::string metadataObjectsAvailable, void(*callback)(std::vector>)); + void On(std::string error, void(*callback)(int32_t)); + void Off(std::string metadataObjectsAvailable, void(*callback)(std::vector>)); + void Off(std::string error, void(*callback)(int32_t)); + +private: + sptr metadataOutput_; + static thread_local sptr sMetadataOutput_; + + //@author ChentaoZhang + std::shared_ptr metadataOutputCallback_; + std::shared_ptr metadataStateCallback_; +}; +} // namespace CameraStandard +} // namespace OHOS +#endif /* CAMERA_MANAGER_FFI_H */ \ No newline at end of file diff --git a/frameworks/cj/src/camera_output_impl.cpp b/frameworks/cj/src/camera_output_impl.cpp new file mode 100644 index 00000000..76e706ee --- /dev/null +++ b/frameworks/cj/src/camera_output_impl.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "camera_output_impl.h" + +namespace OHOS { +namespace CameraStandard { + CameraOutput::CameraOutput() {} + CameraOutput::~CameraOutput(){} + void CameraOutput::Release(){ + cameraoutput_->Release(); + } +} // namespace CameraStandard +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/cj/src/listener_base.tpp b/frameworks/cj/src/listener_base.tpp new file mode 100644 index 00000000..8bd75a7e --- /dev/null +++ b/frameworks/cj/src/listener_base.tpp @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "listener_base.h" + +namespace OHOS { +namespace CameraStandard { + +template +void ListenerBase::SaveCallbackRef(const std::shared_ptr> callback) +{ + std::lock_guard lock(listMutex_); + callbackList.push_back(callback); +} + +template +void ListenerBase::RemoveCallbackRef(const std::shared_ptr> callback) +{ + std::lock_guard lock(listMutex_); + auto it = callbackList.begin(); + while (it != callbackList.end()) { + if (callback == *it) { + callbackList.erase(it); + break; + } + } +} + +template +void ListenerBase::RemoveAllCallbackRef() +{ + std::lock_guard lock(listMutex_); + for (auto &callback : callbackList) { + RemoveCallbackRef(callback); + } + callbackList.clear(); +} + +template +void ListenerBase::ExecuteCallback(T const... callbackPara) const +{ + std::lock_guard lock(listMutex_); + if (callbackList.size() == 0) { + //LOG("no OnError func registered") + return; + } + int len = static_cast(callbackList.size()); + for (int i = 0; i < len; i++) { + callbackList[i]->ref(callbackPara...); + } +} + +} +} \ No newline at end of file diff --git a/frameworks/cj/src/metadata_output_impl.cpp b/frameworks/cj/src/metadata_output_impl.cpp new file mode 100644 index 00000000..dce96fb2 --- /dev/null +++ b/frameworks/cj/src/metadata_output_impl.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "metadata_output_impl.h" + +namespace OHOS { +namespace CameraStandard { + +// thread_local sptr MetadataOutputNapi::sMetadataOutput_ = nullptr; + +//@author ChentaoZhang + +CjMetadataOutputCallback::CjMetadataOutputCallback() {} + +CjMetadataStateCallback::CjMetadataStateCallback() {} + +void CjMetadataOutputCallback::OnMetadataObjectsAvailable(std::vector> metaObjects)const{ + // 可能有问题 + ExecuteCallback(metaObjects); +} + +void CjMetadataStateCallback::OnError(const int32_t errorType)const{ + // 可能有问题 + ExecuteCallback(errorType); +} +//end author + +CjMetadataOutput::CjMetadataOutput() {} +// CjMetadataOutput::CjMetadataOutput() { +// metadataOutput_ = sMetadataOutput_; +// sMetadataOutput_ = nullptr; +// } + + +CjMetadataOutput::~CjMetadataOutput() {} + +// int32_t CjMetadataOutput::CreateMetadataOutput() // return errCode +// { +// int retCode = CameraManager::GetInstance()->CreateMetadataOutput(sMetadataOutput_); +// return retCode; +// } + +void CjMetadataOutput::SetMetadataObjectTypes(std::vector metadataObjectTypes) +{ + metadataOutput_->SetCapturingMetadataObjectTypes(metadataObjectTypes); +} + +//@author ChentaoZhang +int32_t CjMetadataOutput::Start(){ + return metadataOutput_->Start(); +} + +int32_t CjMetadataOutput::Stop(){ + return metadataOutput_->Stop(); +} + +void CjMetadataOutput::On(std::string metadataObjectsAvailable, void(*callback)(std::vector>)){ + if(metadataOutputCallback_ == nullptr){ + metadataOutputCallback_ = std::make_shared(); + metadataOutput_->SetCallback(metadataOutputCallback_); + } + metadataOutputCallback_->SaveCallbackRef( + std::make_shared>>>(CJLambda::Create(callback)) + ); +} + +void CjMetadataOutput::On(std::string error, void (*callback)(int32_t)){ + if (metadataStateCallback_ == nullptr) { + metadataStateCallback_ = std::make_shared(); + metadataOutput_->SetCallback(metadataStateCallback_); + } + metadataStateCallback_->SaveCallbackRef(std::make_shared>(CJLambda::Create(callback))); +} + +void CjMetadataOutput::Off(std::string metadataObjectsAvailable, void(*callback)(std::vector>)){ + if (metadataOutputCallback_ == nullptr) { + return; + } + metadataOutputCallback_->RemoveCallbackRef( + std::make_shared>>>(CJLambda::Create(callback)) + ); +} + +void CjMetadataOutput::Off(std::string error, void(*callback)(int32_t)){ + if (metadataStateCallback_ == nullptr) { + return; + } + metadataStateCallback_->RemoveCallbackRef(std::make_shared>(CJLambda::Create(callback))); +} + +} // namespace CameraStandard +} // namespace OHOS \ No newline at end of file -- Gitee From bc2309ad8420b03196eed92026d921489243d4fd Mon Sep 17 00:00:00 2001 From: ForeverMeteor <2675561402@qq.com> Date: Thu, 25 Jul 2024 10:06:02 +0800 Subject: [PATCH 5/7] =?UTF-8?q?feature=2020240725=20=E6=96=B0=E5=A2=9Emeta?= =?UTF-8?q?dataoutput=E7=9A=84ffi=E5=B1=82=20Change-Id:=20I2498b6777d3db03?= =?UTF-8?q?fd69bf16a076ddbe6e81b6875?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/cj/include/metadata_output_ffi.h | 35 ++++++++ frameworks/cj/include/metadata_output_impl.h | 9 +- frameworks/cj/src/metadata_output_ffi.cpp | 89 ++++++++++++++++++++ frameworks/cj/src/metadata_output_impl.cpp | 8 +- 4 files changed, 133 insertions(+), 8 deletions(-) create mode 100644 frameworks/cj/include/metadata_output_ffi.h create mode 100644 frameworks/cj/src/metadata_output_ffi.cpp diff --git a/frameworks/cj/include/metadata_output_ffi.h b/frameworks/cj/include/metadata_output_ffi.h new file mode 100644 index 00000000..8657fe0c --- /dev/null +++ b/frameworks/cj/include/metadata_output_ffi.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ffi_remote_data.h" +#include "cj_common_ffi.h" +#include "camera_log.h" +#include "utils.h" + +namespace OHOS { +namespace CameraStandard { + +extern "C"{ + FFI_EXPORT int64_t FfiOHOSMetadataOutputConstructor(); + FFI_EXPORT int32_t FfiOHOSMetadataOutputStart(int64_t id); + FFI_EXPORT int32_t FfiOHOSMetadataOutputStop(int64_t id); + FFI_EXPORT int32_t FfiOHOSMetadataOutputOnMetadataObjectsAvailable(int64_t id, void(*callback)(std::vector>)); + FFI_EXPORT int32_t FfiOHOSMetadataOutputOnError(int64_t id, void (*callback)(int32_t)); + FFI_EXPORT int32_t FfiOHOSMetadataOutputOnMetadataObjectsAvailable(int64_t id, void(*callback)(std::vector>)); + FFI_EXPORT int32_t FfiOHOSMetadataOutputOnError(int64_t id, void(*callback)(int32_t)); +} + +} +} \ No newline at end of file diff --git a/frameworks/cj/include/metadata_output_impl.h b/frameworks/cj/include/metadata_output_impl.h index 58f59cdf..5d17af14 100644 --- a/frameworks/cj/include/metadata_output_impl.h +++ b/frameworks/cj/include/metadata_output_impl.h @@ -21,6 +21,7 @@ #include "camera_output_impl.h" #include "metadata_output.h" #include "./listener_base.h" +#include "metadata_output_ffi.h" namespace OHOS { namespace CameraStandard { @@ -74,10 +75,10 @@ public: //@author ChentaoZhang int32_t Start(); int32_t Stop(); - void On(std::string metadataObjectsAvailable, void(*callback)(std::vector>)); - void On(std::string error, void(*callback)(int32_t)); - void Off(std::string metadataObjectsAvailable, void(*callback)(std::vector>)); - void Off(std::string error, void(*callback)(int32_t)); + void On(void(*callback)(std::vector>)); + void On(void(*callback)(int32_t)); + void Off(void(*callback)(std::vector>)); + void Off(void(*callback)(int32_t)); private: sptr metadataOutput_; diff --git a/frameworks/cj/src/metadata_output_ffi.cpp b/frameworks/cj/src/metadata_output_ffi.cpp new file mode 100644 index 00000000..9e079688 --- /dev/null +++ b/frameworks/cj/src/metadata_output_ffi.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "metadata_output_impl.h" + +namespace OHOS { +namespace CameraStandard { + +extern "C"{ + // MetadataOutput + int64_t FfiOHOSMetadataOutputConstructor(){ + auto metadataOutput = FFIData::Create(); + if (metadataOutput == nullptr){ + MEDIA_ERR_LOG("New MetadataOutput Failed!"); + return -1; + } + return metadataOutput->GetID(); + } + + int32_t FfiOHOSMetadataOutputStart(int64_t id){ + auto metadataOutput = FFIData::GetData(id); + if(metadataOutput == nullptr){ //is init? + MEDIA_ERR_LOG("Start Failed!"); + return -1; + } + return metadataOutput->Start(); + } + + int32_t FfiOHOSMetadataOutputStop(int64_t id){ + auto metadataOutput = FFIData::GetData(id); + if(metadataOutput == nullptr){ //is init? + MEDIA_ERR_LOG("Stop Failed!"); + return -1; + } + return metadataOutput->Stop(); + } + + int32_t FfiOHOSMetadataOutputOnMetadataObjectsAvailable(int64_t id, void(*callback)(std::vector>)){ + auto metadataOutput = FFIData::GetData(id); + if(metadataOutput == nullptr){ //is init? + MEDIA_ERR_LOG("OnMetadataObjectsAvailable Failed!"); + return -1; + } + return metadataOutput->On(callback); + } + + int32_t FfiOHOSMetadataOutputOnError(int64_t id, void (*callback)(int32_t)){ + auto metadataOutput = FFIData::GetData(id); + if(metadataOutput == nullptr){ //is init? + MEDIA_ERR_LOG("OnError Failed!"); + return -1; + } + return metadataOutput->On(callback); + } + + int32_t FfiOHOSMetadataOutputOnMetadataObjectsAvailable(int64_t id, void(*callback)(std::vector>)){ + auto metadataOutput = FFIData::GetData(id); + if(metadataOutput == nullptr){ //is init? + MEDIA_ERR_LOG("OffMetadataObjectsAvailable Failed!"); + return -1; + } + return metadataOutput->Off(callback); + } + + int32_t FfiOHOSMetadataOutputOnError(int64_t id, void(*callback)(int32_t)){ + auto metadataOutput = FFIData::GetData(id); + if(metadataOutput == nullptr){ //is init? + MEDIA_ERR_LOG("OffError Failed!"); + return -1; + } + return metadataOutput->Off(callback); + } + +} + +} +} diff --git a/frameworks/cj/src/metadata_output_impl.cpp b/frameworks/cj/src/metadata_output_impl.cpp index dce96fb2..47396b5a 100644 --- a/frameworks/cj/src/metadata_output_impl.cpp +++ b/frameworks/cj/src/metadata_output_impl.cpp @@ -66,7 +66,7 @@ int32_t CjMetadataOutput::Stop(){ return metadataOutput_->Stop(); } -void CjMetadataOutput::On(std::string metadataObjectsAvailable, void(*callback)(std::vector>)){ +void CjMetadataOutput::On(void(*callback)(std::vector>)){ if(metadataOutputCallback_ == nullptr){ metadataOutputCallback_ = std::make_shared(); metadataOutput_->SetCallback(metadataOutputCallback_); @@ -76,7 +76,7 @@ void CjMetadataOutput::On(std::string metadataObjectsAvailable, void(*callback)( ); } -void CjMetadataOutput::On(std::string error, void (*callback)(int32_t)){ +void CjMetadataOutput::On(void (*callback)(int32_t)){ if (metadataStateCallback_ == nullptr) { metadataStateCallback_ = std::make_shared(); metadataOutput_->SetCallback(metadataStateCallback_); @@ -84,7 +84,7 @@ void CjMetadataOutput::On(std::string error, void (*callback)(int32_t)){ metadataStateCallback_->SaveCallbackRef(std::make_shared>(CJLambda::Create(callback))); } -void CjMetadataOutput::Off(std::string metadataObjectsAvailable, void(*callback)(std::vector>)){ +void CjMetadataOutput::Off(void(*callback)(std::vector>)){ if (metadataOutputCallback_ == nullptr) { return; } @@ -93,7 +93,7 @@ void CjMetadataOutput::Off(std::string metadataObjectsAvailable, void(*callback) ); } -void CjMetadataOutput::Off(std::string error, void(*callback)(int32_t)){ +void CjMetadataOutput::Off(void(*callback)(int32_t)){ if (metadataStateCallback_ == nullptr) { return; } -- Gitee From 7866a09acfcfc483b3fdb0f8ad29bef11faf6f1a Mon Sep 17 00:00:00 2001 From: ForeverMeteor <2675561402@qq.com> Date: Thu, 25 Jul 2024 10:51:47 +0800 Subject: [PATCH 6/7] =?UTF-8?q?fix=2020240725=20=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=91=BD=E5=90=8D=EF=BC=8C=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=5Fimpl=E7=BB=93=E5=B0=BE=20Change-Id:=20Ib9b900d970985c795eba4?= =?UTF-8?q?a02923021756b3a261d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/cj/BUILD.gn | 12 ++++++------ .../include/{autoexposure.h => autoexposure_impl.h} | 2 +- ...{autoexposurequery.h => autoexposurequery_impl.h} | 0 .../{colormanagement.h => colormanagement_impl.h} | 2 +- ...managementquery.h => colormanagementquery_impl.h} | 0 frameworks/cj/include/{zoom.h => zoom_impl.h} | 2 +- .../cj/include/{zoomquery.h => zoomquery_impl.h} | 0 frameworks/cj/src/autoexposure_ffi.cpp | 2 +- .../src/{autoexposure.cpp => autoexposure_impl.cpp} | 2 +- ...oexposurequery.cpp => autoexposurequery_impl.cpp} | 2 +- frameworks/cj/src/colormanagement_ffi.cpp | 2 +- ...{colormanagement.cpp => colormanagement_impl.cpp} | 2 +- ...gementquery.cpp => colormanagementquery_impl.cpp} | 2 +- frameworks/cj/src/zoom_ffi.cpp | 2 +- frameworks/cj/src/{zoom.cpp => zoom_impl.cpp} | 2 +- .../cj/src/{zoomquery.cpp => zoomquery_impl.cpp} | 2 +- 16 files changed, 18 insertions(+), 18 deletions(-) rename frameworks/cj/include/{autoexposure.h => autoexposure_impl.h} (97%) rename frameworks/cj/include/{autoexposurequery.h => autoexposurequery_impl.h} (100%) rename frameworks/cj/include/{colormanagement.h => colormanagement_impl.h} (96%) rename frameworks/cj/include/{colormanagementquery.h => colormanagementquery_impl.h} (100%) rename frameworks/cj/include/{zoom.h => zoom_impl.h} (97%) rename frameworks/cj/include/{zoomquery.h => zoomquery_impl.h} (100%) rename frameworks/cj/src/{autoexposure.cpp => autoexposure_impl.cpp} (99%) rename frameworks/cj/src/{autoexposurequery.cpp => autoexposurequery_impl.cpp} (98%) rename frameworks/cj/src/{colormanagement.cpp => colormanagement_impl.cpp} (98%) rename frameworks/cj/src/{colormanagementquery.cpp => colormanagementquery_impl.cpp} (98%) rename frameworks/cj/src/{zoom.cpp => zoom_impl.cpp} (99%) rename frameworks/cj/src/{zoomquery.cpp => zoomquery_impl.cpp} (98%) diff --git a/frameworks/cj/BUILD.gn b/frameworks/cj/BUILD.gn index 617632e8..ef58b488 100644 --- a/frameworks/cj/BUILD.gn +++ b/frameworks/cj/BUILD.gn @@ -67,14 +67,14 @@ ohos_shared_library("cj_camera_ffi") { "src/camera_manager_ffi.cpp", "src/utils.cpp", "src/zoom_ffi.cpp", - "src/zoom.cpp", - "src/zoomquery.cpp", + "src/zoom_impl.cpp", + "src/zoomquery_impl.cpp", "src/autoexposure_ffi.cpp", - "src/autoexposure.cpp", - "src/autoexposurequery.cpp", + "src/autoexposure_impl.cpp", + "src/autoexposurequery_impl.cpp", "src/colormanagement_ffi.cpp", - "src/colormanagement.cpp", - "src/colormanagementquery.cpp", + "src/colormanagement_impl.cpp", + "src/colormanagementquery_impl.cpp", "src/camera_output_impl.cpp", "src/metadata_output_impl.cpp", ] diff --git a/frameworks/cj/include/autoexposure.h b/frameworks/cj/include/autoexposure_impl.h similarity index 97% rename from frameworks/cj/include/autoexposure.h rename to frameworks/cj/include/autoexposure_impl.h index 4d20f447..10590cc5 100644 --- a/frameworks/cj/include/autoexposure.h +++ b/frameworks/cj/include/autoexposure_impl.h @@ -16,7 +16,7 @@ #ifndef AUTOEXPOSURE_FFI_H #define AUTOEXPOSURE_FFI_H -#include "autoexposurequery.h" +#include "autoexposurequery_impl.h" namespace OHOS { namespace CameraStandard { diff --git a/frameworks/cj/include/autoexposurequery.h b/frameworks/cj/include/autoexposurequery_impl.h similarity index 100% rename from frameworks/cj/include/autoexposurequery.h rename to frameworks/cj/include/autoexposurequery_impl.h diff --git a/frameworks/cj/include/colormanagement.h b/frameworks/cj/include/colormanagement_impl.h similarity index 96% rename from frameworks/cj/include/colormanagement.h rename to frameworks/cj/include/colormanagement_impl.h index 7465e2d8..02ed16e6 100644 --- a/frameworks/cj/include/colormanagement.h +++ b/frameworks/cj/include/colormanagement_impl.h @@ -16,7 +16,7 @@ #ifndef COLORMANAGEMENT_FFI_H #define COLORMANAGEMENT_FFI_H -#include "colormanagementquery.h" +#include "colormanagementquery_impl.h" namespace OHOS { namespace CameraStandard { diff --git a/frameworks/cj/include/colormanagementquery.h b/frameworks/cj/include/colormanagementquery_impl.h similarity index 100% rename from frameworks/cj/include/colormanagementquery.h rename to frameworks/cj/include/colormanagementquery_impl.h diff --git a/frameworks/cj/include/zoom.h b/frameworks/cj/include/zoom_impl.h similarity index 97% rename from frameworks/cj/include/zoom.h rename to frameworks/cj/include/zoom_impl.h index 195fb02c..817b7d3a 100644 --- a/frameworks/cj/include/zoom.h +++ b/frameworks/cj/include/zoom_impl.h @@ -16,7 +16,7 @@ #ifndef ZOOM_FFI_H #define ZOOM_FFI_H -#include "zoomquery.h" +#include "zoomquery_impl.h" namespace OHOS { namespace CameraStandard { diff --git a/frameworks/cj/include/zoomquery.h b/frameworks/cj/include/zoomquery_impl.h similarity index 100% rename from frameworks/cj/include/zoomquery.h rename to frameworks/cj/include/zoomquery_impl.h diff --git a/frameworks/cj/src/autoexposure_ffi.cpp b/frameworks/cj/src/autoexposure_ffi.cpp index 003432b9..e108af4c 100644 --- a/frameworks/cj/src/autoexposure_ffi.cpp +++ b/frameworks/cj/src/autoexposure_ffi.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "autoexposure.h" +#include "autoexposure_impl.h" using namespace OHOS::FFI; diff --git a/frameworks/cj/src/autoexposure.cpp b/frameworks/cj/src/autoexposure_impl.cpp similarity index 99% rename from frameworks/cj/src/autoexposure.cpp rename to frameworks/cj/src/autoexposure_impl.cpp index f5b466c6..d35931a2 100644 --- a/frameworks/cj/src/autoexposure.cpp +++ b/frameworks/cj/src/autoexposure_impl.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "autoexposure.h" +#include "autoexposure_impl.h" namespace OHOS { namespace CameraStandard { diff --git a/frameworks/cj/src/autoexposurequery.cpp b/frameworks/cj/src/autoexposurequery_impl.cpp similarity index 98% rename from frameworks/cj/src/autoexposurequery.cpp rename to frameworks/cj/src/autoexposurequery_impl.cpp index 3e4aadf4..6ac9b01d 100644 --- a/frameworks/cj/src/autoexposurequery.cpp +++ b/frameworks/cj/src/autoexposurequery_impl.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "autoexposurequery.h" +#include "autoexposurequery_impl.h" namespace OHOS { namespace CameraStandard { diff --git a/frameworks/cj/src/colormanagement_ffi.cpp b/frameworks/cj/src/colormanagement_ffi.cpp index 5e8e40ab..7bb39bef 100644 --- a/frameworks/cj/src/colormanagement_ffi.cpp +++ b/frameworks/cj/src/colormanagement_ffi.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "colormanagement.h" +#include "colormanagement_impl.h" using namespace OHOS::FFI; diff --git a/frameworks/cj/src/colormanagement.cpp b/frameworks/cj/src/colormanagement_impl.cpp similarity index 98% rename from frameworks/cj/src/colormanagement.cpp rename to frameworks/cj/src/colormanagement_impl.cpp index 35cff919..eaf1ae2a 100644 --- a/frameworks/cj/src/colormanagement.cpp +++ b/frameworks/cj/src/colormanagement_impl.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "colormanagement.h" +#include "colormanagement_impl.h" namespace OHOS { namespace CameraStandard { diff --git a/frameworks/cj/src/colormanagementquery.cpp b/frameworks/cj/src/colormanagementquery_impl.cpp similarity index 98% rename from frameworks/cj/src/colormanagementquery.cpp rename to frameworks/cj/src/colormanagementquery_impl.cpp index d50bfb3f..5874d655 100644 --- a/frameworks/cj/src/colormanagementquery.cpp +++ b/frameworks/cj/src/colormanagementquery_impl.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "colormanagementquery.h" +#include "colormanagementquery_impl.h" namespace OHOS { namespace CameraStandard { diff --git a/frameworks/cj/src/zoom_ffi.cpp b/frameworks/cj/src/zoom_ffi.cpp index 475b8fc5..f1b0b4cc 100644 --- a/frameworks/cj/src/zoom_ffi.cpp +++ b/frameworks/cj/src/zoom_ffi.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "zoom.h" +#include "zoom_impl.h" using namespace OHOS::FFI; diff --git a/frameworks/cj/src/zoom.cpp b/frameworks/cj/src/zoom_impl.cpp similarity index 99% rename from frameworks/cj/src/zoom.cpp rename to frameworks/cj/src/zoom_impl.cpp index adbc658d..67c7183b 100644 --- a/frameworks/cj/src/zoom.cpp +++ b/frameworks/cj/src/zoom_impl.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "zoom.h" +#include "zoom_impl.h" namespace OHOS { namespace CameraStandard { diff --git a/frameworks/cj/src/zoomquery.cpp b/frameworks/cj/src/zoomquery_impl.cpp similarity index 98% rename from frameworks/cj/src/zoomquery.cpp rename to frameworks/cj/src/zoomquery_impl.cpp index f1f9ad38..cb697f8b 100644 --- a/frameworks/cj/src/zoomquery.cpp +++ b/frameworks/cj/src/zoomquery_impl.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "zoomquery.h" +#include "zoomquery_impl.h" namespace OHOS { namespace CameraStandard { -- Gitee From 5bd944e5849a263e5f351dadb7ce419b8318ade7 Mon Sep 17 00:00:00 2001 From: ForeverMeteor <2675561402@qq.com> Date: Mon, 29 Jul 2024 11:43:07 +0800 Subject: [PATCH 7/7] =?UTF-8?q?feature=2020240729=20=E6=96=B0=E5=A2=9EPhot?= =?UTF-8?q?oOutput=E9=83=A8=E5=88=86=E6=96=B9=E6=B3=95=EF=BC=8C=E5=8C=85?= =?UTF-8?q?=E6=8B=AC=EF=BC=9A=20IsMirrorSupported=20IsMovingPhotoSupported?= =?UTF-8?q?=20EnableMovingPhoto=20OnError=20OffError=20OnFrameShutter=20Of?= =?UTF-8?q?fFrameShutter=20OnFrameShutterEnd=20OffFrameShutterEnd=20OnCapt?= =?UTF-8?q?ureEnd=20OffCaptureEnd=20Change-Id:=20I439e31842c14d797f5f5fd8e?= =?UTF-8?q?fae3a88e2b4fdb55?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/cj/BUILD.gn | 2 + frameworks/cj/include/metadata_output_ffi.h | 8 +- frameworks/cj/include/photo_output_ffi.h | 37 +++ frameworks/cj/include/photo_output_impl.h | 130 ++++++++++ frameworks/cj/src/metadata_output_ffi.cpp | 16 +- frameworks/cj/src/photo_output_ffi.cpp | 134 ++++++++++ frameworks/cj/src/photo_output_impl.cpp | 262 ++++++++++++++++++++ 7 files changed, 577 insertions(+), 12 deletions(-) create mode 100644 frameworks/cj/include/photo_output_ffi.h create mode 100644 frameworks/cj/include/photo_output_impl.h create mode 100644 frameworks/cj/src/photo_output_ffi.cpp create mode 100644 frameworks/cj/src/photo_output_impl.cpp diff --git a/frameworks/cj/BUILD.gn b/frameworks/cj/BUILD.gn index ef58b488..a3fa776b 100644 --- a/frameworks/cj/BUILD.gn +++ b/frameworks/cj/BUILD.gn @@ -77,6 +77,8 @@ ohos_shared_library("cj_camera_ffi") { "src/colormanagementquery_impl.cpp", "src/camera_output_impl.cpp", "src/metadata_output_impl.cpp", + "src/photo_output_ffi.cpp", + "src/photo_output_impl.cpp", ] } else { defines += [ "PREVIEWER" ] diff --git a/frameworks/cj/include/metadata_output_ffi.h b/frameworks/cj/include/metadata_output_ffi.h index 8657fe0c..cbdbf65a 100644 --- a/frameworks/cj/include/metadata_output_ffi.h +++ b/frameworks/cj/include/metadata_output_ffi.h @@ -25,10 +25,10 @@ extern "C"{ FFI_EXPORT int64_t FfiOHOSMetadataOutputConstructor(); FFI_EXPORT int32_t FfiOHOSMetadataOutputStart(int64_t id); FFI_EXPORT int32_t FfiOHOSMetadataOutputStop(int64_t id); - FFI_EXPORT int32_t FfiOHOSMetadataOutputOnMetadataObjectsAvailable(int64_t id, void(*callback)(std::vector>)); - FFI_EXPORT int32_t FfiOHOSMetadataOutputOnError(int64_t id, void (*callback)(int32_t)); - FFI_EXPORT int32_t FfiOHOSMetadataOutputOnMetadataObjectsAvailable(int64_t id, void(*callback)(std::vector>)); - FFI_EXPORT int32_t FfiOHOSMetadataOutputOnError(int64_t id, void(*callback)(int32_t)); + FFI_EXPORT void FfiOHOSMetadataOutputOnMetadataObjectsAvailable(int64_t id, void(*callback)(std::vector>)); + FFI_EXPORT void FfiOHOSMetadataOutputOnError(int64_t id, void (*callback)(int32_t)); + FFI_EXPORT void FfiOHOSMetadataOutputOffMetadataObjectsAvailable(int64_t id, void(*callback)(std::vector>)); + FFI_EXPORT void FfiOHOSMetadataOutputOffError(int64_t id, void(*callback)(int32_t)); } } diff --git a/frameworks/cj/include/photo_output_ffi.h b/frameworks/cj/include/photo_output_ffi.h new file mode 100644 index 00000000..d343c6c6 --- /dev/null +++ b/frameworks/cj/include/photo_output_ffi.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "photo_output_impl.h" + +namespace OHOS { +namespace CameraStandard { + +extern "C"{ + FFI_EXPORT int64_t FfiOHOSPhotoOutputConstructor(); + FFI_EXPORT void FfiOHOSPhotoOutputOnError(int64_t id, void(*callback)(int32_t)); + FFI_EXPORT void FfiOHOSPhotoOutputOffError(int64_t id, void(*callback)(int32_t)); + FFI_EXPORT void FfiOHOSPhotoOutputOnFrameShutter(int64_t id, void(*callback)(std::vector>)); + FFI_EXPORT void FfiOHOSPhotoOutputOffFrameShutter(int64_t id, void(*callback)(std::vector>)); + FFI_EXPORT void FfiOHOSPhotoOutputOnFrameShutterEnd(int64_t id, void(*callback)(std::vector>)); + FFI_EXPORT void FfiOHOSPhotoOutputOffFrameShutterEnd(int64_t id, void(*callback)(std::vector>)); + FFI_EXPORT void FfiOHOSPhotoOutputOnCaptureEnd(int64_t id, void(*callback)(std::vector>)); + FFI_EXPORT void FfiOHOSPhotoOutputOffCaptureEnd(int64_t id, void(*callback)(std::vector>)); + FFI_EXPORT int32_t FfiOHOSPhotoOutputIsMirrorSupported(int64_t id, bool& isSupported); + FFI_EXPORT int32_t FfiOHOSPhotoOutputIsMovingPhotoSupported(int64_t id, bool& isSupported); + FFI_EXPORT int32_t FfiOHOSPhotoOutputEnableMovingPhoto(int64_t id, bool enabled); +} + +} +} \ No newline at end of file diff --git a/frameworks/cj/include/photo_output_impl.h b/frameworks/cj/include/photo_output_impl.h new file mode 100644 index 00000000..4bf0f753 --- /dev/null +++ b/frameworks/cj/include/photo_output_impl.h @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PHOTO_OUTPUT_IMPL_H +#define PHOTO_OUTPUT_IMPL_H + +// ffi +#include "ffi_remote_data.h" +#include "cj_common_ffi.h" +#include "camera_log.h" +#include "utils.h" + +#include "cj_lambda.h" +#include "camera_manager.h" +#include "camera_output_impl.h" +#include "photo_output.h" + +namespace OHOS { +namespace CameraStandard { + +class CjPhotoOutputCallback : public PhotoStateCallback, + // public ListenerBase<>, + public std::enable_shared_from_this { +public: + CjPhotoOutputCallback(); + virtual ~CjPhotoOutputCallback() = default; + + // 以下是CjPhotoOutputCallback的基类PhotoStateCallback的虚方法,需要给出具体实现,否则编译失败 + // 实现方式开发中 + void OnCaptureStarted(const int32_t captureID) const override; + void OnCaptureStarted(const int32_t captureID, uint32_t exposureTime) const override; + void OnCaptureEnded(const int32_t captureID, const int32_t frameCount) const override; + void OnFrameShutter(const int32_t captureId, const uint64_t timestamp) const override; + void OnFrameShutterEnd(const int32_t captureId, const uint64_t timestamp) const override; + void OnCaptureReady(const int32_t captureId, const uint64_t timestamp) const override; + void OnCaptureError(const int32_t captureId, const int32_t errorCode) const override; + void OnEstimatedCaptureDuration(const int32_t duration) const override; + + // 业务需求的异步函数 + void OnError(const int32_t errorType) const; + // void On +}; + +// 各个Info +/** + * 注意:此处的各个xxxInfo均由其他模块的同事实现,此处写这些空struct只是为了编译通过 + * 实际测试时应该引用外部的.h并将此处空struct删除 + */ +struct CjFrameShutterInfo { + //外部获取 +}; + +struct CjFrameShutterEndInfo { + //外部获取 +}; + +struct CjCaptureEndInfo { + //外部获取 +}; +// end struct + +class CjPhotoOutput : public CameraOutput{ +public: + CjPhotoOutput(); + ~CjPhotoOutput() override; + + static int32_t CreatePhotoOutput(); + + /** + * 异步函数 + */ + // Error + void OnError(void(*callback)(int32_t)); + void OffError(void(*callback)(int32_t)); + + // FrameShutter(注意:此处与上面的抽象函数重名; + // 然而napi中从未使用过上述抽象函数,而是也写了一个新的) + void OnFrameShutter(void(*callback)(std::vector>)); + void OffFrameShutter(void(*callback)(std::vector>)); + + // FrameShutterEnd + void OnFrameShutterEnd(void(*callback)(std::vector>)); + void OffFrameShutterEnd(void(*callback)(std::vector>)); + + // CaptureEnd + void OnCaptureEnd(void(*callback)(std::vector>)); + void OffCaptureEnd(void(*callback)(std::vector>)); + + /** + * 非异步函数 + */ + int32_t IsMirrorSupported(bool& isSupported); + int32_t IsMovingPhotoSupported(bool& isSupported); + int32_t EnableMovingPhoto(bool enabled); + +private: + sptr photoOutput_; + static thread_local sptr sPhotoOutput_; + + std::shared_ptr photoOutputCallback_; + + mutable std::mutex errorCallbackListMutex_ {}; + std::vector errorCallbackList; + + mutable std::mutex frameShutterCallbackListMutex_ {}; + std::vector>)> frameShutterCallbackList; + + mutable std::mutex frameShutterEndCallbackListMutex_ {}; + std::vector>)> frameShutterEndCallbackList; + + mutable std::mutex captureEndCallbackListMutex_ {}; + std::vector>)> captureEndCallbackList; + +}; + +} // namespace CameraStandard +} // namespace OHOS +#endif /* PHOTO_OUTPUT_FFI_H */ \ No newline at end of file diff --git a/frameworks/cj/src/metadata_output_ffi.cpp b/frameworks/cj/src/metadata_output_ffi.cpp index 9e079688..1b4a3c4b 100644 --- a/frameworks/cj/src/metadata_output_ffi.cpp +++ b/frameworks/cj/src/metadata_output_ffi.cpp @@ -47,38 +47,38 @@ extern "C"{ return metadataOutput->Stop(); } - int32_t FfiOHOSMetadataOutputOnMetadataObjectsAvailable(int64_t id, void(*callback)(std::vector>)){ + void FfiOHOSMetadataOutputOnMetadataObjectsAvailable(int64_t id, void(*callback)(std::vector>)){ auto metadataOutput = FFIData::GetData(id); if(metadataOutput == nullptr){ //is init? MEDIA_ERR_LOG("OnMetadataObjectsAvailable Failed!"); - return -1; + return; } return metadataOutput->On(callback); } - int32_t FfiOHOSMetadataOutputOnError(int64_t id, void (*callback)(int32_t)){ + void FfiOHOSMetadataOutputOnError(int64_t id, void (*callback)(int32_t)){ auto metadataOutput = FFIData::GetData(id); if(metadataOutput == nullptr){ //is init? MEDIA_ERR_LOG("OnError Failed!"); - return -1; + return; } return metadataOutput->On(callback); } - int32_t FfiOHOSMetadataOutputOnMetadataObjectsAvailable(int64_t id, void(*callback)(std::vector>)){ + void FfiOHOSMetadataOutputOffMetadataObjectsAvailable(int64_t id, void(*callback)(std::vector>)){ auto metadataOutput = FFIData::GetData(id); if(metadataOutput == nullptr){ //is init? MEDIA_ERR_LOG("OffMetadataObjectsAvailable Failed!"); - return -1; + return; } return metadataOutput->Off(callback); } - int32_t FfiOHOSMetadataOutputOnError(int64_t id, void(*callback)(int32_t)){ + void FfiOHOSMetadataOutputOffError(int64_t id, void(*callback)(int32_t)){ auto metadataOutput = FFIData::GetData(id); if(metadataOutput == nullptr){ //is init? MEDIA_ERR_LOG("OffError Failed!"); - return -1; + return; } return metadataOutput->Off(callback); } diff --git a/frameworks/cj/src/photo_output_ffi.cpp b/frameworks/cj/src/photo_output_ffi.cpp new file mode 100644 index 00000000..306f7b25 --- /dev/null +++ b/frameworks/cj/src/photo_output_ffi.cpp @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "photo_output_ffi.h" + +using namespace OHOS::FFI; + +namespace OHOS { +namespace CameraStandard { + +extern "C"{ + int64_t FfiOHOSPhotoOutputConstructor(){ + auto photoOutput = FFIData::Create(); + if (photoOutput == nullptr){ + MEDIA_ERR_LOG("New PhotoOutput Failed!"); + return -1; + } + return photoOutput->GetID(); + } + + void FfiOHOSPhotoOutputOnError(int64_t id, void(*callback)(int32_t)){ + auto photoOutput = FFIData::GetData(id); + if(photoOutput == nullptr){ //is init? + MEDIA_ERR_LOG("IsMirrorSupported Failed!"); + return; + } + return photoOutput->OnError(callback); + } + + void FfiOHOSPhotoOutputOffError(int64_t id, void(*callback)(int32_t)){ + auto photoOutput = FFIData::GetData(id); + if(photoOutput == nullptr){ //is init? + MEDIA_ERR_LOG("IsMirrorSupported Failed!"); + return; + } + return photoOutput->OffError(callback); + } + + void FfiOHOSPhotoOutputOnFrameShutter(int64_t id, void(*callback)(std::vector>)){ + auto photoOutput = FFIData::GetData(id); + if(photoOutput == nullptr){ //is init? + MEDIA_ERR_LOG("IsMirrorSupported Failed!"); + return; + } + return photoOutput->OnFrameShutter(callback); + } + + void FfiOHOSPhotoOutputOffFrameShutter(int64_t id, void(*callback)(std::vector>)){ + auto photoOutput = FFIData::GetData(id); + if(photoOutput == nullptr){ //is init? + MEDIA_ERR_LOG("IsMirrorSupported Failed!"); + return; + } + return photoOutput->OffFrameShutter(callback); + } + + void FfiOHOSPhotoOutputOnFrameShutterEnd(int64_t id, void(*callback)(std::vector>)){ + auto photoOutput = FFIData::GetData(id); + if(photoOutput == nullptr){ //is init? + MEDIA_ERR_LOG("IsMirrorSupported Failed!"); + return; + } + return photoOutput->OnFrameShutterEnd(callback); + } + + void FfiOHOSPhotoOutputOffFrameShutterEnd(int64_t id, void(*callback)(std::vector>)){ + auto photoOutput = FFIData::GetData(id); + if(photoOutput == nullptr){ //is init? + MEDIA_ERR_LOG("IsMirrorSupported Failed!"); + return; + } + return photoOutput->OffFrameShutterEnd(callback); + } + + void FfiOHOSPhotoOutputOnCaptureEnd(int64_t id, void(*callback)(std::vector>)){ + auto photoOutput = FFIData::GetData(id); + if(photoOutput == nullptr){ //is init? + MEDIA_ERR_LOG("IsMirrorSupported Failed!"); + return; + } + return photoOutput->OnCaptureEnd(callback); + } + + void FfiOHOSPhotoOutputOffCaptureEnd(int64_t id, void(*callback)(std::vector>)){ + auto photoOutput = FFIData::GetData(id); + if(photoOutput == nullptr){ //is init? + MEDIA_ERR_LOG("IsMirrorSupported Failed!"); + return; + } + return photoOutput->OffCaptureEnd(callback); + } + + int32_t FfiOHOSPhotoOutputIsMirrorSupported(int64_t id, bool& isSupported){ + auto photoOutput = FFIData::GetData(id); + if(photoOutput == nullptr){ //is init? + MEDIA_ERR_LOG("IsMirrorSupported Failed!"); + return -1; + } + return photoOutput->IsMirrorSupported(isSupported); + } + + int32_t FfiOHOSPhotoOutputIsMovingPhotoSupported(int64_t id, bool& isSupported){ + auto photoOutput = FFIData::GetData(id); + if(photoOutput == nullptr){ //is init? + MEDIA_ERR_LOG("IsMovingPhotoSupported Failed!"); + return -1; + } + return photoOutput->IsMovingPhotoSupported(isSupported); + } + + int32_t FfiOHOSPhotoOutputEnableMovingPhoto(int64_t id, bool enabled){ + auto photoOutput = FFIData::GetData(id); + if(photoOutput == nullptr){ //is init? + MEDIA_ERR_LOG("IsMovingPhotoSupported Failed!"); + return -1; + } + return photoOutput->EnableMovingPhoto(enabled); + } +} + +} +} \ No newline at end of file diff --git a/frameworks/cj/src/photo_output_impl.cpp b/frameworks/cj/src/photo_output_impl.cpp new file mode 100644 index 00000000..86205661 --- /dev/null +++ b/frameworks/cj/src/photo_output_impl.cpp @@ -0,0 +1,262 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "photo_output_impl.h" + +namespace OHOS { +namespace CameraStandard { + +CjPhotoOutputCallback::CjPhotoOutputCallback() {} + +// 以下是CjPhotoOutputCallback的基类PhotoStateCallback的虚方法,需要给出具体实现,否则编译失败 +// 实现方式开发中 +void CjPhotoOutputCallback::OnCaptureStarted(const int32_t captureID) const +{ + // CAMERA_SYNC_TRACE; + // MEDIA_DEBUG_LOG("OnCaptureStarted is called!, captureID: %{public}d", captureID); + // CallbackInfo info; + // info.captureID = captureID; + // UpdateJSCallbackAsync(PhotoOutputEventType::CAPTURE_START_WITH_INFO, info); +} + +void CjPhotoOutputCallback::OnCaptureStarted(const int32_t captureID, uint32_t exposureTime) const +{ + // CAMERA_SYNC_TRACE; + // MEDIA_DEBUG_LOG("OnCaptureStarted is called!, captureID: %{public}d", captureID); + // CallbackInfo info; + // info.captureID = captureID; + // info.timestamp = exposureTime; + // UpdateJSCallbackAsync(PhotoOutputEventType::CAPTURE_START, info); +} + +void CjPhotoOutputCallback::OnCaptureEnded(const int32_t captureID, const int32_t frameCount) const +{ + // CAMERA_SYNC_TRACE; + // MEDIA_DEBUG_LOG("OnCaptureEnded is called!, captureID: %{public}d, frameCount: %{public}d", + // captureID, frameCount); + // CallbackInfo info; + // info.captureID = captureID; + // info.frameCount = frameCount; + // UpdateJSCallbackAsync(PhotoOutputEventType::CAPTURE_END, info); +} + +void CjPhotoOutputCallback::OnFrameShutter(const int32_t captureId, const uint64_t timestamp) const +{ + // CAMERA_SYNC_TRACE; + // MEDIA_DEBUG_LOG( + // "OnFrameShutter is called, captureID: %{public}d, timestamp: %{public}" PRIu64, captureId, timestamp); + // CallbackInfo info; + // info.captureID = captureId; + // info.timestamp = timestamp; + // UpdateJSCallbackAsync(PhotoOutputEventType::CAPTURE_FRAME_SHUTTER, info); +} + +void CjPhotoOutputCallback::OnFrameShutterEnd(const int32_t captureId, const uint64_t timestamp) const +{ + // CAMERA_SYNC_TRACE; + // MEDIA_DEBUG_LOG( + // "OnFrameShutterEnd is called, captureID: %{public}d, timestamp: %{public}" PRIu64, captureId, timestamp); + // CallbackInfo info; + // info.captureID = captureId; + // info.timestamp = timestamp; + // UpdateJSCallbackAsync(PhotoOutputEventType::CAPTURE_FRAME_SHUTTER_END, info); +} + +void CjPhotoOutputCallback::OnCaptureReady(const int32_t captureId, const uint64_t timestamp) const +{ + // CAMERA_SYNC_TRACE; + // MEDIA_DEBUG_LOG( + // "OnCaptureReady is called, captureID: %{public}d, timestamp: %{public}" PRIu64, captureId, timestamp); + // CallbackInfo info; + // info.captureID = captureId; + // info.timestamp = timestamp; + // UpdateJSCallbackAsync(PhotoOutputEventType::CAPTURE_READY, info); +} + +void CjPhotoOutputCallback::OnCaptureError(const int32_t captureId, const int32_t errorCode) const +{ + // MEDIA_DEBUG_LOG("OnCaptureError is called!, captureID: %{public}d, errorCode: %{public}d", captureId, errorCode); + // CallbackInfo info; + // info.captureID = captureId; + // info.errorCode = errorCode; + // UpdateJSCallbackAsync(PhotoOutputEventType::CAPTURE_ERROR, info); +} + +void CjPhotoOutputCallback::OnEstimatedCaptureDuration(const int32_t duration) const +{ + // MEDIA_DEBUG_LOG("OnEstimatedCaptureDuration is called!, duration: %{public}d", duration); + // CallbackInfo info; + // info.duration = duration; + // UpdateJSCallbackAsync(PhotoOutputEventType::CAPTURE_ESTIMATED_CAPTURE_DURATION, info); +} +// 以上需实现(方式未知) + + + +void CjPhotoOutputCallback::OnError(const int32_t errorType) const{ + // TODO +} + +CjPhotoOutput::CjPhotoOutput() {} + +CjPhotoOutput::~CjPhotoOutput() {} + +/** + * 异步函数 + */ +void CjPhotoOutput::OnError(void(*callback)(int32_t)){ + if (photoOutputCallback_ == nullptr) { + photoOutputCallback_ = std::make_shared(); + photoOutput_->SetCallback(photoOutputCallback_); + } + // SaveCallbackReference + errorCallbackList.emplace_back(callback); +} + +void CjPhotoOutput::OffError(void(*callback)(int32_t)){ + std::lock_guard lock(errorCallbackListMutex_); + auto it = errorCallbackList.begin(); + while (it != errorCallbackList.end()) { + if (callback == *it) { + errorCallbackList.erase(it); + break; + } + } +} + +// FrameShutter(注意:此处与上面的抽象函数重名; +// 然而napi中从未使用过上述抽象函数,而是也写了一个新的) +void CjPhotoOutput::OnFrameShutter(void(*callback)(std::vector>)){ + if (photoOutputCallback_ == nullptr) { + photoOutputCallback_ = std::make_shared(); + photoOutput_->SetCallback(photoOutputCallback_); + } + // SaveCallbackReference + frameShutterCallbackList.emplace_back(callback); +} + +void CjPhotoOutput::OffFrameShutter(void(*callback)(std::vector>)){ + std::lock_guard lock(frameShutterCallbackListMutex_); + auto it = frameShutterCallbackList.begin(); + while (it != frameShutterCallbackList.end()) { + if (callback == *it) { + frameShutterCallbackList.erase(it); + break; + } + } +} + +void CjPhotoOutput::OnFrameShutterEnd(void(*callback)(std::vector>)){ + if (photoOutputCallback_ == nullptr) { + photoOutputCallback_ = std::make_shared(); + photoOutput_->SetCallback(photoOutputCallback_); + } + // SaveCallbackReference + frameShutterEndCallbackList.emplace_back(callback); +} + +void CjPhotoOutput::OffFrameShutterEnd(void(*callback)(std::vector>)){ + std::lock_guard lock(frameShutterEndCallbackListMutex_); + auto it = frameShutterEndCallbackList.begin(); + while (it != frameShutterEndCallbackList.end()) { + if (callback == *it) { + frameShutterEndCallbackList.erase(it); + break; + } + } +} + +void CjPhotoOutput::OnCaptureEnd(void(*callback)(std::vector>)){ + if (photoOutputCallback_ == nullptr) { + photoOutputCallback_ = std::make_shared(); + photoOutput_->SetCallback(photoOutputCallback_); + } + // SaveCallbackReference + captureEndCallbackList.emplace_back(callback); +} + +void CjPhotoOutput::OffCaptureEnd(void(*callback)(std::vector>)){ + std::lock_guard lock(captureEndCallbackListMutex_); + auto it = captureEndCallbackList.begin(); + while (it != captureEndCallbackList.end()) { + if (callback == *it) { + captureEndCallbackList.erase(it); + break; + } + } +} + +/** + * 非异步函数 + */ +int32_t CjPhotoOutput::IsMirrorSupported(bool& isSupported){ + MEDIA_INFO_LOG("IsMirrorSupported is called!"); + if(photoOutput_ == nullptr){ + MEDIA_ERR_LOG("IsMirrorSupported call Failed!"); + MEDIA_ERR_LOG("photooutput is nullptr."); + MEDIA_ERR_LOG("RetCode: -1"); + return -1; + } + bool result = photoOutput_->IsMirrorSupported(); + isSupported = result; + MEDIA_INFO_LOG("IsMirrorSupported success"); + return 0; +} + +int32_t CjPhotoOutput::IsMovingPhotoSupported(bool& isSupported){ + MEDIA_INFO_LOG("IsMovingPhotoSupported is called!"); + if(photoOutput_ == nullptr){ + MEDIA_ERR_LOG("IsMovingPhotoSupported call Failed!"); + MEDIA_ERR_LOG("photooutput is nullptr."); + MEDIA_ERR_LOG("RetCode: -1"); + return -1; + } + auto session = photoOutput_->GetSession(); + if(session == nullptr){ + MEDIA_ERR_LOG("IsMovingPhotoSupported call Failed!"); + MEDIA_ERR_LOG("session is nullptr."); + MEDIA_ERR_LOG("RetCode: -1"); + return -1; + } + bool result = session->IsMovingPhotoSupported(); + isSupported = result; + MEDIA_INFO_LOG("IsMovingPhotoSupported success"); + return 0; +} + +int32_t CjPhotoOutput::EnableMovingPhoto(bool enabled){ + MEDIA_INFO_LOG("EnableMovingPhoto is called!"); + if(photoOutput_ == nullptr){ + MEDIA_ERR_LOG("EnableMovingPhoto call Failed!"); + MEDIA_ERR_LOG("photooutput is nullptr."); + MEDIA_ERR_LOG("RetCode: -1"); + return -1; + } + auto session = photoOutput_->GetSession(); + if(session == nullptr){ + MEDIA_ERR_LOG("EnableMovingPhoto call Failed!"); + MEDIA_ERR_LOG("session is nullptr."); + MEDIA_ERR_LOG("RetCode: -1"); + return -1; + } + session->LockForControl(); + int32_t retCode = session->EnableMovingPhoto(enabled); + session->UnlockForControl(); + MEDIA_INFO_LOG("EnableMovingPhoto success"); + return retCode; +} + +} +} \ No newline at end of file -- Gitee