diff --git a/bundle.json b/bundle.json index 020f16dbdd31e97fe0416170132d2e56d061be08..0b7dae9d03be6d415916c5fe339ea460e1a17d46 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 0000000000000000000000000000000000000000..a3fa776b6774362765c946381c68463cdb4b6b91 --- /dev/null +++ b/frameworks/cj/BUILD.gn @@ -0,0 +1,101 @@ +# 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/utils.cpp", + "src/zoom_ffi.cpp", + "src/zoom_impl.cpp", + "src/zoomquery_impl.cpp", + "src/autoexposure_ffi.cpp", + "src/autoexposure_impl.cpp", + "src/autoexposurequery_impl.cpp", + "src/colormanagement_ffi.cpp", + "src/colormanagement_impl.cpp", + "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" ] + #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/autoexposure_ffi.h b/frameworks/cj/include/autoexposure_ffi.h new file mode 100644 index 0000000000000000000000000000000000000000..0d3b4d77dd891eff4250de1c0dc56cb7acb70386 --- /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/autoexposure_impl.h b/frameworks/cj/include/autoexposure_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..10590cc547b1e1a806f2df3070f1eba6a9cb1831 --- /dev/null +++ b/frameworks/cj/include/autoexposure_impl.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_impl.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/autoexposurequery_impl.h b/frameworks/cj/include/autoexposurequery_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..a9aab0e8872c10d45e6b910aa8ee433cbe2f534a --- /dev/null +++ b/frameworks/cj/include/autoexposurequery_impl.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 0000000000000000000000000000000000000000..225f45e087343b76102ab1abff17431f2d2c2ee5 --- /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/camera_output_impl.h b/frameworks/cj/include/camera_output_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..c97c9fd72cb19f20fcac1d7021a3fd751d2454ed --- /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/colormanagement_ffi.h b/frameworks/cj/include/colormanagement_ffi.h new file mode 100644 index 0000000000000000000000000000000000000000..43f737fac64a463fa70ae5f5d278d9db345c0c44 --- /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/colormanagement_impl.h b/frameworks/cj/include/colormanagement_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..02ed16e648836cd5c12d6a894ef99919aea590d8 --- /dev/null +++ b/frameworks/cj/include/colormanagement_impl.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_impl.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/colormanagementquery_impl.h b/frameworks/cj/include/colormanagementquery_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..829626b7e949b3413704d75c2cc9d884dea8efa3 --- /dev/null +++ b/frameworks/cj/include/colormanagementquery_impl.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/include/listener_base.h b/frameworks/cj/include/listener_base.h new file mode 100644 index 0000000000000000000000000000000000000000..f06deccbcfd1f2e26c0efbfffd5f71e9c904a853 --- /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_ffi.h b/frameworks/cj/include/metadata_output_ffi.h new file mode 100644 index 0000000000000000000000000000000000000000..cbdbf65ae2efb14589debb7ba94c7451e7a60e3f --- /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 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)); +} + +} +} \ 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 0000000000000000000000000000000000000000..5d17af1464b68ad747855ca1ba8d9cfe97f7d485 --- /dev/null +++ b/frameworks/cj/include/metadata_output_impl.h @@ -0,0 +1,93 @@ +/* + * 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" +#include "metadata_output_ffi.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(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_; + 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/include/photo_output_ffi.h b/frameworks/cj/include/photo_output_ffi.h new file mode 100644 index 0000000000000000000000000000000000000000..d343c6c628e884b70b26b1cafdf91bc0fdd591ac --- /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 0000000000000000000000000000000000000000..4bf0f753e0887a203f10f4057b348b785eb8a191 --- /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/include/utils.h b/frameworks/cj/include/utils.h new file mode 100644 index 0000000000000000000000000000000000000000..c53c22eab068f82f4377090d2a0dd95fe08452c1 --- /dev/null +++ b/frameworks/cj/include/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/zoom_ffi.h b/frameworks/cj/include/zoom_ffi.h new file mode 100644 index 0000000000000000000000000000000000000000..71021d67f42b4b4d31a47999bb224925c2115c79 --- /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 "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_impl.h b/frameworks/cj/include/zoom_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..817b7d3a9851da19c7e45c3654c2cc620877d154 --- /dev/null +++ b/frameworks/cj/include/zoom_impl.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_impl.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/zoomquery_impl.h b/frameworks/cj/include/zoomquery_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..b21527e43a30ece4e620faaa4e6178df2f076cc3 --- /dev/null +++ b/frameworks/cj/include/zoomquery_impl.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/autoexposure_ffi.cpp b/frameworks/cj/src/autoexposure_ffi.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e108af4cf918a261d38c003fa126348e7758f7e3 --- /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_impl.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/autoexposure_impl.cpp b/frameworks/cj/src/autoexposure_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d35931a26ad8ee18485b01bdf32060ef1165ff82 --- /dev/null +++ b/frameworks/cj/src/autoexposure_impl.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_impl.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/autoexposurequery_impl.cpp b/frameworks/cj/src/autoexposurequery_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6ac9b01d31d128d900ac090d1e88c3f3ff645cb6 --- /dev/null +++ b/frameworks/cj/src/autoexposurequery_impl.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_impl.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 0000000000000000000000000000000000000000..410f9fbc09c52a8e3bdd68fcef7c6f7d953688cd --- /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/camera_output_impl.cpp b/frameworks/cj/src/camera_output_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..76e706ee61bb26338b7fab65adb38c0a1ee75dbd --- /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/colormanagement_ffi.cpp b/frameworks/cj/src/colormanagement_ffi.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7bb39bef57cab63211b311fa7cb202238656cf55 --- /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_impl.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/colormanagement_impl.cpp b/frameworks/cj/src/colormanagement_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..eaf1ae2aeb812bed8449c06906d6bb45214df3a9 --- /dev/null +++ b/frameworks/cj/src/colormanagement_impl.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_impl.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/colormanagementquery_impl.cpp b/frameworks/cj/src/colormanagementquery_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5874d655e7c204bc8062dbe53d9682dd073a7533 --- /dev/null +++ b/frameworks/cj/src/colormanagementquery_impl.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_impl.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 diff --git a/frameworks/cj/src/listener_base.tpp b/frameworks/cj/src/listener_base.tpp new file mode 100644 index 0000000000000000000000000000000000000000..8bd75a7ebcb81600cc875c4bed26fc17eb5ac3f1 --- /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_ffi.cpp b/frameworks/cj/src/metadata_output_ffi.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1b4a3c4b1b9407b7bbc375bfd5530c7e7e73902a --- /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(); + } + + 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; + } + return metadataOutput->On(callback); + } + + 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; + } + return metadataOutput->On(callback); + } + + 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; + } + return metadataOutput->Off(callback); + } + + 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; + } + return metadataOutput->Off(callback); + } + +} + +} +} diff --git a/frameworks/cj/src/metadata_output_impl.cpp b/frameworks/cj/src/metadata_output_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..47396b5a5acb229197ec8a3d379647b43fc0761a --- /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(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(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(void(*callback)(std::vector>)){ + if (metadataOutputCallback_ == nullptr) { + return; + } + metadataOutputCallback_->RemoveCallbackRef( + std::make_shared>>>(CJLambda::Create(callback)) + ); +} + +void CjMetadataOutput::Off(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 diff --git a/frameworks/cj/src/photo_output_ffi.cpp b/frameworks/cj/src/photo_output_ffi.cpp new file mode 100644 index 0000000000000000000000000000000000000000..306f7b255a2a4751d46e0add4ec3854047a33cbe --- /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 0000000000000000000000000000000000000000..86205661ee694e670437d62fef249f1e0eb543f5 --- /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 diff --git a/frameworks/cj/src/utils.cpp b/frameworks/cj/src/utils.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5975b188bd09ac26bb457e74db802b4edd78d8a0 --- /dev/null +++ b/frameworks/cj/src/utils.cpp @@ -0,0 +1,8 @@ +#include "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/zoom_ffi.cpp b/frameworks/cj/src/zoom_ffi.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f1b0b4cce3ba6d401b172b61c4bd1bd1b3377a42 --- /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_impl.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_impl.cpp b/frameworks/cj/src/zoom_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..67c7183b07bb1a38697abc3e48348e94cdcc8e70 --- /dev/null +++ b/frameworks/cj/src/zoom_impl.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_impl.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/zoomquery_impl.cpp b/frameworks/cj/src/zoomquery_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cb697f8ba602558784dff3b6f2ea397dca0b85e2 --- /dev/null +++ b/frameworks/cj/src/zoomquery_impl.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_impl.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