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 251e2f80458f16f72ae0cdd5bbaf59385471970c..a27827f9d643ee49c3ef476ba83cbec4a3ed5458 100644 --- a/frameworks/js/camera_napi/src/input/camera_manager_napi.cpp +++ b/frameworks/js/camera_napi/src/input/camera_manager_napi.cpp @@ -993,6 +993,10 @@ napi_value CameraManagerNapi::GetSupportedModes(napi_env env, napi_callback_info break; } } + if (modeObjList.empty()) { + modeObjList.emplace_back(CAPTURE); + modeObjList.emplace_back(VIDEO); + } MEDIA_INFO_LOG("CameraManagerNapi::GetSupportedModes size=[%{public}zu]", modeObjList.size()); jsResult = CreateJSArray(env, status, modeObjList); if (status == napi_ok) { diff --git a/frameworks/native/camera/src/input/camera_manager.cpp b/frameworks/native/camera/src/input/camera_manager.cpp index 9e7a7e9a3d6cf404bd9c032fc1251634fa5c9f89..6afa6524367c2ecc4b8178f1b671c244ecff9172 100644 --- a/frameworks/native/camera/src/input/camera_manager.cpp +++ b/frameworks/native/camera/src/input/camera_manager.cpp @@ -984,12 +984,17 @@ void CameraManager::SetProfile(sptr& cameraObj) if (supportedModes.empty()) { capability = GetSupportedOutputCapability(cameraObj); if (capability != nullptr) { - cameraObj->modePreviewProfiles_[0] = capability->GetPreviewProfiles(); - cameraObj->modePhotoProfiles_[0] = capability->GetPhotoProfiles(); - cameraObj->modeVideoProfiles_[0] = capability->GetVideoProfiles(); + cameraObj->modePreviewProfiles_[NORMAL] = capability->GetPreviewProfiles(); + cameraObj->modePhotoProfiles_[NORMAL] = capability->GetPhotoProfiles(); + cameraObj->modeVideoProfiles_[NORMAL] = capability->GetVideoProfiles(); + cameraObj->modePreviewProfiles_[CAPTURE] = capability->GetPreviewProfiles(); + cameraObj->modePhotoProfiles_[CAPTURE] = capability->GetPhotoProfiles(); + cameraObj->modePreviewProfiles_[VIDEO] = capability->GetPreviewProfiles(); + cameraObj->modePhotoProfiles_[VIDEO] = capability->GetPhotoProfiles(); + cameraObj->modeVideoProfiles_[VIDEO] = capability->GetVideoProfiles(); } } else { - for (const auto &modeName : GetSupportedModes(cameraObj)) { + for (const auto &modeName : supportedModes) { int32_t mode = isTemplateMode_.count(modeName) ? SceneMode::NORMAL : modeName; capability = GetSupportedOutputCapability(cameraObj, mode); if (capability != nullptr) { diff --git a/frameworks/native/camera/src/session/capture_session.cpp b/frameworks/native/camera/src/session/capture_session.cpp index 2bf8d1db8f8d9690f01c83220a3859b53e55a92e..9c94b08b0983287e5c10fa443a3ee686fd4299cd 100644 --- a/frameworks/native/camera/src/session/capture_session.cpp +++ b/frameworks/native/camera/src/session/capture_session.cpp @@ -535,7 +535,7 @@ int32_t CaptureSession::AddOutput(sptr& output) return ServiceToCameraError(errCode); } -bool CaptureSession::CanAddOutput(sptr &output) +bool CaptureSession::CanAddOutput(sptr &output, SceneMode modeName) { CAMERA_SYNC_TRACE; MEDIA_DEBUG_LOG("Enter Into CaptureSession::CanAddOutput"); @@ -547,19 +547,18 @@ bool CaptureSession::CanAddOutput(sptr &output) MEDIA_ERR_LOG("CaptureSession::CanAddOutput Failed inputDevice_ is nullptr"); return false; } - int32_t normalMode = 0; if (output->GetOutputType() == CAPTURE_OUTPUT_TYPE_PREVIEW) { - std::vector previewProfiles = inputDevice_->GetCameraDeviceInfo()->modePreviewProfiles_[normalMode]; + std::vector previewProfiles = inputDevice_->GetCameraDeviceInfo()->modePreviewProfiles_[modeName]; Profile vaildateProfile = output->GetPreviewProfile(); return std::any_of(previewProfiles.begin(), previewProfiles.end(), [&vaildateProfile] (const auto& previewProfile) { return vaildateProfile == previewProfile; }); } else if (output->GetOutputType() == CAPTURE_OUTPUT_TYPE_PHOTO) { - std::vector photoProfiles = inputDevice_->GetCameraDeviceInfo()->modePhotoProfiles_[normalMode]; + std::vector photoProfiles = inputDevice_->GetCameraDeviceInfo()->modePhotoProfiles_[modeName]; Profile vaildateProfile = output->GetPhotoProfile(); return std::any_of(photoProfiles.begin(), photoProfiles.end(), [&vaildateProfile] (const auto& photoProfile) { return vaildateProfile == photoProfile; }); } else if (output->GetOutputType() == CAPTURE_OUTPUT_TYPE_VIDEO) { - std::vector videoProfiles = inputDevice_->GetCameraDeviceInfo()->modeVideoProfiles_[normalMode]; + std::vector videoProfiles = inputDevice_->GetCameraDeviceInfo()->modeVideoProfiles_[modeName]; VideoProfile vaildateProfile = output->GetVideoProfile(); return std::any_of(videoProfiles.begin(), videoProfiles.end(), [&vaildateProfile] (const auto& profile) { return vaildateProfile == profile; }); diff --git a/frameworks/native/camera/src/session/night_session.cpp b/frameworks/native/camera/src/session/night_session.cpp index 89bb753516fc17ab6511423822517eb45ce328b3..86dae64ac1f341f322bb066287468c780d1566c3 100644 --- a/frameworks/native/camera/src/session/night_session.cpp +++ b/frameworks/native/camera/src/session/night_session.cpp @@ -133,30 +133,12 @@ void NightSession::NightSessionMetadataResultProcessor::ProcessCallbacks( session->ProcessAutoFocusUpdates(result); } -bool NightSession::CanAddOutput(sptr &output) +bool NightSession::CanAddOutput(sptr &output, SceneMode modeName) { 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(); - return std::any_of(previewProfiles.begin(), previewProfiles.end(), [&vaildateProfile] - (const auto& previewProfile) { return vaildateProfile == previewProfile; }); - } else if (output->GetOutputType() == CAPTURE_OUTPUT_TYPE_PHOTO) { - std::vector photoProfiles = inputDevice_->GetCameraDeviceInfo()->modePhotoProfiles_[night]; - Profile vaildateProfile = output->GetPhotoProfile(); - return std::any_of(photoProfiles.begin(), photoProfiles.end(), [&vaildateProfile] - (const auto& photoProfile) { return vaildateProfile == photoProfile; }); - } else if (output->GetOutputType() == CAPTURE_OUTPUT_TYPE_METADATA) { - MEDIA_INFO_LOG("ScanSession::CanAddOutput MetadataOutput"); - return true; - } - return false; + return output->GetOutputType() != CAPTURE_OUTPUT_TYPE_VIDEO && + CaptureSession::CanAddOutput(output, SceneMode::NIGHT); } } // CameraStandard } // OHOS diff --git a/frameworks/native/camera/src/session/photo_session.cpp b/frameworks/native/camera/src/session/photo_session.cpp index f2bcde865e425e5d15493aec6fcd19658117f0aa..6f5c975092cf68d7d253d2f1a04f91d967158842 100644 --- a/frameworks/native/camera/src/session/photo_session.cpp +++ b/frameworks/native/camera/src/session/photo_session.cpp @@ -27,11 +27,11 @@ PhotoSession::~PhotoSession() { } -bool PhotoSession::CanAddOutput(sptr &output) +bool PhotoSession::CanAddOutput(sptr &output, SceneMode modeName) { - CAMERA_SYNC_TRACE; MEDIA_DEBUG_LOG("Enter Into PhotoSession::CanAddOutput"); - return output->GetOutputType() != CAPTURE_OUTPUT_TYPE_VIDEO && CaptureSession::CanAddOutput(output); + return output->GetOutputType() != CAPTURE_OUTPUT_TYPE_VIDEO && + CaptureSession::CanAddOutput(output, SceneMode::CAPTURE); } } // 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 4fcc7f2d7744b3ef491f36573486e785966543cd..046f3e7ec48bfe0ffeaadeedb3f02c4980cfccc8 100644 --- a/frameworks/native/camera/src/session/portrait_session.cpp +++ b/frameworks/native/camera/src/session/portrait_session.cpp @@ -147,30 +147,12 @@ void PortraitSession::SetPortraitEffect(PortraitEffect portraitEffect) } return; } -bool PortraitSession::CanAddOutput(sptr &output) +bool PortraitSession::CanAddOutput(sptr &output, SceneMode modeName) { 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(); - return std::any_of(previewProfiles.begin(), previewProfiles.end(), [&vaildateProfile] - (const auto& previewProfile) { return vaildateProfile == previewProfile; }); - } else if (output->GetOutputType() == CAPTURE_OUTPUT_TYPE_PHOTO) { - std::vector photoProfiles = inputDevice_->GetCameraDeviceInfo()->modePhotoProfiles_[portrait]; - Profile vaildateProfile = output->GetPhotoProfile(); - return std::any_of(photoProfiles.begin(), photoProfiles.end(), [&vaildateProfile] - (const auto& photoProfile) { return vaildateProfile == photoProfile; }); - } else if (output->GetOutputType() == CAPTURE_OUTPUT_TYPE_METADATA) { - MEDIA_INFO_LOG("PortraitSession::CanAddOutput MetadataOutput"); - return true; - } - return false; + return output->GetOutputType() != CAPTURE_OUTPUT_TYPE_VIDEO && + CaptureSession::CanAddOutput(output, SceneMode::PORTRAIT); } std::vector PortraitSession::GetSupportedVirtualApertures() diff --git a/frameworks/native/camera/src/session/scan_session.cpp b/frameworks/native/camera/src/session/scan_session.cpp index 5236ab5e87511d4210b3adafdd9b2db34a2fb0e6..557ad0c774105580ecde27173f59fb4a107e0a64 100644 --- a/frameworks/native/camera/src/session/scan_session.cpp +++ b/frameworks/native/camera/src/session/scan_session.cpp @@ -54,30 +54,11 @@ int32_t ScanSession::AddOutput(sptr &output) return result; } -bool ScanSession::CanAddOutput(sptr &output) +bool ScanSession::CanAddOutput(sptr &output, SceneMode modeName) { - 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(); - return std::any_of(previewProfiles.begin(), previewProfiles.end(), [&vaildateProfile] - (const auto& previewProfile) { return vaildateProfile == previewProfile; }); - } else if (output->GetOutputType() == CAPTURE_OUTPUT_TYPE_PHOTO) { - std::vector photoProfiles = inputDevice_->GetCameraDeviceInfo()->modePhotoProfiles_[scan]; - Profile vaildateProfile = output->GetPhotoProfile(); - return std::any_of(photoProfiles.begin(), photoProfiles.end(), [&vaildateProfile] - (const auto& photoProfile) { return vaildateProfile == photoProfile; }); - } else if (output->GetOutputType() == CAPTURE_OUTPUT_TYPE_METADATA) { - MEDIA_INFO_LOG("ScanSession::CanAddOutput MetadataOutput"); - return true; - } - return false; + return output->GetOutputType() != CAPTURE_OUTPUT_TYPE_VIDEO && + CaptureSession::CanAddOutput(output, SceneMode::SCAN); } } // 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 2beec60178f895b2d0af4eecfc5060f8531c4b6b..462393328aac7d1e81752db591eaefaa926cf1a2 100644 --- a/frameworks/native/camera/src/session/video_session.cpp +++ b/frameworks/native/camera/src/session/video_session.cpp @@ -26,5 +26,10 @@ namespace CameraStandard { VideoSession::~VideoSession() { } +bool VideoSession::CanAddOutput(sptr &output, SceneMode modeName) +{ + MEDIA_DEBUG_LOG("Enter Into VideoSession::CanAddOutput"); + return CaptureSession::CanAddOutput(output, SceneMode::VIDEO); +} } // namespace CameraStandard } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_api/native/camera/include/session/capture_session.h b/interfaces/inner_api/native/camera/include/session/capture_session.h index becaca34feb03d83aa08244a1917a7f7c08c8ed8..b463b549b6fa66c185aabc10e144a071241ed910 100644 --- a/interfaces/inner_api/native/camera/include/session/capture_session.h +++ b/interfaces/inner_api/native/camera/include/session/capture_session.h @@ -240,7 +240,7 @@ public: * * @param CaptureOutput to be added to session. */ - virtual bool CanAddOutput(sptr& output); + virtual bool CanAddOutput(sptr& output, SceneMode modeName = SceneMode::NORMAL); /** * @brief Add CaptureOutput for the capture session. 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 8e92f43985006590a90b11723e19f92cb324522e..6f863f512354dc1826bb4cefa6e646f178b5c4b2 100644 --- a/interfaces/inner_api/native/camera/include/session/night_session.h +++ b/interfaces/inner_api/native/camera/include/session/night_session.h @@ -74,7 +74,7 @@ public: * * @param CaptureOutput to be added to session. */ - bool CanAddOutput(sptr& output) override; + bool CanAddOutput(sptr& output, SceneMode modeName = SceneMode::NIGHT) override; }; } // namespace CameraStandard } // namespace OHOS 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 3513cefe8cf854540edc7a710b01221fe43e8033..8070b07534b1d45dcc387aa91bae65d0f8827b1f 100644 --- a/interfaces/inner_api/native/camera/include/session/photo_session.h +++ b/interfaces/inner_api/native/camera/include/session/photo_session.h @@ -31,7 +31,7 @@ public: * * @param CaptureOutput to be added to session. */ - bool CanAddOutput(sptr& output) override; + bool CanAddOutput(sptr& output, SceneMode modeName = SceneMode::CAPTURE) override; }; } // namespace CameraStandard } // namespace OHOS 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 3db4fcf96a26528d3636eee2f8bcb231a6e3afe5..d426963032a264a3fa1fe3d2b9ec3aead6a72056 100644 --- a/interfaces/inner_api/native/camera/include/session/portrait_session.h +++ b/interfaces/inner_api/native/camera/include/session/portrait_session.h @@ -68,7 +68,7 @@ public: * * @param CaptureOutput to be added to session. */ - bool CanAddOutput(sptr& output) override; + bool CanAddOutput(sptr& output, SceneMode modeName = SceneMode::PORTRAIT) override; /** * @brief Get the supported virtual apertures. 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 0383006139d3f3302948197b63ab6ed08256b08f..0c523bb856e302ea2e61dc2666ccc82d4f812f1a 100644 --- a/interfaces/inner_api/native/camera/include/session/scan_session.h +++ b/interfaces/inner_api/native/camera/include/session/scan_session.h @@ -33,7 +33,7 @@ public: * * @param CaptureOutput to be added to session. */ - bool CanAddOutput(sptr& output) override; + bool CanAddOutput(sptr& output, SceneMode modeName = SceneMode::SCAN) 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 6bc76c6bd679bbda51d9d522506a4c2e14392a5a..f29c5a978b7d41236bb9521a7b4d74e37ee8d5c7 100644 --- a/interfaces/inner_api/native/camera/include/session/video_session.h +++ b/interfaces/inner_api/native/camera/include/session/video_session.h @@ -25,6 +25,13 @@ class VideoSession : public CaptureSession { public: explicit VideoSession(sptr &videoSession): CaptureSession(videoSession) {} ~VideoSession(); + + /** + * @brief Determine if the given Ouput can be added to session. + * + * @param CaptureOutput to be added to session. + */ + bool CanAddOutput(sptr& output, SceneMode modeName = SceneMode::VIDEO) override; }; } // namespace CameraStandard } // namespace OHOS diff --git a/services/camera_service/src/hcamera_device.cpp b/services/camera_service/src/hcamera_device.cpp index ab2ea9f679a4ad3ceae354c37e87c8f3a96d8159..82f559fa522fa541bef91deb993f0f9d6ab4118e 100644 --- a/services/camera_service/src/hcamera_device.cpp +++ b/services/camera_service/src/hcamera_device.cpp @@ -1005,7 +1005,7 @@ int32_t HCameraDevice::CommitStreams( static_cast(operationMode), setting)); } else { MEDIA_DEBUG_LOG("HCameraDevice::CommitStreams IStreamOperator V1_0"); - OperationMode opMode = static_cast(operationMode); + OperationMode opMode = OperationMode::NORMAL; hdiRc = (CamRetCode)(streamOperator->CommitStreams(opMode, setting)); } MEDIA_DEBUG_LOG("HCameraDevice::CommitStreams end");