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(dataDrivenSingleVideoPlayerTestFast4)32 FIXTURE(dataDrivenSingleVideoPlayerTestFast4)
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 std::string FilePathToFd(std::string url, int32_t fileSize)
38 {
39 std::string uri = "fd://?offset=0&size=";
40 uri += std::to_string(fileSize);
41 int32_t fd = open(url.c_str(), O_RDONLY|O_BINARY);
42 std::string fdStr = std::to_string(fd);
43 uri.insert(5, fdStr); // 5 ---fd:://
44 return uri;
45 }
46
47 // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_SETVOLUME_CALLBACK_0100
48 // @test(data="myfdurl", tags=video_play_fast)
49 PTEST((std::string url, int32_t fileSize), Test fdsource prepare, setvolume, release)
50 {
51 float leftVolume {1};
52 float rightVolume {1};
53 std::string uri = FilePathToFd(url, fileSize);
54 std::unique_ptr<TestPlayer> player = TestPlayer::Create();
55 ASSERT_EQ(0, player->SetVolume(leftVolume, rightVolume));
56 ASSERT_EQ(0, player->Release());
57 }
58
59 // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_SETVOLUME_CALLBACK_0200
60 // @test(data="myfdurl", tags=video_play_fast)
61 PTEST((std::string url, int32_t fileSize), Test fdsource prepare, setvolume, release)
62 {
63 float leftVolume {1};
64 float rightVolume {1};
65 std::string uri = FilePathToFd(url, fileSize);
66 std::unique_ptr<TestPlayer> player = TestPlayer::Create();
67 ASSERT_EQ(0, player->SetSource(TestSource(uri)));
68 ASSERT_EQ(0, player->Prepare());
69 ASSERT_EQ(0, player->SetVolume(leftVolume, rightVolume));
70 ASSERT_EQ(0, player->Release());
71 }
72
73 // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_PLAY_CALLBACK_0300
74 // @test(data="myfdurl", tags=video_play_fast)
75 PTEST((std::string url, int32_t fileSize), Test fdsource prepare, play, setvolume, release)
76 {
77 float leftVolume {1};
78 float rightVolume {1};
79 std::string uri = FilePathToFd(url, fileSize);
80 std::unique_ptr<TestPlayer> player = TestPlayer::Create();
81 ASSERT_EQ(0, player->SetSource(TestSource(uri)));
82 ASSERT_EQ(0, player->Prepare());
83 ASSERT_EQ(0, player->Play());
84 ASSERT_EQ(0, player->SetVolume(leftVolume, rightVolume));
85 ASSERT_EQ(0, player->Release());
86 }
87
88 // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_SETVOLUME_CALLBACK_0400
89 // @test(data="myfdurl", tags=video_play_fast)
90 PTEST((std::string url, int32_t fileSize), Test fdsource prepare, play, pause, setvolume, release)
91 {
92 float leftVolume {1};
93 float rightVolume {1};
94 std::string uri = FilePathToFd(url, fileSize);
95 std::unique_ptr<TestPlayer> player = TestPlayer::Create();
96 ASSERT_EQ(0, player->SetSource(TestSource(uri)));
97 ASSERT_EQ(0, player->Prepare());
98 ASSERT_EQ(0, player->Play());
99 ASSERT_EQ(0, player->Pause());
100 ASSERT_EQ(0, player->SetVolume(leftVolume, rightVolume));
101 ASSERT_EQ(0, player->Release());
102 }
103
104 // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_SETVOLUME_CALLBACK_0500
105 // @test(data="myfdurl", tags=video_play_fast)
106 PTEST((std::string url, int32_t fileSize), Test fdsource prepare, play, stop, setvolume, release)
107 {
108 float leftVolume {1};
109 float rightVolume {1};
110 std::string uri = FilePathToFd(url, fileSize);
111 std::unique_ptr<TestPlayer> player = TestPlayer::Create();
112 ASSERT_EQ(0, player->SetSource(TestSource(uri)));
113 ASSERT_EQ(0, player->Prepare());
114 ASSERT_EQ(0, player->Play());
115 ASSERT_EQ(0, player->Stop());
116 ASSERT_EQ(0, player->SetVolume(leftVolume, rightVolume));
117 ASSERT_EQ(0, player->Release());
118 }
119
120 // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_SETVOLUME_CALLBACK_0600
121 // @test(data="myfdurl", tags=video_play_fast)
122 PTEST((std::string url, int32_t fileSize), Test fdsource prepare, play, reset, setvolume, release)
123 {
124 float leftVolume {1};
125 float rightVolume {1};
126 std::string uri = FilePathToFd(url, fileSize);
127 std::unique_ptr<TestPlayer> player = TestPlayer::Create();
128 ASSERT_EQ(0, player->SetSource(TestSource(uri)));
129 ASSERT_EQ(0, player->Prepare());
130 ASSERT_EQ(0, player->Play());
131 ASSERT_EQ(0, player->Reset());
132 ASSERT_EQ(0, player->SetVolume(leftVolume, rightVolume));
133 ASSERT_EQ(0, player->Release());
134 }
135
136 // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_SETVOLUME_CALLBACK_0700
137 // @test(data="myfdurl", tags=video_play_fast)
138 PTEST((std::string url, int32_t fileSize), Test fdsource prepare, play, seek, setvolume, release)
139 {
140 float leftVolume {1};
141 float rightVolume {1};
142 int64_t seekPos {5000};
143 std::string uri = FilePathToFd(url, fileSize);
144 std::unique_ptr<TestPlayer> player = TestPlayer::Create();
145 ASSERT_EQ(0, player->SetSource(TestSource(uri)));
146 ASSERT_EQ(0, player->Prepare());
147 ASSERT_EQ(0, player->Play());
148 ASSERT_TRUE(player->IsPlaying());
149 std::this_thread::sleep_for(std::chrono::milliseconds(1000));
150 ASSERT_EQ(0, player->Seek(seekPos));
151 ASSERT_EQ(0, player->SetVolume(leftVolume, rightVolume));
152 ASSERT_EQ(0, player->Release());
153 }
154
155 // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_SETVOLUME_CALLBACK_0900
156 // @test(data="myfdurl", tags=video_play_fast)
157 PTEST((std::string url, int32_t fileSize), Test fdsource setsourse, setvolume, release)
158 {
159 float leftVolume {1};
160 float rightVolume {1};
161 std::string uri = FilePathToFd(url, fileSize);
162 std::unique_ptr<TestPlayer> player = TestPlayer::Create();
163 ASSERT_EQ(0, player->SetSource(TestSource(uri)));
164 ASSERT_EQ(0, player->SetVolume(leftVolume, rightVolume));
165 ASSERT_EQ(0, player->Release());
166 }
167
168 // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_SETVOLUME_CALLBACK_1100
169 // @test(data="myfdurl", tags=video_play_fast)
170 PTEST((std::string url, int32_t fileSize), Test fdsource prepare, setvolume, setvolume, setvolume, release)
171 {
172 float leftVolume {1};
173 float rightVolume {1};
174 std::string uri = FilePathToFd(url, fileSize);
175 std::unique_ptr<TestPlayer> player = TestPlayer::Create();
176 ASSERT_EQ(0, player->SetSource(TestSource(uri)));
177 ASSERT_EQ(0, player->Prepare());
178 ASSERT_EQ(0, player->Play());
179 ASSERT_EQ(0, player->SetVolume(leftVolume, rightVolume));
180 ASSERT_EQ(0, player->SetVolume(leftVolume, rightVolume));
181 ASSERT_EQ(0, player->SetVolume(leftVolume, rightVolume));
182 ASSERT_EQ(0, player->Release());
183 }
184
185 // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_SETVOLUME_CALLBACK_1300
186 // @test(data="myfdurl", tags=video_play_fast)
187 PTEST((std::string url, int32_t fileSize), Test fdsource prepare, play, setVolume, -1, release)
188 {
189 float leftVolume {-1};
190 float rightVolume {-1};
191 std::string uri = FilePathToFd(url, fileSize);
192 std::unique_ptr<TestPlayer> player = TestPlayer::Create();
193 ASSERT_EQ(0, player->SetSource(TestSource(uri)));
194 ASSERT_EQ(0, player->Prepare());
195 ASSERT_EQ(0, player->Play());
196 std::this_thread::sleep_for(std::chrono::milliseconds(3000));
197 ASSERT_NE(0, player->SetVolume(leftVolume, rightVolume));
198 ASSERT_EQ(0, player->Release());
199 }
200
201 // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_SETVOLUME_CALLBACK_1400
202 // @test(data="myfdurl", tags=video_play_fast)
203 PTEST((std::string url, int32_t fileSize), Test fdsource prepare, play, setVolume, 2, release)
204 {
205 float leftVolume {2};
206 float rightVolume {2};
207 std::string uri = FilePathToFd(url, fileSize);
208 std::unique_ptr<TestPlayer> player = TestPlayer::Create();
209 ASSERT_EQ(0, player->SetSource(TestSource(uri)));
210 ASSERT_EQ(0, player->Prepare());
211 ASSERT_EQ(0, player->Play());
212 std::this_thread::sleep_for(std::chrono::milliseconds(3000));
213 ASSERT_NE(0, player->SetVolume(leftVolume, rightVolume));
214 ASSERT_EQ(0, player->Release());
215 }
216
217 // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_FUNCTION_CALLBACK_LOOP
218 // @test(data="myfdurl", tags=video_play_fast)
219 PTEST((std::string url, int32_t fileSize), Test fdsource prepare, setsingleloop true, play, seek, durationtime
220 3 times, setsingleloop flase, release)
221 {
222 int64_t durationMs {0};
223 std::string uri = FilePathToFd(url, fileSize);
224 std::unique_ptr<TestPlayer> player = TestPlayer::Create();
225 ASSERT_EQ(0, player->SetSource(TestSource(uri)));
226 ASSERT_EQ(0, player->Prepare());
227 ASSERT_EQ(0, player->SetSingleLoop(true));
228 ASSERT_EQ(0, player->Play());
229 ASSERT_EQ(0, player->GetDuration(durationMs));
230 ASSERT_EQ(0, player->Seek(durationMs, OHOS::Media::PlayerSeekMode::SEEK_PREVIOUS_SYNC));
231 std::this_thread::sleep_for(std::chrono::milliseconds(3000));
232 ASSERT_EQ(0, player->GetDuration(durationMs));
233 ASSERT_EQ(0, player->Seek(durationMs, OHOS::Media::PlayerSeekMode::SEEK_PREVIOUS_SYNC));
234 std::this_thread::sleep_for(std::chrono::milliseconds(5000));
235 ASSERT_EQ(0, player->GetDuration(durationMs));
236 ASSERT_EQ(0, player->Seek(durationMs, OHOS::Media::PlayerSeekMode::SEEK_PREVIOUS_SYNC));
237 std::this_thread::sleep_for(std::chrono::milliseconds(1000));
238 ASSERT_EQ(0, player->GetDuration(durationMs));
239 ASSERT_EQ(0, player->Seek(durationMs, OHOS::Media::PlayerSeekMode::SEEK_PREVIOUS_SYNC));
240 std::this_thread::sleep_for(std::chrono::milliseconds(8000));
241 ASSERT_EQ(0, player->SetSingleLoop(false));
242 ASSERT_EQ(0, player->Release());
243 }
244
245 // SUB_MULTIMEDIA_MEDIA_VIDEO_PLAYER_FUNCTION_CALLBACK_BASE
246 // @test(data="myfdurl", tags=video_play_fast)
247 PTEST((std::string url, int32_t fileSize), Test fdsource prepare, setsingleloop true, play, seek, set fd, seek
248 2 times, setsingleloop false, release)
249 {
250 int64_t durationMs {0};
251 std::unique_ptr<TestPlayer> player = TestPlayer::Create();
252 ASSERT_EQ(0, player->SetSource(TestSource(url)));
253 ASSERT_EQ(0, player->Prepare());
254 ASSERT_EQ(0, player->Play());
255 std::this_thread::sleep_for(std::chrono::milliseconds(3000));
256 ASSERT_EQ(0, player->Pause());
257 ASSERT_EQ(0, player->Play());
258 std::this_thread::sleep_for(std::chrono::milliseconds(3000));
259 ASSERT_EQ(0, player->Stop());
260 ASSERT_EQ(0, player->Reset());
261 std::string uri = FilePathToFd(url, fileSize);
262 ASSERT_EQ(0, player->SetSource(TestSource(uri)));
263 ASSERT_EQ(0, player->Prepare());
264 ASSERT_EQ(0, player->SetSingleLoop(true));
265 ASSERT_EQ(0, player->Play());
266 ASSERT_TRUE(player->IsPlaying());
267 std::this_thread::sleep_for(std::chrono::milliseconds(3000));
268 ASSERT_EQ(0, player->GetDuration(durationMs));
269 ASSERT_EQ(0, player->Seek(durationMs/2));
270 ASSERT_EQ(0, player->Seek(0));
271 std::this_thread::sleep_for(std::chrono::milliseconds(1000));
272 ASSERT_EQ(0, player->GetDuration(durationMs));
273 ASSERT_EQ(0, player->Seek(durationMs, OHOS::Media::PlayerSeekMode::SEEK_PREVIOUS_SYNC));
274 std::this_thread::sleep_for(std::chrono::milliseconds(8000));
275 ASSERT_EQ(0, player->SetSingleLoop(false));
276 ASSERT_EQ(0, player->Release());
277 }
278 };