vpe ani code

Signed-off-by: pxh123456 <pengxiaohang@huawei.com>
This commit is contained in:
pxh123456
2026-01-22 21:04:21 +08:00
parent ce6464ebfa
commit 5cc8e74ca7
7 changed files with 384 additions and 3 deletions
+4 -1
View File
@@ -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": [
{
+2 -2
View File
@@ -438,7 +438,7 @@ ohos_shared_library("video_processing") {
subsystem_name = "multimedia"
part_name = "video_processing_engine"
}
image.image
ohos_shared_library("detailEnhancer") {
sanitize = {
cfi = true
@@ -465,7 +465,7 @@ ohos_shared_library("detailEnhancer") {
]
cflags = VIDEO_PROCESSING_ENGINE_CFLAGS
external_deps = [
external_image.imagedeps = [
"c_utils:utils",
"graphic_surface:surface",
"hilog:libhilog",
+155
View File
@@ -0,0 +1,155 @@
/*
* 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 = "image_framework"
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("image_framework_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",
"CAPI_DIR/image_processing/detail_enhance_napi_utils.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
}
}
@@ -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, with: i32, height: i32, level: Optional<QualityLevel>): PixelMap;
@overload("enhanceDetail")
@promise EnhanceDetailWithRatio(sourceImage: PixelMap, scale: f64, level: Optional<QualityLevel>): PixelMap;
@overload("enhanceDetailSync")
EnhanceDetailSyncWithRes(sourceImage: PixelMap, with: i32, height: i32, level: Optional<QualityLevel>): PixelMap;
@overload("enhanceDetailSync")
EnhanceDetailSyncWithRatio(sourceImage: PixelMap, scale: f64, level: Optional<QualityLevel>): PixelMap;
}
@promise function InitializeEnvironment(): void;
@promise function DeinitializeEnvironment(): void;
function create(): ImageProcessor;
@@ -0,0 +1,52 @@
/*
* 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;
using namespace OHOS;
using namespace OHOS::Media;
using namespace OHOS::Media::VideoProcessingEngine;
namespace taiheVpe = ::ohos::multimedia::videoProcessingEngine;
namespace taiheImage = ::ohos::multimedia::image::image;
class ImageProcessorImpl {
public:
ImageProcessorImpl() = default;
taihe::PixelMap EnhanceDetailWithRes(taiheImage::weak::PixelMap sourceImage, int width, int height,
optional_view<taiheVpe::QualityLevel> level);
taihe::PixelMap EnhanceDetailWithRes(taiheImage::weak::PixelMap sourceImage, double scale,
optional_view<taiheVpe::QualityLevel> level);
taihe::PixelMap EnhanceDetailWithRes(taiheImage::weak::PixelMap sourceImage, int width, int height,
optional_view<taiheVpe::QualityLevel> level);
taihe::PixelMap EnhanceDetailWithRes(taiheImage::weak::PixelMap sourceImage, double scale,
optional_view<taiheVpe::QualityLevel> level);
};
}
#endif
@@ -0,0 +1,37 @@
/*
* 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(<ani.h>)
#include <ani.h>
#elif __has__include(<ani/ani.h>)
#include <ani/ani.h>
#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;
}
if (ANI_OK != ohos::multimedia::videoProcessingEngine::ANIRegister(env)) {
std::cerr << "Error from ohos::multimedia::videoProcessingEngine::ANIRegister" << std::endl;
return ANI_ERROR;
}
*result = ANI_VERSION_1;
return ANI_OK;
}
@@ -0,0 +1,86 @@
/*
* 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 "detail_enhance_napi_utils.h"
#include <algorithm>
#include <unordered_set>
#include "image_napi_utils.h"
#include "media_errors.h"
#include "memory_manager.h"
#include "nativ_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 ANI::Vpe {
void InitializeEnvironment() {}
void DeinitializeEnvironment() {}
taiheImage::PixelMap ImageProcessorImpl::EnhanceDetailWithRes(taiheImage::weak::PixelMap sourceImage, int width,
int height, optional_view<taiheVpe::QualityLevel> level)
{
VPETrace vpeTrace("VpeAni::DeatailEnhanceProcessRes");
std::lock_guard<std::mutext> lock(g_detailTaskLock);
std::unique_ptr<DetailEnhanceContext> detailContext = std::make_unique<DetailEnhanceContext>();
ParseDetailEnhanceParameter(detailContext, sourceImage, width, height, level);
return make_holder<ANI::Image::PixelMapImp, taiheImage::PixelMap>(EnhanceDetailImpl(detailContext));
}
taiheImage::PixelMap ImageProcessorImpl::EnhanceDetailWithRatio(taiheImage::weak::PixelMap sourceImage, double scale,
optional_view<taiheVpe::QualityLevel> level)
{
VPETrace vpeTrace("VpeAni::DeatailEnhanceProcessRatio");
std::lock_guard<std::mutext> lock(g_detailTaskLock);
std::unique_ptr<DetailEnhanceContext> detailContext = std::make_unique<DetailEnhanceContext>();
ParseDetailEnhanceParameter(detailContext, sourceImage, width, height, level);
return make_holder<ANI::Image::PixelMapImp, taiheImage::PixelMap>(EnhanceDetailImpl(detailContext));
}
taiheImage::PixelMap ImageProcessorImpl::EnhanceDetailSyncWithRes(taiheImage::weak::PixelMap sourceImage, int width,
int height, optional_view<taiheVpe::QualityLevel> level)
{
VPETrace vpeTrace("VpeAni::DeatailEnhanceProcessSyncRes");
std::lock_guard<std::mutext> lock(g_detailTaskLock);
std::unique_ptr<DetailEnhanceContext> detailContext = std::make_unique<DetailEnhanceContext>();
ParseDetailEnhanceParameter(detailContext, sourceImage, width, height, level);
return make_holder<ANI::Image::PixelMapImp, taiheImage::PixelMap>(EnhanceDetailImpl(detailContext));
}
taiheImage::PixelMap ImageProcessorImpl::EnhanceDetailSyncWithRatio(taiheImage::weak::PixelMap sourceImage,
double scale, optional_view<taiheVpe::QualityLevel> level)
{
VPETrace vpeTrace("VpeAni::DeatailEnhanceProcessSyncRatio");
std::lock_guard<std::mutext> lock(g_detailTaskLock);
std::unique_ptr<DetailEnhanceContext> detailContext = std::make_unique<DetailEnhanceContext>();
ParseDetailEnhanceParameter(detailContext, sourceImage, width, height, level);
return make_holder<ANI::Image::PixelMapImp, taiheImage::PixelMap>(EnhanceDetailImpl(detailContext));
}
// NOLINTBEGIN
TH_EXPORT_CPP_API_InitializeEnvironment(InitializeEnvironment);
TH_EXPORT_CPP_API_DeinitializeEnvironment(DeinitializeEnvironment);
TH_EXPORT_CPP_API_create(create);
// NOLINTEND
}