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 struct SQRParam { 56 std::optional<int32_t> bitrate; 57 std::optional<int32_t> maxBitrate; 58 std::optional<int32_t> sqrFactor; 59 }; 60 61 enum ParamType { 62 SET_PARAM, 63 PER_FRAME_PARAM, 64 RESOURCE_PARAM, 65 }; 66 67 struct SetParameterParams { 68 std::optional<bool> requestIdr; 69 std::optional<uint32_t> bitRate; 70 std::optional<double> frameRate; 71 std::optional<QPRange> qpRange; 72 std::optional<VideoRotation> rotate; 73 std::optional<OH_ScalingMode> scaleMode; 74 std::optional<uint32_t> targetQp; 75 std::optional<SQRParam> sqrParam; 76 std::optional<double> operatingRate; 77 }; 78 79 struct PerFrameParams { 80 std::optional<bool> requestIdr; 81 std::optional<QPRange> qpRange; 82 std::optional<LTRParam> ltrParam; 83 std::optional<bool> discard; 84 std::optional<EBRParam> ebrParam; 85 std::optional<std::string> roiParams; 86 std::optional<bool> absQpMap; 87 std::optional<int32_t> qpMapValue; 88 }; 89 90 struct ResourceParams { 91 std::string inputFile; 92 uint32_t dispW = 0; 93 uint32_t dispH = 0; 94 VideoPixelFormat pixFmt = VideoPixelFormat::NV12; 95 }; 96 97 struct WaterMarkParam { 98 bool isSet = false; 99 ResourceParams waterMarkFile; 100 int32_t dstX; 101 int32_t dstY; 102 int32_t dstW; 103 int32_t dstH; 104 }; 105 106 struct CommandOpt { 107 ApiType apiType = ApiType::TEST_CODEC_BASE; 108 bool isEncoder = false; 109 bool isBufferMode = false; 110 uint32_t ltrFrameCount = 0; 111 uint32_t repeatCnt = 1; 112 std::string inputFile; 113 uint32_t maxReadFrameCnt = 0; // 0 means read whole file 114 uint32_t dispW = 0; 115 uint32_t dispH = 0; 116 CodeType protocol = H264; 117 VideoPixelFormat pixFmt = VideoPixelFormat::NV12; 118 uint32_t frameRate = 30; 119 int32_t timeout = -1; 120 bool isHighPerfMode = false; 121 // encoder only 122 bool enableInputCb = false; 123 std::optional<uint32_t> mockFrameCnt; // when read up to maxReadFrameCnt, stop read and send input directly 124 std::optional<bool> rangeFlag; 125 std::optional<ColorPrimary> primary; 126 std::optional<TransferCharacteristic> transfer; 127 std::optional<MatrixCoefficient> matrix; 128 std::optional<int32_t> iFrameInterval; 129 std::optional<int> profile; 130 std::optional<VideoEncodeBitrateMode> rateMode; 131 std::optional<uint32_t> bitRate; // bps 132 std::optional<uint32_t> quality; 133 std::optional<QPRange> qpRange; 134 std::optional<uint32_t> ltrListLen; 135 std::optional<int32_t> repeatAfter; 136 std::optional<int32_t> repeatMaxCnt; 137 std::optional<uint32_t> layerCnt; 138 std::optional<int32_t> isVrrEnable; 139 std::optional<int32_t> sqrFactor; 140 std::optional<int32_t> maxBitrate; 141 std::optional<std::string> roiParams; 142 std::optional<uint32_t> targetQp; 143 WaterMarkParam waterMark; 144 bool paramsFeedback; 145 bool enableQPMap = false; 146 std::optional<int32_t> gopBMode; 147 148 // decoder only 149 bool decThenEnc = false; 150 VideoRotation rotation = VIDEO_ROTATION_0; 151 int flushCnt = 0; 152 std::optional<uint32_t> scaleMode; 153 154 // associate with frame number 155 std::map<uint32_t, SetParameterParams> setParameterParamsMap; 156 std::map<uint32_t, PerFrameParams> perFrameParamsMap; 157 std::map<uint32_t, ResourceParams> resourceParamsMap; 158 159 void Print() const; 160 void ParseParamFromCmdLine(ParamType paramType, const char *cmd); 161 void ParseSetParameter(uint32_t frameNo, const std::string &s); 162 void ParsePerFrameParam(uint32_t frameNo, const std::string &s); 163 static void ParseResourceParam(const std::string &src, ResourceParams& dst); 164 void ParseWaterMark(const char *cmd); 165 }; 166 167 CommandOpt Parse(int argc, char *argv[]); 168 void ShowUsage(); 169 } 170 #endif