From 2e27be6dc8de7db627de8525bbd96f9c755550c2 Mon Sep 17 00:00:00 2001 From: mediaTest Date: Fri, 13 Jun 2025 12:04:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=E5=91=8A?= =?UTF-8?q?=E8=AD=A6=E6=B8=85=E7=90=86=E5=90=8C=E6=AD=A56.0=20Beta?= =?UTF-8?q?=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: mediaTest --- test/BUILD.gn | 8 ++- test/ndk/BUILD.gn | 15 ++--- test/ndk/moduletest/common/enum_list.h | 4 +- test/ndk/moduletest/video/BUILD.gn | 1 + test/ndk/moduletest/video/func_test.cpp | 1 - test/ndk/moduletest/video/video_sample.cpp | 78 +++++++++++++--------- test/ndk/moduletest/video/video_sample.h | 8 --- 7 files changed, 61 insertions(+), 54 deletions(-) diff --git a/test/BUILD.gn b/test/BUILD.gn index 074b429..cbb5a3a 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. +# Copyright (c) 2025 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 @@ -54,6 +54,7 @@ declare_args() { contrast_enhancer_unit_test = false services_fuzzer_test = false } + vpe_support_ndk_module_test = true } group("demo_test") { @@ -122,6 +123,11 @@ group("module_test") { "moduletest/metadata_generator_video:metadata_generator_video_module_test", ] } + if (vpe_support_ndk_module_test) { + deps += [ + "ndk:vpe_module_test", + ] + } } group("fuzz_test") { diff --git a/test/ndk/BUILD.gn b/test/ndk/BUILD.gn index 529184e..afee443 100644 --- a/test/ndk/BUILD.gn +++ b/test/ndk/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. +# Copyright (c) 2025 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 @@ -17,14 +17,11 @@ group("vpe_module_test") { testonly = true deps = [] if (!use_libfuzzer) { + if (defined(global_parts_info) && + defined(global_parts_info.multimedia_video_processing_engine_ext)) { + defines += ["ENABLE_ALL_PROCESS"] + } deps += [ "moduletest/video:vpe_video_native_module_test" ] - deps += [ "nativedemo:vpe_video_nativedemo" ] + deps += [ "moduletest/image:vpe_image_native_module_test" ] } } - -group("vpe_fuzz_test") { - testonly = true - deps = [] - - deps += [ "fuzztest/videometadata_fuzzer:VideoMetadataFuzzTest" ] -} \ No newline at end of file diff --git a/test/ndk/moduletest/common/enum_list.h b/test/ndk/moduletest/common/enum_list.h index 3a498a0..6c1f0b3 100644 --- a/test/ndk/moduletest/common/enum_list.h +++ b/test/ndk/moduletest/common/enum_list.h @@ -98,14 +98,14 @@ int32_t NativeBuffer_MetadataType[] = { OH_VIDEO_HDR_HLG, OH_VIDEO_HDR_HDR10, OH_VIDEO_HDR_VIVID, - OH_VIDEO_HDR_NONE + OH_VIDEO_NONE }; std::unordered_map metadataString = { {OH_VIDEO_HDR_HLG, "HDR_HLG"}, {OH_VIDEO_HDR_HDR10, "HDR_HDR10"}, {OH_VIDEO_HDR_VIVID, "HDR_VIVID"}, - {OH_VIDEO_HDR_NONE, "NONE"} + {OH_VIDEO_NONE, "NONE"} }; std::unordered_map formatString = { diff --git a/test/ndk/moduletest/video/BUILD.gn b/test/ndk/moduletest/video/BUILD.gn index 20f7b9a..e63c7fa 100644 --- a/test/ndk/moduletest/video/BUILD.gn +++ b/test/ndk/moduletest/video/BUILD.gn @@ -69,6 +69,7 @@ ohos_unittest("vpe_video_native_module_test") { "media_foundation:native_media_core", "window_manager:libwm", "json:nlohmann_json_static", + "openssl:libcrypto_shared" ] resource_config_file = "$VIDEO_PROCESSING_ENGINE_ROOT_DIR/test/ndk/moduletest/resources/ohos_test.xml" } diff --git a/test/ndk/moduletest/video/func_test.cpp b/test/ndk/moduletest/video/func_test.cpp index a722d2b..8880c60 100644 --- a/test/ndk/moduletest/video/func_test.cpp +++ b/test/ndk/moduletest/video/func_test.cpp @@ -136,7 +136,6 @@ HWTEST_F(VpeVideoFuncTest, VPE_VIDEO_FUNC_TEST_0030, TestSize.Level0) */ HWTEST_F(VpeVideoFuncTest, VPE_VIDEO_FUNC_TEST_0040, TestSize.Level0) { - std::unique_ptr sample = std::make_unique(); sample->inputFilePath = "/data/test/media/vivid_pq_nv21.yuv"; sample->inputMetaPath = "/data/test/media/vivid_pq.bin"; diff --git a/test/ndk/moduletest/video/video_sample.cpp b/test/ndk/moduletest/video/video_sample.cpp index 678e375..0eb3091 100644 --- a/test/ndk/moduletest/video/video_sample.cpp +++ b/test/ndk/moduletest/video/video_sample.cpp @@ -62,7 +62,7 @@ vector VideoSample::LoadHashFile() void VideoSample::ShowHashValue(uint8_t source[]) { for (int32_t i = 0; i < SHA512_DIGEST_LENGTH; i++) { - cout << std::hex << std::setfill('0') << std::setw(2) << int(source[i]); + cout << std::hex << std::setfill('0') << std::setw(sizeof(uint16_t)) << int(source[i]); if (i != SHA512_DIGEST_LENGTH - 1) { cout << ","; } @@ -102,7 +102,7 @@ void VideoSample::ProcessOutputData(SurfaceBuffer *buffer) cropSize = picWidth * picHeight * FOUR; } else if (param_.outFmt == NATIVEBUFFER_PIXEL_FMT_YCBCR_420_SP || param_.outFmt == NATIVEBUFFER_PIXEL_FMT_YCRCB_420_SP) { - cropSize = picWidth * picHeight * THREE >> 1; + cropSize = (picWidth * picHeight * THREE) >> 1; } uint8_t *cropBuffer = new uint8_t[cropSize]; if (param_.outFmt == NATIVEBUFFER_PIXEL_FMT_RGBA_1010102 || @@ -113,7 +113,7 @@ void VideoSample::ProcessOutputData(SurfaceBuffer *buffer) memcpy_s(cropBuffer, cropSize, bufferAddr, picWidth * picHeight * THREE); } else if (param_.outFmt == NATIVEBUFFER_PIXEL_FMT_YCBCR_420_SP || param_.outFmt == NATIVEBUFFER_PIXEL_FMT_YCRCB_420_SP) { - memcpy_s(cropBuffer, cropSize, bufferAddr, picWidth * picHeight * THREE >> 1); + memcpy_s(cropBuffer, cropSize, bufferAddr, (picWidth * picHeight * THREE) >> 1); } outFile->write(reinterpret_cast(cropBuffer), cropSize); outFile->close(); @@ -215,11 +215,12 @@ int32_t VideoSample::InitVideoSample(const int32_t type, int32_t width, int32_t height_ = height; isRunning = true; param_ = param; - int32_t ret = OH_VideoProcessing_Create(&videoProcessor, type); if (type == VIDEO_PROCESSING_TYPE_METADATA_GENERATION) { isMetadataGen = true; } - CHECK_AND_RETURN_RET(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_Create failed"); + if (OH_VideoProcessing_Create(&videoProcessor, type) != VIDEO_PROCESSING_SUCCESS) { + return -1; + } cs = Surface::CreateSurfaceAsConsumer(); sptr listener = new VPEConsumerListener(cs, this); cs->RegisterConsumerListener(listener); @@ -229,11 +230,11 @@ int32_t VideoSample::InitVideoSample(const int32_t type, int32_t width, int32_t (void)OH_NativeWindow_NativeWindowHandleOpt(outWindow, SET_FORMAT, param_.outFmt); if (!isMetadataGen) { (void)OH_NativeWindow_NativeWindowHandleOpt(outWindow, SET_FORMAT, param_.outFmt); - ret = OH_NativeWindow_SetColorSpace(outWindow, param_.outColorSpace); + OH_NativeWindow_SetColorSpace(outWindow, param_.outColorSpace); } if (isHDRVividOut) { uint8_t val = OH_VIDEO_HDR_VIVID; - ret = OH_NativeWindow_SetMetadataValue(outWindow, OH_HDR_METADATA_TYPE, sizeof(uint8_t), &val); + int32_t ret = OH_NativeWindow_SetMetadataValue(outWindow, OH_HDR_METADATA_TYPE, sizeof(uint8_t), &val); if (ret != 0) { cout << "set metadata failed" << endl; } @@ -242,18 +243,20 @@ int32_t VideoSample::InitVideoSample(const int32_t type, int32_t width, int32_t uint8_t outMeta = OH_VIDEO_HDR_HLG; OH_NativeWindow_SetMetadataValue(outWindow, OH_HDR_METADATA_TYPE, sizeof(uint8_t), &outMeta); } - ret = OH_VideoProcessing_SetSurface(videoProcessor, outWindow); - CHECK_AND_RETURN_RET(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_SetSurface failed."); - ret = OH_VideoProcessing_GetSurface(videoProcessor, &inWindow); - CHECK_AND_RETURN_RET(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_GetSurface failed."); + if (OH_VideoProcessing_SetSurface(videoProcessor, outWindow) != VIDEO_PROCESSING_SUCCESS) { + return -1; + } + if (OH_VideoProcessing_GetSurface(videoProcessor, &inWindow) != VIDEO_PROCESSING_SUCCESS) { + return -1; + } SetInputWindowParam(); - ret = OH_VideoProcessingCallback_Create(&callback); - CHECK_AND_RETURN_RET(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessingCallback_Create failed."); + OH_VideoProcessingCallback_Create(&callback); OH_VideoProcessingCallback_BindOnError(callback, OnError); OH_VideoProcessingCallback_BindOnState(callback, OnState); OH_VideoProcessingCallback_BindOnNewOutputBuffer(callback, OnNewOutputBuffer); - ret = OH_VideoProcessing_RegisterCallback(videoProcessor, callback, this); - CHECK_AND_RETURN_RET(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_RegisterCallback failed."); + if (OH_VideoProcessing_RegisterCallback(videoProcessor, callback, this) != VIDEO_PROCESSING_SUCCESS) { + return -1; + } return VIDEO_PROCESSING_SUCCESS; } @@ -318,27 +321,32 @@ void VideoSample::GetMetadata(OH_NativeBuffer *buffer) int32_t VideoSample::InputFunc() { inFile = std::make_unique(inputFilePath); - CHECK_AND_RETURN_RET(inFile->is_open(), -1, "open input file failed"); + if (!inFile->is_open()) { + return 1; + } int fenceFd = -1; OHNativeWindowBuffer *ohNativeWindowBuffer; if (isHDRVivid) { - int32_t ret = OH_NativeWindow_SetMetadataValue(inWindow, OH_HDR_DYNAMIC_METADATA, metadataSize, metaData); - CHECK_AND_RETURN_RET(ret == 0, ret, "set metadata value failed"); + if (OH_NativeWindow_SetMetadataValue(inWindow, OH_HDR_DYNAMIC_METADATA, metadataSize, metaData) != 0) { + return -1; + } + } + if (OH_NativeWindow_NativeWindowRequestBuffer(inWindow, &ohNativeWindowBuffer, &fenceFd) != 0) { + return -1; } - int32_t err = OH_NativeWindow_NativeWindowRequestBuffer(inWindow, &ohNativeWindowBuffer, &fenceFd); - CHECK_AND_RETURN_RET(err == 0, err, "OH_NativeWindow_NativeWindowRequestBuffer failed"); if (fenceFd > 0) { close(fenceFd); } OH_NativeBuffer *nativeBuffer = nullptr; - err = OH_NativeBuffer_FromNativeWindowBuffer(ohNativeWindowBuffer, &nativeBuffer); - CHECK_AND_RETURN_RET(err == 0, err, "OH_NativeBuffer_FromNativeWindowBuffer failed."); + if (OH_NativeBuffer_FromNativeWindowBuffer(ohNativeWindowBuffer, &nativeBuffer) != 0) { + return -1; + } void *virAddr = nullptr; OH_NativeBuffer_Config config; OH_NativeBuffer_GetConfig(nativeBuffer, &config); - err = OH_NativeBuffer_Map(nativeBuffer, &virAddr); - CHECK_AND_RETURN_RET(err == 0, err, "OH_NativeBuffer_Map failed."); - + if (OH_NativeBuffer_Map(nativeBuffer, &virAddr) != 0) { + return -1; + } if (param_.inFmt == NATIVEBUFFER_PIXEL_FMT_YCBCR_P010 || param_.inFmt == NATIVEBUFFER_PIXEL_FMT_YCRCB_P010) { ReadOneFrameP010(reinterpret_cast(virAddr), config); @@ -350,11 +358,13 @@ int32_t VideoSample::InputFunc() ReadOneFrameYUV420SP(reinterpret_cast(virAddr), config); } NativeWindowHandleOpt(inWindow, SET_UI_TIMESTAMP, GetSystemTimeUs()); - err = OH_NativeBuffer_Unmap(nativeBuffer); - CHECK_AND_RETURN_RET(err == 0, err, "OH_NativeBuffer_Unmap failed."); - err = OH_NativeWindow_NativeWindowFlushBuffer(inWindow, ohNativeWindowBuffer, -1, region); + if (OH_NativeBuffer_Unmap(nativeBuffer) != 0) { + return -1; + } + if (OH_NativeWindow_NativeWindowFlushBuffer(inWindow, ohNativeWindowBuffer, -1, region) != 0) { + return -1; + } inCount++; - CHECK_AND_RETURN_RET(err == 0, err, "OH_NativeWindow_NativeWindowFlushBuffer failed."); inputFuncFinished = true; inFile->close(); return 0; @@ -392,8 +402,9 @@ void VideoSample::OutputThread() int32_t VideoSample::StartProcess() { - int32_t ret = OH_VideoProcessing_Start(videoProcessor); - CHECK_AND_RETURN_RET(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_Start failed."); + if (OH_VideoProcessing_Start(videoProcessor) != VIDEO_PROCESSING_SUCCESS) { + return -1; + } inputLoop_ = make_unique(&VideoSample::InputFunc, this); outputLoop_ = make_unique(&VideoSample::OutputThread, this); return VIDEO_PROCESSING_SUCCESS; @@ -403,8 +414,9 @@ int32_t VideoSample::WaitAndStopSample() { inputLoop_->join(); outputLoop_->join(); - int32_t ret = OH_VideoProcessing_Stop(videoProcessor); - CHECK_AND_RETURN_RET(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_Stop failed."); + if (OH_VideoProcessing_Stop(videoProcessor) != VIDEO_PROCESSING_SUCCESS) { + return -1; + } return 0; } diff --git a/test/ndk/moduletest/video/video_sample.h b/test/ndk/moduletest/video/video_sample.h index c267c03..01bf51c 100644 --- a/test/ndk/moduletest/video/video_sample.h +++ b/test/ndk/moduletest/video/video_sample.h @@ -28,14 +28,6 @@ #include "openssl/crypto.h" #include "openssl/sha.h" -#define CHECK_AND_RETURN_RET(cond, ret, msg) \ - if (1) { \ - if (!(cond)) { \ - std::cout << msg << " ErrCode:" << ret <