diff --git a/framework/algorithm/metadata_generator/metadata_generator_fwk.cpp b/framework/algorithm/metadata_generator/metadata_generator_fwk.cpp index 3018ba0..f165e63 100644 --- a/framework/algorithm/metadata_generator/metadata_generator_fwk.cpp +++ b/framework/algorithm/metadata_generator/metadata_generator_fwk.cpp @@ -175,6 +175,36 @@ int32_t MetadataGeneratorProcessImage(int32_t instance, OHNativeWindowBuffer* in return ret; } +int32_t MetadataGeneratorProcessVideo(int32_t instance, OHNativeWindowBuffer* inputImage) +{ + CHECK_AND_RETURN_RET_LOG((inputImage != nullptr), VPE_ALGO_ERR_INVALID_VAL, + "invalid parameters"); + auto someInstance = Extension::ExtensionManager::GetInstance().GetInstance(instance); + CHECK_AND_RETURN_RET_LOG(someInstance != std::nullopt, VPE_ALGO_ERR_INVALID_VAL, "invalid instance"); + + VPEAlgoErrCode ret = VPE_ALGO_ERR_INVALID_VAL; + auto visitFunc = [inputImage, &ret](auto&& var) { + using VarType = std::decay_t; + if constexpr (std::is_same_v>) { + OH_NativeBuffer* inputImageNativeBuffer = nullptr; + CHECK_AND_RETURN_LOG( + (OH_NativeBuffer_FromNativeWindowBuffer(inputImage, &inputImageNativeBuffer) == GSERROR_OK), + "invalid input image"); + sptr inputImageSurfaceBuffer( + SurfaceBuffer::NativeBufferToSurfaceBuffer(inputImageNativeBuffer)); + MetadataGeneratorParameter param; + param.algoType = MetadataGeneratorAlgoType::META_GEN_ALGO_TYPE_VIDEO; + (void)var->SetParameter(param); + ret = var->Process(inputImageSurfaceBuffer); + } else { + VPE_LOGE("instance may be miss used"); + } + }; + std::visit(visitFunc, *someInstance); + + return ret; +} + int32_t MetadataGeneratorDestroy(int32_t* instance) { CHECK_AND_RETURN_RET_LOG(instance != nullptr, VPE_ALGO_ERR_INVALID_VAL, "instance is null"); diff --git a/framework/algorithm/metadata_generator_video/include/metadata_generator_video_impl.h b/framework/algorithm/metadata_generator_video/include/metadata_generator_video_impl.h index 5c61b38..02a9b58 100644 --- a/framework/algorithm/metadata_generator_video/include/metadata_generator_video_impl.h +++ b/framework/algorithm/metadata_generator_video/include/metadata_generator_video_impl.h @@ -82,7 +82,7 @@ private: std::mutex mutex_; bool getUsage_{false}; std::atomic initBuffer_{false}; - std::atomic style_{VideoMetadataGeneratorStyle::META_GEN_BRIGHT_STYLE}; + std::atomic style_{VideoMetadataGeneratorStyle::META_GEN_CONTRAST_STYLE}; // task相关 std::mutex mtxTaskDone_; diff --git a/interfaces/inner_api/algorithm_common.h b/interfaces/inner_api/algorithm_common.h index 19bcc7f..16148f0 100644 --- a/interfaces/inner_api/algorithm_common.h +++ b/interfaces/inner_api/algorithm_common.h @@ -150,7 +150,7 @@ struct MetadataGeneratorParameter { MetadataGeneratorAlgoType algoType = MetadataGeneratorAlgoType::META_GEN_ALGO_TYPE_IMAGE; bool isOldHdrVivid = false; float avgGainmapGray = 0.0; - VideoMetadataGeneratorStyle styleType = VideoMetadataGeneratorStyle::META_GEN_BRIGHT_STYLE; + VideoMetadataGeneratorStyle styleType = VideoMetadataGeneratorStyle::META_GEN_CONTRAST_STYLE; }; uint32_t GetColorSpaceType(const CM_ColorSpaceInfo &colorSpaceInfo); diff --git a/interfaces/inner_api/metadata_generator.h b/interfaces/inner_api/metadata_generator.h index 1bca172..439c413 100644 --- a/interfaces/inner_api/metadata_generator.h +++ b/interfaces/inner_api/metadata_generator.h @@ -71,6 +71,8 @@ extern "C" int32_t MetadataGeneratorCreate(int32_t* instance); extern "C" int32_t MetadataGeneratorProcessImage(int32_t instance, OHNativeWindowBuffer* inputImage); +extern "C" int32_t MetadataGeneratorProcessVideo(int32_t instance, OHNativeWindowBuffer* inputImage); + extern "C" int32_t MetadataGeneratorDestroy(int32_t* instance); } // namespace VideoProcessingEngine diff --git a/interfaces/kits/c/video_processing/libvideo_processing.ndk.json b/interfaces/kits/c/video_processing/libvideo_processing.ndk.json index 3303292..5a36558 100644 --- a/interfaces/kits/c/video_processing/libvideo_processing.ndk.json +++ b/interfaces/kits/c/video_processing/libvideo_processing.ndk.json @@ -96,7 +96,7 @@ "type": "variable" }, { - "first_introduced": "21", + "first_introduced": "22", "name": "VIDEO_METADATA_GENERATOR_STYLE_CONTROL", "type": "variable" } diff --git a/interfaces/kits/c/video_processing_types.h b/interfaces/kits/c/video_processing_types.h index 2bf286c..d7decbd 100644 --- a/interfaces/kits/c/video_processing_types.h +++ b/interfaces/kits/c/video_processing_types.h @@ -121,10 +121,7 @@ extern const char* VIDEO_DETAIL_ENHANCER_PARAMETER_KEY_QUALITY_LEVEL; * Use {@link OH_VideoProcessing_SetParameter} to set parameter into video processing instance. * Use {@link OH_VideoProcessing_GetParameter} to get the current mode. * - * @see OH_AVFormat_SetIntValue - * @see OH_VideoProcessing_SetParameter - * @see OH_VideoProcessing_GetParameter - * @since 21 + * @since 22 */ extern const char* VIDEO_METADATA_GENERATOR_STYLE_CONTROL; @@ -171,7 +168,7 @@ typedef enum VideoDetailEnhancer_QualityLevel { * @see OH_AVFormat_SetIntValue * @see OH_VideoProcessing_SetParameter * @see OH_VideoProcessing_GetParameter - * @since 21 + * @since 22 */ typedef enum VideoMetadataGeneratorStyleControl { /** Style Control into bright mode */ diff --git a/test/unittest/image_processing/image_processing_unit_test.cpp b/test/unittest/image_processing/image_processing_unit_test.cpp index 0691a03..e8d2082 100644 --- a/test/unittest/image_processing/image_processing_unit_test.cpp +++ b/test/unittest/image_processing/image_processing_unit_test.cpp @@ -20,6 +20,7 @@ #include "native_avformat.h" #include "pixelmap_native.h" #include "image_processing_factory.h" +#include "metadata_generator.h" using namespace std; using namespace testing::ext; @@ -364,6 +365,59 @@ HWTEST_F(ImageProcessingUnitTest, process_10, TestSize.Level1) EXPECT_EQ(ret, IMAGE_PROCESSING_SUCCESS); OH_ImageProcessing_DeinitializeEnvironment(); } + +HWTEST_F(ImageProcessingUnitTest, apitest_01, TestSize.Level1) +{ + int32_t instanceSrId = -1; + int32_t* tmp = &instanceSrId; + auto ret = MetadataGeneratorCreate(tmp); + EXPECT_EQ(ret, VPE_ALGO_ERR_OK); + EXPECT_NE(instanceSrId, (int32_t)(-1)); + auto input = CreateSurfaceBuffer(GRAPHIC_PIXEL_FMT_RGBA_1010102, 1920, 1080); + EXPECT_NE(input, nullptr); + OHNativeWindowBuffer* srTmp = OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer(&input); + EXPECT_NE(srTmp, nullptr); + OH_NativeBuffer* inputImageNativeBuffer = nullptr; + OH_NativeBuffer_FromNativeWindowBuffer(srTmp, &inputImageNativeBuffer); + EXPECT_NE(inputImageNativeBuffer, nullptr); + uint8_t metadataType = CM_IMAGE_HDR_VIVID_DUAL; + OH_NativeBuffer_SetMetadataValue(inputImageNativeBuffer, OH_HDR_METADATA_TYPE, sizeof(uint8_t), &metadataType); + OH_NativeBuffer_ColorSpace colorSpace = OH_COLORSPACE_BT2020_HLG_LIMIT; + OH_NativeBuffer_SetColorSpace(inputImageNativeBuffer, colorSpace); + OHNativeWindowBuffer* srIn = OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer(inputImageNativeBuffer); + EXPECT_NE(srIn, nullptr); + ret = MetadataGeneratorProcessImage(instanceSrId, srIn); + EXPECT_EQ(ret, VPE_ALGO_ERR_OK); + ret = MetadataGeneratorDestroy(tmp); + EXPECT_EQ(ret, VPE_ALGO_ERR_OK); +} + +HWTEST_F(ImageProcessingUnitTest, apitest_02, TestSize.Level1) +{ + int32_t instanceSrId = -1; + int32_t* tmp = &instanceSrId; + auto ret = MetadataGeneratorCreate(tmp); + EXPECT_EQ(ret, VPE_ALGO_ERR_OK); + EXPECT_NE(instanceSrId, (int32_t)(-1)); + auto input = CreateSurfaceBuffer(GRAPHIC_PIXEL_FMT_RGBA_1010102, 1920, 1080); + EXPECT_NE(input, nullptr); + OHNativeWindowBuffer* srTmp = OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer(&input); + EXPECT_NE(srTmp, nullptr); + OH_NativeBuffer* inputVideoNativeBuffer = nullptr; + OH_NativeBuffer_FromNativeWindowBuffer(srTmp, &inputVideoNativeBuffer); + EXPECT_NE(inputVideoNativeBuffer, nullptr); + uint8_t metadataType = OH_VIDEO_HDR_HLG; + OH_NativeBuffer_SetMetadataValue(inputVideoNativeBuffer, OH_HDR_METADATA_TYPE, sizeof(uint8_t), &metadataType); + OH_NativeBuffer_ColorSpace colorSpace = OH_COLORSPACE_BT2020_HLG_LIMIT; + OH_NativeBuffer_SetColorSpace(inputVideoNativeBuffer, colorSpace); + OHNativeWindowBuffer* srIn = OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer(inputVideoNativeBuffer); + EXPECT_NE(srIn, nullptr); + ret = MetadataGeneratorProcessVideo(instanceSrId, srIn); + EXPECT_EQ(ret, VPE_ALGO_ERR_OK); + ret = MetadataGeneratorDestroy(tmp); + EXPECT_EQ(ret, VPE_ALGO_ERR_OK); +} + } // namespace VideoProcessingEngine } // namespace Media } // namespace OHOS