TimedAudioBuffers<T>
pull (T time)
{
+ assert (time >= _last_pull);
+
TimedAudioBuffers<T> out;
F const to_return = _t_to_f (time - _last_pull);
(*i)->decoder->seek (ct, accurate);
}
- _video_position = _audio_position = t;
- _audio_merger.clear (t);
+ _video_position = time_round_up (t, TIME_HZ / _film->video_frame_rate());
+ _audio_position = time_round_up (t, TIME_HZ / _film->audio_frame_rate());
+
+ _audio_merger.clear (_audio_position);
if (!accurate) {
/* We just did an inaccurate seek, so it's likely that the next thing seen
return libdcp::Size (full_frame.width, rint (full_frame.width / ratio));
}
+
+DCPTime
+time_round_up (DCPTime t, DCPTime nearest)
+{
+ DCPTime const a = t + nearest - 1;
+ return a - (a % nearest);
+}
extern int dcp_audio_frame_rate (int);
extern int stride_round_up (int, int const *, int);
+extern DCPTime time_round_up (DCPTime, DCPTime);
extern std::multimap<std::string, std::string> read_key_value (std::istream& s);
extern int get_required_int (std::multimap<std::string, std::string> const & kv, std::string k);
extern float get_required_float (std::multimap<std::string, std::string> const & kv, std::string k);
using std::string;
using std::stringstream;
using boost::shared_ptr;
+using boost::optional;
#define FFMPEG_SEEK_TEST_DEBUG 1
-boost::optional<DCPTime> first_video;
-boost::optional<DCPTime> first_audio;
+optional<DCPTime> first_video;
+optional<DCPTime> first_audio;
+shared_ptr<Film> film;
static void
process_video (shared_ptr<PlayerImage>, Eyes, ColourConversion, bool, DCPTime t)
cout << "First video " << print_time (first_video.get(), 24) << "\n";
cout << "First audio " << print_time (first_audio.get(), 24) << "\n";
#endif
-
+
+ /* Outputs should be on or after seek time */
BOOST_CHECK (first_video.get() >= t);
BOOST_CHECK (first_audio.get() >= t);
+ /* And should be rounded to frame boundaries */
+ BOOST_CHECK ((first_video.get() % (TIME_HZ / film->video_frame_rate())) == 0);
+ BOOST_CHECK ((first_audio.get() % (TIME_HZ / film->audio_frame_rate())) == 0);
}
BOOST_AUTO_TEST_CASE (ffmpeg_seek_test)
{
- shared_ptr<Film> film = new_test_film ("ffmpeg_audio_test");
+ film = new_test_film ("ffmpeg_audio_test");
film->set_name ("ffmpeg_audio_test");
film->set_container (Ratio::from_id ("185"));
shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/staircase.mov"));
p.push_back ("foobar");
BOOST_CHECK_THROW (md5_digest (p, shared_ptr<Job> ()), std::runtime_error);
}
+
+/* Straightforward test of time_round_up_test */
+BOOST_AUTO_TEST_CASE (time_round_up_test)
+{
+ BOOST_CHECK_EQUAL (time_round_up (0, 2), 0);
+ BOOST_CHECK_EQUAL (time_round_up (1, 2), 2);
+ BOOST_CHECK_EQUAL (time_round_up (2, 2), 2);
+ BOOST_CHECK_EQUAL (time_round_up (3, 2), 4);
+
+ BOOST_CHECK_EQUAL (time_round_up (0, 42), 0);
+ BOOST_CHECK_EQUAL (time_round_up (1, 42), 42);
+ BOOST_CHECK_EQUAL (time_round_up (42, 42), 42);
+ BOOST_CHECK_EQUAL (time_round_up (43, 42), 84);
+}