Merge.
[dcpomatic.git] / test / ffmpeg_decoder_seek_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 #include <vector>
21 #include <boost/test/unit_test.hpp>
22 #include <boost/filesystem.hpp>
23 #include "lib/ffmpeg_content.h"
24 #include "lib/ffmpeg_decoder.h"
25 #include "lib/log.h"
26 #include "lib/film.h"
27 #include "test.h"
28
29 using std::cerr;
30 using std::vector;
31 using boost::shared_ptr;
32 using boost::optional;
33
34 static void
35 check (FFmpegDecoder& decoder, int frame)
36 {
37         optional<ContentVideo> v;
38         v = decoder.get_video (frame, true);
39         BOOST_CHECK (v);
40         BOOST_CHECK_EQUAL (v->frame, frame);
41 }
42
43 static void
44 test (boost::filesystem::path file, vector<int> frames)
45 {
46         boost::filesystem::path path = private_data / file;
47         if (!boost::filesystem::exists (path)) {
48                 cerr << "Skipping test: " << path.string() << " not found.\n";
49                 return;
50         }
51
52         shared_ptr<Film> film = new_test_film ("ffmpeg_decoder_seek_test_" + file.string());
53         shared_ptr<FFmpegContent> content (new FFmpegContent (film, path)); 
54         film->examine_and_add_content (content);
55         wait_for_jobs ();
56         shared_ptr<Log> log (new NullLog);
57         FFmpegDecoder decoder (content, log);
58
59         for (vector<int>::const_iterator i = frames.begin(); i != frames.end(); ++i) {
60                 check (decoder, *i);
61         }
62 }
63
64 BOOST_AUTO_TEST_CASE (ffmpeg_decoder_seek_test)
65 {
66         vector<int> frames;
67         
68         frames.clear ();
69         frames.push_back (0);
70         frames.push_back (42);
71         frames.push_back (999);
72         frames.push_back (0);
73
74         test ("boon_telly.mkv", frames);
75         test ("Sintel_Trailer1.480p.DivX_Plus_HD.mkv", frames);
76         
77         frames.clear ();
78         frames.push_back (15);
79         frames.push_back (42);
80         frames.push_back (999);
81         frames.push_back (15);
82         
83         test ("prophet_clip.mkv", frames);
84 }
85