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 * Description: header of HCode System test command parse 16 */ 17 18 #ifndef HCODEC_TEST_COMMAND_PARSE_H 19 #define HCODEC_TEST_COMMAND_PARSE_H 20 21 #include <string> 22 #include <optional> 23 #include "native_avcodec_base.h" 24 #include "av_common.h" 25 #include "avcodec_info.h" 26 #include "media_description.h" 27 #include "start_code_detector.h" 28 29 namespace OHOS::MediaAVCodec { 30 31 enum class ApiType { 32 TEST_CODEC_BASE, 33 TEST_C_API_NEW, 34 TEST_C_API_OLD, 35 }; 36 37 struct QPRange { 38 uint32_t qpMin; 39 uint32_t qpMax; 40 }; 41 42 struct LTRParam { 43 bool markAsLTR; 44 bool useLTR; 45 uint32_t useLTRPoc; 46 }; 47 48 struct EBRParam { 49 int32_t minQp; 50 int32_t maxQp; 51 int32_t startQp; 52 int32_t isSkip; 53 }; 54 55 enum ParamType { 56 SET_PARAM, 57 PER_FRAME_PARAM, 58 RESOURCE_PARAM, 59 }; 60 61 struct SetParameterParams { 62 std::optional<bool> requestIdr; 63 std::optional<uint32_t> bitRate; 64 std::optional<double> frameRate; 65 std::optional<QPRange> qpRange; 66 std::optional<VideoRotation> rotate; 67 std::optional<OH_ScalingMode> scaleMode; 68 }; 69 70 struct PerFrameParams { 71 std::optional<bool> requestIdr; 72 std::optional<QPRange> qpRange; 73 std::optional<LTRParam> ltrParam; 74 std::optional<bool> discard; 75 std::optional<EBRParam> ebrParam; 76 }; 77 78 struct ResourceParams { 79 std::string inputFile; 80 uint32_t dispW = 0; 81 uint32_t dispH = 0; 82 VideoPixelFormat pixFmt = VideoPixelFormat::NV12; 83 }; 84 85 struct WaterMarkParam { 86 bool isSet = false; 87 ResourceParams waterMarkFile; 88 int32_t dstX; 89 int32_t dstY; 90 int32_t dstW; 91 int32_t dstH; 92 }; 93 94 struct CommandOpt { 95 ApiType apiType = ApiType::TEST_CODEC_BASE; 96 bool isEncoder = false; 97 bool isBufferMode = false; 98 uint32_t ltrFrameCount = 0; 99 uint32_t repeatCnt = 1; 100 std::string inputFile; 101 uint32_t maxReadFrameCnt = 0; // 0 means read whole file 102 uint32_t dispW = 0; 103 uint32_t dispH = 0; 104 CodeType protocol = H264; 105 VideoPixelFormat pixFmt = VideoPixelFormat::NV12; 106 uint32_t frameRate = 30; 107 int32_t timeout = -1; 108 bool isHighPerfMode = false; 109 // encoder only 110 bool enableInputCb = false; 111 std::optional<uint32_t> mockFrameCnt; // when read up to maxReadFrameCnt, stop read and send input directly 112 std::optional<bool> rangeFlag; 113 std::optional<ColorPrimary> primary; 114 std::optional<TransferCharacteristic> transfer; 115 std::optional<MatrixCoefficient> matrix; 116 std::optional<int32_t> iFrameInterval; 117 std::optional<int> profile; 118 std::optional<VideoEncodeBitrateMode> rateMode; 119 std::optional<uint32_t> bitRate; // bps 120 std::optional<uint32_t> quality; 121 std::optional<QPRange> qpRange; 122 std::optional<uint32_t> ltrListLen; 123 std::optional<int32_t> repeatAfter; 124 std::optional<int32_t> repeatMaxCnt; 125 std::optional<uint32_t> layerCnt; 126 std::optional<int32_t> isVrrEnable; 127 WaterMarkParam waterMark; 128 bool paramsFeedback; 129 130 // decoder only 131 bool render = false; 132 bool decThenEnc = false; 133 VideoRotation rotation = VIDEO_ROTATION_0; 134 int flushCnt = 0; 135 std::optional<uint32_t> scaleMode; 136 137 // associate with frame number 138 std::map<uint32_t, SetParameterParams> setParameterParamsMap; 139 std::map<uint32_t, PerFrameParams> perFrameParamsMap; 140 std::map<uint32_t, ResourceParams> resourceParamsMap; 141 142 void Print() const; 143 void ParseParamFromCmdLine(ParamType paramType, const char *cmd); 144 void ParseSetParameter(uint32_t frameNo, const std::string &s); 145 void ParsePerFrameParam(uint32_t frameNo, const std::string &s); 146 static void ParseResourceParam(const std::string &src, ResourceParams& dst); 147 void ParseWaterMark(const char *cmd); 148 }; 149 150 CommandOpt Parse(int argc, char *argv[]); 151 void ShowUsage(); 152 } 153 #endif