Rename some methods.
[dcpomatic.git] / test / ffmpeg_decoder_sequential_test.cc
1 /*
2     Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /** @file  test/ffmpeg_decoder_sequential_test.cc
21  *  @brief Check that the FFmpeg decoder produces sequential frames without gaps or dropped frames;
22  *  (dropped frames being checked by assert() in VideoDecoder).  Also that the decoder picks up frame rates correctly.
23  */
24
25 #include "lib/ffmpeg_content.h"
26 #include "lib/ffmpeg_decoder.h"
27 #include "lib/null_log.h"
28 #include "lib/content_video.h"
29 #include "lib/video_decoder.h"
30 #include "lib/film.h"
31 #include "test.h"
32 #include <boost/filesystem.hpp>
33 #include <boost/test/unit_test.hpp>
34 #include <iostream>
35
36 using std::cout;
37 using std::cerr;
38 using std::list;
39 using boost::shared_ptr;
40 using boost::optional;
41
42 void
43 ffmpeg_decoder_sequential_test_one (boost::filesystem::path file, float fps, int gaps, int video_length)
44 {
45         boost::filesystem::path path = private_data / file;
46         if (!boost::filesystem::exists (path)) {
47                 cerr << "Skipping test: " << path.string() << " not found.\n";
48                 return;
49         }
50
51         shared_ptr<Film> film = new_test_film ("ffmpeg_decoder_seek_test_" + file.string());
52         shared_ptr<FFmpegContent> content (new FFmpegContent (film, path));
53         film->examine_and_add_content (content);
54         wait_for_jobs ();
55         shared_ptr<Log> log (new NullLog);
56         shared_ptr<FFmpegDecoder> decoder (new FFmpegDecoder (content, log, false));
57
58         BOOST_REQUIRE (decoder->video->_content->video_frame_rate());
59         BOOST_CHECK_CLOSE (decoder->video->_content->video_frame_rate().get(), fps, 0.01);
60
61 #ifdef DCPOMATIC_DEBUG
62         decoder->video->test_gaps = 0;
63 #endif
64         for (Frame i = 0; i < video_length; ++i) {
65                 list<ContentVideo> v;
66                 v = decoder->video->get (i, true);
67                 BOOST_REQUIRE_EQUAL (v.size(), 1U);
68                 BOOST_CHECK_EQUAL (v.front().frame, i);
69         }
70 #ifdef DCPOMATIC_DEBUG
71         BOOST_CHECK_EQUAL (decoder->video->test_gaps, gaps);
72 #endif
73 }
74
75 BOOST_AUTO_TEST_CASE (ffmpeg_decoder_sequential_test)
76 {
77         ffmpeg_decoder_sequential_test_one ("boon_telly.mkv", 29.97, 0, 6910);
78         ffmpeg_decoder_sequential_test_one ("Sintel_Trailer1.480p.DivX_Plus_HD.mkv", 24, 0, 1248);
79         /* The first video frame is 12 here, so VideoDecoder should see 12 gaps
80            (at the start of the file)
81         */
82         ffmpeg_decoder_sequential_test_one ("prophet_clip.mkv", 23.976, 12, 2875);
83 }