1 /*
2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 <iostream>
18 #include <thread>
19 #include <memory>
20 #include <string>
21 #include <chrono>
22 #include <fcntl.h>
23 #include <cstdlib>
24 #include <cstring>
25
26
27 #include "common/sharing_log.h"
28 #include "media_controller.h"
29 #include "media_channel.h"
30 #include "common/event_comm.h"
31 #include "common/media_log.h"
32 #include "media_channel_def.h"
33 #include "media_channel.h"
34 #include "video_play_controller.h"
35 #include "buffer_dispatcher.h"
36 #include "protocol/frame/h264_frame.h"
37 #include "extend/magic_enum/magic_enum.hpp"
38 #include "surface.h"
39 #include "surface_utils.h"
40 #include "transaction/rs_transaction.h"
41 #include "utils/utils.h"
42 #include "securec.h"
43 #include "window.h"
44 #include "window_option.h"
45 #include "ui/rs_surface_node.h"
46 #include "configuration/include/config.h"
47
48 using namespace testing::ext;
49 using namespace OHOS::Sharing;
50
51 namespace OHOS {
52 namespace Sharing {
53 class VideoPlayControllerTestBaseImpl
54 : public Singleton<VideoPlayControllerTestBaseImpl> {
55 private:
56 FILE *videoTestFp_;
57 std::string videoTestPath_ = "/data/mediaplayer_video_test.h264";
58 DataBuffer::Ptr videoTestData_;
59 MediaData::Ptr mediaData_;
60 size_t videoTestDataLen_;
61
62 VideoTrack videoTrack_;
63 BufferDispatcher::Ptr dispatcher_ = nullptr;
64 MediaController::Ptr mediaController_ = nullptr;
65 MediaChannel::Ptr mediaChannel_ = nullptr;
66
67 bool playbackRun_;
68 std::unique_ptr<std::thread> playbackThread_ = nullptr;
69
70 sptr<Rosen::WindowOption> windowOption_ = nullptr;
71 sptr<Rosen::Window> window_ = nullptr;
72 std::shared_ptr<Rosen::RSSurfaceNode> surfaceNode_ = nullptr;
73 sptr<Surface> surface_ = nullptr;
74 uint64_t surfaceId_ = 0;
75
76 bool isFirstKeyFrame_ = false;
77 size_t frameNums_ = 0;
78 std::chrono::steady_clock::time_point gopInterval_;
79 public:
GetVideoTestData(void)80 DataBuffer::Ptr& GetVideoTestData(void)
81 {
82 return videoTestData_;
83 }
84
GetVideoTestDataLength(void) const85 size_t GetVideoTestDataLength(void) const
86 {
87 return videoTestDataLen_;
88 }
89
GetSurface(void)90 sptr<Surface>& GetSurface(void)
91 {
92 return surface_;
93 }
94
GetBufferDispatcher(void)95 BufferDispatcher::Ptr& GetBufferDispatcher(void)
96 {
97 return dispatcher_;
98 }
99
GetVideoTrack(void)100 VideoTrack& GetVideoTrack(void)
101 {
102 return videoTrack_;
103 }
104
GetMediaController(void)105 MediaController::Ptr& GetMediaController(void)
106 {
107 return mediaController_;
108 }
109
GetId(void)110 uint32_t GetId(void)
111 {
112 return mediaChannel_->GetId();
113 }
114
VideoTrackReset(void)115 void VideoTrackReset(void)
116 {
117 videoTrack_.codecId = CodecId::CODEC_H264;
118 videoTrack_.width = defaultWidth;
119 videoTrack_.height = defaultHeight;
120 videoTrack_.frameRate = defaultFrameRate;
121 }
122
IsPlaybackRunning(void) const123 bool IsPlaybackRunning(void) const
124 {
125 return playbackRun_;
126 }
127
PlaybackStop(void)128 void PlaybackStop(void)
129 {
130 playbackRun_ = false;
131 playbackThread_->join();
132 playbackThread_ = nullptr;
133 }
134
BufferDispatcherReset(void)135 void BufferDispatcherReset(void)
136 {
137 if (dispatcher_ != nullptr) {
138 dispatcher_->StopDispatch();
139 dispatcher_->FlushBuffer();
140 dispatcher_->ReleaseAllReceiver();
141 }
142 }
VideoPlayerPlaybackStart(void)143 void VideoPlayerPlaybackStart(void)
144 {
145 EXPECT_EQ(nullptr, playbackThread_);
146 EXPECT_EQ(false, playbackRun_);
147 constexpr uint32_t waitForThread = 100;
148
149 playbackRun_ = true;
150 playbackThread_ = std::make_unique<std::thread>(
151 [this]() {
152 constexpr uint32_t interval = 20;
153 SHARING_LOGD("VideoPlayerPlayback test start\n");
154 while (IsPlaybackRunning()) {
155 SHARING_LOGD("VideoPlayerPlayback Writing\n");
156 VideoDataPlayOnce();
157 std::this_thread::sleep_for(std::chrono::milliseconds(interval));
158 }
159 SHARING_LOGD("VideoPlayerPlayback test complete\n");
160 }
161 );
162 pthread_setname_np(playbackThread_->native_handle(), "VideoPlayerPlayback");
163 std::this_thread::sleep_for(std::chrono::milliseconds(waitForThread));
164 }
165
SpsDataSetup(const char *buf, size_t len)166 void SpsDataSetup(const char *buf, size_t len)
167 {
168 auto sps = std::make_shared<MediaData>();
169 sps->buff = std::make_shared<DataBuffer>();
170 sps->mediaType = MEDIA_TYPE_VIDEO;
171 sps->buff->Assign(const_cast<char *>(buf), len);
172 dispatcher_->SetSpsNalu(sps);
173 }
174
PpsDataSetup(const char *buf, size_t len)175 void PpsDataSetup(const char *buf, size_t len)
176 {
177 auto pps = std::make_shared<MediaData>();
178 pps->buff = std::make_shared<DataBuffer>();
179 pps->mediaType = MEDIA_TYPE_VIDEO;
180 pps->buff->Assign(const_cast<char *>(buf), len);
181 dispatcher_->SetPpsNalu(pps);
182 }
183
MediaDataSetup(const char *buf, size_t len, size_t prefix)184 void MediaDataSetup(const char *buf, size_t len, size_t prefix)
185 {
186 auto mediaData = std::make_shared<MediaData>();
187 mediaData->buff = std::make_shared<DataBuffer>();
188 mediaData->mediaType = MEDIA_TYPE_VIDEO;
189 mediaData->isRaw = false;
190 mediaData->keyFrame = (*(buf + prefix) & 0x1f) == 0x05 ? true : false;
191 if (mediaData->keyFrame) {
192 if (isFirstKeyFrame_) {
193 MEDIA_LOGD("TEST STATISTICS Miracast:first, agent ID:%{public}d, get video frame.", GetId());
194 isFirstKeyFrame_ = false;
195 } else {
196 auto end = std::chrono::steady_clock::now();
197 std::chrono::duration<double, std::milli> diff = end - gopInterval_;
198 MEDIA_LOGD("TEST STATISTIC Miracast:interval:%{public}.0f ms, "
199 "agent ID:%{public}d, get video frame, gop:%{public}d, "
200 "average receiving frames time:%{public}.0f ms.",
201 diff.count(), GetId(), frameNums_, diff.count() / frameNums_);
202 }
203 frameNums_ = 0;
204 gopInterval_ = std::chrono::steady_clock::now();
205 }
206 ++frameNums_;
207 mediaData->buff->ReplaceData((char *)buf, len);
208 mediaData->pts = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
209 dispatcher_->InputData(mediaData);
210 }
211
VideoDataPlayOnce(void)212 void VideoDataPlayOnce(void)
213 {
214 SplitH264(reinterpret_cast<char *>(videoTestData_->Data()), videoTestData_->Size(), 0,
215 [&](const char *buf, size_t len, size_t prefix) {
216 if ((*(buf + prefix) & 0x1f) == 0x06) {
217 return;
218 }
219 if ((*(buf + prefix) & 0x1f) == 0x07) {
220 auto spsOld = dispatcher_->GetSPS();
221 if (spsOld != nullptr && spsOld->buff != nullptr) {
222 return;
223 }
224 SpsDataSetup(buf, len);
225 return;
226 }
227 if ((*(buf + prefix) & 0x1f) == 0x08) {
228 auto ppsOld = dispatcher_->GetPPS();
229 if (ppsOld != nullptr && ppsOld->buff != nullptr) {
230 return;
231 }
232 PpsDataSetup(buf, len);
233 return;
234 }
235 MediaDataSetup(buf, len, prefix);
236 });
237 }
238
239 private:
VideoTestDataLoad(void)240 void VideoTestDataLoad(void)
241 {
242 videoTestFp_ = ::fopen(videoTestPath_.c_str(), "r");
243 EXPECT_NE(nullptr, videoTestFp_);
244
245 bool ret = fseek(videoTestFp_, 0, SEEK_END);
246 EXPECT_EQ(false, ret < 0);
247
248 size_t fileLen = ftell(videoTestFp_);
249 EXPECT_EQ(false, fileLen < 0);
250
251 videoTestDataLen_ = fileLen + 1;
252 rewind(videoTestFp_);
253 char *videoTestDataTmp = new char[videoTestDataLen_];
254 EXPECT_NE(nullptr, videoTestDataTmp);
255
256 memset_s(videoTestDataTmp, videoTestDataLen_, 0, videoTestDataLen_);
257
258 ret = fread(videoTestDataTmp, 1, fileLen, videoTestFp_);
259 EXPECT_EQ(true, ret > 0);
260
261 ::fclose(videoTestFp_);
262 videoTestData_ = std::make_shared<DataBuffer>(videoTestDataLen_);
263 videoTestData_->Assign(videoTestDataTmp, fileLen);
264 videoTestFp_ = nullptr;
265 delete[] videoTestDataTmp;
266 }
267
VideoTestDataUnLoad(void)268 void VideoTestDataUnLoad(void)
269 {
270 if (nullptr != videoTestFp_) {
271 ::fclose(videoTestFp_);
272 videoTestFp_ = nullptr;
273 }
274 if (nullptr != videoTestData_) {
275 videoTestData_ = nullptr;
276 }
277 videoTestDataLen_ = 0;
278 }
279
InitWindow(void)280 void InitWindow(void)
281 {
282 EXPECT_EQ(nullptr, windowOption_);
283 EXPECT_EQ(nullptr, window_);
284 EXPECT_EQ(nullptr, surfaceNode_);
285 EXPECT_EQ(nullptr, surface_);
286
287 windowOption_ = new Rosen::WindowOption();
288 windowOption_->SetWindowRect({
289 defaultPositionX,
290 defaultPositionY,
291 defaultWidth,
292 defaultHeight});
293 windowOption_->SetWindowType(
294 Rosen::WindowType::WINDOW_TYPE_APP_LAUNCHING);
295 windowOption_->SetWindowMode(
296 Rosen::WindowMode::WINDOW_MODE_FULLSCREEN);
297 window_ = Rosen::Window::Create(
298 "Video Controller Test Window",
299 windowOption_);
300
301 surfaceNode_ = window_->GetSurfaceNode();
302 surfaceNode_->SetFrameGravity(Rosen::Gravity::RESIZE);
303 Rosen::RSTransaction::FlushImplicitTransaction();
304
305 surface_ = surfaceNode_->GetSurface();
306 window_->SetRequestedOrientation(Rosen::Orientation::HORIZONTAL);
307 window_->Show();
308 surfaceId_ = surface_->GetUniqueId();
309
310 int32_t ret = SurfaceUtils::GetInstance()->Add(surfaceId_, surface_);
311 EXPECT_EQ(ret, 0);
312 }
313 public:
VideoPlayControllerTestBaseImpl()314 VideoPlayControllerTestBaseImpl()
315 {
316 Config::GetInstance().Init();
317 mediaChannel_ = std::make_shared<MediaChannel>();
318 mediaController_ = std::make_shared<MediaController>(mediaChannel_->GetId());
319 mediaController_->SetMediaChannel(mediaChannel_);
320 dispatcher_ = std::make_shared<BufferDispatcher>(maxBufferCapacity, maxBufferCapacityIncrement);
321 VideoTestDataLoad();
322 VideoTrackReset();
323 InitWindow();
324 }
325
326 ~VideoPlayControllerTestBaseImpl() override
327 {
328 PlaybackStop();
329 VideoTestDataUnLoad();
330 BufferDispatcherReset();
331 }
332
333 public:
334 static constexpr int32_t maxBufferCapacity = ::MAX_BUFFER_CAPACITY;
335 static constexpr int32_t maxBufferCapacityIncrement = ::BUFFER_CAPACITY_INCREMENT;
336 static constexpr int32_t stabilityLoops = 100;
337 static constexpr int32_t defaultPositionX = 0;
338 static constexpr int32_t defaultPositionY = 0;
339 static constexpr int32_t defaultHeight = 720;
340 static constexpr int32_t defaultWidth = 1280;
341 static constexpr int32_t defaultFrameRate = 30;
342 };
343
344 class VideoPlayControllerUnitTest : public testing::Test {};
345
346 namespace {
347 VideoPlayControllerTestBaseImpl& g_testBase =
348 VideoPlayControllerTestBaseImpl::GetInstance();
349
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Create_01, Function | SmallTest | Level2)350 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Create_01,
351 Function | SmallTest | Level2)
352 {
353 SHARING_LOGD("trace");
354 std::shared_ptr<ContextEventMsg> cem = std::make_shared<ContextEventMsg>();
355 std::unique_ptr<VideoPlayController> videoPlayController =
356 std::make_unique<VideoPlayController>(g_testBase.GetId());
357 EXPECT_NE(nullptr, videoPlayController);
358 }
359
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_SetKeyMode_01, Function | SmallTest | Level2)360 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_SetKeyMode_01,
361 Function | SmallTest | Level2)
362 {
363 SHARING_LOGD("trace");
364 int32_t ret = -1;
365 std::unique_ptr<VideoPlayController> videoPlayController =
366 std::make_unique<VideoPlayController>(g_testBase.GetId());
367 EXPECT_NE(nullptr, videoPlayController);
368
369 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
370 EXPECT_EQ(ret, true);
371
372 ret = videoPlayController->Start(g_testBase.GetBufferDispatcher());
373 EXPECT_EQ(ret, true);
374 videoPlayController->SetKeyMode(true);
375 }
376
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_SetKeyRedirect_01, Function | SmallTest | Level2)377 HWTEST_F(VideoPlayControllerUnitTest,
378 Video_Play_Controller_Test_SetKeyRedirect_01,
379 Function | SmallTest | Level2)
380 {
381 SHARING_LOGD("trace");
382 std::unique_ptr<VideoPlayController> videoPlayController =
383 std::make_unique<VideoPlayController>(g_testBase.GetId());
384 EXPECT_NE(nullptr, videoPlayController);
385
386 videoPlayController->SetKeyMode(true);
387 }
388
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_SetMediaController_01, Function | SmallTest | Level2)389 HWTEST_F(VideoPlayControllerUnitTest,
390 Video_Play_Controller_Test_SetMediaController_01,
391 Function | SmallTest | Level2)
392 {
393 SHARING_LOGD("trace");
394 std::unique_ptr<VideoPlayController> videoPlayController =
395 std::make_unique<VideoPlayController>(g_testBase.GetId());
396 EXPECT_NE(nullptr, videoPlayController);
397
398 videoPlayController->SetMediaController(g_testBase.GetMediaController());
399 }
400
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Init_01, Function | SmallTest | Level2)401 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Init_01,
402 Function | SmallTest | Level2)
403 {
404 SHARING_LOGD("trace");
405 bool ret = true;
406 std::unique_ptr<VideoPlayController> videoPlayController =
407 std::make_unique<VideoPlayController>(g_testBase.GetId());
408 EXPECT_NE(nullptr, videoPlayController);
409
410 g_testBase.GetVideoTrack().codecId = CodecId::CODEC_PCM;
411 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
412 EXPECT_EQ(ret, false);
413
414 g_testBase.VideoTrackReset();
415 }
416
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Init_02, Function | SmallTest | Level2)417 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Init_02,
418 Function | SmallTest | Level2)
419 {
420 SHARING_LOGD("trace");
421 bool ret = true;
422 std::unique_ptr<VideoPlayController> videoPlayController =
423 std::make_unique<VideoPlayController>(g_testBase.GetId());
424 EXPECT_NE(nullptr, videoPlayController);
425
426 g_testBase.GetVideoTrack().codecId = CodecId::CODEC_DEFAULT;
427 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
428 EXPECT_EQ(ret, false);
429
430 g_testBase.VideoTrackReset();
431 }
432
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Init_03, Function | SmallTest | Level2)433 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Init_03,
434 Function | SmallTest | Level2)
435 {
436 SHARING_LOGD("trace");
437 bool ret = true;
438 std::unique_ptr<VideoPlayController> videoPlayController =
439 std::make_unique<VideoPlayController>(g_testBase.GetId());
440 EXPECT_NE(nullptr, videoPlayController);
441
442 g_testBase.GetVideoTrack().codecId = CodecId::CODEC_H264;
443 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
444 EXPECT_EQ(ret, true);
445
446 g_testBase.VideoTrackReset();
447 }
448
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Init_04, Function | SmallTest | Level2)449 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Init_04,
450 Function | SmallTest | Level2)
451 {
452 SHARING_LOGD("trace");
453 bool ret = true;
454 std::unique_ptr<VideoPlayController> videoPlayController =
455 std::make_unique<VideoPlayController>(g_testBase.GetId());
456 EXPECT_NE(nullptr, videoPlayController);
457
458 g_testBase.GetVideoTrack().codecId = CodecId::CODEC_H265;
459 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
460 EXPECT_EQ(ret, true);
461
462 g_testBase.VideoTrackReset();
463 }
464
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Init_05, Function | SmallTest | Level2)465 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Init_05,
466 Function | SmallTest | Level2)
467 {
468 SHARING_LOGD("trace");
469 bool ret = true;
470 std::unique_ptr<VideoPlayController> videoPlayController =
471 std::make_unique<VideoPlayController>(g_testBase.GetId());
472 EXPECT_NE(nullptr, videoPlayController);
473
474 g_testBase.GetVideoTrack().codecId = CodecId::CODEC_VP8;
475 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
476 EXPECT_EQ(ret, false);
477
478 g_testBase.VideoTrackReset();
479 }
480
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Init_06, Function | SmallTest | Level2)481 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Init_06,
482 Function | SmallTest | Level2)
483 {
484 SHARING_LOGD("trace");
485 bool ret = true;
486 std::unique_ptr<VideoPlayController> videoPlayController =
487 std::make_unique<VideoPlayController>(g_testBase.GetId());
488 EXPECT_NE(nullptr, videoPlayController);
489
490 g_testBase.GetVideoTrack().codecId = CodecId::CODEC_VP9;
491 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
492 EXPECT_EQ(ret, false);
493
494 g_testBase.VideoTrackReset();
495 }
496
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Init_07, Function | SmallTest | Level2)497 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Init_07,
498 Function | SmallTest | Level2)
499 {
500 SHARING_LOGD("trace");
501 bool ret = true;
502 std::unique_ptr<VideoPlayController> videoPlayController =
503 std::make_unique<VideoPlayController>(g_testBase.GetId());
504 EXPECT_NE(nullptr, videoPlayController);
505
506 g_testBase.GetVideoTrack().codecId = CodecId::CODEC_AV1;
507 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
508 EXPECT_EQ(ret, true);
509
510 g_testBase.VideoTrackReset();
511 }
512
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Init_08, Function | SmallTest | Level2)513 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Init_08,
514 Function | SmallTest | Level2)
515 {
516 SHARING_LOGD("trace");
517 bool ret = true;
518 std::unique_ptr<VideoPlayController> videoPlayController =
519 std::make_unique<VideoPlayController>(g_testBase.GetId());
520 EXPECT_NE(nullptr, videoPlayController);
521
522 g_testBase.GetVideoTrack().codecId = CodecId::CODEC_AAC;
523 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
524 EXPECT_EQ(ret, false);
525
526 g_testBase.VideoTrackReset();
527 }
528
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Init_09, Function | SmallTest | Level2)529 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Init_09,
530 Function | SmallTest | Level2)
531 {
532 SHARING_LOGD("trace");
533 bool ret = true;
534 std::unique_ptr<VideoPlayController> videoPlayController =
535 std::make_unique<VideoPlayController>(g_testBase.GetId());
536 EXPECT_NE(nullptr, videoPlayController);
537
538 g_testBase.GetVideoTrack().codecId = CodecId::CODEC_G711A;
539 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
540 EXPECT_EQ(ret, false);
541
542 g_testBase.VideoTrackReset();
543 }
544
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Init_10, Function | SmallTest | Level2)545 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Init_10,
546 Function | SmallTest | Level2)
547 {
548 SHARING_LOGD("trace");
549 bool ret = true;
550 std::unique_ptr<VideoPlayController> videoPlayController =
551 std::make_unique<VideoPlayController>(g_testBase.GetId());
552 EXPECT_NE(nullptr, videoPlayController);
553
554 g_testBase.GetVideoTrack().codecId = CodecId::CODEC_G711U;
555 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
556 EXPECT_EQ(ret, false);
557
558 g_testBase.VideoTrackReset();
559 }
560
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Init_11, Function | SmallTest | Level2)561 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Init_11,
562 Function | SmallTest | Level2)
563 {
564 SHARING_LOGD("trace");
565 bool ret = true;
566 std::unique_ptr<VideoPlayController> videoPlayController =
567 std::make_unique<VideoPlayController>(g_testBase.GetId());
568 EXPECT_NE(nullptr, videoPlayController);
569
570 g_testBase.GetVideoTrack().codecId = CodecId::CODEC_OPUS;
571 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
572 EXPECT_EQ(ret, false);
573
574 g_testBase.VideoTrackReset();
575 }
576
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Init_12, Function | SmallTest | Level2)577 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Init_12,
578 Function | SmallTest | Level2)
579 {
580 SHARING_LOGD("trace");
581 bool ret = true;
582 std::unique_ptr<VideoPlayController> videoPlayController =
583 std::make_unique<VideoPlayController>(g_testBase.GetId());
584 EXPECT_NE(nullptr, videoPlayController);
585
586 g_testBase.GetVideoTrack().codecId = CodecId::CODEC_L16;
587 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
588 EXPECT_EQ(ret, false);
589
590 g_testBase.VideoTrackReset();
591 }
592
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Play_01, Function | SmallTest | Level2)593 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Play_01, Function | SmallTest | Level2)
594 {
595 SHARING_LOGD("trace");
596 bool ret = true;
597 std::unique_ptr<VideoPlayController> videoPlayController =
598 std::make_unique<VideoPlayController>(g_testBase.GetId());
599 EXPECT_NE(nullptr, videoPlayController);
600
601 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
602 EXPECT_EQ(ret, true);
603
604 ret = videoPlayController->Start(g_testBase.GetBufferDispatcher());
605 EXPECT_EQ(ret, true);
606
607 ret = videoPlayController->SetSurface(g_testBase.GetSurface());
608 EXPECT_EQ(ret, true);
609
610 g_testBase.VideoDataPlayOnce();
611 videoPlayController->Stop(g_testBase.GetBufferDispatcher());
612 }
613
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Start_01, Function | SmallTest | Level2)614 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Start_01, Function | SmallTest | Level2)
615 {
616 SHARING_LOGD("trace");
617 bool ret = true;
618 std::unique_ptr<VideoPlayController> videoPlayController =
619 std::make_unique<VideoPlayController>(g_testBase.GetId());
620 EXPECT_NE(nullptr, videoPlayController);
621
622 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
623 EXPECT_EQ(ret, true);
624
625 ret = videoPlayController->Start(g_testBase.GetBufferDispatcher());
626 EXPECT_EQ(ret, true);
627 }
628
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Start_02, Function | SmallTest | Level2)629 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Start_02, Function | SmallTest | Level2)
630 {
631 SHARING_LOGD("trace");
632 bool ret = true;
633 std::unique_ptr<VideoPlayController> videoPlayController =
634 std::make_unique<VideoPlayController>(g_testBase.GetId());
635 EXPECT_NE(nullptr, videoPlayController);
636
637 ret = videoPlayController->Start(g_testBase.GetBufferDispatcher());
638 EXPECT_EQ(ret, false);
639 }
640
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Start_03, Function | SmallTest | Level2)641 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Start_03, Function | SmallTest | Level2)
642 {
643 SHARING_LOGD("trace");
644 bool ret = true;
645 std::unique_ptr<VideoPlayController> videoPlayController =
646 std::make_unique<VideoPlayController>(g_testBase.GetId());
647 EXPECT_NE(nullptr, videoPlayController);
648
649 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
650 EXPECT_EQ(ret, true);
651
652 videoPlayController->Release();
653 ret = videoPlayController->Start(g_testBase.GetBufferDispatcher());
654 EXPECT_EQ(ret, false);
655 }
656
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Start_04, Function | SmallTest | Level2)657 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Start_04, Function | SmallTest | Level2)
658 {
659 SHARING_LOGD("trace");
660 bool ret = true;
661 std::unique_ptr<VideoPlayController> videoPlayController =
662 std::make_unique<VideoPlayController>(g_testBase.GetId());
663 EXPECT_NE(nullptr, videoPlayController);
664
665 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
666 EXPECT_EQ(ret, true);
667
668 ret = videoPlayController->Start(g_testBase.GetBufferDispatcher());
669 EXPECT_EQ(ret, true);
670
671 videoPlayController->Stop(g_testBase.GetBufferDispatcher());
672 ret = videoPlayController->Start(g_testBase.GetBufferDispatcher());
673 EXPECT_EQ(ret, true);
674 }
675
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Start_05, Function | SmallTest | Level2)676 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Start_05, Function | SmallTest | Level2)
677 {
678 SHARING_LOGD("trace");
679 bool ret = true;
680 std::unique_ptr<VideoPlayController> videoPlayController =
681 std::make_unique<VideoPlayController>(g_testBase.GetId());
682 EXPECT_NE(nullptr, videoPlayController);
683
684 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
685 EXPECT_EQ(ret, true);
686
687 ret = videoPlayController->Start(g_testBase.GetBufferDispatcher());
688 EXPECT_EQ(ret, true);
689
690 ret = videoPlayController->Start(g_testBase.GetBufferDispatcher());
691 EXPECT_EQ(ret, true);
692
693 videoPlayController->Stop(g_testBase.GetBufferDispatcher());
694 }
695
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_SetSurface_01, Function | SmallTest | Level2)696 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_SetSurface_01, Function | SmallTest | Level2)
697 {
698 SHARING_LOGD("trace");
699 bool ret = true;
700 std::unique_ptr<VideoPlayController> videoPlayController =
701 std::make_unique<VideoPlayController>(g_testBase.GetId());
702 EXPECT_NE(nullptr, videoPlayController);
703
704 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
705 EXPECT_EQ(ret, true);
706
707 ret = videoPlayController->SetSurface(g_testBase.GetSurface());
708 EXPECT_EQ(ret, true);
709 }
710
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_SetSurface_02, Function | SmallTest | Level2)711 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_SetSurface_02, Function | SmallTest | Level2)
712 {
713 SHARING_LOGD("trace");
714 bool ret = true;
715 std::unique_ptr<VideoPlayController> videoPlayController =
716 std::make_unique<VideoPlayController>(g_testBase.GetId());
717 EXPECT_NE(nullptr, videoPlayController);
718
719 ret = videoPlayController->SetSurface(g_testBase.GetSurface());
720 EXPECT_EQ(ret, false);
721 }
722
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_SetSurface_03, Function | SmallTest | Level2)723 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_SetSurface_03, Function | SmallTest | Level2)
724 {
725 SHARING_LOGD("trace");
726 bool ret = true;
727 std::unique_ptr<VideoPlayController> videoPlayController =
728 std::make_unique<VideoPlayController>(g_testBase.GetId());
729 EXPECT_NE(nullptr, videoPlayController);
730
731 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
732 EXPECT_EQ(ret, true);
733
734 ret = videoPlayController->SetSurface(g_testBase.GetSurface());
735 EXPECT_EQ(ret, true);
736
737 ret = videoPlayController->Start(g_testBase.GetBufferDispatcher());
738 EXPECT_EQ(ret, true);
739
740 ret = videoPlayController->SetSurface(g_testBase.GetSurface());
741 EXPECT_EQ(ret, false);
742
743 videoPlayController->Stop(g_testBase.GetBufferDispatcher());
744 }
745
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_OnAccelerationDoneNotify_01, Function | SmallTest | Level2)746 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_OnAccelerationDoneNotify_01,
747 Function | SmallTest | Level2)
748 {
749 SHARING_LOGD("trace");
750 bool ret = true;
751 std::unique_ptr<VideoPlayController> videoPlayController =
752 std::make_unique<VideoPlayController>(g_testBase.GetId());
753 EXPECT_NE(nullptr, videoPlayController);
754
755 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
756 EXPECT_EQ(ret, true);
757
758 ret = videoPlayController->SetSurface(g_testBase.GetSurface());
759 EXPECT_EQ(ret, true);
760
761 videoPlayController->OnAccelerationDoneNotify();
762 }
763
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_OnKeyModeNotify_01, Function | SmallTest | Level2)764 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_OnKeyModeNotify_01, Function | SmallTest | Level2)
765 {
766 SHARING_LOGD("trace");
767 bool ret = true;
768 std::unique_ptr<VideoPlayController> videoPlayController =
769 std::make_unique<VideoPlayController>(g_testBase.GetId());
770 EXPECT_NE(nullptr, videoPlayController);
771
772 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
773 EXPECT_EQ(ret, true);
774
775 ret = videoPlayController->SetSurface(g_testBase.GetSurface());
776 EXPECT_EQ(ret, true);
777
778 videoPlayController->OnKeyModeNotify(true);
779 }
780
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_OnKeyModeNotify_02, Function | SmallTest | Level2)781 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_OnKeyModeNotify_02, Function | SmallTest | Level2)
782 {
783 SHARING_LOGD("trace");
784 bool ret = true;
785 std::unique_ptr<VideoPlayController> videoPlayController =
786 std::make_unique<VideoPlayController>(g_testBase.GetId());
787 EXPECT_NE(nullptr, videoPlayController);
788
789 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
790 EXPECT_EQ(ret, true);
791
792 ret = videoPlayController->SetSurface(g_testBase.GetSurface());
793 EXPECT_EQ(ret, true);
794
795 videoPlayController->OnKeyModeNotify(false);
796 }
797
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Stop_01, Function | SmallTest | Level2)798 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Stop_01, Function | SmallTest | Level2)
799 {
800 SHARING_LOGD("trace");
801 bool ret = true;
802 std::unique_ptr<VideoPlayController> videoPlayController =
803 std::make_unique<VideoPlayController>(g_testBase.GetId());
804 EXPECT_NE(nullptr, videoPlayController);
805
806 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
807 EXPECT_EQ(ret, true);
808
809 ret = videoPlayController->Start(g_testBase.GetBufferDispatcher());
810 EXPECT_EQ(ret, true);
811
812 videoPlayController->Stop(g_testBase.GetBufferDispatcher());
813 }
814
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Stop_02, Function | SmallTest | Level2)815 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Stop_02, Function | SmallTest | Level2)
816 {
817 SHARING_LOGD("trace");
818 bool ret = true;
819 std::unique_ptr<VideoPlayController> videoPlayController =
820 std::make_unique<VideoPlayController>(g_testBase.GetId());
821 EXPECT_NE(nullptr, videoPlayController);
822
823 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
824 EXPECT_EQ(ret, true);
825
826 videoPlayController->Stop(g_testBase.GetBufferDispatcher());
827 }
828
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Stop_03, Function | SmallTest | Level2)829 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Stop_03, Function | SmallTest | Level2)
830 {
831 SHARING_LOGD("trace");
832 std::unique_ptr<VideoPlayController> videoPlayController =
833 std::make_unique<VideoPlayController>(g_testBase.GetId());
834 EXPECT_NE(nullptr, videoPlayController);
835
836 videoPlayController->Stop(g_testBase.GetBufferDispatcher());
837 }
838
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Stop_04, Function | SmallTest | Level2)839 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Stop_04, Function | SmallTest | Level2)
840 {
841 SHARING_LOGD("trace");
842 bool ret = true;
843 std::unique_ptr<VideoPlayController> videoPlayController =
844 std::make_unique<VideoPlayController>(g_testBase.GetId());
845 EXPECT_NE(nullptr, videoPlayController);
846
847 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
848 EXPECT_EQ(ret, true);
849
850 videoPlayController->Release();
851
852 videoPlayController->Stop(g_testBase.GetBufferDispatcher());
853 }
854
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Stop_05, Function | SmallTest | Level2)855 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Stop_05, Function | SmallTest | Level2)
856 {
857 SHARING_LOGD("trace");
858 bool ret = true;
859 std::unique_ptr<VideoPlayController> videoPlayController =
860 std::make_unique<VideoPlayController>(g_testBase.GetId());
861 EXPECT_NE(nullptr, videoPlayController);
862
863 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
864 EXPECT_EQ(ret, true);
865
866 ret = videoPlayController->Start(g_testBase.GetBufferDispatcher());
867 EXPECT_EQ(ret, true);
868
869 videoPlayController->Stop(g_testBase.GetBufferDispatcher());
870 ret = videoPlayController->Start(g_testBase.GetBufferDispatcher());
871 EXPECT_EQ(ret, true);
872
873 videoPlayController->Stop(g_testBase.GetBufferDispatcher());
874 }
875
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Release_01, Function | SmallTest | Level2)876 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Release_01, Function | SmallTest | Level2)
877 {
878 SHARING_LOGD("trace");
879 bool ret = true;
880 std::unique_ptr<VideoPlayController> videoPlayController =
881 std::make_unique<VideoPlayController>(g_testBase.GetId());
882 EXPECT_NE(nullptr, videoPlayController);
883
884 ret = videoPlayController->Init(g_testBase.GetVideoTrack());
885 EXPECT_EQ(ret, true);
886
887 videoPlayController->Release();
888 }
889
HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Release_02, Function | SmallTest | Level2)890 HWTEST_F(VideoPlayControllerUnitTest, Video_Play_Controller_Test_Release_02, Function | SmallTest | Level2)
891 {
892 SHARING_LOGD("trace");
893 std::unique_ptr<VideoPlayController> videoPlayController =
894 std::make_unique<VideoPlayController>(g_testBase.GetId());
895 EXPECT_NE(nullptr, videoPlayController);
896
897 videoPlayController->Release();
898 }
899
900 } // namespace
901 } // namespace Sharing
902 } // namespace OHOS