Debian Codegraph @

xbmc/cores/VideoPlayer/test/edl/TestEdl.cpp

raw
1 /*
2 * Copyright (C) 2022- Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #include "FileItem.h"
10 #include "ServiceBroker.h"
11 #include "cores/VideoPlayer/Edl.h"
12 #include "settings/AdvancedSettings.h"
13 #include "settings/SettingsComponent.h"
14 #include "test/TestUtils.h"
15
16 #include <cmath>
17
18 #include <gtest/gtest.h>
19
20 using namespace EDL;
21
22
23 class TestEdl : public ::testing::Test
24 {
25 protected:
26 TestEdl() = default;
27 };
28
29 TEST_F(TestEdl, TestParsingMplayerTimeBasedEDL)
30 {
31 CEdl edl;
32
33 // create a dummy "media" fileitem whose corresponding edl file is testdata/mplayertimebased.edl
34 CFileItem mediaItem;
35 mediaItem.SetPath(
36 XBMC_REF_FILE_PATH("xbmc/cores/VideoPlayer/test/edl/testdata/mplayertimebased.mkv"));
37 const bool found = edl.ReadEditDecisionLists(mediaItem, 0);
38 // expect kodi to be able to parse the file correctly
39 EXPECT_EQ(found, true);
40 // the file has 5 interest points: 2 scenemarkers, 1 mute, 1 cut and 1 commbreak
41 // edit list should contain any edit that is not a scene marker nor a cut, so 2.
42 // scenemarkers should be 4 (two "raw" scene markers and 2 from the commbreak - start and end of commbreaks)
43 EXPECT_EQ(edl.HasEdits(), true);
44 EXPECT_EQ(edl.HasSceneMarker(), true);
45 EXPECT_EQ(edl.GetEditList().size(), 2);
46 EXPECT_EQ(edl.GetSceneMarkers().size(), 4);
47
48 // cuts
49 // file has only 1 cut starting at 5.3 secs and ending at 7.1 secs
50 // so total cut time should be 1.8 seconds (1800 msec)
51 EXPECT_EQ(edl.HasCuts(), true);
52 EXPECT_EQ(edl.GetTotalCutTime(), 1.8 * 1000);
53 EXPECT_EQ(edl.GetCutMarkers().size(), 1);
54 EXPECT_EQ(edl.GetCutMarkers().at(0), 5.3 * 1000); // 5.3 secs
55 // When removing or restoring cuts, EDL adds (or removes) 1 msec to jump over the start or end boundary of the edit
56 EXPECT_EQ(edl.GetTimeWithoutCuts(edl.GetRawEditList().at(0).start),
57 edl.GetRawEditList().at(0).start + 1);
58 EXPECT_EQ(edl.GetTimeAfterRestoringCuts(edl.GetRawEditList().at(0).start),
59 edl.GetRawEditList().at(0).start);
60 EXPECT_EQ(edl.GetTimeAfterRestoringCuts(edl.GetRawEditList().at(0).start + 2),
61 edl.GetRawEditList().at(0).end + 2);
62
63 // the first edit (note editlist does not contain cuts) is a mute section starting at 15 seconds
64 // of the real file this should correspond to 13.2 secs on the kodi VideoPlayer timeline (start - cuttime)
65 // raw edit list contains cuts so mute should be index 1
66 const auto mute = edl.GetEditList().at(0);
67 const auto muteRaw = edl.GetRawEditList().at(1);
68 EXPECT_EQ(mute.action, Action::MUTE);
69 EXPECT_EQ(muteRaw.action, Action::MUTE);
70 EXPECT_EQ(edl.GetTimeWithoutCuts(mute.start), mute.start - edl.GetTotalCutTime());
71 EXPECT_EQ(edl.GetTimeAfterRestoringCuts(mute.start - edl.GetTotalCutTime()), mute.start);
72 EXPECT_EQ(muteRaw.start - edl.GetTotalCutTime(), mute.start);
73 EXPECT_EQ(edl.InEdit(muteRaw.start, nullptr), true);
74 EXPECT_EQ(edl.InEdit(mute.start, nullptr), false);
75
76 // scene markers
77 // one of the scenemarkers (the first) have start and end times defined, kodi should assume the marker at the END position (255.3 secs)
78 EXPECT_EQ(edl.GetSceneMarkers().at(0), edl.GetTimeWithoutCuts(255.3 * 1000));
79 // one of them only has start defined, at 720.1 secs
80 EXPECT_EQ(edl.GetSceneMarkers().at(1), edl.GetTimeWithoutCuts(720.1 * 1000));
81
82 // commbreaks
83 // the second edit on the file is a commbreak
84 const auto commbreak = edl.GetEditList().at(1);
85 EXPECT_EQ(commbreak.action, Action::COMM_BREAK);
86 // We should have a scenemarker at the commbreak start and another on commbreak end
87 int time;
88 // lets cycle to the next scenemarker if starting from 1 msec before the start (or end) of the commbreak
89 EXPECT_EQ(edl.GetNextSceneMarker(true, commbreak.start - 1, &time), true);
90 EXPECT_EQ(edl.GetTimeWithoutCuts(time), commbreak.start);
91 EXPECT_EQ(edl.GetNextSceneMarker(true, commbreak.end - 1, &time), true);
92 EXPECT_EQ(edl.GetTimeWithoutCuts(time), commbreak.end);
93 // same if we cycle backwards
94 EXPECT_EQ(edl.GetNextSceneMarker(false, commbreak.start + 1, &time), true);
95 EXPECT_EQ(edl.GetTimeWithoutCuts(time), commbreak.start);
96 EXPECT_EQ(edl.GetNextSceneMarker(false, commbreak.end + 1, &time), true);
97 EXPECT_EQ(edl.GetTimeWithoutCuts(time), commbreak.end);
98 // We should be in an edit if we are in the middle of a commbreak...
99 // lets check and confirm the edits match (after restoring cuts)
100 Edit thisEdit;
101 const int middleOfCommbreak = commbreak.start + (commbreak.end - commbreak.start) / 2;
102 EXPECT_EQ(edl.InEdit(edl.GetTimeWithoutCuts(middleOfCommbreak), &thisEdit), true);
103 EXPECT_EQ(thisEdit.action, Action::COMM_BREAK);
104 EXPECT_EQ(thisEdit.start, edl.GetTimeAfterRestoringCuts(commbreak.start));
105 EXPECT_EQ(thisEdit.end, edl.GetTimeAfterRestoringCuts(commbreak.end));
106 }
107
108 TEST_F(TestEdl, TestParsingMplayerTimeBasedInterleavedCutsEDL)
109 {
110 CEdl edl;
111
112 // create a dummy "media" fileitem whose corresponding edl file is testdata/mplayertimebasedinterleavedcuts.edl
113 // this is an edl file with commbreaks interleaved with cuts
114 CFileItem mediaItem;
115 mediaItem.SetPath(XBMC_REF_FILE_PATH(
116 "xbmc/cores/VideoPlayer/test/edl/testdata/mplayertimebasedinterleavedcuts.mkv"));
117 const bool found = edl.ReadEditDecisionLists(mediaItem, 0);
118 // expect kodi to be able to parse the file correctly
119 EXPECT_EQ(found, true);
120 EXPECT_EQ(edl.GetEditList().size(), 2);
121 EXPECT_EQ(edl.HasCuts(), true);
122 EXPECT_EQ(edl.HasEdits(), true);
123 EXPECT_EQ(edl.GetCutMarkers().size(), 2);
124 // lets check the total cut time matches the sum of the two cut durations defined in the file
125 EXPECT_EQ(edl.GetTotalCutTime(), ((7.1 - 5.3) + (19 - 18)) * 1000);
126 // the first edit is after the first cut, so lets check the start time was adjusted exactly by the cut duration
127 EXPECT_EQ(edl.GetEditList().at(0).start, edl.GetRawEditList().at(1).start - ((7.1 - 5.3) * 1000));
128 EXPECT_EQ(edl.GetEditList().at(0).start,
129 edl.GetTimeWithoutCuts(edl.GetRawEditList().at(1).start));
130 EXPECT_EQ(edl.GetEditList().at(1).start,
131 edl.GetRawEditList().at(3).start - edl.GetTotalCutTime());
132 EXPECT_EQ(edl.GetEditList().at(1).start,
133 edl.GetTimeWithoutCuts(edl.GetRawEditList().at(3).start));
134 }
135
136 TEST_F(TestEdl, TestParsingMplayerFrameBasedEDL)
137 {
138 CEdl edl;
139 // suppose we're playing a file with 60 fps
140 const float fps = 60;
141
142 // create a dummy "media" fileitem whose corresponding edl file is testdata/mplayerframebased.edl
143 // this is an edl file with frame based edit points
144 CFileItem mediaItem;
145 mediaItem.SetPath(
146 XBMC_REF_FILE_PATH("xbmc/cores/VideoPlayer/test/edl/testdata/mplayerframebased.mkv"));
147 const bool found = edl.ReadEditDecisionLists(mediaItem, fps);
148 // expect kodi to be able to parse the file correctly
149 EXPECT_EQ(found, true);
150 EXPECT_EQ(edl.HasEdits(), true);
151 EXPECT_EQ(edl.HasCuts(), true);
152 EXPECT_EQ(edl.HasSceneMarker(), true);
153 EXPECT_EQ(edl.GetEditList().size(), 2);
154 // check edit times are correctly calculated provided the fps
155 EXPECT_EQ(edl.GetEditList().at(0).start,
156 static_cast<int64_t>((360 / fps) * 1000) - edl.GetTotalCutTime());
157 EXPECT_EQ(edl.GetSceneMarkers().at(0),
158 static_cast<int64_t>((6127 / fps) * 1000) - edl.GetTotalCutTime());
159 }
160
161 TEST_F(TestEdl, TestParsingMplayerTimeBasedMixedEDL)
162 {
163 CEdl edl;
164
165 // create a dummy "media" fileitem whose corresponding edl file is testdata/mplayertimebasedmixed.edl
166 // this file has edit points with seconds and others with seconds timestrings
167 CFileItem mediaItem;
168 mediaItem.SetPath(
169 XBMC_REF_FILE_PATH("xbmc/cores/VideoPlayer/test/edl/testdata/mplayertimebasedmixed.mkv"));
170 bool found = edl.ReadEditDecisionLists(mediaItem, 0);
171 // expect kodi to be able to parse the file correctly
172 EXPECT_EQ(found, true);
173 EXPECT_EQ(edl.HasEdits(), true);
174 EXPECT_EQ(edl.HasCuts(), true);
175 EXPECT_EQ(edl.HasSceneMarker(), true);
176 EXPECT_EQ(edl.GetSceneMarkers().size(), 4);
177 bool sceneFound = false;
178 // check we have correctly parsed the scene with 12:00.1 start point
179 for (const auto& scene : edl.GetSceneMarkers())
180 {
181 if (scene == (12 * 60 + 0.1) * 1000 - edl.GetTotalCutTime())
182 {
183 sceneFound = true;
184 break;
185 }
186 }
187 EXPECT_EQ(sceneFound, true);
188 // check that the first ordered edit starts at 15 secs
189 EXPECT_EQ(edl.GetEditList().front().start, (15 * 1000) - edl.GetTotalCutTime());
190 }
191
192 TEST_F(TestEdl, TestParsingVideoRedoEDL)
193 {
194 CEdl edl;
195
196 // create a dummy "media" fileitem whose corresponding edl file is testdata/videoredo.Vprj
197 // this is an edl file in VideoReDo format
198 CFileItem mediaItem;
199 mediaItem.SetPath(XBMC_REF_FILE_PATH("xbmc/cores/VideoPlayer/test/edl/testdata/videoredo.mkv"));
200 bool found = edl.ReadEditDecisionLists(mediaItem, 0);
201 EXPECT_EQ(found, true);
202 EXPECT_EQ(edl.HasEdits(), true);
203 // videoredo only supports cuts or scenemarkers, hence the editlist should be empty. Raw editlist should contain the cuts.
204 EXPECT_EQ(edl.GetEditList().size(), 0);
205 EXPECT_GT(edl.GetRawEditList().size(), 0);
206 EXPECT_EQ(edl.HasCuts(), true);
207 EXPECT_EQ(edl.HasSceneMarker(), true);
208 EXPECT_EQ(edl.GetSceneMarkers().size(), 4);
209 EXPECT_EQ(edl.GetCutMarkers().size(), 3);
210 // in videoredo time processing is ms * 10000
211 // first cut in the file is at 4235230000 - let's confirm this corresponds to second 423.523
212 EXPECT_EQ(edl.GetCutMarkers().front(), 423.523 * 1000);
213 }
214
215 TEST_F(TestEdl, TestSnapStreamEDL)
216 {
217 CEdl edl;
218
219 // create a dummy "media" fileitem whose corresponding edl file is testdata/snapstream.mkv.chapters.xml
220 // this is an edl file in SnapStream BeyondTV format
221 CFileItem mediaItem;
222 mediaItem.SetPath(XBMC_REF_FILE_PATH("xbmc/cores/VideoPlayer/test/edl/testdata/snapstream.mkv"));
223 const bool found = edl.ReadEditDecisionLists(mediaItem, 0);
224 EXPECT_EQ(found, true);
225 // this format only supports commbreak types
226 EXPECT_EQ(edl.HasEdits(), true);
227 EXPECT_EQ(edl.GetCutMarkers().empty(), true);
228 EXPECT_EQ(edl.GetEditList().size(), 3);
229 EXPECT_EQ(edl.GetSceneMarkers().size(), 3 * 2); // start and end of each commbreak
230 // snapstream beyond tv uses ms * 10000
231 // check if first commbreak (4235230000 - 5936600000) is 423.523 sec - 593.660 sec
232 EXPECT_EQ(edl.GetEditList().front().start, std::lround(423.523 * 1000));
233 EXPECT_EQ(edl.GetEditList().front().end, std::lround(593.660 * 1000));
234 }
235
236 TEST_F(TestEdl, TestComSkipVersion1EDL)
237 {
238 CEdl edl;
239
240 // create a dummy "media" fileitem whose corresponding edl file is testdata/comskipversion1.txt
241 // this is an edl file in ComSkip (version 1) format
242 CFileItem mediaItem;
243 mediaItem.SetPath(
244 XBMC_REF_FILE_PATH("xbmc/cores/VideoPlayer/test/edl/testdata/comskipversion1.mkv"));
245 bool found = edl.ReadEditDecisionLists(mediaItem, 0);
246 // fps was not supplied, kodi will not be able to process the file
247 EXPECT_EQ(found, false);
248 // parse the file again this time supplying 60 fps
249 const float fps = 60;
250 found = edl.ReadEditDecisionLists(mediaItem, fps);
251 EXPECT_EQ(found, true);
252 EXPECT_EQ(edl.HasEdits(), true);
253 EXPECT_EQ(edl.GetCutMarkers().empty(), true);
254 EXPECT_EQ(edl.GetEditList().size(), 3);
255 EXPECT_EQ(edl.GetSceneMarkers().size(), 3 * 2); // start and end of each commbreak
256 EXPECT_EQ(edl.GetEditList().front().start, std::lround(12693 / fps * 1000));
257 EXPECT_EQ(edl.GetEditList().front().end, std::lround(17792 / fps * 1000));
258 }
259
260 TEST_F(TestEdl, TestComSkipVersion2EDL)
261 {
262 CEdl edl;
263
264 // create a dummy "media" fileitem whose corresponding edl file is testdata/comskipversion2.txt
265 // this is an edl file in ComSkip (version 2) format where fps is obtained from the file
266 CFileItem mediaItem;
267 mediaItem.SetPath(
268 XBMC_REF_FILE_PATH("xbmc/cores/VideoPlayer/test/edl/testdata/comskipversion2.mkv"));
269 const bool found = edl.ReadEditDecisionLists(mediaItem, 0);
270 EXPECT_EQ(found, true);
271 // fps is obtained from the file as it always takes precedence (note we supplied 0 above),
272 // the EDL file has the value of 2500 for fps. kodi converts this to 25 fps by dividing by a factor of 100
273 const float fpsInEdlFile = 2500 / 100;
274 // this format only supports commbreak types
275 EXPECT_EQ(edl.HasEdits(), true);
276 EXPECT_EQ(edl.GetCutMarkers().empty(), true);
277 EXPECT_EQ(edl.GetEditList().size(), 3);
278 EXPECT_EQ(edl.GetSceneMarkers().size(), 3 * 2); // start and end of each commbreak
279 EXPECT_EQ(edl.GetEditList().front().start, std::lround(12693 / fpsInEdlFile * 1000));
280 EXPECT_EQ(edl.GetEditList().front().end, std::lround(17792 / fpsInEdlFile * 1000));
281 }
282
283 TEST_F(TestEdl, TestRuntimeSetEDL)
284 {
285 // this is a simple test for SetLastEditTime, SetLastEditActionType and corresponding getters
286 CEdl edl;
287 edl.SetLastEditTime(1000);
288 edl.SetLastEditActionType(Action::COMM_BREAK);
289 EXPECT_EQ(edl.GetLastEditTime(), 1000);
290 EXPECT_EQ(edl.GetLastEditActionType(), Action::COMM_BREAK);
291 }
292
293 TEST_F(TestEdl, TestCommBreakAdvancedSettings)
294 {
295 CEdl edl;
296 const std::shared_ptr<CAdvancedSettings> advancedSettings =
297 CServiceBroker::GetSettingsComponent()->GetAdvancedSettings();
298
299 // the test goal is to test m_iEdlCommBreakAutowait and m_iEdlCommBreakAutowind
300 // lets check first the behaviour with default values (both disabled)
301 // Keep all EDL advanced settings to default
302 advancedSettings->m_iEdlCommBreakAutowait = 0; // disabled (default)
303 advancedSettings->m_iEdlCommBreakAutowind = 0; // disabled (default)
304 advancedSettings->m_bEdlMergeShortCommBreaks = false; // disabled (default)
305 advancedSettings->m_iEdlMinCommBreakLength = 3 * 30; // 3*30 secs (default)
306 advancedSettings->m_iEdlMaxCommBreakLength = 8 * 30 + 10; // 8*30+10 secs (default value)
307 advancedSettings->m_iEdlMaxStartGap = 5 * 60; // 5 minutes (default)
308 EXPECT_EQ(advancedSettings->m_iEdlCommBreakAutowait, 0);
309 EXPECT_EQ(advancedSettings->m_iEdlCommBreakAutowind, 0);
310 EXPECT_EQ(advancedSettings->m_bEdlMergeShortCommBreaks, false);
311 EXPECT_EQ(advancedSettings->m_iEdlMinCommBreakLength, 3 * 30);
312 EXPECT_EQ(advancedSettings->m_iEdlMinCommBreakLength, 3 * 30);
313 EXPECT_EQ(advancedSettings->m_iEdlMaxCommBreakLength, 8 * 30 + 10);
314 EXPECT_EQ(advancedSettings->m_iEdlMaxStartGap, 5 * 60);
315
316 // create a dummy "media" fileitem whose corresponding edl file is testdata/edlautowindautowait.txt
317 CFileItem mediaItem;
318 mediaItem.SetPath(
319 XBMC_REF_FILE_PATH("xbmc/cores/VideoPlayer/test/edl/testdata/edlautowindautowait.mkv"));
320 bool found = edl.ReadEditDecisionLists(mediaItem, 0);
321 EXPECT_EQ(found, true);
322 // confirm the start and end times of all the commbreaks match
323 EXPECT_EQ(edl.GetEditList().size(), 5);
324 EXPECT_EQ(edl.GetEditList().at(0).start, 10 * 1000);
325 EXPECT_EQ(edl.GetEditList().at(0).end, 22 * 1000);
326 EXPECT_EQ(edl.GetEditList().at(1).start, 30 * 1000);
327 EXPECT_EQ(edl.GetEditList().at(1).end, 32 * 1000);
328 EXPECT_EQ(edl.GetEditList().at(2).start, 37 * 1000);
329 EXPECT_EQ(edl.GetEditList().at(2).end, 50 * 1000);
330 EXPECT_EQ(edl.GetEditList().at(3).start, 52 * 1000);
331 EXPECT_EQ(edl.GetEditList().at(3).end, 60 * 1000);
332 EXPECT_EQ(edl.GetEditList().at(4).start, 62 * 1000);
333 EXPECT_EQ(edl.GetEditList().at(4).end, std::lround(65.1 * 1000));
334 // now lets change autowait and autowind and check the edits are correcly adjusted
335 edl.Clear();
336 advancedSettings->m_iEdlCommBreakAutowait = 3; // secs
337 advancedSettings->m_iEdlCommBreakAutowind = 3; // secs
338 EXPECT_EQ(advancedSettings->m_iEdlCommBreakAutowait, 3);
339 EXPECT_EQ(advancedSettings->m_iEdlCommBreakAutowind, 3);
340 found = edl.ReadEditDecisionLists(mediaItem, 0);
341 EXPECT_EQ(edl.GetEditList().size(), 5);
342 // the second edit has a duration smaller than the autowait
343 // this moves the start time to the end of the edit
344 EXPECT_EQ(edl.GetEditList().at(1).start, 32 * 1000);
345 EXPECT_EQ(edl.GetEditList().at(1).end, edl.GetEditList().at(1).start);
346 // the others should be adjusted + 3 secs at the start and -3 secs at the end
347 // due to the provided values for autowait and autowind.
348 EXPECT_EQ(edl.GetEditList().at(0).start, (10 + 3) * 1000);
349 EXPECT_EQ(edl.GetEditList().at(0).end, (22 - 3) * 1000);
350 EXPECT_EQ(edl.GetEditList().at(2).start, (37 + 3) * 1000);
351 EXPECT_EQ(edl.GetEditList().at(2).end, (50 - 3) * 1000);
352 EXPECT_EQ(edl.GetEditList().at(3).start, (52 + 3) * 1000);
353 EXPECT_EQ(edl.GetEditList().at(3).end, (60 - 3) * 1000);
354 // since we adjust the start to second 65 and the autowind is 3 seconds kodi should
355 // shift the end time not by 3 seconds but by the "excess" time (in this case 0.1 sec)
356 // this means start and end will be exactly the same. The commbreak would be removed if
357 // mergeshortcommbreaks was active and advancedsetting m_iEdlMinCommBreakLength
358 // was set to a reasonable threshold.
359 EXPECT_EQ(edl.GetEditList().at(4).start, (62 + 3) * 1000);
360 EXPECT_EQ(edl.GetEditList().at(4).end, (65.1 - 0.1) * 1000);
361 EXPECT_EQ(edl.GetEditList().at(4).start, edl.GetEditList().at(4).end);
362 }
363
364 TEST_F(TestEdl, TestCommBreakAdvancedSettingsRemoveSmallCommbreaks)
365 {
366 // this is a variation of TestCommBreakAdvancedSettings
367 // should make sure the number of commbreaks in the file is now 3 instead of 5
368 // since two of them have duration smaller than 1 sec
369 CEdl edl;
370 const std::shared_ptr<CAdvancedSettings> advancedSettings =
371 CServiceBroker::GetSettingsComponent()->GetAdvancedSettings();
372
373 // set EDL advanced settings specific for the test case
374 advancedSettings->m_iEdlCommBreakAutowait = 3; // secs
375 advancedSettings->m_iEdlCommBreakAutowind = 3; // secs
376 advancedSettings->m_bEdlMergeShortCommBreaks = true;
377 advancedSettings->m_iEdlMinCommBreakLength = 1; // sec
378 advancedSettings->m_iEdlMaxCommBreakLength = 0; // deactivate
379 advancedSettings->m_iEdlMaxStartGap = 0; // deactivate
380 EXPECT_EQ(advancedSettings->m_iEdlCommBreakAutowait, 3);
381 EXPECT_EQ(advancedSettings->m_iEdlCommBreakAutowind, 3);
382 EXPECT_EQ(advancedSettings->m_bEdlMergeShortCommBreaks, true);
383 EXPECT_EQ(advancedSettings->m_iEdlMinCommBreakLength, 1);
384 EXPECT_EQ(advancedSettings->m_iEdlMaxCommBreakLength, 0);
385 EXPECT_EQ(advancedSettings->m_iEdlMaxStartGap, 0);
386
387 CFileItem mediaItem;
388 mediaItem.SetPath(
389 XBMC_REF_FILE_PATH("xbmc/cores/VideoPlayer/test/edl/testdata/edlautowindautowait.mkv"));
390 const bool found = edl.ReadEditDecisionLists(mediaItem, 0);
391 EXPECT_EQ(found, true);
392 EXPECT_EQ(edl.GetEditList().size(), 3);
393 }
394
395 TEST_F(TestEdl, TestMergeSmallCommbreaks)
396 {
397 CEdl edl;
398 const std::shared_ptr<CAdvancedSettings> advancedSettings =
399 CServiceBroker::GetSettingsComponent()->GetAdvancedSettings();
400
401 // set EDL advanced settings specific for the test case
402 advancedSettings->m_bEdlMergeShortCommBreaks = true;
403 EXPECT_EQ(advancedSettings->m_bEdlMergeShortCommBreaks, true);
404 // keep any other EDL advanced settings to default
405 advancedSettings->m_iEdlCommBreakAutowait = 0; // disabled (default)
406 advancedSettings->m_iEdlCommBreakAutowind = 0; // disabled (default)
407 advancedSettings->m_iEdlMinCommBreakLength = 3 * 30; // 3*30 secs (default)
408 advancedSettings->m_iEdlMaxCommBreakLength = 8 * 30 + 10; // 8*30+10 secs (default value)
409 advancedSettings->m_iEdlMaxStartGap = 5 * 60; // 5 minutes (default)
410 EXPECT_EQ(advancedSettings->m_iEdlCommBreakAutowait, 0);
411 EXPECT_EQ(advancedSettings->m_iEdlCommBreakAutowind, 0);
412 EXPECT_EQ(advancedSettings->m_iEdlMinCommBreakLength, 3 * 30);
413 EXPECT_EQ(advancedSettings->m_iEdlMaxCommBreakLength, 8 * 30 + 10);
414 EXPECT_EQ(advancedSettings->m_iEdlMaxStartGap, 5 * 60);
415
416 CFileItem mediaItem;
417 mediaItem.SetPath(
418 XBMC_REF_FILE_PATH("xbmc/cores/VideoPlayer/test/edl/testdata/edlautowindautowait.mkv"));
419 const bool found = edl.ReadEditDecisionLists(mediaItem, 0);
420 EXPECT_EQ(found, true);
421 // kodi should merge all commbreaks into a single one starting at the first point (0)
422 // and ending at the last edit time
423 EXPECT_EQ(edl.GetEditList().size(), 1);
424 EXPECT_EQ(edl.GetEditList().at(0).start, 0);
425 EXPECT_EQ(edl.GetEditList().at(0).end, std::lround(65.1 * 1000));
426 }
427
428 TEST_F(TestEdl, TestMergeSmallCommbreaksAdvanced)
429 {
430 CEdl edl;
431 const std::shared_ptr<CAdvancedSettings> advancedSettings =
432 CServiceBroker::GetSettingsComponent()->GetAdvancedSettings();
433
434 // set EDL advanced settings specific for the test case
435 advancedSettings->m_bEdlMergeShortCommBreaks = true;
436 advancedSettings->m_iEdlMaxCommBreakLength = 30; // 30 secs
437 advancedSettings->m_iEdlMinCommBreakLength = 1; // 1 sec
438 advancedSettings->m_iEdlMaxStartGap = 2; // 2 secs
439 EXPECT_EQ(advancedSettings->m_bEdlMergeShortCommBreaks, true);
440 EXPECT_EQ(advancedSettings->m_iEdlMaxCommBreakLength, 30);
441 EXPECT_EQ(advancedSettings->m_iEdlMinCommBreakLength, 1);
442 EXPECT_EQ(advancedSettings->m_iEdlMaxStartGap, 2);
443 // keep any other EDL advanced settings to default
444 advancedSettings->m_iEdlCommBreakAutowait = 0; // disabled (default)
445 advancedSettings->m_iEdlCommBreakAutowind = 0; // disabled (default)
446 EXPECT_EQ(advancedSettings->m_iEdlCommBreakAutowait, 0);
447 EXPECT_EQ(advancedSettings->m_iEdlCommBreakAutowind, 0);
448
449 CFileItem mediaItem;
450 mediaItem.SetPath(
451 XBMC_REF_FILE_PATH("xbmc/cores/VideoPlayer/test/edl/testdata/edlautowindautowait.mkv"));
452 const bool found = edl.ReadEditDecisionLists(mediaItem, 0);
453 EXPECT_EQ(found, true);
454 // kodi should merge all commbreaks into two
455 EXPECT_EQ(edl.GetEditList().size(), 2);
456 // second edit of the original file + third one
457 EXPECT_EQ(edl.GetEditList().at(0).end - edl.GetEditList().at(0).start, (32 - 10) * 1000);
458 // 4th, 5th and 6th commbreaks joined
459 EXPECT_EQ(edl.GetEditList().at(1).end - edl.GetEditList().at(1).start,
460 std::lround((65.1 - 37) * 1000));
461 }