diff --git a/camera_hdf/hdi_impl/include/dcamera_device/dcamera_device.h b/camera_hdf/hdi_impl/include/dcamera_device/dcamera_device.h index ecf84d179fe63504997e550e0792f3e66083e61e..64e08ee9869c7ff302156a6556e3189948b63536 100644 --- a/camera_hdf/hdi_impl/include/dcamera_device/dcamera_device.h +++ b/camera_hdf/hdi_impl/include/dcamera_device/dcamera_device.h @@ -63,7 +63,8 @@ private: DCamRetCode CreateDStreamOperator(); std::string GenerateCameraId(const DHBase &dhBase); void NotifyStartCaptureError(); - void NotifyCameraError(const std::shared_ptr &event); + void NotifyCameraError(const ErrorType type); + void IsOpenSessFailedState(bool state); private: bool isOpened_; std::string dCameraId_; diff --git a/camera_hdf/hdi_impl/include/utils/constants.h b/camera_hdf/hdi_impl/include/utils/constants.h index fd3b6928217b82485a900638dca0af70f711472d..b022c0e2fc85d3fbe8c5924b69c9d7fd58100f10 100644 --- a/camera_hdf/hdi_impl/include/utils/constants.h +++ b/camera_hdf/hdi_impl/include/utils/constants.h @@ -83,6 +83,10 @@ typedef enum { DCAMERA_EVENT_START_CAPTURE_ERROR = -6, DCAMERA_EVENT_STOP_CAPTURE_ERROR = -7, DCAMERA_EVENT_UPDATE_SETTINGS_ERROR = -8, + DCAMERA_EVENT_DEVICE_ERROR = -9, + DCAMERA_EVENT_DEVICE_PREEMPT = -10, + DCAMERA_EVENT_DEVICE_IN_USE = -11, + DCAMERA_EVENT_NO_PERMISSION = -12, } DCameraEventResult; enum DCameraBufferUsage : uint64_t { diff --git a/camera_hdf/hdi_impl/src/dcamera_device/dcamera_device.cpp b/camera_hdf/hdi_impl/src/dcamera_device/dcamera_device.cpp index dc9c03e41a51b3160bf0bf8d71db969e39899870..c53287227f13ceba40f0c18ddda8726ed048c03f 100644 --- a/camera_hdf/hdi_impl/src/dcamera_device/dcamera_device.cpp +++ b/camera_hdf/hdi_impl/src/dcamera_device/dcamera_device.cpp @@ -377,26 +377,15 @@ DCamRetCode DCameraDevice::Notify(const std::shared_ptr &event) } switch (event->result_) { case DCameraEventResult::DCAMERA_EVENT_CHANNEL_CONNECTED: { - { - unique_lock lock(isOpenSessFailedlock_); - isOpenSessFailed_ = false; - } - openSessCV_.notify_one(); + IsOpenSessFailedState(false); break; } case DCameraEventResult::DCAMERA_EVENT_OPEN_CHANNEL_ERROR: { - { - unique_lock lock(isOpenSessFailedlock_); - isOpenSessFailed_ = true; - } - openSessCV_.notify_one(); + IsOpenSessFailedState(true); break; } case DCameraEventResult::DCAMERA_EVENT_CHANNEL_DISCONNECTED: { - if (dCameraDeviceCallback_ != nullptr) { - dCameraDeviceCallback_->OnError(ErrorType::FATAL_ERROR, 0); - Close(); - } + NotifyCameraError(ErrorType::DEVICE_DISCONNECT); break; } case DCameraEventResult::DCAMERA_EVENT_CONFIG_STREAMS_ERROR: @@ -404,8 +393,20 @@ DCamRetCode DCameraDevice::Notify(const std::shared_ptr &event) NotifyStartCaptureError(); break; } - case DCameraEventResult::DCAMERA_EVENT_CAMERA_ERROR: { - NotifyCameraError(event); + case DCameraEventResult::DCAMERA_EVENT_DEVICE_ERROR: { + NotifyCameraError(ErrorType::DRIVER_ERROR); + break; + } + case DCameraEventResult::DCAMERA_EVENT_DEVICE_PREEMPT: { + NotifyCameraError(ErrorType::DEVICE_PREEMPT); + break; + } + case DCameraEventResult::DCAMERA_EVENT_DEVICE_IN_USE: { + NotifyCameraError(ErrorType::DCAMERA_ERROR_DEVICE_IN_USE); + break; + } + case DCameraEventResult::DCAMERA_EVENT_NO_PERMISSION: { + NotifyCameraError(ErrorType::DCAMERA_ERROR_NO_PERMISSION); break; } default: @@ -414,6 +415,15 @@ DCamRetCode DCameraDevice::Notify(const std::shared_ptr &event) return SUCCESS; } +void DCameraDevice::IsOpenSessFailedState(bool state) +{ + { + unique_lock lock(isOpenSessFailedlock_); + isOpenSessFailed_ = state; + } + openSessCV_.notify_one(); +} + void DCameraDevice::NotifyStartCaptureError() { if (dCameraDeviceCallback_ != nullptr) { @@ -429,14 +439,10 @@ void DCameraDevice::NotifyStartCaptureError() } } -void DCameraDevice::NotifyCameraError(const std::shared_ptr &event) +void DCameraDevice::NotifyCameraError(const ErrorType type) { - std::shared_ptr dCameraHost = DCameraHost::GetInstance(); - if (dCameraHost != nullptr) { - dCameraHost->NotifyDCameraStatus(dhBase_, event->result_); - } if (dCameraDeviceCallback_ != nullptr) { - dCameraDeviceCallback_->OnError(ErrorType::REQUEST_TIMEOUT, 0); + dCameraDeviceCallback_->OnError(type, 0); Close(); } } diff --git a/common/include/constants/distributed_camera_constants.h b/common/include/constants/distributed_camera_constants.h index eddb2f5b9d706d0257d47392181f293ae9b3ec60..bf517f2ff9a2844442ee85ad714937276f19314a 100644 --- a/common/include/constants/distributed_camera_constants.h +++ b/common/include/constants/distributed_camera_constants.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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 @@ -58,6 +58,10 @@ typedef enum { DCAMERA_EVENT_START_CAPTURE_ERROR = -6, DCAMERA_EVENT_STOP_CAPTURE_ERROR = -7, DCAMERA_EVENT_UPDATE_SETTINGS_ERROR = -8, + DCAMERA_EVENT_DEVICE_ERROR = -9, + DCAMERA_EVENT_DEVICE_PREEMPT = -10, + DCAMERA_EVENT_DEVICE_IN_USE = -11, + DCAMERA_EVENT_NO_PERMISSION = -12, } DCameraEventResult; typedef enum { diff --git a/common/include/constants/distributed_camera_errno.h b/common/include/constants/distributed_camera_errno.h index 0a1f7e99d39929a8209fe2e3780cc1cbf13e4509..1e2929eee22efd50cdacf657f375b1561d818406 100644 --- a/common/include/constants/distributed_camera_errno.h +++ b/common/include/constants/distributed_camera_errno.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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 @@ -33,6 +33,8 @@ namespace DistributedHardware { DCAMERA_INDEX_OVERFLOW = -11, DCAMERA_REGIST_HAL_FAILED = -12, DCAMERA_UNREGIST_HAL_FAILED = -13, + DCAMERA_ALLOC_ERROR = -14, + DCAMERA_DEVICE_BUSY = -15, }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/cameraoperator/client/BUILD.gn b/services/cameraservice/cameraoperator/client/BUILD.gn index 0562699e33979d69dad083f5cd8408cb04208809..fcf2a64407b405f7aa632bf152ed9fb649655008 100644 --- a/services/cameraservice/cameraoperator/client/BUILD.gn +++ b/services/cameraservice/cameraoperator/client/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# 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 @@ -18,7 +18,9 @@ import( ohos_shared_library("distributed_camera_client") { include_dirs = [ - "//drivers/peripheral/camera/interfaces/metadata/include", + "${camera_hdf_path}/camera/interfaces/metadata/include", + "${camera_hdf_path}/camera/interfaces/include", + "${camera_hdf_path}/camera/interfaces/hdi_ipc", "//utils/native/base/include", "//utils/system/safwk/native/include", "${graphicstandard_path}/frameworks/surface/include", diff --git a/services/cameraservice/cameraoperator/client/include/dcamera_client.h b/services/cameraservice/cameraoperator/client/include/dcamera_client.h index e7342175599df2e01da8c38653fc478549a8ea13..b71727d615f12353872e805de50bde451205d25f 100644 --- a/services/cameraservice/cameraoperator/client/include/dcamera_client.h +++ b/services/cameraservice/cameraoperator/client/include/dcamera_client.h @@ -57,6 +57,7 @@ private: int32_t StartVideoOutput(); void SetQualityAndGpsLocation(const std::shared_ptr& cameraMetadata, std::shared_ptr& photoCaptureSettings); + int32_t CameraServiceErrorType(const int32_T errorType); void ReleasCaptureSession(); bool isInit_; diff --git a/services/cameraservice/cameraoperator/client/src/callback/dcamera_input_callback.cpp b/services/cameraservice/cameraoperator/client/src/callback/dcamera_input_callback.cpp index 34f62a416a0a3366d05916a1c388c69fdaefe6aa..de24c0b91af640345194a3a38c825090de8756e8 100644 --- a/services/cameraservice/cameraoperator/client/src/callback/dcamera_input_callback.cpp +++ b/services/cameraservice/cameraoperator/client/src/callback/dcamera_input_callback.cpp @@ -36,7 +36,7 @@ void DCameraInputCallback::OnError(const int32_t errorType, const int32_t errorM std::shared_ptr event = std::make_shared(); event->eventType_ = DCAMERA_MESSAGE; - event->eventResult_ = DCAMERA_EVENT_CAMERA_ERROR; + event->eventResult_ = DCAMERA_EVENT_DEVICE_ERROR; callback_->OnStateChanged(event); } diff --git a/services/cameraservice/cameraoperator/client/src/callback/dcamera_photo_callback.cpp b/services/cameraservice/cameraoperator/client/src/callback/dcamera_photo_callback.cpp index 1ad5ca507ca09325956e0dcdb6c82f358f9bad5a..bd0cc0e3a470636027f130262f85059acfab5604 100644 --- a/services/cameraservice/cameraoperator/client/src/callback/dcamera_photo_callback.cpp +++ b/services/cameraservice/cameraoperator/client/src/callback/dcamera_photo_callback.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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 @@ -49,7 +49,7 @@ void DCameraPhotoCallback::OnCaptureError(const int32_t captureId, const int32_t std::shared_ptr event = std::make_shared(); event->eventType_ = DCAMERA_MESSAGE; - event->eventResult_ = DCAMERA_EVENT_CAMERA_ERROR; + event->eventResult_ = DCAMERA_EVENT_DEVICE_ERROR; callback_->OnStateChanged(event); } } // namespace DistributedHardware diff --git a/services/cameraservice/cameraoperator/client/src/callback/dcamera_preview_callback.cpp b/services/cameraservice/cameraoperator/client/src/callback/dcamera_preview_callback.cpp index 06aeef6577772c32f961233609c22457793c485b..730a35a373b0525f55dfc1e02989e3909604d4bf 100644 --- a/services/cameraservice/cameraoperator/client/src/callback/dcamera_preview_callback.cpp +++ b/services/cameraservice/cameraoperator/client/src/callback/dcamera_preview_callback.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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 @@ -44,7 +44,7 @@ void DCameraPreviewCallback::OnError(const int32_t errorCode) const std::shared_ptr event = std::make_shared(); event->eventType_ = DCAMERA_MESSAGE; - event->eventResult_ = DCAMERA_EVENT_CAMERA_ERROR; + event->eventResult_ = DCAMERA_EVENT_DEVICE_ERROR; callback_->OnStateChanged(event); } } // namespace DistributedHardware diff --git a/services/cameraservice/cameraoperator/client/src/callback/dcamera_session_callback.cpp b/services/cameraservice/cameraoperator/client/src/callback/dcamera_session_callback.cpp index a1b1aee616a65712b95ce28b376f0066cf25a8d8..8785bcc1dd8ef65e681a8f8a3d8e8a2e6939e05a 100644 --- a/services/cameraservice/cameraoperator/client/src/callback/dcamera_session_callback.cpp +++ b/services/cameraservice/cameraoperator/client/src/callback/dcamera_session_callback.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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 @@ -34,7 +34,7 @@ void DCameraSessionCallback::OnError(int32_t errorCode) std::shared_ptr event = std::make_shared(); event->eventType_ = DCAMERA_MESSAGE; - event->eventResult_ = DCAMERA_EVENT_CAMERA_ERROR; + event->eventResult_ = DCAMERA_EVENT_DEVICE_ERROR; callback_->OnStateChanged(event); } } // namespace DistributedHardware diff --git a/services/cameraservice/cameraoperator/client/src/callback/dcamera_video_callback.cpp b/services/cameraservice/cameraoperator/client/src/callback/dcamera_video_callback.cpp index 2e938fa91c390d8a8c37b826cc01e463a09c0a07..a94acd628243703e56c04d399b5c0714a16b95cc 100644 --- a/services/cameraservice/cameraoperator/client/src/callback/dcamera_video_callback.cpp +++ b/services/cameraservice/cameraoperator/client/src/callback/dcamera_video_callback.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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 @@ -44,7 +44,7 @@ void DCameraVideoCallback::OnError(const int32_t errorCode) const std::shared_ptr event = std::make_shared(); event->eventType_ = DCAMERA_MESSAGE; - event->eventResult_ = DCAMERA_EVENT_CAMERA_ERROR; + event->eventResult_ = DCAMERA_EVENT_DEVICE_ERROR; callback_->OnStateChanged(event); } } // namespace DistributedHardware diff --git a/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp b/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp index f33fed23ef1fdba610035ea39a21a5e8b3113eee..d675f07cf997710ab43362fdcebd9adcdffa8d63 100644 --- a/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp +++ b/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp @@ -17,6 +17,7 @@ #include #include "anonymous_string.h" +#include "camera_util.h" #include "camera_metadata_operator.h" #include "dcamera_input_callback.h" #include "dcamera_manager_callback.h" @@ -152,7 +153,7 @@ int32_t DCameraClient::StartCapture(std::vector& event) { DHLOGI("DCameraSinkController::OnStateChanged dhId: %s, result: %d", GetAnonyString(dhId_).c_str(), event->eventResult_); - DCameraNotifyInner(DCAMERA_MESSAGE, DCAMERA_EVENT_CAMERA_ERROR, std::string("camera error")); + DCameraNotifyInner(DCAMERA_MESSAGE, DCAMERA_EVENT_DEVICE_ERROR, std::string("camera error")); } void DCameraSinkController::OnMetadataResult(std::vector>& settings) @@ -418,7 +418,7 @@ int32_t DCameraSinkController::StartCaptureInner(std::vector