1 /*
2 * Copyright (C) 2025 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 #include <iostream>
16 #include <cstdio>
17 #include <string>
18
19 #include "gtest/gtest.h"
20 #include "avcodec_common.h"
21 #include "meta/format.h"
22 #include "avcodec_video_encoder.h"
23 #include "videoenc_inner_sample.h"
24 #include "native_avcapability.h"
25 #include "avcodec_info.h"
26 #include "avcodec_list.h"
27 using namespace std;
28 using namespace OHOS;
29 using namespace OHOS::MediaAVCodec;
30 using namespace testing::ext;
31
32 namespace {
33 class HwEncInnerCapNdkTest : public testing::Test {
34 public:
35 // SetUpTestCase: Called before all test cases
36 static void SetUpTestCase(void);
37 // TearDownTestCase: Called after all test case
38 static void TearDownTestCase(void);
39 // SetUp: Called before each test cases
40 void SetUp() override;
41 // TearDown: Called after each test cases
42 void TearDown() override;
43 };
44
45 constexpr uint32_t DEFAULT_WIDTH = 1920;
46 constexpr uint32_t DEFAULT_HEIGHT = 1080;
47 std::string g_codecMime = "video/hevc";
48 std::string g_codecName = "";
49 std::shared_ptr<AVCodecVideoEncoder> venc_ = nullptr;
50 std::shared_ptr<VEncInnerSignal> signal_ = nullptr;
SetUpTestCase()51 void HwEncInnerCapNdkTest::SetUpTestCase()
52 {
53 OH_AVCapability *cap = OH_AVCodec_GetCapabilityByCategory(g_codecMime.c_str(), true, HARDWARE);
54 const char *tmpCodecName = OH_AVCapability_GetName(cap);
55 g_codecName = tmpCodecName;
56 cout << "g_codecName: " << g_codecName << endl;
57 }
58
TearDownTestCase()59 void HwEncInnerCapNdkTest::TearDownTestCase() {}
60
SetUp()61 void HwEncInnerCapNdkTest::SetUp()
62 {
63 signal_ = make_shared<VEncInnerSignal>();
64 }
65
TearDown()66 void HwEncInnerCapNdkTest::TearDown()
67 {
68 if (venc_ != nullptr) {
69 venc_->Release();
70 venc_ = nullptr;
71 }
72
73 if (signal_) {
74 signal_ = nullptr;
75 }
76 }
77 } // namespace
78
79 namespace {
IsEncoderBitrateModeSupported(CapabilityData * capData,VideoEncodeBitrateMode bitrateMode)80 bool IsEncoderBitrateModeSupported(CapabilityData *capData, VideoEncodeBitrateMode bitrateMode)
81 {
82 if (!AVCodecInfo::isEncoder(capData->codecType)) {
83 return false;
84 }
85 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capData);
86 const auto &bitrateModeVec = codecInfo->GetSupportedBitrateMode();
87 return find(bitrateModeVec.begin(), bitrateModeVec.end(), bitrateMode) != bitrateModeVec.end();
88 }
89
90 /**
91 * @tc.number : VIDEO_ENCODE_CAPABILITY_0010
92 * @tc.name : GetSupportedMaxBitrate param correct,Configure
93 * @tc.desc : api test
94 */
95 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_API_0010, TestSize.Level0)
96 {
97 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
98 CapabilityData *capabilityData = nullptr;
99 Format format;
100 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
101 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
102 if (IsEncoderBitrateModeSupported(capabilityData, SQR)) {
103 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
104 ASSERT_NE(nullptr, venc_);
105 ASSERT_GT(codecInfo->GetSupportedMaxBitrate().minVal, 0);
106 ASSERT_GT(codecInfo->GetSupportedMaxBitrate().maxVal, 0);
107 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
108 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
109 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
110 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
111 codecInfo->GetSupportedMaxBitrate().maxVal + 1);
112 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
113 venc_->Release();
114
115 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
116 ASSERT_NE(nullptr, venc_);
117 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
118 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
119 codecInfo->GetSupportedMaxBitrate().minVal - 1);
120 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
121 venc_->Release();
122
123 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
124 ASSERT_NE(nullptr, venc_);
125 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
126 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
127 codecInfo->GetSupportedMaxBitrate().minVal);
128 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
129 venc_->Release();
130 } else {
131 ASSERT_EQ(0, codecInfo->GetSupportedMaxBitrate().minVal);
132 ASSERT_EQ(0, codecInfo->GetSupportedMaxBitrate().maxVal);
133 }
134 }
135
136 /**
137 * @tc.number : VIDEO_ENCODE_CAPABILITY_0020
138 * @tc.name : GetSupportedSqrFactor param correct,Configure
139 * @tc.desc : api test
140 */
141 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_API_0020, TestSize.Level1)
142 {
143 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
144 CapabilityData *capabilityData = nullptr;
145 Format format;
146 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
147 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
148 if (IsEncoderBitrateModeSupported(capabilityData, SQR)) {
149 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
150 ASSERT_NE(nullptr, venc_);
151 ASSERT_EQ(0, codecInfo->GetSupportedSqrFactor().minVal);
152 ASSERT_GT(codecInfo->GetSupportedSqrFactor().maxVal, 0);
153 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
154 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
155 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
156 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
157 codecInfo->GetSupportedSqrFactor().maxVal + 1);
158 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
159 venc_->Release();
160
161 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
162 ASSERT_NE(nullptr, venc_);
163 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
164 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
165 codecInfo->GetSupportedSqrFactor().minVal - 1);
166 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
167 venc_->Release();
168
169 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
170 ASSERT_NE(nullptr, venc_);
171 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
172 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
173 codecInfo->GetSupportedSqrFactor().minVal);
174 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
175 venc_->Release();
176 } else {
177 ASSERT_EQ(0, codecInfo->GetSupportedSqrFactor().minVal);
178 ASSERT_EQ(0, codecInfo->GetSupportedSqrFactor().maxVal);
179 }
180 }
181
182 /**
183 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0010
184 * @tc.name : 使能SQR_max_bitrate,confige
185 * @tc.desc : api test
186 */
187 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0010, TestSize.Level0)
188 {
189 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
190 CapabilityData *capabilityData = nullptr;
191 Format format;
192 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
193 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
194 if (IsEncoderBitrateModeSupported(capabilityData, SQR)) {
195 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
196 ASSERT_NE(nullptr, venc_);
197 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
198 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
199 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
200 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
201 venc_->Release();
202
203 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
204 ASSERT_NE(nullptr, venc_);
205 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
206 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
207 codecInfo->GetSupportedMaxBitrate().maxVal);
208 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
209 venc_->Release();
210
211 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
212 ASSERT_NE(nullptr, venc_);
213 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
214 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
215 codecInfo->GetSupportedMaxBitrate().maxVal + 1);
216 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
217 venc_->Release();
218 }
219 }
220
221 /**
222 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0020
223 * @tc.name : 使能SQR_factor,confige
224 * @tc.desc : api test
225 */
226 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0020, TestSize.Level1)
227 {
228 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
229 CapabilityData *capabilityData = nullptr;
230 Format format;
231 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
232 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
233 if (IsEncoderBitrateModeSupported(capabilityData, SQR)) {
234 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
235 ASSERT_NE(nullptr, venc_);
236 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
237 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
238 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
239 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
240 codecInfo->GetSupportedSqrFactor().maxVal);
241 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
242 venc_->Release();
243
244 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
245 ASSERT_NE(nullptr, venc_);
246 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
247 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
248 codecInfo->GetSupportedSqrFactor().maxVal + 1);
249 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
250 venc_->Release();
251 }
252 }
253
254 /**
255 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0030
256 * @tc.name : 使能SQR_max_bitrate_factor,confige
257 * @tc.desc : api test
258 */
259 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0030, TestSize.Level2)
260 {
261 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
262 CapabilityData *capabilityData = nullptr;
263 Format format;
264 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
265 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
266 if (IsEncoderBitrateModeSupported(capabilityData, SQR)) {
267 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
268 ASSERT_NE(nullptr, venc_);
269 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
270 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
271 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
272 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
273 codecInfo->GetSupportedMaxBitrate().maxVal);
274 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
275 codecInfo->GetSupportedSqrFactor().maxVal);
276 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
277 venc_->Release();
278
279 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
280 ASSERT_NE(nullptr, venc_);
281 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
282 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
283 codecInfo->GetSupportedMaxBitrate().maxVal);
284 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
285 codecInfo->GetSupportedSqrFactor().maxVal + 1);
286 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
287 venc_->Release();
288
289 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
290 ASSERT_NE(nullptr, venc_);
291 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
292 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
293 codecInfo->GetSupportedMaxBitrate().maxVal + 1);
294 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
295 codecInfo->GetSupportedSqrFactor().maxVal);
296 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
297 venc_->Release();
298
299 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
300 ASSERT_NE(nullptr, venc_);
301 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
302 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
303 codecInfo->GetSupportedMaxBitrate().maxVal + 1);
304 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
305 codecInfo->GetSupportedSqrFactor().maxVal + 1);
306 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
307 venc_->Release();
308 }
309 }
310
311 /**
312 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0040
313 * @tc.name : 不使能SQR_max_bitrate,confige
314 * @tc.desc : api test
315 */
316 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0040, TestSize.Level0)
317 {
318 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
319 CapabilityData *capabilityData = nullptr;
320 Format format;
321 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
322 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
323 if (IsEncoderBitrateModeSupported(capabilityData, SQR)) {
324 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
325 ASSERT_NE(nullptr, venc_);
326 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
327 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
328 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
329 codecInfo->GetSupportedMaxBitrate().maxVal);
330 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
331 venc_->Release();
332
333 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
334 ASSERT_NE(nullptr, venc_);
335 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
336 codecInfo->GetSupportedMaxBitrate().maxVal + 1);
337 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
338 venc_->Release();
339 }
340 }
341
342 /**
343 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0050
344 * @tc.name : 不使能SQR_factor,confige
345 * @tc.desc : api test
346 */
347 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0050, TestSize.Level1)
348 {
349 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
350 CapabilityData *capabilityData = nullptr;
351 Format format;
352 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
353 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
354 if (IsEncoderBitrateModeSupported(capabilityData, SQR)) {
355 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
356 ASSERT_NE(nullptr, venc_);
357 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
358 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
359 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
360 codecInfo->GetSupportedSqrFactor().maxVal);
361 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
362 venc_->Release();
363
364 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
365 ASSERT_NE(nullptr, venc_);
366 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
367 codecInfo->GetSupportedSqrFactor().maxVal + 1);
368 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
369 venc_->Release();
370 }
371 }
372 /**
373 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0060
374 * @tc.name : 不使能SQR_max_bitrate_factor,confige
375 * @tc.desc : api test
376 */
377 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0060, TestSize.Level2)
378 {
379 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
380 CapabilityData *capabilityData = nullptr;
381 Format format;
382 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
383 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
384 if (IsEncoderBitrateModeSupported(capabilityData, SQR)) {
385 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
386 ASSERT_NE(nullptr, venc_);
387 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
388 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
389 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
390 codecInfo->GetSupportedMaxBitrate().maxVal);
391 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
392 codecInfo->GetSupportedSqrFactor().maxVal);
393 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
394 venc_->Release();
395
396 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
397 ASSERT_NE(nullptr, venc_);
398 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
399 codecInfo->GetSupportedMaxBitrate().maxVal);
400 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
401 codecInfo->GetSupportedSqrFactor().maxVal + 1);
402 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
403 venc_->Release();
404
405 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
406 ASSERT_NE(nullptr, venc_);
407 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
408 codecInfo->GetSupportedMaxBitrate().maxVal + 1);
409 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
410 codecInfo->GetSupportedSqrFactor().maxVal);
411 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
412 venc_->Release();
413
414 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
415 ASSERT_NE(nullptr, venc_);
416 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
417 codecInfo->GetSupportedMaxBitrate().maxVal + 1);
418 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
419 codecInfo->GetSupportedSqrFactor().maxVal + 1);
420 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
421 venc_->Release();
422 }
423 }
424
425 /**
426 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0070
427 * @tc.name : 使能VBR_max_bitrate,confige
428 * @tc.desc : api test
429 */
430 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0070, TestSize.Level2)
431 {
432 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
433 CapabilityData *capabilityData = nullptr;
434 Format format;
435 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
436 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
437 if (IsEncoderBitrateModeSupported(capabilityData, VBR)) {
438 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
439 ASSERT_NE(nullptr, venc_);
440 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
441 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
442 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, VBR);
443 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
444 codecInfo->GetSupportedMaxBitrate().maxVal);
445 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
446 venc_->Release();
447 }
448 }
449
450 /**
451 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0080
452 * @tc.name : 使能VBR_factor,confige
453 * @tc.desc : api test
454 */
455 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0080, TestSize.Level2)
456 {
457 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
458 CapabilityData *capabilityData = nullptr;
459 Format format;
460 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
461 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
462 if (IsEncoderBitrateModeSupported(capabilityData, VBR)) {
463 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
464 ASSERT_NE(nullptr, venc_);
465 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
466 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
467 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, VBR);
468 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
469 codecInfo->GetSupportedSqrFactor().maxVal);
470 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
471 venc_->Release();
472 }
473 }
474
475 /**
476 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0090
477 * @tc.name : 使能VBR_max_bitrate_factor,confige
478 * @tc.desc : api test
479 */
480 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0090, TestSize.Level2)
481 {
482 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
483 CapabilityData *capabilityData = nullptr;
484 Format format;
485 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
486 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
487 if (IsEncoderBitrateModeSupported(capabilityData, VBR)) {
488 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
489 ASSERT_NE(nullptr, venc_);
490 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
491 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
492 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, VBR);
493 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
494 codecInfo->GetSupportedMaxBitrate().maxVal);
495 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
496 codecInfo->GetSupportedSqrFactor().maxVal);
497 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
498 venc_->Release();
499 }
500 }
501
502 /**
503 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0100
504 * @tc.name : 使能CBR_max_bitrate,confige
505 * @tc.desc : api test
506 */
507 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0100, TestSize.Level2)
508 {
509 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
510 CapabilityData *capabilityData = nullptr;
511 Format format;
512 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
513 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
514 if (IsEncoderBitrateModeSupported(capabilityData, CBR)) {
515 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
516 ASSERT_NE(nullptr, venc_);
517 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
518 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
519 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, CBR);
520 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
521 codecInfo->GetSupportedMaxBitrate().maxVal);
522 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
523 venc_->Release();
524 }
525 }
526
527 /**
528 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0110
529 * @tc.name : 使能CBR_factor,confige
530 * @tc.desc : api test
531 */
532 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0110, TestSize.Level2)
533 {
534 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
535 CapabilityData *capabilityData = nullptr;
536 Format format;
537 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
538 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
539 if (IsEncoderBitrateModeSupported(capabilityData, CBR)) {
540 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
541 ASSERT_NE(nullptr, venc_);
542 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
543 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
544 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, CBR);
545 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
546 codecInfo->GetSupportedSqrFactor().maxVal);
547 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
548 venc_->Release();
549 }
550 }
551
552 /**
553 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0120
554 * @tc.name : 使能CBR_max_bitrate_factor,confige
555 * @tc.desc : api test
556 */
557 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0120, TestSize.Level2)
558 {
559 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
560 CapabilityData *capabilityData = nullptr;
561 Format format;
562 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
563 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
564 if (IsEncoderBitrateModeSupported(capabilityData, CBR)) {
565 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
566 ASSERT_NE(nullptr, venc_);
567 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
568 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
569 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, CBR);
570 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
571 codecInfo->GetSupportedMaxBitrate().maxVal);
572 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
573 codecInfo->GetSupportedSqrFactor().maxVal);
574 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
575 venc_->Release();
576 }
577 }
578
579 /**
580 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0130
581 * @tc.name : 使能CQ_max_bitrate,confige
582 * @tc.desc : api test
583 */
584 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0130, TestSize.Level2)
585 {
586 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
587 CapabilityData *capabilityData = nullptr;
588 Format format;
589 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
590 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
591 if (IsEncoderBitrateModeSupported(capabilityData, CQ)) {
592 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
593 ASSERT_NE(nullptr, venc_);
594 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
595 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
596 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, CQ);
597 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
598 codecInfo->GetSupportedMaxBitrate().maxVal);
599 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
600 venc_->Release();
601 }
602 }
603
604 /**
605 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0140
606 * @tc.name : 使能CQ_factor,confige
607 * @tc.desc : api test
608 */
609 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0140, TestSize.Level2)
610 {
611 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
612 CapabilityData *capabilityData = nullptr;
613 Format format;
614 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
615 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
616 if (IsEncoderBitrateModeSupported(capabilityData, CQ)) {
617 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
618 ASSERT_NE(nullptr, venc_);
619 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
620 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
621 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, CQ);
622 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
623 codecInfo->GetSupportedSqrFactor().maxVal);
624 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
625 venc_->Release();
626 }
627 }
628
629 /**
630 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0150
631 * @tc.name : 使能CQ_max_bitrate_factor,confige
632 * @tc.desc : api test
633 */
634 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0150, TestSize.Level2)
635 {
636 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
637 CapabilityData *capabilityData = nullptr;
638 Format format;
639 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
640 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
641 if (IsEncoderBitrateModeSupported(capabilityData, CQ)) {
642 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
643 ASSERT_NE(nullptr, venc_);
644 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
645 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
646 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, CQ);
647 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
648 codecInfo->GetSupportedMaxBitrate().maxVal);
649 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
650 codecInfo->GetSupportedSqrFactor().maxVal);
651 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
652 venc_->Release();
653 }
654 }
655
656 /**
657 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0160
658 * @tc.name : 使能SQR,其他模式参数quality,confige
659 * @tc.desc : api test
660 */
661 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0160, TestSize.Level2)
662 {
663 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
664 CapabilityData *capabilityData = nullptr;
665 Format format;
666 Format fmt;
667 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
668 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
669 if (IsEncoderBitrateModeSupported(capabilityData, SQR)) {
670 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
671 ASSERT_NE(nullptr, venc_);
672 format.PutIntValue(MediaDescriptionKey::MD_KEY_QUALITY, 30);
673 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
674 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
675 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
676 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
677 codecInfo->GetSupportedMaxBitrate().maxVal);
678 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
679 venc_->Release();
680
681 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
682 ASSERT_NE(nullptr, venc_);
683 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_QUALITY, 30);
684 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
685 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
686 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
687 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
688 codecInfo->GetSupportedSqrFactor().maxVal);
689 ASSERT_EQ(venc_->Configure(fmt), AVCS_ERR_OK);
690 venc_->Release();
691
692 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
693 ASSERT_NE(nullptr, venc_);
694 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_QUALITY, 30);
695 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
696 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
697 codecInfo->GetSupportedSqrFactor().maxVal+1);
698 ASSERT_EQ(venc_->Configure(fmt), AVCS_ERR_CODEC_PARAM_INCORRECT);
699 venc_->Release();
700 }
701 }
702
703 /**
704 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0170
705 * @tc.name : 不使能SQR,其他模式参数quality,confige
706 * @tc.desc : api test
707 */
708 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0170, TestSize.Level2)
709 {
710 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
711 CapabilityData *capabilityData = nullptr;
712 Format format;
713 Format fmt;
714 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
715 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
716 if (IsEncoderBitrateModeSupported(capabilityData, SQR)) {
717 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
718 ASSERT_NE(nullptr, venc_);
719 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
720 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
721 format.PutIntValue(MediaDescriptionKey::MD_KEY_QUALITY, 30);
722 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
723 codecInfo->GetSupportedMaxBitrate().maxVal);
724 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
725 venc_->Release();
726
727 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
728 ASSERT_NE(nullptr, venc_);
729 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
730 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
731 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_QUALITY, 30);
732 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
733 codecInfo->GetSupportedSqrFactor().maxVal);
734 ASSERT_EQ(venc_->Configure(fmt), AVCS_ERR_OK);
735 venc_->Release();
736 }
737 }
738
739 /**
740 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0180
741 * @tc.name : 使能SQR,其他模式参数BITRATE,confige
742 * @tc.desc : api test
743 */
744 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0180, TestSize.Level2)
745 {
746 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
747 CapabilityData *capabilityData = nullptr;
748 Format format;
749 Format fmt;
750 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
751 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
752 if (IsEncoderBitrateModeSupported(capabilityData, SQR)) {
753 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
754 ASSERT_NE(nullptr, venc_);
755 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 10000000);
756 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
757 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
758 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
759 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
760 codecInfo->GetSupportedMaxBitrate().maxVal);
761 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
762 venc_->Release();
763
764 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
765 ASSERT_NE(nullptr, venc_);
766 fmt.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 10000000);
767 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
768 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
769 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
770 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
771 codecInfo->GetSupportedSqrFactor().maxVal);
772 ASSERT_EQ(venc_->Configure(fmt), AVCS_ERR_OK);
773 venc_->Release();
774 }
775 }
776
777 /**
778 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0190
779 * @tc.name : 使能SQR,其他模式参数BITRATE,factor_max_bitrate
780 * @tc.desc : api test
781 */
782 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0190, TestSize.Level2)
783 {
784 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
785 CapabilityData *capabilityData = nullptr;
786 Format format;
787 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
788 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
789 if (IsEncoderBitrateModeSupported(capabilityData, SQR)) {
790 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
791 ASSERT_NE(nullptr, venc_);
792 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 10000000);
793 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
794 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
795 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
796 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
797 codecInfo->GetSupportedSqrFactor().maxVal);
798 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
799 codecInfo->GetSupportedMaxBitrate().maxVal);
800 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
801 venc_->Release();
802
803 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
804 ASSERT_NE(nullptr, venc_);
805 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 10000000);
806 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
807 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
808 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
809 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
810 codecInfo->GetSupportedSqrFactor().maxVal);
811 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
812 codecInfo->GetSupportedMaxBitrate().maxVal+1);
813 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
814 venc_->Release();
815 }
816 }
817
818 /**
819 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0200
820 * @tc.name : 不使能SQR,其他模式参数BITRATE,confige
821 * @tc.desc : api test
822 */
823 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0200, TestSize.Level2)
824 {
825 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
826 CapabilityData *capabilityData = nullptr;
827 Format format;
828 Format fmt;
829 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
830 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
831 if (IsEncoderBitrateModeSupported(capabilityData, SQR)) {
832 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
833 ASSERT_NE(nullptr, venc_);
834 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
835 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
836 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 10000000);
837 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
838 codecInfo->GetSupportedMaxBitrate().maxVal);
839 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
840 venc_->Release();
841
842 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
843 ASSERT_NE(nullptr, venc_);
844 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
845 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
846 fmt.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 10000000);
847 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
848 codecInfo->GetSupportedSqrFactor().maxVal);
849 ASSERT_EQ(venc_->Configure(fmt), AVCS_ERR_OK);
850 venc_->Release();
851 }
852 }
853
854 /**
855 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0210
856 * @tc.name : 不使能SQR,其他模式参数quality错误,confige
857 * @tc.desc : api test
858 */
859 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0210, TestSize.Level2)
860 {
861 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
862 CapabilityData *capabilityData = nullptr;
863 Format format;
864 Format fmt;
865 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
866 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
867 if (IsEncoderBitrateModeSupported(capabilityData, SQR)) {
868 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
869 ASSERT_NE(nullptr, venc_);
870 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
871 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
872 format.PutIntValue(MediaDescriptionKey::MD_KEY_QUALITY, -1);
873 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
874 codecInfo->GetSupportedMaxBitrate().maxVal);
875 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_CODEC_PARAM_INCORRECT);
876 venc_->Release();
877
878 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
879 ASSERT_NE(nullptr, venc_);
880 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
881 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
882 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_QUALITY, -1);
883 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
884 codecInfo->GetSupportedSqrFactor().maxVal);
885 ASSERT_EQ(venc_->Configure(fmt), AVCS_ERR_CODEC_PARAM_INCORRECT);
886 venc_->Release();
887 }
888 }
889
890 /**
891 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0220
892 * @tc.name : 使能SQR,其他模式参数BITRATE错误,confige
893 * @tc.desc : api test
894 */
895 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0220, TestSize.Level2)
896 {
897 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
898 CapabilityData *capabilityData = nullptr;
899 Format fmt;
900 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
901 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
902 if (IsEncoderBitrateModeSupported(capabilityData, SQR)) {
903 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
904 ASSERT_NE(nullptr, venc_);
905 fmt.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, -1);
906 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
907 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
908 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
909 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
910 codecInfo->GetSupportedSqrFactor().maxVal);
911 fmt.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
912 codecInfo->GetSupportedMaxBitrate().maxVal+1);
913 ASSERT_EQ(venc_->Configure(fmt), AVCS_ERR_OK);
914 venc_->Release();
915 }
916 }
917
918 /**
919 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0230
920 * @tc.name : 不使能SQR,其他模式参数BITRATE错误,confige
921 * @tc.desc : api test
922 */
923 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0230, TestSize.Level2)
924 {
925 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
926 CapabilityData *capabilityData = nullptr;
927 Format format;
928 Format fmt;
929 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
930 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
931 if (IsEncoderBitrateModeSupported(capabilityData, SQR)) {
932 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
933 ASSERT_NE(nullptr, venc_);
934 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
935 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
936 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, -1);
937 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
938 codecInfo->GetSupportedMaxBitrate().maxVal);
939 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_CODEC_PARAM_INCORRECT);
940 venc_->Release();
941
942 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
943 ASSERT_NE(nullptr, venc_);
944 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
945 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
946 fmt.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, -1);
947 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
948 codecInfo->GetSupportedSqrFactor().maxVal);
949 ASSERT_EQ(venc_->Configure(fmt), AVCS_ERR_CODEC_PARAM_INCORRECT);
950 venc_->Release();
951 }
952 }
953
954 /**
955 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0240
956 * @tc.name : 不支持平台,使能SQR,confige
957 * @tc.desc : api test
958 */
959 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0240, TestSize.Level2)
960 {
961 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
962 CapabilityData *capabilityData = nullptr;
963 Format format;
964 Format format1;
965 Format format2;
966 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
967 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
968 if (!IsEncoderBitrateModeSupported(capabilityData, SQR)) {
969 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
970 ASSERT_NE(nullptr, venc_);
971 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
972 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
973 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
974 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
975 codecInfo->GetSupportedMaxBitrate().maxVal);
976 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
977 venc_->Release();
978
979 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
980 ASSERT_NE(nullptr, venc_);
981 format1.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
982 format1.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
983 format1.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
984 codecInfo->GetSupportedSqrFactor().maxVal);
985 format1.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
986 ASSERT_EQ(venc_->Configure(format1), AVCS_ERR_OK);
987 venc_->Release();
988
989 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
990 ASSERT_NE(nullptr, venc_);
991 format2.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
992 format2.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
993 format2.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
994 format2.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
995 codecInfo->GetSupportedSqrFactor().maxVal);
996 format2.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
997 codecInfo->GetSupportedMaxBitrate().maxVal);
998 ASSERT_EQ(venc_->Configure(format2), AVCS_ERR_OK);
999 venc_->Release();
1000 }
1001 }
1002
1003 /**
1004 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0250
1005 * @tc.name : 不支持平台,不使能SQR,confige
1006 * @tc.desc : api test
1007 */
1008 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0250, TestSize.Level2)
1009 {
1010 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
1011 CapabilityData *capabilityData = nullptr;
1012 Format format;
1013 Format format1;
1014 Format format2;
1015 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
1016 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
1017 if (!IsEncoderBitrateModeSupported(capabilityData, SQR)) {
1018 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
1019 ASSERT_NE(nullptr, venc_);
1020 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
1021 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
1022 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
1023 codecInfo->GetSupportedMaxBitrate().maxVal);
1024 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
1025 venc_->Release();
1026
1027 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
1028 ASSERT_NE(nullptr, venc_);
1029 format1.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
1030 format1.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
1031 format1.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
1032 codecInfo->GetSupportedSqrFactor().maxVal);
1033 ASSERT_EQ(venc_->Configure(format1), AVCS_ERR_OK);
1034 venc_->Release();
1035
1036 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
1037 ASSERT_NE(nullptr, venc_);
1038 format2.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
1039 format2.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
1040 format2.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
1041 codecInfo->GetSupportedSqrFactor().maxVal);
1042 format2.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
1043 codecInfo->GetSupportedMaxBitrate().maxVal);
1044 ASSERT_EQ(venc_->Configure(format2), AVCS_ERR_OK);
1045 venc_->Release();
1046 }
1047 }
1048
1049 /**
1050 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0260
1051 * @tc.name : 不支持平台,使能VBR,config
1052 * @tc.desc : api test
1053 */
1054 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0260, TestSize.Level2)
1055 {
1056 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
1057 CapabilityData *capabilityData = nullptr;
1058 Format format;
1059 Format format1;
1060 Format format2;
1061 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
1062 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
1063 if (!IsEncoderBitrateModeSupported(capabilityData, VBR)) {
1064 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
1065 ASSERT_NE(nullptr, venc_);
1066 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
1067 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
1068 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, VBR);
1069 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
1070 codecInfo->GetSupportedMaxBitrate().maxVal);
1071 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
1072 venc_->Release();
1073
1074 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
1075 ASSERT_NE(nullptr, venc_);
1076 format1.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
1077 format1.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
1078 format1.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, VBR);
1079 format1.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
1080 codecInfo->GetSupportedSqrFactor().maxVal);
1081 ASSERT_EQ(venc_->Configure(format1), AVCS_ERR_OK);
1082 venc_->Release();
1083
1084 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
1085 ASSERT_NE(nullptr, venc_);
1086 format2.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
1087 format2.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
1088 format2.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, VBR);
1089 format2.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
1090 codecInfo->GetSupportedSqrFactor().maxVal);
1091 format2.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
1092 codecInfo->GetSupportedMaxBitrate().maxVal);
1093 ASSERT_EQ(venc_->Configure(format2), AVCS_ERR_OK);
1094 venc_->Release();
1095 }
1096 }
1097 /**
1098 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0270
1099 * @tc.name : 不支持平台,配置其他模式参数quality
1100 * @tc.desc : api test
1101 */
1102 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0270, TestSize.Level2)
1103 {
1104 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
1105 CapabilityData *capabilityData = nullptr;
1106 Format format;
1107 Format format1;
1108 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
1109 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
1110 if (!IsEncoderBitrateModeSupported(capabilityData, SQR)) {
1111 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
1112 ASSERT_NE(nullptr, venc_);
1113 format.PutIntValue(MediaDescriptionKey::MD_KEY_QUALITY, 30);
1114 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
1115 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
1116 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
1117 codecInfo->GetSupportedMaxBitrate().maxVal);
1118 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
1119 venc_->Release();
1120
1121 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
1122 ASSERT_NE(nullptr, venc_);
1123 format1.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
1124 format1.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
1125 format1.PutIntValue(MediaDescriptionKey::MD_KEY_QUALITY, 30);
1126 format1.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
1127 codecInfo->GetSupportedSqrFactor().maxVal);
1128 ASSERT_EQ(venc_->Configure(format1), AVCS_ERR_OK);
1129 venc_->Release();
1130
1131 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
1132 ASSERT_NE(nullptr, venc_);
1133 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
1134 format.PutIntValue(MediaDescriptionKey::MD_KEY_QUALITY, 30);
1135 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
1136 codecInfo->GetSupportedMaxBitrate().maxVal);
1137 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_CODEC_PARAM_INCORRECT);
1138 venc_->Release();
1139
1140 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
1141 ASSERT_NE(nullptr, venc_);
1142 format1.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
1143 format1.PutIntValue(MediaDescriptionKey::MD_KEY_QUALITY, 30);
1144 format1.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
1145 codecInfo->GetSupportedSqrFactor().maxVal);
1146 ASSERT_EQ(venc_->Configure(format1), AVCS_ERR_CODEC_PARAM_INCORRECT);
1147 venc_->Release();
1148 }
1149 }
1150
1151 /**
1152 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0280
1153 * @tc.name : 不支持平台,使能SQR,其他模式参数BITRATE
1154 * @tc.desc : api test
1155 */
1156 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0280, TestSize.Level2)
1157 {
1158 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
1159 CapabilityData *capabilityData = nullptr;
1160 Format format;
1161 Format fmt;
1162 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
1163 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
1164 if (!IsEncoderBitrateModeSupported(capabilityData, SQR)) {
1165 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
1166 ASSERT_NE(nullptr, venc_);
1167 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 10000000);
1168 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
1169 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
1170 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
1171 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
1172 codecInfo->GetSupportedMaxBitrate().maxVal);
1173 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_OK);
1174 venc_->Release();
1175
1176 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
1177 ASSERT_NE(nullptr, venc_);
1178 fmt.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 10000000);
1179 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
1180 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
1181 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
1182 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
1183 codecInfo->GetSupportedSqrFactor().maxVal);
1184 ASSERT_EQ(venc_->Configure(fmt), AVCS_ERR_OK);
1185 venc_->Release();
1186 }
1187 }
1188
1189 /**
1190 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0290
1191 * @tc.name : 不支持平台, 使能SQR,其他模式参数BITRATE, factor_max_bitrate
1192 * @tc.desc : api test
1193 */
1194 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0290, TestSize.Level2)
1195 {
1196 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
1197 CapabilityData *capabilityData = nullptr;
1198 Format fmt;
1199 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
1200 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
1201 if (!IsEncoderBitrateModeSupported(capabilityData, SQR)) {
1202 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
1203 ASSERT_NE(nullptr, venc_);
1204 fmt.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 10000000);
1205 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
1206 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
1207 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
1208 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
1209 codecInfo->GetSupportedSqrFactor().maxVal);
1210 fmt.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
1211 codecInfo->GetSupportedMaxBitrate().maxVal);
1212 ASSERT_EQ(venc_->Configure(fmt), AVCS_ERR_OK);
1213 venc_->Release();
1214
1215 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
1216 ASSERT_NE(nullptr, venc_);
1217 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
1218 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
1219 codecInfo->GetSupportedSqrFactor().maxVal);
1220 fmt.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
1221 codecInfo->GetSupportedMaxBitrate().maxVal+1);
1222 ASSERT_EQ(venc_->Configure(fmt), AVCS_ERR_OK);
1223 venc_->Release();
1224
1225 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
1226 ASSERT_NE(nullptr, venc_);
1227 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
1228 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
1229 codecInfo->GetSupportedSqrFactor().maxVal+1);
1230 fmt.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
1231 codecInfo->GetSupportedMaxBitrate().maxVal);
1232 ASSERT_EQ(venc_->Configure(fmt), AVCS_ERR_OK);
1233 venc_->Release();
1234
1235 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
1236 ASSERT_NE(nullptr, venc_);
1237 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
1238 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
1239 codecInfo->GetSupportedSqrFactor().maxVal+1);
1240 fmt.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
1241 codecInfo->GetSupportedMaxBitrate().maxVal+1);
1242 ASSERT_EQ(venc_->Configure(fmt), AVCS_ERR_OK);
1243 venc_->Release();
1244 }
1245 }
1246
1247 /**
1248 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0300
1249 * @tc.name : 不支持平台, 使能SQR, 其他模式参数BITRATE错误
1250 * @tc.desc : api test
1251 */
1252 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0300, TestSize.Level2)
1253 {
1254 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
1255 CapabilityData *capabilityData = nullptr;
1256 Format format;
1257 Format fmt;
1258 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
1259 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
1260 if (!IsEncoderBitrateModeSupported(capabilityData, SQR)) {
1261 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
1262 ASSERT_NE(nullptr, venc_);
1263 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, -1);
1264 format.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
1265 format.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
1266 format.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
1267 format.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
1268 codecInfo->GetSupportedMaxBitrate().maxVal);
1269 ASSERT_EQ(venc_->Configure(format), AVCS_ERR_CODEC_PARAM_INCORRECT);
1270 venc_->Release();
1271
1272 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
1273 ASSERT_NE(nullptr, venc_);
1274 fmt.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, -1);
1275 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
1276 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
1277 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
1278 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
1279 codecInfo->GetSupportedSqrFactor().maxVal);
1280 ASSERT_EQ(venc_->Configure(fmt), AVCS_ERR_CODEC_PARAM_INCORRECT);
1281 venc_->Release();
1282 }
1283 }
1284
1285 /**
1286 * @tc.number : VIDEO_ENCODE_CAPABILITY_FUNC_0310
1287 * @tc.name : 不支持平台, 使能SQR,其他模式参数BITRATE错误,factor_max_bitrate
1288 * @tc.desc : api test
1289 */
1290 HWTEST_F(HwEncInnerCapNdkTest, VIDEO_ENCODE_CAPABILITY_FUNC_0310, TestSize.Level2)
1291 {
1292 std::shared_ptr<AVCodecList> codecCapability = AVCodecListFactory::CreateAVCodecList();
1293 CapabilityData *capabilityData = nullptr;
1294 Format fmt;
1295 capabilityData = codecCapability->GetCapability(g_codecMime, true, AVCodecCategory::AVCODEC_HARDWARE);
1296 std::shared_ptr<VideoCaps> codecInfo = std::make_shared<VideoCaps>(capabilityData);
1297 if (!IsEncoderBitrateModeSupported(capabilityData, SQR)) {
1298 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
1299 ASSERT_NE(nullptr, venc_);
1300 fmt.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, -1);
1301 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
1302 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
1303 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
1304 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
1305 codecInfo->GetSupportedSqrFactor().maxVal);
1306 fmt.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
1307 codecInfo->GetSupportedMaxBitrate().maxVal);
1308 ASSERT_EQ(venc_->Configure(fmt), AVCS_ERR_CODEC_PARAM_INCORRECT);
1309 venc_->Release();
1310
1311 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
1312 ASSERT_NE(nullptr, venc_);
1313 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
1314 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
1315 codecInfo->GetSupportedSqrFactor().maxVal);
1316 fmt.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
1317 codecInfo->GetSupportedMaxBitrate().maxVal+1);
1318 ASSERT_EQ(venc_->Configure(fmt), AVCS_ERR_CODEC_PARAM_INCORRECT);
1319 venc_->Release();
1320
1321 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
1322 ASSERT_NE(nullptr, venc_);
1323 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
1324 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
1325 codecInfo->GetSupportedSqrFactor().maxVal+1);
1326 fmt.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
1327 codecInfo->GetSupportedMaxBitrate().maxVal);
1328 ASSERT_EQ(venc_->Configure(fmt), AVCS_ERR_CODEC_PARAM_INCORRECT);
1329 venc_->Release();
1330
1331 venc_ = VideoEncoderFactory::CreateByName(g_codecName);
1332 ASSERT_NE(nullptr, venc_);
1333 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODE_BITRATE_MODE, SQR);
1334 fmt.PutIntValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_SQR_FACTOR,
1335 codecInfo->GetSupportedSqrFactor().maxVal+1);
1336 fmt.PutLongValue(MediaDescriptionKey::MD_KEY_VIDEO_ENCODER_MAX_BITRATE,
1337 codecInfo->GetSupportedMaxBitrate().maxVal+1);
1338 ASSERT_EQ(venc_->Configure(fmt), AVCS_ERR_CODEC_PARAM_INCORRECT);
1339 venc_->Release();
1340 }
1341 }
1342 } // namespace