• 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_CAPTURERATE,
44     VID_PUBLIC_PARAM_END,
45     VID_ORIENTATION_HINT,
46     // audio begin
47     AUD_PUBLIC_PARAM_BEGIN,
48     AUD_ENC_FMT,
49     AUD_SAMPLERATE,
50     AUD_CHANNEL,
51     AUD_BITRATE,
52     AUD_PUBIC_PARAM_END,
53     // output begin,
54     MAX_DURATION,
55     MAX_SIZE,
56     OUT_PATH,
57     OUT_FD,
58     NEXT_OUT_FD, // reserved.
59     GEO_LOCATION,
60 
61     PUBLIC_PARAM_TYPE_END,
62 };
63 
64 /*
65  * Recorder parameter base structure, inherite to it to extend the new parameter.
66  */
67 struct RecorderParam {
RecorderParamRecorderParam68     explicit RecorderParam(uint32_t t) : type(t) {}
69     RecorderParam() = delete;
70     virtual ~RecorderParam() = default;
IsVideoParamRecorderParam71     bool IsVideoParam() const
72     {
73         return (type > VID_PUBLIC_PARAM_BEGIN) && (type < VID_PUBLIC_PARAM_END);
74     }
75 
IsAudioParamRecorderParam76     bool IsAudioParam() const
77     {
78         return (type > AUD_PUBLIC_PARAM_BEGIN) && (type < AUD_PUBIC_PARAM_END);
79     }
80 
81     uint32_t type;
82 };
83 
84 struct VidEnc : public RecorderParam {
VidEncVidEnc85     explicit VidEnc(VideoCodecFormat fmt) : RecorderParam(RecorderPublicParamType::VID_ENC_FMT), encFmt(fmt) {}
86     VideoCodecFormat encFmt;
87 };
88 
89 struct VidRectangle : public RecorderParam {
VidRectangleVidRectangle90     VidRectangle(int32_t w, int32_t h) : RecorderParam(RecorderPublicParamType::VID_RECTANGLE), width(w), height(h) {}
91     int32_t width;
92     int32_t height;
93 };
94 
95 struct VidBitRate : public RecorderParam {
VidBitRateVidBitRate96     explicit VidBitRate(int32_t br) : RecorderParam(RecorderPublicParamType::VID_BITRATE), bitRate(br) {}
97     int32_t bitRate;
98 };
99 
100 struct VidFrameRate : public RecorderParam {
VidFrameRateVidFrameRate101     explicit VidFrameRate(int32_t r) : RecorderParam(RecorderPublicParamType::VID_FRAMERATE), frameRate(r) {}
102     int32_t frameRate;
103 };
104 
105 struct CaptureRate : public RecorderParam {
CaptureRateCaptureRate106     explicit CaptureRate(double cr) : RecorderParam(RecorderPublicParamType::VID_CAPTURERATE), capRate(cr) {}
107     double capRate;
108 };
109 
110 struct AudEnc : public RecorderParam {
AudEncAudEnc111     explicit AudEnc(AudioCodecFormat fmt) : RecorderParam(RecorderPublicParamType::AUD_ENC_FMT), encFmt(fmt) {}
112     AudioCodecFormat encFmt;
113 };
114 
115 struct AudSampleRate : public RecorderParam {
AudSampleRateAudSampleRate116     explicit AudSampleRate(int32_t sr) : RecorderParam(RecorderPublicParamType::AUD_SAMPLERATE), sampleRate(sr) {}
117     int32_t sampleRate;
118 };
119 
120 struct AudChannel : public RecorderParam {
AudChannelAudChannel121     explicit AudChannel(int32_t num) : RecorderParam(RecorderPublicParamType::AUD_CHANNEL), channel(num) {}
122     int32_t channel;
123 };
124 
125 struct AudBitRate : public RecorderParam {
AudBitRateAudBitRate126     explicit AudBitRate(int32_t br) : RecorderParam(RecorderPublicParamType::AUD_BITRATE), bitRate(br) {}
127     int32_t bitRate;
128 };
129 
130 struct MaxDuration : public RecorderParam {
MaxDurationMaxDuration131     explicit MaxDuration(int32_t maxDur) : RecorderParam(RecorderPublicParamType::MAX_DURATION), duration(maxDur) {}
132     int32_t duration;
133 };
134 
135 struct MaxFileSize : public RecorderParam {
MaxFileSizeMaxFileSize136     explicit MaxFileSize(int64_t maxSize) : RecorderParam(RecorderPublicParamType::MAX_SIZE), size(maxSize) {}
137     int64_t size;
138 };
139 
140 struct GeoLocation : public RecorderParam {
GeoLocationGeoLocation141     explicit GeoLocation(float lat, float lng)
142         : RecorderParam(RecorderPublicParamType::GEO_LOCATION), latitude(lat), longitude(lng) {}
143     float latitude;
144     float longitude;
145 };
146 
147 struct RotationAngle : public RecorderParam {
RotationAngleRotationAngle148     explicit RotationAngle(int32_t angle)
149         : RecorderParam(RecorderPublicParamType::VID_ORIENTATION_HINT), rotation(angle) {}
150     int32_t rotation;
151 };
152 
153 struct OutFilePath : public RecorderParam {
OutFilePathOutFilePath154     explicit OutFilePath(const std::string &filePath)
155         : RecorderParam(RecorderPublicParamType::OUT_PATH), path(filePath) {}
156     std::string path;
157 };
158 
159 struct OutFd : public RecorderParam {
OutFdOutFd160     explicit OutFd(int32_t outFd) : RecorderParam(RecorderPublicParamType::OUT_FD), fd(outFd) {}
161     int32_t fd;
162 };
163 
164 struct NextOutFd : public RecorderParam {
NextOutFdNextOutFd165     explicit NextOutFd(int32_t nextOutFd) : RecorderParam(RecorderPublicParamType::NEXT_OUT_FD), fd(nextOutFd) {}
166     int32_t fd;
167 };
168 } // namespace Media
169 } // namespace OHOS
170 #endif
171