• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_PUBLIC_PARAM_END,
48     VID_ORIENTATION_HINT,
49     // audio begin
50     AUD_PUBLIC_PARAM_BEGIN,
51     AUD_ENC_FMT,
52     AUD_SAMPLERATE,
53     AUD_CHANNEL,
54     AUD_BITRATE,
55     AUD_PUBIC_PARAM_END,
56     // meta data
57     META_PARAM_BEGIN,
58     META_MIME_TYPE,
59     META_TIMED_KEY,
60     META_SOURCE_TRACK_MIME,
61     META_PARAM_END,
62     // output begin,
63     MAX_DURATION,
64     MAX_SIZE,
65     OUT_PATH,
66     OUT_FD,
67     NEXT_OUT_FD, // reserved.
68     GEO_LOCATION,
69     CUSTOM_INFO,
70     GENRE_INFO,
71 
72     PUBLIC_PARAM_TYPE_END,
73 };
74 
75 /*
76  * Recorder parameter base structure, inherite to it to extend the new parameter.
77  */
78 struct RecorderParam {
RecorderParamRecorderParam79     explicit RecorderParam(uint32_t t) : type(t) {}
80     RecorderParam() = delete;
81     virtual ~RecorderParam() = default;
IsVideoParamRecorderParam82     bool IsVideoParam() const
83     {
84         return (type > VID_PUBLIC_PARAM_BEGIN) && (type < VID_PUBLIC_PARAM_END);
85     }
86 
IsMetaParamRecorderParam87     bool IsMetaParam() const
88     {
89         return (type >= META_PARAM_BEGIN) && (type < META_PARAM_END);
90     }
91 
IsAudioParamRecorderParam92     bool IsAudioParam() const
93     {
94         return (type > AUD_PUBLIC_PARAM_BEGIN) && (type < AUD_PUBIC_PARAM_END);
95     }
96 
97     uint32_t type;
98 };
99 
100 struct VidEnc : public RecorderParam {
VidEncVidEnc101     explicit VidEnc(VideoCodecFormat fmt) : RecorderParam(RecorderPublicParamType::VID_ENC_FMT), encFmt(fmt) {}
102     VideoCodecFormat encFmt;
103 };
104 
105 struct VidRectangle : public RecorderParam {
VidRectangleVidRectangle106     VidRectangle(int32_t w, int32_t h) : RecorderParam(RecorderPublicParamType::VID_RECTANGLE), width(w), height(h) {}
107     int32_t width;
108     int32_t height;
109 };
110 
111 struct VidBitRate : public RecorderParam {
VidBitRateVidBitRate112     explicit VidBitRate(int32_t br) : RecorderParam(RecorderPublicParamType::VID_BITRATE), bitRate(br) {}
113     int32_t bitRate;
114 };
115 
116 struct VidFrameRate : public RecorderParam {
VidFrameRateVidFrameRate117     explicit VidFrameRate(int32_t r) : RecorderParam(RecorderPublicParamType::VID_FRAMERATE), frameRate(r) {}
118     int32_t frameRate;
119 };
120 
121 struct VidIsHdr : public RecorderParam {
VidIsHdrVidIsHdr122     explicit VidIsHdr(bool r) : RecorderParam(RecorderPublicParamType::VID_IS_HDR), isHdr(r) {}
123     bool isHdr;
124 };
125 
126 struct VidEnableTemporalScale : public RecorderParam {
VidEnableTemporalScaleVidEnableTemporalScale127     explicit VidEnableTemporalScale(bool r)
128         : RecorderParam(RecorderPublicParamType::VID_ENABLE_TEMPORAL_SCALE), enableTemporalScale(r) {}
129     bool enableTemporalScale;
130 };
131 
132 struct VidEnableStableQualityMode : public RecorderParam {
VidEnableStableQualityModeVidEnableStableQualityMode133     explicit VidEnableStableQualityMode(bool r)
134         : RecorderParam(RecorderPublicParamType::VID_ENABLE_STABLE_QUALITY_MODE), enableStableQualityMode(r) {}
135     bool enableStableQualityMode;
136 };
137 
138 struct CaptureRate : public RecorderParam {
CaptureRateCaptureRate139     explicit CaptureRate(double cr) : RecorderParam(RecorderPublicParamType::VID_CAPTURERATE), capRate(cr) {}
140     double capRate;
141 };
142 
143 struct AudEnc : public RecorderParam {
AudEncAudEnc144     explicit AudEnc(AudioCodecFormat fmt) : RecorderParam(RecorderPublicParamType::AUD_ENC_FMT), encFmt(fmt) {}
145     AudioCodecFormat encFmt;
146 };
147 
148 struct AudSampleRate : public RecorderParam {
AudSampleRateAudSampleRate149     explicit AudSampleRate(int32_t sr) : RecorderParam(RecorderPublicParamType::AUD_SAMPLERATE), sampleRate(sr) {}
150     int32_t sampleRate;
151 };
152 
153 struct AudChannel : public RecorderParam {
AudChannelAudChannel154     explicit AudChannel(int32_t num) : RecorderParam(RecorderPublicParamType::AUD_CHANNEL), channel(num) {}
155     int32_t channel;
156 };
157 
158 struct AudBitRate : public RecorderParam {
AudBitRateAudBitRate159     explicit AudBitRate(int32_t br) : RecorderParam(RecorderPublicParamType::AUD_BITRATE), bitRate(br) {}
160     int32_t bitRate;
161 };
162 
163 struct MaxDuration : public RecorderParam {
MaxDurationMaxDuration164     explicit MaxDuration(int32_t maxDur) : RecorderParam(RecorderPublicParamType::MAX_DURATION), duration(maxDur) {}
165     int32_t duration;
166 };
167 
168 struct MaxFileSize : public RecorderParam {
MaxFileSizeMaxFileSize169     explicit MaxFileSize(int64_t maxSize) : RecorderParam(RecorderPublicParamType::MAX_SIZE), size(maxSize) {}
170     int64_t size;
171 };
172 
173 struct GeoLocation : public RecorderParam {
GeoLocationGeoLocation174     explicit GeoLocation(float lat, float lng)
175         : RecorderParam(RecorderPublicParamType::GEO_LOCATION), latitude(lat), longitude(lng) {}
176     float latitude;
177     float longitude;
178 };
179 
180 struct RotationAngle : public RecorderParam {
RotationAngleRotationAngle181     explicit RotationAngle(int32_t angle)
182         : RecorderParam(RecorderPublicParamType::VID_ORIENTATION_HINT), rotation(angle) {}
183     int32_t rotation;
184 };
185 
186 struct OutFilePath : public RecorderParam {
OutFilePathOutFilePath187     explicit OutFilePath(const std::string &filePath)
188         : RecorderParam(RecorderPublicParamType::OUT_PATH), path(filePath) {}
189     std::string path;
190 };
191 
192 struct OutFd : public RecorderParam {
OutFdOutFd193     explicit OutFd(int32_t outFd) : RecorderParam(RecorderPublicParamType::OUT_FD), fd(outFd) {}
194     int32_t fd;
195 };
196 
197 struct NextOutFd : public RecorderParam {
NextOutFdNextOutFd198     explicit NextOutFd(int32_t nextOutFd) : RecorderParam(RecorderPublicParamType::NEXT_OUT_FD), fd(nextOutFd) {}
199     int32_t fd;
200 };
201 
202 struct CustomInfo : public RecorderParam {
CustomInfoCustomInfo203     explicit CustomInfo(Meta CustomInfo) : RecorderParam(RecorderPublicParamType::CUSTOM_INFO),
204         userCustomInfo(CustomInfo) {}
205     Meta userCustomInfo;
206 };
207 
208 struct GenreInfo : public RecorderParam {
GenreInfoGenreInfo209     explicit GenreInfo(std::string genreInfo) : RecorderParam(RecorderPublicParamType::GENRE_INFO),
210         genre(genreInfo) {}
211     std::string genre;
212 };
213 
214 struct MetaMimeType : public RecorderParam {
MetaMimeTypeMetaMimeType215     explicit MetaMimeType(const std::string_view &type) : RecorderParam(RecorderPublicParamType::META_MIME_TYPE),
216         mimeType(type) {}
217     std::string mimeType;
218 };
219 
220 struct MetaTimedKey : public RecorderParam {
MetaTimedKeyMetaTimedKey221     explicit MetaTimedKey(const std::string_view &key) : RecorderParam(RecorderPublicParamType::META_TIMED_KEY),
222         timedKey(key) {}
223     std::string timedKey;
224 };
225 
226 struct MetaSourceTrackMime : public RecorderParam {
MetaSourceTrackMimeMetaSourceTrackMime227     explicit MetaSourceTrackMime(std::string_view type)
228         : RecorderParam(RecorderPublicParamType::META_SOURCE_TRACK_MIME), sourceMime(type) {}
229     std::string sourceMime;
230 };
231 } // namespace Media
232 } // namespace OHOS
233 #endif
234