9edca016049e390814a99b83e4e4bf925d8c9c71
[dcpomatic.git] / test / ffmpeg_decoder_sequential_test.cc
1 /*
2     Copyright (C) 2014 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 /** @file  test/ffmpeg_decoder_sequential_test.cc
22  *  @brief Check that the FFmpeg decoder produces sequential frames without gaps or dropped frames;
23  *  (dropped frames being checked by assert() in VideoDecoder).  Also that the decoder picks up frame rates correctly.
24  */
25
26 #include "lib/ffmpeg_content.h"
27 #include "lib/ffmpeg_decoder.h"
28 #include "lib/null_log.h"
29 #include "lib/content_video.h"
30 #include "lib/video_decoder.h"
31 #include "lib/film.h"
32 #include "test.h"
33 #include <boost/filesystem.hpp>
34 #include <boost/make_shared.hpp>
35 #include <boost/test/unit_test.hpp>
36 #include <iostream>
37
38 using std::cout;
39 using std::cerr;
40 using std::list;
41 using boost::shared_ptr;
42 using boost::make_shared;
43 using boost::optional;
44
45 void
46 ffmpeg_decoder_sequential_test_one (boost::filesystem::path file, float fps, int gaps, int video_length)
47 {
48         boost::filesystem::path path = private_data / file;
49         if (!boost::filesystem::exists (path)) {
50                 cerr << "Skipping test: " << path.string() << " not found.\n";
51                 return;
52         }
53
54         shared_ptr<Film> film = new_test_film ("ffmpeg_decoder_seek_test_" + file.string());
55         shared_ptr<FFmpegContent> content = make_shared<FFmpegContent> (film, path);
56         film->examine_and_add_content (content);
57         wait_for_jobs ();
58         shared_ptr<Log> log = make_shared<NullLog> ();
59         shared_ptr<FFmpegDecoder> decoder = make_shared<FFmpegDecoder> (content, log, false);
60
61         BOOST_REQUIRE (decoder->video->_content->video_frame_rate());
62         BOOST_CHECK_CLOSE (decoder->video->_content->video_frame_rate().get(), fps, 0.01);
63
64 #ifdef DCPOMATIC_DEBUG
65         decoder->video->test_gaps = 0;
66 #endif
67         for (Frame i = 0; i < video_length; ++i) {
68                 list<ContentVideo> v;
69                 v = decoder->video->get (i, true);
70                 BOOST_REQUIRE_EQUAL (v.size(), 1U);
71                 BOOST_CHECK_EQUAL (v.front().frame.index(), i);
72         }
73 #ifdef DCPOMATIC_DEBUG
74         BOOST_CHECK_EQUAL (decoder->video->test_gaps, gaps);
75 #endif
76 }
77
78 BOOST_AUTO_TEST_CASE (ffmpeg_decoder_sequential_test)
79 {
80         ffmpeg_decoder_sequential_test_one ("boon_telly.mkv", 29.97, 0, 6910);
81         ffmpeg_decoder_sequential_test_one ("Sintel_Trailer1.480p.DivX_Plus_HD.mkv", 24, 0, 1248);
82         /* The first video frame is 12 here, so VideoDecoder should see 12 gaps
83            (at the start of the file)
84         */
85         ffmpeg_decoder_sequential_test_one ("prophet_clip.mkv", 23.976, 12, 2875);
86 }