diff --git a/frameworks/js/camera_napi/demo/entry/src/main/ets/model/CameraService.ts b/frameworks/js/camera_napi/demo/entry/src/main/ets/model/CameraService.ts index 3d17774ddd4872f884e5c2c2dd9742d1b00c2934..b7bd95f254db0277a7daea8ab88e9d6cd6dc00be 100644 --- a/frameworks/js/camera_napi/demo/entry/src/main/ets/model/CameraService.ts +++ b/frameworks/js/camera_napi/demo/entry/src/main/ets/model/CameraService.ts @@ -40,7 +40,8 @@ enum CameraMode { NORMAL = 0, VIDEO, PORTRAIT, - SUPER_STAB + SUPER_STAB, + NIGHT } const TAG: string = 'CameraService'; @@ -56,6 +57,7 @@ class CameraService { private photoOutPut: camera.PhotoOutput | undefined = undefined; private captureSession: camera.CaptureSession | undefined = undefined; private portraitSession: camera.PortraitPhotoSession | undefined = undefined; + private nightSession: camera.NightPhotoSession | undefined = undefined; private mReceiver: image.ImageReceiver | undefined = undefined; private fileAsset: photoAccessHelper.PhotoAsset | undefined = undefined; private fd: number = -1; @@ -263,6 +265,20 @@ class CameraService { Logger.error('videoProfileObj not supported'); } break; + case CameraMode.NIGHT: + previewProfileObj = previewProfiles.find((profile: camera.Profile) => { + return profile.size.height === this.defaultProfile.size.height && + profile.size.width === this.defaultProfile.size.width; + }); + Logger.info(`previewProfileObj: ${JSON.stringify(previewProfileObj)}`); + this.previewProfileObj = previewProfileObj; + photoProfileObj = photoProfiles.find((profile: camera.Profile) => { + return profile.size.height === this.defaultProfile.size.height && + profile.size.width === this.defaultProfile.size.width; + }); + Logger.info(`photoProfileObj: ${JSON.stringify(photoProfileObj)}`); + this.photoProfileObj = photoProfileObj; + break; case CameraMode.NORMAL: case CameraMode.VIDEO: default: @@ -358,12 +374,12 @@ class CameraService { await this.releaseCamera(); // 获取相机管理器实例 this.getCameraManagerFn(); - if (this.cameraMode === CameraMode.PORTRAIT) { + if (this.cameraMode === CameraMode.PORTRAIT || this.cameraMode === CameraMode.NIGHT) { this.getModeManagerFn(); } // 获取支持指定的相机设备对象 this.getSupportedCamerasFn(); - if (this.cameraMode === CameraMode.PORTRAIT) { + if (this.cameraMode === CameraMode.PORTRAIT || this.cameraMode === CameraMode.NIGHT) { this.getSupportedModeFn(cameraDeviceIndex); } this.initProfile(cameraDeviceIndex); @@ -393,6 +409,8 @@ class CameraService { // 会话流程 if (this.cameraMode === CameraMode.PORTRAIT) { await this.portraitSessionFlowFn(); + } else if (this.cameraMode === CameraMode.NIGHT) { + await this.nightSessionFlowFn(); } else { await this.sessionFlowFn(); } @@ -419,7 +437,7 @@ class CameraService { isExposureModeSupportedFn(aeMode: camera.ExposureMode): boolean { // 检测曝光模式是否支持 let isSupported: boolean = false; - let session: camera.PortraitPhotoSession | camera.CaptureSession = this.getSession(); + let session: camera.PortraitPhotoSession | camera.CaptureSession | camera.NightPhotoSession = this.getSession(); if (!session) { return isSupported; } @@ -429,7 +447,7 @@ class CameraService { } setExposureMode(aeMode: camera.ExposureMode): void { - let session: camera.PortraitPhotoSession | camera.CaptureSession = this.getSession(); + let session: camera.PortraitPhotoSession | camera.CaptureSession | camera.NightPhotoSession = this.getSession(); if (!session) { return; } @@ -444,7 +462,7 @@ class CameraService { */ isMeteringPoint(point: camera.Point): void { // 获取当前曝光模式 - let session: camera.PortraitPhotoSession | camera.CaptureSession = this.getSession(); + let session: camera.PortraitPhotoSession | camera.CaptureSession | camera.NightPhotoSession = this.getSession(); if (!session) { return; } @@ -463,7 +481,7 @@ class CameraService { isExposureBiasRange(exposureBias: number): void { Logger.debug(TAG, `setExposureBias value ${exposureBias}`); // 查询曝光补偿范围 - let session: camera.PortraitPhotoSession | camera.CaptureSession = this.getSession(); + let session: camera.PortraitPhotoSession | camera.CaptureSession | camera.NightPhotoSession = this.getSession(); if (!session) { return; } @@ -478,7 +496,7 @@ class CameraService { * 是否支持对应对焦模式 */ isFocusModeSupported(focusMode: camera.FocusMode): boolean { - let session: camera.PortraitPhotoSession | camera.CaptureSession = this.getSession(); + let session: camera.PortraitPhotoSession | camera.CaptureSession | camera.NightPhotoSession = this.getSession(); if (!session) { return false; } @@ -496,7 +514,7 @@ class CameraService { if (!isSupported) { return; } - let session: camera.PortraitPhotoSession | camera.CaptureSession = this.getSession(); + let session: camera.PortraitPhotoSession | camera.CaptureSession | camera.NightPhotoSession = this.getSession(); if (!session) { return; } @@ -508,7 +526,7 @@ class CameraService { */ isFocusPoint(point: camera.Point): void { // 设置焦点 - let session: camera.PortraitPhotoSession | camera.CaptureSession = this.getSession(); + let session: camera.PortraitPhotoSession | camera.CaptureSession | camera.NightPhotoSession = this.getSession(); if (!session) { return; } @@ -524,7 +542,7 @@ class CameraService { * 闪关灯 */ hasFlashFn(flashMode: camera.FlashMode): void { - let session: camera.PortraitPhotoSession | camera.CaptureSession = this.getSession(); + let session: camera.PortraitPhotoSession | camera.CaptureSession | camera.NightPhotoSession = this.getSession(); if (!session) { return; } @@ -541,10 +559,12 @@ class CameraService { Logger.debug(TAG, `getFlashMode success, nowFlashMode: ${nowFlashMode}`); } - getSession(): camera.PortraitPhotoSession | camera.CaptureSession | undefined { - let session: camera.PortraitPhotoSession | camera.CaptureSession = undefined; + getSession(): camera.PortraitPhotoSession | camera.CaptureSession | camera.NightPhotoSession | undefined { + let session: camera.PortraitPhotoSession | camera.CaptureSession | camera.NightPhotoSession = undefined; if (this.cameraMode === CameraMode.PORTRAIT) { session = this.portraitSession; + } else if(this.cameraMode === CameraMode.NIGHT) { + session = this.nightSession; } else { session = this.captureSession; } @@ -557,7 +577,7 @@ class CameraService { setZoomRatioFn(zoomRatio: number): void { Logger.info(TAG, `setZoomRatioFn value ${zoomRatio}`); // 获取支持的变焦范围 - let session: camera.PortraitPhotoSession | camera.CaptureSession = this.getSession(); + let session: camera.PortraitPhotoSession | camera.CaptureSession | camera.NightPhotoSession = this.getSession(); if (!session) { return; } @@ -604,6 +624,24 @@ class CameraService { Logger.info(TAG, `getActiveVideoStabilizationMode nowVideoStabilizationMod: ${nowVideoStabilizationMod}`); } + /** + * 是否支持夜景模式 + */ + isNightModeSupportedFn(): boolean { + let isSupportNightMode: boolean = this.sceneModes.indexOf(CameraMode.NIGHT) >= 0; + Logger.info(TAG, `isSupportNightMode success: ${JSON.stringify(isSupportNightMode)}`); + return isSupportNightMode; + } + + /** + * 是否支持人像模式 + */ + isPortraitModeSupportedFn(): boolean { + let isSupportPortraitMode: boolean = this.sceneModes.indexOf(CameraMode.PORTRAIT) >= 0; + Logger.info(TAG, `isSupportPortraitMode success: ${JSON.stringify(isSupportPortraitMode)}`); + return isSupportPortraitMode; + } + /** * 是否支持镜像 */ @@ -882,6 +920,16 @@ class CameraService { this.portraitSession = null; } } + if (this.nightSession) { + try { + await this.nightSession.release(); + } catch (error) { + let err = error as BusinessError; + Logger.error(TAG, `nightSession release fail: error: ${JSON.stringify(err)}`); + } finally { + this.nightSession = null; + } + } if (this.cameraInput) { try { await this.cameraInput.close(); @@ -1096,6 +1144,47 @@ class CameraService { } } + async nightSessionFlowFn(sceneModeIndex?: number): Promise { + try { + // 创建PortraitSession实例 + this.nightSession = this.cameraManager.createSession(camera.SceneMode.NIGHT_PHOTO); + // 监听焦距的状态变化 + this.onFocusStateChange(); + // 监听拍照会话的错误事件 + this.onCaptureSessionErrorChange(); + // 开始配置会话 + this.nightSession.beginConfig(); + // 把CameraInput加入到会话 + this.nightSession.addInput(this.cameraInput); + // 把previewOutput加入到会话 + this.nightSession.addOutput(this.previewOutput); + // 把photoOutPut加入到会话 + this.nightSession.addOutput(this.photoOutPut); + if (AppStorage.get('deferredImage')) { + this.isDeferredImageDeliverySupported(1); + this.deferImageDeliveryFor(1); + this.isDeferredImageDeliveryEnabled(1); + } + + // 提交配置信息 + await this.nightSession.commitConfig(); + const deviceType = AppStorage.get('deviceType'); + if (deviceType !== Constants.DEFAULT) { + AppStorage.setOrCreate('colorEffectComponentIsHidden', this.getSupportedColorEffects().length > 0 ? false : true); + if (this.colorEffect) { + this.setColorEffect(this.colorEffect); + } + } + // 开始会话工作 + await this.nightSession.start(); + this.isFocusMode((this.globalContext.getObject('cameraConfig') as CameraConfig).focusMode); + Logger.info(TAG, 'nightSessionFlowFn success'); + } catch (error) { + let err = error as BusinessError; + Logger.error(TAG, `nightSessionFlowFn fail : ${JSON.stringify(err)}`); + } + } + setPortraitEffect(): void { try { this.portraitSession.setPortraitEffect(camera.PortraitEffect.CIRCLES); @@ -1118,10 +1207,10 @@ class CameraService { setColorEffect(colorEffect: camera.ColorEffectType): void { Logger.info(TAG, 'setColorEffect is called.'); - if (this.captureSession || this.portraitSession) { + if (this.captureSession || this.portraitSession || this.nightSession) { let res: Array | undefined = []; res = this.getSupportedColorEffects(); - let session: camera.PortraitPhotoSession | camera.CaptureSession = this.getSession(); + let session: camera.PortraitPhotoSession | camera.CaptureSession | camera.NightPhotoSession = this.getSession(); if (!session) { return; } @@ -1140,8 +1229,8 @@ class CameraService { getColorEffect(): camera.ColorEffectType | undefined { Logger.info(TAG, 'getColorEffect is called.'); let colorEffect: camera.ColorEffectType | undefined = undefined; - if (this.captureSession || this.portraitSession) { - let session: camera.PortraitPhotoSession | camera.CaptureSession = this.getSession(); + if (this.captureSession || this.portraitSession || this.nightSession) { + let session: camera.PortraitPhotoSession | camera.CaptureSession | camera.NightPhotoSession = this.getSession(); if (!session) { return colorEffect; } @@ -1158,8 +1247,8 @@ class CameraService { getSupportedColorEffects(): Array | undefined { Logger.info(TAG, 'getSupportedColorEffects is called.'); let res: Array | undefined = []; - if (this.captureSession || this.portraitSession) { - let session: camera.PortraitPhotoSession | camera.CaptureSession = this.getSession(); + if (this.captureSession || this.portraitSession || this.nightSession) { + let session: camera.PortraitPhotoSession | camera.CaptureSession | camera.NightPhotoSession = this.getSession(); if (!session) { return res; } @@ -1280,7 +1369,7 @@ class CameraService { * 监听焦距的状态变化 */ onFocusStateChange(): void { - let session: camera.PortraitPhotoSession | camera.CaptureSession = this.getSession(); + let session: camera.PortraitPhotoSession | camera.CaptureSession | camera.NightPhotoSession = this.getSession(); if (!session) { return; } @@ -1293,7 +1382,7 @@ class CameraService { * 监听拍照会话的错误事件 */ onCaptureSessionErrorChange(): void { - let session: camera.PortraitPhotoSession | camera.CaptureSession = this.getSession(); + let session: camera.PortraitPhotoSession | camera.CaptureSession | camera.NightPhotoSession = this.getSession(); if (!session) { return; } diff --git a/frameworks/js/camera_napi/demo/entry/src/main/ets/views/ModeSwitchPage.ets b/frameworks/js/camera_napi/demo/entry/src/main/ets/views/ModeSwitchPage.ets index 60e05af3c2e5538a5dad70ec3bf1e56d53246094..a80d3f7c419132b509fb98ab1ed24f071848ee59 100644 --- a/frameworks/js/camera_napi/demo/entry/src/main/ets/views/ModeSwitchPage.ets +++ b/frameworks/js/camera_napi/demo/entry/src/main/ets/views/ModeSwitchPage.ets @@ -145,7 +145,7 @@ export struct ModeSwitchPage { * 判断录像或者照片模式 */ isVideoPhotoFn(): void { - if (this.modelBagCol == 'photo' || this.modelBagCol == 'portrait') { + if (this.modelBagCol == 'photo' || this.modelBagCol == 'portrait' || this.modelBagCol == 'night') { CameraService.takePicture(); } else if (this.modelBagCol == 'video' || this.modelBagCol == 'superStab') { this.isModeBol = false; @@ -228,6 +228,39 @@ export struct ModeSwitchPage { AppStorage.setOrCreate('isHiddenSlide', false); CameraService.setCameraMode(2); await CameraService.initCamera(this.surfaceId, this.cameraDeviceIndex); + let isSupported = CameraService.isPortraitModeSupportedFn(); + if (!isSupported) { + (GlobalContext.get().getPromptAction() as PromptAction).showToast({ + message: '当前不支持人像模式,请切换其他模式', + duration: 2000, + bottom: '50%' + }) + } + }) + .visibility(this.deviceType === Constants.DEFAULT ? Visibility.Hidden : Visibility.Visible) + + // 夜景 + Column() { + Text('夜景') + .fontSize(14) + .fontColor(Color.White) + } + .width(50) + .backgroundColor(this.modelBagCol === 'night' ? $r('app.color.theme_color') : '') + .borderRadius(14) + .onClick(async () => { + this.modelBagCol = 'night'; + AppStorage.setOrCreate('isHiddenSlide', true); + CameraService.setCameraMode(4); + await CameraService.initCamera(this.surfaceId, this.cameraDeviceIndex); + let isSupported = CameraService.isNightModeSupportedFn(); + if (!isSupported) { + (GlobalContext.get().getPromptAction() as PromptAction).showToast({ + message: '当前不支持夜景模式,请切换其他模式', + duration: 2000, + bottom: '50%' + }) + } }) .visibility(this.deviceType === Constants.DEFAULT ? Visibility.Hidden : Visibility.Visible) diff --git a/frameworks/js/camera_napi/src/camera_napi_security_utils.cpp b/frameworks/js/camera_napi/src/camera_napi_security_utils.cpp index 652c457aac4a48325788ebe3a5dd4644568d0907..cf90752add7932c775717aa4ab569e85ec5ccc49 100644 --- a/frameworks/js/camera_napi/src/camera_napi_security_utils.cpp +++ b/frameworks/js/camera_napi/src/camera_napi_security_utils.cpp @@ -23,14 +23,16 @@ namespace OHOS { namespace CameraStandard { namespace CameraNapiSecurity { -bool CheckSystemApp(napi_env env) +bool CheckSystemApp(napi_env env, bool enableThrowError) { uint64_t tokenId = IPCSkeleton::GetSelfTokenID(); int32_t errorCode = CameraErrorCode::NO_SYSTEM_APP_PERMISSION; if (!Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(tokenId)) { - std::string errorMessage = "System api can be invoked only by system applications"; - if (napi_throw_error(env, std::to_string(errorCode).c_str(), errorMessage.c_str()) != napi_ok) { - MEDIA_ERR_LOG("failed to throw err, code=%{public}d, msg=%{public}s.", errorCode, errorMessage.c_str()); + if (enableThrowError) { + std::string errorMessage = "System api can be invoked only by system applications"; + if (napi_throw_error(env, std::to_string(errorCode).c_str(), errorMessage.c_str()) != napi_ok) { + MEDIA_ERR_LOG("failed to throw err, code=%{public}d, msg=%{public}s.", errorCode, errorMessage.c_str()); + } } return false; } diff --git a/frameworks/js/camera_napi/src/input/camera_manager_napi.cpp b/frameworks/js/camera_napi/src/input/camera_manager_napi.cpp index 38471aac8ee8fddfa4a670fc3cf4ea3697fc6974..251e2f80458f16f72ae0cdd5bbaf59385471970c 100644 --- a/frameworks/js/camera_napi/src/input/camera_manager_napi.cpp +++ b/frameworks/js/camera_napi/src/input/camera_manager_napi.cpp @@ -20,12 +20,15 @@ #include "camera_napi_security_utils.h" #include "camera_napi_template_utils.h" #include "camera_napi_utils.h" +#include "camera_napi_security_utils.h" #include "input/camera_napi.h" #include "input/camera_pre_launch_config_napi.h" #include "mode/night_session_napi.h" #include "mode/photo_session_napi.h" +#include "mode/photo_session_for_sys_napi.h" #include "mode/portrait_session_napi.h" #include "mode/video_session_napi.h" +#include "mode/video_session_for_sys_napi.h" namespace OHOS { namespace CameraStandard { using namespace std; @@ -554,10 +557,12 @@ napi_value CameraManagerNapi::CreateSessionInstance(napi_env env, napi_callback_ MEDIA_INFO_LOG("CameraManagerNapi::CreateSessionInstance mode = %{public}d", jsModeName); switch (jsModeName) { case JS_CAPTURE: - result = PhotoSessionNapi::CreateCameraSession(env); + result = CameraNapiSecurity::CheckSystemApp(env, false) ? + PhotoSessionForSysNapi::CreateCameraSession(env) : PhotoSessionNapi::CreateCameraSession(env); break; case JS_VIDEO: - result = VideoSessionNapi::CreateCameraSession(env); + result = CameraNapiSecurity::CheckSystemApp(env, false) ? + VideoSessionForSysNapi::CreateCameraSession(env) : VideoSessionNapi::CreateCameraSession(env); break; case JS_PORTRAIT: result = PortraitSessionNapi::CreateCameraSession(env); diff --git a/frameworks/js/camera_napi/src/input/camera_napi.cpp b/frameworks/js/camera_napi/src/input/camera_napi.cpp index fc2fcf67bc661b8f97d9090ba177e7291a5eb449..2c5e4278dc59b40ca294076ecf8d7953ef94ee80 100644 --- a/frameworks/js/camera_napi/src/input/camera_napi.cpp +++ b/frameworks/js/camera_napi/src/input/camera_napi.cpp @@ -49,6 +49,7 @@ thread_local napi_ref CameraNapi::beautyTypeRef_ = nullptr; thread_local napi_ref CameraNapi::portraitEffectRef_ = nullptr; thread_local napi_ref CameraNapi::torchModeRef_ = nullptr; thread_local napi_ref CameraNapi::deferredDeliveryImageTypeRef_ = nullptr; +thread_local napi_ref CameraNapi::SmoothZoomModeRef_ = nullptr; CameraNapi::CameraNapi() : env_(nullptr), wrapper_(nullptr) { @@ -172,6 +173,8 @@ napi_value CameraNapi::Init(napi_env env, napi_value exports) DECLARE_NAPI_PROPERTY("DeferredDeliveryImageType", CreateObjectWithMap(env, "DeferredDeliveryImageType", mapDeferredDeliveryImageType, deferredDeliveryImageTypeRef_)), + DECLARE_NAPI_PROPERTY("SmoothZoomMode", + CreateObjectWithMap(env, "SmoothZoomMode", mapSmoothZoomMode, SmoothZoomModeRef_)), }; status = napi_define_class(env, CAMERA_LIB_NAPI_CLASS_NAME, NAPI_AUTO_LENGTH, CameraNapiConstructor, diff --git a/frameworks/js/camera_napi/src/mode/photo_session_for_sys_napi.cpp b/frameworks/js/camera_napi/src/mode/photo_session_for_sys_napi.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dbfcbb75c996ba99d3886038a1edad58866565f7 --- /dev/null +++ b/frameworks/js/camera_napi/src/mode/photo_session_for_sys_napi.cpp @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2023-2023 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 "mode/photo_session_for_sys_napi.h" + +namespace OHOS { +namespace CameraStandard { +using namespace std; + +thread_local napi_ref PhotoSessionForSysNapi::sConstructor_ = nullptr; + +PhotoSessionForSysNapi::PhotoSessionForSysNapi() : env_(nullptr), wrapper_(nullptr) +{ +} +PhotoSessionForSysNapi::~PhotoSessionForSysNapi() +{ + MEDIA_DEBUG_LOG("~PhotoSessionForSysNapi is called"); + if (wrapper_ != nullptr) { + napi_delete_reference(env_, wrapper_); + } + if (photoSession_) { + photoSession_ = nullptr; + } +} +void PhotoSessionForSysNapi::PhotoSessionForSysNapiDestructor(napi_env env, void* nativeObject, void* finalize_hint) +{ + MEDIA_DEBUG_LOG("PhotoSessionForSysNapiDestructor is called"); + PhotoSessionForSysNapi* cameraObj = reinterpret_cast(nativeObject); + if (cameraObj != nullptr) { + delete cameraObj; + } +} +napi_value PhotoSessionForSysNapi::Init(napi_env env, napi_value exports) +{ + MEDIA_DEBUG_LOG("Init is called"); + napi_status status; + napi_value ctorObj; + std::vector> descriptors = {camera_process_props, + flash_props, auto_exposure_props, focus_props, zoom_props, filter_props, beauty_props, + color_effect_props, macro_props, color_management_props}; + std::vector photo_session_props = CameraNapiUtils::GetPropertyDescriptor(descriptors); + status = napi_define_class(env, PHOTO_SESSION_FOR_SYS_NAPI_CLASS_NAME, NAPI_AUTO_LENGTH, + PhotoSessionForSysNapiConstructor, nullptr, + photo_session_props.size(), + photo_session_props.data(), &ctorObj); + if (status == napi_ok) { + int32_t refCount = 1; + status = napi_create_reference(env, ctorObj, refCount, &sConstructor_); + if (status == napi_ok) { + status = napi_set_named_property(env, exports, PHOTO_SESSION_FOR_SYS_NAPI_CLASS_NAME, ctorObj); + if (status == napi_ok) { + return exports; + } + } + } + MEDIA_ERR_LOG("Init call Failed!"); + return nullptr; +} + +napi_value PhotoSessionForSysNapi::CreateCameraSession(napi_env env) +{ + MEDIA_DEBUG_LOG("CreateCameraSession is called"); + CAMERA_SYNC_TRACE; + napi_status status; + napi_value result = nullptr; + napi_value constructor; + status = napi_get_reference_value(env, sConstructor_, &constructor); + if (status == napi_ok) { + sCameraSession_ = CameraManager::GetInstance()->CreateCaptureSession(SceneMode::CAPTURE); + if (sCameraSession_ == nullptr) { + MEDIA_ERR_LOG("Failed to create Photo session instance"); + napi_get_undefined(env, &result); + return result; + } + status = napi_new_instance(env, constructor, 0, nullptr, &result); + sCameraSession_ = nullptr; + if (status == napi_ok && result != nullptr) { + MEDIA_DEBUG_LOG("success to create Photo session napi instance"); + return result; + } else { + MEDIA_ERR_LOG("Failed to create Photo session napi instance"); + } + } + MEDIA_ERR_LOG("Failed to create Photo session napi instance last"); + napi_get_undefined(env, &result); + return result; +} + +napi_value PhotoSessionForSysNapi::PhotoSessionForSysNapiConstructor(napi_env env, napi_callback_info info) +{ + MEDIA_DEBUG_LOG("PhotoSessionForSysNapiConstructor is called"); + napi_status status; + napi_value result = nullptr; + napi_value thisVar = nullptr; + + napi_get_undefined(env, &result); + CAMERA_NAPI_GET_JS_OBJ_WITH_ZERO_ARGS(env, info, status, thisVar); + + if (status == napi_ok && thisVar != nullptr) { + std::unique_ptr obj = std::make_unique(); + obj->env_ = env; + if (sCameraSession_ == nullptr) { + MEDIA_ERR_LOG("sCameraSession_ is null"); + return result; + } + obj->photoSession_ = static_cast(sCameraSession_.GetRefPtr()); + obj->cameraSession_ = obj->photoSession_; + if (obj->photoSession_ == nullptr) { + MEDIA_ERR_LOG("photoSession_ is null"); + return result; + } + status = napi_wrap(env, thisVar, reinterpret_cast(obj.get()), + PhotoSessionForSysNapi::PhotoSessionForSysNapiDestructor, nullptr, nullptr); + if (status == napi_ok) { + obj.release(); + return thisVar; + } else { + MEDIA_ERR_LOG("PhotoSessionForSysNapi Failure wrapping js to native napi"); + } + } + MEDIA_ERR_LOG("PhotoSessionForSysNapi call Failed!"); + return result; +} +} // namespace CameraStandard +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/js/camera_napi/src/mode/photo_session_napi.cpp b/frameworks/js/camera_napi/src/mode/photo_session_napi.cpp index 9238e47838a9566cd41b563d3269dace92d399bd..efabd8235f8f418f7baa8c4d2c5edf9d2cd3d93e 100644 --- a/frameworks/js/camera_napi/src/mode/photo_session_napi.cpp +++ b/frameworks/js/camera_napi/src/mode/photo_session_napi.cpp @@ -48,8 +48,7 @@ napi_value PhotoSessionNapi::Init(napi_env env, napi_value exports) napi_status status; napi_value ctorObj; std::vector> descriptors = {camera_process_props, - flash_props, auto_exposure_props, focus_props, zoom_props, filter_props, beauty_props, - color_effect_props, macro_props, color_management_props}; + flash_props, auto_exposure_props, focus_props, zoom_props, filter_props}; std::vector photo_session_props = CameraNapiUtils::GetPropertyDescriptor(descriptors); status = napi_define_class(env, PHOTO_SESSION_NAPI_CLASS_NAME, NAPI_AUTO_LENGTH, PhotoSessionNapiConstructor, nullptr, diff --git a/frameworks/js/camera_napi/src/mode/video_session_for_sys_napi.cpp b/frameworks/js/camera_napi/src/mode/video_session_for_sys_napi.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bc854e3f9062b380b620b603b9ead34600dde611 --- /dev/null +++ b/frameworks/js/camera_napi/src/mode/video_session_for_sys_napi.cpp @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2023-2023 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 "mode/video_session_for_sys_napi.h" + +namespace OHOS { +namespace CameraStandard { +using namespace std; + +thread_local napi_ref VideoSessionForSysNapi::sConstructor_ = nullptr; + +VideoSessionForSysNapi::VideoSessionForSysNapi() : env_(nullptr), wrapper_(nullptr) +{ +} +VideoSessionForSysNapi::~VideoSessionForSysNapi() +{ + MEDIA_DEBUG_LOG("~VideoSessionForSysNapi is called"); + if (wrapper_ != nullptr) { + napi_delete_reference(env_, wrapper_); + } + if (videoSession_) { + videoSession_ = nullptr; + } +} +void VideoSessionForSysNapi::VideoSessionForSysNapiDestructor(napi_env env, void* nativeObject, void* finalize_hint) +{ + MEDIA_DEBUG_LOG("VideoSessionForSysNapiDestructor is called"); + VideoSessionForSysNapi* cameraObj = reinterpret_cast(nativeObject); + if (cameraObj != nullptr) { + delete cameraObj; + } +} +napi_value VideoSessionForSysNapi::Init(napi_env env, napi_value exports) +{ + MEDIA_DEBUG_LOG("Init is called"); + napi_status status; + napi_value ctorObj; + std::vector> descriptors = {camera_process_props, + flash_props, auto_exposure_props, focus_props, zoom_props, filter_props, beauty_props, + color_effect_props, macro_props, color_management_props, stabilization_props}; + std::vector video_session_props = CameraNapiUtils::GetPropertyDescriptor(descriptors); + status = napi_define_class(env, VIDEO_SESSION_FOR_SYS_NAPI_CLASS_NAME, NAPI_AUTO_LENGTH, + VideoSessionForSysNapiConstructor, nullptr, + video_session_props.size(), + video_session_props.data(), &ctorObj); + if (status == napi_ok) { + int32_t refCount = 1; + status = napi_create_reference(env, ctorObj, refCount, &sConstructor_); + if (status == napi_ok) { + status = napi_set_named_property(env, exports, VIDEO_SESSION_FOR_SYS_NAPI_CLASS_NAME, ctorObj); + if (status == napi_ok) { + return exports; + } + } + } + MEDIA_ERR_LOG("Init call Failed!"); + return nullptr; +} + +napi_value VideoSessionForSysNapi::CreateCameraSession(napi_env env) +{ + MEDIA_DEBUG_LOG("CreateCameraSession is called"); + CAMERA_SYNC_TRACE; + napi_status status; + napi_value result = nullptr; + napi_value constructor; + status = napi_get_reference_value(env, sConstructor_, &constructor); + if (status == napi_ok) { + sCameraSession_ = CameraManager::GetInstance()->CreateCaptureSession(SceneMode::VIDEO); + if (sCameraSession_ == nullptr) { + MEDIA_ERR_LOG("Failed to create Video session instance"); + napi_get_undefined(env, &result); + return result; + } + status = napi_new_instance(env, constructor, 0, nullptr, &result); + sCameraSession_ = nullptr; + if (status == napi_ok && result != nullptr) { + MEDIA_DEBUG_LOG("success to create Video session napi instance"); + return result; + } else { + MEDIA_ERR_LOG("Failed to create Video session napi instance"); + } + } + MEDIA_ERR_LOG("Failed to create Video session napi instance last"); + napi_get_undefined(env, &result); + return result; +} + +napi_value VideoSessionForSysNapi::VideoSessionForSysNapiConstructor(napi_env env, napi_callback_info info) +{ + MEDIA_DEBUG_LOG("VideoSessionForSysNapiConstructor is called"); + napi_status status; + napi_value result = nullptr; + napi_value thisVar = nullptr; + + napi_get_undefined(env, &result); + CAMERA_NAPI_GET_JS_OBJ_WITH_ZERO_ARGS(env, info, status, thisVar); + + if (status == napi_ok && thisVar != nullptr) { + std::unique_ptr obj = std::make_unique(); + obj->env_ = env; + if (sCameraSession_ == nullptr) { + MEDIA_ERR_LOG("sCameraSession_ is null"); + return result; + } + obj->videoSession_ = static_cast(sCameraSession_.GetRefPtr()); + obj->cameraSession_ = obj->videoSession_; + if (obj->videoSession_ == nullptr) { + MEDIA_ERR_LOG("videoSession_ is null"); + return result; + } + status = napi_wrap(env, thisVar, reinterpret_cast(obj.get()), + VideoSessionForSysNapi::VideoSessionForSysNapiDestructor, nullptr, nullptr); + if (status == napi_ok) { + obj.release(); + return thisVar; + } else { + MEDIA_ERR_LOG("VideoSessionForSysNapi Failure wrapping js to native napi"); + } + } + MEDIA_ERR_LOG("VideoSessionForSysNapi call Failed!"); + return result; +} +} // namespace CameraStandard +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/js/camera_napi/src/mode/video_session_napi.cpp b/frameworks/js/camera_napi/src/mode/video_session_napi.cpp index 4f8f65aeb980966cd2ffa3d31b28fa3b10a9f899..e956d222cd588991defa3c3a53dec7535a83b6a8 100644 --- a/frameworks/js/camera_napi/src/mode/video_session_napi.cpp +++ b/frameworks/js/camera_napi/src/mode/video_session_napi.cpp @@ -48,8 +48,7 @@ napi_value VideoSessionNapi::Init(napi_env env, napi_value exports) napi_status status; napi_value ctorObj; std::vector> descriptors = {camera_process_props, - flash_props, auto_exposure_props, focus_props, zoom_props, filter_props, beauty_props, - color_effect_props, macro_props, color_management_props, stabilization_props}; + flash_props, auto_exposure_props, focus_props, zoom_props, filter_props}; std::vector video_session_props = CameraNapiUtils::GetPropertyDescriptor(descriptors); status = napi_define_class(env, VIDEO_SESSION_NAPI_CLASS_NAME, NAPI_AUTO_LENGTH, VideoSessionNapiConstructor, nullptr, diff --git a/frameworks/js/camera_napi/src/native_module_ohos_camera.cpp b/frameworks/js/camera_napi/src/native_module_ohos_camera.cpp index 4d91791cbcfc9138473539cabf00302a1141f1c2..d5d47cb90cbfdb490e37a7ca095abd34d2c10233 100644 --- a/frameworks/js/camera_napi/src/native_module_ohos_camera.cpp +++ b/frameworks/js/camera_napi/src/native_module_ohos_camera.cpp @@ -41,7 +41,9 @@ static napi_value Export(napi_env env, napi_value exports) PortraitSessionNapi::Init(env, exports); NightSessionNapi::Init(env, exports); PhotoSessionNapi::Init(env, exports); + PhotoSessionForSysNapi::Init(env, exports); VideoSessionNapi::Init(env, exports); + VideoSessionForSysNapi::Init(env, exports); ModeManagerNapi::Init(env, exports); PhotoNapi::Init(env, exports); DeferredPhotoProxyNapi::Init(env, exports); diff --git a/frameworks/js/camera_napi/src/output/photo_output_napi.cpp b/frameworks/js/camera_napi/src/output/photo_output_napi.cpp index cd052da6a7a116e66756626535ad65933111f36e..79f3fde5b229c288871df770617f9020009a5d3d 100644 --- a/frameworks/js/camera_napi/src/output/photo_output_napi.cpp +++ b/frameworks/js/camera_napi/src/output/photo_output_napi.cpp @@ -835,6 +835,7 @@ napi_value PhotoOutputNapi::Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("enableQuickThumbnail", EnableQuickThumbnail), DECLARE_NAPI_FUNCTION("isQuickThumbnailSupported", IsQuickThumbnailSupported), DECLARE_NAPI_FUNCTION("on", On), DECLARE_NAPI_FUNCTION("once", Once), DECLARE_NAPI_FUNCTION("off", Off), + DECLARE_NAPI_FUNCTION("deferImageDelivery", DeferImageDeliveryFor), DECLARE_NAPI_FUNCTION("deferImageDeliveryFor", DeferImageDeliveryFor), DECLARE_NAPI_FUNCTION("isDeferredImageDeliverySupported", IsDeferredImageDeliverySupported), DECLARE_NAPI_FUNCTION("isDeferredImageDeliveryEnabled", IsDeferredImageDeliveryEnabled) diff --git a/frameworks/js/camera_napi/src/output/video_output_napi.cpp b/frameworks/js/camera_napi/src/output/video_output_napi.cpp index 9381ec584a93ec7db1d8d4b0ecc0f4e8b3622850..c42a12c79ade008f4c3fae6cb7324b0c6b41c0b7 100644 --- a/frameworks/js/camera_napi/src/output/video_output_napi.cpp +++ b/frameworks/js/camera_napi/src/output/video_output_napi.cpp @@ -545,7 +545,7 @@ napi_value VideoOutputNapi::Stop(napi_env env, napi_callback_info info) if (context->objectInfo != nullptr && context->objectInfo->videoOutput_ != nullptr) { context->bRetBool = false; context->errorCode = ((sptr &)(context->objectInfo->videoOutput_))->Stop(); - context->status = context->errorCode == 0; + context->status = true; } }, CommonCompleteCallback, static_cast(asyncContext.get()), &asyncContext->work); diff --git a/frameworks/native/camera/src/output/capture_output.cpp b/frameworks/native/camera/src/output/capture_output.cpp index 7ac6300a9659c6f6aec236ba4abafbe02ed4fbcc..88a90a9320a19f8ef623a6753dc3de4d8d8b5d85 100644 --- a/frameworks/native/camera/src/output/capture_output.cpp +++ b/frameworks/native/camera/src/output/capture_output.cpp @@ -62,6 +62,7 @@ StreamType CaptureOutput::GetStreamType() sptr CaptureOutput::GetStream() { + std::lock_guard lock(streamMutex_); return stream_; } @@ -79,7 +80,10 @@ void CaptureOutput::SetSession(wptr captureSession) int32_t CaptureOutput::Release() { - stream_ = nullptr; + { + std::lock_guard lock(streamMutex_); + stream_ = nullptr; + } SetSession(nullptr); return 0; } diff --git a/interfaces/inner_api/native/camera/include/output/capture_output.h b/interfaces/inner_api/native/camera/include/output/capture_output.h index 8ec1d622656299ac3a14cf4c416b87812beb75fb..32cb46e266fbdf472551e50ad14a7fbb4e8d0c78 100644 --- a/interfaces/inner_api/native/camera/include/output/capture_output.h +++ b/interfaces/inner_api/native/camera/include/output/capture_output.h @@ -131,6 +131,7 @@ private: sptr stream_; wptr session_; std::mutex sessionMutex_; + std::mutex streamMutex_; Profile photoProfile_; Profile previewProfile_; VideoProfile videoProfile_; diff --git a/interfaces/kits/js/camera_napi/BUILD.gn b/interfaces/kits/js/camera_napi/BUILD.gn index fbdffbf5230feb3996a534ce8de0c519e1dfc294..3702bcbc6c775f9742f761fabdde5186a1b06741 100644 --- a/interfaces/kits/js/camera_napi/BUILD.gn +++ b/interfaces/kits/js/camera_napi/BUILD.gn @@ -59,8 +59,10 @@ ohos_shared_library("camera_napi") { "${multimedia_camera_framework_path}/frameworks/js/camera_napi/src/listener_base.cpp", "${multimedia_camera_framework_path}/frameworks/js/camera_napi/src/mode/mode_manager_napi.cpp", "${multimedia_camera_framework_path}/frameworks/js/camera_napi/src/mode/night_session_napi.cpp", + "${multimedia_camera_framework_path}/frameworks/js/camera_napi/src/mode/photo_session_for_sys_napi.cpp", "${multimedia_camera_framework_path}/frameworks/js/camera_napi/src/mode/photo_session_napi.cpp", "${multimedia_camera_framework_path}/frameworks/js/camera_napi/src/mode/portrait_session_napi.cpp", + "${multimedia_camera_framework_path}/frameworks/js/camera_napi/src/mode/video_session_for_sys_napi.cpp", "${multimedia_camera_framework_path}/frameworks/js/camera_napi/src/mode/video_session_napi.cpp", "${multimedia_camera_framework_path}/frameworks/js/camera_napi/src/native_module_ohos_camera.cpp", "${multimedia_camera_framework_path}/frameworks/js/camera_napi/src/output/camera_output_napi.cpp", diff --git a/interfaces/kits/js/camera_napi/include/camera_napi_security_utils.h b/interfaces/kits/js/camera_napi/include/camera_napi_security_utils.h index 9bd9a98e4517d9cbc4c804622dfc831b2f412c74..212e064f0fccb983d621401a3f683ebe126e54b4 100644 --- a/interfaces/kits/js/camera_napi/include/camera_napi_security_utils.h +++ b/interfaces/kits/js/camera_napi/include/camera_napi_security_utils.h @@ -24,7 +24,7 @@ namespace OHOS { namespace CameraStandard { namespace CameraNapiSecurity { -bool CheckSystemApp(napi_env env); +bool CheckSystemApp(napi_env env, bool enableThrowError = true); } } // namespace CameraStandard } // namespace OHOS diff --git a/interfaces/kits/js/camera_napi/include/input/camera_napi.h b/interfaces/kits/js/camera_napi/include/input/camera_napi.h index 4e02160b94485b34fd449ed42c3b154b2a4f68f0..9b9a1a53181de59b32b07e7dda5cf9be6e9b7d26 100644 --- a/interfaces/kits/js/camera_napi/include/input/camera_napi.h +++ b/interfaces/kits/js/camera_napi/include/input/camera_napi.h @@ -82,6 +82,7 @@ static const std::unordered_map mapCameraPosition = { {"CAMERA_POSITION_UNSPECIFIED", 0}, {"CAMERA_POSITION_BACK", 1}, {"CAMERA_POSITION_FRONT", 2}, + {"CAMERA_POSITION_FOLD_INNER", 3}, }; static const std::unordered_map mapCameraType = { @@ -257,6 +258,10 @@ static const std::unordered_map mapDeferredDeliveryImageTy {"VIDEO", 2}, }; +static const std::unordered_map mapSmoothZoomMode = { + {"NORMAL", 0}, +}; + enum CreateAsyncCallbackModes { CREATE_CAMERA_MANAGER_ASYNC_CALLBACK = 10, }; @@ -314,6 +319,7 @@ private: static thread_local napi_ref metadataObjectTypeRef_; static thread_local napi_ref errorMetadataOutputRef_; static thread_local napi_ref deferredDeliveryImageTypeRef_; + static thread_local napi_ref SmoothZoomModeRef_; napi_env env_; napi_ref wrapper_; }; diff --git a/interfaces/kits/js/camera_napi/include/mode/photo_session_for_sys_napi.h b/interfaces/kits/js/camera_napi/include/mode/photo_session_for_sys_napi.h new file mode 100644 index 0000000000000000000000000000000000000000..bec6d4f4fbabe5529789d70ae01d5383e5b93269 --- /dev/null +++ b/interfaces/kits/js/camera_napi/include/mode/photo_session_for_sys_napi.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023-2023 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_SESSION_FOR_SYS_NAPI_H +#define PHOTO_SESSION_FOR_SYS_NAPI_H + +#include "napi/native_api.h" +#include "napi/native_node_api.h" +#include "session/camera_session_napi.h" + +namespace OHOS { +namespace CameraStandard { +static const char PHOTO_SESSION_FOR_SYS_NAPI_CLASS_NAME[] = "PohtoSessionForSys"; +class PhotoSessionForSysNapi : public CameraSessionNapi { +public: + static napi_value Init(napi_env env, napi_value exports); + static napi_value CreateCameraSession(napi_env env); + PhotoSessionForSysNapi(); + ~PhotoSessionForSysNapi(); + + static void PhotoSessionForSysNapiDestructor(napi_env env, void* nativeObject, void* finalize_hint); + static napi_value PhotoSessionForSysNapiConstructor(napi_env env, napi_callback_info info); + + napi_env env_; + napi_ref wrapper_; + sptr photoSession_; + static thread_local napi_ref sConstructor_; +}; +} +} +#endif /* PHOTO_SESSION_FOR_SYS_NAPI_H */ diff --git a/interfaces/kits/js/camera_napi/include/mode/video_session_for_sys_napi.h b/interfaces/kits/js/camera_napi/include/mode/video_session_for_sys_napi.h new file mode 100644 index 0000000000000000000000000000000000000000..ddfe75d9dfd7ca52d4c97724723bc7950e41dde0 --- /dev/null +++ b/interfaces/kits/js/camera_napi/include/mode/video_session_for_sys_napi.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023-2023 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_SESSION_FOR_SYS_NAPI_H +#define VIDEO_SESSION_FOR_SYS_NAPI_H + +#include "napi/native_api.h" +#include "napi/native_node_api.h" +#include "session/camera_session_napi.h" + +namespace OHOS { +namespace CameraStandard { +static const char VIDEO_SESSION_FOR_SYS_NAPI_CLASS_NAME[] = "VideoSessionForSys"; +class VideoSessionForSysNapi : public CameraSessionNapi { +public: + static napi_value Init(napi_env env, napi_value exports); + static napi_value CreateCameraSession(napi_env env); + VideoSessionForSysNapi(); + ~VideoSessionForSysNapi(); + + static void VideoSessionForSysNapiDestructor(napi_env env, void* nativeObject, void* finalize_hint); + static napi_value VideoSessionForSysNapiConstructor(napi_env env, napi_callback_info info); + + napi_env env_; + napi_ref wrapper_; + sptr videoSession_; + static thread_local napi_ref sConstructor_; +}; +} +} +#endif /* VIDEO_SESSION_FOR_SYS_NAPI_H */ diff --git a/interfaces/kits/js/camera_napi/include/native_module_ohos_camera.h b/interfaces/kits/js/camera_napi/include/native_module_ohos_camera.h index 48d2a1907ea824e25f0844b433fed03150bb6a1d..fc9837dc1b218381b17dfe06ea8a9b486bcba381 100644 --- a/interfaces/kits/js/camera_napi/include/native_module_ohos_camera.h +++ b/interfaces/kits/js/camera_napi/include/native_module_ohos_camera.h @@ -26,7 +26,9 @@ #include "mode/night_session_napi.h" #include "mode/portrait_session_napi.h" #include "mode/photo_session_napi.h" +#include "mode/photo_session_for_sys_napi.h" #include "mode/video_session_napi.h" +#include "mode/video_session_for_sys_napi.h" #include "output/metadata_object_napi.h" #include "output/photo_output_napi.h" #include "output/preview_output_napi.h" diff --git a/services/camera_service/include/hcamera_device.h b/services/camera_service/include/hcamera_device.h index 7568c2079b06bffffb04be1c03f292d7974a0efb..7fb9d2b4a6d0afe703060340f05b4181cac63496 100644 --- a/services/camera_service/include/hcamera_device.h +++ b/services/camera_service/include/hcamera_device.h @@ -127,6 +127,8 @@ private: std::string clientName_; int clientUserId_; + + std::mutex unPrepareZoomMutex_; uint32_t zoomTimerId_; std::atomic inPrepareZoom_; diff --git a/services/camera_service/src/hcamera_device.cpp b/services/camera_service/src/hcamera_device.cpp index 9ebdcbfa2d23e2303f5bdf3c04b04acc8d0850a9..151334a94771c759c7ecd6c856a13c07d53671e7 100644 --- a/services/camera_service/src/hcamera_device.cpp +++ b/services/camera_service/src/hcamera_device.cpp @@ -394,6 +394,7 @@ void HCameraDevice::ResetZoomTimer() void HCameraDevice::UnPrepareZoom() { MEDIA_INFO_LOG("entered."); + std::lock_guard lock(unPrepareZoomMutex_); if (inPrepareZoom_) { inPrepareZoom_ = false; uint32_t count = 1; diff --git a/services/camera_service/src/hcapture_session.cpp b/services/camera_service/src/hcapture_session.cpp index b4bbf535ef76f1b95970613c210b2fdb3c105cb8..ece3a125d4692ac1318bb7cb5f1b5c57bc40dc7d 100644 --- a/services/camera_service/src/hcapture_session.cpp +++ b/services/camera_service/src/hcapture_session.cpp @@ -793,7 +793,10 @@ int32_t HCaptureSession::SetSmoothZoom( int indexAdded = targetZoomRatio > currentZoomRatio ? 1 : 2; auto zoomAlgorithm = SmoothZoom::GetZoomAlgorithm(static_cast(smoothZoomType)); auto array = zoomAlgorithm->GetZoomArray(currentZoomRatio, targetZoomRatio, frameIntervalMs); - + if (array.empty()) { + MEDIA_ERR_LOG("HCaptureSession::SetSmoothZoom array is empty"); + return CAMERA_UNKNOWN_ERROR; + } for (int i = 0; i < static_cast(crossZoomAndTime.size()); i = i + dataLenPerPoint) { float crossZoom = crossZoomAndTime[i]; if ((crossZoom - currentZoomRatio) * (crossZoom - targetZoomRatio) > 0) { diff --git a/services/camera_service/src/smooth_zoom/cubic_bezier.cpp b/services/camera_service/src/smooth_zoom/cubic_bezier.cpp index 96beaca0ee9a7d7936053c2d84275da091651440..91badb2ff054e8ed505211bfabac7f2ab2e09539 100644 --- a/services/camera_service/src/smooth_zoom/cubic_bezier.cpp +++ b/services/camera_service/src/smooth_zoom/cubic_bezier.cpp @@ -31,6 +31,7 @@ constexpr float CONTROL_POINT_Y2 = 1.0; constexpr float DURATION_SLOP = 55.0; constexpr float DURATION_BASE = 450.0; constexpr float DURATION_POWER = 1.2; +constexpr int MAX_ZOOM_ARRAY_SIZE = 100; } std::vector CubicBezier::GetZoomArray(const float& currentZoom, const float& targetZoom, @@ -43,6 +44,10 @@ std::vector CubicBezier::GetZoomArray(const float& currentZoom, const flo return result; } int arraySize = static_cast(duration / frameInterval); + if (arraySize > MAX_ZOOM_ARRAY_SIZE) { + MEDIA_ERR_LOG("Error size, duration is:%{public}f, interval is:%{public}f", duration, frameInterval); + return result; + } for (int i = 1; i <= arraySize; i++) { float time = frameInterval * i / duration; float zoom = (currentZoom + (targetZoom - currentZoom) * GetInterpolation(time)); diff --git a/services/deferred_processing_service/include/base/buffer_info.h b/services/deferred_processing_service/include/base/buffer_info.h index 22b18a0e5ae5b841cf15e0f55714a730a5fccc3e..10f6289762727605f34400a6ac40d731332d2629 100644 --- a/services/deferred_processing_service/include/base/buffer_info.h +++ b/services/deferred_processing_service/include/base/buffer_info.h @@ -31,6 +31,7 @@ public: sptr GetIPCFileDescriptor(); long GetDataSize(); bool IsHighQuality(); + void ReleaseBuffer(); private: sptr ipcFileDescriptor_; diff --git a/services/deferred_processing_service/src/base/buffer_info.cpp b/services/deferred_processing_service/src/base/buffer_info.cpp index 6ef578dfea3185fb9ed6cc13b2ddae18f43e8f61..ad64b28f4019c322234a1dbd1ef67dd6dad88686 100644 --- a/services/deferred_processing_service/src/base/buffer_info.cpp +++ b/services/deferred_processing_service/src/base/buffer_info.cpp @@ -12,6 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +#include + #include "buffer_info.h" namespace OHOS { @@ -43,6 +46,14 @@ bool BufferInfo::IsHighQuality() { return isHighQuality_; } + +void BufferInfo::ReleaseBuffer() +{ + if (ipcFileDescriptor_) { + close(ipcFileDescriptor_->GetFd()); + } + return; +} } //namespace DeferredProcessing } // namespace CameraStandard } // namespace OHOS diff --git a/services/deferred_processing_service/src/post_processor/photo_post_processor.cpp b/services/deferred_processing_service/src/post_processor/photo_post_processor.cpp index 1b489caf4bf36141f96f244ddda93a818244d547..6c6104aab244f4a8d80a9d4d321bba553f96ecbc 100644 --- a/services/deferred_processing_service/src/post_processor/photo_post_processor.cpp +++ b/services/deferred_processing_service/src/post_processor/photo_post_processor.cpp @@ -249,6 +249,7 @@ int PhotoPostProcessor::GetUserId() int PhotoPostProcessor::GetConcurrency(ExecutionMode mode) { + std::lock_guard lock(mutex_); int count = 1; if (imageProcessSession_) { int32_t ret = imageProcessSession_->GetCoucurrency(OHOS::HDI::Camera::V1_2::ExecutionMode::BALANCED, count); @@ -260,6 +261,7 @@ int PhotoPostProcessor::GetConcurrency(ExecutionMode mode) bool PhotoPostProcessor::GetPendingImages(std::vector& pendingImages) { + std::lock_guard lock(mutex_); DP_INFO_LOG("entered"); if (imageProcessSession_) { int32_t ret = imageProcessSession_->GetPendingImages(pendingImages); @@ -273,6 +275,7 @@ bool PhotoPostProcessor::GetPendingImages(std::vector& pendingImage void PhotoPostProcessor::SetExecutionMode(ExecutionMode executionMode) { + std::lock_guard lock(mutex_); DP_INFO_LOG("entered, executionMode: %d", executionMode); if (imageProcessSession_) { int32_t ret = imageProcessSession_->SetExecutionMode(MapToHdiExecutionMode(executionMode)); @@ -288,6 +291,7 @@ void PhotoPostProcessor::ProcessImage(std::string imageId) OnError(imageId, DpsError::DPS_ERROR_SESSION_NOT_READY_TEMPORARILY); return; } + std::lock_guard lock(mutex_); int32_t ret = imageProcessSession_->ProcessImage(imageId); DP_INFO_LOG("processImage, ret: %d", ret); uint32_t callbackHandle; @@ -305,6 +309,7 @@ void PhotoPostProcessor::ProcessImage(std::string imageId) void PhotoPostProcessor::RemoveImage(std::string imageId) { + std::lock_guard lock(mutex_); DP_INFO_LOG("entered, imageId: %s", imageId.c_str()); if (imageProcessSession_) { int32_t ret = imageProcessSession_->RemoveImage(imageId); @@ -315,6 +320,7 @@ void PhotoPostProcessor::RemoveImage(std::string imageId) void PhotoPostProcessor::Interrupt() { + std::lock_guard lock(mutex_); DP_INFO_LOG("entered"); if (imageProcessSession_) { int32_t ret = imageProcessSession_->Interrupt(); @@ -324,6 +330,7 @@ void PhotoPostProcessor::Interrupt() void PhotoPostProcessor::Reset() { + std::lock_guard lock(mutex_); DP_INFO_LOG("entered"); if (imageProcessSession_) { int32_t ret = imageProcessSession_->Reset(); @@ -382,6 +389,7 @@ void PhotoPostProcessor::OnSessionDied() DP_INFO_LOG("entered, session died!"); std::lock_guard lock(mutex_); imageProcessSession_ = nullptr; + consecutiveTimeoutCount_ = 0; OnStateChanged(HdiStatus::HDI_DISCONNECTED); ScheduleConnectService(); } diff --git a/services/deferred_processing_service/src/schedule/photo_processor/deferred_photo_processor.cpp b/services/deferred_processing_service/src/schedule/photo_processor/deferred_photo_processor.cpp index 0c3342225965a35c908b1538655085db0f271ab4..b585625e1d32b1f3a50b2c5adcbd3455df323128 100644 --- a/services/deferred_processing_service/src/schedule/photo_processor/deferred_photo_processor.cpp +++ b/services/deferred_processing_service/src/schedule/photo_processor/deferred_photo_processor.cpp @@ -115,6 +115,7 @@ void DeferredPhotoProcessor::OnProcessDone(int userId, const std::string& imageI if ((repository_->GetJobPriority(imageId) != PhotoJobPriority::HIGH)) { DP_INFO_LOG("not high quality and not high priority, need retry"); repository_->SetJobPending(imageId); + bufferInfo->ReleaseBuffer(); return; } else { DP_INFO_LOG("not high quality, but high priority, and process as normal job before, need retry");