From 3f1e140dfc9600ad0ab2b38f8176818c18ded202 Mon Sep 17 00:00:00 2001 From: mediaTest Date: Tue, 27 May 2025 09:42:52 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: mediaTest --- test/BUILD.gn | 6 ++++++ test/ndk/BUILD.gn | 13 +++++-------- test/ndk/moduletest/common/enum_list.h | 4 ++-- test/ndk/moduletest/video/func_test.cpp | 1 - test/ndk/moduletest/video/video_sample.cpp | 6 +++--- test/ndk/moduletest/video/video_sample.h | 12 ++++++------ 6 files changed, 22 insertions(+), 20 deletions(-) diff --git a/test/BUILD.gn b/test/BUILD.gn index 074b429..829c518 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -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..7716444 100644 --- a/test/ndk/BUILD.gn +++ b/test/ndk/BUILD.gn @@ -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/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..87427a2 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(); diff --git a/test/ndk/moduletest/video/video_sample.h b/test/ndk/moduletest/video/video_sample.h index c267c03..c7faae8 100644 --- a/test/ndk/moduletest/video/video_sample.h +++ b/test/ndk/moduletest/video/video_sample.h @@ -28,12 +28,12 @@ #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 < Date: Tue, 27 May 2025 10:17:01 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=89=88=E6=9D=83?= =?UTF-8?q?=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: mediaTest --- test/ndk/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ndk/BUILD.gn b/test/ndk/BUILD.gn index 7716444..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 -- Gitee From 51f6ae339bbb9e1e9f5df241cbc160ab9105f20e Mon Sep 17 00:00:00 2001 From: mediaTest Date: Tue, 10 Jun 2025 15:39:21 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: mediaTest --- test/ndk/moduletest/video/video_sample.cpp | 56 ++++++++++++++++------ test/ndk/moduletest/video/video_sample.h | 15 +++--- 2 files changed, 50 insertions(+), 21 deletions(-) diff --git a/test/ndk/moduletest/video/video_sample.cpp b/test/ndk/moduletest/video/video_sample.cpp index 87427a2..90fb1d2 100644 --- a/test/ndk/moduletest/video/video_sample.cpp +++ b/test/ndk/moduletest/video/video_sample.cpp @@ -219,7 +219,9 @@ int32_t VideoSample::InitVideoSample(const int32_t type, int32_t width, int32_t if (type == VIDEO_PROCESSING_TYPE_METADATA_GENERATION) { isMetadataGen = true; } - CHECK_AND_RETURN_RET(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_Create failed"); + if (check_return(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_Create failed")) { + return ret; + } cs = Surface::CreateSurfaceAsConsumer(); sptr listener = new VPEConsumerListener(cs, this); cs->RegisterConsumerListener(listener); @@ -243,17 +245,25 @@ int32_t VideoSample::InitVideoSample(const int32_t type, int32_t width, int32_t 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."); + if (check_return(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_SetSurface failed.")) { + return ret; + } ret = OH_VideoProcessing_GetSurface(videoProcessor, &inWindow); - CHECK_AND_RETURN_RET(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_GetSurface failed."); + if (check_return(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_GetSurface failed.")) { + return ret; + } SetInputWindowParam(); ret = OH_VideoProcessingCallback_Create(&callback); - CHECK_AND_RETURN_RET(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessingCallback_Create failed."); + if (check_return(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessingCallback_Create failed.")) { + return ret; + } 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 (check_return(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_RegisterCallback failed.")) { + return ret; + } return VIDEO_PROCESSING_SUCCESS; } @@ -318,26 +328,36 @@ 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 (check_return(inFile->is_open(), -1, "open input file failed")) { + return ret; + } 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 (check_return(ret == 0, ret, "set metadata value failed")) { + return ret; + } } int32_t err = OH_NativeWindow_NativeWindowRequestBuffer(inWindow, &ohNativeWindowBuffer, &fenceFd); - CHECK_AND_RETURN_RET(err == 0, err, "OH_NativeWindow_NativeWindowRequestBuffer failed"); + if (check_return(err == 0, err, "OH_NativeWindow_NativeWindowRequestBuffer failed")) { + return ret; + } 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 (check_return(err == 0, err, "OH_NativeBuffer_FromNativeWindowBuffer failed.")) { + return ret; + } 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 (check_return(err == 0, err, "OH_NativeBuffer_Map failed.")) { + return ret; + } if (param_.inFmt == NATIVEBUFFER_PIXEL_FMT_YCBCR_P010 || param_.inFmt == NATIVEBUFFER_PIXEL_FMT_YCRCB_P010) { @@ -351,10 +371,14 @@ int32_t VideoSample::InputFunc() } NativeWindowHandleOpt(inWindow, SET_UI_TIMESTAMP, GetSystemTimeUs()); err = OH_NativeBuffer_Unmap(nativeBuffer); - CHECK_AND_RETURN_RET(err == 0, err, "OH_NativeBuffer_Unmap failed."); + if (check_return(err == 0, err, "OH_NativeBuffer_Unmap failed.")) { + return ret; + } err = OH_NativeWindow_NativeWindowFlushBuffer(inWindow, ohNativeWindowBuffer, -1, region); inCount++; - CHECK_AND_RETURN_RET(err == 0, err, "OH_NativeWindow_NativeWindowFlushBuffer failed."); + if (check_return(err == 0, err, "OH_NativeWindow_NativeWindowFlushBuffer failed.")) { + return ret; + } inputFuncFinished = true; inFile->close(); return 0; @@ -393,7 +417,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 (check_return(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_Start failed.")) { + return ret; + } inputLoop_ = make_unique(&VideoSample::InputFunc, this); outputLoop_ = make_unique(&VideoSample::OutputThread, this); return VIDEO_PROCESSING_SUCCESS; @@ -404,7 +430,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 (check_return(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_Stop failed.")) { + return ret; + } return 0; } diff --git a/test/ndk/moduletest/video/video_sample.h b/test/ndk/moduletest/video/video_sample.h index c7faae8..3e90ec7 100644 --- a/test/ndk/moduletest/video/video_sample.h +++ b/test/ndk/moduletest/video/video_sample.h @@ -28,13 +28,14 @@ #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 < Date: Tue, 10 Jun 2025 15:58:41 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: mediaTest --- test/ndk/moduletest/video/video_sample.cpp | 40 +++++++--------------- test/ndk/moduletest/video/video_sample.h | 4 +-- 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/test/ndk/moduletest/video/video_sample.cpp b/test/ndk/moduletest/video/video_sample.cpp index 90fb1d2..5f3bdb8 100644 --- a/test/ndk/moduletest/video/video_sample.cpp +++ b/test/ndk/moduletest/video/video_sample.cpp @@ -216,12 +216,10 @@ int32_t VideoSample::InitVideoSample(const int32_t type, int32_t width, int32_t isRunning = true; param_ = param; int32_t ret = OH_VideoProcessing_Create(&videoProcessor, type); - if (type == VIDEO_PROCESSING_TYPE_METADATA_GENERATION) { + if (type == VIDEO_PROCESSING_TYPE_METADATA_GENERATION) isMetadataGen = true; - } - if (check_return(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_Create failed")) { + if (check_return(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_Create failed")) return ret; - } cs = Surface::CreateSurfaceAsConsumer(); sptr listener = new VPEConsumerListener(cs, this); cs->RegisterConsumerListener(listener); @@ -245,25 +243,21 @@ int32_t VideoSample::InitVideoSample(const int32_t type, int32_t width, int32_t OH_NativeWindow_SetMetadataValue(outWindow, OH_HDR_METADATA_TYPE, sizeof(uint8_t), &outMeta); } ret = OH_VideoProcessing_SetSurface(videoProcessor, outWindow); - if (check_return(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_SetSurface failed.")) { + if (check_return(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_SetSurface failed.")) return ret; - } ret = OH_VideoProcessing_GetSurface(videoProcessor, &inWindow); - if (check_return(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_GetSurface failed.")) { + if (check_return(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_GetSurface failed.")) return ret; - } SetInputWindowParam(); ret = OH_VideoProcessingCallback_Create(&callback); - if (check_return(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessingCallback_Create failed.")) { + if (check_return(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessingCallback_Create failed.")) return ret; - } OH_VideoProcessingCallback_BindOnError(callback, OnError); OH_VideoProcessingCallback_BindOnState(callback, OnState); OH_VideoProcessingCallback_BindOnNewOutputBuffer(callback, OnNewOutputBuffer); ret = OH_VideoProcessing_RegisterCallback(videoProcessor, callback, this); - if (check_return(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_RegisterCallback failed.")) { + if (check_return(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_RegisterCallback failed.")) return ret; - } return VIDEO_PROCESSING_SUCCESS; } @@ -328,37 +322,31 @@ void VideoSample::GetMetadata(OH_NativeBuffer *buffer) int32_t VideoSample::InputFunc() { inFile = std::make_unique(inputFilePath); - if (check_return(inFile->is_open(), -1, "open input file failed")) { + if (check_return(inFile->is_open(), -1, "open input file failed")) return ret; - } int fenceFd = -1; OHNativeWindowBuffer *ohNativeWindowBuffer; if (isHDRVivid) { int32_t ret = OH_NativeWindow_SetMetadataValue(inWindow, OH_HDR_DYNAMIC_METADATA, metadataSize, metaData); - if (check_return(ret == 0, ret, "set metadata value failed")) { + if (check_return(ret == 0, ret, "set metadata value failed")) return ret; - } } int32_t err = OH_NativeWindow_NativeWindowRequestBuffer(inWindow, &ohNativeWindowBuffer, &fenceFd); - if (check_return(err == 0, err, "OH_NativeWindow_NativeWindowRequestBuffer failed")) { + if (check_return(err == 0, err, "OH_NativeWindow_NativeWindowRequestBuffer failed")) return ret; - } if (fenceFd > 0) { close(fenceFd); } OH_NativeBuffer *nativeBuffer = nullptr; err = OH_NativeBuffer_FromNativeWindowBuffer(ohNativeWindowBuffer, &nativeBuffer); - if (check_return(err == 0, err, "OH_NativeBuffer_FromNativeWindowBuffer failed.")) { + if (check_return(err == 0, err, "OH_NativeBuffer_FromNativeWindowBuffer failed.")) return ret; - } void *virAddr = nullptr; OH_NativeBuffer_Config config; OH_NativeBuffer_GetConfig(nativeBuffer, &config); err = OH_NativeBuffer_Map(nativeBuffer, &virAddr); - if (check_return(err == 0, err, "OH_NativeBuffer_Map failed.")) { + if (check_return(err == 0, err, "OH_NativeBuffer_Map failed.")) return ret; - } - if (param_.inFmt == NATIVEBUFFER_PIXEL_FMT_YCBCR_P010 || param_.inFmt == NATIVEBUFFER_PIXEL_FMT_YCRCB_P010) { ReadOneFrameP010(reinterpret_cast(virAddr), config); @@ -371,14 +359,12 @@ int32_t VideoSample::InputFunc() } NativeWindowHandleOpt(inWindow, SET_UI_TIMESTAMP, GetSystemTimeUs()); err = OH_NativeBuffer_Unmap(nativeBuffer); - if (check_return(err == 0, err, "OH_NativeBuffer_Unmap failed.")) { + if (check_return(err == 0, err, "OH_NativeBuffer_Unmap failed.")) return ret; - } err = OH_NativeWindow_NativeWindowFlushBuffer(inWindow, ohNativeWindowBuffer, -1, region); inCount++; - if (check_return(err == 0, err, "OH_NativeWindow_NativeWindowFlushBuffer failed.")) { + if (check_return(err == 0, err, "OH_NativeWindow_NativeWindowFlushBuffer failed.")) return ret; - } inputFuncFinished = true; inFile->close(); return 0; diff --git a/test/ndk/moduletest/video/video_sample.h b/test/ndk/moduletest/video/video_sample.h index 3e90ec7..4e134b4 100644 --- a/test/ndk/moduletest/video/video_sample.h +++ b/test/ndk/moduletest/video/video_sample.h @@ -28,10 +28,10 @@ #include "openssl/crypto.h" #include "openssl/sha.h" -int32_t check_return(bool cond, uint32_t ret, const char *msg) +int32_t CheckReturn(bool cond, uint32_t ret, const char *msg) { if (!cond) { - std::cout << msg << " ErrCode:" << ret < Date: Wed, 11 Jun 2025 17:13:05 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: mediaTest --- test/ndk/moduletest/video/video_sample.cpp | 85 +++++++++++----------- test/ndk/moduletest/video/video_sample.h | 9 --- 2 files changed, 42 insertions(+), 52 deletions(-) diff --git a/test/ndk/moduletest/video/video_sample.cpp b/test/ndk/moduletest/video/video_sample.cpp index 5f3bdb8..ef9dc01 100644 --- a/test/ndk/moduletest/video/video_sample.cpp +++ b/test/ndk/moduletest/video/video_sample.cpp @@ -215,11 +215,11 @@ 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; - if (check_return(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_Create failed")) - return ret; + 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 +229,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,22 +242,22 @@ 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); - if (check_return(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_SetSurface failed.")) - return ret; - ret = OH_VideoProcessing_GetSurface(videoProcessor, &inWindow); - if (check_return(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_GetSurface failed.")) - return ret; + 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); - if (check_return(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessingCallback_Create failed.")) - return ret; + if (OH_VideoProcessingCallback_Create(&callback) != VIDEO_PROCESSING_SUCCESS) { + return -1; + } OH_VideoProcessingCallback_BindOnError(callback, OnError); OH_VideoProcessingCallback_BindOnState(callback, OnState); OH_VideoProcessingCallback_BindOnNewOutputBuffer(callback, OnNewOutputBuffer); - ret = OH_VideoProcessing_RegisterCallback(videoProcessor, callback, this); - if (check_return(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_RegisterCallback failed.")) - return ret; + if (OH_VideoProcessing_RegisterCallback(videoProcessor, callback, this) != VIDEO_PROCESSING_SUCCESS){ + return -1; + } return VIDEO_PROCESSING_SUCCESS; } @@ -322,31 +322,32 @@ void VideoSample::GetMetadata(OH_NativeBuffer *buffer) int32_t VideoSample::InputFunc() { inFile = std::make_unique(inputFilePath); - if (check_return(inFile->is_open(), -1, "open input file failed")) - return ret; + 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); - if (check_return(ret == 0, ret, "set metadata value failed")) - return ret; + 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); - if (check_return(err == 0, err, "OH_NativeWindow_NativeWindowRequestBuffer failed")) - return ret; if (fenceFd > 0) { close(fenceFd); } OH_NativeBuffer *nativeBuffer = nullptr; - err = OH_NativeBuffer_FromNativeWindowBuffer(ohNativeWindowBuffer, &nativeBuffer); - if (check_return(err == 0, err, "OH_NativeBuffer_FromNativeWindowBuffer failed.")) - return ret; + 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); - if (check_return(err == 0, err, "OH_NativeBuffer_Map failed.")) - return ret; + 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); @@ -358,13 +359,13 @@ int32_t VideoSample::InputFunc() ReadOneFrameYUV420SP(reinterpret_cast(virAddr), config); } NativeWindowHandleOpt(inWindow, SET_UI_TIMESTAMP, GetSystemTimeUs()); - err = OH_NativeBuffer_Unmap(nativeBuffer); - if (check_return(err == 0, err, "OH_NativeBuffer_Unmap failed.")) - return ret; - 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++; - if (check_return(err == 0, err, "OH_NativeWindow_NativeWindowFlushBuffer failed.")) - return ret; inputFuncFinished = true; inFile->close(); return 0; @@ -402,9 +403,8 @@ void VideoSample::OutputThread() int32_t VideoSample::StartProcess() { - int32_t ret = OH_VideoProcessing_Start(videoProcessor); - if (check_return(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_Start failed.")) { - return ret; + if (OH_VideoProcessing_Start(videoProcessor) != VIDEO_PROCESSING_SUCCESS) { + return -1; } inputLoop_ = make_unique(&VideoSample::InputFunc, this); outputLoop_ = make_unique(&VideoSample::OutputThread, this); @@ -415,9 +415,8 @@ int32_t VideoSample::WaitAndStopSample() { inputLoop_->join(); outputLoop_->join(); - int32_t ret = OH_VideoProcessing_Stop(videoProcessor); - if (check_return(ret == VIDEO_PROCESSING_SUCCESS, ret, "OH_VideoProcessing_Stop failed.")) { - return ret; + 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 4e134b4..01bf51c 100644 --- a/test/ndk/moduletest/video/video_sample.h +++ b/test/ndk/moduletest/video/video_sample.h @@ -28,15 +28,6 @@ #include "openssl/crypto.h" #include "openssl/sha.h" -int32_t CheckReturn(bool cond, uint32_t ret, const char *msg) -{ - if (!cond) { - std::cout << msg << " ErrCode:" << ret << std:: endl; - return ret; - } - return 0; -} - typedef struct VideoProcessParam { OH_NativeBuffer_Format inFmt; OH_NativeBuffer_ColorSpace inColorSpace; -- Gitee From ba2d2145d421feb169f81fbf02f83f8daaf25160 Mon Sep 17 00:00:00 2001 From: mediaTest Date: Thu, 12 Jun 2025 08:56:44 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: mediaTest --- test/ndk/moduletest/video/video_sample.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/ndk/moduletest/video/video_sample.cpp b/test/ndk/moduletest/video/video_sample.cpp index ef9dc01..66b5068 100644 --- a/test/ndk/moduletest/video/video_sample.cpp +++ b/test/ndk/moduletest/video/video_sample.cpp @@ -215,8 +215,9 @@ int32_t VideoSample::InitVideoSample(const int32_t type, int32_t width, int32_t height_ = height; isRunning = true; param_ = param; - if (type == VIDEO_PROCESSING_TYPE_METADATA_GENERATION) + if (type == VIDEO_PROCESSING_TYPE_METADATA_GENERATION) { isMetadataGen = true; + } if (OH_VideoProcessing_Create(&videoProcessor, type) != VIDEO_PROCESSING_SUCCESS) { return -1; } @@ -255,7 +256,7 @@ int32_t VideoSample::InitVideoSample(const int32_t type, int32_t width, int32_t OH_VideoProcessingCallback_BindOnError(callback, OnError); OH_VideoProcessingCallback_BindOnState(callback, OnState); OH_VideoProcessingCallback_BindOnNewOutputBuffer(callback, OnNewOutputBuffer); - if (OH_VideoProcessing_RegisterCallback(videoProcessor, callback, this) != VIDEO_PROCESSING_SUCCESS){ + if (OH_VideoProcessing_RegisterCallback(videoProcessor, callback, this) != VIDEO_PROCESSING_SUCCESS) { return -1; } return VIDEO_PROCESSING_SUCCESS; -- Gitee From 519e23022555c48aa242a67d311304a9c06aa87f Mon Sep 17 00:00:00 2001 From: mediaTest Date: Thu, 12 Jun 2025 09:24:33 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: mediaTest --- test/ndk/moduletest/video/video_sample.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/ndk/moduletest/video/video_sample.cpp b/test/ndk/moduletest/video/video_sample.cpp index 66b5068..0eb3091 100644 --- a/test/ndk/moduletest/video/video_sample.cpp +++ b/test/ndk/moduletest/video/video_sample.cpp @@ -250,9 +250,7 @@ int32_t VideoSample::InitVideoSample(const int32_t type, int32_t width, int32_t return -1; } SetInputWindowParam(); - if (OH_VideoProcessingCallback_Create(&callback) != VIDEO_PROCESSING_SUCCESS) { - return -1; - } + OH_VideoProcessingCallback_Create(&callback); OH_VideoProcessingCallback_BindOnError(callback, OnError); OH_VideoProcessingCallback_BindOnState(callback, OnState); OH_VideoProcessingCallback_BindOnNewOutputBuffer(callback, OnNewOutputBuffer); -- Gitee From 5caedb58e41279fd499dfcd48c89f94bd9b8a207 Mon Sep 17 00:00:00 2001 From: mediaTest Date: Thu, 12 Jun 2025 10:12:53 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: mediaTest --- test/ndk/moduletest/video/BUILD.gn | 1 + 1 file changed, 1 insertion(+) 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" } -- Gitee