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 #include <boost/test/unit_test.hpp>
21 #include "lib/player.h"
22 #include "lib/ffmpeg_decoder.h"
24 #include "lib/ratio.h"
29 using std::stringstream;
30 using boost::shared_ptr;
32 #define FFMPEG_SEEK_TEST_DEBUG 1
34 boost::optional<DCPTime> first_video;
35 boost::optional<DCPTime> first_audio;
38 process_video (shared_ptr<PlayerImage>, Eyes, ColourConversion, bool, DCPTime t)
46 process_audio (shared_ptr<const AudioBuffers>, DCPTime t)
54 print_time (DCPTime t, float fps)
57 s << t << " " << (float(t) / TIME_HZ) << "s " << (float(t) * fps / TIME_HZ) << "f";
62 check (shared_ptr<Player> p, DCPTime t)
67 #if FFMPEG_SEEK_TEST_DEBUG == 1
68 cout << "\n-- Seek to " << print_time (t, 24) << "\n";
72 while (!first_video || !first_audio) {
76 #if FFMPEG_SEEK_TEST_DEBUG == 1
77 cout << "First video " << print_time (first_video.get(), 24) << "\n";
78 cout << "First audio " << print_time (first_audio.get(), 24) << "\n";
81 BOOST_CHECK (first_video.get() >= t);
82 BOOST_CHECK (first_audio.get() >= t);
85 BOOST_AUTO_TEST_CASE (ffmpeg_seek_test)
87 shared_ptr<Film> film = new_test_film ("ffmpeg_audio_test");
88 film->set_name ("ffmpeg_audio_test");
89 film->set_container (Ratio::from_id ("185"));
90 shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/staircase.mov"));
91 c->set_ratio (Ratio::from_id ("185"));
92 film->examine_and_add_content (c);
96 shared_ptr<Player> player = film->make_player ();
97 player->Video.connect (boost::bind (&process_video, _1, _2, _3, _4, _5));
98 player->Audio.connect (boost::bind (&process_audio, _1, _2));
101 check (player, 0.1 * TIME_HZ);
102 check (player, 0.2 * TIME_HZ);
103 check (player, 0.3 * TIME_HZ);