Restore ffmpeg_decoder_seek_test.
[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 seek() with 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 #include <iostream>
39
40 using std::cerr;
41 using std::vector;
42 using std::list;
43 using std::cout;
44 using boost::shared_ptr;
45 using boost::optional;
46
47 static optional<ContentVideo> stored;
48 static void
49 store (ContentVideo v)
50 {
51         stored = v;
52 }
53
54 static void
55 check (shared_ptr<FFmpegDecoder> decoder, int frame)
56 {
57         BOOST_REQUIRE (decoder->ffmpeg_content()->video_frame_rate ());
58         decoder->seek (ContentTime::from_frames (frame, decoder->ffmpeg_content()->video_frame_rate().get()), true);
59         stored = optional<ContentVideo> ();
60         while (!decoder->pass() && !stored) {}
61         BOOST_CHECK (stored->frame <= frame);
62 }
63
64 static void
65 test (boost::filesystem::path file, vector<int> frames)
66 {
67         boost::filesystem::path path = private_data / file;
68         BOOST_REQUIRE (boost::filesystem::exists (path));
69
70         shared_ptr<Film> film = new_test_film ("ffmpeg_decoder_seek_test_" + file.string());
71         shared_ptr<FFmpegContent> content (new FFmpegContent (film, path));
72         film->examine_and_add_content (content);
73         wait_for_jobs ();
74         shared_ptr<Log> log (new NullLog);
75         shared_ptr<FFmpegDecoder> decoder (new FFmpegDecoder (content, log));
76         decoder->video->Data.connect (bind (&store, _1));
77
78         for (vector<int>::const_iterator i = frames.begin(); i != frames.end(); ++i) {
79                 check (decoder, *i);
80         }
81 }
82
83 BOOST_AUTO_TEST_CASE (ffmpeg_decoder_seek_test)
84 {
85         vector<int> frames;
86
87         frames.clear ();
88         frames.push_back (0);
89         frames.push_back (42);
90         frames.push_back (999);
91         frames.push_back (0);
92
93         test ("boon_telly.mkv", frames);
94         test ("Sintel_Trailer1.480p.DivX_Plus_HD.mkv", frames);
95
96         frames.clear ();
97         frames.push_back (15);
98         frames.push_back (42);
99         frames.push_back (999);
100         frames.push_back (15);
101
102         test ("prophet_clip.mkv", frames);
103 }