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 14f2ce6a27b5a2bb6cda6c1b010d9cd0997baf9a..2a27b03bee2761eaf878599a872e43e08d258991 100644 --- a/frameworks/js/camera_napi/src/output/photo_output_napi.cpp +++ b/frameworks/js/camera_napi/src/output/photo_output_napi.cpp @@ -220,7 +220,6 @@ void PhotoListener::ExecutePhotoAsset(sptr surfaceBuffer, bool is napi_call_function(env_, nullptr, callback, ARGS_TWO, result, &retVal); // return buffer to buffer queue photoSurface_->ReleaseBuffer(surfaceBuffer, -1); - newSurfaceBuffer->Unmap(); } void PhotoListener::CreateMediaLibrary(sptr surfaceBuffer, BufferHandle *bufferHandle, @@ -237,12 +236,26 @@ void PhotoListener::CreateMediaLibrary(sptr surfaceBuffer, Buffer int32_t photoHeight; surfaceBuffer->GetExtraData()->ExtraGet(OHOS::CameraStandard::dataWidth, photoWidth); surfaceBuffer->GetExtraData()->ExtraGet(OHOS::CameraStandard::dataHeight, photoHeight); - MEDIA_INFO_LOG("photoWidth:%{public}d, photoHeight: %{public}d", photoWidth, photoHeight); + uint64_t size = static_cast(surfaceBuffer->GetSize()); + int32_t extraDataSize = 0; + auto res = surfaceBuffer->GetExtraData()->ExtraGet(OHOS::Camera::dataSize, extraDataSize); + if (res != 0) { + MEDIA_INFO_LOG("ExtraGet dataSize error %{public}d", res); + } else if (extraDataSize <= 0) { + MEDIA_INFO_LOG("ExtraGet dataSize Ok, but size <= 0"); + } else if (static_cast(extraDataSize) > size) { + MEDIA_INFO_LOG("ExtraGet dataSize Ok,but dataSize %{public}d is bigger than bufferSize %{public}" PRIu64, + extraDataSize, size); + } else { + MEDIA_INFO_LOG("ExtraGet dataSize %{public}d", extraDataSize); + size = extraDataSize; + } + MEDIA_INFO_LOG("width:%{public}d, height:%{public}d, size:%{public}" PRId64, photoWidth, photoHeight, size); int32_t format = bufferHandle->format; sptr photoProxy; std::string imageIdStr = std::to_string(imageId); photoProxy = new(std::nothrow) CameraPhotoProxy(bufferHandle, format, photoWidth, photoHeight, isHighQuality); - photoProxy->SetDeferredAttrs(imageIdStr, deferredProcessingType); + photoProxy->SetDeferredAttrs(imageIdStr, deferredProcessingType, size); auto photoOutput = photoOutput_.promote(); if (photoOutput && photoOutput->GetSession()) { photoOutput->GetSession()->CreateMediaLibrary(photoProxy, uri, cameraShotType); @@ -265,11 +278,11 @@ void PhotoListener::UpdateJSCallback(sptr photoSurface) const int32_t isDegradedImage; surfaceBuffer->GetExtraData()->ExtraGet(OHOS::Camera::isDegradedImage, isDegradedImage); MEDIA_INFO_LOG("PhotoListener UpdateJSCallback isDegradedImage:%{public}d", isDegradedImage); - if ((callbackFlag & CAPTURE_PHOTO_ASSET) != 0) { + if ((callbackFlag_ & CAPTURE_PHOTO_ASSET) != 0) { ExecutePhotoAsset(surfaceBuffer, isDegradedImage == 0); - } else if (isDegradedImage == 0 && (callbackFlag & CAPTURE_PHOTO) != 0) { + } else if (isDegradedImage == 0 && (callbackFlag_ & CAPTURE_PHOTO) != 0) { ExecutePhoto(surfaceBuffer); - } else if (isDegradedImage != 0 && (callbackFlag & CAPTURE_DEFERRED_PHOTO) != 0) { + } else if (isDegradedImage != 0 && (callbackFlag_ & CAPTURE_DEFERRED_PHOTO) != 0) { ExecuteDeferredPhoto(surfaceBuffer); } else { MEDIA_INFO_LOG("PhotoListener on error callback"); @@ -325,27 +338,25 @@ void PhotoListener::SaveCallbackReference(const std::string &eventType, napi_val switch (eventTypeEnum) { case PhotoOutputEventType::CAPTURE_PHOTO_AVAILABLE: curCallbackRef = &capturePhotoCb_; - callbackFlag |= CAPTURE_PHOTO; + callbackFlag_ |= CAPTURE_PHOTO; break; case PhotoOutputEventType::CAPTURE_DEFERRED_PHOTO_AVAILABLE: curCallbackRef = &captureDeferredPhotoCb_; - callbackFlag |= CAPTURE_DEFERRED_PHOTO; + callbackFlag_ |= CAPTURE_DEFERRED_PHOTO; break; case PhotoOutputEventType::CAPTURE_PHOTO_ASSET_AVAILABLE: curCallbackRef = &capturePhotoAssetCb_; - callbackFlag |= CAPTURE_PHOTO_ASSET; + callbackFlag_ |= CAPTURE_PHOTO_ASSET; break; default: MEDIA_ERR_LOG("Incorrect photo callback event type received from JS"); return; } - if (eventTypeEnum == PhotoOutputEventType::CAPTURE_PHOTO_ASSET_AVAILABLE) { - auto photoOutput = photoOutput_.promote(); - if (photoOutput) { - photoOutput->AddDeferType(DeferredDeliveryImageType::DELIVERY_PHOTO); - } else { - MEDIA_ERR_LOG("cannot get photoOutput"); - } + auto photoOutput = photoOutput_.promote(); + if (photoOutput) { + photoOutput->SetCallbackFlag(callbackFlag_); + } else { + MEDIA_ERR_LOG("cannot get photoOutput"); } napi_ref callbackRef = nullptr; const int32_t refCount = 1; @@ -362,15 +373,15 @@ void PhotoListener::RemoveCallbackRef(napi_env env, napi_value callback, const s if (eventType == CONST_CAPTURE_PHOTO_AVAILABLE) { napi_delete_reference(env_, capturePhotoCb_); capturePhotoCb_ = nullptr; - callbackFlag &= ~CAPTURE_PHOTO; + callbackFlag_ &= ~CAPTURE_PHOTO; } else if (eventType == CONST_CAPTURE_DEFERRED_PHOTO_AVAILABLE) { napi_delete_reference(env_, captureDeferredPhotoCb_); captureDeferredPhotoCb_ = nullptr; - callbackFlag &= ~CAPTURE_DEFERRED_PHOTO; + callbackFlag_ &= ~CAPTURE_DEFERRED_PHOTO; } else if (eventType == CONST_CAPTURE_PHOTO_ASSET_AVAILABLE) { napi_delete_reference(env_, capturePhotoAssetCb_); photoOutput_->DeferImageDeliveryFor(DeferredDeliveryImageType::DELIVERY_NONE); - callbackFlag &= ~CAPTURE_PHOTO_ASSET; + callbackFlag_ &= ~CAPTURE_PHOTO_ASSET; capturePhotoAssetCb_ = nullptr; } diff --git a/frameworks/native/camera/src/output/camera_photo_proxy.cpp b/frameworks/native/camera/src/output/camera_photo_proxy.cpp index fa2ad1fb76695b8e5b537b771d1b873778159c02..ddace9a9c6986b6ce9771775827d1b95397458eb 100644 --- a/frameworks/native/camera/src/output/camera_photo_proxy.cpp +++ b/frameworks/native/camera/src/output/camera_photo_proxy.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include #include #include #include @@ -65,6 +66,7 @@ void CameraPhotoProxy::ReadFromParcel(MessageParcel &parcel) photoWidth_ = parcel.ReadInt32(); photoHeight_ = parcel.ReadInt32(); isHighQuality_ = parcel.ReadBool(); + fileSize_ = parcel.ReadUint64(); bufferHandle_ = ReadBufferHandle(parcel); MEDIA_INFO_LOG("PhotoProxy::ReadFromParcel"); } @@ -101,6 +103,7 @@ void CameraPhotoProxy::WriteToParcel(MessageParcel &parcel) parcel.WriteInt32(photoWidth_); parcel.WriteInt32(photoHeight_); parcel.WriteBool(isHighQuality_); + parcel.WriteUint64(fileSize_); if (bufferHandle_) { MEDIA_DEBUG_LOG("PhotoProxy::WriteToParcel %{public}d", bufferHandle_->fd); bool ret = WriteBufferHandle(parcel, *bufferHandle_); @@ -113,11 +116,13 @@ void CameraPhotoProxy::WriteToParcel(MessageParcel &parcel) MEDIA_INFO_LOG("PhotoProxy::WriteToParcel"); } -void CameraPhotoProxy::SetDeferredAttrs(std::string photoId, int32_t deferredProcType) +void CameraPhotoProxy::SetDeferredAttrs(std::string photoId, int32_t deferredProcType, uint64_t fileSize) { + std::lock_guard lock(mutex_); isDeferredPhoto_ = 1; photoId_ = photoId; deferredProcType_ = deferredProcType; + fileSize_ = fileSize; } } // namespace CameraStandard } // namespace OHOS diff --git a/frameworks/native/camera/src/output/photo_output.cpp b/frameworks/native/camera/src/output/photo_output.cpp index f8fc0ad90bf5b916b804bd9e05fa0ce5a8c84be6..0789ac5852c9ebd4bf054714d3df0e9775e03a94 100644 --- a/frameworks/native/camera/src/output/photo_output.cpp +++ b/frameworks/native/camera/src/output/photo_output.cpp @@ -15,6 +15,7 @@ #include "output/photo_output.h" +#include #include #include "camera_error_code.h" @@ -285,6 +286,34 @@ PhotoOutput::~PhotoOutput() defaultCaptureSetting_ = nullptr; } +void PhotoOutput::SetCallbackFlag(uint8_t callbackFlag) +{ + std::lock_guard lock(callbackMutex_); + bool beforeStatus = IsEnableDeferred(); + callbackFlag_ = callbackFlag; + bool afterStatus = IsEnableDeferred(); + // if session is commit or start, and isEnableDeferred is oppsite, need to restart session config + auto session = GetSession(); + if (beforeStatus != afterStatus && session) { + if (session->IsSessionStarted()) { + MEDIA_INFO_LOG("session restart when callback status changed"); + session->BeginConfig(); + session->CommitConfig(); + session->Start(); + } else if (session->IsSessionCommited()) { + MEDIA_INFO_LOG("session recommit when callback status changed"); + session->BeginConfig(); + session->CommitConfig(); + } + } +} + +bool PhotoOutput::IsEnableDeferred() +{ + MEDIA_DEBUG_LOG("Enter Into PhotoOutput::IsEnableDeferred()"); + return (callbackFlag_ & CAPTURE_PHOTO_ASSET) != 0 || (callbackFlag_ & CAPTURE_PHOTO) == 0; +} + void PhotoOutput::SetCallback(std::shared_ptr callback) { std::lock_guard lock(outputCallbackMutex_); @@ -607,28 +636,11 @@ int32_t PhotoOutput::DeferImageDeliveryFor(DeferredDeliveryImageType type) MEDIA_ERR_LOG("PhotoOutput DeferImageDeliveryFor error!, cameraObj is nullptr"); return SESSION_NOT_RUNNING; } - captureSession->EnableDeferredType(type); + captureSession->EnableDeferredType(type, true); captureSession->SetUserId(); return 0; } -int32_t PhotoOutput::AddDeferType(DeferredDeliveryImageType type) -{ - MEDIA_INFO_LOG("PhotoOutput AddDeferType type:%{public}d!", type); - deferredType_ = type; - return 0; -} - -void PhotoOutput::SetSession(wptr captureSession) -{ - MEDIA_INFO_LOG("PhotoOutput SetSession"); - CaptureOutput::SetSession(captureSession); - if (deferredType_ == DeferredDeliveryImageType::DELIVERY_NONE) { - return; - } - DeferImageDeliveryFor(deferredType_); -} - int32_t PhotoOutput::IsDeferredImageDeliverySupported(DeferredDeliveryImageType type) { MEDIA_INFO_LOG("IsDeferredImageDeliverySupported type:%{public}d!", type); diff --git a/frameworks/native/camera/src/session/capture_session.cpp b/frameworks/native/camera/src/session/capture_session.cpp index d2dba2e7f0aa4e6d3da9da99ddbd3f32468549fa..477c5e60a7eacd772e97fe5f682dfd8e8fe0b828 100644 --- a/frameworks/native/camera/src/session/capture_session.cpp +++ b/frameworks/native/camera/src/session/capture_session.cpp @@ -322,6 +322,12 @@ int32_t CaptureSession::CommitConfig() if (!isColorSpaceSetted_) { SetDefaultColorSpace(); } + // DELIVERY_PHOTO for default when commit + if (photoOutput_ && !isDeferTypeSetted_) { + EnableDeferredType(((sptr &)photoOutput_)->IsEnableDeferred() ? DELIVERY_PHOTO + : DELIVERY_NONE, false); + SetUserId(); + } int32_t errCode = CAMERA_UNKNOWN_ERROR; if (captureSession_) { errCode = captureSession_->CommitConfig(); @@ -2784,7 +2790,7 @@ void CaptureSession::SetMode(SceneMode modeName) } currentMode_ = modeName; // reset deferred enable status when reset mode - EnableDeferredType(DELIVERY_NONE); + EnableDeferredType(DELIVERY_NONE, false); if (captureSession_) { captureSession_->SetFeatureMode(modeName); MEDIA_INFO_LOG("CaptureSession::SetSceneMode SceneMode = %{public}d", modeName); @@ -3407,11 +3413,23 @@ bool CaptureSession::IsSessionCommited() if (captureSession_) { CaptureSessionState currentState; captureSession_->GetSessionState(currentState); - isCommitConfig = (currentState == CaptureSessionState::SESSION_CONFIG_COMMITTED); + isCommitConfig = (currentState == CaptureSessionState::SESSION_CONFIG_COMMITTED) + || (currentState == CaptureSessionState::SESSION_STARTED); } return isCommitConfig; } +bool CaptureSession::IsSessionStarted() +{ + bool isStarted = false; + if (captureSession_) { + CaptureSessionState currentState; + captureSession_->GetSessionState(currentState); + isStarted = (currentState == CaptureSessionState::SESSION_STARTED); + } + return isStarted; +} + int32_t CaptureSession::CalculateExposureValue(float exposureValue) { camera_metadata_item_t item; @@ -4235,7 +4253,7 @@ std::shared_ptr CaptureSession::GeneratePreconfigProfiles(Pre return nullptr; } -void CaptureSession::EnableDeferredType(DeferredDeliveryImageType type) +void CaptureSession::EnableDeferredType(DeferredDeliveryImageType type, bool isEnableByUser) { MEDIA_INFO_LOG("CaptureSession::EnableDeferredType type:%{public}d", type); if (IsSessionCommited()) { @@ -4280,7 +4298,9 @@ void CaptureSession::EnableDeferredType(DeferredDeliveryImageType type) int32_t errCode = this->UnlockForControl(); if (errCode != CameraErrorCode::SUCCESS) { MEDIA_DEBUG_LOG("CaptureSession::EnableDeferredType Failed"); + return; } + isDeferTypeSetted_ = isEnableByUser; } void CaptureSession::SetUserId() diff --git a/interfaces/inner_api/native/camera/include/camera_photo_proxy.h b/interfaces/inner_api/native/camera/include/camera_photo_proxy.h index f1c276b0670ffabd012eb43924489b3f73b006d6..d0d260cc960905bfc4f6c30705aeda4568e46b43 100644 --- a/interfaces/inner_api/native/camera/include/camera_photo_proxy.h +++ b/interfaces/inner_api/native/camera/include/camera_photo_proxy.h @@ -30,7 +30,7 @@ public: virtual ~CameraPhotoProxy(); void ReadFromParcel(MessageParcel &parcel); void WriteToParcel(MessageParcel &parcel); - void SetDeferredAttrs(std::string photoId, int32_t deferredProcType); + void SetDeferredAttrs(std::string photoId, int32_t deferredProcType, uint64_t fileSize); int32_t CameraFreeBufferHandle(); private: 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 d0a5323299f8626d93ba7a3e423d28bd8eda967b..5251702047636e7a49a8575449b565579c50b8df 100644 --- a/interfaces/inner_api/native/camera/include/output/capture_output.h +++ b/interfaces/inner_api/native/camera/include/output/capture_output.h @@ -120,7 +120,7 @@ public: void SetStream(sptr stream); bool IsStreamCreated(); sptr GetSession(); - virtual void SetSession(wptr captureSession); + void SetSession(wptr captureSession); std::mutex asyncOpMutex_; std::mutex outputCallbackMutex_; void SetPhotoProfile(Profile& profile); diff --git a/interfaces/inner_api/native/camera/include/output/photo_output.h b/interfaces/inner_api/native/camera/include/output/photo_output.h index 472e247daa87abcd7fd35d03aaaf8c374069248b..c3cb6e878b36fa123bf5be53376666d221f329dd 100644 --- a/interfaces/inner_api/native/camera/include/output/photo_output.h +++ b/interfaces/inner_api/native/camera/include/output/photo_output.h @@ -16,7 +16,9 @@ #ifndef OHOS_CAMERA_PHOTO_OUTPUT_H #define OHOS_CAMERA_PHOTO_OUTPUT_H +#include #include +#include #include "camera_metadata_info.h" #include "capture_output.h" @@ -220,6 +222,10 @@ private: std::shared_ptr captureMetadataSetting_; }; +constexpr uint8_t CAPTURE_PHOTO = 1 << 0; +constexpr uint8_t CAPTURE_DEFERRED_PHOTO = 1 << 1; +constexpr uint8_t CAPTURE_PHOTO_ASSET = 1 << 2; + class PhotoOutput : public CaptureOutput { public: explicit PhotoOutput(sptr bufferProducer); @@ -325,16 +331,9 @@ public: int32_t IsDeferredImageDeliverySupported(DeferredDeliveryImageType type); /** - * @brief Add the deferredImageDelivery type when on photoAssetAvailable. - * - */ - int32_t AddDeferType(DeferredDeliveryImageType type); - - /** - * @brief Set the captureSession. - * + * @brief Set the callbackFlag when on photoAssetAvailable. */ - void SetSession(wptr captureSession) override; + void SetCallbackFlag(uint8_t callbackFlag); /** * @brief To check the deferredImageDelivery capability is enable or not. @@ -358,6 +357,13 @@ public: * @return Returns the result of the auto high quality photo enable. */ int32_t EnableAutoHighQualityPhoto(bool enabled); + + /** + * @brief To get status by callbackFlags. + * + * @return Returns the result to check enable deferred. + */ + bool IsEnableDeferred(); /** * @brief Get default photo capture setting. @@ -371,14 +377,17 @@ public: sptr rawPhotoSurface_; sptr deferredSurface_; - + private: + std::mutex callbackMutex_; + uint8_t callbackFlag_ = CAPTURE_DEFERRED_PHOTO; DeferredDeliveryImageType deferredType_ = DeferredDeliveryImageType::DELIVERY_NONE; std::shared_ptr appCallback_; sptr cameraSvcCallback_; std::shared_ptr defaultCaptureSetting_; void CameraServerDied(pid_t pid) override; }; + class HStreamCaptureCallbackImpl : public HStreamCaptureCallbackStub { public: wptr photoOutput_ = nullptr; 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 e4b0e565c49f95c5545b45eab7d9b839f538c5cd..af1cc4bc6d543758fa744941c93dfd1ed1ba428c 100644 --- a/interfaces/inner_api/native/camera/include/session/capture_session.h +++ b/interfaces/inner_api/native/camera/include/session/capture_session.h @@ -1108,6 +1108,13 @@ public: */ bool IsSessionConfiged(); + /** + * @brief Get whether or not start session. + * + * @return Returns whether or not start session. + */ + bool IsSessionStarted(); + /** * @brief Set FrameRate Range. * @@ -1202,7 +1209,7 @@ public: return metadataResultProcessor_; } - void EnableDeferredType(DeferredDeliveryImageType deferredType); + void EnableDeferredType(DeferredDeliveryImageType deferredType, bool isEnableByUser); void SetUserId(); bool IsMovingPhotoEnabled(); bool IsImageDeferred(); @@ -1295,6 +1302,7 @@ private: std::atomic prevDuration_ = 0; sptr deathRecipient_ = nullptr; bool isColorSpaceSetted_ = false; + atomic isDeferTypeSetted_ = false; std::mutex preconfigProfilesMutex_; std::shared_ptr preconfigProfiles_ = nullptr; diff --git a/interfaces/kits/js/camera_napi/include/output/photo_output_napi.h b/interfaces/kits/js/camera_napi/include/output/photo_output_napi.h index b5c7b792ba08c2e84d75c576b638123a93715700..4151417c6bdec021f7402d5b2123919b24bfa8d2 100644 --- a/interfaces/kits/js/camera_napi/include/output/photo_output_napi.h +++ b/interfaces/kits/js/camera_napi/include/output/photo_output_napi.h @@ -101,10 +101,6 @@ private: sptr photoSurface_ = nullptr; }; -constexpr int32_t CAPTURE_PHOTO = 1 << 0; -constexpr int32_t CAPTURE_DEFERRED_PHOTO = 1 << 1; -constexpr int32_t CAPTURE_PHOTO_ASSET = 1 << 2; - class PhotoListener : public IBufferConsumerListener { public: explicit PhotoListener(napi_env env, const sptr photoSurface, wptr photoOutput); @@ -131,7 +127,7 @@ private: napi_ref capturePhotoCb_; napi_ref captureDeferredPhotoCb_; napi_ref capturePhotoAssetCb_; - int32_t callbackFlag = 0; + uint8_t callbackFlag_ = 0; }; class RawPhotoListener : public IBufferConsumerListener { diff --git a/services/camera_service/binder/base/include/icapture_session.h b/services/camera_service/binder/base/include/icapture_session.h index 9de0a0943e979452d4ead5542abec44f00d2d36d..64e9cff9000c6f91977270d285b48d10a1c0f9df 100644 --- a/services/camera_service/binder/base/include/icapture_session.h +++ b/services/camera_service/binder/base/include/icapture_session.h @@ -30,7 +30,8 @@ enum class CaptureSessionState : uint32_t { SESSION_CONFIG_INPROGRESS = 1, SESSION_CONFIG_COMMITTED = 2, SESSION_RELEASED = 3, - SESSION_STATE_MAX = 4 + SESSION_STARTED = 4, + SESSION_STATE_MAX = 5 }; enum ColorSpace { diff --git a/services/camera_service/src/avcodec/audio_capturer_session.cpp b/services/camera_service/src/avcodec/audio_capturer_session.cpp index 84c8a4d974a3b94dfbb7c207c5b43a6abb084e67..1122a170ec4af12cc222aad6522f6585a9342c93 100644 --- a/services/camera_service/src/avcodec/audio_capturer_session.cpp +++ b/services/camera_service/src/avcodec/audio_capturer_session.cpp @@ -122,12 +122,6 @@ void AudioCapturerSession::ProcessAudioBuffer() MEDIA_DEBUG_LOG("audio push buffer frameId: %{public}s", audioRecord->GetFrameId().c_str()); buffer.release(); audioBufferQueue_.Push(audioRecord); - if (bytesRead < 0) { - MEDIA_ERR_LOG("Bytes read failed. error code %{public}zu", bytesRead); - break; - } else if (bytesRead == 0) { - continue; - } } } diff --git a/services/camera_service/src/avcodec/camera_server_photo_proxy.cpp b/services/camera_service/src/avcodec/camera_server_photo_proxy.cpp index 57fc439b0433370e7bbd3b801ecbdfb85d648e13..b7c92e5da3d6d8ad1f0047f29a6e997dcaf1b219 100644 --- a/services/camera_service/src/avcodec/camera_server_photo_proxy.cpp +++ b/services/camera_service/src/avcodec/camera_server_photo_proxy.cpp @@ -44,7 +44,7 @@ CameraServerPhotoProxy::~CameraServerPhotoProxy() std::lock_guard lock(mutex_); MEDIA_INFO_LOG("~CameraServerPhotoProxy"); if (isMmaped_) { - munmap(fileDataAddr_, fileSize_); + munmap(fileDataAddr_, bufferHandle_->size); } CameraFreeBufferHandle(const_cast(bufferHandle_)); fileDataAddr_ = nullptr; @@ -87,6 +87,7 @@ void CameraServerPhotoProxy::ReadFromParcel(MessageParcel &parcel) photoWidth_ = parcel.ReadInt32(); photoHeight_ = parcel.ReadInt32(); isHighQuality_ = parcel.ReadBool(); + fileSize_ = parcel.ReadUint64(); bufferHandle_ = ReadBufferHandle(parcel); MEDIA_INFO_LOG("PhotoProxy::ReadFromParcel"); } @@ -125,8 +126,6 @@ size_t CameraServerPhotoProxy::GetFileSize() { MEDIA_INFO_LOG("PhotoProxy::GetFileSize"); std::lock_guard lock(mutex_); - - fileSize_ = bufferHandle_->size; return fileSize_; } diff --git a/services/camera_service/src/hcapture_session.cpp b/services/camera_service/src/hcapture_session.cpp index 17c0e9808812387cc7328ff31bbbd0a88179cdee..b004f5d00a432a2b18e19c9e99a6687a93dca1b2 100644 --- a/services/camera_service/src/hcapture_session.cpp +++ b/services/camera_service/src/hcapture_session.cpp @@ -1099,8 +1099,9 @@ int32_t HCaptureSession::Start() int32_t errorCode = CAMERA_OK; MEDIA_INFO_LOG("HCaptureSession::Start prepare execute"); stateMachine_.StateGuard([&errorCode, this](CaptureSessionState currentState) { - if (currentState != CaptureSessionState::SESSION_CONFIG_COMMITTED) { - MEDIA_ERR_LOG("HCaptureSession::Start(), Invalid session state: %{public}d", currentState); + bool isTransferSupport = stateMachine_.CheckTransfer(CaptureSessionState::SESSION_STARTED); + if (!isTransferSupport) { + MEDIA_ERR_LOG("HCaptureSession::Start() Need to call after committing configuration"); errorCode = CAMERA_INVALID_STATE; return; } @@ -1124,6 +1125,7 @@ int32_t HCaptureSession::Start() if (errorCode == CAMERA_OK) { isSessionStarted_ = true; } + stateMachine_.Transfer(CaptureSessionState::SESSION_STARTED); }); MEDIA_INFO_LOG("HCaptureSession::Start execute success"); return errorCode; @@ -1181,7 +1183,9 @@ int32_t HCaptureSession::Stop() int32_t errorCode = CAMERA_OK; MEDIA_INFO_LOG("HCaptureSession::Stop prepare execute"); stateMachine_.StateGuard([&errorCode, this](CaptureSessionState currentState) { - if (currentState != CaptureSessionState::SESSION_CONFIG_COMMITTED) { + bool isTransferSupport = stateMachine_.CheckTransfer(CaptureSessionState::SESSION_CONFIG_COMMITTED); + if (!isTransferSupport) { + MEDIA_ERR_LOG("HCaptureSession::Stop() Need to call after Start"); errorCode = CAMERA_INVALID_STATE; return; } @@ -1213,6 +1217,7 @@ int32_t HCaptureSession::Stop() if (errorCode == CAMERA_OK) { isSessionStarted_ = false; } + stateMachine_.Transfer(CaptureSessionState::SESSION_CONFIG_COMMITTED); }); MEDIA_INFO_LOG("HCaptureSession::Stop execute success"); return errorCode; @@ -1757,9 +1762,15 @@ StateMachine::StateMachine() }; stateTransferMap_[static_cast(CaptureSessionState::SESSION_CONFIG_COMMITTED)] = { - CaptureSessionState::SESSION_CONFIG_INPROGRESS, CaptureSessionState::SESSION_RELEASED + CaptureSessionState::SESSION_CONFIG_INPROGRESS, CaptureSessionState::SESSION_STARTED, + CaptureSessionState::SESSION_RELEASED }; - + + stateTransferMap_[static_cast(CaptureSessionState::SESSION_STARTED)] = { + CaptureSessionState::SESSION_CONFIG_INPROGRESS, CaptureSessionState::SESSION_CONFIG_COMMITTED, + CaptureSessionState::SESSION_RELEASED + }; + stateTransferMap_[static_cast(CaptureSessionState::SESSION_RELEASED)] = {}; }