From ae5f1f90f3331cac26e420935913b6e75aaa03a7 Mon Sep 17 00:00:00 2001 From: banana_pluto Date: Thu, 4 Sep 2025 21:43:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EremoveDeferredBuffer=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=8F=B3=E6=BB=91=E5=BD=95=E5=83=8F=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: banana_pluto --- .../src/output/preview_output_napi.cpp | 37 +++++++++++++++++++ .../camera/base/src/output/preview_output.cpp | 10 +++++ .../camera/include/output/preview_output.h | 7 ++++ .../include/output/preview_output_napi.h | 1 + .../camera_service/idls/IStreamRepeat.idl | 1 + .../camera_service/include/hstream_repeat.h | 1 + .../camera_service/src/hstream_repeat.cpp | 21 +++++++++++ 7 files changed, 78 insertions(+) diff --git a/frameworks/js/camera_napi/src/output/preview_output_napi.cpp b/frameworks/js/camera_napi/src/output/preview_output_napi.cpp index 40d42fcd1..9707075e2 100644 --- a/frameworks/js/camera_napi/src/output/preview_output_napi.cpp +++ b/frameworks/js/camera_napi/src/output/preview_output_napi.cpp @@ -221,6 +221,7 @@ napi_value PreviewOutputNapi::Init(napi_env env, napi_value exports) napi_property_descriptor preview_output_props[] = { DECLARE_NAPI_FUNCTION("addDeferredSurface", AddDeferredSurface), + DECLARE_NAPI_FUNCTION("removeDeferredSurface", RemoveDeferredSurface), DECLARE_NAPI_FUNCTION("start", Start), DECLARE_NAPI_FUNCTION("stop", Stop), DECLARE_NAPI_FUNCTION("release", Release), @@ -491,6 +492,42 @@ napi_value PreviewOutputNapi::AddDeferredSurface(napi_env env, napi_callback_inf return CameraNapiUtils::GetUndefinedValue(env); } +napi_value PreviewOutputNapi::RemoveDeferredSurface(napi_env env, napi_callback_info info) +{ + MEDIA_DEBUG_LOG("RemoveDeferredSurface is called"); + if (!CameraNapiSecurity::CheckSystemApp(env)) { + MEDIA_ERR_LOG("SystemApi RemoveDeferredSurface is called!"); + return nullptr; + } + + PreviewOutputNapi* previewOutputNapi; + std::string surfaceId; + CameraNapiParamParser jsParamParser(env, info, previewOutputNapi, surfaceId); + if (!jsParamParser.AssertStatus(INVALID_ARGUMENT, "invalid argument")) { + MEDIA_ERR_LOG("CameraInputNapi::RemoveDeferredSurface invalid argument"); + return nullptr; + } + + uint64_t iSurfaceId; + std::istringstream iss(surfaceId); + iss >> iSurfaceId; + sptr surface = SurfaceUtils::GetInstance()->GetSurface(iSurfaceId); + if (!surface) { + surface = Media::ImageReceiver::getSurfaceById(surfaceId); + } + if (surface == nullptr) { + MEDIA_ERR_LOG("CameraInputNapi::RemoveDeferredSurface failed to get surface"); + CameraNapiUtils::ThrowError(env, INVALID_ARGUMENT, "invalid argument surface get fail"); + return nullptr; + } + auto previewProfile = previewOutputNapi->previewOutput_->GetPreviewProfile(); + if (previewProfile != nullptr) { + surface->SetUserData(CameraManager::surfaceFormat, std::to_string(previewProfile->GetCameraFormat())); + } + previewOutputNapi->previewOutput_->RemoveDeferredSurface(surface); + return CameraNapiUtils::GetUndefinedValue(env); +} + napi_value PreviewOutputNapi::Start(napi_env env, napi_callback_info info) { MEDIA_INFO_LOG("Start is called"); diff --git a/frameworks/native/camera/base/src/output/preview_output.cpp b/frameworks/native/camera/base/src/output/preview_output.cpp index 7b38131f8..da00b461a 100644 --- a/frameworks/native/camera/base/src/output/preview_output.cpp +++ b/frameworks/native/camera/base/src/output/preview_output.cpp @@ -207,6 +207,16 @@ void PreviewOutput::AddDeferredSurface(sptr surface) itemStream->AddDeferredSurface(surface->GetProducer()); } +void PreviewOutput::RemoveDeferredSurface(sptr surface) +{ + MEDIA_INFO_LOG("PreviewOutput::RemoveDeferredSurface called"); + CHECK_RETURN_ELOG(surface == nullptr, "PreviewOutput::RemoveDeferredSurface surface is null"); + auto stream = GetStream(); + CHECK_RETURN_ELOG(!stream, "PreviewOutput::RemoveDeferredSurface itemStream is null"); + sptr itemStream = static_cast(stream.GetRefPtr()); + itemStream->RemoveDeferredSurface(surface->GetProducer()); +} + int32_t PreviewOutput::Start() { std::lock_guard lock(asyncOpMutex_); diff --git a/interfaces/inner_api/native/camera/include/output/preview_output.h b/interfaces/inner_api/native/camera/include/output/preview_output.h index b11fcbfae..385ca66f1 100644 --- a/interfaces/inner_api/native/camera/include/output/preview_output.h +++ b/interfaces/inner_api/native/camera/include/output/preview_output.h @@ -106,6 +106,13 @@ public: */ void AddDeferredSurface(sptr surface); + /** + * @brief Remove delayed preview surface. + * + * @param surface to remove. + */ + void RemoveDeferredSurface(sptr surface); + /** * @brief Start preview stream. */ diff --git a/interfaces/kits/js/camera_napi/include/output/preview_output_napi.h b/interfaces/kits/js/camera_napi/include/output/preview_output_napi.h index ea86d6be4..2c0f0894b 100644 --- a/interfaces/kits/js/camera_napi/include/output/preview_output_napi.h +++ b/interfaces/kits/js/camera_napi/include/output/preview_output_napi.h @@ -98,6 +98,7 @@ public: static napi_value CreateDeferredPreviewOutput(napi_env env, Profile& profile); static bool IsPreviewOutput(napi_env env, napi_value obj); static napi_value AddDeferredSurface(napi_env env, napi_callback_info info); + static napi_value RemoveDeferredSurface(napi_env env, napi_callback_info info); static napi_value Start(napi_env env, napi_callback_info info); static napi_value Stop(napi_env env, napi_callback_info info); static napi_value Release(napi_env env, napi_callback_info info); diff --git a/services/camera_service/idls/IStreamRepeat.idl b/services/camera_service/idls/IStreamRepeat.idl index 9b5345ea8..c7ad72542 100644 --- a/services/camera_service/idls/IStreamRepeat.idl +++ b/services/camera_service/idls/IStreamRepeat.idl @@ -37,4 +37,5 @@ interface IStreamRepeat extends IStreamCommon { [ipccode 13] void SetCameraApi([in] unsigned int apiCompatibleVersion); [ipccode 14] void GetMirror([out] boolean isEnable); [ipccode 15] void UnSetCallback(); + [ipccode 20] void RemoveDeferredSurface([in] IBufferProducer producer); } \ No newline at end of file diff --git a/services/camera_service/include/hstream_repeat.h b/services/camera_service/include/hstream_repeat.h index 44f5f76a4..48a83fce7 100644 --- a/services/camera_service/include/hstream_repeat.h +++ b/services/camera_service/include/hstream_repeat.h @@ -68,6 +68,7 @@ public: int32_t OnSketchStatusChanged(SketchStatus status); int32_t OnDeferredVideoEnhancementInfo(CaptureEndedInfoExt captureEndedInfo); int32_t AddDeferredSurface(const sptr& producer) override; + int32_t RemoveDeferredSurface(const sptr& producer) override; int32_t ForkSketchStreamRepeat( int32_t width, int32_t height, sptr& sketchStream, float sketchRatio) override; int32_t RemoveSketchStreamRepeat() override; diff --git a/services/camera_service/src/hstream_repeat.cpp b/services/camera_service/src/hstream_repeat.cpp index f895c2d5c..564671634 100644 --- a/services/camera_service/src/hstream_repeat.cpp +++ b/services/camera_service/src/hstream_repeat.cpp @@ -563,6 +563,27 @@ int32_t HStreamRepeat::AddDeferredSurface(const sptr& pro return CAMERA_OK; } +int32_t HStreamRepeat::RemoveDeferredSurface(const sptr& producer) +{ + MEDIA_INFO_LOG("HStreamRepeat::RemoveDeferredSurface called"); + { + std::lock_guard lock(producerLock_); + CHECK_RETURN_RET_ELOG( + producer == nullptr, CAMERA_INVALID_ARG, "HStreamRepeat::RemoveDeferredSurface producer is null"); + producer_ = producer; + } + auto streamOperator = GetStreamOperator(); + CHECK_RETURN_RET_ELOG(streamOperator == nullptr, CAMERA_INVALID_STATE, + "HStreamRepeat::RemoveDeferredSurface(), streamOperator_ == null"); + MEDIA_INFO_LOG("HStreamRepeat::DetachBufferQueue start streamId:%{public}d, hdiStreamId:%{public}d", + GetFwkStreamId(), GetHdiStreamId()); + CamRetCode rc = (CamRetCode)(streamOperator->DetachBufferQueue(GetHdiStreamId())); + CHECK_PRINT_ELOG(rc != HDI::Camera::V1_0::NO_ERROR, + "HStreamRepeat::DetachBufferQueue(), Failed to DetachBufferQueue %{public}d", rc); + MEDIA_INFO_LOG("HStreamRepeat::RemoveDeferredSurface end %{public}d", rc); + return CAMERA_OK; +} + int32_t HStreamRepeat::ForkSketchStreamRepeat( int32_t width, int32_t height, sptr& sketchStream, float sketchRatio) { -- Gitee