• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 #include <algorithm>
17 #include "native_avmagic.h"
18 #include "avcodec_list.h"
19 #include "avcodec_info.h"
20 #include "avcodec_log.h"
21 #include "avcodec_errors.h"
22 #include "native_avcapability.h"
23 
24 namespace {
25 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "NativeAVCapability"};
26 }
27 using namespace OHOS::MediaAVCodec;
28 
~OH_AVCapability()29 OH_AVCapability::~OH_AVCapability() {}
30 
OH_AVCodec_GetCapability(const char * mime,bool isEncoder)31 OH_AVCapability *OH_AVCodec_GetCapability(const char *mime, bool isEncoder)
32 {
33     CHECK_AND_RETURN_RET_LOG(mime != nullptr, nullptr, "Get capability failed: mime is nullptr");
34     CHECK_AND_RETURN_RET_LOG(strlen(mime) != 0, nullptr, "Get capability failed: mime is empty");
35     std::shared_ptr<AVCodecList> codeclist = AVCodecListFactory::CreateAVCodecList();
36     uint32_t sizeOfCap = sizeof(OH_AVCapability);
37     CapabilityData *capabilityData = codeclist->GetCapability(mime, isEncoder, AVCodecCategory::AVCODEC_NONE);
38     CHECK_AND_RETURN_RET_LOG(capabilityData != nullptr, nullptr,
39                              "Get capability failed: cannot find matched capability");
40     const std::string &name = capabilityData->codecName;
41     CHECK_AND_RETURN_RET_LOG(!name.empty(), nullptr, "Get capability failed: cannot find matched capability");
42     void *addr = codeclist->GetBuffer(name, sizeOfCap);
43     CHECK_AND_RETURN_RET_LOG(addr != nullptr, nullptr, "Get capability failed: malloc capability buffer failed");
44     OH_AVCapability *obj = static_cast<OH_AVCapability *>(addr);
45     obj->capabilityData_ = capabilityData;
46     AVCODEC_LOGD("OH_AVCodec_GetCapability successful");
47     return obj;
48 }
49 
OH_AVCodec_GetCapabilityByCategory(const char * mime,bool isEncoder,OH_AVCodecCategory category)50 OH_AVCapability *OH_AVCodec_GetCapabilityByCategory(const char *mime, bool isEncoder, OH_AVCodecCategory category)
51 {
52     CHECK_AND_RETURN_RET_LOG(mime != nullptr, nullptr, "Get capabilityByCategory failed: mime is nullptr");
53     CHECK_AND_RETURN_RET_LOG(strlen(mime) != 0, nullptr, "Get capabilityByCategory failed: mime is empty");
54     std::shared_ptr<AVCodecList> codeclist = AVCodecListFactory::CreateAVCodecList();
55     AVCodecCategory innerCategory;
56     if (category == HARDWARE) {
57         innerCategory = AVCodecCategory::AVCODEC_HARDWARE;
58     } else {
59         innerCategory = AVCodecCategory::AVCODEC_SOFTWARE;
60     }
61     uint32_t sizeOfCap = sizeof(OH_AVCapability);
62     CapabilityData *capabilityData = codeclist->GetCapability(mime, isEncoder, innerCategory);
63     CHECK_AND_RETURN_RET_LOG(capabilityData != nullptr, nullptr,
64                              "Get capabilityByCategory failed: cannot find matched capability");
65     const std::string &name = capabilityData->codecName;
66     CHECK_AND_RETURN_RET_LOG(!name.empty(), nullptr, "Get capabilityByCategory failed: cannot find matched capability");
67     void *addr = codeclist->GetBuffer(name, sizeOfCap);
68     CHECK_AND_RETURN_RET_LOG(addr != nullptr, nullptr,
69                              "Get capabilityByCategory failed: malloc capability buffer failed");
70     OH_AVCapability *obj = static_cast<OH_AVCapability *>(addr);
71     obj->capabilityData_ = capabilityData;
72     AVCODEC_LOGD("OH_AVCodec_GetCapability successful");
73     return obj;
74 }
75 
OH_AVCapability_GetName(OH_AVCapability * capability)76 const char *OH_AVCapability_GetName(OH_AVCapability *capability)
77 {
78     if (capability == nullptr) {
79         AVCODEC_LOGE("Get name failed:  null input");
80         return "";
81     }
82     const auto &name = capability->capabilityData_->codecName;
83     return name.data();
84 }
85 
OH_AVCapability_IsHardware(OH_AVCapability * capability)86 bool OH_AVCapability_IsHardware(OH_AVCapability *capability)
87 {
88     if (capability == nullptr) {
89         AVCODEC_LOGE("Varified is hardware failed:  null input");
90         return false;
91     }
92     std::shared_ptr<AVCodecInfo> codecInfo = std::make_shared<AVCodecInfo>(capability->capabilityData_);
93     return codecInfo->IsHardwareAccelerated();
94 }
95 
OH_AVCapability_GetMaxSupportedInstances(OH_AVCapability * capability)96 int32_t OH_AVCapability_GetMaxSupportedInstances(OH_AVCapability *capability)
97 {
98     if (capability == nullptr) {
99         AVCODEC_LOGE("Get max supported instance failed: null input");
100         return 0;
101     }
102     std::shared_ptr<AVCodecInfo> codecInfo = std::make_shared<AVCodecInfo>(capability->capabilityData_);
103     return codecInfo->GetMaxSupportedInstances();
104 }
105 
OH_AVCapability_GetSupportedProfiles(OH_AVCapability * capability,const int32_t ** profiles,uint32_t * profileNum)106 OH_AVErrCode OH_AVCapability_GetSupportedProfiles(OH_AVCapability *capability, const int32_t **profiles,
107                                                   uint32_t *profileNum)
108 {
109     CHECK_AND_RETURN_RET_LOG(profileNum != nullptr && profiles != nullptr, AV_ERR_INVALID_VAL,
110                              "Get supported profiles failed: null input");
111     if (capability == nullptr) {
112         *profiles = nullptr;
113         *profileNum = 0;
114         AVCODEC_LOGE("Get supported profiles failed: null input");
115         return AV_ERR_INVALID_VAL;
116     }
117     std::shared_ptr<AudioCaps> codecInfo = std::make_shared<AudioCaps>(capability->capabilityData_);
118     const auto &profile = codecInfo->GetSupportedProfiles();
119     *profiles = profile.data();
120     *profileNum = profile.size();
121     return AV_ERR_OK;
122 }
123 
OH_AVCapability_GetSupportedLevelsForProfile(OH_AVCapability * capability,int32_t profile,const int32_t ** levels,uint32_t * levelNum)124 OH_AVErrCode OH_AVCapability_GetSupportedLevelsForProfile(OH_AVCapability *capability, int32_t profile,
125                                                           const int32_t **levels, uint32_t *levelNum)
126 {
127     CHECK_AND_RETURN_RET_LOG(levels != nullptr && levelNum != nullptr, AV_ERR_INVALID_VAL,
128                              "Get supported levels for profile failed: null input");
129     if (capability == nullptr) {
130         *levels = nullptr;
131         *levelNum = 0;
132         AVCODEC_LOGE("Get supported levels for profile failed: null input");
133         return AV_ERR_INVALID_VAL;
134     }
135     std::shared_ptr<AVCodecInfo> codecInfo = std::make_shared<AVCodecInfo>(capability->capabilityData_);
136     const auto &profileLevelsMap = codecInfo->GetSupportedLevelsForProfile();
137     const auto &levelsmatch = profileLevelsMap.find(profile);
138     if (levelsmatch == profileLevelsMap.end()) {
139         return AV_ERR_INVALID_VAL;
140     }
141     *levels = levelsmatch->second.data();
142     *levelNum = levelsmatch->second.size();
143     return AV_ERR_OK;
144 }
145 
OH_AVCapability_AreProfileAndLevelSupported(OH_AVCapability * capability,int32_t profile,int32_t level)146 bool OH_AVCapability_AreProfileAndLevelSupported(OH_AVCapability *capability, int32_t profile, int32_t level)
147 {
148     if (capability == nullptr) {
149         AVCODEC_LOGE("Varified profiles and level failed: null input");
150         return false;
151     }
152     std::shared_ptr<AVCodecInfo> codecInfo = std::make_shared<AVCodecInfo>(capability->capabilityData_);
153     const auto &profileLevelsMap = codecInfo->GetSupportedLevelsForProfile();
154     const auto &levels = profileLevelsMap.find(profile);
155     if (levels == profileLevelsMap.end()) {
156         return false;
157     }
158     return find(levels->second.begin(), levels->second.end(), level) != levels->second.end();
159 }
160 
OH_AVCapability_GetEncoderBitrateRange(OH_AVCapability * capability,OH_AVRange * bitrateRange)161 OH_AVErrCode OH_AVCapability_GetEncoderBitrateRange(OH_AVCapability *capability, OH_AVRange *bitrateRange)
162 {
163     CHECK_AND_RETURN_RET_LOG(bitrateRange != nullptr, AV_ERR_INVALID_VAL,
164                              "Get encoder bitrate range failed: null input");
165     if (capability == nullptr) {
166         bitrateRange->minVal = 0;
167         bitrateRange->maxVal = 0;
168         AVCODEC_LOGE("Get encoder bitrate range failed: null input");
169         return AV_ERR_INVALID_VAL;
170     }
171     std::shared_ptr<AudioCaps> codecInfo = std::make_shared<AudioCaps>(capability->capabilityData_);
172     const auto &bitrate = codecInfo->GetSupportedBitrate();
173     bitrateRange->minVal = bitrate.minVal;
174     bitrateRange->maxVal = bitrate.maxVal;
175     return AV_ERR_OK;
176 }
177 
OH_AVCapability_GetEncoderQualityRange(OH_AVCapability * capability,OH_AVRange * qualityRange)178 OH_AVErrCode OH_AVCapability_GetEncoderQualityRange(OH_AVCapability *capability, OH_AVRange *qualityRange)
179 {
180     CHECK_AND_RETURN_RET_LOG(qualityRange != nullptr, AV_ERR_INVALID_VAL, "Get encoder quality failed: null input");
181     if (capability == nullptr) {
182         qualityRange->minVal = 0;
183         qualityRange->maxVal = 0;
184         AVCODEC_LOGE("Get encoder quality failed: null input");
185         return AV_ERR_INVALID_VAL;
186     }
187     std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capability->capabilityData_);
188     const auto &quality = codecInfo->GetSupportedEncodeQuality();
189     qualityRange->minVal = quality.minVal;
190     qualityRange->maxVal = quality.maxVal;
191     return AV_ERR_OK;
192 }
193 
OH_AVCapability_GetEncoderComplexityRange(OH_AVCapability * capability,OH_AVRange * complexityRange)194 OH_AVErrCode OH_AVCapability_GetEncoderComplexityRange(OH_AVCapability *capability, OH_AVRange *complexityRange)
195 {
196     CHECK_AND_RETURN_RET_LOG(complexityRange != nullptr, AV_ERR_INVALID_VAL,
197                              "Get encoder complexity range failed: null input");
198     if (capability == nullptr) {
199         complexityRange->minVal = 0;
200         complexityRange->maxVal = 0;
201         AVCODEC_LOGE("Get encoder complexity range failed: null input");
202         return AV_ERR_INVALID_VAL;
203     }
204     std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capability->capabilityData_);
205     const auto &complexity = codecInfo->GetSupportedComplexity();
206     complexityRange->minVal = complexity.minVal;
207     complexityRange->maxVal = complexity.maxVal;
208     return AV_ERR_OK;
209 }
210 
OH_AVCapability_IsEncoderBitrateModeSupported(OH_AVCapability * capability,OH_BitrateMode bitrateMode)211 bool OH_AVCapability_IsEncoderBitrateModeSupported(OH_AVCapability *capability, OH_BitrateMode bitrateMode)
212 {
213     if (capability == nullptr) {
214         AVCODEC_LOGE("Varified encoder bitrate mode failed: null input");
215         return false;
216     }
217     std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capability->capabilityData_);
218     const auto &bitrateModeVec = codecInfo->GetSupportedBitrateMode();
219     return find(bitrateModeVec.begin(), bitrateModeVec.end(), bitrateMode) != bitrateModeVec.end();
220 }
221 
OH_AVCapability_GetAudioSupportedSampleRates(OH_AVCapability * capability,const int32_t ** sampleRates,uint32_t * sampleRateNum)222 OH_AVErrCode OH_AVCapability_GetAudioSupportedSampleRates(OH_AVCapability *capability, const int32_t **sampleRates,
223                                                           uint32_t *sampleRateNum)
224 {
225     CHECK_AND_RETURN_RET_LOG(sampleRates != nullptr && sampleRateNum != nullptr, AV_ERR_INVALID_VAL,
226                              "Get audio supported samplerates failed: null input");
227     if (capability == nullptr) {
228         *sampleRates = nullptr;
229         *sampleRateNum = 0;
230         AVCODEC_LOGE("Get audio supported samplerates failed: null input");
231         return AV_ERR_INVALID_VAL;
232     }
233     std::shared_ptr<AudioCaps> codecInfo = std::make_shared<AudioCaps>(capability->capabilityData_);
234     const auto &vec = codecInfo->GetSupportedSampleRates();
235     *sampleRates = vec.data();
236     *sampleRateNum = vec.size();
237     return AV_ERR_OK;
238 }
239 
OH_AVCapability_GetAudioChannelCountRange(OH_AVCapability * capability,OH_AVRange * channelCountRange)240 OH_AVErrCode OH_AVCapability_GetAudioChannelCountRange(OH_AVCapability *capability, OH_AVRange *channelCountRange)
241 {
242     CHECK_AND_RETURN_RET_LOG(channelCountRange != nullptr, AV_ERR_INVALID_VAL,
243                              "Get audio channel count range failed: null input");
244     if (capability == nullptr) {
245         channelCountRange->minVal = 0;
246         channelCountRange->maxVal = 0;
247         AVCODEC_LOGE("Get audio channel count range failed: null input");
248         return AV_ERR_INVALID_VAL;
249     }
250     std::shared_ptr<AudioCaps> codecInfo = std::make_shared<AudioCaps>(capability->capabilityData_);
251     const auto &channels = codecInfo->GetSupportedChannel();
252     channelCountRange->minVal = channels.minVal;
253     channelCountRange->maxVal = channels.maxVal;
254     return AV_ERR_OK;
255 }
256 
OH_AVCapability_GetVideoSupportedPixelFormats(OH_AVCapability * capability,const int32_t ** pixFormats,uint32_t * pixFormatNum)257 OH_AVErrCode OH_AVCapability_GetVideoSupportedPixelFormats(OH_AVCapability *capability, const int32_t **pixFormats,
258                                                            uint32_t *pixFormatNum)
259 {
260     CHECK_AND_RETURN_RET_LOG(pixFormats != nullptr && pixFormatNum != nullptr, AV_ERR_INVALID_VAL,
261                              "Get video supported pixel formats failed: null input");
262     if (capability == nullptr) {
263         *pixFormats = nullptr;
264         *pixFormatNum = 0;
265         AVCODEC_LOGE("Get video supported pixel formats failed: null input");
266         return AV_ERR_INVALID_VAL;
267     }
268     std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capability->capabilityData_);
269     const auto &pixFmt = codecInfo->GetSupportedFormats();
270     *pixFormats = pixFmt.data();
271     *pixFormatNum = pixFmt.size();
272     return AV_ERR_OK;
273 }
274 
OH_AVCapability_GetVideoWidthAlignment(OH_AVCapability * capability,int32_t * widthAlignment)275 OH_AVErrCode OH_AVCapability_GetVideoWidthAlignment(OH_AVCapability *capability, int32_t *widthAlignment)
276 {
277     CHECK_AND_RETURN_RET_LOG(widthAlignment != nullptr, AV_ERR_INVALID_VAL,
278                              "Get video width alignment failed: null input");
279     if (capability == nullptr) {
280         *widthAlignment = 0;
281         AVCODEC_LOGE("Get video width alignment failed: null input");
282         return AV_ERR_INVALID_VAL;
283     }
284     std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capability->capabilityData_);
285     *widthAlignment = codecInfo->GetSupportedWidthAlignment();
286     return AV_ERR_OK;
287 }
288 
OH_AVCapability_GetVideoHeightAlignment(OH_AVCapability * capability,int32_t * heightAlignment)289 OH_AVErrCode OH_AVCapability_GetVideoHeightAlignment(OH_AVCapability *capability, int32_t *heightAlignment)
290 {
291     CHECK_AND_RETURN_RET_LOG(heightAlignment != nullptr, AV_ERR_INVALID_VAL,
292                              "Get video height alignment failed: null input");
293     if (capability == nullptr) {
294         *heightAlignment = 0;
295         AVCODEC_LOGE("Get video height alignment failed: null input");
296         return AV_ERR_INVALID_VAL;
297     }
298     std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capability->capabilityData_);
299     *heightAlignment = codecInfo->GetSupportedHeightAlignment();
300     return AV_ERR_OK;
301 }
302 
OH_AVCapability_GetVideoWidthRangeForHeight(OH_AVCapability * capability,int32_t height,OH_AVRange * widthRange)303 OH_AVErrCode OH_AVCapability_GetVideoWidthRangeForHeight(OH_AVCapability *capability, int32_t height,
304                                                          OH_AVRange *widthRange)
305 {
306     CHECK_AND_RETURN_RET_LOG(widthRange != nullptr, AV_ERR_INVALID_VAL,
307                              "Get video width range for height failed: null input");
308     if (capability == nullptr || height <= 0) {
309         widthRange->minVal = 0;
310         widthRange->maxVal = 0;
311         AVCODEC_LOGE("Get video width range for height failed: invalid input");
312         return AV_ERR_INVALID_VAL;
313     }
314     std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capability->capabilityData_);
315     const auto &width = codecInfo->GetVideoWidthRangeForHeight(height);
316     widthRange->minVal = width.minVal;
317     widthRange->maxVal = width.maxVal;
318     if (width.minVal == 0 && width.maxVal == 0) {
319         return AV_ERR_INVALID_VAL;
320     }
321     return AV_ERR_OK;
322 }
323 
OH_AVCapability_GetVideoHeightRangeForWidth(OH_AVCapability * capability,int32_t width,OH_AVRange * heightRange)324 OH_AVErrCode OH_AVCapability_GetVideoHeightRangeForWidth(OH_AVCapability *capability, int32_t width,
325                                                          OH_AVRange *heightRange)
326 {
327     CHECK_AND_RETURN_RET_LOG(heightRange != nullptr, AV_ERR_INVALID_VAL,
328                              "Get video height range for width failed: null input");
329     if (capability == nullptr || width <= 0) {
330         heightRange->minVal = 0;
331         heightRange->maxVal = 0;
332         AVCODEC_LOGE("Get video height range for width failed: invalid input");
333         return AV_ERR_INVALID_VAL;
334     }
335     std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capability->capabilityData_);
336     const auto &height = codecInfo->GetVideoHeightRangeForWidth(width);
337     heightRange->minVal = height.minVal;
338     heightRange->maxVal = height.maxVal;
339     if (height.minVal == 0 && height.maxVal == 0) {
340         return AV_ERR_INVALID_VAL;
341     }
342     return AV_ERR_OK;
343 }
344 
OH_AVCapability_GetVideoWidthRange(OH_AVCapability * capability,OH_AVRange * widthRange)345 OH_AVErrCode OH_AVCapability_GetVideoWidthRange(OH_AVCapability *capability, OH_AVRange *widthRange)
346 {
347     CHECK_AND_RETURN_RET_LOG(widthRange != nullptr, AV_ERR_INVALID_VAL, "Get video width range failed: null input");
348     if (capability == nullptr) {
349         widthRange->minVal = 0;
350         widthRange->maxVal = 0;
351         AVCODEC_LOGE("Get video width range failed: null input");
352         return AV_ERR_INVALID_VAL;
353     }
354     std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capability->capabilityData_);
355     const auto &width = codecInfo->GetSupportedWidth();
356     widthRange->minVal = width.minVal;
357     widthRange->maxVal = width.maxVal;
358     return AV_ERR_OK;
359 }
360 
OH_AVCapability_GetVideoHeightRange(OH_AVCapability * capability,OH_AVRange * heightRange)361 OH_AVErrCode OH_AVCapability_GetVideoHeightRange(OH_AVCapability *capability, OH_AVRange *heightRange)
362 {
363     CHECK_AND_RETURN_RET_LOG(heightRange != nullptr, AV_ERR_INVALID_VAL, "Get video height range failed: null input");
364     if (capability == nullptr) {
365         heightRange->minVal = 0;
366         heightRange->maxVal = 0;
367         AVCODEC_LOGE("Get video height range failed: null input");
368         return AV_ERR_INVALID_VAL;
369     }
370 
371     std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capability->capabilityData_);
372     const auto &height = codecInfo->GetSupportedHeight();
373     heightRange->minVal = height.minVal;
374     heightRange->maxVal = height.maxVal;
375     return AV_ERR_OK;
376 }
377 
OH_AVCapability_IsVideoSizeSupported(OH_AVCapability * capability,int32_t width,int32_t height)378 bool OH_AVCapability_IsVideoSizeSupported(OH_AVCapability *capability, int32_t width, int32_t height)
379 {
380     if (capability == nullptr) {
381         AVCODEC_LOGE("Varified is video size supported failed: null input");
382         return false;
383     }
384     std::shared_ptr<VideoCaps> videoCap = std::make_shared<VideoCaps>(capability->capabilityData_);
385     return videoCap->IsSizeSupported(width, height);
386 }
387 
OH_AVCapability_GetVideoFrameRateRange(OH_AVCapability * capability,OH_AVRange * frameRateRange)388 OH_AVErrCode OH_AVCapability_GetVideoFrameRateRange(OH_AVCapability *capability, OH_AVRange *frameRateRange)
389 {
390     CHECK_AND_RETURN_RET_LOG(frameRateRange != nullptr, AV_ERR_INVALID_VAL,
391                              "Get video framerate range failed: null input");
392     if (capability == nullptr) {
393         frameRateRange->minVal = 0;
394         frameRateRange->maxVal = 0;
395         AVCODEC_LOGE("Get video framerate range failed: null input");
396         return AV_ERR_INVALID_VAL;
397     }
398     std::shared_ptr<VideoCaps> videoCap = std::make_shared<VideoCaps>(capability->capabilityData_);
399     const auto &frameRate = videoCap->GetSupportedFrameRate();
400     frameRateRange->minVal = frameRate.minVal;
401     frameRateRange->maxVal = frameRate.maxVal;
402     return AV_ERR_OK;
403 }
404 
OH_AVCapability_GetVideoFrameRateRangeForSize(OH_AVCapability * capability,int32_t width,int32_t height,OH_AVRange * frameRateRange)405 OH_AVErrCode OH_AVCapability_GetVideoFrameRateRangeForSize(OH_AVCapability *capability, int32_t width, int32_t height,
406                                                            OH_AVRange *frameRateRange)
407 {
408     CHECK_AND_RETURN_RET_LOG(frameRateRange != nullptr, AV_ERR_INVALID_VAL,
409                              "Get video framerate range for size failed: null input");
410     if (capability == nullptr || width <= 0 || height <= 0) {
411         frameRateRange->minVal = 0;
412         frameRateRange->maxVal = 0;
413         AVCODEC_LOGE("Get video framerate range for size failed: invalid input");
414         return AV_ERR_INVALID_VAL;
415     }
416     std::shared_ptr<VideoCaps> videoCap = std::make_shared<VideoCaps>(capability->capabilityData_);
417     const auto &frameRate = videoCap->GetSupportedFrameRatesFor(width, height);
418     frameRateRange->minVal = frameRate.minVal;
419     frameRateRange->maxVal = frameRate.maxVal;
420     if (frameRate.minVal == 0 && frameRate.maxVal == 0) {
421         return AV_ERR_INVALID_VAL;
422     }
423     return AV_ERR_OK;
424 }
425 
OH_AVCapability_AreVideoSizeAndFrameRateSupported(OH_AVCapability * capability,int32_t width,int32_t height,int32_t frameRate)426 bool OH_AVCapability_AreVideoSizeAndFrameRateSupported(OH_AVCapability *capability, int32_t width, int32_t height,
427                                                        int32_t frameRate)
428 {
429     if (capability == nullptr) {
430         AVCODEC_LOGE("Varified video framerate and size failed: null input");
431         return false;
432     }
433     std::shared_ptr<VideoCaps> videoCap = std::make_shared<VideoCaps>(capability->capabilityData_);
434     return videoCap->IsSizeAndRateSupported(width, height, frameRate);
435 }