From 2aef6ca804abd68b6624d30b301407f030d48780 Mon Sep 17 00:00:00 2001 From: qano Date: Tue, 19 Dec 2023 16:03:22 +0800 Subject: [PATCH] add CanAddXXX interface Signed-off-by: qano --- .../camera/src/input/camera_manager.cpp | 42 +++++++---- .../camera/src/output/capture_output.cpp | 12 +++ .../camera/src/session/capture_session.cpp | 73 ++++++++++++++++--- .../camera/src/session/night_session.cpp | 32 ++++++++ .../camera/src/session/photo_session.cpp | 15 +--- .../camera/src/session/portrait_session.cpp | 31 ++++++++ .../camera/src/session/scan_session.cpp | 32 ++++++++ .../camera/src/session/video_session.cpp | 16 ---- .../camera/include/input/camera_manager.h | 1 + .../include/output/camera_output_capability.h | 5 ++ .../camera/include/output/capture_output.h | 3 + .../camera/include/session/night_session.h | 7 ++ .../camera/include/session/photo_session.h | 7 -- .../camera/include/session/portrait_session.h | 7 ++ .../camera/include/session/scan_session.h | 7 ++ .../camera/include/session/video_session.h | 13 ---- .../camera_service_ipc_interface_code.h | 1 + .../binder/base/include/icapture_session.h | 2 + .../client/include/hcapture_session_proxy.h | 2 + .../client/src/hcapture_session_proxy.cpp | 26 +++++++ .../server/include/hcapture_session_stub.h | 1 + .../server/src/hcapture_session_stub.cpp | 17 +++++ .../camera_service/include/hcapture_session.h | 1 + .../camera_service/src/hcapture_session.cpp | 24 ++++++ 24 files changed, 301 insertions(+), 76 deletions(-) diff --git a/frameworks/native/camera/src/input/camera_manager.cpp b/frameworks/native/camera/src/input/camera_manager.cpp index 71909f5e4..fc22b7dc2 100644 --- a/frameworks/native/camera/src/input/camera_manager.cpp +++ b/frameworks/native/camera/src/input/camera_manager.cpp @@ -541,6 +541,7 @@ int CameraManager::CreateVideoOutput(VideoProfile &profile, sptr &surfa if (videoFrameRates.size() >= 2) { // vaild frame rate range length is 2 videoOutput->SetFrameRateRange(videoFrameRates[0], videoFrameRates[1]); } + videoOutput->SetVideoProfile(profile); POWERMGR_SYSEVENT_CAMERA_CONFIG(VIDEO, profile.GetSize().width, profile.GetSize().height); @@ -765,12 +766,6 @@ void CameraManager::InitCameraList() tempDmDeviceInfo.networkId = ""; } cameraObj = new(std::nothrow) CameraDevice(it, cameraAbilityList[index++], tempDmDeviceInfo); - int32_t portraitMode = 3; - sptr capability = GetSupportedOutputCapability(cameraObj, portraitMode); - if (capability != nullptr) { - cameraObj->modePreviewProfiles_[portraitMode] = capability->GetPreviewProfiles(); - cameraObj->modePhotoProfiles_[portraitMode] = capability->GetPhotoProfiles(); - } cameraObjList.emplace_back(cameraObj); } } else { @@ -816,17 +811,8 @@ void CameraManager::AlignVideoFpsProfile(std::vector>& camera std::vector frontVideoProfiles = {}; std::vector backVideoProfiles = {}; sptr frontCamera = nullptr; - std::vector modes = {0, 3}; - sptr capability = nullptr; for (auto& camera : cameraObjList) { - for (auto &mode : modes) { - capability = GetSupportedOutputCapability(camera, mode); - if (capability != nullptr) { - camera->modePreviewProfiles_[mode] = capability->GetPreviewProfiles(); - camera->modePhotoProfiles_[mode] = capability->GetPhotoProfiles(); - camera->modeVideoProfiles_[mode] = capability->GetVideoProfiles(); - } - } + SetProfile(camera); if (camera->GetPosition() == CAMERA_POSITION_FRONT) { frontVideoProfiles = camera->modeVideoProfiles_[normalMode]; frontCamera = camera; @@ -867,6 +853,30 @@ void CameraManager::AlignVideoFpsProfile(std::vector>& camera } } +void CameraManager::SetProfile(sptr& cameraObj) +{ + std::vector supportedModes = GetSupportedModes(cameraObj); + sptr capability = nullptr; + if (supportedModes.empty()) { + capability = GetSupportedOutputCapability(cameraObj); + if (capability != nullptr) { + cameraObj->modePreviewProfiles_[0] = capability->GetPreviewProfiles(); + cameraObj->modePhotoProfiles_[0] = capability->GetPhotoProfiles(); + cameraObj->modeVideoProfiles_[0] = capability->GetVideoProfiles(); + } + } else { + for (auto &modeName : GetSupportedModes(cameraObj)) { + int32_t mode = isTemplateMode_.count(modeName) ? SceneMode::NORMAL : modeName; + capability = GetSupportedOutputCapability(cameraObj, mode); + if (capability != nullptr) { + cameraObj->modePreviewProfiles_[mode] = capability->GetPreviewProfiles(); + cameraObj->modePhotoProfiles_[mode] = capability->GetPhotoProfiles(); + cameraObj->modeVideoProfiles_[mode] = capability->GetVideoProfiles(); + } + } + } +} + sptr CameraManager::CreateCameraInput(sptr &camera) { CAMERA_SYNC_TRACE; diff --git a/frameworks/native/camera/src/output/capture_output.cpp b/frameworks/native/camera/src/output/capture_output.cpp index cb457b8d3..f66a81699 100644 --- a/frameworks/native/camera/src/output/capture_output.cpp +++ b/frameworks/native/camera/src/output/capture_output.cpp @@ -95,6 +95,7 @@ Profile CaptureOutput::GetPhotoProfile() { return photoProfile_; } + int32_t CaptureOutput::SetPreviewProfile(Profile &profile) { previewProfile_ = profile; @@ -105,5 +106,16 @@ Profile CaptureOutput::GetPreviewProfile() { return previewProfile_; } + +int32_t CaptureOutput::SetVideoProfile(VideoProfile &videoProfile) +{ + videoProfile_ = videoProfile; + return 0; +} + +VideoProfile CaptureOutput::GetVideoProfile() +{ + return videoProfile_; +} } // CameraStandard } // OHOS diff --git a/frameworks/native/camera/src/session/capture_session.cpp b/frameworks/native/camera/src/session/capture_session.cpp index 96012a75e..c9761714c 100644 --- a/frameworks/native/camera/src/session/capture_session.cpp +++ b/frameworks/native/camera/src/session/capture_session.cpp @@ -392,9 +392,20 @@ void CaptureSession::SetDefaultColorSpace() bool CaptureSession::CanAddInput(sptr &input) { - // todo: get Profile passed to createOutput and compare with OutputCapability - // if present in capability return ok. - return true; + // can only add one cameraInput + CAMERA_SYNC_TRACE; + bool ret = false; + MEDIA_INFO_LOG("Enter Into CaptureSession::CanAddInput"); + if (!IsSessionConfiged() || input == nullptr) { + MEDIA_ERR_LOG("CaptureSession::AddInput operation Not allowed!"); + return ret; + } + if (captureSession_) { + captureSession_->CanAddInput(((sptr &)input)->GetCameraDevice(), ret); + } else { + MEDIA_ERR_LOG("CaptureSession::CanAddInput() captureSession_ is nullptr"); + } + return ret; } int32_t CaptureSession::AddInput(sptr &input) @@ -409,13 +420,14 @@ int32_t CaptureSession::AddInput(sptr &input) MEDIA_ERR_LOG("CaptureSession::AddInput input is null"); return ServiceToCameraError(CAMERA_INVALID_ARG); } - input->SetSession(this); - inputDevice_ = input; int32_t errCode = CAMERA_UNKNOWN_ERROR; if (captureSession_) { errCode = captureSession_->AddInput(((sptr &)input)->GetCameraDevice()); if (errCode != CAMERA_OK) { MEDIA_ERR_LOG("Failed to AddInput!, %{public}d", errCode); + } else { + input->SetSession(this); + inputDevice_ = input; } } else { MEDIA_ERR_LOG("CaptureSession::AddInput() captureSession_ is nullptr"); @@ -423,13 +435,6 @@ int32_t CaptureSession::AddInput(sptr &input) return ServiceToCameraError(errCode); } -bool CaptureSession::CanAddOutput(sptr &output) -{ - // todo: get Profile passed to createOutput and compare with OutputCapability - // if present in capability return ok. - return true; -} - sptr CaptureSession::GetMetaOutput() { MEDIA_DEBUG_LOG("CaptureSession::GetMetadataOutput metaOuput(%{public}d)", metaOutput_ != nullptr); @@ -502,6 +507,10 @@ int32_t CaptureSession::AddOutput(sptr& output) metaOutput_ = output; return ServiceToCameraError(CAMERA_OK); } + if (!CanAddOutput(output)) { + MEDIA_ERR_LOG("CanAddOutput check failed!"); + return ServiceToCameraError(CAMERA_INVALID_ARG); + } int32_t errCode = CAMERA_UNKNOWN_ERROR; if (captureSession_ == nullptr) { MEDIA_ERR_LOG("CaptureSession::AddOutput() captureSession_ is nullptr"); @@ -517,6 +526,46 @@ int32_t CaptureSession::AddOutput(sptr& output) return ServiceToCameraError(errCode); } +bool CaptureSession::CanAddOutput(sptr &output) +{ + CAMERA_SYNC_TRACE; + MEDIA_DEBUG_LOG("Enter Into CaptureSession::CanAddOutput"); + if (!IsSessionConfiged() || output == nullptr) { + MEDIA_ERR_LOG("CaptureSession::CanAddOutput operation Not allowed!"); + return false; + } + int32_t normalMode = 0; + if (output->GetOutputType() == CAPTURE_OUTPUT_TYPE_PREVIEW) { + std::vector previewProfiles = inputDevice_->GetCameraDeviceInfo()->modePreviewProfiles_[normalMode]; + Profile vaildateProfile = output->GetPreviewProfile(); + for (auto& previewProfile : previewProfiles) { + if (vaildateProfile == previewProfile) { + return true; + } + } + } else if (output->GetOutputType() == CAPTURE_OUTPUT_TYPE_PHOTO) { + std::vector photoProfiles = inputDevice_->GetCameraDeviceInfo()->modePhotoProfiles_[normalMode]; + Profile vaildateProfile = output->GetPhotoProfile(); + for (auto& photoProfile : photoProfiles) { + if (vaildateProfile == photoProfile) { + return true; + } + } + } else if (output->GetOutputType() == CAPTURE_OUTPUT_TYPE_VIDEO) { + std::vector videoProfiles = inputDevice_->GetCameraDeviceInfo()->modeVideoProfiles_[normalMode]; + VideoProfile vaildateProfile = output->GetVideoProfile(); + for (auto& videoProfile : videoProfiles) { + if (vaildateProfile == videoProfile) { + return true; + } + } + } else if (output->GetOutputType() == CAPTURE_OUTPUT_TYPE_METADATA) { + MEDIA_INFO_LOG("CaptureSession::CanAddOutput MetadataOutput"); + return true; + } + return false; +} + int32_t CaptureSession::RemoveInput(sptr &input) { CAMERA_SYNC_TRACE; diff --git a/frameworks/native/camera/src/session/night_session.cpp b/frameworks/native/camera/src/session/night_session.cpp index 8cf700522..c01367f6e 100644 --- a/frameworks/native/camera/src/session/night_session.cpp +++ b/frameworks/native/camera/src/session/night_session.cpp @@ -126,5 +126,37 @@ void NightSession::ProcessCallbacks(const uint64_t timestamp, ProcessFaceRecUpdates(timestamp, result); ProcessAutoFocusUpdates(result); } + +bool NightSession::CanAddOutput(sptr &output) +{ + CAMERA_SYNC_TRACE; + MEDIA_DEBUG_LOG("Enter Into NightSession::CanAddOutput"); + if (!IsSessionConfiged() || output == nullptr) { + MEDIA_ERR_LOG("ScanSession::CanAddOutput operation Not allowed!"); + return false; + } + int32_t night = 4; + if (output->GetOutputType() == CAPTURE_OUTPUT_TYPE_PREVIEW) { + std::vector previewProfiles = inputDevice_->GetCameraDeviceInfo()->modePreviewProfiles_[night]; + Profile vaildateProfile = output->GetPreviewProfile(); + for (auto& previewProfile : previewProfiles) { + if (vaildateProfile == previewProfile) { + return true; + } + } + } else if (output->GetOutputType() == CAPTURE_OUTPUT_TYPE_PHOTO) { + std::vector photoProfiles = inputDevice_->GetCameraDeviceInfo()->modePhotoProfiles_[night]; + Profile vaildateProfile = output->GetPhotoProfile(); + for (auto& photoProfile : photoProfiles) { + if (vaildateProfile == photoProfile) { + return true; + } + } + } else if (output->GetOutputType() == CAPTURE_OUTPUT_TYPE_METADATA) { + MEDIA_INFO_LOG("ScanSession::CanAddOutput MetadataOutput"); + return true; + } + return false; +} } // CameraStandard } // OHOS diff --git a/frameworks/native/camera/src/session/photo_session.cpp b/frameworks/native/camera/src/session/photo_session.cpp index 17b9c9397..f2bcde865 100644 --- a/frameworks/native/camera/src/session/photo_session.cpp +++ b/frameworks/native/camera/src/session/photo_session.cpp @@ -26,21 +26,12 @@ namespace CameraStandard { PhotoSession::~PhotoSession() { } - -bool PhotoSession::CanAddInput(sptr &input) -{ - // todo: get Profile passed to createOutput and compare with OutputCapability - // if present in capability return ok. - MEDIA_INFO_LOG("Enter Into PhotoSession::CanAddInput"); - return true; -} bool PhotoSession::CanAddOutput(sptr &output) { - // todo: get Profile passed to createOutput and compare with OutputCapability - // if present in capability return ok. - MEDIA_INFO_LOG("Enter Into PhotoSession::CanAddOutput"); - return true; + CAMERA_SYNC_TRACE; + MEDIA_DEBUG_LOG("Enter Into PhotoSession::CanAddOutput"); + return output->GetOutputType() != CAPTURE_OUTPUT_TYPE_VIDEO && CaptureSession::CanAddOutput(output); } } // namespace CameraStandard } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/camera/src/session/portrait_session.cpp b/frameworks/native/camera/src/session/portrait_session.cpp index 14f160f17..c45cf74a3 100644 --- a/frameworks/native/camera/src/session/portrait_session.cpp +++ b/frameworks/native/camera/src/session/portrait_session.cpp @@ -147,5 +147,36 @@ void PortraitSession::SetPortraitEffect(PortraitEffect portraitEffect) } return; } +bool PortraitSession::CanAddOutput(sptr &output) +{ + CAMERA_SYNC_TRACE; + MEDIA_DEBUG_LOG("Enter Into PortraitSession::CanAddOutput"); + if (!IsSessionConfiged() || output == nullptr) { + MEDIA_ERR_LOG("PortraitSession::CanAddOutput operation Not allowed!"); + return false; + } + int32_t portrait = 3; + if (output->GetOutputType() == CAPTURE_OUTPUT_TYPE_PREVIEW) { + std::vector previewProfiles = inputDevice_->GetCameraDeviceInfo()->modePreviewProfiles_[portrait]; + Profile vaildateProfile = output->GetPreviewProfile(); + for (auto& previewProfile : previewProfiles) { + if (vaildateProfile == previewProfile) { + return true; + } + } + } else if (output->GetOutputType() == CAPTURE_OUTPUT_TYPE_PHOTO) { + std::vector photoProfiles = inputDevice_->GetCameraDeviceInfo()->modePhotoProfiles_[portrait]; + Profile vaildateProfile = output->GetPhotoProfile(); + for (auto& photoProfile : photoProfiles) { + if (vaildateProfile == photoProfile) { + return true; + } + } + } else if (output->GetOutputType() == CAPTURE_OUTPUT_TYPE_METADATA) { + MEDIA_INFO_LOG("PortraitSession::CanAddOutput MetadataOutput"); + return true; + } + return false; +} } // CameraStandard } // OHOS diff --git a/frameworks/native/camera/src/session/scan_session.cpp b/frameworks/native/camera/src/session/scan_session.cpp index c78f8a577..fcb711139 100644 --- a/frameworks/native/camera/src/session/scan_session.cpp +++ b/frameworks/native/camera/src/session/scan_session.cpp @@ -53,5 +53,37 @@ int32_t ScanSession::AddOutput(sptr &output) } return result; } + +bool ScanSession::CanAddOutput(sptr &output) +{ + CAMERA_SYNC_TRACE; + MEDIA_DEBUG_LOG("Enter Into ScanSession::CanAddOutput"); + if (!IsSessionConfiged() || output == nullptr) { + MEDIA_ERR_LOG("ScanSession::CanAddOutput operation Not allowed!"); + return false; + } + int32_t scan = 7; + if (output->GetOutputType() == CAPTURE_OUTPUT_TYPE_PREVIEW) { + std::vector previewProfiles = inputDevice_->GetCameraDeviceInfo()->modePreviewProfiles_[scan]; + Profile vaildateProfile = output->GetPreviewProfile(); + for (auto& previewProfile : previewProfiles) { + if (vaildateProfile == previewProfile) { + return true; + } + } + } else if (output->GetOutputType() == CAPTURE_OUTPUT_TYPE_PHOTO) { + std::vector photoProfiles = inputDevice_->GetCameraDeviceInfo()->modePhotoProfiles_[scan]; + Profile vaildateProfile = output->GetPhotoProfile(); + for (auto& photoProfile : photoProfiles) { + if (vaildateProfile == photoProfile) { + return true; + } + } + } else if (output->GetOutputType() == CAPTURE_OUTPUT_TYPE_METADATA) { + MEDIA_INFO_LOG("ScanSession::CanAddOutput MetadataOutput"); + return true; + } + return false; +} } // namespace CameraStandard } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/camera/src/session/video_session.cpp b/frameworks/native/camera/src/session/video_session.cpp index 08e2595a4..2beec6017 100644 --- a/frameworks/native/camera/src/session/video_session.cpp +++ b/frameworks/native/camera/src/session/video_session.cpp @@ -26,21 +26,5 @@ namespace CameraStandard { VideoSession::~VideoSession() { } - -bool VideoSession::CanAddInput(sptr &input) -{ - // todo: get Profile passed to createOutput and compare with OutputCapability - // if present in capability return ok. - MEDIA_INFO_LOG("Enter Into VideoSession::CanAddInput"); - return true; -} - -bool VideoSession::CanAddOutput(sptr &output) -{ - // todo: get Profile passed to createOutput and compare with OutputCapability - // if present in capability return ok. - MEDIA_INFO_LOG("Enter Into VideoSession::CanAddOutput"); - return true; -} } // namespace CameraStandard } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_api/native/camera/include/input/camera_manager.h b/interfaces/inner_api/native/camera/include/input/camera_manager.h index 380d44ba9..3b27d38ba 100644 --- a/interfaces/inner_api/native/camera/include/input/camera_manager.h +++ b/interfaces/inner_api/native/camera/include/input/camera_manager.h @@ -604,6 +604,7 @@ private: void ParseBasicCapability(sptr cameraOutputCapability, std::shared_ptr metadata, const camera_metadata_item_t &item); void AlignVideoFpsProfile(std::vector>& cameraObjList); + void SetProfile(sptr& cameraObj); std::mutex mutex_; std::mutex cameraListMutex_; std::mutex vectorMutex_; diff --git a/interfaces/inner_api/native/camera/include/output/camera_output_capability.h b/interfaces/inner_api/native/camera/include/output/camera_output_capability.h index 4f6dde8ca..4f68c4269 100644 --- a/interfaces/inner_api/native/camera/include/output/camera_output_capability.h +++ b/interfaces/inner_api/native/camera/include/output/camera_output_capability.h @@ -62,6 +62,11 @@ public: } return *this; } + bool operator==(const Profile& profile) + { + return this->format_ == profile.format_ && this->size_.width == profile.size_.width && + this->size_.height == profile.size_.height; + } virtual ~Profile() = default; /** 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 99a7276b8..b027dc490 100644 --- a/interfaces/inner_api/native/camera/include/output/capture_output.h +++ b/interfaces/inner_api/native/camera/include/output/capture_output.h @@ -78,6 +78,8 @@ public: Profile GetPhotoProfile(); int32_t SetPreviewProfile(Profile& profile); Profile GetPreviewProfile(); + int32_t SetVideoProfile(VideoProfile& videoProfile); + VideoProfile GetVideoProfile(); virtual void CameraServerDied(pid_t pid) = 0; protected: @@ -90,6 +92,7 @@ private: wptr session_; Profile photoProfile_; Profile previewProfile_; + VideoProfile videoProfile_; }; } // namespace CameraStandard } // namespace OHOS diff --git a/interfaces/inner_api/native/camera/include/session/night_session.h b/interfaces/inner_api/native/camera/include/session/night_session.h index 1de1dddd2..350c8b77c 100644 --- a/interfaces/inner_api/native/camera/include/session/night_session.h +++ b/interfaces/inner_api/native/camera/include/session/night_session.h @@ -57,6 +57,13 @@ public: */ int32_t GetExposure(uint32_t &exposureValue); + /** + * @brief Determine if the given Ouput can be added to session. + * + * @param CaptureOutput to be added to session. + */ + bool CanAddOutput(sptr& output) override; + void ProcessCallbacks(const uint64_t timestamp, const std::shared_ptr &result) override; }; diff --git a/interfaces/inner_api/native/camera/include/session/photo_session.h b/interfaces/inner_api/native/camera/include/session/photo_session.h index 287294206..bf80572ff 100644 --- a/interfaces/inner_api/native/camera/include/session/photo_session.h +++ b/interfaces/inner_api/native/camera/include/session/photo_session.h @@ -26,13 +26,6 @@ public: explicit PhotoSession(sptr &photoSession): CaptureSession(photoSession) {} PhotoSession() {}; ~PhotoSession(); - - /** - * @brief Determine if the given Input can be added to session. - * - * @param CaptureInput to be added to session. - */ - bool CanAddInput(sptr& input) override; /** * @brief Determine if the given Ouput can be added to session. diff --git a/interfaces/inner_api/native/camera/include/session/portrait_session.h b/interfaces/inner_api/native/camera/include/session/portrait_session.h index 487f262bb..ac35ed946 100644 --- a/interfaces/inner_api/native/camera/include/session/portrait_session.h +++ b/interfaces/inner_api/native/camera/include/session/portrait_session.h @@ -64,6 +64,13 @@ public: */ void SetPortraitEffect(PortraitEffect effect); + /** + * @brief Determine if the given Ouput can be added to session. + * + * @param CaptureOutput to be added to session. + */ + bool CanAddOutput(sptr& output) override; + private: static const std::unordered_map metaToFwPortraitEffect_; static const std::unordered_map fwToMetaPortraitEffect_; diff --git a/interfaces/inner_api/native/camera/include/session/scan_session.h b/interfaces/inner_api/native/camera/include/session/scan_session.h index 51fc73638..d7b5f24c2 100644 --- a/interfaces/inner_api/native/camera/include/session/scan_session.h +++ b/interfaces/inner_api/native/camera/include/session/scan_session.h @@ -28,6 +28,13 @@ public: ~ScanSession(); int32_t AddOutput(sptr &output) override; + + /** + * @brief Determine if the given Ouput can be added to session. + * + * @param CaptureOutput to be added to session. + */ + bool CanAddOutput(sptr& output) override; }; } // namespace CameraStandard } // namespace OHOS diff --git a/interfaces/inner_api/native/camera/include/session/video_session.h b/interfaces/inner_api/native/camera/include/session/video_session.h index ade31fd91..a0aedec40 100644 --- a/interfaces/inner_api/native/camera/include/session/video_session.h +++ b/interfaces/inner_api/native/camera/include/session/video_session.h @@ -26,19 +26,6 @@ public: explicit VideoSession(sptr &videoSession): CaptureSession(videoSession) {} VideoSession() {}; ~VideoSession(); - /** - * @brief Determine if the given Input can be added to session. - * - * @param CaptureInput to be added to session. - */ - bool CanAddInput(sptr& input) override; - - /** - * @brief Determine if the given Ouput can be added to session. - * - * @param CaptureOutput to be added to session. - */ - bool CanAddOutput(sptr& output) override; }; } // namespace CameraStandard } // namespace OHOS diff --git a/services/camera_service/binder/base/include/camera_service_ipc_interface_code.h b/services/camera_service/binder/base/include/camera_service_ipc_interface_code.h index 0c1d228d1..a6f4a7e9e 100644 --- a/services/camera_service/binder/base/include/camera_service_ipc_interface_code.h +++ b/services/camera_service/binder/base/include/camera_service_ipc_interface_code.h @@ -106,6 +106,7 @@ enum CameraServiceInterfaceCode { enum CaptureSessionInterfaceCode { CAMERA_CAPTURE_SESSION_BEGIN_CONFIG = 0, CAMERA_CAPTURE_SESSION_ADD_INPUT, + CAMERA_CAPTURE_SESSION_CAN_ADD_INPUT, CAMERA_CAPTURE_SESSION_ADD_OUTPUT, CAMERA_CAPTURE_SESSION_REMOVE_INPUT, CAMERA_CAPTURE_SESSION_REMOVE_OUTPUT, diff --git a/services/camera_service/binder/base/include/icapture_session.h b/services/camera_service/binder/base/include/icapture_session.h index 72527faef..b3cb1d8d7 100644 --- a/services/camera_service/binder/base/include/icapture_session.h +++ b/services/camera_service/binder/base/include/icapture_session.h @@ -56,6 +56,8 @@ public: virtual int32_t AddInput(sptr cameraDevice) = 0; + virtual int32_t CanAddInput(sptr cameraDevice, bool& result) = 0; + virtual int32_t AddOutput(StreamType streamType, sptr stream) = 0; virtual int32_t RemoveInput(sptr cameraDevice) = 0; diff --git a/services/camera_service/binder/client/include/hcapture_session_proxy.h b/services/camera_service/binder/client/include/hcapture_session_proxy.h index b37b1edb4..a61abf68a 100644 --- a/services/camera_service/binder/client/include/hcapture_session_proxy.h +++ b/services/camera_service/binder/client/include/hcapture_session_proxy.h @@ -29,6 +29,8 @@ public: int32_t BeginConfig() override; + int32_t CanAddInput(sptr cameraDevice, bool& result) override; + int32_t AddInput(sptr cameraDevice) override; int32_t AddOutput(StreamType streamType, sptr stream) override; diff --git a/services/camera_service/binder/client/src/hcapture_session_proxy.cpp b/services/camera_service/binder/client/src/hcapture_session_proxy.cpp index 7bfb1c9d5..ed39c8660 100644 --- a/services/camera_service/binder/client/src/hcapture_session_proxy.cpp +++ b/services/camera_service/binder/client/src/hcapture_session_proxy.cpp @@ -38,6 +38,32 @@ int32_t HCaptureSessionProxy::BeginConfig() return error; } +int32_t HCaptureSessionProxy::CanAddInput(sptr cameraDevice, bool& result) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (cameraDevice == nullptr) { + MEDIA_ERR_LOG("HCaptureSessionProxy CanAddInput cameraDevice is null"); + return IPC_PROXY_ERR; + } + + data.WriteInterfaceToken(GetDescriptor()); + data.WriteRemoteObject(cameraDevice->AsObject()); + (void)data.WriteBool(result); + + int error = Remote()->SendRequest( + static_cast(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_CAN_ADD_INPUT), data, reply, option); + if (error != ERR_NONE) { + MEDIA_ERR_LOG("HCaptureSessionProxy CanAddInput failed, error: %{public}d", error); + return error; + } + result = reply.ReadBool(); + MEDIA_DEBUG_LOG("CanAddInput result is %{public}d", result); + return error; +} + int32_t HCaptureSessionProxy::AddInput(sptr cameraDevice) { MessageParcel data; diff --git a/services/camera_service/binder/server/include/hcapture_session_stub.h b/services/camera_service/binder/server/include/hcapture_session_stub.h index efa900180..6ef69683f 100644 --- a/services/camera_service/binder/server/include/hcapture_session_stub.h +++ b/services/camera_service/binder/server/include/hcapture_session_stub.h @@ -29,6 +29,7 @@ public: int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; private: + int32_t HandleCanAddInput(MessageParcel& data, MessageParcel& reply); int32_t HandleAddInput(MessageParcel& data); int32_t HandleAddOutput(MessageParcel& data); int32_t HandleRemoveInput(MessageParcel& data); diff --git a/services/camera_service/binder/server/src/hcapture_session_stub.cpp b/services/camera_service/binder/server/src/hcapture_session_stub.cpp index 2704c4c99..ee833f598 100644 --- a/services/camera_service/binder/server/src/hcapture_session_stub.cpp +++ b/services/camera_service/binder/server/src/hcapture_session_stub.cpp @@ -34,6 +34,9 @@ int HCaptureSessionStub::OnRemoteRequest( case static_cast(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_BEGIN_CONFIG): errCode = BeginConfig(); break; + case static_cast(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_CAN_ADD_INPUT): + errCode = HCaptureSessionStub::HandleCanAddInput(data, reply); + break; case static_cast(CaptureSessionInterfaceCode::CAMERA_CAPTURE_SESSION_ADD_INPUT): errCode = HCaptureSessionStub::HandleAddInput(data); break; @@ -93,6 +96,20 @@ int32_t HCaptureSessionStub::HandleAddInput(MessageParcel &data) return AddInput(cameraDevice); } +int HCaptureSessionStub::HandleCanAddInput(MessageParcel &data, MessageParcel &reply) +{ + sptr remoteObj = data.ReadRemoteObject(); + CHECK_AND_RETURN_RET_LOG(remoteObj != nullptr, IPC_STUB_INVALID_DATA_ERR, + "HCaptureSessionStub HandleAddInput CameraDevice is null"); + sptr cameraDevice = iface_cast(remoteObj); + bool result = false; + int32_t ret = CanAddInput(cameraDevice, result); + MEDIA_INFO_LOG("HandleCanAddInput ret: %{public}d, result: %{public}d", ret, result); + CHECK_AND_RETURN_RET_LOG(reply.WriteBool(result), IPC_STUB_WRITE_PARCEL_ERR, + "HCameraServiceStub HandleCanAddInput Write result failed"); + return ret; +} + int32_t HCaptureSessionStub::HandleRemoveInput(MessageParcel &data) { sptr remoteObj = data.ReadRemoteObject(); diff --git a/services/camera_service/include/hcapture_session.h b/services/camera_service/include/hcapture_session.h index b05de531d..2de89e595 100644 --- a/services/camera_service/include/hcapture_session.h +++ b/services/camera_service/include/hcapture_session.h @@ -129,6 +129,7 @@ public: int32_t BeginConfig() override; int32_t CommitConfig() override; + int32_t CanAddInput(sptr cameraDevice, bool& result) override; int32_t AddInput(sptr cameraDevice) override; int32_t AddOutput(StreamType streamType, sptr stream) override; diff --git a/services/camera_service/src/hcapture_session.cpp b/services/camera_service/src/hcapture_session.cpp index a17142bad..48503eb3e 100644 --- a/services/camera_service/src/hcapture_session.cpp +++ b/services/camera_service/src/hcapture_session.cpp @@ -174,6 +174,30 @@ int32_t HCaptureSession::BeginConfig() return errCode; } +int32_t HCaptureSession::CanAddInput(sptr cameraDevice, bool& result) +{ + CAMERA_SYNC_TRACE; + int32_t errorCode = CAMERA_OK; + result = false; + stateMachine_.StateGuard([this, &errorCode](const CaptureSessionState currentState) { + if (currentState != CaptureSessionState::SESSION_CONFIG_INPROGRESS) { + MEDIA_ERR_LOG("HCaptureSession::CanAddInput Need to call BeginConfig before adding input"); + errorCode = CAMERA_INVALID_STATE; + return; + } + if ((GetCameraDevice() != nullptr)) { + MEDIA_ERR_LOG("HCaptureSession::CanAddInput Only one input is supported"); + errorCode = CAMERA_INVALID_SESSION_CFG; + return; + } + }); + if (errorCode == CAMERA_OK) { + result = true; + CAMERA_SYSEVENT_STATISTIC(CreateMsg("CaptureSession::CanAddInput")); + } + return errorCode; +} + int32_t HCaptureSession::AddInput(sptr cameraDevice) { CAMERA_SYNC_TRACE; -- Gitee