diff --git a/foundation/multimedia/camera_framework/bundle.json b/foundation/multimedia/camera_framework/bundle.json new file mode 100644 index 0000000000000000000000000000000000000000..a96884307c6004aa3135d311513b0bf5d034ccd2 --- /dev/null +++ b/foundation/multimedia/camera_framework/bundle.json @@ -0,0 +1,159 @@ +{ + "name": "@ohos/camera_framework", + "description": "Camera standard provides managers and provides the camera resources to application to capture photo/preview/videos", + "version": "3.1", + "license": "Apache License 2.0", + "publishAs": "code-segment", + "segment": { + "destPath": "foundation/multimedia/camera_framework" + }, + "dirs": {}, + "scripts": {}, + "component": { + "name": "camera_framework", + "subsystem": "multimedia", + "syscap": ["SystemCapability.Multimedia.Camera.Core"], + "features": [], + "adapted_system_type": [ "standard" ], + "rom": "", + "ram": "", + "hisysevent_config": [ "//foundation/multimedia/camera_framework/hisysevent.yaml" ], + "deps": { + "components": [ + "ability_base", + "ability_runtime", + "access_token", + "ace_engine", + "audio_framework", + "av_codec", + "bundle_framework", + "c_utils", + "common_event_service", + "data_share", + "device_manager", + "drivers_interface_camera", + "drivers_interface_display", + "graphic_2d", + "graphic_surface", + "hdf_core", + "hicollie", + "hilog", + "hisysevent", + "hitrace", + "init", + "ipc", + "image_framework", + "media_foundation", + "media_library", + "napi", + "os_account", + "player_framework", + "safwk", + "samgr", + "sensor", + "thermal_manager", + "window_manager", + "memmgr" + ], + "third_party": [ + ] + }, + "build": { + "group_type": { + "base_group": [], + "fwk_group": [ + "//foundation/multimedia/camera_framework/frameworks/native/camera:camera_framework", + "//foundation/multimedia/camera_framework/frameworks/native/ndk:ohcamera", + "//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/frameworks/cj/camera_cj:cj_camera_ffi" + ], + "service_group": [ + "//foundation/multimedia/camera_framework/sa_profile:camera_service_sa_profile", + "//foundation/multimedia/camera_framework/services/etc:camera_service.rc", + "//foundation/multimedia/camera_framework/services/camera_service:camera_service", + "//foundation/multimedia/camera_framework/services/deferred_processing_service:deferred_processing_service" + ] + }, + + "inner_kits": [ + { + "type": "none", + "name": "//foundation/multimedia/camera_framework/frameworks/native/camera:camera_framework", + "header": { + "header_base": [ + "//foundation/multimedia/camera_framework/interfaces/inner_api/native/camera/include/input", + "//foundation/multimedia/camera_framework/interfaces/inner_api/native/camera/include/output", + "//foundation/multimedia/camera_framework/interfaces/inner_api/native/camera/include/session", + "//foundation/multimedia/camera_framework/interfaces/inner_api/native/camera/include/deferred_proc_session", + "//foundation/multimedia/camera_framework/interfaces/inner_api/native/camera/include/utils" + ], + "header_files": [ + "camera_info.h", + "camera_input.h", + "camera_manager.h", + "capture_input.h", + "capture_output.h", + "metadata_output.h", + "photo_output.h", + "preview_output.h", + "video_output.h", + "capture_session.h", + "deferred_photo_proc_session.h", + "dps_metadata_info.h" + ] + } + }, + { + "type": "none", + "name": "//foundation/multimedia/camera_framework/interfaces/kits/js/camera_napi:camera_napi", + "header": { + "header_base": [ + "//foundation/multimedia/camera_framework/interfaces/kits/js/camera_napi/include", + "//foundation/multimedia/camera_framework/interfaces/kits/js/camera_napi/include/input", + "//foundation/multimedia/camera_framework/interfaces/kits/js/camera_napi/include/output", + "//foundation/multimedia/camera_framework/interfaces/kits/js/camera_napi/include/session" + ], + "header_files": [ + "camera_input_napi.h", + "camera_manager_napi.h", + "camera_napi.h", + "photo_output_napi.h", + "preview_output_napi.h", + "video_output_napi.h", + "camera_session_napi.h", + "camera_napi_utils.h", + "native_module_ohos_camera.h", + "listener_base.h", + "metadata_output_napi.h" + ] + } + }, + { + "type": "none", + "name": "//foundation/multimedia/camera_framework/interfaces/kits/js/camera_napi:camerapicker_napi", + "header": { + "header_base": [ + "//foundation/multimedia/camera_framework/interfaces/kits/js/camera_napi/include", + "//foundation/multimedia/camera_framework/interfaces/kits/js/camera_napi/include/picker" + ], + "header_files": [ + "camera_picker_napi.h" + ] + } + } + ], + "test": [ + "//foundation/multimedia/camera_framework/interfaces/inner_api/native/test:camera_video", + "//foundation/multimedia/camera_framework/interfaces/inner_api/native/test:camera_capture", + "//foundation/multimedia/camera_framework/interfaces/inner_api/native/test:camera_capture_video", + "//foundation/multimedia/camera_framework/frameworks/native/camera/test/moduletest:camera_framework_moduletest", + "//foundation/multimedia/camera_framework/frameworks/native/camera/test/unittest:camera_framework_unittest_v1_1", + "//foundation/multimedia/camera_framework/frameworks/native/camera/test/unittest:camera_ndk_unittest_v1_1", + "//foundation/multimedia/camera_framework/test:camera_fuzz_test" + ] + } + } +} diff --git a/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/BUILD.gn b/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..156589cfcc71547e1dc2243aec81f88b1249c89a --- /dev/null +++ b/foundation/multimedia/camera_framework/frameworks/cj/camera_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 = [ + "${multimedia_camera_framework_path}/frameworks/cj/camera_cj/include", + "${multimedia_camera_framework_path}/frameworks/cj/camera_cj/include/session", + "${multimedia_camera_framework_path}/frameworks/cj/camera_cj/include/picker", + "${multimedia_camera_framework_path}/frameworks/cj/camera_cj" + ] +} + +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 = [ + "ability_base:base", + "ability_base:configuration", # configuration.h + "ability_base:want", + "ability_runtime:ability_context_native", # ability_context.h + "ability_runtime:ability_manager", # pixel_map.h + "ability_runtime:napi_base_context", # napi_base_context.h + "ace_engine:ace_uicontent", + "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/session/camera_session_ffi.cpp", + "src/session/camera_session_impl.cpp", + "src/picker/camera_picker_ffi.cpp", + "src/picker/camera_picker_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/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/include/listener_base.h b/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/include/listener_base.h new file mode 100644 index 0000000000000000000000000000000000000000..8b9736090aad7522ee8ba5a470479e6772c74d3a --- /dev/null +++ b/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/include/listener_base.h @@ -0,0 +1,52 @@ +/* + * 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_CJ_H +#define LISTENER_BASE_CJ_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/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/include/picker/camera_picker_ffi.h b/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/include/picker/camera_picker_ffi.h new file mode 100644 index 0000000000000000000000000000000000000000..9b9680a0c3b45256707ae2345375412fcda60c3a --- /dev/null +++ b/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/include/picker/camera_picker_ffi.h @@ -0,0 +1,32 @@ +#ifndef CAMERA_PICKER_FFI_H +#define CAMERA_PICKER_FFI_H + +#include +#include +#include +#include +#include + +#include "ffi_remote_data.h" +#include "cj_common_ffi.h" +#include "camera_log.h" +#include "camera_picker_impl.h" + + +namespace OHOS { +namespace CameraStandard { + +struct CPickerResult +{ + int32_t resultCode; + const char* resultUri; + int32_t mediaType; +}; + +extern "C" { + FFI_EXPORT CPickerResult FfiOHOSCameraPickerPick(int64_t id, OHOS::AbilityRuntime::Context *context, CArrString pickerMediaTypes, OHOS::CameraStandard::PickerProfile pickerProfile); +} + +} +} +#endif \ No newline at end of file diff --git a/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/include/picker/camera_picker_impl.h b/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/include/picker/camera_picker_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..d0b77a60ef419fdd335b899e2af29d0fe7e3c7c2 --- /dev/null +++ b/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/include/picker/camera_picker_impl.h @@ -0,0 +1,113 @@ +#ifndef CAMERA_PICKER_H +#define CAMERA_PICKER_H + +#include +#include +#include +#include +#include +#include + +#include "ffi_remote_data.h" +#include "camera_log.h" +#include "ui_content.h" +#include "ability_context.h" +#include "camera_device.h" +#include "cj_common_ffi.h" + +namespace OHOS { +namespace CameraStandard { + +enum PickerMediaType +{ + PHOTO = 0, + VIDEO +}; + +struct PickerResult +{ + int32_t resultCode; + std::string resultUri; + PickerMediaType mediaType; +}; + +struct PickerProfile +{ + std::string saveUri; + CameraPosition cameraPosition; + int64_t videoDuration; +}; + +class CameraPickerImpl: public OHOS::FFI::FFIData { + DECL_TYPE(CameraPicker, OHOS::FFI::FFIData) +public: + explicit CameraPickerImpl() = default; + explicit CameraPickerImpl(int64_t id); + ~CameraPickerImpl() override; + + PickerResult Pick(OHOS::AbilityRuntime::Context *context, CArrString pickerMediaTypes, PickerProfile pickerProfile); + +private: + int64_t cameraId = -1; +}; + +class UIExtensionCallback { +public: + explicit UIExtensionCallback(std::shared_ptr abilityContext); + void SetSessionId(int32_t sessionId); + void OnRelease(int32_t releaseCode); + void OnResult(int32_t resultCode, const OHOS::AAFwk::Want& result); + void OnReceive(const OHOS::AAFwk::WantParams& request); + void OnError(int32_t code, const std::string& name, const std::string& message); + void OnRemoteReady(const std::shared_ptr& uiProxy); + void OnDestroy(); + void SendMessageBack(); + + inline void WaitResultLock() + { + std::unique_lock lock(cbMutex_); + while (!isCallbackReturned_) { + cbFinishCondition_.wait(lock); + } + } + + inline void NotifyResultLock() + { + std::unique_lock lock(cbMutex_); + cbFinishCondition_.notify_one(); + } + + inline int32_t GetResultCode() + { + return resultCode_; + } + + inline std::string GetResultUri() + { + return resultUri_; + } + + inline int32_t GetResultMediaType() + { + if (resultMode_ == "VIDEO") { + return 1; + } + return 0; + } + +private: + bool SetErrorCode(int32_t code); + int32_t sessionId_ = 0; + int32_t resultCode_ = 0; + std::string resultUri_ = ""; + std::string resultMode_ = ""; + std::weak_ptr abilityContext_; + std::condition_variable cbFinishCondition_; + std::mutex cbMutex_; + bool isCallbackReturned_ = false; +}; + +} +} + +#endif \ No newline at end of file diff --git a/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/include/session/camera_session_ffi.h b/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/include/session/camera_session_ffi.h new file mode 100644 index 0000000000000000000000000000000000000000..1c2fb4b8a8cb9edf8a5a116381309105968ef3ed --- /dev/null +++ b/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/include/session/camera_session_ffi.h @@ -0,0 +1,35 @@ +#ifndef CAMERA_SESSION_FFI_H +#define CAMERA_SESSION_FFI_H + +#include +#include +#include +#include +#include + +#include "ffi_remote_data.h" +#include "cj_common_ffi.h" +#include "camera_log.h" +#include "session/capture_session.h" + +namespace OHOS { +namespace CameraStandard { + +extern "C" { + FFI_EXPORT bool FfiOHOSCameraSessionIsVideoStabilizationModeSupported(int64_t id, int32_t videoStabilizationMode, int32_t *errCode); + FFI_EXPORT int32_t FfiOHOSCameraSessionGetActiveVideoStabilizationMode(int64_t id, int32_t *errCode); + FFI_EXPORT int32_t FfiOHOSCameraSessionSetVideoStabilizationMode(int64_t id, int32_t videoStabilizationMode); + FFI_EXPORT int32_t FfiOHOSVideoSessionOnError(int64_t id, void (*callbackRef)(int32_t)); + FFI_EXPORT int32_t FfiOHOSVideoSessionOffError(int64_t id, void (*callbackRef)(int32_t)); + FFI_EXPORT int32_t FfiOHOSVideoSessionOffAllError(int64_t id); + FFI_EXPORT int32_t FfiOHOSVideoSessionOnFocusStateChange(int64_t id, void (*callbackRef)(int32_t)); + FFI_EXPORT int32_t FfiOHOSVideoSessionOffFocusStateChange(int64_t id, void (*callbackRef)(int32_t)); + FFI_EXPORT int32_t FfiOHOSVideoSessionOffAllFocusStateChange(int64_t id); + FFI_EXPORT int32_t FfiOHOSVideoSessionOnSmoothZoomInfoAvailable(int64_t id, void (*callbackRef)(int32_t)); + FFI_EXPORT int32_t FfiOHOSVideoSessionOffSmoothZoomInfoAvailable(int64_t id, void (*callbackRef)(int32_t)); + FFI_EXPORT int32_t FfiOHOSVideoSessionOffAllSmoothZoomInfoAvailable(int64_t id); +} + +} +} +#endif \ No newline at end of file diff --git a/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/include/session/camera_session_impl.h b/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/include/session/camera_session_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..614dabac7e52b4c870e486bbbdade1a0a9030ddb --- /dev/null +++ b/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/include/session/camera_session_impl.h @@ -0,0 +1,76 @@ +#ifndef CAMERA_SESSION_H +#define CAMERA_SESSION_H + +#include +#include +#include +#include +#include + +#include "session/capture_session.h" +#include "ffi_remote_data.h" +#include "camera_log.h" +#include "listener_base.h" +#include "cj_lambda.h" + +namespace OHOS { +namespace CameraStandard { + +class SessionCallbackListener: public SessionCallback, + public ListenerBase { +public: + void OnError(int32_t errorType) override; +}; + +class FocusCallbackListener: public FocusCallback, public ListenerBase { +public: + void OnFocusState(FocusState state) override; +}; + +class SmoothCallbackListener: public SmoothZoomCallback, public ListenerBase { +public: + void OnSmoothZoom(int32_t duration) override; +}; + +class CameraSessionImpl: public OHOS::FFI::FFIData { + DECL_TYPE(CameraSessionImpl, OHOS::FFI::FFIData) +public: + explicit CameraSessionImpl() = default; + explicit CameraSessionImpl(int64_t id); + ~CameraSessionImpl() override; + + int32_t IsVideoStabilizationModeSupported(VideoStabilizationMode vsMode, bool isSupported); + VideoStabilizationMode GetActiveVideoStabilizationMode(); + int32_t SetVideoStabilizationMode(VideoStabilizationMode vsMode); + void OnError(void (*callbackRef)(int32_t)); + void OffError(void (*callbackRef)(int32_t)); + void OffAllError(); + void OnFocusState(void (*callbackRef)(int32_t)); + void OffFocusState(void (*callbackRef)(int32_t)); + void OffAllFocusState(); + void OnSmoothZoom(void (*callbackRef)(int32_t)); + void OffSmoothZoom(void (*callbackRef)(int32_t)); + void OffAllSmoothZoom(); + +private: + sptr captureSession_ = nullptr; + int64_t cameraId = -1; + std::shared_ptr sessionCallback_; + std::shared_ptr focusCallback_; + std::shared_ptr smoothCallback_; + void RegisterSessionCallbackListener(void (*callback)(int32_t)); + void UnregisterSessionCallbackListener(void (*callback)(int32_t)); + void UnregisterAllSessionCallbackListener(); + void RegisterFocusCallbackListener(void (*callback)(int32_t)); + void UnregisterFocusCallbackListener(void (*callback)(int32_t)); + void UnregisterAllFocusCallbackListener(); + void RegisterSmoothCallbackListener(void (*callback)(int32_t)); + void UnregisterSmoothCallbackListener(void (*callback)(int32_t)); + void UnregisterAllSmoothCallbackListener(); +}; + + +} +} + +#endif \ No newline at end of file diff --git a/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/src/listener_base.tpp b/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/src/listener_base.tpp new file mode 100644 index 0000000000000000000000000000000000000000..8bd75a7ebcb81600cc875c4bed26fc17eb5ac3f1 --- /dev/null +++ b/foundation/multimedia/camera_framework/frameworks/cj/camera_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/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/src/picker/camera_picker_ffi.cpp b/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/src/picker/camera_picker_ffi.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1115b8e29c3991c75c5d18dc1fcb4a1635272a33 --- /dev/null +++ b/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/src/picker/camera_picker_ffi.cpp @@ -0,0 +1,28 @@ +#include "camera_picker_ffi.h" +#include "camera_error_code.h" + +using namespace OHOS::FFI; + +namespace OHOS { +namespace CameraStandard { + +extern "C" { + + CPickerResult FfiOHOSCameraPickerPick(int64_t id, OHOS::AbilityRuntime::Context *context, CArrString pickerMediaTypes, PickerProfile pickerProfile) + { + CPickerResult res = {.resultCode = -1, .resultUri = nullptr, .mediaType = 0}; + auto nativeCameraPicker = FFIData::Create(id); + if (nativeCameraPicker == nullptr) { + MEDIA_ERR_LOG("new camera picker failed"); + return res; + } + PickerResult pickerResult = nativeCameraPicker->Pick(context, pickerMediaTypes, pickerProfile); + res.resultCode = pickerResult.resultCode; + res.resultUri = pickerResult.resultUri.c_str(); + res.mediaType = pickerResult.mediaType; + return res; + } +} + +} +} \ No newline at end of file diff --git a/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/src/picker/camera_picker_impl.cpp b/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/src/picker/camera_picker_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d792b55b7182c839fcbb62ed1ce6e81993440276 --- /dev/null +++ b/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/src/picker/camera_picker_impl.cpp @@ -0,0 +1,138 @@ +#include "camera_picker_impl.h" +#include "bool_wrapper.h" +#include "int_wrapper.h" +#include "string_wrapper.h" + +namespace OHOS::CameraStandard { + constexpr char CAMERA_PICKER_ABILITY_ACTION_PHOTO[] = "ohos.want.action.imageCapture"; + constexpr char CAMERA_PICKER_ABILITY_ACTION_VIDEO[] = "ohos.want.action.videoCapture"; + + using namespace std; + CameraPickerImpl::CameraPickerImpl(int64_t id) : cameraId(id){ + MEDIA_ERR_LOG("Id is %{public}lld", this->cameraId); + } + + CameraPickerImpl::~CameraPickerImpl(){} + + struct AsyncContext { + bool status; + int32_t taskId; + int32_t errorCode; + std::string errorMsg; + std::string funcName; + bool isInvalidArgument; + }; + + struct CameraPickerAsyncContext : public AsyncContext { + std::string resultUri; + std::string errorMsg; + PickerProfile pickerProfile; + AAFwk::Want want; + std::shared_ptr abilityContext; + std::shared_ptr uiExtCallback; + int32_t resultCode; + bool bRetBool; + }; + + static vector CArrStringToVector(const CArrString& cArr) + { + vector ret; + for(int64_t i = 0; i < cArr.size; i++) { + ret.emplace_back(string(cArr.head[i])); + } + return ret; + } + + static void SetPickerWantParams(AAFwk::Want& want, std::shared_ptr& abilityContext, + const vector& mediaTypes, PickerProfile& pickerProfile) + { + MEDIA_DEBUG_LOG("SetPickerWantParams enter"); + AAFwk::WantParams wantParam; + bool isPhotoType = false; + bool isVideoType = false; + for (auto type : mediaTypes) { + MEDIA_INFO_LOG("SetPickerWantParams current type is:%{public}s", type.c_str()); + if(type.compare(std::string("PHOTO")) == 0) isPhotoType = true; + else if(type.compare(std::string("VIDEO")) == 0) isVideoType = true; + } + + want.SetUri(pickerProfile.saveUri); + want.SetFlags(AAFwk::Want::FLAG_AUTH_READ_URI_PERMISSION | AAFwk::Want::FLAG_AUTH_WRITE_URI_PERMISSION); + wantParam.SetParam("ability.want.params.uiExtensionTargetType", AAFwk::String::Box("cameraPicker")); + wantParam.SetParam("callBundleName", AAFwk::String::Box(abilityContext->GetAbilityInfo()->bundleName.c_str())); + wantParam.SetParam("cameraPosition", AAFwk::Integer::Box(pickerProfile.cameraPosition)); + wantParam.SetParam("videoDuration", AAFwk::Integer::Box(pickerProfile.videoDuration)); + wantParam.SetParam("saveUri", AAFwk::String::Box(pickerProfile.saveUri.c_str())); + if (isPhotoType && isVideoType) { + wantParam.SetParam("supportMultiMode", AAFwk::Boolean::Box(true)); + } + want.SetParams(wantParam); + if (isPhotoType) { + want.SetAction(CAMERA_PICKER_ABILITY_ACTION_PHOTO); + } else if (isVideoType) { + want.SetAction(CAMERA_PICKER_ABILITY_ACTION_VIDEO); + } else { + MEDIA_ERR_LOG("SetPickerWantParams set action fail!"); + } + MEDIA_DEBUG_LOG("SetPickerWantParams end"); + } + + static std::shared_ptr StartCameraAbility(std::shared_ptr abilityContext, AAFwk::Want& want) + { + auto uiExtCallback = std::make_shared(abilityContext); + OHOS::Ace::ModalUIExtensionCallbacks extensionCallbacks = { + std::bind(&UIExtensionCallback::OnRelease, uiExtCallback, std::placeholders::_1), + std::bind(&UIExtensionCallback::OnResult, uiExtCallback, std::placeholders::_1, std::placeholders::_2), + std::bind(&UIExtensionCallback::OnReceive, uiExtCallback, std::placeholders::_1), + std::bind(&UIExtensionCallback::OnError, uiExtCallback, std::placeholders::_1, std::placeholders::_2, + std::placeholders::_3), + std::bind(&UIExtensionCallback::OnRemoteReady, uiExtCallback, std::placeholders::_1), + std::bind(&UIExtensionCallback::OnDestroy, uiExtCallback) + }; + Ace::ModalUIExtensionConfig config; + auto uiContent = abilityContext->GetUIContent(); + if (uiContent == nullptr) { + MEDIA_ERR_LOG("StartCameraAbility fail uiContent is null"); + return nullptr; + } + int32_t sessionId = uiContent->CreateModalUIExtension(want, extensionCallbacks, config); + MEDIA_DEBUG_LOG("StartCameraAbility CreateModalUIExtension session id is %{public}d", sessionId); + if (sessionId == 0) { + MEDIA_ERR_LOG("StartCameraAbility CreateModalUIExtension fail"); + return nullptr; + } + uiExtCallback->SetSessionId(sessionId); + return uiExtCallback; + } + + PickerResult CameraPickerImpl::Pick(OHOS::AbilityRuntime::Context *context, CArrString pickerMediaTypes, PickerProfile pickerProfile) + { + PickerResult res = {.resultCode = -1, .resultUri = nullptr, .mediaType = PHOTO}; + MEDIA_INFO_LOG("CameraPicker::Pick is called"); + //context + std::unique_ptr asyncCtx = std::make_unique(); + auto contextSharedPtr = context->shared_from_this(); + asyncCtx->abilityContext = AbilityRuntime::Context::ConvertTo(contextSharedPtr); + if (asyncCtx->abilityContext == nullptr) { + MEDIA_ERR_LOG("GetAbilityContext failed"); + return res; + } + MEDIA_DEBUG_LOG("CameraPickerNapi GetAbilityContext success"); + //mediaType + auto mediaTypes = CArrStringToVector(pickerMediaTypes); + asyncCtx->pickerProfile.cameraPosition = static_cast(pickerProfile.cameraPosition); + asyncCtx->pickerProfile.videoDuration = pickerProfile.videoDuration; + asyncCtx->pickerProfile.saveUri = std::string(pickerProfile.saveUri); + SetPickerWantParams(asyncCtx->want, asyncCtx->abilityContext, mediaTypes, asyncCtx->pickerProfile); + asyncCtx->uiExtCallback = StartCameraAbility(asyncCtx->abilityContext, asyncCtx->want); + if (asyncCtx->uiExtCallback == nullptr) { + MEDIA_ERR_LOG("StartCameraAbility failed"); + return res; + } + res.resultCode = asyncCtx->uiExtCallback->GetResultCode(); + res.resultUri = asyncCtx->uiExtCallback->GetResultUri(); + res.mediaType = static_cast(asyncCtx->uiExtCallback->GetResultMediaType()); + return res; + } + +} \ No newline at end of file diff --git a/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/src/session/camera_session_ffi.cpp b/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/src/session/camera_session_ffi.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b7d1b6f0f8f0011f426ac0ec799a8353c55c657d --- /dev/null +++ b/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/src/session/camera_session_ffi.cpp @@ -0,0 +1,189 @@ +#include "camera_session_ffi.h" +#include "camera_session_impl.h" +#include "camera_error_code.h" + +using namespace OHOS::FFI; + +namespace OHOS { +namespace CameraStandard { + +extern "C" { + bool FfiOHOSCameraSessionIsVideoStabilizationModeSupported(int64_t id, int32_t videoStabilizationMode, int32_t *errCode) + { + auto nativeCameraSession = FFIData::Create(id); + if (nativeCameraSession == nullptr) { + MEDIA_ERR_LOG("new camera session failed"); + *errCode = -1; + return false; + } + bool isSupported = false; + *errCode = nativeCameraSession->IsVideoStabilizationModeSupported(VideoStabilizationMode(videoStabilizationMode), isSupported); + if(*errCode != CameraErrorCode::SUCCESS) { + MEDIA_ERR_LOG("IsVideoStabilizationModeSupported failed"); + return false; + } + MEDIA_ERR_LOG("IsVideoStabilizationModeSupported success"); + return isSupported; + }//issuported可能没有正确赋值 + + int32_t FfiOHOSCameraSessionGetActiveVideoStabilizationMode(int64_t id, int32_t *errCode) + { + auto nativeCameraSession = FFIData::Create(id); + if (nativeCameraSession == nullptr) { + MEDIA_ERR_LOG("new camera session failed"); + *errCode = -1; + return OFF; + } + auto ret = nativeCameraSession->GetActiveVideoStabilizationMode(); + *errCode = CameraErrorCode::SUCCESS; + MEDIA_ERR_LOG("GetActiveVideoStabilizationMode success"); + return ret; + } + + int32_t FfiOHOSCameraSessionSetVideoStabilizationMode(int64_t id, int32_t videoStabilizationMode) + { + int32_t ret = -1; + auto nativeCameraSession = FFIData::Create(id); + if (nativeCameraSession == nullptr) { + MEDIA_ERR_LOG("new camera session failed"); + return ret; + } + ret = nativeCameraSession->SetVideoStabilizationMode(VideoStabilizationMode(videoStabilizationMode)); + if(ret != CameraErrorCode::SUCCESS) + { + MEDIA_ERR_LOG("GetActiveVideoStabilizationMode failed"); + return ret; + } + MEDIA_ERR_LOG("GetActiveVideoStabilizationMode success"); + return ret; + } + + int32_t FfiOHOSVideoSessionOnError(int64_t id, void (*callbackRef)(int32_t)) + { + int32_t ret = -1; + auto nativeCameraSession = FFIData::Create(id); + if (nativeCameraSession == nullptr) { + MEDIA_ERR_LOG("new camera session failed"); + return ret; + } + nativeCameraSession->OnError(callbackRef); + MEDIA_ERR_LOG("OnError success"); + ret = CameraErrorCode::SUCCESS; + return ret; + } + + int32_t FfiOHOSVideoSessionOffError(int64_t id, void (*callbackRef)(int32_t)) + { + int32_t ret = -1; + auto nativeCameraSession = FFIData::Create(id); + if (nativeCameraSession == nullptr) { + MEDIA_ERR_LOG("new camera session failed"); + return ret; + } + nativeCameraSession->OffError(callbackRef); + MEDIA_ERR_LOG("OffError success"); + ret = CameraErrorCode::SUCCESS; + return ret; + } + + int32_t FfiOHOSVideoSessionOffAllError(int64_t id) + { + int32_t ret = -1; + auto nativeCameraSession = FFIData::Create(id); + if (nativeCameraSession == nullptr) { + MEDIA_ERR_LOG("new camera session failed"); + return ret; + } + nativeCameraSession->OffAllError(); + MEDIA_ERR_LOG("OffAllError success"); + ret = CameraErrorCode::SUCCESS; + return ret; + } + + int32_t FfiOHOSVideoSessionOnFocusStateChange(int64_t id, void (*callbackRef)(int32_t)) + { + int32_t ret = -1; + auto nativeCameraSession = FFIData::Create(id); + if (nativeCameraSession == nullptr) { + MEDIA_ERR_LOG("new camera session failed"); + return ret; + } + nativeCameraSession->OnFocusState(callbackRef); + MEDIA_ERR_LOG("OnFocusState success"); + ret = CameraErrorCode::SUCCESS; + return ret; + } + + int32_t FfiOHOSVideoSessionOffFocusStateChange(int64_t id, void (*callbackRef)(int32_t)) + { + int32_t ret = -1; + auto nativeCameraSession = FFIData::Create(id); + if (nativeCameraSession == nullptr) { + MEDIA_ERR_LOG("new camera session failed"); + return ret; + } + nativeCameraSession->OffFocusState(callbackRef); + MEDIA_ERR_LOG("OffFocusState success"); + ret = CameraErrorCode::SUCCESS; + return ret; + } + + int32_t FfiOHOSVideoSessionOffAllFocusStateChange(int64_t id) + { + int32_t ret = -1; + auto nativeCameraSession = FFIData::Create(id); + if (nativeCameraSession == nullptr) { + MEDIA_ERR_LOG("new camera session failed"); + return ret; + } + nativeCameraSession->OffAllFocusState(); + MEDIA_ERR_LOG("OffAllFocusState success"); + ret = CameraErrorCode::SUCCESS; + return ret; + } + + int32_t FfiOHOSVideoSessionOnSmoothZoomInfoAvailable(int64_t id, void (*callbackRef)(int32_t)) + { + int32_t ret = -1; + auto nativeCameraSession = FFIData::Create(id); + if (nativeCameraSession == nullptr) { + MEDIA_ERR_LOG("new camera session failed"); + return ret; + } + nativeCameraSession->OnSmoothZoom(callbackRef); + MEDIA_ERR_LOG("OnSmoothZoom success"); + ret = CameraErrorCode::SUCCESS; + return ret; + } + + int32_t FfiOHOSVideoSessionOffSmoothZoomInfoAvailable(int64_t id, void (*callbackRef)(int32_t)) + { + int32_t ret = -1; + auto nativeCameraSession = FFIData::Create(id); + if (nativeCameraSession == nullptr) { + MEDIA_ERR_LOG("new camera session failed"); + return ret; + } + nativeCameraSession->OffSmoothZoom(callbackRef); + MEDIA_ERR_LOG("OffSmoothZoom success"); + ret = CameraErrorCode::SUCCESS; + return ret; + } + + int32_t FfiOHOSVideoSessionOffAllSmoothZoomInfoAvailable(int64_t id) + { + int32_t ret = -1; + auto nativeCameraSession = FFIData::Create(id); + if (nativeCameraSession == nullptr) { + MEDIA_ERR_LOG("new camera session failed"); + return ret; + } + nativeCameraSession->OffAllSmoothZoom(); + MEDIA_ERR_LOG("OffAllSmoothZoom success"); + ret = CameraErrorCode::SUCCESS; + return ret; + } +} + +} +} \ No newline at end of file diff --git a/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/src/session/camera_session_impl.cpp b/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/src/session/camera_session_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7be6176f94e5ee04dc91f6f12e3bdef82be5ccdf --- /dev/null +++ b/foundation/multimedia/camera_framework/frameworks/cj/camera_cj/src/session/camera_session_impl.cpp @@ -0,0 +1,158 @@ +#include "camera_session_impl.h" + + +namespace OHOS::CameraStandard { + CameraSessionImpl::CameraSessionImpl(int64_t id) : cameraId(id){ + MEDIA_ERR_LOG("Id is %{public}lld", this->cameraId); + } + + CameraSessionImpl::~CameraSessionImpl(){} + + int32_t CameraSessionImpl::IsVideoStabilizationModeSupported(VideoStabilizationMode vsMode, bool isSupported) + { + return captureSession_->IsVideoStabilizationModeSupported(vsMode, isSupported); + } + + VideoStabilizationMode CameraSessionImpl::GetActiveVideoStabilizationMode() { + return captureSession_->GetActiveVideoStabilizationMode(); + } + + int32_t CameraSessionImpl::SetVideoStabilizationMode(VideoStabilizationMode vsMode) { + return captureSession_->SetVideoStabilizationMode(vsMode); + } + + void SessionCallbackListener::OnError(const int32_t errorType) + { + ExecuteCallback(errorType); + } + + void CameraSessionImpl::OnError(void (*callbackRef)(int32_t)) + { + RegisterSessionCallbackListener(callbackRef); + } + + void CameraSessionImpl::OffError(void (*callbackRef)(int32_t)) + { + UnregisterSessionCallbackListener(callbackRef); + } + + void CameraSessionImpl::OffAllError() + { + UnregisterAllSessionCallbackListener(); + } + + void CameraSessionImpl::RegisterSessionCallbackListener(void (*callback)(int32_t)) + { + if (sessionCallback_ == nullptr) { + sessionCallback_ = make_shared(); + captureSession_->SetCallback(sessionCallback_); + } + sessionCallback_->SaveCallbackRef(std::make_shared>(CJLambda::Create(callback))); + } + + void CameraSessionImpl::UnregisterSessionCallbackListener(void (*callback)(int32_t)) + { + if (sessionCallback_ == nullptr) { + return; + } + sessionCallback_->RemoveCallbackRef(std::make_shared>(CJLambda::Create(callback))); + } + + void CameraSessionImpl::UnregisterAllSessionCallbackListener() + { + if (sessionCallback_ == nullptr) { + return; + } + sessionCallback_->RemoveAllCallbackRef(); + } + + void FocusCallbackListener::OnFocusState(const FocusState state) + { + ExecuteCallback(static_cast(state)); + } + + void CameraSessionImpl::OnFocusState(void (*callbackRef)(int32_t)) + { + RegisterFocusCallbackListener(callbackRef); + } + + void CameraSessionImpl::OffFocusState(void (*callbackRef)(int32_t)) + { + UnregisterFocusCallbackListener(callbackRef); + } + + void CameraSessionImpl::OffAllFocusState() + { + UnregisterAllFocusCallbackListener(); + } + + void CameraSessionImpl::RegisterFocusCallbackListener(void (*callback)(int32_t)) + { + if (focusCallback_ == nullptr) { + focusCallback_ = make_shared(); + captureSession_->SetFocusCallback(focusCallback_); + } + focusCallback_->SaveCallbackRef(std::make_shared>(CJLambda::Create(callback))); + } + + void CameraSessionImpl::UnregisterFocusCallbackListener(void (*callback)(int32_t)) + { + if (focusCallback_ == nullptr) { + return; + } + focusCallback_->RemoveCallbackRef(std::make_shared>(CJLambda::Create(callback))); + } + + void CameraSessionImpl::UnregisterAllFocusCallbackListener() + { + if (focusCallback_ == nullptr) { + return; + } + focusCallback_->RemoveAllCallbackRef(); + } + + void SmoothCallbackListener::OnSmoothZoom(const int32_t duration) + { + ExecuteCallback(duration); + } + + void CameraSessionImpl::OnSmoothZoom(void (*callbackRef)(int32_t)) + { + RegisterFocusCallbackListener(callbackRef); + } + + void CameraSessionImpl::OffSmoothZoom(void (*callbackRef)(int32_t)) + { + UnregisterSmoothCallbackListener(callbackRef); + } + + void CameraSessionImpl::OffAllSmoothZoom() + { + UnregisterAllSmoothCallbackListener(); + } + + void CameraSessionImpl::RegisterSmoothCallbackListener(void (*callback)(int32_t)) + { + if (smoothCallback_ == nullptr) { + smoothCallback_ = make_shared(); + captureSession_->SetSmoothZoomCallback(smoothCallback_); + } + smoothCallback_->SaveCallbackRef(std::make_shared>(CJLambda::Create(callback))); + } + + void CameraSessionImpl::UnregisterSmoothCallbackListener(void (*callback)(int32_t)) + { + if (smoothCallback_ == nullptr) { + return; + } + smoothCallback_->RemoveCallbackRef(std::make_shared>(CJLambda::Create(callback))); + } + + void CameraSessionImpl::UnregisterAllSmoothCallbackListener() + { + if (smoothCallback_ == nullptr) { + return; + } + smoothCallback_->RemoveAllCallbackRef(); + } +} \ No newline at end of file