!54 merge master into master

add vpe taihe impl

Created-by: pxh123456
Commit-by: pxh123456
Merged-by: openharmony_ci
Description: ### 一、内容说明(相关的Issue)

https://gitcode.com/openharmony/multimedia_video_processing_engine/issues/36

### 二、建议测试周期和提测地址  
  建议测试完成时间:2026.3.9
  投产上线时间:2026.3.9
  提测地址:CI环境/压测环境  
  测试账号:  

### 三、变更内容
  * 3.1 关联PR列表
无
  * 3.2 数据库和部署说明  
    1. 常规更新 
    2. 重启unicorn
    3. 重启sidekiq
    4. 迁移任务:是否有迁移任务,没有写 "无"
    5. rake脚本:`bundle exec xxx RAILS_ENV = production`;没有写 "无"

  * 3.4 其他技术优化内容(做了什么,变更了什么)
补充vpe静态接口实现


  * 3.5 废弃通知(什么字段、方法弃用?)
无


  * 3.6  后向不兼容变更(是否有无法向后兼容的变更?)
无

  
### 四、研发自测点(自测哪些?冒烟用例全部自测?)
  自测测试结论:pass


### 五、测试关注点(需要提醒QA重点关注的、可能会忽略的地方)
  检查点:静态接口功能

| 需求名称 | 是否影响xx公共模块 | 是否需要xx功能 | 需求升级是否依赖其他子产品 |
|------|------------|----------|---------------|
| xxx  | 否          | 需要       | 不需要           |
|      |            |          |               |

  接口测试:

  性能测试:

  并发测试:

  其他:



See merge request: openharmony/multimedia_video_processing_engine!54
This commit is contained in:
openharmony_ci
2026-03-16 14:32:39 +08:00
2 changed files with 136 additions and 3 deletions
@@ -61,6 +61,14 @@ private:
taiheImage::weak::PixelMap sourceImage, double scale, taihe::optional_view<taiheVpe::QualityLevel> level);
std::shared_ptr<OHOS::Media::PixelMap> EnhanceDetail(std::unique_ptr<DetailEnhanceContext>& detailContext);
std::shared_ptr<OHOS::Media::PixelMap> EnhanceDetailImpl(std::unique_ptr<DetailEnhanceContext>& context);
std::shared_ptr<OHOS::Media::PixelMap> PrepareDstPixelMap(std::unique_ptr<DetailEnhanceContext>& context);
bool SetDetailAlgoParam(int level);
bool InitDetailAlgo();
bool ConvertPixelmapToSurfaceBuffer(const std::shared_ptr<OHOS::Media::PixelMap>& pixelmap,
OHOS::sptr<OHOS::SurfaceBuffer>& bufferImpl);
OHOS::sptr<OHOS::SurfaceBuffer> GetSurfaceBufferFromDMAPixelMap(
const std::shared_ptr<OHOS::Media::PixelMap>& pixelmap);
void ThrowExceptionError(const int32_t errCode, const std::string& errMsg);
};
}
#endif
@@ -34,6 +34,9 @@
#include "vpe_utils.h"
namespace {
constexpr int32_t MIN_RESOLUTION_DETAIL = 32; // min support resolution 32, consistent with fwk
constexpr int32_t MAX_RESOLUTION_DETAIL = 8192; // max support resolution 8192, consistent with fwk
static std::shared_ptr<OHOS::Media::VideoProcessingEngine::DetailEnhancerImage> g_detailEnh{};
static std::mutex g_detailTaskLock{std::mutex()};
}
@@ -47,6 +50,12 @@ namespace ANI::Vpe {
void InitializeEnvironment() {}
void DeinitializeEnvironment() {}
void ImageProcessorImpl::ThrowExceptionError(const int32_t errCode, const std::string& errMsg)
{
VPE_LOGE("errCode: %{public}d, errMsg: %{public}s", errCode, errMsg.c_str());
taihe::set_business_error(errCode, errMsg);
}
taiheVpe::ImageProcessor create()
{
return make_holder<ImageProcessorImpl, taiheVpe::ImageProcessor>();
@@ -86,9 +95,51 @@ void ImageProcessorImpl::ParseDetailEnhanceParameter(std::unique_ptr<DetailEnhan
detailContext->inputPixelMap = pixelMapImpl->GetNativePtr();
}
std::shared_ptr<PixelMap> ImageProcessorImpl::PrepareDstPixelMap(std::unique_ptr<DetailEnhanceContext>& context)
{
CHECK_AND_RETURN_RET_LOG(context->inputPixelMap->GetWidth() >= MIN_RESOLUTION_DETAIL &&
context->inputPixelMap->GetHeight() >= MIN_RESOLUTION_DETAIL &&
context->inputPixelMap->GetWidth() <= MAX_RESOLUTION_DETAIL &&
context->inputPixelMap->GetHeight() <= MAX_RESOLUTION_DETAIL,
nullptr, "invalid resolution");
InitializationOptions opts {
.size = {
.width = static_cast<int>(context->xArg),
.height = static_cast<int>(context->yArg),
},
};
VPE_LOGD("res:w %{public}d, h %{public}d, -> w %{public}d, h %{public}d",
context->inputPixelMap->GetWidth(), context->inputPixelMap->GetHeight(),
static_cast<int>(context->xArg), static_cast<int>(context->yArg));
std::unique_ptr<PixelMap> outputPtr = context->inputPixelMap->Create(*context->inputPixelMap, opts);
if (outputPtr == nullptr) {
ThrowExceptionError(IMAGE_PROCESSING_ERROR_INVALID_VALUE, "create failed");
return nullptr;
}
std::shared_ptr<PixelMap> dstPixelMap{std::move(outputPtr)};
return dstPixelMap;
}
bool ImageProcessorImpl::SetDetailAlgoParam(int level)
{
DetailEnhancerParameters param {
.uri = "",
.level = static_cast<DetailEnhancerLevel>(level),
};
if (g_detailEnh->SetParameter(param)!= VPE_ALGO_ERR_OK) {
ThrowExceptionError(IMAGE_PROCESSING_ERROR_CREATE_FAILED, "set parameter failed");
return false;
}
return true;
}
std::shared_ptr<OHOS::Media::PixelMap> ImageProcessorImpl::EnhanceDetail(
std::unique_ptr<DetailEnhanceContext>& detailContext)
{
if (detailContext == nullptr) {
VPE_LOGE("detail context is nullptr");
return nullptr;
}
std::shared_ptr<OHOS::Media::PixelMap> outputPixelMap = EnhanceDetailImpl(detailContext);
detailContext->inputPixelMap = nullptr; // Dereferencing prevents memory leaks
if (outputPixelMap == nullptr) {
@@ -98,10 +149,84 @@ std::shared_ptr<OHOS::Media::PixelMap> ImageProcessorImpl::EnhanceDetail(
return outputPixelMap;
}
std::shared_ptr<OHOS::Media::PixelMap> ImageProcessorImpl::EnhanceDetailImpl(
std::unique_ptr<DetailEnhanceContext>& detailContext)
bool ImageProcessorImpl::InitDetailAlgo()
{
return nullptr;
VPETrace vpeTrace("ImageProcessorImpl::DetailEnhanceInitAlgo");
if (g_detailEnh != nullptr) {
VPE_LOGW("DetailEnhancerImage handle has created");
return true;
}
g_detailEnh = DetailEnhancerImage::Create();
CHECK_AND_RETURN_RET_LOG(g_detailEnh != nullptr, false, "create DetailEnhancerImage failed");
return true;
}
bool ImageProcessorImpl::ConvertPixelmapToSurfaceBuffer(const std::shared_ptr<OHOS::Media::PixelMap>& pixelmap,
sptr<SurfaceBuffer>& bufferImpl)
{
BufferRequestConfig bfConfig = {};
bfConfig.width = pixelmap->GetWidth();
bfConfig.height = pixelmap->GetHeight();
bfConfig.usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA | BUFFER_USAGE_MEM_MMZ_CACHE;
bfConfig.strideAlignment = bfConfig.width;
bfConfig.format = GraphicPixelFormat::GRAPHIC_PIXEL_FMT_RGBA_8888;
bfConfig.timeout = 0;
bfConfig.colorGamut = GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB;
bfConfig.transform = GraphicTransformType::GRAPHIC_ROTATE_NONE;
CHECK_AND_RETURN_RET_LOG((bufferImpl->Alloc(bfConfig) == GSERROR_OK), false, "invalid OH_PixelmapNative image");
return true;
}
sptr<SurfaceBuffer> ImageProcessorImpl::GetSurfaceBufferFromDMAPixelMap(
const std::shared_ptr<OHOS::Media::PixelMap>& pixelmap)
{
CHECK_AND_RETURN_RET_LOG(pixelmap != nullptr, nullptr, "pixelmap == nullptr");
if (pixelmap->GetAllocatorType() == AllocatorType::DMA_ALLOC) {
return reinterpret_cast<SurfaceBuffer*>(pixelmap->GetFd());
}
auto buffer = SurfaceBuffer::Create();
CHECK_AND_RETURN_RET_LOG(buffer != nullptr, nullptr, "get surface buffer failed!");
CHECK_AND_RETURN_RET_LOG(ConvertPixelmapToSurfaceBuffer(pixelmap, buffer), nullptr,
"get surface buffer failed!");
return buffer;
}
std::shared_ptr<OHOS::Media::PixelMap> ImageProcessorImpl::EnhanceDetailImpl(
std::unique_ptr<DetailEnhanceContext>& context)
{
VPETrace vpeTrace("ImageProcessorImpl::DetailEnhanceImpl");
if (context == nullptr) {
VPE_LOGE("context == nullptr");
return nullptr;
}
if (context->inputPixelMap->GetPixelFormat() == PixelFormat::YCBCR_P010 ||
context->inputPixelMap->GetPixelFormat() == PixelFormat::YCRCB_P010) {
VPE_LOGI("not support P010");
return context->inputPixelMap;
}
if (!InitDetailAlgo()) {
VPE_LOGE("init algo failed");
ThrowExceptionError(IMAGE_PROCESSING_ERROR_CREATE_FAILED, "init algo failed");
return nullptr;
}
if (!SetDetailAlgoParam(context->qualityLevel)) {
VPE_LOGE("set detail param failed");
return nullptr;
}
if (context->inputPixelMap == nullptr) {
VPE_LOGE("*context->inputPixelMap == nullptr");
return nullptr;
}
auto dstPixelMap = PrepareDstPixelMap(context);
if (dstPixelMap == nullptr) {
VPE_LOGE("move failed");
return nullptr;
}
auto output = GetSurfaceBufferFromDMAPixelMap(dstPixelMap);
auto input = GetSurfaceBufferFromDMAPixelMap(context->inputPixelMap);
CHECK_AND_RETURN_RET_LOG((g_detailEnh != nullptr && g_detailEnh->Process(input, output) == VPE_ALGO_ERR_OK),
nullptr, "process failed");
return dstPixelMap;
}
taiheImage::PixelMap ImageProcessorImpl::EnhanceDetailWithRes(taiheImage::weak::PixelMap sourceImage, int width,