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..e972e62b3ba5fb3f8386c36a36e3709583361488 --- /dev/null +++ b/frameworks/cj/BUILD.gn @@ -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. + +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", + ] + + 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_error.cpp", + "src/camera_manager_impl.cpp", + "src/camera_manager_ffi.cpp", + "src/cj_camera_utils.cpp", + "src/camera_input_impl.cpp", + "src/output/camera_output_impl.cpp", + "src/output/metadata_output_impl.cpp", + "src/output/photo_output_impl.cpp", + "src/output/preview_output_impl.cpp", + "src/output/video_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/camera_error.h b/frameworks/cj/include/camera_error.h new file mode 100644 index 0000000000000000000000000000000000000000..b8971cc56b1a72968046b82dbf0fae1f313db54a --- /dev/null +++ b/frameworks/cj/include/camera_error.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 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_ERRORS_FFI_H +#define CAMERA_ERRORS_FFI_H + +#include "errors.h" + +#include + +namespace OHOS { +namespace CameraStandard { +namespace CameraError{ +// constexpr ErrCode CAMERA_ERROR = -1; +constexpr ErrCode NO_ERROR = 0; +// constexpr ErrCode PARAM_CHECK_ERROR = 401; + +constexpr ErrCode INVALID_PARAM = 7400101; +constexpr ErrCode INVALID_OPTION = 7400102; +constexpr ErrCode SESSION_NOT_CONFIG = 7400103; +constexpr ErrCode SESSION_NOT_RUNNING = 7400104; +constexpr ErrCode SESSION_CONFIG_LOCKED = 7400105; +constexpr ErrCode DEVICE_SETTING_LOCKED = 7400106; +constexpr ErrCode CAMERA_CONFLICT = 7400107; +constexpr ErrCode SECURITY_DISABLED = 7400108; +constexpr ErrCode CAMERA_PREEMPED = 7400109; +constexpr ErrCode CONFLICT_WITH_CURRENT = 7400110; +constexpr ErrCode CAMERA_SERVICE_ERROR = 7400201; + +constexpr ErrCode CAMERA_MANAGER_INIT_ERROR = 7400202; +constexpr ErrCode MEMORY_MALLOC_ERROR = 7400203; + +std::string GetErrMsgByErrCode(ErrCode code); +} +} +} +#endif diff --git a/frameworks/cj/include/camera_input_impl.h b/frameworks/cj/include/camera_input_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..027c96b1643344ce99fe96fb231f8805780cd3f4 --- /dev/null +++ b/frameworks/cj/include/camera_input_impl.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_INPUT_IMPL_H +#define CAMERA_INPUT_IMPL_H + +#include "ffi_remote_data.h" +#include "camera_input.h" + +namespace OHOS { +namespace CameraStandard { + +class CjCameraInput : public OHOS::FFI::FFIData { + DECL_TYPE(CjCameraInput, OHOS::FFI::FFIData) + public: + CjCameraInput(sptr cameraInputInstance); + ~CjCameraInput() override; + + private: + static thread_local sptr cameraInput_; + }; +} +} +#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..b00b350f46768aafce6b8854d55d5ca288ca7e1b --- /dev/null +++ b/frameworks/cj/include/camera_manager_ffi.h @@ -0,0 +1,50 @@ +/* + * 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 CAMERA_MANAGER_FFI_H +#define CAMERA_MANAGER_FFI_H + +#include +#include "ffi_remote_data.h" +#include "cj_camera_utils.h" +#include "camera_error.h" +#include "camera_output_capability.h" + +extern "C" { + FFI_EXPORT int64_t FfiOHOSCameraManagerConstructor(); // return remote register id + + // camera manager static APIs + FFI_EXPORT bool FfiOHOSCameraIsCameraMuted(); + FFI_EXPORT bool FfiOHOSCameraIsTorchModeSupported(int32_t modeType); // TYPE TRANSFER TO TORCHMODE + FFI_EXPORT int32_t FfiOHOSCameraGetTorchMode(); + FFI_EXPORT int32_t FfiOHOSCameraSetTorchMode(int32_t modeType); + FFI_EXPORT bool FfiOHOSCameraIsTorchSupported(); + + // camera create-APIs like CameraManagerConstructor + FFI_EXPORT int64_t FfiOHOSCameraCreatePreviewOutput(OHOS::CameraStandard::CJProfile profile, const char* surfaceId, int32_t* errCode); + FFI_EXPORT int64_t FfiOHOSCameraCreatePhotoOutput(OHOS::CameraStandard::CJProfile profile, int32_t* errCode); + FFI_EXPORT int64_t FfiOHOSCameraCreateVideoOutput(OHOS::CameraStandard::CJVideoProfile profile, const char* surfaceId, int32_t* errCode); + FFI_EXPORT int64_t FfiOHOSCameraCreateMetadataOutput(CArrI32 metadataObjectTypes, int32_t* errCode); + + FFI_EXPORT int64_t FfiOHOSCameraCreateCameraInputWithCameraDevice(int64_t id, OHOS::CameraStandard::CJCameraDevice cameraDevice, int32_t* errCode); + FFI_EXPORT int64_t FfiOHOSCameraCreateCameraInputWithCameraDeviceInfo(int64_t id, int32_t cameraPosition, int32_t cameraType, int32_t* errCode); + + // camera manager object APIs + FFI_EXPORT RetDataCArrI32 FfiOHOSCameraManagerGetSupportedSceneModes(int64_t id, OHOS::CameraStandard::CJCameraDevice cameraDevice); + FFI_EXPORT OHOS::CameraStandard::RetDataCArrCJCameraDevice FfiOHOSCameraManagerGetSupportedCameras(int64_t id); + FFI_EXPORT OHOS::CameraStandard::RetDataCJCameraOutputCapability FfiOHOSCameraManagerGetSupportedOutputCapability(int64_t id, OHOS::CameraStandard::CJCameraDevice cameraDevice, int32_t modeType); +} + +#endif // CJ_CAMERA_MANAGER_FFI_H \ No newline at end of file diff --git a/frameworks/cj/include/camera_manager_impl.h b/frameworks/cj/include/camera_manager_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..7e61e566a2737ca7d8f59b27b17749e13af2f920 --- /dev/null +++ b/frameworks/cj/include/camera_manager_impl.h @@ -0,0 +1,56 @@ +/* + * 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_IMPL_H +#define CAMERA_MANAGER_IMPL_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: + // constructor function + CjCameraManager(); + ~CjCameraManager() override; + + // static methods + static bool IsCameraMuted(); + static bool IsTorchModeSupported(int32_t modeType); + static int32_t GetTorchMode(); + static int32_t SetTorchMode(int32_t modeType); + static bool IsTorchSupported(); + + // class common methods + sptr GetCameraDeviceById(std::string cameraId); + + // create methods + int64_t CreateCameraInputWithCameraDevice(sptr &camera, sptr *pCameraInput); + int64_t CreateCameraInputWithCameraDeviceInfo(CameraPosition position, CameraType cameraType, sptr *pCameraInput); + + // instance methods + std::vector GetSupportedModes(sptr& camera); + std::vector> GetSupportedCameras(); + sptr GetSupportedOutputCapability(sptr& camera, int32_t modeType = 0); +private: + sptr cameraManager_; + // static thread_local uint32_t cameraManagerTaskId; +}; +} // namespace CameraStandard +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/cj/include/cj_camera_utils.h b/frameworks/cj/include/cj_camera_utils.h new file mode 100644 index 0000000000000000000000000000000000000000..e76d210d42a7dbe2ef593f2e9a0180ad37d6f30e --- /dev/null +++ b/frameworks/cj/include/cj_camera_utils.h @@ -0,0 +1,98 @@ +/* + * 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 CJ_CAMERA_UTILS_H +#define CJ_CAMERA_UTILS_H + +#include +#include +#include +#include +#include "camera_device.h" +#include "camera_output_capability.h" +#include "cj_common_ffi.h" + +namespace OHOS { +namespace CameraStandard { + + struct CJCameraDevice + { + char* cameraId; + int32_t cameraPosition; + int32_t cameraType; + int32_t connectionType; + uint32_t cameraOrientation; + }; + + struct CArrCJCameraDevice { + CJCameraDevice* head; + int64_t size; + }; + + struct RetDataCArrCJCameraDevice + { + CArrCJCameraDevice data; + int32_t code; + }; + + struct CJProfile + { + int32_t format; + // Size size; + uint32_t width; + uint32_t height; + }; + + struct CArrCJProfile + { + CJProfile* head; + int64_t size; + }; + + + struct CJVideoProfile + { + int32_t format; + // Size size; + uint32_t width; + uint32_t height; + CArrI32 frameRateRange; + }; + + struct CArrCJVideoProfile + { + CJVideoProfile* head; + int64_t size; + }; + + struct CJCameraOutputCapability + { + CArrCJProfile previewProfiles; + CArrCJProfile photoProfiles; + CArrCJVideoProfile videoProfiles; + CArrI32 supportedMetadataObjectTypes; + }; + + struct RetDataCJCameraOutputCapability + { + CJCameraOutputCapability data; + int32_t code; + }; + + char* MallocCString(const std::string& origin); +} +} + +#endif // CJ_CAMERA_UTILS_H \ No newline at end of file diff --git a/frameworks/cj/include/output/camera_output_impl.h b/frameworks/cj/include/output/camera_output_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..0b402d489103d4a638951d256e3f2af0f0251c8c --- /dev/null +++ b/frameworks/cj/include/output/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 \ No newline at end of file diff --git a/frameworks/cj/include/output/metadata_output_impl.h b/frameworks/cj/include/output/metadata_output_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..848c69dc1baeb40a1a02f86b56221af088a9f277 --- /dev/null +++ b/frameworks/cj/include/output/metadata_output_impl.h @@ -0,0 +1,38 @@ +/* + * 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 "camera_output_impl.h" +#include "metadata_output.h" + +namespace OHOS { +namespace CameraStandard { + class CjMetadataOutput : public CameraOutput { + public: + CjMetadataOutput(); + ~CjMetadataOutput() override; + + static int32_t CreateMetadataOutput(); + void SetMetadataObjectTypes(std::vector metadataObjectTypes); + + private: + sptr metadataOutput_; + static thread_local sptr sMetadataOutput_; + }; + } // namespace CameraStandard +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/cj/include/output/photo_output_impl.h b/frameworks/cj/include/output/photo_output_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..fa9f1c0254ad5638ee8f63071dd32b50192df0c0 --- /dev/null +++ b/frameworks/cj/include/output/photo_output_impl.h @@ -0,0 +1,40 @@ +/* + * 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 + +#include "camera_output_impl.h" +#include "camera_output_capability.h" +#include "photo_output.h" + +namespace OHOS { +namespace CameraStandard { + class CjPhotoOutput : public CameraOutput { + public: + CjPhotoOutput(); + ~CjPhotoOutput() override; + + static int32_t CreatePhotoOutput(Profile& profile, std::string& surfaceId); + + private: + static thread_local sptr sPhotoOutput_; + static thread_local sptr sPhotoSurface_; + + sptr photoOutput_; + }; + } // namespace CameraStandard +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/cj/include/output/preview_output_impl.h b/frameworks/cj/include/output/preview_output_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..ed1904c938ed9d56aaeb67474ca767ae95afa2e0 --- /dev/null +++ b/frameworks/cj/include/output/preview_output_impl.h @@ -0,0 +1,39 @@ +/* + * 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 PREVIEW_OUTPUT_IMPL_H +#define PREVIEW_OUTPUT_IMPL_H + +#include "camera_output_impl.h" +#include "preview_output.h" +// #include "image_receiver.h" + +namespace OHOS { +namespace CameraStandard { + class CjPreviewOutput : public CameraOutput { + public: + CjPreviewOutput(); + ~CjPreviewOutput() override; + + static sptr GetSurfaceBySurfaceId(std::string& surfaceId); + static int32_t CreatePreviewOutput(Profile& profile, std::string& surfaceId); + + private: + sptr previewOutput_; + static thread_local sptr sPreviewOutput_; + }; + } // namespace CameraStandard +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/cj/include/output/video_output_impl.h b/frameworks/cj/include/output/video_output_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..944f2b894d033374787891c13a07e6a479193617 --- /dev/null +++ b/frameworks/cj/include/output/video_output_impl.h @@ -0,0 +1,37 @@ +/* + * 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 VIDEO_OUTPUT_IMPL_H +#define VIDEO_OUTPUT_IMPL_H + +#include "camera_output_impl.h" +#include "video_output.h" + +namespace OHOS { +namespace CameraStandard { + class CjVideoOutput : public CameraOutput { + public: + CjVideoOutput(); + ~CjVideoOutput() override; + + static int32_t CreateVideoOutput(VideoProfile& profile, std::string& surfaceId); + + private: + sptr videoOutput_; + static thread_local sptr sVideoOutput_; + }; + } // namespace CameraStandard +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/cj/src/camera_error.cpp b/frameworks/cj/src/camera_error.cpp new file mode 100644 index 0000000000000000000000000000000000000000..729f264d298ec396ec84284b7415385fb05b3f90 --- /dev/null +++ b/frameworks/cj/src/camera_error.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 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. + */ + +#include "camera_error.h" + +#include +#include + +namespace OHOS { +namespace CameraStandard { +namespace CameraError { +// error message +const std::string INVALID_PARAM_MSG = "Parameter missing or parameter type incorrect."; +const std::string INVALID_OPTION_MSG = "Operation not allowed."; +const std::string SESSION_NOT_CONFIG_MSG = "Session not config."; +const std::string SESSION_NOT_RUNNING_MSG = "Session not running."; +const std::string SESSION_CONFIG_LOCKED_MSG = "Session config locked."; +const std::string DEVICE_SETTING_LOCKED_MSG = "Device setting locked."; +const std::string CAMERA_CONFLICT_MSG = "Can not use camera cause of conflict."; +const std::string SECURITY_DISABLED_MSG = "Camera disabled cause of security reason."; +const std::string CAMERA_PREEMPED_MSG = "Can not use camera cause of preempted."; +const std::string CONFLICT_WITH_CURRENT_MSG = "Unresolved conflicts with current configurations."; +const std::string CAMERA_SERVICE_ERROR_MSG = "Camera service fatal error."; +const std::string CAMERA_MANAGER_INIT_ERROR_MSG = "Camera Manager Instance Init Failed."; +const std::string MEMORY_MALLOC_ERROR_MSG = "Malloc Memory Failed."; + +std::unordered_map g_errCodeMsgMap = { + {INVALID_PARAM, INVALID_PARAM_MSG}, + {INVALID_OPTION, INVALID_OPTION_MSG}, + {SESSION_NOT_CONFIG, SESSION_NOT_CONFIG_MSG}, + {SESSION_NOT_RUNNING, SESSION_NOT_RUNNING_MSG}, + {SESSION_CONFIG_LOCKED, SESSION_CONFIG_LOCKED_MSG}, + {DEVICE_SETTING_LOCKED, DEVICE_SETTING_LOCKED_MSG}, + {CAMERA_CONFLICT, CAMERA_CONFLICT_MSG}, + {SECURITY_DISABLED, SECURITY_DISABLED_MSG}, + {CAMERA_PREEMPED, CAMERA_PREEMPED_MSG}, + {CONFLICT_WITH_CURRENT, CONFLICT_WITH_CURRENT_MSG}, + {CAMERA_SERVICE_ERROR, CAMERA_SERVICE_ERROR_MSG}, + {CAMERA_MANAGER_INIT_ERROR, CAMERA_MANAGER_INIT_ERROR_MSG}, + {MEMORY_MALLOC_ERROR, MEMORY_MALLOC_ERROR_MSG}, +}; + +std::string GetErrMsgByErrCode(ErrCode code) +{ + return g_errCodeMsgMap[code]; +} +} +} // namespace CJCAMERAERROR +} // namespace OHOS diff --git a/frameworks/cj/src/camera_input_impl.cpp b/frameworks/cj/src/camera_input_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..977c096cb379e63fe5d17c3512f2d3f1783ae115 --- /dev/null +++ b/frameworks/cj/src/camera_input_impl.cpp @@ -0,0 +1,31 @@ +/* + * 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 "cj_camera_utils.h" +#include "camera_input_impl.h" + +namespace OHOS { +namespace CameraStandard { +thread_local sptr CjCameraInput::cameraInput_ = nullptr; + +// class constructor +CjCameraInput::CjCameraInput(sptr cameraInputInstance) { + cameraInput_ = cameraInputInstance; +} + +CjCameraInput::~CjCameraInput() {} + +} // 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..17e2f1aa472f54048a5d79293c9b11302b2d69f3 --- /dev/null +++ b/frameworks/cj/src/camera_manager_ffi.cpp @@ -0,0 +1,409 @@ +/* + * 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" +#include "camera_manager_impl.h" +#include "camera_input_impl.h" +#include "output/preview_output_impl.h" +#include "output/photo_output_impl.h" +#include "output/video_output_impl.h" +#include "output/metadata_output_impl.h" +#include "camera_device.h" +#include "camera_output_capability.h" +#include + +using namespace OHOS::FFI; + +namespace OHOS { +namespace CameraStandard { + +extern "C" { + int64_t FfiOHOSCameraManagerConstructor() + { + auto cameraManagerImpl = FFIData::Create(); + if (cameraManagerImpl == nullptr) { + //CAMERALOG("Camera Manager Init failed."); + return -1; + } + return cameraManagerImpl->GetID(); + } + + bool FfiOHOSCameraIsCameraMuted() + { + return CjCameraManager::IsCameraMuted(); + } + + bool FfiOHOSCameraIsTorchModeSupported(int32_t modeType) + { + return CjCameraManager::IsTorchModeSupported(modeType); + } + + bool FfiOHOSCameraIsTorchSupported() + { + return CjCameraManager::IsTorchSupported(); + } + + int32_t FfiOHOSCameraGetTorchMode() + { + return CjCameraManager::GetTorchMode(); + } + + int32_t FfiOHOSCameraSetTorchMode(int32_t modeType) + { + return CjCameraManager::SetTorchMode(modeType); + } + + RetDataCArrI32 FfiOHOSCameraManagerGetSupportedSceneModes(int64_t id, CJCameraDevice cameraDevice) + { + CArrI32 result = {nullptr, 0}; + RetDataCArrI32 ret = {CameraError::CAMERA_MANAGER_INIT_ERROR, result}; + + auto cameraManagerImpl = FFIData::GetData(id); + if (cameraManagerImpl == nullptr) { + //CAMERALOG("Camera Manager Init failed."); + return ret; + } + + std::string cameraId = std::string(cameraDevice.cameraId); + sptr cameraInfo = cameraManagerImpl->GetCameraDeviceById(cameraId); + if (cameraInfo == nullptr) { + ret.code = CameraError::INVALID_PARAM; + return ret; + } + + std::vector modeObjList = cameraManagerImpl->GetSupportedModes(cameraInfo); + for (auto it = modeObjList.begin(); it != modeObjList.end(); it++) { + if (*it == SCAN) { + modeObjList.erase(it); + break; + } + } + if (modeObjList.empty()) { + modeObjList.emplace_back(CAPTURE); + modeObjList.emplace_back(VIDEO); + } + + int32_t* sceneModes = static_cast(malloc(sizeof(int32_t) * modeObjList.size())); + if (sceneModes == nullptr) { + ret.code = CameraError::MEMORY_MALLOC_ERROR; + return ret; + } + + for (int i = 0; i < modeObjList.size(); i++) { + sceneModes[i] = modeObjList[i]; + } + result.head = sceneModes; + result.size = modeObjList.size(); + ret.data = result; + ret.code = CameraError::NO_ERROR; + return ret; + } + + RetDataCArrCJCameraDevice FfiOHOSCameraManagerGetSupportedCameras(int64_t id) + { + CArrCJCameraDevice result = {nullptr, 0}; + RetDataCArrCJCameraDevice ret = {result, CameraError::CAMERA_MANAGER_INIT_ERROR}; + + auto cameraManagerImpl = FFIData::GetData(id); + if (cameraManagerImpl == nullptr) { + //CAMERALOG("Camera Manager Init failed."); + return ret; + } + + std::vector> supportedCameraDevices = cameraManagerImpl->GetSupportedCameras(); + int len = supportedCameraDevices.size(); + CJCameraDevice* supportedCameras = static_cast(malloc(sizeof(CJCameraDevice) * len)); + + if (supportedCameras == nullptr) { + //CAMERALOG("supported camera devices malloc failed."); + ret.code = CameraError::MEMORY_MALLOC_ERROR; + return ret; + } + + int i = 0; + for (auto it = supportedCameraDevices.begin(); it != supportedCameraDevices.end(); ++it) { + sptr cameraDevice = *it; + char* cameraDeviceId = MallocCString(cameraDevice->GetID()); + if (cameraDeviceId == nullptr) { + //CAMERALOG("supported camera devices malloc failed."); + ret.code = CameraError::MEMORY_MALLOC_ERROR; + free(supportedCameras); + for (int j = 0; j < i; j++) + free(supportedCameras[j].cameraId); + return ret; + } + + supportedCameras[i].cameraId = cameraDeviceId; + supportedCameras[i].cameraPosition = static_cast(cameraDevice->GetPosition()); + supportedCameras[i].cameraType = static_cast(cameraDevice->GetCameraType()); + supportedCameras[i].connectionType = static_cast(cameraDevice->GetConnectionType()); + supportedCameras[i].cameraOrientation = cameraDevice->GetCameraOrientation(); + i++; + } + + result.size = len; + result.head = supportedCameras; + ret.data = result; + ret.code = CameraError::NO_ERROR; + return ret; + } + + RetDataCJCameraOutputCapability FfiOHOSCameraManagerGetSupportedOutputCapability(int64_t id, CJCameraDevice cameraDevice, int32_t modeType) + { + CJCameraOutputCapability result; + RetDataCJCameraOutputCapability ret = {result, CameraError::CAMERA_MANAGER_INIT_ERROR}; + + auto cameraManagerImpl = FFIData::GetData(id); + if (cameraManagerImpl == nullptr) { + //CAMERALOG("Camera Manager Init failed."); + return ret; + } + + std::string cameraId = std::string(cameraDevice.cameraId); + sptr cameraInfo = cameraManagerImpl->GetCameraDeviceById(cameraId); + if (cameraInfo == nullptr) { + ret.code = CameraError::INVALID_PARAM; + return ret; + } + + sptr cameraOutputCapability = cameraManagerImpl->GetSupportedOutputCapability(cameraInfo, modeType); + + std::vector photoProfiles_ = cameraOutputCapability->GetPhotoProfiles(); + std::vector previewProfiles_ = cameraOutputCapability->GetPreviewProfiles(); + std::vector videoProfiles_ = cameraOutputCapability->GetVideoProfiles(); + std::vector metadataObjectType_ = cameraOutputCapability->GetSupportedMetadataObjectType(); + + //CAMERALOG("Camera OutputCapability Set PhotoProfiles."); + result.previewProfiles.size = previewProfiles_.size(); + result.previewProfiles.head = static_cast(malloc(sizeof(CJProfile) * previewProfiles_.size())); + if (result.previewProfiles.head == nullptr) { + ret.code = CameraError::MEMORY_MALLOC_ERROR; + return ret; + } + for (int i = 0; i < previewProfiles_.size(); i++) + { + result.previewProfiles.head[i].format = previewProfiles_[i].GetCameraFormat(); + Size t = previewProfiles_[i].GetSize(); + result.previewProfiles.head[i].width = t.width; + result.previewProfiles.head[i].height = t.height; + } + + //CAMERALOG("Camera OutputCapability Set PreviewProfiles."); + result.photoProfiles.size = photoProfiles_.size(); + result.photoProfiles.head = static_cast(malloc(sizeof(CJProfile) * photoProfiles_.size())); + if (result.photoProfiles.head == nullptr) { + ret.code = CameraError::MEMORY_MALLOC_ERROR; + free(result.previewProfiles.head); + return ret; + } + for (int i = 0; i < photoProfiles_.size(); i++) + { + result.photoProfiles.head[i].format = photoProfiles_[i].GetCameraFormat(); + Size t = photoProfiles_[i].GetSize(); + result.photoProfiles.head[i].width = t.width; + result.photoProfiles.head[i].height = t.height; + } + + //CAMERALOG("Camera OutputCapability Set VideoProfiles."); + result.videoProfiles.size = videoProfiles_.size(); + result.videoProfiles.head = static_cast(malloc(sizeof(CJVideoProfile) * videoProfiles_.size())); + if (result.videoProfiles.head == nullptr) { + ret.code = CameraError::MEMORY_MALLOC_ERROR; + free(result.previewProfiles.head); + free(result.photoProfiles.head); + return ret; + } + for (int i = 0; i < videoProfiles_.size(); i++) + { + result.videoProfiles.head[i].format = videoProfiles_[i].GetCameraFormat(); + Size t = videoProfiles_[i].GetSize(); + result.videoProfiles.head[i].width = t.width; + result.videoProfiles.head[i].height = t.height; + + std::vector vpi_framerates = videoProfiles_[i].GetFrameRates(); + result.videoProfiles.head[i].frameRateRange.size = vpi_framerates.size(); + result.videoProfiles.head[i].frameRateRange.head = static_cast(malloc(sizeof(int32_t) * vpi_framerates.size())); + if (result.videoProfiles.head[i].frameRateRange.head == nullptr) { + ret.code = CameraError::MEMORY_MALLOC_ERROR; + free(result.previewProfiles.head); + free(result.photoProfiles.head); + for (int j = 0; j < i;j++) { + free(result.videoProfiles.head[j].frameRateRange.head); + } + free(result.videoProfiles.head); + return ret; + } + for (int k = 0; k < vpi_framerates.size(); k++) { + result.videoProfiles.head[i].frameRateRange.head[k] = vpi_framerates[k]; + } + } + + //CAMERALOG("Camera OutputCapability Set MetadataObjectType."); + result.supportedMetadataObjectTypes.head = static_cast(malloc(sizeof(int32_t) * metadataObjectType_.size())); + if (result.supportedMetadataObjectTypes.head == nullptr) { + ret.code = CameraError::MEMORY_MALLOC_ERROR; + free(result.previewProfiles.head); + free(result.photoProfiles.head); + for (int i = 0; i < videoProfiles_.size(); i++) { + free(result.videoProfiles.head[i].frameRateRange.head); + } + free(result.videoProfiles.head); + return ret; + } + for (int i = 0; i < metadataObjectType_.size(); i++) + { + result.supportedMetadataObjectTypes.head[i] = static_cast(metadataObjectType_[i]); + } + + //CAMERALOG("Camera OutputCapability Set Successful."); + ret.data = result; + ret.code = CameraError::NO_ERROR; + return ret; + } + + int64_t FfiOHOSCameraCreateCameraInputWithCameraDevice(int64_t id, CJCameraDevice cameraDevice, int32_t* errCode) + { + sptr cameraInput = nullptr; + auto cameraManagerImpl = FFIData::GetData(id); + if (cameraManagerImpl == nullptr) { + //CAMERALOG("Camera Manager Init failed."); + *errCode = CameraError::CAMERA_MANAGER_INIT_ERROR; + return -1; + } + + std::string cameraId = std::string(cameraDevice.cameraId); + sptr cameraInfo = cameraManagerImpl->GetCameraDeviceById(cameraId); + if (cameraInfo == nullptr) { + *errCode = CameraError::INVALID_PARAM; + return -1; + } + + *errCode = cameraManagerImpl->CreateCameraInputWithCameraDevice(cameraInfo, &cameraInput); + auto cameraInputImpl = FFIData::Create(cameraInput); + if (cameraInputImpl == nullptr) { + //CAMERALOG("Camera Manager Init failed."); + *errCode = CameraError::CAMERA_SERVICE_ERROR; + return -1; + } + + return cameraInputImpl->GetID(); + } + + int64_t FfiOHOSCameraCreateCameraInputWithCameraDeviceInfo(int64_t id, int32_t cameraPosition, int32_t cameraType, int32_t* errCode) + { + sptr cameraInput = nullptr; + auto cameraManagerImpl = FFIData::GetData(id); + if (cameraManagerImpl == nullptr) { + //CAMERALOG("Camera Manager Init failed."); + *errCode = CameraError::CAMERA_MANAGER_INIT_ERROR; + return -1; + } + + *errCode = cameraManagerImpl->CreateCameraInputWithCameraDeviceInfo(static_cast(cameraPosition), static_cast(cameraType), &cameraInput); + auto cameraInputImpl = FFIData::Create(cameraInput); + if (cameraInputImpl == nullptr) { + //CAMERALOG("Camera Manager Init failed."); + *errCode = CameraError::CAMERA_SERVICE_ERROR; + return -1; + } + + return cameraInputImpl->GetID(); + } + + int64_t FfiOHOSCameraCreatePreviewOutput(CJProfile profile, const char* surfaceId, int32_t* errCode) + { + std::string surfaceId_s = std::string(surfaceId); + Size size = {profile.width, profile.height}; + Profile c_Profile(CameraFormat(profile.format), size); + + *errCode = CjPreviewOutput::CreatePreviewOutput(c_Profile, surfaceId_s); + if (*errCode == CameraError::CAMERA_SERVICE_ERROR) { + return -1; + } + + auto previewOutputImpl = FFIData::Create(); + if (previewOutputImpl == nullptr) { + //CAMERALOG("PreviewOutput Init failed."); + return -1; + } + return previewOutputImpl->GetID(); + } + + int64_t FfiOHOSCameraCreatePhotoOutput(CJProfile profile, int32_t* errCode) + { + Size size = {profile.width, profile.height}; + Profile c_Profile(CameraFormat(profile.format), size); + std::string surfaceId = ""; + + *errCode = CjPhotoOutput::CreatePhotoOutput(c_Profile, surfaceId); + if (*errCode == CameraError::CAMERA_SERVICE_ERROR) { + return -1; + } + + auto photoOutputImpl = FFIData::Create(); + if (photoOutputImpl == nullptr) { + //CAMERALOG("PhotoOutput Init failed."); + return -1; + } + return photoOutputImpl->GetID(); + } + + int64_t FfiOHOSCameraCreateVideoOutput(CJVideoProfile profile, const char* surfaceId, int32_t* errCode) + { + std::vector framerates(profile.frameRateRange.head, profile.frameRateRange.head + profile.frameRateRange.size); + Size size = {profile.width, profile.height}; + VideoProfile profile_(CameraFormat(profile.format), size, framerates); + + std::string surfaceId_s = std::string(surfaceId); + + *errCode = CjVideoOutput::CreateVideoOutput(profile_, surfaceId_s); + if (*errCode == CameraError::CAMERA_SERVICE_ERROR) { + return -1; + } + + auto videoOutputImpl = FFIData::Create(); + if (videoOutputImpl == nullptr) { + //CAMERALOG("VideoOutput Init failed."); + return -1; + } + return videoOutputImpl->GetID(); + } + + int64_t FfiOHOSCameraCreateMetadataOutput(CArrI32 metadataObjectTypes, int32_t* errCode) + { + *errCode = CjMetadataOutput::CreateMetadataOutput(); + if (*errCode == CameraError::CAMERA_SERVICE_ERROR) { + return -1; + } + + auto metadataOutputImpl = FFIData::Create(); + if (metadataOutputImpl == nullptr) { + //CAMERALOG("VideoOutput Init failed."); + *errCode = CameraError::CAMERA_SERVICE_ERROR; + return -1; + } + + std::vector metadataObjectTypesVector(metadataObjectTypes.size); + for (int i = 0; i < metadataObjectTypes.size; i++) + { + metadataObjectTypesVector[i] = static_cast(metadataObjectTypes.head[i]); + } + metadataOutputImpl->SetMetadataObjectTypes(metadataObjectTypesVector); + return metadataOutputImpl->GetID(); + } + +} +} +} diff --git a/frameworks/cj/src/camera_manager_impl.cpp b/frameworks/cj/src/camera_manager_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..99d386223ecf9cf47e74d9e866919158e8ff4218 --- /dev/null +++ b/frameworks/cj/src/camera_manager_impl.cpp @@ -0,0 +1,111 @@ +/* + * 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_impl.h" +#include "cj_camera_utils.h" + +namespace OHOS { +namespace CameraStandard { + +// class constructor +CjCameraManager::CjCameraManager() { + cameraManager_ = CameraManager::GetInstance(); +} + +CjCameraManager::~CjCameraManager() {} + +// class static methods +bool CjCameraManager::IsCameraMuted() +{ + bool isMuted = CameraManager::GetInstance()->IsCameraMuted(); + return isMuted; +} + +bool CjCameraManager::IsTorchModeSupported(int32_t modeType) +{ + TorchMode mode = TorchMode(modeType); + bool isTorchModeSupported = CameraManager::GetInstance()->IsTorchModeSupported(mode); + return isTorchModeSupported; +} + +int32_t CjCameraManager::GetTorchMode() +{ + TorchMode torchMode = CameraManager::GetInstance()->GetTorchMode(); + return torchMode; +} + +int32_t CjCameraManager::SetTorchMode(int32_t modeType) +{ + TorchMode mode = TorchMode(modeType); + int32_t retCode = CameraManager::GetInstance()->SetTorchMode(mode); + return retCode; +} + +bool CjCameraManager::IsTorchSupported() +{ + bool isTorchSupported = CameraManager::GetInstance()->IsTorchSupported(); + return isTorchSupported; +} + +// class common methods +sptr CjCameraManager::GetCameraDeviceById(std::string cameraId) +{ + return cameraManager_->GetCameraDeviceFromId(cameraId); +} + +// class create methods +int64_t CjCameraManager::CreateCameraInputWithCameraDevice(sptr &camera, sptr *pCameraInput) +{ + int retCode = cameraManager_->CreateCameraInput(camera, pCameraInput); + return retCode; +} + +int64_t CjCameraManager::CreateCameraInputWithCameraDeviceInfo(CameraPosition position, CameraType cameraType, sptr *pCameraInput) +{ + std::vector> cameraObjList = cameraManager_->GetSupportedCameras(); + sptr cameraInfo = nullptr; + for (size_t i = 0; i < cameraObjList.size(); i++) { + sptr cameraDevice = cameraObjList[i]; + if (cameraDevice == nullptr) { + continue; + } + if (cameraDevice->GetPosition() == position && + cameraDevice->GetCameraType() == cameraType) { + cameraInfo = cameraDevice; + break; + } + } + return CreateCameraInputWithCameraDevice(cameraInfo, pCameraInput); +} + +// class instance methods +std::vector CjCameraManager::GetSupportedModes(sptr& camera) +{ + return cameraManager_->GetSupportedModes(camera); +} + +std::vector> CjCameraManager::GetSupportedCameras() +{ + std::vector> cameraObjList = cameraManager_->GetSupportedCameras(); + return cameraObjList; +} + +sptr CjCameraManager::GetSupportedOutputCapability(sptr& camera, int32_t modeType) +{ + return cameraManager_->GetSupportedOutputCapability(camera, modeType); +} + +} // namespace CameraStandard +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/cj/src/cj_camera_utils.cpp b/frameworks/cj/src/cj_camera_utils.cpp new file mode 100644 index 0000000000000000000000000000000000000000..44a3842ac3350d2bc2323e0deab3b34553a4e743 --- /dev/null +++ b/frameworks/cj/src/cj_camera_utils.cpp @@ -0,0 +1,33 @@ +/* + * 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 "cj_camera_utils.h" + +namespace OHOS { +namespace CameraStandard { + char* MallocCString(const std::string& origin) + { + auto len = origin.length() + 1; + char* res = static_cast(malloc(sizeof(char) * len)); + if (res == nullptr) { + return nullptr; + } + return std::char_traits::copy(res, origin.c_str(), len); + } +} +} \ No newline at end of file diff --git a/frameworks/cj/src/output/camera_output_impl.cpp b/frameworks/cj/src/output/camera_output_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f443ddc3a3c99928dcdf2f50791fd3f88576beb6 --- /dev/null +++ b/frameworks/cj/src/output/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 "output/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/output/metadata_output_impl.cpp b/frameworks/cj/src/output/metadata_output_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f72382b3139f95cbf4a90d6072cbf03234ceb4bc --- /dev/null +++ b/frameworks/cj/src/output/metadata_output_impl.cpp @@ -0,0 +1,43 @@ +/* + * 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 "output/metadata_output_impl.h" +#include "camera_manager.h" + +namespace OHOS { +namespace CameraStandard { + +thread_local sptr CjMetadataOutput::sMetadataOutput_ = nullptr; + +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); +} + +} // namespace CameraStandard +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/cj/src/output/photo_output_impl.cpp b/frameworks/cj/src/output/photo_output_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d9c272e4a0420ac9b5d53c58ad219547c283db71 --- /dev/null +++ b/frameworks/cj/src/output/photo_output_impl.cpp @@ -0,0 +1,68 @@ +/* + * 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 "output/photo_output_impl.h" +#include "surface_utils.h" +#include "camera_manager.h" +#include "camera_error.h" + +namespace OHOS { +namespace CameraStandard { + +thread_local sptr CjPhotoOutput::sPhotoOutput_ = nullptr; +thread_local sptr CjPhotoOutput::sPhotoSurface_ = nullptr; + +CjPhotoOutput::CjPhotoOutput() { + photoOutput_ = sPhotoOutput_; + sPhotoOutput_ = nullptr; +} + +CjPhotoOutput::~CjPhotoOutput() {} + +int32_t CjPhotoOutput::CreatePhotoOutput(Profile& profile, std::string& surfaceId) +{ + sptr photoSurface = Surface::CreateSurfaceAsConsumer("photoOutput"); + sPhotoSurface_ = photoSurface; + + if (photoSurface == nullptr) { + // MEDIA_ERR_LOG("failed to get surface"); + return CameraError::CAMERA_SERVICE_ERROR; + } + photoSurface->SetUserData(CameraManager::surfaceFormat, std::to_string(profile.GetCameraFormat())); + sptr surfaceProducer = photoSurface->GetProducer(); + // MEDIA_INFO_LOG("profile width: %{public}d, height: %{public}d, format = %{public}d, " + // "surface width: %{public}d, height: %{public}d", profile.GetSize().height, + // profile.GetSize().width, static_cast(profile.GetCameraFormat()), + // photoSurface->GetDefaultWidth(), photoSurface->GetDefaultHeight()); + int retCode = CameraManager::GetInstance()->CreatePhotoOutput(profile, surfaceProducer, &sPhotoOutput_); + + if (retCode != 0 || sPhotoOutput_ == nullptr) { + // MEDIA_ERR_LOG("failed to create CreatePhotoOutput"); + return CameraError::CAMERA_SERVICE_ERROR; + } + + if (surfaceId == "") { + sPhotoOutput_->SetNativeSurface(true); + } + if (profile.GetCameraFormat() == CAMERA_FORMAT_DNG) { + sptr rawPhotoSurface = Surface::CreateSurfaceAsConsumer("rawPhotoOutput"); + sPhotoOutput_->SetRawPhotoInfo(rawPhotoSurface); + } + + return retCode; +} + +} // namespace CameraStandard +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/cj/src/output/preview_output_impl.cpp b/frameworks/cj/src/output/preview_output_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7a8fa382c0ce2078b36feaac69c559d38f859d9a --- /dev/null +++ b/frameworks/cj/src/output/preview_output_impl.cpp @@ -0,0 +1,61 @@ +/* + * 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 "output/preview_output_impl.h" +#include "surface_utils.h" +#include "camera_error.h" +#include "camera_manager.h" + +namespace OHOS { +namespace CameraStandard { + +thread_local sptr CjPreviewOutput::sPreviewOutput_ = nullptr; + +CjPreviewOutput::CjPreviewOutput() { + previewOutput_ = sPreviewOutput_; + sPreviewOutput_ = nullptr; +} + +CjPreviewOutput::~CjPreviewOutput() {} + +sptr CjPreviewOutput::GetSurfaceBySurfaceId(std::string& surfaceId) +{ + uint64_t iSurfaceId = std::stoull(surfaceId); + return SurfaceUtils::GetInstance()->GetSurface(iSurfaceId); +} + +int32_t CjPreviewOutput::CreatePreviewOutput(Profile& profile, std::string& surfaceId) // return errCode +{ + sptr surface = GetSurfaceBySurfaceId(surfaceId); + // if (!surface) { + // surface = Media::ImageReceiver::getSurfaceById(surfaceId); + // } + if (surface == nullptr) { + // MEDIA_ERR_LOG("failed to get surface"); + return CameraError::CAMERA_SERVICE_ERROR; + } + + surface->SetUserData(CameraManager::surfaceFormat, std::to_string(profile.GetCameraFormat())); + int retCode = CameraManager::GetInstance()->CreatePreviewOutput(profile, surface, &sPreviewOutput_); + if (sPreviewOutput_ == nullptr) { + // MEDIA_ERR_LOG("failed to create previewOutput"); + return CameraError::CAMERA_SERVICE_ERROR; + } + + return retCode; +} + +} // namespace CameraStandard +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/cj/src/output/video_output_impl.cpp b/frameworks/cj/src/output/video_output_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8a80b5915cfa13ad6565b619e09ce759a2520800 --- /dev/null +++ b/frameworks/cj/src/output/video_output_impl.cpp @@ -0,0 +1,56 @@ +/* + * 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 "output/video_output_impl.h" +#include "surface_utils.h" +#include "camera_error.h" +#include "camera_manager.h" + +namespace OHOS { +namespace CameraStandard { + +thread_local sptr CjVideoOutput::sVideoOutput_ = nullptr; + +CjVideoOutput::CjVideoOutput() { + videoOutput_ = sVideoOutput_; + sVideoOutput_ = nullptr; +} + +CjVideoOutput::~CjVideoOutput() {} + +int32_t CjVideoOutput::CreateVideoOutput(VideoProfile& profile, std::string& surfaceId) // return errCode +{ + uint64_t iSurfaceId; + std::istringstream iss(surfaceId); + iss >> iSurfaceId; + sptr surface = SurfaceUtils::GetInstance()->GetSurface(iSurfaceId); + if (surface == nullptr) { + // MEDIA_ERR_LOG("failed to get surface from SurfaceUtils"); + return CameraError::CAMERA_SERVICE_ERROR; + } + + surface->SetUserData(CameraManager::surfaceFormat, std::to_string(profile.GetCameraFormat())); + int retCode = CameraManager::GetInstance()->CreateVideoOutput(profile, surface, &sVideoOutput_); + + if (sVideoOutput_ == nullptr) { + // MEDIA_ERR_LOG("failed to create VideoOutput"); + return CameraError::CAMERA_SERVICE_ERROR; + } + + return retCode; +} + +} // namespace CameraStandard +} // namespace OHOS \ No newline at end of file