Fill test disk partitions with random noise to expose more bugs.
[dcpomatic.git] / test / ffmpeg_decoder_sequential_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_sequential_test.cc
23  *  @brief Check that the FFmpeg decoder and Player produce sequential frames without gaps or dropped frames;
24  *  Also that the decoder picks up frame rates correctly.
25  *  @ingroup feature
26  */
27
28
29 #include "lib/ffmpeg_content.h"
30 #include "lib/ffmpeg_decoder.h"
31 #include "lib/content_video.h"
32 #include "lib/video_decoder.h"
33 #include "lib/film.h"
34 #include "lib/player_video.h"
35 #include "lib/player.h"
36 #include "test.h"
37 #include <boost/filesystem.hpp>
38 #include <boost/test/unit_test.hpp>
39 #include <iostream>
40
41
42 using std::cerr;
43 using std::cout;
44 using std::list;
45 using std::make_shared;
46 using std::shared_ptr;
47 using boost::optional;
48 using boost::bind;
49 #if BOOST_VERSION >= 106100
50 using namespace boost::placeholders;
51 #endif
52 using namespace dcpomatic;
53
54
55 static DCPTime next;
56 static DCPTime frame;
57
58
59 static void
60 check (shared_ptr<PlayerVideo>, DCPTime time)
61 {
62         BOOST_REQUIRE (time == next);
63         next += frame;
64 }
65
66
67 void
68 ffmpeg_decoder_sequential_test_one (boost::filesystem::path file, float fps, int video_length)
69 {
70         auto path = TestPaths::private_data() / file;
71         BOOST_REQUIRE (boost::filesystem::exists (path));
72
73         auto film = new_test_film ("ffmpeg_decoder_sequential_test_" + file.string());
74         auto content = make_shared<FFmpegContent>(path);
75         film->examine_and_add_content (content);
76         BOOST_REQUIRE (!wait_for_jobs());
77         film->write_metadata ();
78         auto player = make_shared<Player>(film, Image::Alignment::COMPACT);
79
80         BOOST_REQUIRE (content->video_frame_rate());
81         BOOST_CHECK_CLOSE (content->video_frame_rate().get(), fps, 0.01);
82
83         player->Video.connect (bind (&check, _1, _2));
84
85         next = DCPTime ();
86         frame = DCPTime::from_frames (1, film->video_frame_rate ());
87         while (!player->pass()) {}
88         BOOST_REQUIRE (next == DCPTime::from_frames (video_length, film->video_frame_rate()));
89 }
90
91
92 BOOST_AUTO_TEST_CASE (ffmpeg_decoder_sequential_test)
93 {
94         ffmpeg_decoder_sequential_test_one ("boon_telly.mkv", 29.97, 6912);
95         ffmpeg_decoder_sequential_test_one ("Sintel_Trailer1.480p.DivX_Plus_HD.mkv", 24, 1253);
96         ffmpeg_decoder_sequential_test_one ("prophet_long_clip.mkv", 23.976, 2879);
97 }