diff --git a/bundle.json b/bundle.json index e79f618..83f79dc 100644 --- a/bundle.json +++ b/bundle.json @@ -35,6 +35,7 @@ "media_foundation", "napi", "ipc", + "runtime_core", "safwk", "samgr", "eventhandler", @@ -51,7 +52,9 @@ "build": { "sub_component": [ "//foundation/multimedia/video_processing_engine/framework:videoprocessingengine", - "//foundation/multimedia/video_processing_engine/services:video_processing_service_group" + "//foundation/multimedia/video_processing_engine/services:video_processing_service_group", + "//foundation/multimedia/video_processing_engine/interfaces/kits/taihe:video_processing_engine_taihe_gen_only", + "//foundation/multimedia/video_processing_engine/interfaces/kits/taihe:video_processing_engine_taihe_group" ], "inner_kits": [ { diff --git a/framework/BUILD.gn b/framework/BUILD.gn index be44261..97cee84 100644 --- a/framework/BUILD.gn +++ b/framework/BUILD.gn @@ -457,7 +457,6 @@ ohos_shared_library("detailEnhancer") { ] sources = [ "//foundation/multimedia/video_processing_engine/framework/capi/image_processing/detail_enhance_napi.cpp", - "//foundation/multimedia/image_framework/frameworks/innerkitsimpl/common/src/memory_manager.cpp", ] deps = [ diff --git a/interfaces/kits/taihe/BUILD.gn b/interfaces/kits/taihe/BUILD.gn new file mode 100644 index 0000000..8e50e5a --- /dev/null +++ b/interfaces/kits/taihe/BUILD.gn @@ -0,0 +1,150 @@ +# Copyright (c) 2026 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") +import("//foundation/multimedia/video_processing_engine/config.gni") + +subsystem_name = "multimedia" +part_name = "video_processing_engine" +taihe_generated_file_path = "$taihe_file_path/out/$subsystem_name/$part_name" + +config("video_processing_engine_taihe_config") { + visibility = [ ":*" ] + include_dirs = [ "include" ] +} + +copy_taihe_idl("copy_video_processing_engine_taihe") { + sources = [ + "$INTERFACES_DIR/kits/taihe/idl/ohos.multimedia.videoProcessingEngine.taihe", + ] + + external_deps = [ + "image_framework:copy_image_taihe" + ] +} + +ohos_taihe("run_taihe") { + taihe_generated_file_path = "$taihe_generated_file_path" + deps = [ ":copy_video_processing_engine_taihe" ] + outputs = [ + "$taihe_generated_file_path/src/ohos.multimedia.videoProcessingEngine.ani.cpp", + "$taihe_generated_file_path/src/ohos.multimedia.videoProcessingEngine.abi.c", + ] +} + +generate_static_abc("video_processing_engine_taihe_abc") { + base_url = "$taihe_generated_file_path" + files = [ "$taihe_generated_file_path/@ohos.multimedia.videoProcessingEngine.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/video_processing_engine_taihe_abc.abc" + dependencies = [ ":run_taihe" ] +} + +ohos_prebuilt_etc("video_processing_engine_etc") { + source = "$target_out_dir/video_processing_engine_taihe_abc.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":video_processing_engine_taihe_abc" ] +} + +group("video_processing_engine_taihe_group") { + deps = [ + ":video_processing_engine_etc", + ":video_processing_engine_taihe_core", + ] +} + +group("video_processing_engine_taihe_gen_only") { + deps = [ ":run_taihe" ] +} + +taihe_shared_library("video_processing_engine_taihe") { + taihe_generated_file_path = "$taihe_generated_file_path" + subsystem_name = "$subsystem_name" + part_name = "$part_name" + + public_configs = [ ":video_processing_engine_taihe_config" ] + + include_dirs = [ + "include/video_processing_engine_taihe.h", + "$DFX_DIR/include", + "$INTERFACES_DIR/kits/js", + "$INTERFACES_INNER_API_DIR", + "$CAPI_DIR/image_processing/include/", + "$ALGORITHM_COMMON_DIR/include/", + "$INTERFACES_CAPI_DIR", + ] + + sources = get_target_outputs(":run_taihe") + sources += [ + "src/video_processing_engine_taihe.cpp", + ] + + deps = [ + ":run_taihe", + "$VIDEO_PROCESSING_ENGINE_ROOT_DIR/framework:videoprocessingengine", + ] + + external_deps = [ + "c_utils:utils", + "drivers_interface_display:libdisplay_commontype_proxy_2.1", + "graphic_surface:surface", + "hilog:libhilog", + "hitrace:hitrace_meter", + "image_framework:image_utils", + "image_framework:image_native", + "image_framework:pixelmap", + "image_framework:image", + "image_framework:image_taihe", + "ipc:ipc_napi", + "media_foundation:native_media_core", + "media_foundation:media_foundation", + "runtime_core:ani_helpers", + ] + + cflags = [ + "-DIMAGE_DEBUG_FLAG", + "-DIMAGE_COLORSPACE_FLAG", + ] + + sanitize = { + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + integer_overflow = true + ubsan = true + debug = false + } +} + +taihe_shared_library("video_processing_engine_taihe_core") { + taihe_generated_file_path = "$taihe_generated_file_path" + subsystem_name = "$subsystem_name" + part_name = "$part_name" + shlib_type = "ani" + + sources = [ "src/ani_constructor.cpp" ] + deps = [ ":video_processing_engine_taihe" ] + + sanitize = { + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + integer_overflow = true + ubsan = true + debug = false + } +} \ No newline at end of file diff --git a/interfaces/kits/taihe/idl/ohos.multimedia.videoProcessingEngine.taihe b/interfaces/kits/taihe/idl/ohos.multimedia.videoProcessingEngine.taihe new file mode 100644 index 0000000..b97d6fa --- /dev/null +++ b/interfaces/kits/taihe/idl/ohos.multimedia.videoProcessingEngine.taihe @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2026 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@!namespace("@ohos.multimedia.videoProcessingEngine", "videoProcessingEngine") +@!sts_export_default +@!sts_inject(""" +static { loadLibraryWithPermissionCheck("video_processing_engine_taihe_core.z", "@ohos.multimedia.videoProcessingEngine"); } +""") + +from ohos.multimedia.image.image use PixelMap; + +enum QualityLevel : i32 { + NONE = 0, + LOW = 1, + MEDIUM = 2, + HIGH = 3 +} + +interface ImageProcessor { +@overload("enhanceDetail") +@promise EnhanceDetailWithRes(sourceImage: PixelMap, width: i32, height: i32, level: Optional): PixelMap; + +@overload("enhanceDetail") +@promise EnhanceDetailWithRatio(sourceImage: PixelMap, scale: f64, level: Optional): PixelMap; + +@overload("enhanceDetailSync") +EnhanceDetailSyncWithRes(sourceImage: PixelMap, width: i32, height: i32, level: Optional): PixelMap; + +@overload("enhanceDetailSync") +EnhanceDetailSyncWithRatio(sourceImage: PixelMap, scale: f64, level: Optional): PixelMap; +} + +@promise function InitializeEnvironment(): void; +@promise function DeinitializeEnvironment(): void; + +function create(): ImageProcessor; \ No newline at end of file diff --git a/interfaces/kits/taihe/include/video_processing_engine_taihe.h b/interfaces/kits/taihe/include/video_processing_engine_taihe.h new file mode 100644 index 0000000..d3c2b61 --- /dev/null +++ b/interfaces/kits/taihe/include/video_processing_engine_taihe.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2026 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_KITS_TAIHE_INCLUDE_VIDEO_PROCESSING_ENGINE_TAIHE_H +#define FRAMEWORKS_KITS_TAIHE_INCLUDE_VIDEO_PROCESSING_ENGINE_TAIHE_H + +#include "ohos.multimedia.videoProcessingEngine.impl.hpp" +#include "ohos.multimedia.videoProcessingEngine.proj.hpp" + +#include "detail_enhancer_image.h" +#include "image_type.h" +#include "image_processing_types.h" +#include "pixel_map.h" + +#include "taihe/runtime.hpp" +#include "pixel_map_taihe.h" + +namespace ANI::Vpe { +using namespace taihe; +namespace taiheVpe = ::ohos::multimedia::videoProcessingEngine; +namespace taiheImage = ::ohos::multimedia::image::image; + +class ImageProcessorImpl { +public: + ImageProcessorImpl() = default; + ~ImageProcessorImpl() = default; + taiheImage::PixelMap EnhanceDetailWithRes(taiheImage::weak::PixelMap sourceImage, int width, int height, + taihe::optional_view level); + taiheImage::PixelMap EnhanceDetailWithRatio(taiheImage::weak::PixelMap sourceImage, double scale, + taihe::optional_view level); + taiheImage::PixelMap EnhanceDetailSyncWithRes(taiheImage::weak::PixelMap sourceImage, int width, int height, + taihe::optional_view level); + taiheImage::PixelMap EnhanceDetailSyncWithRatio(taiheImage::weak::PixelMap sourceImage, double scale, + taihe::optional_view level); + +private: + struct DetailEnhanceContext { + double xArg{}; + double yArg{}; + int32_t qualityLevel{}; + std::shared_ptr inputPixelMap{}; + std::shared_ptr outputPixelMap{}; + }; + + void ParseDetailEnhanceParameter(std::unique_ptr& detailContext, + taiheImage::weak::PixelMap sourceImage, int width, int height, + taihe::optional_view level); + void ParseDetailEnhanceParameter(std::unique_ptr& detailContext, + taiheImage::weak::PixelMap sourceImage, double scale, taihe::optional_view level); + std::shared_ptr EnhanceDetail(std::unique_ptr& detailContext); + std::shared_ptr EnhanceDetailImpl(std::unique_ptr& context); +}; +} +#endif \ No newline at end of file diff --git a/interfaces/kits/taihe/src/ani_constructor.cpp b/interfaces/kits/taihe/src/ani_constructor.cpp new file mode 100644 index 0000000..9c2b0a1 --- /dev/null +++ b/interfaces/kits/taihe/src/ani_constructor.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2026 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos.multimedia.videoProcessingEngine.ani.hpp" +#if __has_include() +#include +#elif __has_include() +#include +#else +#error "ani.h not found. Please ensure the Ani SDK is correctly installed." +#endif + +ANI_EXPORT ani_status ANI_Constructor(ani_vm* vm, uint32_t* result) +{ + ani_env* env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + return ANI_ERROR; + } + ani_status status = ANI_OK; + if (ANI_OK != ohos::multimedia::videoProcessingEngine::ANIRegister(env)) { + std::cerr << "Error from ohos::multimedia::videoProcessingEngine::ANIRegister" << std::endl; + status = ANI_ERROR; + } + *result = ANI_VERSION_1; + return status; +} diff --git a/interfaces/kits/taihe/src/video_processing_engine_taihe.cpp b/interfaces/kits/taihe/src/video_processing_engine_taihe.cpp new file mode 100644 index 0000000..2888e7c --- /dev/null +++ b/interfaces/kits/taihe/src/video_processing_engine_taihe.cpp @@ -0,0 +1,165 @@ +/* + * Copyright (C) 2026 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "video_processing_engine_taihe.h" + +#include "detail_enhance_napi_formal.h" + +#include +#include + +#include "image_napi_utils.h" +#include "media_errors.h" +#include "memory_manager.h" +#include "native_avformat.h" +#include "pixelmap_native_impl.h" +#include "pixelmap_native.h" +#include "surface_buffer.h" + +#include "detail_enhancer_common.h" +#include "vpe_log.h" +#include "vpe_trace.h" +#include "vpe_utils.h" + +namespace { +static std::mutex g_detailTaskLock{std::mutex()}; +} + +using namespace taihe; +using namespace OHOS::Media; +using namespace VideoProcessingEngine; +using namespace ANI; +using namespace ANI::Vpe; + +namespace ANI::Vpe { +void InitializeEnvironment() {} +void DeinitializeEnvironment() {} + +taiheVpe::ImageProcessor create() +{ + return make_holder(); +} +} // namespace + +void ImageProcessorImpl::ParseDetailEnhanceParameter(std::unique_ptr& detailContext, + taiheImage::weak::PixelMap sourceImage, int width, int height, optional_view level) +{ + if (detailContext == nullptr) { + VPE_LOGE("detailContext == nullptr"); + return; + } + ANI::Image::PixelMapImpl* pixelMapImpl = reinterpret_cast(sourceImage->GetImplPtr()); + detailContext->xArg = width; + detailContext->yArg = height; + if (level.has_value()) { + detailContext->qualityLevel = level.value(); + } + detailContext->inputPixelMap = pixelMapImpl->GetNativePtr(); +} + +void ImageProcessorImpl::ParseDetailEnhanceParameter(std::unique_ptr& detailContext, + taiheImage::weak::PixelMap sourceImage, double scale, optional_view level) +{ + if (detailContext == nullptr) { + VPE_LOGE("detailContext == nullptr"); + return; + } + ANI::Image::PixelMapImpl* pixelMapImpl = reinterpret_cast(sourceImage->GetImplPtr()); + std::shared_ptr inputPixelMap = pixelMapImpl->GetNativePtr(); + detailContext->xArg = inputPixelMap->GetWidth() * scale; + detailContext->yArg = inputPixelMap->GetHeight() * scale; + if (level.has_value()) { + detailContext->qualityLevel = level.value(); + } + detailContext->inputPixelMap = pixelMapImpl->GetNativePtr(); +} + +std::shared_ptr ImageProcessorImpl::EnhanceDetail( + std::unique_ptr& detailContext) +{ + std::shared_ptr outputPixelMap = EnhanceDetailImpl(detailContext); + detailContext->inputPixelMap = nullptr; // Dereferencing prevents memory leaks + if (outputPixelMap == nullptr) { + VPE_LOGE("DetailEnhance processed failed"); + return nullptr; + } + return outputPixelMap; +} + +std::shared_ptr ImageProcessorImpl::EnhanceDetailImpl( + std::unique_ptr& detailContext) +{ + return nullptr; +} + +taiheImage::PixelMap ImageProcessorImpl::EnhanceDetailWithRes(taiheImage::weak::PixelMap sourceImage, int width, + int height, optional_view level) +{ + VPETrace vpeTrace("VpeAni::DeatailEnhanceProcessRes"); + std::unique_ptr detailContext = std::make_unique(); + if (detailContext == nullptr) { + VPE_LOGE("invalid context"); + return make_holder(); + } + ParseDetailEnhanceParameter(detailContext, sourceImage, width, height, level); + return make_holder(EnhanceDetail(detailContext)); +} + +taiheImage::PixelMap ImageProcessorImpl::EnhanceDetailWithRatio(taiheImage::weak::PixelMap sourceImage, double scale, + optional_view level) +{ + VPETrace vpeTrace("VpeAni::DeatailEnhanceProcessRatio"); + std::unique_ptr detailContext = std::make_unique(); + if (detailContext == nullptr) { + VPE_LOGE("invalid context"); + return make_holder(); + } + ParseDetailEnhanceParameter(detailContext, sourceImage, scale, level); + return make_holder(EnhanceDetail(detailContext)); +} + +taiheImage::PixelMap ImageProcessorImpl::EnhanceDetailSyncWithRes(taiheImage::weak::PixelMap sourceImage, int width, + int height, optional_view level) +{ + VPETrace vpeTrace("VpeAni::DeatailEnhanceProcessSyncRes"); + std::lock_guard lock(g_detailTaskLock); + std::unique_ptr detailContext = std::make_unique(); + if (detailContext == nullptr) { + VPE_LOGE("invalid context"); + return make_holder(); + } + ParseDetailEnhanceParameter(detailContext, sourceImage, width, height, level); + return make_holder(EnhanceDetail(detailContext)); +} + +taiheImage::PixelMap ImageProcessorImpl::EnhanceDetailSyncWithRatio(taiheImage::weak::PixelMap sourceImage, + double scale, optional_view level) +{ + VPETrace vpeTrace("VpeAni::DeatailEnhanceProcessSyncRatio"); + std::lock_guard lock(g_detailTaskLock); + std::unique_ptr detailContext = std::make_unique(); + if (detailContext == nullptr) { + VPE_LOGE("invalid context"); + return make_holder(); + } + ParseDetailEnhanceParameter(detailContext, sourceImage, scale, level); + return make_holder(EnhanceDetail(detailContext)); +} + +// NOLINTBEGIN +TH_EXPORT_CPP_API_InitializeEnvironment(InitializeEnvironment); +TH_EXPORT_CPP_API_DeinitializeEnvironment(DeinitializeEnvironment); +TH_EXPORT_CPP_API_create(create); +// NOLINTEND \ No newline at end of file