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;
31 using boost::optional;
33 #define FFMPEG_SEEK_TEST_DEBUG 1
35 optional<DCPTime> first_video;
36 optional<DCPTime> first_audio;
37 shared_ptr<Film> film;
40 process_video (shared_ptr<PlayerImage>, Eyes, ColourConversion, bool, DCPTime t)
48 process_audio (shared_ptr<const AudioBuffers>, DCPTime t)
56 print_time (DCPTime t, float fps)
59 s << t << " " << (float(t) / TIME_HZ) << "s " << (float(t) * fps / TIME_HZ) << "f";
64 check (shared_ptr<Player> p, DCPTime t)
69 #if FFMPEG_SEEK_TEST_DEBUG == 1
70 cout << "\n-- Seek to " << print_time (t, 24) << "\n";
74 while (!first_video || !first_audio) {
78 #if FFMPEG_SEEK_TEST_DEBUG == 1
79 cout << "First video " << print_time (first_video.get(), 24) << "\n";
80 cout << "First audio " << print_time (first_audio.get(), 24) << "\n";
83 /* Outputs should be on or after seek time */
84 BOOST_CHECK (first_video.get() >= t);
85 BOOST_CHECK (first_audio.get() >= t);
86 /* And should be rounded to frame boundaries */
87 BOOST_CHECK ((first_video.get() % (TIME_HZ / film->video_frame_rate())) == 0);
88 BOOST_CHECK ((first_audio.get() % (TIME_HZ / film->audio_frame_rate())) == 0);
91 BOOST_AUTO_TEST_CASE (ffmpeg_seek_test)
93 film = new_test_film ("ffmpeg_audio_test");
94 film->set_name ("ffmpeg_audio_test");
95 film->set_container (Ratio::from_id ("185"));
96 shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/staircase.mov"));
97 c->set_ratio (Ratio::from_id ("185"));
98 film->examine_and_add_content (c);
102 shared_ptr<Player> player = film->make_player ();
103 player->Video.connect (boost::bind (&process_video, _1, _2, _3, _4, _5));
104 player->Audio.connect (boost::bind (&process_audio, _1, _2));
107 check (player, 0.1 * TIME_HZ);
108 check (player, 0.2 * TIME_HZ);
109 check (player, 0.3 * TIME_HZ);