1 /* 2 * Copyright (C) 2021 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 16 #ifndef RECORDER_PARAM_H 17 #define RECORDER_PARAM_H 18 19 #include <cstdint> 20 #include <string> 21 #include "recorder.h" 22 23 namespace OHOS { 24 namespace Media { 25 /* 26 * Declare the type enum value valid range for different kind of RecorderParam. 27 * The "Public" means externally visible. 28 * The "Private" means internally visible. 29 */ 30 enum RecorderParamSectionStart { 31 PUBLIC_PARAM_SECTION_START = 0, 32 PRIVATE_PARAM_SECTION_START = 0x10000, 33 }; 34 35 enum RecorderPublicParamType : uint32_t { 36 PUBLIC_PARAM_TYPE_BEGIN = PUBLIC_PARAM_SECTION_START, 37 // video begin 38 VID_PUBLIC_PARAM_BEGIN, 39 VID_ENC_FMT, 40 VID_RECTANGLE, 41 VID_BITRATE, 42 VID_FRAMERATE, 43 VID_IS_HDR, 44 VID_CAPTURERATE, 45 VID_ENABLE_TEMPORAL_SCALE, 46 VID_ENABLE_STABLE_QUALITY_MODE, 47 VID_ENABLE_B_FRAME, 48 VID_PUBLIC_PARAM_END, 49 VID_ORIENTATION_HINT, 50 // audio begin 51 AUD_PUBLIC_PARAM_BEGIN, 52 AUD_ENC_FMT, 53 AUD_SAMPLERATE, 54 AUD_CHANNEL, 55 AUD_BITRATE, 56 AUD_PUBIC_PARAM_END, 57 // meta data 58 META_PARAM_BEGIN, 59 META_MIME_TYPE, 60 META_TIMED_KEY, 61 META_SOURCE_TRACK_MIME, 62 META_PARAM_END, 63 // output begin, 64 MAX_DURATION, 65 MAX_SIZE, 66 OUT_PATH, 67 OUT_FD, 68 NEXT_OUT_FD, // reserved. 69 GEO_LOCATION, 70 CUSTOM_INFO, 71 GENRE_INFO, 72 73 PUBLIC_PARAM_TYPE_END, 74 }; 75 76 /* 77 * Recorder parameter base structure, inherite to it to extend the new parameter. 78 */ 79 struct RecorderParam { RecorderParamRecorderParam80 explicit RecorderParam(uint32_t t) : type(t) {} 81 RecorderParam() = delete; 82 virtual ~RecorderParam() = default; IsVideoParamRecorderParam83 bool IsVideoParam() const 84 { 85 return (type > VID_PUBLIC_PARAM_BEGIN) && (type < VID_PUBLIC_PARAM_END); 86 } 87 IsMetaParamRecorderParam88 bool IsMetaParam() const 89 { 90 return (type >= META_PARAM_BEGIN) && (type < META_PARAM_END); 91 } 92 IsAudioParamRecorderParam93 bool IsAudioParam() const 94 { 95 return (type > AUD_PUBLIC_PARAM_BEGIN) && (type < AUD_PUBIC_PARAM_END); 96 } 97 98 uint32_t type; 99 }; 100 101 struct VidEnc : public RecorderParam { VidEncVidEnc102 explicit VidEnc(VideoCodecFormat fmt) : RecorderParam(RecorderPublicParamType::VID_ENC_FMT), encFmt(fmt) {} 103 VideoCodecFormat encFmt; 104 }; 105 106 struct VidRectangle : public RecorderParam { VidRectangleVidRectangle107 VidRectangle(int32_t w, int32_t h) : RecorderParam(RecorderPublicParamType::VID_RECTANGLE), width(w), height(h) {} 108 int32_t width; 109 int32_t height; 110 }; 111 112 struct VidBitRate : public RecorderParam { VidBitRateVidBitRate113 explicit VidBitRate(int32_t br) : RecorderParam(RecorderPublicParamType::VID_BITRATE), bitRate(br) {} 114 int32_t bitRate; 115 }; 116 117 struct VidFrameRate : public RecorderParam { VidFrameRateVidFrameRate118 explicit VidFrameRate(int32_t r) : RecorderParam(RecorderPublicParamType::VID_FRAMERATE), frameRate(r) {} 119 int32_t frameRate; 120 }; 121 122 struct VidIsHdr : public RecorderParam { VidIsHdrVidIsHdr123 explicit VidIsHdr(bool r) : RecorderParam(RecorderPublicParamType::VID_IS_HDR), isHdr(r) {} 124 bool isHdr; 125 }; 126 127 struct VidEnableTemporalScale : public RecorderParam { VidEnableTemporalScaleVidEnableTemporalScale128 explicit VidEnableTemporalScale(bool r) 129 : RecorderParam(RecorderPublicParamType::VID_ENABLE_TEMPORAL_SCALE), enableTemporalScale(r) {} 130 bool enableTemporalScale; 131 }; 132 133 struct VidEnableStableQualityMode : public RecorderParam { VidEnableStableQualityModeVidEnableStableQualityMode134 explicit VidEnableStableQualityMode(bool r) 135 : RecorderParam(RecorderPublicParamType::VID_ENABLE_STABLE_QUALITY_MODE), enableStableQualityMode(r) {} 136 bool enableStableQualityMode; 137 }; 138 139 struct VidEnableBFrame : public RecorderParam { VidEnableBFrameVidEnableBFrame140 explicit VidEnableBFrame(bool r) 141 : RecorderParam(RecorderPublicParamType::VID_ENABLE_B_FRAME), enableBFrame(r) {} 142 bool enableBFrame; 143 }; 144 145 struct CaptureRate : public RecorderParam { CaptureRateCaptureRate146 explicit CaptureRate(double cr) : RecorderParam(RecorderPublicParamType::VID_CAPTURERATE), capRate(cr) {} 147 double capRate; 148 }; 149 150 struct AudEnc : public RecorderParam { AudEncAudEnc151 explicit AudEnc(AudioCodecFormat fmt) : RecorderParam(RecorderPublicParamType::AUD_ENC_FMT), encFmt(fmt) {} 152 AudioCodecFormat encFmt; 153 }; 154 155 struct AudSampleRate : public RecorderParam { AudSampleRateAudSampleRate156 explicit AudSampleRate(int32_t sr) : RecorderParam(RecorderPublicParamType::AUD_SAMPLERATE), sampleRate(sr) {} 157 int32_t sampleRate; 158 }; 159 160 struct AudChannel : public RecorderParam { AudChannelAudChannel161 explicit AudChannel(int32_t num) : RecorderParam(RecorderPublicParamType::AUD_CHANNEL), channel(num) {} 162 int32_t channel; 163 }; 164 165 struct AudBitRate : public RecorderParam { AudBitRateAudBitRate166 explicit AudBitRate(int32_t br) : RecorderParam(RecorderPublicParamType::AUD_BITRATE), bitRate(br) {} 167 int32_t bitRate; 168 }; 169 170 struct MaxDuration : public RecorderParam { MaxDurationMaxDuration171 explicit MaxDuration(int32_t maxDur) : RecorderParam(RecorderPublicParamType::MAX_DURATION), duration(maxDur) {} 172 int32_t duration; 173 }; 174 175 struct MaxFileSize : public RecorderParam { MaxFileSizeMaxFileSize176 explicit MaxFileSize(int64_t maxSize) : RecorderParam(RecorderPublicParamType::MAX_SIZE), size(maxSize) {} 177 int64_t size; 178 }; 179 180 struct GeoLocation : public RecorderParam { GeoLocationGeoLocation181 explicit GeoLocation(float lat, float lng) 182 : RecorderParam(RecorderPublicParamType::GEO_LOCATION), latitude(lat), longitude(lng) {} 183 float latitude; 184 float longitude; 185 }; 186 187 struct RotationAngle : public RecorderParam { RotationAngleRotationAngle188 explicit RotationAngle(int32_t angle) 189 : RecorderParam(RecorderPublicParamType::VID_ORIENTATION_HINT), rotation(angle) {} 190 int32_t rotation; 191 }; 192 193 struct OutFilePath : public RecorderParam { OutFilePathOutFilePath194 explicit OutFilePath(const std::string &filePath) 195 : RecorderParam(RecorderPublicParamType::OUT_PATH), path(filePath) {} 196 std::string path; 197 }; 198 199 struct OutFd : public RecorderParam { OutFdOutFd200 explicit OutFd(int32_t outFd) : RecorderParam(RecorderPublicParamType::OUT_FD), fd(outFd) {} 201 int32_t fd; 202 }; 203 204 struct NextOutFd : public RecorderParam { NextOutFdNextOutFd205 explicit NextOutFd(int32_t nextOutFd) : RecorderParam(RecorderPublicParamType::NEXT_OUT_FD), fd(nextOutFd) {} 206 int32_t fd; 207 }; 208 209 struct CustomInfo : public RecorderParam { CustomInfoCustomInfo210 explicit CustomInfo(Meta CustomInfo) : RecorderParam(RecorderPublicParamType::CUSTOM_INFO), 211 userCustomInfo(CustomInfo) {} 212 Meta userCustomInfo; 213 }; 214 215 struct GenreInfo : public RecorderParam { GenreInfoGenreInfo216 explicit GenreInfo(std::string genreInfo) : RecorderParam(RecorderPublicParamType::GENRE_INFO), 217 genre(genreInfo) {} 218 std::string genre; 219 }; 220 221 struct MetaMimeType : public RecorderParam { MetaMimeTypeMetaMimeType222 explicit MetaMimeType(const std::string_view &type) : RecorderParam(RecorderPublicParamType::META_MIME_TYPE), 223 mimeType(type) {} 224 std::string mimeType; 225 }; 226 227 struct MetaTimedKey : public RecorderParam { MetaTimedKeyMetaTimedKey228 explicit MetaTimedKey(const std::string_view &key) : RecorderParam(RecorderPublicParamType::META_TIMED_KEY), 229 timedKey(key) {} 230 std::string timedKey; 231 }; 232 233 struct MetaSourceTrackMime : public RecorderParam { MetaSourceTrackMimeMetaSourceTrackMime234 explicit MetaSourceTrackMime(std::string_view type) 235 : RecorderParam(RecorderPublicParamType::META_SOURCE_TRACK_MIME), sourceMime(type) {} 236 std::string sourceMime; 237 }; 238 } // namespace Media 239 } // namespace OHOS 240 #endif 241