2 Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
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.
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.
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.
20 /** @file test/ffmpeg_seek_test.cc
21 * @brief Test seek using Player with an FFmpegDecoder; note that the player
22 * can hide problems with FFmpegDecoder seeking as it will skip frames / insert
23 * black as it sees fit.
26 #include <boost/test/unit_test.hpp>
27 #include "lib/player.h"
28 #include "lib/ffmpeg_decoder.h"
30 #include "lib/ratio.h"
35 using std::stringstream;
36 using boost::shared_ptr;
37 using boost::optional;
39 #define FFMPEG_SEEK_TEST_DEBUG 1
41 optional<DCPTime> first_video;
42 optional<DCPTime> first_audio;
43 shared_ptr<Film> film;
46 process_video (shared_ptr<PlayerImage>, Eyes, ColourConversion, bool, DCPTime t)
54 process_audio (shared_ptr<const AudioBuffers>, DCPTime t)
62 print_time (DCPTime t, float fps)
65 s << t << " " << (float(t) / TIME_HZ) << "s " << (float(t) * fps / TIME_HZ) << "f";
70 check (shared_ptr<Player> p, DCPTime t)
75 #if FFMPEG_SEEK_TEST_DEBUG == 1
76 cout << "\n-- Seek to " << print_time (t, 24) << "\n";
80 while (!first_video || !first_audio) {
84 #if FFMPEG_SEEK_TEST_DEBUG == 1
85 cout << "First video " << print_time (first_video.get(), 24) << "\n";
86 cout << "First audio " << print_time (first_audio.get(), 24) << "\n";
89 /* Outputs should be on or after seek time */
90 BOOST_CHECK (first_video.get() >= t);
91 BOOST_CHECK (first_audio.get() >= t);
92 /* And should be rounded to frame boundaries */
93 BOOST_CHECK ((first_video.get() % (TIME_HZ / film->video_frame_rate())) == 0);
94 BOOST_CHECK ((first_audio.get() % (TIME_HZ / film->audio_frame_rate())) == 0);
97 /* Test basic seeking */
98 BOOST_AUTO_TEST_CASE (ffmpeg_seek_test)
100 film = new_test_film ("ffmpeg_seek_test");
101 film->set_name ("ffmpeg_seek_test");
102 film->set_container (Ratio::from_id ("185"));
103 shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/staircase.mov"));
104 c->set_ratio (Ratio::from_id ("185"));
105 film->examine_and_add_content (c);
109 shared_ptr<Player> player = film->make_player ();
110 player->Video.connect (boost::bind (&process_video, _1, _2, _3, _4, _5));
111 player->Audio.connect (boost::bind (&process_audio, _1, _2));
114 check (player, 0.1 * TIME_HZ);
115 check (player, 0.2 * TIME_HZ);
116 check (player, 0.3 * TIME_HZ);