• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <chrono>
16 #include <fcntl.h>
17 #ifndef WIN32
18 #include <sys/types.h>
19 #include <unistd.h>
20 #define O_BINARY 0 // which is not defined for Linux
21 #endif
22 #include <math.h>
23 #include <thread>
24 #include "foundation/log.h"
25 #include "helper/test_player.hpp"
26 #include "testngpp/testngpp.hpp"
27 #include "test_single_video_player_fast_1.h"
28 
29 using namespace OHOS::Media::Test;
30 
31 // @fixture(tags=video_play_fast)
FIXTURE(dataDrivenSingleVideoPlayerTestFast3)32 FIXTURE(dataDrivenSingleVideoPlayerTestFast3)
33 {
34     DATA_PROVIDER(myfdurl, 2,
35                   DATA_GROUP(std::string(RESOURCE_DIR "/MP4/H264_AAC.mp4"), 1894335),
36                   DATA_GROUP(std::string(RESOURCE_DIR "/../demo_resource/video/1h264_320x240_60.3gp"), 494522));
37     static const int64_t NEXT_FRAME_TIME {8300};
38     static const int64_t PREV_FRAME_TIME {4166};
39     std::string FilePathToFd(std::string url, int32_t fileSize)
40     {
41         std::string uri = "fd://?offset=0&size=";
42         uri += std::to_string(fileSize);
43         int32_t fd = open(url.c_str(), O_RDONLY|O_BINARY);
44         std::string fdStr = std::to_string(fd);
45         uri.insert(5, fdStr); // 5 ---fd:://
46         return uri;
47     }
48     bool CheckTimeEquality(int32_t expectValue, int32_t currentValue)
49     {
50         MEDIA_LOG_I("expectValue : %d, currentValue : %d", expectValue, currentValue);
51         return fabs(expectValue - currentValue) < 100; // if open debug log, should use value >= 1000
52     }
53     //  SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_RELEASE_CALLBACK_0100
54     // @test(data="myfdurl", tags=video_play_fast)
55     PTEST((std::string url, int32_t fileSize), Test fdsource create, reset)
56     {
57         std::string uri = FilePathToFd(url, fileSize);
58         std::unique_ptr<TestPlayer> player = TestPlayer::Create();
59         ASSERT_EQ(0, player->Release());
60     }
61 
62     // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_RELEASE_CALLBACK_0200
63     // @test(data="myfdurl", tags=video_play_fast)
64     PTEST((std::string url, int32_t fileSize), Test fdsource prepare, release)
65     {
66         std::string uri = FilePathToFd(url, fileSize);
67         std::unique_ptr<TestPlayer> player = TestPlayer::Create();
68         ASSERT_EQ(0, player->SetSource(TestSource(uri)));
69         ASSERT_EQ(0, player->Prepare());
70         ASSERT_EQ(0, player->Release());
71     }
72 
73     // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_RELEASE_CALLBACK_0300
74     // @test(data="myfdurl", tags=video_play_fast)
75     PTEST((std::string url, int32_t fileSize), Test fdsource prepare, play, release)
76     {
77         std::string uri = FilePathToFd(url, fileSize);
78         std::unique_ptr<TestPlayer> player = TestPlayer::Create();
79         ASSERT_EQ(0, player->SetSource(TestSource(uri)));
80         ASSERT_EQ(0, player->Prepare());
81         ASSERT_EQ(0, player->Play());
82         std::this_thread::sleep_for(std::chrono::milliseconds(5000));
83         ASSERT_EQ(0, player->Release());
84     }
85 
86     // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_RELEASE_CALLBACK_0400
87     // @test(data="myfdurl", tags=video_play_fast)
88     PTEST((std::string url, int32_t fileSize), Test fdsource prepare, play, pause, release)
89     {
90         std::string uri = FilePathToFd(url, fileSize);
91         std::unique_ptr<TestPlayer> player = TestPlayer::Create();
92         ASSERT_EQ(0, player->SetSource(TestSource(uri)));
93         ASSERT_EQ(0, player->Prepare());
94         ASSERT_EQ(0, player->Play());
95         std::this_thread::sleep_for(std::chrono::milliseconds(5000));
96         ASSERT_EQ(0, player->Pause());
97         ASSERT_EQ(0, player->Release());
98     }
99 
100     // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_RELEASE_CALLBACK_0500
101     // @test(data="myfdurl", tags=video_play_fast)
102     PTEST((std::string url, int32_t fileSize), Test fdsource prepare, play, stop, release)
103     {
104         std::string uri = FilePathToFd(url, fileSize);
105         std::unique_ptr<TestPlayer> player = TestPlayer::Create();
106         ASSERT_EQ(0, player->SetSource(TestSource(uri)));
107         ASSERT_EQ(0, player->Prepare());
108         ASSERT_EQ(0, player->Play());
109         std::this_thread::sleep_for(std::chrono::milliseconds(5000));
110         ASSERT_EQ(0, player->Stop());
111         ASSERT_EQ(0, player->Release());
112     }
113 
114     // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_RELEASE_CALLBACK_0700
115     // @test(data="myfdurl", tags=video_play_fast)
116     PTEST((std::string url, int32_t fileSize), Test fdsource prepare, play, seek, release, 700)
117     {
118         int64_t seekPos {5000};
119         int64_t currentMS {0};
120         std::string uri = FilePathToFd(url, fileSize);
121         std::unique_ptr<TestPlayer> player = TestPlayer::Create();
122         ASSERT_EQ(0, player->SetSource(TestSource(uri)));
123         ASSERT_EQ(0, player->Prepare());
124         ASSERT_EQ(0, player->Play());
125         ASSERT_TRUE(player->IsPlaying());
126         std::this_thread::sleep_for(std::chrono::milliseconds(3000));
127         ASSERT_EQ(0, player->Seek(seekPos, OHOS::Media::PlayerSeekMode::SEEK_NEXT_SYNC));
128         ASSERT_EQ(0, player->GetCurrentTime(currentMS));
129         EXPECT_TRUE(CheckTimeEquality(NEXT_FRAME_TIME, currentMS));
130         ASSERT_EQ(0, player->Release());
131     }
132 
133     // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_RELEASE_CALLBACK_0800
134     // @test(data="myfdurl", tags=video_play_fast)
135     PTEST((std::string url, int32_t fileSize), Test fdsource prepare, play, setvolume, release)
136     {
137         float leftVolume {1};
138         float rightVolume {1};
139         std::string uri = FilePathToFd(url, fileSize);
140         std::unique_ptr<TestPlayer> player = TestPlayer::Create();
141         ASSERT_EQ(0, player->SetSource(TestSource(uri)));
142         ASSERT_EQ(0, player->Prepare());
143         ASSERT_EQ(0, player->Play());
144         ASSERT_EQ(0, player->SetVolume(leftVolume, rightVolume));
145         ASSERT_EQ(0, player->Release());
146     }
147 
148     // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_RELEASE_CALLBACK_1000
149     // @test(data="myfdurl", tags=video_play_fast)
150     PTEST((std::string url, int32_t fileSize), Test fdsource setSource, release)
151     {
152         std::string uri = FilePathToFd(url, fileSize);
153         std::unique_ptr<TestPlayer> player = TestPlayer::Create();
154         ASSERT_EQ(0, player->SetSource(TestSource(uri)));
155         ASSERT_EQ(0, player->Release());
156     }
157 
158     // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_RELEASE_CALLBACK_1200
159     // @test(data="myfdurl", tags=video_play_fast)
160     PTEST((std::string url, int32_t fileSize), Test fdsource prepare, reset, release)
161     {
162         std::string uri = FilePathToFd(url, fileSize);
163         std::unique_ptr<TestPlayer> player = TestPlayer::Create();
164         ASSERT_EQ(0, player->SetSource(TestSource(uri)));
165         ASSERT_EQ(0, player->Prepare());
166         ASSERT_EQ(0, player->Reset());
167         ASSERT_EQ(0, player->Release());
168     }
169 
170     // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_SEEK_CALLBACK_0100
171     // @test(data="myfdurl", tags=video_play_fast)
172     PTEST((std::string url, int32_t fileSize), Test fdsource create, seek, release)
173     {
174         int64_t seekPos {5000};
175         int64_t currentMS {0};
176         std::string uri = FilePathToFd(url, fileSize);
177         std::unique_ptr<TestPlayer> player = TestPlayer::Create();
178         ASSERT_NE(0, player->Seek(seekPos));
179         ASSERT_EQ(0, player->GetCurrentTime(currentMS));
180         ASSERT_EQ(0, player->Release());
181     }
182 
183     // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_SEEK_CALLBACK_0200
184     // @test(data="myfdurl", tags=video_play_fast)
185     PTEST((std::string url, int32_t fileSize), Test fdsource prepare, seek, release)
186     {
187         int64_t seekPos {5000};
188         int64_t currentMS {0};
189         std::string uri = FilePathToFd(url, fileSize);
190         std::unique_ptr<TestPlayer> player = TestPlayer::Create();
191         ASSERT_EQ(0, player->SetSource(TestSource(uri)));
192         ASSERT_EQ(0, player->Prepare());
193         ASSERT_EQ(0, player->Seek(seekPos));
194         ASSERT_EQ(0, player->GetCurrentTime(currentMS));
195         EXPECT_TRUE(CheckTimeEquality(NEXT_FRAME_TIME, currentMS));
196         ASSERT_EQ(0, player->Release());
197     }
198 
199     // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_SEEK_CALLBACK_0300
200     // @test(data="myfdurl", tags=video_play_fast)
201     PTEST((std::string url, int32_t fileSize), Test fdsource prepare, play, seek, release, 300)
202     {
203         int64_t seekPos {5000};
204         int64_t currentMS {0};
205         std::string uri = FilePathToFd(url, fileSize);
206         std::unique_ptr<TestPlayer> player = TestPlayer::Create();
207         ASSERT_EQ(0, player->SetSource(TestSource(uri)));
208         ASSERT_EQ(0, player->Prepare());
209         ASSERT_EQ(0, player->Play());
210         ASSERT_TRUE(player->IsPlaying());
211         std::this_thread::sleep_for(std::chrono::milliseconds(3000));
212         ASSERT_EQ(0, player->Seek(seekPos, OHOS::Media::PlayerSeekMode::SEEK_NEXT_SYNC));
213         ASSERT_EQ(0, player->GetCurrentTime(currentMS));
214         EXPECT_TRUE(CheckTimeEquality(NEXT_FRAME_TIME, currentMS));
215         ASSERT_EQ(0, player->Release());
216     }
217 
218     // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_SEEK_CALLBACK_0400
219     // @test(data="myfdurl", tags=video_play_fast)
220     PTEST((std::string url, int32_t fileSize), Test fdsource prepare, play, pause, seek, release)
221     {
222         int64_t seekPos {5000};
223         int64_t currentMS {0};
224         std::string uri = FilePathToFd(url, fileSize);
225         std::unique_ptr<TestPlayer> player = TestPlayer::Create();
226         ASSERT_EQ(0, player->SetSource(TestSource(uri)));
227         ASSERT_EQ(0, player->Prepare());
228         ASSERT_EQ(0, player->Play());
229         ASSERT_TRUE(player->IsPlaying());
230         std::this_thread::sleep_for(std::chrono::milliseconds(3000));
231         ASSERT_EQ(0, player->Pause());
232         ASSERT_EQ(0, player->Seek(seekPos));
233         ASSERT_EQ(0, player->GetCurrentTime(currentMS));
234         EXPECT_TRUE(CheckTimeEquality(NEXT_FRAME_TIME, currentMS));
235         ASSERT_EQ(0, player->Release());
236     }
237 
238     //  SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_SEEK_CALLBACK_0500
239     // @test(data="myfdurl", tags=video_play_fast)
240     PTEST((std::string url, int32_t fileSize), Test fdsource prepare, play, stop, seek, release)
241     {
242         int64_t seekPos {5000};
243         int64_t currentMS {0};
244         std::string uri = FilePathToFd(url, fileSize);
245         std::unique_ptr<TestPlayer> player = TestPlayer::Create();
246         ASSERT_EQ(0, player->SetSource(TestSource(uri)));
247         ASSERT_EQ(0, player->Prepare());
248         ASSERT_EQ(0, player->Play());
249         ASSERT_TRUE(player->IsPlaying());
250         std::this_thread::sleep_for(std::chrono::milliseconds(3000));
251         ASSERT_EQ(0, player->Stop());
252         ASSERT_NE(0, player->Seek(seekPos));
253         ASSERT_EQ(0, player->GetCurrentTime(currentMS));
254         ASSERT_EQ(0, player->Release());
255     }
256 
257     // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_SEEK_CALLBACK_0600
258     // @test(data="myfdurl", tags=video_play_fast)
259     PTEST((std::string url, int32_t fileSize), Test fdsource prepare, play, reset, seek, release)
260     {
261         int64_t seekPos {5000};
262         int64_t currentMS {0};
263         std::string uri = FilePathToFd(url, fileSize);
264         std::unique_ptr<TestPlayer> player = TestPlayer::Create();
265         ASSERT_EQ(0, player->SetSource(TestSource(uri)));
266         ASSERT_EQ(0, player->Prepare());
267         ASSERT_EQ(0, player->Play());
268         ASSERT_TRUE(player->IsPlaying());
269         std::this_thread::sleep_for(std::chrono::milliseconds(3000));
270         ASSERT_EQ(0, player->Reset());
271         ASSERT_NE(0, player->Seek(seekPos));
272         ASSERT_EQ(0, player->Release());
273     }
274 
275     //  SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_SEEK_CALLBACK_0700
276     // @test(data="myfdurl", tags=video_play_fast)
277     PTEST((std::string url, int32_t fileSize), Test fdsource prepare, play, setvolume, seek, release)
278     {
279         float leftVolume {1};
280         float rightVolume {1};
281         int64_t  seekPos {5000};
282         std::string uri = FilePathToFd(url, fileSize);
283         std::unique_ptr<TestPlayer> player = TestPlayer::Create();
284         ASSERT_EQ(0, player->SetSource(TestSource(uri)));
285         ASSERT_EQ(0, player->Prepare());
286         ASSERT_EQ(0, player->Play());
287         ASSERT_EQ(0, player->SetVolume(leftVolume, rightVolume));
288         ASSERT_EQ(0, player->Seek(seekPos));
289         ASSERT_EQ(0, player->Release());
290     }
291 
292     // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_SEEK_CALLBACK_0900
293     // @test(data="myfdurl", tags=video_play_fast)
294     PTEST((std::string url, int32_t fileSize), Test fdsource prepare, play, seek, release, 900)
295     {
296         int64_t seekPos {5000};
297         int64_t currentMS {0};
298         std::string uri = FilePathToFd(url, fileSize);
299         std::unique_ptr<TestPlayer> player = TestPlayer::Create();
300         ASSERT_EQ(0, player->SetSource(TestSource(uri)));
301         ASSERT_NE(0, player->Seek(seekPos));
302         ASSERT_EQ(0, player->GetCurrentTime(currentMS));
303         ASSERT_EQ(0, player->Release());
304     }
305 
306     // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_SEEK_CALLBACK_1100
307     // @test(data="myfdurl", tags=video_play_fast)
308     PTEST((std::string url, int32_t fileSize), Test fdsource prepare, play, seek, seek, seek, release)
309     {
310         int64_t seekPos {5000};
311         int64_t currentMS {0};
312         std::string uri = FilePathToFd(url, fileSize);
313         std::unique_ptr<TestPlayer> player = TestPlayer::Create();
314         ASSERT_EQ(0, player->SetSource(TestSource(uri)));
315         ASSERT_EQ(0, player->Prepare());
316         ASSERT_EQ(0, player->Play());
317         ASSERT_TRUE(player->IsPlaying());
318         std::this_thread::sleep_for(std::chrono::milliseconds(3000));
319         ASSERT_EQ(0, player->Seek(seekPos, OHOS::Media::PlayerSeekMode::SEEK_NEXT_SYNC));
320         ASSERT_EQ(0, player->GetCurrentTime(currentMS));
321         EXPECT_TRUE(CheckTimeEquality(NEXT_FRAME_TIME, currentMS));
322         seekPos = 5000;
323         ASSERT_EQ(0, player->Seek(seekPos, OHOS::Media::PlayerSeekMode::SEEK_PREVIOUS_SYNC));
324         ASSERT_EQ(0, player->GetCurrentTime(currentMS));
325         EXPECT_TRUE(CheckTimeEquality(PREV_FRAME_TIME, currentMS));
326         seekPos = 5000;
327         ASSERT_EQ(0, player->Seek(seekPos, OHOS::Media::PlayerSeekMode::SEEK_NEXT_SYNC));
328         ASSERT_EQ(0, player->GetCurrentTime(currentMS));
329         EXPECT_TRUE(CheckTimeEquality(NEXT_FRAME_TIME, currentMS));
330         ASSERT_EQ(0, player->Release());
331     }
332 
333     //  SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_SEEK_CALLBACK_1300
334     // @test(data="myfdurl", tags=video_play_fast)
335     PTEST((std::string url, int32_t fileSize), Test fdsource prepare, play, seek, -1, release)
336     {
337         int64_t seekPos {-1};
338         int64_t currentMS {0};
339         std::string uri = FilePathToFd(url, fileSize);
340         std::unique_ptr<TestPlayer> player = TestPlayer::Create();
341         ASSERT_EQ(0, player->SetSource(TestSource(uri)));
342         ASSERT_EQ(0, player->Prepare());
343         ASSERT_EQ(0, player->Play());
344         ASSERT_TRUE(player->IsPlaying());
345         std::this_thread::sleep_for(std::chrono::milliseconds(3000));
346         ASSERT_EQ(0, player->Seek(seekPos));
347         ASSERT_EQ(0, player->GetCurrentTime(currentMS));
348         ASSERT_EQ(0, player->Release());
349     }
350 
351     // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_SEEK_CALLBACK_1400
352     // @test(data="myfdurl", tags=video_play_fast)
353     PTEST((std::string url, int32_t fileSize), Test fdsource prepare, play, seek, durationTime + 1000, release)
354     {
355         int64_t seekPos {0};
356         int64_t currentMS {0};
357         int64_t durationMs {0};
358         int64_t realSeekTime {8300};
359         std::string uri = FilePathToFd(url, fileSize);
360         std::unique_ptr<TestPlayer> player = TestPlayer::Create();
361         ASSERT_EQ(0, player->SetSource(TestSource(uri)));
362         ASSERT_EQ(0, player->Prepare());
363         ASSERT_EQ(0, player->Play());
364         ASSERT_TRUE(player->IsPlaying());
365         std::this_thread::sleep_for(std::chrono::milliseconds(3000));
366         ASSERT_EQ(0, player->GetDuration(durationMs));
367         seekPos = durationMs + 1000;
368         ASSERT_EQ(0, player->Seek(seekPos, OHOS::Media::PlayerSeekMode::SEEK_PREVIOUS_SYNC));
369         ASSERT_EQ(0, player->GetCurrentTime(currentMS));
370         EXPECT_TRUE(CheckTimeEquality(realSeekTime, currentMS));
371         ASSERT_EQ(0, player->Release());
372     }
373 };