operator bool on Time is a really bad idea; removed it and fixed lots of bugs.
[dcpomatic.git] / test / ffmpeg_seek_test.cc
index 7014bf1b0d7aa3b5c57e75f6d6585d413dd29554..c25a071deedb9fd082cfe8919ab4448baa5c50a3 100644 (file)
 
 */
 
+/** @file  test/ffmpeg_seek_test.cc
+ *  @brief Test seek using Player with an FFmpegDecoder; note that the player
+ *  can hide problems with FFmpegDecoder seeking as it will skip frames / insert
+ *  black as it sees fit.
+ */
+
 #include <boost/test/unit_test.hpp>
 #include "lib/player.h"
 #include "lib/ffmpeg_decoder.h"
@@ -28,14 +34,16 @@ using std::cout;
 using std::string;
 using std::stringstream;
 using boost::shared_ptr;
+using boost::optional;
 
 #define FFMPEG_SEEK_TEST_DEBUG 1
 
-boost::optional<Time> first_video;
-boost::optional<Time> first_audio;
+optional<DCPTime> first_video;
+optional<DCPTime> first_audio;
+shared_ptr<Film> film;
 
 static void
-process_video (shared_ptr<PlayerImage>, Eyes, ColourConversion, bool, Time t)
+process_video (shared_ptr<PlayerImage>, Eyes, ColourConversion, bool, DCPTime t)
 {
        if (!first_video) {
                first_video = t;
@@ -43,7 +51,7 @@ process_video (shared_ptr<PlayerImage>, Eyes, ColourConversion, bool, Time t)
 }
 
 static void
-process_audio (shared_ptr<const AudioBuffers>, Time t)
+process_audio (shared_ptr<const AudioBuffers>, DCPTime t)
 {
        if (!first_audio) {
                first_audio = t;
@@ -51,15 +59,15 @@ process_audio (shared_ptr<const AudioBuffers>, Time t)
 }
 
 static string
-print_time (Time t, float fps)
+print_time (DCPTime t, float fps)
 {
        stringstream s;
-       s << t << " " << (float(t) / TIME_HZ) << "s " << (float(t) * fps / TIME_HZ) << "f";
+       s << t.seconds() << "s " << t.frames (fps) << "f";
        return s.str ();
 }
 
 static void
-check (shared_ptr<Player> p, Time t)
+check (shared_ptr<Player> p, DCPTime t)
 {
        first_video.reset ();
        first_audio.reset ();
@@ -77,18 +85,23 @@ check (shared_ptr<Player> p, Time 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_EQUAL (first_video.get(), first_video.get().round_up (film->video_frame_rate()));
+       BOOST_CHECK_EQUAL (first_audio.get(), first_audio.get().round_up (film->audio_frame_rate()));
 }
 
+/* Test basic seeking */
 BOOST_AUTO_TEST_CASE (ffmpeg_seek_test)
 {
-       shared_ptr<Film> film = new_test_film ("ffmpeg_audio_test");
-       film->set_name ("ffmpeg_audio_test");
+       film = new_test_film ("ffmpeg_seek_test");
+       film->set_name ("ffmpeg_seek_test");
        film->set_container (Ratio::from_id ("185"));
        shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/staircase.mov"));
-       c->set_ratio (Ratio::from_id ("185"));
+       c->set_scale (VideoContentScale (Ratio::from_id ("185")));
        film->examine_and_add_content (c);
 
        wait_for_jobs ();
@@ -97,10 +110,8 @@ BOOST_AUTO_TEST_CASE (ffmpeg_seek_test)
        player->Video.connect (boost::bind (&process_video, _1, _2, _3, _4, _5));
        player->Audio.connect (boost::bind (&process_audio, _1, _2));
 
-       check (player, 0);
-       check (player, 0.1 * TIME_HZ);
-       check (player, 0.2 * TIME_HZ);
-       check (player, 0.3 * TIME_HZ);
+       check (player, DCPTime::from_seconds (0));
+       check (player, DCPTime::from_seconds (0.1));
+       check (player, DCPTime::from_seconds (0.2));
+       check (player, DCPTime::from_seconds (0.3));
 }
-
-