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