• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
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(10); // start run 10s
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_h265_h265_0100
208  * @tc.desc: video codec h265->h265
209  * @tc.type: FUNC
210  * @tc.require: issueI5OOKN issueI5OOKW issueI5OX06 issueI5P8N0
211  */
212 HWTEST_F(VCodecUnitTest, video_codec_format_h265_h265_0100, TestSize.Level0)
213 {
214     if (!CreateVideoCodecByName("OMX_hisi_video_decoder_hevc", "OMX_hisi_video_encoder_hevc")) {
215         std::cout << "This device does not support hard hevc" << std::endl;
216         createCodecSuccess_ = false;
217         return;
218     }
219     std::shared_ptr<FormatMock> format = AVCodecMockFactory::CreateFormat();
220     ASSERT_NE(nullptr, format);
221     string width = "width";
222     string height = "height";
223     string pixelFormat = "pixel_format";
224     string frameRate = "frame_rate";
225     (void)format->PutIntValue(width.c_str(), DEFAULT_WIDTH);
226     (void)format->PutIntValue(height.c_str(), DEFAULT_HEIGHT);
227     (void)format->PutIntValue(pixelFormat.c_str(), NV12);
228     (void)format->PutIntValue(frameRate.c_str(), DEFAULT_FRAME_RATE);
229     videoDec_->SetSource(H265_SRC_PATH, ES_H265, ES_LENGTH_H265);
230     ASSERT_EQ(MSERR_OK, videoEnc_->Configure(format));
231     ASSERT_EQ(MSERR_OK, videoDec_->Configure(format));
232     std::shared_ptr<SurfaceMock> surface = videoEnc_->GetInputSurface();
233     ASSERT_NE(nullptr, surface);
234     ASSERT_EQ(MSERR_OK, videoDec_->SetOutputSurface(surface));
235 
236     EXPECT_EQ(MSERR_OK, videoDec_->Prepare());
237     EXPECT_EQ(MSERR_OK, videoEnc_->Prepare());
238     EXPECT_EQ(MSERR_OK, videoDec_->Start());
239     EXPECT_EQ(MSERR_OK, videoEnc_->Start());
240     sleep(10); // start run 10s
241     EXPECT_EQ(MSERR_OK, videoDec_->Stop());
242     EXPECT_EQ(MSERR_OK, videoEnc_->Stop());
243     format->Destroy();
244 }
245 
246 /**
247  * @tc.name: video_decode_Flush_0100
248  * @tc.desc: video decodec flush
249  * @tc.type: FUNC
250  * @tc.require: issueI5OX06 issueI5P8N0
251  */
252 HWTEST_F(VCodecUnitTest, video_decode_Flush_0100, TestSize.Level0)
253 {
254     ASSERT_TRUE(CreateVideoCodecByMime("video/avc", "video/avc"));
255     std::shared_ptr<FormatMock> format = AVCodecMockFactory::CreateFormat();
256     ASSERT_NE(nullptr, format);
257     string width = "width";
258     string height = "height";
259     string pixelFormat = "pixel_format";
260     string frameRate = "frame_rate";
261     (void)format->PutIntValue(width.c_str(), DEFAULT_WIDTH);
262     (void)format->PutIntValue(height.c_str(), DEFAULT_HEIGHT);
263     (void)format->PutIntValue(pixelFormat.c_str(), NV12);
264     (void)format->PutIntValue(frameRate.c_str(), DEFAULT_FRAME_RATE);
265     videoDec_->SetSource(H264_SRC_PATH, ES_H264, ES_LENGTH_H264);
266     ASSERT_EQ(MSERR_OK, videoEnc_->Configure(format));
267     ASSERT_EQ(MSERR_OK, videoDec_->Configure(format));
268     std::shared_ptr<SurfaceMock> surface = videoEnc_->GetInputSurface();
269     ASSERT_NE(nullptr, surface);
270     ASSERT_EQ(MSERR_OK, videoDec_->SetOutputSurface(surface));
271 
272     EXPECT_EQ(MSERR_OK, videoDec_->Prepare());
273     EXPECT_EQ(MSERR_OK, videoEnc_->Prepare());
274     EXPECT_EQ(MSERR_OK, videoDec_->Start());
275     EXPECT_EQ(MSERR_OK, videoEnc_->Start());
276     sleep(3); // start run 3s
277     EXPECT_EQ(MSERR_OK, videoDec_->Flush());
278     sleep(7); // start run 7s
279     EXPECT_EQ(MSERR_OK, videoDec_->Stop());
280     EXPECT_EQ(MSERR_OK, videoEnc_->Stop());
281     format->Destroy();
282 }
283 
284 /**
285  * @tc.name: video_encode_Flush_0100
286  * @tc.desc: video encodec flush
287  * @tc.type: FUNC
288  * @tc.require: issueI5NYCP issueI5OX06 issueI5P8N0
289  */
290 HWTEST_F(VCodecUnitTest, video_encode_Flush_0100, TestSize.Level0)
291 {
292     ASSERT_TRUE(CreateVideoCodecByMime("video/avc", "video/avc"));
293     std::shared_ptr<FormatMock> format = AVCodecMockFactory::CreateFormat();
294     ASSERT_NE(nullptr, format);
295     string width = "width";
296     string height = "height";
297     string pixelFormat = "pixel_format";
298     string frameRate = "frame_rate";
299     (void)format->PutIntValue(width.c_str(), DEFAULT_WIDTH);
300     (void)format->PutIntValue(height.c_str(), DEFAULT_HEIGHT);
301     (void)format->PutIntValue(pixelFormat.c_str(), NV12);
302     (void)format->PutIntValue(frameRate.c_str(), DEFAULT_FRAME_RATE);
303     videoDec_->SetSource(H264_SRC_PATH, ES_H264, ES_LENGTH_H264);
304     ASSERT_EQ(MSERR_OK, videoEnc_->Configure(format));
305     ASSERT_EQ(MSERR_OK, videoDec_->Configure(format));
306     std::shared_ptr<SurfaceMock> surface = videoEnc_->GetInputSurface();
307     ASSERT_NE(nullptr, surface);
308     ASSERT_EQ(MSERR_OK, videoDec_->SetOutputSurface(surface));
309 
310     EXPECT_EQ(MSERR_OK, videoDec_->Prepare());
311     EXPECT_EQ(MSERR_OK, videoEnc_->Prepare());
312     EXPECT_EQ(MSERR_OK, videoDec_->Start());
313     EXPECT_EQ(MSERR_OK, videoEnc_->Start());
314     sleep(3); // start run 3s
315     EXPECT_EQ(MSERR_OK, videoEnc_->Flush());
316     sleep(7); // start run 7s
317     EXPECT_EQ(MSERR_OK, videoDec_->Stop());
318     EXPECT_EQ(MSERR_OK, videoEnc_->Stop());
319     format->Destroy();
320 }
321 
322 
323 /**
324  * @tc.name: video_codec_abnormal_0100
325  * @tc.desc: video codec abnormal func
326  * @tc.type: FUNC
327  * @tc.require: issueI5NYCP issueI5OX06 issueI5P8N0
328  */
329 HWTEST_F(VCodecUnitTest, video_codec_abnormal_0100, TestSize.Level0)
330 {
331     ASSERT_TRUE(CreateVideoCodecByMime("video/avc", "video/avc"));
332     std::shared_ptr<FormatMock> format = AVCodecMockFactory::CreateFormat();
333     ASSERT_NE(nullptr, format);
334     string width = "width";
335     string height = "height";
336     string pixelFormat = "pixel_format";
337     string frameRate = "frame_rate";
338     string maxInputSize = "max_input_size";
339     string rotationAngle = "rotation_angle";
340     (void)format->PutIntValue(width.c_str(), DEFAULT_WIDTH);
341     (void)format->PutIntValue(height.c_str(), DEFAULT_HEIGHT);
342     (void)format->PutIntValue(pixelFormat.c_str(), NV12);
343     (void)format->PutIntValue(frameRate.c_str(), DEFAULT_FRAME_RATE);
344     (void)format->PutIntValue(rotationAngle.c_str(), 20); // invalid rotation_angle 20
345     (void)format->PutIntValue(maxInputSize.c_str(), -1); // invalid max input size -1
346     videoDec_->SetSource(H264_SRC_PATH, ES_H264, ES_LENGTH_H264);
347     videoEnc_->Configure(format);
348     videoDec_->Configure(format);
349     videoDec_->Prepare();
350     videoEnc_->Prepare();
351     EXPECT_EQ(MSERR_OK, videoDec_->Reset());
352     EXPECT_EQ(MSERR_OK, videoEnc_->Reset());
353     ASSERT_NE(MSERR_OK, videoDec_->Start());
354     ASSERT_NE(MSERR_OK, videoEnc_->Start());
355     ASSERT_NE(MSERR_OK, videoDec_->Flush());
356     ASSERT_NE(MSERR_OK, videoEnc_->Flush());
357     ASSERT_NE(MSERR_OK, videoDec_->Stop());
358     ASSERT_NE(MSERR_OK, videoEnc_->Stop());
359     format->Destroy();
360 }
361 
362 /**
363  * @tc.name: video_codec_SetParameter_0100
364  * @tc.desc: video codec SetParameter
365  * @tc.type: FUNC
366  * @tc.require: issueI5OX06 issueI5P8N0
367  */
368 HWTEST_F(VCodecUnitTest, video_codec_SetParameter_0100, TestSize.Level0)
369 {
370     ASSERT_TRUE(CreateVideoCodecByMime("video/avc", "video/avc"));
371     std::shared_ptr<FormatMock> format = AVCodecMockFactory::CreateFormat();
372     ASSERT_NE(nullptr, format);
373     string width = "width";
374     string height = "height";
375     string pixelFormat = "pixel_format";
376     string frameRate = "frame_rate";
377     string suspendInputSurface = "suspend_input_surface";
378     string maxEncoderFps = "max_encoder_fps";
379     string repeatFrameAfter = "repeat_frame_after";
380     string reqIFrame = "req_i_frame";
381     string bitrate = "bitrate";
382     string vendorCustom = "vendor.custom";
383     (void)format->PutIntValue(width.c_str(), DEFAULT_WIDTH);
384     (void)format->PutIntValue(height.c_str(), DEFAULT_HEIGHT);
385     (void)format->PutIntValue(pixelFormat.c_str(), NV12);
386     (void)format->PutIntValue(frameRate.c_str(), DEFAULT_FRAME_RATE);
387     videoDec_->SetSource(H264_SRC_PATH, ES_H264, ES_LENGTH_H264);
388     ASSERT_EQ(MSERR_OK, videoDec_->Configure(format));
389     (void)format->PutIntValue(suspendInputSurface.c_str(), 0); // set suspend_input_surface value 0
390     (void)format->PutIntValue(maxEncoderFps.c_str(), DEFAULT_FRAME_RATE);
391     (void)format->PutIntValue(repeatFrameAfter.c_str(), 1); // set repeat_frame_after 1ms
392     (void)format->PutIntValue(reqIFrame.c_str(), 0); // set request i frame false
393     (void)format->PutIntValue(bitrate.c_str(), 1000000); // set bitrate 1Mbps
394     uint8_t *addr = nullptr;
395     size_t size = 0;
396     (void)format->PutBuffer(vendorCustom, addr, size);
397     ASSERT_EQ(MSERR_OK, videoEnc_->Configure(format));
398     std::shared_ptr<SurfaceMock> surface = videoEnc_->GetInputSurface();
399     ASSERT_NE(nullptr, surface);
400     ASSERT_EQ(MSERR_OK, videoDec_->SetOutputSurface(surface));
401     EXPECT_EQ(MSERR_OK, videoDec_->Prepare());
402     EXPECT_EQ(MSERR_OK, videoEnc_->Prepare());
403     EXPECT_EQ(MSERR_OK, videoDec_->Start());
404     EXPECT_EQ(MSERR_OK, videoEnc_->Start());
405     EXPECT_EQ(MSERR_OK, videoEnc_->SetParameter(format));
406     EXPECT_EQ(MSERR_OK, videoDec_->SetParameter(format));
407     sleep(5); // start run 5s
408     EXPECT_EQ(MSERR_OK, videoDec_->Stop());
409     EXPECT_EQ(MSERR_OK, videoEnc_->Stop());
410     format->Destroy();
411 }
412 
413 /**
414  * @tc.name: video_codec_GetOutputMediaDescription_0100
415  * @tc.desc: video codec GetOutputMediaDescription
416  * @tc.type: FUNC
417  * @tc.require: issueI5NYCP issueI5OX06 issueI5P8N0
418  */
419 HWTEST_F(VCodecUnitTest, video_codec_GetOutputMediaDescription_0100, TestSize.Level0)
420 {
421     ASSERT_TRUE(CreateVideoCodecByMime("video/avc", "video/avc"));
422     std::shared_ptr<FormatMock> format = AVCodecMockFactory::CreateFormat();
423     ASSERT_NE(nullptr, format);
424     string width = "width";
425     string height = "height";
426     string pixelFormat = "pixel_format";
427     string frameRate = "frame_rate";
428     (void)format->PutIntValue(width.c_str(), DEFAULT_WIDTH);
429     (void)format->PutIntValue(height.c_str(), DEFAULT_HEIGHT);
430     (void)format->PutIntValue(pixelFormat.c_str(), NV12);
431     (void)format->PutIntValue(frameRate.c_str(), DEFAULT_FRAME_RATE);
432     videoDec_->SetSource(H264_SRC_PATH, ES_H264, ES_LENGTH_H264);
433     ASSERT_EQ(MSERR_OK, videoEnc_->Configure(format));
434     ASSERT_EQ(MSERR_OK, videoDec_->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     sleep(2); // start run 2s
443     EXPECT_NE(nullptr, videoDec_->GetOutputMediaDescription());
444     EXPECT_NE(nullptr, videoEnc_->GetOutputMediaDescription());
445     EXPECT_EQ(MSERR_OK, videoDec_->Stop());
446     EXPECT_EQ(MSERR_OK, videoEnc_->Stop());
447     format->Destroy();
448 }
449 
450 /**
451  * @tc.name: video_NotifyEos_0100
452  * @tc.desc: video encodec NotifyEos
453  * @tc.type: FUNC
454  * @tc.require: issueI5NYCF issueI5OX06 issueI5P8N0
455 */
456 HWTEST_F(VCodecUnitTest, video_NotifyEos_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 
476     EXPECT_EQ(MSERR_OK, videoDec_->Prepare());
477     EXPECT_EQ(MSERR_OK, videoEnc_->Prepare());
478     EXPECT_EQ(MSERR_OK, videoDec_->Start());
479     EXPECT_EQ(MSERR_OK, videoEnc_->Start());
480     sleep(10); // start run 10s
481     EXPECT_EQ(MSERR_OK, videoEnc_->NotifyEos());
482     EXPECT_EQ(MSERR_OK, videoDec_->Stop());
483     EXPECT_EQ(MSERR_OK, videoEnc_->Stop());
484     format->Destroy();
485 }
486 
487 /**
488  * @tc.name: video_codec_format_none_0100
489  * @tc.desc: video format none
490  * @tc.type: FUNC
491  * @tc.require: issueI5OX06 issueI5P8N0
492 */
493 HWTEST_F(VCodecUnitTest, video_codec_format_none_0100, TestSize.Level0)
494 {
495     CreateVideoCodecByMime("", "");
496     videoDec_->Release();
497     videoEnc_->Release();
498 }
499 
500 /**
501  * @tc.name: video_codec_format_mpeg2_mpeg4_0100
502  * @tc.desc: video format decoder-mpeg2 encoder-mpeg4
503  * @tc.type: FUNC
504  * @tc.require: issueI5OX06 issueI5P8N0
505  */
506 HWTEST_F(VCodecUnitTest, video_codec_format_mpeg2_mpeg4_0100, TestSize.Level0)
507 {
508     ASSERT_TRUE(CreateVideoCodecByMime("video/mpeg2", "video/mp4v-es"));
509     std::shared_ptr<FormatMock> format = AVCodecMockFactory::CreateFormat();
510     ASSERT_NE(nullptr, format);
511     string width = "width";
512     string height = "height";
513     string pixelFormat = "pixel_format";
514     string frameRate = "frame_rate";
515     (void)format->PutIntValue(width.c_str(), 720); // set width 720
516     (void)format->PutIntValue(height.c_str(), 480); // set height 480
517     (void)format->PutIntValue(pixelFormat.c_str(), NV12);
518     (void)format->PutIntValue(frameRate.c_str(), DEFAULT_FRAME_RATE);
519     videoDec_->SetSource(MPEG2_SRC_PATH, ES_MPEG2, ES_LENGTH_MPEG2);
520     ASSERT_EQ(MSERR_OK, videoDec_->Configure(format));
521     ASSERT_EQ(MSERR_OK, videoEnc_->Configure(format));
522     std::shared_ptr<SurfaceMock> surface = videoEnc_->GetInputSurface();
523     ASSERT_NE(nullptr, surface);
524     ASSERT_EQ(MSERR_OK, videoDec_->SetOutputSurface(surface));
525     EXPECT_EQ(MSERR_OK, videoDec_->Prepare());
526     EXPECT_EQ(MSERR_OK, videoEnc_->Prepare());
527     EXPECT_EQ(MSERR_OK, videoDec_->Start());
528     EXPECT_EQ(MSERR_OK, videoEnc_->Start());
529     sleep(5); // start run 5s
530     EXPECT_EQ(MSERR_OK, videoDec_->Stop());
531     EXPECT_EQ(MSERR_OK, videoEnc_->Stop());
532     format->Destroy();
533 }
534 
535 /**
536  * @tc.name: video_codec_format_mpeg4_mpeg4_0100
537  * @tc.desc: video format decoder-mpeg4 encoder-mpeg4
538  * @tc.type: FUNC
539  * @tc.require: issueI5OX06 issueI5P8N0
540  */
541 HWTEST_F(VCodecUnitTest, video_codec_format_mpeg4_mpeg4_0100, TestSize.Level0)
542 {
543     ASSERT_TRUE(CreateVideoCodecByMime("video/mp4v-es", "video/mp4v-es"));
544     std::shared_ptr<FormatMock> format = AVCodecMockFactory::CreateFormat();
545     ASSERT_NE(nullptr, format);
546     string width = "width";
547     string height = "height";
548     string pixelFormat = "pixel_format";
549     string frameRate = "frame_rate";
550     (void)format->PutIntValue(width.c_str(), DEFAULT_WIDTH);
551     (void)format->PutIntValue(height.c_str(), DEFAULT_HEIGHT);
552     (void)format->PutIntValue(pixelFormat.c_str(), NV12);
553     (void)format->PutIntValue(frameRate.c_str(), DEFAULT_FRAME_RATE);
554     videoDec_->SetSource(MPEG4_SRC_PATH, ES_MPEG4, ES_LENGTH_MPEG4);
555     ASSERT_EQ(MSERR_OK, videoDec_->Configure(format));
556     ASSERT_EQ(MSERR_OK, videoEnc_->Configure(format));
557     std::shared_ptr<SurfaceMock> surface = videoEnc_->GetInputSurface();
558     ASSERT_NE(nullptr, surface);
559     ASSERT_EQ(MSERR_OK, videoDec_->SetOutputSurface(surface));
560 
561     EXPECT_EQ(MSERR_OK, videoDec_->Prepare());
562     EXPECT_EQ(MSERR_OK, videoEnc_->Prepare());
563     EXPECT_EQ(MSERR_OK, videoDec_->Start());
564     EXPECT_EQ(MSERR_OK, videoEnc_->Start());
565     sleep(5); // start run 5s
566     EXPECT_EQ(MSERR_OK, videoDec_->Stop());
567     EXPECT_EQ(MSERR_OK, videoEnc_->Stop());
568     format->Destroy();
569 }