9a14c5adbdb1695a5ef890b5c41bfb637361e315
[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 <boost/test/unit_test.hpp>
26 #include <boost/filesystem.hpp>
27 #include "lib/ffmpeg_content.h"
28 #include "lib/ffmpeg_decoder.h"
29 #include "lib/log.h"
30 #include "lib/film.h"
31 #include "test.h"
32
33 using std::cout;
34 using std::cerr;
35 using std::list;
36 using boost::shared_ptr;
37 using boost::optional;
38
39 /** @param black Frame index of first frame in the video */ 
40 static void
41 test (boost::filesystem::path file, float fps, int first)
42 {
43         boost::filesystem::path path = private_data / file;
44         if (!boost::filesystem::exists (path)) {
45                 cerr << "Skipping test: " << path.string() << " not found.\n";
46                 return;
47         }
48
49         shared_ptr<Film> film = new_test_film ("ffmpeg_decoder_seek_test_" + file.string());
50         shared_ptr<FFmpegContent> content (new FFmpegContent (film, path)); 
51         film->examine_and_add_content (content);
52         wait_for_jobs ();
53         shared_ptr<Log> log (new NullLog);
54         FFmpegDecoder decoder (content, log);
55
56         BOOST_CHECK_CLOSE (decoder.video_content()->video_frame_rate(), fps, 0.01);
57         
58         VideoFrame const N = decoder.video_content()->video_length().frames (decoder.video_content()->video_frame_rate ());
59 #ifdef DCPOMATIC_DEBUG  
60         decoder.test_gaps = 0;
61 #endif  
62         for (VideoFrame i = 0; i < N; ++i) {
63                 list<ContentVideo> v;
64                 v = decoder.get_video (i, true);
65                 if (i < first) {
66                         BOOST_CHECK (v.empty ());
67                 } else {
68                         BOOST_CHECK (v.size() == 1);
69                         BOOST_CHECK_EQUAL (v.front().frame, i);
70                 }
71         }
72 #ifdef DCPOMATIC_DEBUG  
73         BOOST_CHECK_EQUAL (decoder.test_gaps, 0);
74 #endif
75 }
76
77 BOOST_AUTO_TEST_CASE (ffmpeg_decoder_sequential_test)
78 {
79         test ("boon_telly.mkv", 29.97, 0);
80         test ("Sintel_Trailer1.480p.DivX_Plus_HD.mkv", 24, 0);
81         test ("prophet_clip.mkv", 23.976, 12);
82 }
83