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 #include "gtest/gtest.h"
17 #include "media_errors.h"
18 #include "vcodec_unit_test.h"
19
20 using namespace std;
21 using namespace OHOS;
22 using namespace OHOS::Media;
23 using namespace testing::ext;
24 using namespace OHOS::Media::VCodecTestParam;
25
SetUpTestCase(void)26 void VCodecUnitTest::SetUpTestCase(void) {}
27
TearDownTestCase(void)28 void VCodecUnitTest::TearDownTestCase(void) {}
29
SetUp(void)30 void VCodecUnitTest::SetUp(void)
31 {
32 createCodecSuccess_ = false;
33 std::shared_ptr<VDecSignal> vdecSignal = std::make_shared<VDecSignal>();
34 vdecCallback_ = std::make_shared<VDecCallbackTest>(vdecSignal);
35 ASSERT_NE(nullptr, vdecCallback_);
36 videoDec_ = std::make_shared<VDecMock>(vdecSignal);
37
38 std::shared_ptr<VEncSignal> vencSignal = std::make_shared<VEncSignal>();
39 vencCallback_ = std::make_shared<VEncCallbackTest>(vencSignal);
40 ASSERT_NE(nullptr, vencCallback_);
41 videoEnc_ = std::make_shared<VEncMock>(vencSignal);
42
43 testInfo_ = ::testing::UnitTest::GetInstance()->current_test_info();
44 string prefix = "/data/test/media/";
45 string fileName = testInfo_->name();
46 string suffix = ".es";
47 videoEnc_->SetOutPath(prefix + fileName + suffix);
48 }
49
CreateVideoCodecByMime(const std::string & decMime,const std::string & encMime)50 bool VCodecUnitTest::CreateVideoCodecByMime(const std::string &decMime, const std::string &encMime)
51 {
52 if (videoDec_->CreateVideoDecMockByMime(decMime) == false ||
53 videoEnc_->CreateVideoEncMockByMime(encMime) == false ||
54 videoDec_->SetCallback(vdecCallback_) != MSERR_OK ||
55 videoEnc_->SetCallback(vencCallback_) != MSERR_OK) {
56 return false;
57 }
58 createCodecSuccess_ = true;
59 return true;
60 }
61
CreateVideoCodecByName(const std::string & decName,const std::string & encName)62 bool VCodecUnitTest::CreateVideoCodecByName(const std::string &decName, const std::string &encName)
63 {
64 if (videoDec_->CreateVideoDecMockByName(decName) == false ||
65 videoEnc_->CreateVideoEncMockByName(encName) == false ||
66 videoDec_->SetCallback(vdecCallback_) != MSERR_OK ||
67 videoEnc_->SetCallback(vencCallback_) != MSERR_OK) {
68 return false;
69 }
70 createCodecSuccess_ = true;
71 return true;
72 }
73
TearDown(void)74 void VCodecUnitTest::TearDown(void)
75 {
76 if (videoDec_ != nullptr && createCodecSuccess_) {
77 EXPECT_EQ(MSERR_OK, videoDec_->Reset());
78 EXPECT_EQ(MSERR_OK, videoDec_->Release());
79 }
80
81 if (videoEnc_ != nullptr && createCodecSuccess_) {
82 EXPECT_EQ(MSERR_OK, videoEnc_->Reset());
83 EXPECT_EQ(MSERR_OK, videoEnc_->Release());
84 }
85 }
86
87 /**
88 * @tc.name: video_codec_create_0100
89 * @tc.desc: video create
90 * @tc.type: FUNC
91 * @tc.require: issueI5OX06 issueI5P8N0
92 */
93 HWTEST_F(VCodecUnitTest, video_codec_create_0100, TestSize.Level0)
94 {
95 ASSERT_TRUE(CreateVideoCodecByName("avdec_h264", "avenc_mpeg4"));
96 }
97
98 /**
99 * @tc.name: video_codec_Configure_0100
100 * @tc.desc: video codec Configure
101 * @tc.type: FUNC
102 * @tc.require: issueI5OX06 issueI5P8N0
103 */
104 HWTEST_F(VCodecUnitTest, video_codec_Configure_0100, TestSize.Level0)
105 {
106 ASSERT_TRUE(CreateVideoCodecByMime("video/avc", "video/avc"));
107 std::shared_ptr<FormatMock> format = AVCodecMockFactory::CreateFormat();
108 ASSERT_NE(nullptr, format);
109 string width = "width";
110 string height = "height";
111 string pixelFormat = "pixel_format";
112 string frameRate = "frame_rate";
113 string maxInputSize = "max_input_size";
114 string rotationAngle = "rotation_angle";
115 string videoEncodeBitrateMode = "video_encode_bitrate_mode";
116 string iFrameInterval = "i_frame_interval";
117 string codecQuality = "codec_quality";
118 string codecProfile = "codec_profile";
119 (void)format->PutIntValue(width.c_str(), DEFAULT_WIDTH);
120 (void)format->PutIntValue(height.c_str(), DEFAULT_HEIGHT);
121 (void)format->PutIntValue(pixelFormat.c_str(), NV12);
122 (void)format->PutIntValue(frameRate.c_str(), DEFAULT_FRAME_RATE);
123 (void)format->PutIntValue(rotationAngle.c_str(), 0); // set rotation_angle 0
124 (void)format->PutIntValue(maxInputSize.c_str(), 15000); // set max input size 15000
125 EXPECT_EQ(MSERR_OK, videoDec_->Configure(format));
126 (void)format->PutIntValue(videoEncodeBitrateMode.c_str(), 0); // CBR
127 (void)format->PutIntValue(iFrameInterval.c_str(), 1); // i_frame_interval 1ms
128 (void)format->PutIntValue(codecQuality.c_str(), 0); // set codec_quality 0
129 (void)format->PutIntValue(codecProfile.c_str(), 0); // AVC_PROFILE_BASELINE
130 EXPECT_EQ(MSERR_OK, videoEnc_->Configure(format));
131 EXPECT_EQ(MSERR_OK, videoDec_->Prepare());
132 EXPECT_EQ(MSERR_OK, videoEnc_->Prepare());
133 format->Destroy();
134 }
135
136 /**
137 * @tc.name: video_codec_start_0100
138 * @tc.desc: video decodec start
139 * @tc.type: FUNC
140 * @tc.require: issueI5OX06 issueI5P8N0
141 */
142 HWTEST_F(VCodecUnitTest, video_codec_start_0100, TestSize.Level0)
143 {
144 ASSERT_TRUE(CreateVideoCodecByMime("video/avc", "video/avc"));
145 std::shared_ptr<FormatMock> format = AVCodecMockFactory::CreateFormat();
146 ASSERT_NE(nullptr, format);
147 string width = "width";
148 string height = "height";
149 string pixelFormat = "pixel_format";
150 string frameRate = "frame_rate";
151 (void)format->PutIntValue(width.c_str(), DEFAULT_WIDTH);
152 (void)format->PutIntValue(height.c_str(), DEFAULT_HEIGHT);
153 (void)format->PutIntValue(pixelFormat.c_str(), NV12);
154 (void)format->PutIntValue(frameRate.c_str(), DEFAULT_FRAME_RATE);
155 videoDec_->SetSource(H264_SRC_PATH, ES_H264, ES_LENGTH_H264);
156 ASSERT_EQ(MSERR_OK, videoEnc_->Configure(format));
157 ASSERT_EQ(MSERR_OK, videoDec_->Configure(format));
158 std::shared_ptr<SurfaceMock> surface = videoEnc_->GetInputSurface();
159 ASSERT_NE(nullptr, surface);
160 ASSERT_EQ(MSERR_OK, videoDec_->SetOutputSurface(surface));
161
162 EXPECT_EQ(MSERR_OK, videoDec_->Prepare());
163 EXPECT_EQ(MSERR_OK, videoEnc_->Prepare());
164 EXPECT_EQ(MSERR_OK, videoDec_->Start());
165 EXPECT_EQ(MSERR_OK, videoEnc_->Start());
166 format->Destroy();
167 }
168
169 /**
170 * @tc.name: video_codec_format_h264_h264_0100
171 * @tc.desc: video decodec h264->h264, adaptive soft or hard codec
172 * @tc.type: FUNC
173 * @tc.require: issueI5OX06 issueI5P8N0
174 */
175 HWTEST_F(VCodecUnitTest, video_codec_format_h264_h264_0100, TestSize.Level0)
176 {
177 ASSERT_TRUE(CreateVideoCodecByMime("video/avc", "video/avc"));
178 std::shared_ptr<FormatMock> format = AVCodecMockFactory::CreateFormat();
179 ASSERT_NE(nullptr, format);
180 string width = "width";
181 string height = "height";
182 string pixelFormat = "pixel_format";
183 string frameRate = "frame_rate";
184 (void)format->PutIntValue(width.c_str(), DEFAULT_WIDTH);
185 (void)format->PutIntValue(height.c_str(), DEFAULT_HEIGHT);
186 (void)format->PutIntValue(pixelFormat.c_str(), NV12);
187 (void)format->PutIntValue(frameRate.c_str(), DEFAULT_FRAME_RATE);
188 videoDec_->SetSource(H264_SRC_PATH, ES_H264, ES_LENGTH_H264);
189 ASSERT_EQ(MSERR_OK, videoEnc_->Configure(format));
190 ASSERT_EQ(MSERR_OK, videoDec_->Configure(format));
191 std::shared_ptr<SurfaceMock> surface = videoEnc_->GetInputSurface();
192 ASSERT_NE(nullptr, surface);
193 ASSERT_EQ(MSERR_OK, videoDec_->SetOutputSurface(surface));
194
195 EXPECT_EQ(MSERR_OK, videoDec_->Prepare());
196 EXPECT_EQ(MSERR_OK, videoEnc_->Prepare());
197 EXPECT_EQ(MSERR_OK, videoDec_->Start());
198 EXPECT_EQ(MSERR_OK, videoEnc_->Start());
199 system("hidumper -s 3002 -a codec");
200 sleep(3); // start run 3s
201 EXPECT_EQ(MSERR_OK, videoDec_->Stop());
202 EXPECT_EQ(MSERR_OK, videoEnc_->Stop());
203 format->Destroy();
204 }
205
206 /**
207 * @tc.name: video_codec_format_h264_mpeg4_0100
208 * @tc.desc: video software decodec h264->mpeg4
209 * @tc.type: FUNC
210 * @tc.require: issueI5OX06 issueI5P8N0
211 */
212 HWTEST_F(VCodecUnitTest, video_codec_format_h264_mpeg4_0100, TestSize.Level0)
213 {
214 ASSERT_TRUE(CreateVideoCodecByName("avdec_h264", "avenc_mpeg4"));
215 std::shared_ptr<FormatMock> format = AVCodecMockFactory::CreateFormat();
216 ASSERT_NE(nullptr, format);
217 string width = "width";
218 string height = "height";
219 string pixelFormat = "pixel_format";
220 string frameRate = "frame_rate";
221 (void)format->PutIntValue(width.c_str(), DEFAULT_WIDTH);
222 (void)format->PutIntValue(height.c_str(), DEFAULT_HEIGHT);
223 (void)format->PutIntValue(pixelFormat.c_str(), NV12);
224 (void)format->PutIntValue(frameRate.c_str(), DEFAULT_FRAME_RATE);
225 videoDec_->SetSource(H264_SRC_PATH, ES_H264, ES_LENGTH_H264);
226 ASSERT_EQ(MSERR_OK, videoEnc_->Configure(format));
227 ASSERT_EQ(MSERR_OK, videoDec_->Configure(format));
228 std::shared_ptr<SurfaceMock> surface = videoEnc_->GetInputSurface();
229 ASSERT_NE(nullptr, surface);
230 ASSERT_EQ(MSERR_OK, videoDec_->SetOutputSurface(surface));
231
232 EXPECT_EQ(MSERR_OK, videoDec_->Prepare());
233 EXPECT_EQ(MSERR_OK, videoEnc_->Prepare());
234 EXPECT_EQ(MSERR_OK, videoDec_->Start());
235 EXPECT_EQ(MSERR_OK, videoEnc_->Start());
236 system("hidumper -s 3002 -a codec");
237 sleep(3); // start run 3s
238 EXPECT_EQ(MSERR_OK, videoDec_->Stop());
239 EXPECT_EQ(MSERR_OK, videoEnc_->Stop());
240 format->Destroy();
241 }
242
243 /**
244 * @tc.name: video_codec_format_h265_h265_0100
245 * @tc.desc: video codec h265->h265
246 * @tc.type: FUNC
247 * @tc.require: issueI5OOKN issueI5OOKW issueI5OX06 issueI5P8N0
248 */
249 HWTEST_F(VCodecUnitTest, video_codec_format_h265_h265_0100, TestSize.Level0)
250 {
251 if (!CreateVideoCodecByName("OMX_hisi_video_decoder_hevc", "OMX_hisi_video_encoder_hevc")) {
252 std::cout << "This device does not support hard hevc" << std::endl;
253 createCodecSuccess_ = false;
254 return;
255 }
256 std::shared_ptr<FormatMock> format = AVCodecMockFactory::CreateFormat();
257 ASSERT_NE(nullptr, format);
258 string width = "width";
259 string height = "height";
260 string pixelFormat = "pixel_format";
261 string frameRate = "frame_rate";
262 (void)format->PutIntValue(width.c_str(), DEFAULT_WIDTH);
263 (void)format->PutIntValue(height.c_str(), DEFAULT_HEIGHT);
264 (void)format->PutIntValue(pixelFormat.c_str(), NV12);
265 (void)format->PutIntValue(frameRate.c_str(), DEFAULT_FRAME_RATE);
266 videoDec_->SetSource(H265_SRC_PATH, ES_H265, ES_LENGTH_H265);
267 ASSERT_EQ(MSERR_OK, videoEnc_->Configure(format));
268 ASSERT_EQ(MSERR_OK, videoDec_->Configure(format));
269 std::shared_ptr<SurfaceMock> surface = videoEnc_->GetInputSurface();
270 ASSERT_NE(nullptr, surface);
271 ASSERT_EQ(MSERR_OK, videoDec_->SetOutputSurface(surface));
272
273 EXPECT_EQ(MSERR_OK, videoDec_->Prepare());
274 EXPECT_EQ(MSERR_OK, videoEnc_->Prepare());
275 EXPECT_EQ(MSERR_OK, videoDec_->Start());
276 EXPECT_EQ(MSERR_OK, videoEnc_->Start());
277 sleep(3); // start run 3s
278 EXPECT_EQ(MSERR_OK, videoDec_->Stop());
279 EXPECT_EQ(MSERR_OK, videoEnc_->Stop());
280 format->Destroy();
281 }
282
283 /**
284 * @tc.name: video_decode_Flush_0100
285 * @tc.desc: video decodec flush
286 * @tc.type: FUNC
287 * @tc.require: issueI5OX06 issueI5P8N0
288 */
289 HWTEST_F(VCodecUnitTest, video_decode_Flush_0100, TestSize.Level0)
290 {
291 ASSERT_TRUE(CreateVideoCodecByMime("video/avc", "video/avc"));
292 std::shared_ptr<FormatMock> format = AVCodecMockFactory::CreateFormat();
293 ASSERT_NE(nullptr, format);
294 string width = "width";
295 string height = "height";
296 string pixelFormat = "pixel_format";
297 string frameRate = "frame_rate";
298 (void)format->PutIntValue(width.c_str(), DEFAULT_WIDTH);
299 (void)format->PutIntValue(height.c_str(), DEFAULT_HEIGHT);
300 (void)format->PutIntValue(pixelFormat.c_str(), NV12);
301 (void)format->PutIntValue(frameRate.c_str(), DEFAULT_FRAME_RATE);
302 videoDec_->SetSource(H264_SRC_PATH, ES_H264, ES_LENGTH_H264);
303 ASSERT_EQ(MSERR_OK, videoEnc_->Configure(format));
304 ASSERT_EQ(MSERR_OK, videoDec_->Configure(format));
305 std::shared_ptr<SurfaceMock> surface = videoEnc_->GetInputSurface();
306 ASSERT_NE(nullptr, surface);
307 ASSERT_EQ(MSERR_OK, videoDec_->SetOutputSurface(surface));
308
309 EXPECT_EQ(MSERR_OK, videoDec_->Prepare());
310 EXPECT_EQ(MSERR_OK, videoEnc_->Prepare());
311 EXPECT_EQ(MSERR_OK, videoDec_->Start());
312 EXPECT_EQ(MSERR_OK, videoEnc_->Start());
313 sleep(3); // start run 3s
314 EXPECT_EQ(MSERR_OK, videoDec_->Flush());
315 sleep(3); // start run 3s
316 EXPECT_EQ(MSERR_OK, videoDec_->Stop());
317 EXPECT_EQ(MSERR_OK, videoEnc_->Stop());
318 format->Destroy();
319 }
320
321 /**
322 * @tc.name: video_encode_Flush_0100
323 * @tc.desc: video encodec flush
324 * @tc.type: FUNC
325 * @tc.require: issueI5NYCP issueI5OX06 issueI5P8N0
326 */
327 HWTEST_F(VCodecUnitTest, video_encode_Flush_0100, TestSize.Level0)
328 {
329 ASSERT_TRUE(CreateVideoCodecByMime("video/avc", "video/avc"));
330 std::shared_ptr<FormatMock> format = AVCodecMockFactory::CreateFormat();
331 ASSERT_NE(nullptr, format);
332 string width = "width";
333 string height = "height";
334 string pixelFormat = "pixel_format";
335 string frameRate = "frame_rate";
336 (void)format->PutIntValue(width.c_str(), DEFAULT_WIDTH);
337 (void)format->PutIntValue(height.c_str(), DEFAULT_HEIGHT);
338 (void)format->PutIntValue(pixelFormat.c_str(), NV12);
339 (void)format->PutIntValue(frameRate.c_str(), DEFAULT_FRAME_RATE);
340 videoDec_->SetSource(H264_SRC_PATH, ES_H264, ES_LENGTH_H264);
341 ASSERT_EQ(MSERR_OK, videoEnc_->Configure(format));
342 ASSERT_EQ(MSERR_OK, videoDec_->Configure(format));
343 std::shared_ptr<SurfaceMock> surface = videoEnc_->GetInputSurface();
344 ASSERT_NE(nullptr, surface);
345 ASSERT_EQ(MSERR_OK, videoDec_->SetOutputSurface(surface));
346
347 EXPECT_EQ(MSERR_OK, videoDec_->Prepare());
348 EXPECT_EQ(MSERR_OK, videoEnc_->Prepare());
349 EXPECT_EQ(MSERR_OK, videoDec_->Start());
350 EXPECT_EQ(MSERR_OK, videoEnc_->Start());
351 sleep(3); // start run 3s
352 EXPECT_EQ(MSERR_OK, videoEnc_->Flush());
353 sleep(3); // start run 3s
354 EXPECT_EQ(MSERR_OK, videoDec_->Stop());
355 EXPECT_EQ(MSERR_OK, videoEnc_->Stop());
356 format->Destroy();
357 }
358
359
360 /**
361 * @tc.name: video_codec_abnormal_0100
362 * @tc.desc: video codec abnormal func
363 * @tc.type: FUNC
364 * @tc.require: issueI5NYCP issueI5OX06 issueI5P8N0
365 */
366 HWTEST_F(VCodecUnitTest, video_codec_abnormal_0100, TestSize.Level0)
367 {
368 ASSERT_TRUE(CreateVideoCodecByMime("video/avc", "video/avc"));
369 std::shared_ptr<FormatMock> format = AVCodecMockFactory::CreateFormat();
370 ASSERT_NE(nullptr, format);
371 string width = "width";
372 string height = "height";
373 string pixelFormat = "pixel_format";
374 string frameRate = "frame_rate";
375 string maxInputSize = "max_input_size";
376 string rotationAngle = "rotation_angle";
377 (void)format->PutIntValue(width.c_str(), DEFAULT_WIDTH);
378 (void)format->PutIntValue(height.c_str(), DEFAULT_HEIGHT);
379 (void)format->PutIntValue(pixelFormat.c_str(), NV12);
380 (void)format->PutIntValue(frameRate.c_str(), DEFAULT_FRAME_RATE);
381 (void)format->PutIntValue(rotationAngle.c_str(), 20); // invalid rotation_angle 20
382 (void)format->PutIntValue(maxInputSize.c_str(), -1); // invalid max input size -1
383 videoDec_->SetSource(H264_SRC_PATH, ES_H264, ES_LENGTH_H264);
384 videoEnc_->Configure(format);
385 videoDec_->Configure(format);
386 videoDec_->Prepare();
387 videoEnc_->Prepare();
388 EXPECT_EQ(MSERR_OK, videoDec_->Reset());
389 EXPECT_EQ(MSERR_OK, videoEnc_->Reset());
390 ASSERT_NE(MSERR_OK, videoDec_->Start());
391 ASSERT_NE(MSERR_OK, videoEnc_->Start());
392 ASSERT_NE(MSERR_OK, videoDec_->Flush());
393 ASSERT_NE(MSERR_OK, videoEnc_->Flush());
394 ASSERT_NE(MSERR_OK, videoDec_->Stop());
395 ASSERT_NE(MSERR_OK, videoEnc_->Stop());
396 format->Destroy();
397 }
398
399 /**
400 * @tc.name: video_codec_SetParameter_0100
401 * @tc.desc: video codec SetParameter
402 * @tc.type: FUNC
403 * @tc.require: issueI5OX06 issueI5P8N0
404 */
405 HWTEST_F(VCodecUnitTest, video_codec_SetParameter_0100, TestSize.Level0)
406 {
407 ASSERT_TRUE(CreateVideoCodecByMime("video/avc", "video/avc"));
408 std::shared_ptr<FormatMock> format = AVCodecMockFactory::CreateFormat();
409 ASSERT_NE(nullptr, format);
410 string width = "width";
411 string height = "height";
412 string pixelFormat = "pixel_format";
413 string frameRate = "frame_rate";
414 string suspendInputSurface = "suspend_input_surface";
415 string maxEncoderFps = "max_encoder_fps";
416 string repeatFrameAfter = "repeat_frame_after";
417 string reqIFrame = "req_i_frame";
418 string bitrate = "bitrate";
419 string vendorCustom = "vendor.custom";
420 (void)format->PutIntValue(width.c_str(), DEFAULT_WIDTH);
421 (void)format->PutIntValue(height.c_str(), DEFAULT_HEIGHT);
422 (void)format->PutIntValue(pixelFormat.c_str(), NV12);
423 (void)format->PutIntValue(frameRate.c_str(), DEFAULT_FRAME_RATE);
424 videoDec_->SetSource(H264_SRC_PATH, ES_H264, ES_LENGTH_H264);
425 ASSERT_EQ(MSERR_OK, videoDec_->Configure(format));
426 (void)format->PutIntValue(suspendInputSurface.c_str(), 0); // set suspend_input_surface value 0
427 (void)format->PutIntValue(maxEncoderFps.c_str(), DEFAULT_FRAME_RATE);
428 (void)format->PutIntValue(repeatFrameAfter.c_str(), 1); // set repeat_frame_after 1ms
429 (void)format->PutIntValue(reqIFrame.c_str(), 0); // set request i frame false
430 (void)format->PutIntValue(bitrate.c_str(), 1000000); // set bitrate 1Mbps
431 uint8_t *addr = nullptr;
432 size_t size = 0;
433 (void)format->PutBuffer(vendorCustom, addr, size);
434 ASSERT_EQ(MSERR_OK, videoEnc_->Configure(format));
435 std::shared_ptr<SurfaceMock> surface = videoEnc_->GetInputSurface();
436 ASSERT_NE(nullptr, surface);
437 ASSERT_EQ(MSERR_OK, videoDec_->SetOutputSurface(surface));
438 EXPECT_EQ(MSERR_OK, videoDec_->Prepare());
439 EXPECT_EQ(MSERR_OK, videoEnc_->Prepare());
440 EXPECT_EQ(MSERR_OK, videoDec_->Start());
441 EXPECT_EQ(MSERR_OK, videoEnc_->Start());
442 EXPECT_EQ(MSERR_OK, videoEnc_->SetParameter(format));
443 EXPECT_EQ(MSERR_OK, videoDec_->SetParameter(format));
444 sleep(3); // start run 3s
445 EXPECT_EQ(MSERR_OK, videoDec_->Stop());
446 EXPECT_EQ(MSERR_OK, videoEnc_->Stop());
447 format->Destroy();
448 }
449
450 /**
451 * @tc.name: video_codec_GetOutputMediaDescription_0100
452 * @tc.desc: video codec GetOutputMediaDescription
453 * @tc.type: FUNC
454 * @tc.require: issueI5NYCP issueI5OX06 issueI5P8N0
455 */
456 HWTEST_F(VCodecUnitTest, video_codec_GetOutputMediaDescription_0100, TestSize.Level0)
457 {
458 ASSERT_TRUE(CreateVideoCodecByMime("video/avc", "video/avc"));
459 std::shared_ptr<FormatMock> format = AVCodecMockFactory::CreateFormat();
460 ASSERT_NE(nullptr, format);
461 string width = "width";
462 string height = "height";
463 string pixelFormat = "pixel_format";
464 string frameRate = "frame_rate";
465 (void)format->PutIntValue(width.c_str(), DEFAULT_WIDTH);
466 (void)format->PutIntValue(height.c_str(), DEFAULT_HEIGHT);
467 (void)format->PutIntValue(pixelFormat.c_str(), NV12);
468 (void)format->PutIntValue(frameRate.c_str(), DEFAULT_FRAME_RATE);
469 videoDec_->SetSource(H264_SRC_PATH, ES_H264, ES_LENGTH_H264);
470 ASSERT_EQ(MSERR_OK, videoEnc_->Configure(format));
471 ASSERT_EQ(MSERR_OK, videoDec_->Configure(format));
472 std::shared_ptr<SurfaceMock> surface = videoEnc_->GetInputSurface();
473 ASSERT_NE(nullptr, surface);
474 ASSERT_EQ(MSERR_OK, videoDec_->SetOutputSurface(surface));
475 EXPECT_EQ(MSERR_OK, videoDec_->Prepare());
476 EXPECT_EQ(MSERR_OK, videoEnc_->Prepare());
477 EXPECT_EQ(MSERR_OK, videoDec_->Start());
478 EXPECT_EQ(MSERR_OK, videoEnc_->Start());
479 sleep(2); // start run 2s
480 EXPECT_NE(nullptr, videoDec_->GetOutputMediaDescription());
481 EXPECT_NE(nullptr, videoEnc_->GetOutputMediaDescription());
482 EXPECT_EQ(MSERR_OK, videoDec_->Stop());
483 EXPECT_EQ(MSERR_OK, videoEnc_->Stop());
484 format->Destroy();
485 }
486
487 /**
488 * @tc.name: video_NotifyEos_0100
489 * @tc.desc: video encodec NotifyEos
490 * @tc.type: FUNC
491 * @tc.require: issueI5NYCF issueI5OX06 issueI5P8N0
492 */
493 HWTEST_F(VCodecUnitTest, video_NotifyEos_0100, TestSize.Level0)
494 {
495 ASSERT_TRUE(CreateVideoCodecByMime("video/avc", "video/avc"));
496 std::shared_ptr<FormatMock> format = AVCodecMockFactory::CreateFormat();
497 ASSERT_NE(nullptr, format);
498 string width = "width";
499 string height = "height";
500 string pixelFormat = "pixel_format";
501 string frameRate = "frame_rate";
502 (void)format->PutIntValue(width.c_str(), DEFAULT_WIDTH);
503 (void)format->PutIntValue(height.c_str(), DEFAULT_HEIGHT);
504 (void)format->PutIntValue(pixelFormat.c_str(), NV12);
505 (void)format->PutIntValue(frameRate.c_str(), DEFAULT_FRAME_RATE);
506 videoDec_->SetSource(H264_SRC_PATH, ES_H264, ES_LENGTH_H264);
507 ASSERT_EQ(MSERR_OK, videoEnc_->Configure(format));
508 ASSERT_EQ(MSERR_OK, videoDec_->Configure(format));
509 std::shared_ptr<SurfaceMock> surface = videoEnc_->GetInputSurface();
510 ASSERT_NE(nullptr, surface);
511 ASSERT_EQ(MSERR_OK, videoDec_->SetOutputSurface(surface));
512
513 EXPECT_EQ(MSERR_OK, videoDec_->Prepare());
514 EXPECT_EQ(MSERR_OK, videoEnc_->Prepare());
515 EXPECT_EQ(MSERR_OK, videoDec_->Start());
516 EXPECT_EQ(MSERR_OK, videoEnc_->Start());
517 sleep(3); // start run 3s
518 EXPECT_EQ(MSERR_OK, videoEnc_->NotifyEos());
519 EXPECT_EQ(MSERR_OK, videoDec_->Stop());
520 EXPECT_EQ(MSERR_OK, videoEnc_->Stop());
521 format->Destroy();
522 }
523
524 /**
525 * @tc.name: video_codec_format_none_0100
526 * @tc.desc: video format none
527 * @tc.type: FUNC
528 * @tc.require: issueI5OX06 issueI5P8N0
529 */
530 HWTEST_F(VCodecUnitTest, video_codec_format_none_0100, TestSize.Level0)
531 {
532 CreateVideoCodecByMime("", "");
533 videoDec_->Release();
534 videoEnc_->Release();
535 }
536
537 /**
538 * @tc.name: video_codec_format_mpeg2_mpeg4_0100
539 * @tc.desc: video format decoder-mpeg2 encoder-mpeg4
540 * @tc.type: FUNC
541 * @tc.require: issueI5OX06 issueI5P8N0
542 */
543 HWTEST_F(VCodecUnitTest, video_codec_format_mpeg2_mpeg4_0100, TestSize.Level0)
544 {
545 ASSERT_TRUE(CreateVideoCodecByMime("video/mpeg2", "video/mp4v-es"));
546 std::shared_ptr<FormatMock> format = AVCodecMockFactory::CreateFormat();
547 ASSERT_NE(nullptr, format);
548 string width = "width";
549 string height = "height";
550 string pixelFormat = "pixel_format";
551 string frameRate = "frame_rate";
552 (void)format->PutIntValue(width.c_str(), 720); // set width 720
553 (void)format->PutIntValue(height.c_str(), 480); // set height 480
554 (void)format->PutIntValue(pixelFormat.c_str(), NV12);
555 (void)format->PutIntValue(frameRate.c_str(), DEFAULT_FRAME_RATE);
556 videoDec_->SetSource(MPEG2_SRC_PATH, ES_MPEG2, ES_LENGTH_MPEG2);
557 ASSERT_EQ(MSERR_OK, videoDec_->Configure(format));
558 ASSERT_EQ(MSERR_OK, videoEnc_->Configure(format));
559 std::shared_ptr<SurfaceMock> surface = videoEnc_->GetInputSurface();
560 ASSERT_NE(nullptr, surface);
561 ASSERT_EQ(MSERR_OK, videoDec_->SetOutputSurface(surface));
562 EXPECT_EQ(MSERR_OK, videoDec_->Prepare());
563 EXPECT_EQ(MSERR_OK, videoEnc_->Prepare());
564 EXPECT_EQ(MSERR_OK, videoDec_->Start());
565 EXPECT_EQ(MSERR_OK, videoEnc_->Start());
566 sleep(3); // start run 3s
567 EXPECT_EQ(MSERR_OK, videoDec_->Stop());
568 EXPECT_EQ(MSERR_OK, videoEnc_->Stop());
569 format->Destroy();
570 }
571
572 /**
573 * @tc.name: video_codec_format_mpeg4_mpeg4_0100
574 * @tc.desc: video format decoder-mpeg4 encoder-mpeg4
575 * @tc.type: FUNC
576 * @tc.require: issueI5OX06 issueI5P8N0
577 */
578 HWTEST_F(VCodecUnitTest, video_codec_format_mpeg4_mpeg4_0100, TestSize.Level0)
579 {
580 ASSERT_TRUE(CreateVideoCodecByMime("video/mp4v-es", "video/mp4v-es"));
581 std::shared_ptr<FormatMock> format = AVCodecMockFactory::CreateFormat();
582 ASSERT_NE(nullptr, format);
583 string width = "width";
584 string height = "height";
585 string pixelFormat = "pixel_format";
586 string frameRate = "frame_rate";
587 (void)format->PutIntValue(width.c_str(), DEFAULT_WIDTH);
588 (void)format->PutIntValue(height.c_str(), DEFAULT_HEIGHT);
589 (void)format->PutIntValue(pixelFormat.c_str(), NV12);
590 (void)format->PutIntValue(frameRate.c_str(), DEFAULT_FRAME_RATE);
591 videoDec_->SetSource(MPEG4_SRC_PATH, ES_MPEG4, ES_LENGTH_MPEG4);
592 ASSERT_EQ(MSERR_OK, videoDec_->Configure(format));
593 ASSERT_EQ(MSERR_OK, videoEnc_->Configure(format));
594 std::shared_ptr<SurfaceMock> surface = videoEnc_->GetInputSurface();
595 ASSERT_NE(nullptr, surface);
596 ASSERT_EQ(MSERR_OK, videoDec_->SetOutputSurface(surface));
597
598 EXPECT_EQ(MSERR_OK, videoDec_->Prepare());
599 EXPECT_EQ(MSERR_OK, videoEnc_->Prepare());
600 EXPECT_EQ(MSERR_OK, videoDec_->Start());
601 EXPECT_EQ(MSERR_OK, videoEnc_->Start());
602 sleep(3); // start run 3s
603 EXPECT_EQ(MSERR_OK, videoDec_->Stop());
604 EXPECT_EQ(MSERR_OK, videoEnc_->Stop());
605 format->Destroy();
606 }