1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef VPE_UTIL_DEFINE_H 16 #define VPE_UTIL_DEFINE_H 17 18 #include <string> 19 #include <cstdio> 20 #include "graphic_common_c.h" 21 #include "algorithm_common.h" 22 #include "algorithm_errors.h" 23 #include "v1_0/cm_color_space.h" 24 #include "vpe_context.h" 25 26 namespace OHOS { 27 namespace Media { 28 namespace VideoProcessingEngine { 29 struct ParameterBase { 30 int modelType; 31 int width; 32 int height; 33 int widthGainmap; 34 int heightGainmap; 35 int metadatInPut; 36 CM_HDR_Metadata_Type inMetaType; // CM_METADATA_NONE, CM_VIDEO_HLG, CM_VIDEO_HDR10, CM_VIDEO_HDR_VIVID 37 CM_ColorSpaceInfo inColspcInfo; 38 GraphicPixelFormat inPixFmt; // nv12 10bit 39 CM_HDR_Metadata_Type outMetaType; 40 CM_ColorSpaceInfo outColspcInfo; 41 GraphicPixelFormat outPixFmt; 42 CM_HDR_Metadata_Type gainmapMetaType; 43 CM_ColorSpaceInfo gainmapColspcInfo; 44 GraphicPixelFormat gainmapPixFmt; 45 std::string yuvFilePath; 46 std::string metadataFilePath; 47 VPEContext context; 48 }; 49 50 void ReadFileYuv42016(std::string yuvFilePath, sptr<SurfaceBuffer> &buffer, int width, int height); 51 void ReadFileYuv42010ToNv1216(std::string yuvFilePath, sptr<SurfaceBuffer> &buffer, int width, int height); 52 void ReadInputFile(std::string yuvFilePath, sptr<SurfaceBuffer> &buffer, int frameSize); 53 54 void SaveMetadataFromSurBuffer(const sptr<SurfaceBuffer> &input, int frame, const std::string &metadataBin); 55 void WriteOutFile(int frame, const std::string &outYuvFileName, const sptr<SurfaceBuffer> &output, int frameSize); 56 std::string GetPixFmtString(GraphicPixelFormat pixfmt); 57 std::string GetMetadataString(CM_HDR_Metadata_Type metaType); 58 std::string GetColspcString(CM_ColorSpaceInfo colorSpaceInfo); 59 std::string GetOutFileName(const std::string &baseName, const ParameterBase ¶m); 60 void SetMeatadata(sptr<SurfaceBuffer> &buffer, uint32_t value); 61 void SetMeatadata(sptr<SurfaceBuffer> &buffer, const CM_ColorSpaceInfo &colorspaceInfo); 62 void SetMeatadata(sptr<SurfaceBuffer> &buffer, int key, const float &data); 63 void SetMeatadata(sptr<SurfaceBuffer> &buffer, int key, const int &data); 64 void SetMeatadata(sptr<SurfaceBuffer> &buffer, std::unique_ptr<std::ifstream> &metadataFile); 65 sptr<SurfaceBuffer> CreateSurfaceBuffer(uint32_t pixelFormat, int32_t width, int32_t height); 66 } // namespace VideoProcessingEngine 67 } // namespace Media 68 } // namespace OHOS 69 #endif // VPE_UTIL_DEFINE_H