Rename some methods.
[dcpomatic.git] / test / ffmpeg_decoder_seek_test.cc
1 /*
2     Copyright (C) 2014-2015 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_seek_test.cc
21  *  @brief Check that get_video() returns the frame indexes that we ask for
22  *  for FFmpegDecoder.
23  *
24  *  This doesn't check that the contents of those frames are right, which
25  *  it probably should.
26  */
27
28 #include "lib/ffmpeg_content.h"
29 #include "lib/ffmpeg_decoder.h"
30 #include "lib/null_log.h"
31 #include "lib/film.h"
32 #include "lib/content_video.h"
33 #include "lib/video_decoder.h"
34 #include "test.h"
35 #include <boost/test/unit_test.hpp>
36 #include <boost/filesystem.hpp>
37 #include <vector>
38
39 using std::cerr;
40 using std::vector;
41 using std::list;
42 using boost::shared_ptr;
43 using boost::optional;
44
45 static void
46 check (shared_ptr<FFmpegDecoder> decoder, int frame)
47 {
48         list<ContentVideo> v;
49         v = decoder->video->get (frame, true);
50         BOOST_CHECK (v.size() == 1);
51         BOOST_CHECK_EQUAL (v.front().frame, frame);
52 }
53
54 static void
55 test (boost::filesystem::path file, vector<int> frames)
56 {
57         boost::filesystem::path path = private_data / file;
58         if (!boost::filesystem::exists (path)) {
59                 cerr << "Skipping test: " << path.string() << " not found.\n";
60                 return;
61         }
62
63         shared_ptr<Film> film = new_test_film ("ffmpeg_decoder_seek_test_" + file.string());
64         shared_ptr<FFmpegContent> content (new FFmpegContent (film, path));
65         film->examine_and_add_content (content);
66         wait_for_jobs ();
67         shared_ptr<Log> log (new NullLog);
68         shared_ptr<FFmpegDecoder> decoder (new FFmpegDecoder (content, log, false));
69
70         for (vector<int>::const_iterator i = frames.begin(); i != frames.end(); ++i) {
71                 check (decoder, *i);
72         }
73 }
74
75 BOOST_AUTO_TEST_CASE (ffmpeg_decoder_seek_test)
76 {
77         vector<int> frames;
78
79         frames.clear ();
80         frames.push_back (0);
81         frames.push_back (42);
82         frames.push_back (999);
83         frames.push_back (0);
84
85         test ("boon_telly.mkv", frames);
86         test ("Sintel_Trailer1.480p.DivX_Plus_HD.mkv", frames);
87
88         frames.clear ();
89         frames.push_back (15);
90         frames.push_back (42);
91         frames.push_back (999);
92         frames.push_back (15);
93
94         test ("prophet_clip.mkv", frames);
95 }