1 /*
2  * Copyright (C) 2022 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 RECORDERPROFILES_H
17 #define RECORDERPROFILES_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include "avcodec_info.h"
22 
23 namespace OHOS {
24 namespace Media {
25 using namespace MediaAVCodec;
26 /**
27  * @brief Video recorder quality level
28  *
29  * @since 3.2
30  * @version 3.2
31  */
32 enum VideoRecorderQualityLevel : int32_t {
33     /**
34      * Quality level corresponding to the lowest available resolution.
35      * @since 9
36      */
37     RECORDER_QUALITY_LOW = 0,
38 
39     /**
40     * Quality level corresponding to the highest available resolution.
41     * @since 9
42     */
43     RECORDER_QUALITY_HIGH = 1,
44 
45     /**
46     * Quality level corresponding to the qcif (176 x 144) resolution.
47     * @since 9
48     */
49     RECORDER_QUALITY_QCIF = 2,
50 
51     /**
52     * Quality level corresponding to the cif (352 x 288) resolution.
53     * @since 9
54     */
55     RECORDER_QUALITY_CIF = 3,
56 
57     /**
58     * Quality level corresponding to the 480p (720 x 480) resolution.
59     * @since 9
60     */
61     RECORDER_QUALITY_480P = 4,
62 
63     /**
64     * Quality level corresponding to the 720P (1280 x 720) resolution.
65     * @since 9
66     */
67     RECORDER_QUALITY_720P = 5,
68 
69     /**
70     * Quality level corresponding to the 1080P (1920 x 1080) resolution.
71     * @since 9
72     */
73     RECORDER_QUALITY_1080P = 6,
74 
75     /**
76     * Quality level corresponding to the QVGA (320x240) resolution.
77     * @since 9
78     */
79     RECORDER_QUALITY_QVGA = 7,
80 
81     /**
82     * Quality level corresponding to the 2160p (3840x2160) resolution.
83     * @since 9
84     */
85     RECORDER_QUALITY_2160P = 8,
86 
87     /**
88     * Time lapse quality level corresponding to the lowest available resolution.
89     * @since NA
90     */
91     RECORDER_QUALITY_TIME_LAPSE_LOW = 100,
92 
93     /**
94     * Time lapse quality level corresponding to the highest available resolution.
95     * @since NA
96     */
97     RECORDER_QUALITY_TIME_LAPSE_HIGH = 101,
98 
99     /**
100     * Time lapse quality level corresponding to the qcif (176 x 144) resolution.
101     * @since NA
102     */
103     RECORDER_QUALITY_TIME_LAPSE_QCIF = 102,
104 
105     /**
106     * Time lapse quality level corresponding to the cif (352 x 288) resolution.
107     * @since NA
108     */
109     RECORDER_QUALITY_TIME_LAPSE_CIF = 103,
110 
111     /**
112     * Time lapse quality level corresponding to the 480p (720 x 480) resolution.
113     * @since NA
114     */
115     RECORDER_QUALITY_TIME_LAPSE_480P = 104,
116 
117     /**
118     * Time lapse quality level corresponding to the 720p (1280 x 720) resolution.
119     * @since NA
120     */
121     RECORDER_QUALITY_TIME_LAPSE_720P = 105,
122 
123     /**
124     * Time lapse quality level corresponding to the 1080p (1920 x 1088) resolution.
125     * @since NA
126     */
127     RECORDER_QUALITY_TIME_LAPSE_1080P = 106,
128 
129     /**
130     * Time lapse quality level corresponding to the QVGA (320 x 240) resolution.
131     * @since NA
132     */
133     RECORDER_QUALITY_TIME_LAPSE_QVGA = 107,
134 
135     /**
136     * Time lapse quality level corresponding to the 2160p (3840 x 2160) resolution.
137     * @since NA
138     */
139     RECORDER_QUALITY_TIME_LAPSE_2160P = 108,
140 
141     /**
142     * High speed ( >= 100fps) quality level corresponding to the lowest available resolution.
143     * @since NA
144     */
145     RECORDER_QUALITY_HIGH_SPEED_LOW = 200,
146 
147     /**
148     * High speed ( >= 100fps) quality level corresponding to the highest available resolution.
149     * @since NA
150     */
151     RECORDER_QUALITY_HIGH_SPEED_HIGH = 201,
152 
153     /**
154     * High speed ( >= 100fps) quality level corresponding to the 480p (720 x 480) resolution.
155     * @since NA
156     */
157     RECORDER_QUALITY_HIGH_SPEED_480P = 202,
158 
159     /**
160     * High speed ( >= 100fps) quality level corresponding to the 720p (1280 x 720) resolution.
161     * @since NA
162     */
163     RECORDER_QUALITY_HIGH_SPEED_720P = 203,
164 
165     /**
166     * High speed ( >= 100fps) quality level corresponding to the 1080p (1920 x 1080 or 1920x1088)
167     * resolution.
168     * @since NA
169     */
170     RECORDER_QUALITY_HIGH_SPEED_1080P = 204,
171 };
172 
173 /**
174  * @brief Capability data struct of video recorder caps
175  *
176  * @since 3.2
177  * @version 3.2
178  */
179 struct VideoRecorderCaps {
180     std::string containerFormatType = "";
181     std::string audioEncoderMime = "";
182     Range audioBitrateRange;
183     std::vector<int32_t> audioSampleRates;
184     Range audioChannelRange;
185     Range videoBitrateRange;
186     Range videoFramerateRange;
187     std::string videoEncoderMime = "";
188     Range videoWidthRange;
189     Range videoHeightRange;
190 };
191 
192 /**
193  * @brief Capability data struct of audio recorder caps
194  *
195  * @since 3.2
196  * @version 3.2
197  */
198 struct AudioRecorderCaps {
199     std::string containerFormatType = "";
200     std::string mimeType = "";
201     Range bitrate;
202     Range channels;
203     std::vector<int32_t> sampleRate;
204 };
205 
206 /**
207  * @brief Capability data struct of video recorder profile
208  *
209  * @since 3.2
210  * @version 3.2
211  */
212 struct VideoRecorderProfile {
213     std::string containerFormatType = "";
214     std::string audioCodec = "";
215     std::string videoCodec = "";
216     int32_t audioBitrate = 0;
217     int32_t audioChannels = 0;
218     int32_t audioSampleRate = 0;
219     int32_t durationTime = 0;
220     int32_t qualityLevel = RECORDER_QUALITY_LOW;
221     int32_t videoBitrate = 0;
222     int32_t videoFrameWidth = 0;
223     int32_t videoFrameHeight = 0;
224     int32_t videoFrameRate = 0;
225 };
226 
227 /**
228  * @brief Capability data struct of audio recorder profile
229  *
230  * @since 3.2
231  * @version 3.2
232  */
233 struct  AudioRecorderProfile {
234     std::string containerFormatType = "";
235     std::string audioCodec = "";
236     int32_t audioBitrate = 0;
237     int32_t audioSampleRate = 0;
238     int32_t audioChannels = 0;
239 };
240 
241 class RecorderProfiles {
242 public:
243     virtual ~RecorderProfiles() = default;
244 
245     /**
246      * @brief check wether the audio recorder profile is supported.
247      * @param profile see @AudioRecorderProfile .
248      * @return  Returns the audio profile is support, if support, return true.
249      * @since 3.2
250      * @version 3.2
251      */
252     virtual bool IsAudioRecorderConfigSupported(const AudioRecorderProfile &profile) = 0;
253 
254     /**
255      * @brief Checks if there is a profile of the recorder used for a specified sourceId and video record quality.
256      * @param sourceId recorder source id, The lower 16 bits are valid. 8-15 bits indicates the type of source.
257      * 0: camera, 1 virtual display. 0-7 bits indicates corresponding to the id under the source type.
258      * @param qualityLevel record quality level, see @VideoRecorderQualityLevel .
259      * @return  Returns the qualityLevel and sourceId of the video profile is exist, if exist, return true.
260      * @since 3.2
261      * @version 3.2
262      */
263     virtual bool HasVideoRecorderProfile(int32_t sourceId, int32_t qualityLevel) = 0;
264 
265     /**
266      * @brief Get the supported audio recorder capabilities.
267      * @return Returns an array of supported audio recorder capability.
268      * @since 3.2
269      * @version 3.2
270      */
271     virtual std::vector<std::shared_ptr<AudioRecorderCaps>> GetAudioRecorderCaps() = 0;
272 
273     /**
274      * @brief Get the supported video recorder capabilities.
275      * @return Returns an array of supported video recorder capability.
276      * @since 3.2
277      * @version 3.2
278      */
279     virtual std::vector<std::shared_ptr<VideoRecorderCaps>> GetVideoRecorderCaps() = 0;
280 
281     /**
282      * @brief Get the  video recorder profile used for a specified sourceId and video record quality.
283      * @param sourceId recorder source id, The lower 16 bits are valid. 8-15 bits indicates the type of source.
284      * 0: camera, 1 virtual display. 0-7 bits indicates corresponding to the id under the source type.
285      * @param qualityLevel record quality level, see @VideoRecorderQualityLevel .
286      * @return Returns a supported video recorder profile.
287      * @since 3.2
288      * @version 3.2
289      */
290     virtual std::shared_ptr<VideoRecorderProfile> GetVideoRecorderProfile(int32_t sourceId, int32_t qualityLevel) = 0;
291 };
292 
293 class __attribute__((visibility("default"))) RecorderProfilesFactory {
294 public:
295     static RecorderProfiles& CreateRecorderProfiles();
296 private:
297     RecorderProfilesFactory() = default;
298     ~RecorderProfilesFactory() = default;
299 };
300 }  // namespace Media
301 }  // namespace OHOS
302 #endif  // RECORDERPROFILES_H
303