Change how video timing is done.
[dcpomatic.git] / test / ffmpeg_decoder_seek_test.cc
1 /*
2     Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21
22 /** @file  test/ffmpeg_decoder_seek_test.cc
23  *  @brief Check seek() with FFmpegDecoder.
24  *  @ingroup selfcontained
25  *
26  *  This doesn't check that the contents of those frames are right, which
27  *  it probably should.
28  */
29
30
31 #include "lib/content_video.h"
32 #include "lib/ffmpeg_content.h"
33 #include "lib/ffmpeg_decoder.h"
34 #include "lib/film.h"
35 #include "lib/null_log.h"
36 #include "lib/video_decoder.h"
37 #include "test.h"
38 #include <boost/filesystem.hpp>
39 #include <boost/test/unit_test.hpp>
40 #include <iostream>
41 #include <vector>
42
43
44 using std::cerr;
45 using std::cout;
46 using std::list;
47 using std::make_shared;
48 using std::shared_ptr;
49 using std::vector;
50 using boost::optional;
51 #if BOOST_VERSION >= 106100
52 using namespace boost::placeholders;
53 #endif
54 using namespace dcpomatic;
55
56
57 static optional<ContentVideo> stored;
58 static bool
59 store (ContentVideo v)
60 {
61         stored = v;
62         return true;
63 }
64
65
66 static void
67 check (shared_ptr<FFmpegDecoder> decoder, ContentTime time)
68 {
69         BOOST_REQUIRE (decoder->ffmpeg_content()->video_frame_rate ());
70         decoder->seek(time, true);
71         stored = optional<ContentVideo> ();
72         while (!decoder->pass() && !stored) {}
73         BOOST_CHECK(stored->time <= time);
74 }
75
76
77 static void
78 test (boost::filesystem::path file, vector<ContentTime> times)
79 {
80         auto path = TestPaths::private_data() / file;
81         BOOST_REQUIRE (boost::filesystem::exists (path));
82
83         auto film = new_test_film ("ffmpeg_decoder_seek_test_" + file.string());
84         auto content = make_shared<FFmpegContent>(path);
85         film->examine_and_add_content (content);
86         BOOST_REQUIRE (!wait_for_jobs());
87         auto decoder = make_shared<FFmpegDecoder>(film, content, false);
88         decoder->video->Data.connect (bind (&store, _1));
89
90         for (auto i: times) {
91                 check (decoder, i);
92         }
93 }
94
95
96 BOOST_AUTO_TEST_CASE (ffmpeg_decoder_seek_test)
97 {
98         test(
99                 "boon_telly.mkv",
100                 {
101                         ContentTime::from_frames(0, 29.97),
102                         ContentTime::from_frames(42, 29.97),
103                         ContentTime::from_frames(999, 29.97),
104                         ContentTime::from_frames(0, 29.97),
105                 }
106             );
107
108         test(
109                 "Sintel_Trailer1.480p.DivX_Plus_HD.mkv",
110                 {
111                         ContentTime::from_frames(0, 24),
112                         ContentTime::from_frames(42, 24),
113                         ContentTime::from_frames(999, 24),
114                         ContentTime::from_frames(0, 24),
115                 }
116             );
117
118         test(
119                 "prophet_long_clip.mkv",
120                 {
121                         ContentTime::from_frames(15, 23.976),
122                         ContentTime::from_frames(42, 23.976),
123                         ContentTime::from_frames(999, 23.976),
124                         ContentTime::from_frames(15, 23.976)
125                 }
126             );
127
128         test(
129                 "dolby_aurora.vob",
130                 {
131                         ContentTime::from_frames(0, 25),
132                         ContentTime::from_frames(125, 25),
133                         ContentTime::from_frames(250, 25),
134                         ContentTime::from_frames(41, 25)
135                 }
136             );
137 }