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_PUBLIC_PARAM_END,
47     VID_ORIENTATION_HINT,
48     // audio begin
49     AUD_PUBLIC_PARAM_BEGIN,
50     AUD_ENC_FMT,
51     AUD_SAMPLERATE,
52     AUD_CHANNEL,
53     AUD_BITRATE,
54     AUD_PUBIC_PARAM_END,
55     // meta data
56     META_PARAM_BEGIN,
57     META_MIME_TYPE,
58     META_TIMED_KEY,
59     META_SOURCE_TRACK_MIME,
60     META_PARAM_END,
61     // output begin,
62     MAX_DURATION,
63     MAX_SIZE,
64     OUT_PATH,
65     OUT_FD,
66     NEXT_OUT_FD, // reserved.
67     GEO_LOCATION,
68     CUSTOM_INFO,
69     GENRE_INFO,
70 
71     PUBLIC_PARAM_TYPE_END,
72 };
73 
74 /*
75  * Recorder parameter base structure, inherite to it to extend the new parameter.
76  */
77 struct RecorderParam {
RecorderParamRecorderParam78     explicit RecorderParam(uint32_t t) : type(t) {}
79     RecorderParam() = delete;
80     virtual ~RecorderParam() = default;
IsVideoParamRecorderParam81     bool IsVideoParam() const
82     {
83         return (type > VID_PUBLIC_PARAM_BEGIN) && (type < VID_PUBLIC_PARAM_END);
84     }
85 
IsMetaParamRecorderParam86     bool IsMetaParam() const
87     {
88         return (type >= META_PARAM_BEGIN) && (type < META_PARAM_END);
89     }
90 
IsAudioParamRecorderParam91     bool IsAudioParam() const
92     {
93         return (type > AUD_PUBLIC_PARAM_BEGIN) && (type < AUD_PUBIC_PARAM_END);
94     }
95 
96     uint32_t type;
97 };
98 
99 struct VidEnc : public RecorderParam {
VidEncVidEnc100     explicit VidEnc(VideoCodecFormat fmt) : RecorderParam(RecorderPublicParamType::VID_ENC_FMT), encFmt(fmt) {}
101     VideoCodecFormat encFmt;
102 };
103 
104 struct VidRectangle : public RecorderParam {
VidRectangleVidRectangle105     VidRectangle(int32_t w, int32_t h) : RecorderParam(RecorderPublicParamType::VID_RECTANGLE), width(w), height(h) {}
106     int32_t width;
107     int32_t height;
108 };
109 
110 struct VidBitRate : public RecorderParam {
VidBitRateVidBitRate111     explicit VidBitRate(int32_t br) : RecorderParam(RecorderPublicParamType::VID_BITRATE), bitRate(br) {}
112     int32_t bitRate;
113 };
114 
115 struct VidFrameRate : public RecorderParam {
VidFrameRateVidFrameRate116     explicit VidFrameRate(int32_t r) : RecorderParam(RecorderPublicParamType::VID_FRAMERATE), frameRate(r) {}
117     int32_t frameRate;
118 };
119 
120 struct VidIsHdr : public RecorderParam {
VidIsHdrVidIsHdr121     explicit VidIsHdr(bool r) : RecorderParam(RecorderPublicParamType::VID_IS_HDR), isHdr(r) {}
122     bool isHdr;
123 };
124 
125 struct VidEnableTemporalScale : public RecorderParam {
VidEnableTemporalScaleVidEnableTemporalScale126     explicit VidEnableTemporalScale(bool r)
127         : RecorderParam(RecorderPublicParamType::VID_ENABLE_TEMPORAL_SCALE), enableTemporalScale(r) {}
128     bool enableTemporalScale;
129 };
130 
131 struct CaptureRate : public RecorderParam {
CaptureRateCaptureRate132     explicit CaptureRate(double cr) : RecorderParam(RecorderPublicParamType::VID_CAPTURERATE), capRate(cr) {}
133     double capRate;
134 };
135 
136 struct AudEnc : public RecorderParam {
AudEncAudEnc137     explicit AudEnc(AudioCodecFormat fmt) : RecorderParam(RecorderPublicParamType::AUD_ENC_FMT), encFmt(fmt) {}
138     AudioCodecFormat encFmt;
139 };
140 
141 struct AudSampleRate : public RecorderParam {
AudSampleRateAudSampleRate142     explicit AudSampleRate(int32_t sr) : RecorderParam(RecorderPublicParamType::AUD_SAMPLERATE), sampleRate(sr) {}
143     int32_t sampleRate;
144 };
145 
146 struct AudChannel : public RecorderParam {
AudChannelAudChannel147     explicit AudChannel(int32_t num) : RecorderParam(RecorderPublicParamType::AUD_CHANNEL), channel(num) {}
148     int32_t channel;
149 };
150 
151 struct AudBitRate : public RecorderParam {
AudBitRateAudBitRate152     explicit AudBitRate(int32_t br) : RecorderParam(RecorderPublicParamType::AUD_BITRATE), bitRate(br) {}
153     int32_t bitRate;
154 };
155 
156 struct MaxDuration : public RecorderParam {
MaxDurationMaxDuration157     explicit MaxDuration(int32_t maxDur) : RecorderParam(RecorderPublicParamType::MAX_DURATION), duration(maxDur) {}
158     int32_t duration;
159 };
160 
161 struct MaxFileSize : public RecorderParam {
MaxFileSizeMaxFileSize162     explicit MaxFileSize(int64_t maxSize) : RecorderParam(RecorderPublicParamType::MAX_SIZE), size(maxSize) {}
163     int64_t size;
164 };
165 
166 struct GeoLocation : public RecorderParam {
GeoLocationGeoLocation167     explicit GeoLocation(float lat, float lng)
168         : RecorderParam(RecorderPublicParamType::GEO_LOCATION), latitude(lat), longitude(lng) {}
169     float latitude;
170     float longitude;
171 };
172 
173 struct RotationAngle : public RecorderParam {
RotationAngleRotationAngle174     explicit RotationAngle(int32_t angle)
175         : RecorderParam(RecorderPublicParamType::VID_ORIENTATION_HINT), rotation(angle) {}
176     int32_t rotation;
177 };
178 
179 struct OutFilePath : public RecorderParam {
OutFilePathOutFilePath180     explicit OutFilePath(const std::string &filePath)
181         : RecorderParam(RecorderPublicParamType::OUT_PATH), path(filePath) {}
182     std::string path;
183 };
184 
185 struct OutFd : public RecorderParam {
OutFdOutFd186     explicit OutFd(int32_t outFd) : RecorderParam(RecorderPublicParamType::OUT_FD), fd(outFd) {}
187     int32_t fd;
188 };
189 
190 struct NextOutFd : public RecorderParam {
NextOutFdNextOutFd191     explicit NextOutFd(int32_t nextOutFd) : RecorderParam(RecorderPublicParamType::NEXT_OUT_FD), fd(nextOutFd) {}
192     int32_t fd;
193 };
194 
195 struct CustomInfo : public RecorderParam {
CustomInfoCustomInfo196     explicit CustomInfo(Meta CustomInfo) : RecorderParam(RecorderPublicParamType::CUSTOM_INFO),
197         userCustomInfo(CustomInfo) {}
198     Meta userCustomInfo;
199 };
200 
201 struct GenreInfo : public RecorderParam {
GenreInfoGenreInfo202     explicit GenreInfo(std::string genreInfo) : RecorderParam(RecorderPublicParamType::GENRE_INFO),
203         genre(genreInfo) {}
204     std::string genre;
205 };
206 
207 struct MetaMimeType : public RecorderParam {
MetaMimeTypeMetaMimeType208     explicit MetaMimeType(const std::string_view &type) : RecorderParam(RecorderPublicParamType::META_MIME_TYPE),
209         mimeType(type) {}
210     std::string mimeType;
211 };
212 
213 struct MetaTimedKey : public RecorderParam {
MetaTimedKeyMetaTimedKey214     explicit MetaTimedKey(const std::string_view &key) : RecorderParam(RecorderPublicParamType::META_TIMED_KEY),
215         timedKey(key) {}
216     std::string timedKey;
217 };
218 
219 struct MetaSourceTrackMime : public RecorderParam {
MetaSourceTrackMimeMetaSourceTrackMime220     explicit MetaSourceTrackMime(std::string_view type)
221         : RecorderParam(RecorderPublicParamType::META_SOURCE_TRACK_MIME), sourceMime(type) {}
222     std::string sourceMime;
223 };
224 } // namespace Media
225 } // namespace OHOS
226 #endif
227