summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/ffmpeg_audio_test.cc4
-rw-r--r--test/ffmpeg_pts_offset.cc5
-rw-r--r--test/ffmpeg_seek_test.cc117
-rw-r--r--test/frame_rate_test.cc52
-rw-r--r--test/long_ffmpeg_seek_test.cc105
-rw-r--r--test/play_test.cc14
-rw-r--r--test/repeat_frame_test.cc50
-rw-r--r--test/resampler_test.cc8
-rw-r--r--test/seek_zero_test.cc57
-rw-r--r--test/skip_frame_test.cc51
-rw-r--r--test/subrip_test.cc196
-rw-r--r--test/test.cc22
-rw-r--r--test/test.h5
-rw-r--r--test/util_test.cc14
-rw-r--r--test/wscript19
15 files changed, 677 insertions, 42 deletions
diff --git a/test/ffmpeg_audio_test.cc b/test/ffmpeg_audio_test.cc
index 65c29325c..bba05ae9b 100644
--- a/test/ffmpeg_audio_test.cc
+++ b/test/ffmpeg_audio_test.cc
@@ -17,6 +17,10 @@
*/
+/** @file test/ffmpeg_audio_test.cc
+ * @brief A simple test of reading audio from an FFmpeg file.
+ */
+
#include <boost/test/unit_test.hpp>
#include <libdcp/cpl.h>
#include <libdcp/dcp.h>
diff --git a/test/ffmpeg_pts_offset.cc b/test/ffmpeg_pts_offset.cc
index 6caf0d07a..53303f154 100644
--- a/test/ffmpeg_pts_offset.cc
+++ b/test/ffmpeg_pts_offset.cc
@@ -38,7 +38,6 @@ BOOST_AUTO_TEST_CASE (ffmpeg_pts_offset_test)
content->_audio_stream->first_audio = 0;
FFmpegDecoder decoder (film, content, true, true);
BOOST_CHECK_EQUAL (decoder._pts_offset, 0);
- BOOST_CHECK_EQUAL (decoder._pts_offset, 0);
}
{
@@ -47,7 +46,6 @@ BOOST_AUTO_TEST_CASE (ffmpeg_pts_offset_test)
content->_audio_stream->first_audio = 600;
FFmpegDecoder decoder (film, content, true, true);
BOOST_CHECK_EQUAL (decoder._pts_offset, -600);
- BOOST_CHECK_EQUAL (decoder._pts_offset, -600);
}
{
@@ -56,7 +54,6 @@ BOOST_AUTO_TEST_CASE (ffmpeg_pts_offset_test)
content->_audio_stream->first_audio = 0;
FFmpegDecoder decoder (film, content, true, true);
BOOST_CHECK_EQUAL (decoder._pts_offset, 0);
- BOOST_CHECK_EQUAL (decoder._pts_offset, 0);
}
{
@@ -66,7 +63,6 @@ BOOST_AUTO_TEST_CASE (ffmpeg_pts_offset_test)
content->_audio_stream->first_audio = 0;
FFmpegDecoder decoder (film, content, true, true);
BOOST_CHECK_CLOSE (decoder._pts_offset, (frame - 0.0215), 0.00001);
- BOOST_CHECK_CLOSE (decoder._pts_offset, (frame - 0.0215), 0.00001);
}
{
@@ -76,6 +72,5 @@ BOOST_AUTO_TEST_CASE (ffmpeg_pts_offset_test)
content->_audio_stream->first_audio = 4.1;
FFmpegDecoder decoder (film, content, true, true);
BOOST_CHECK_EQUAL (decoder._pts_offset, (frame - 0.0215) - 4.1);
- BOOST_CHECK_EQUAL (decoder._pts_offset, (frame - 0.0215) - 4.1);
}
}
diff --git a/test/ffmpeg_seek_test.cc b/test/ffmpeg_seek_test.cc
new file mode 100644
index 000000000..3c175f08c
--- /dev/null
+++ b/test/ffmpeg_seek_test.cc
@@ -0,0 +1,117 @@
+/*
+ Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+/** @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"
+#include "lib/film.h"
+#include "lib/ratio.h"
+#include "test.h"
+
+using std::cout;
+using std::string;
+using std::stringstream;
+using boost::shared_ptr;
+using boost::optional;
+
+#define FFMPEG_SEEK_TEST_DEBUG 1
+
+optional<DCPTime> first_video;
+optional<DCPTime> first_audio;
+shared_ptr<Film> film;
+
+static void
+process_video (shared_ptr<PlayerImage>, Eyes, ColourConversion, bool, DCPTime t)
+{
+ if (!first_video) {
+ first_video = t;
+ }
+}
+
+static void
+process_audio (shared_ptr<const AudioBuffers>, DCPTime t)
+{
+ if (!first_audio) {
+ first_audio = t;
+ }
+}
+
+static string
+print_time (DCPTime t, float fps)
+{
+ stringstream s;
+ s << t << " " << (float(t) / TIME_HZ) << "s " << (float(t) * fps / TIME_HZ) << "f";
+ return s.str ();
+}
+
+static void
+check (shared_ptr<Player> p, DCPTime t)
+{
+ first_video.reset ();
+ first_audio.reset ();
+
+#if FFMPEG_SEEK_TEST_DEBUG == 1
+ cout << "\n-- Seek to " << print_time (t, 24) << "\n";
+#endif
+
+ p->seek (t, true);
+ while (!first_video || !first_audio) {
+ p->pass ();
+ }
+
+#if FFMPEG_SEEK_TEST_DEBUG == 1
+ 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);
+}
+
+/* Test basic seeking */
+BOOST_AUTO_TEST_CASE (ffmpeg_seek_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"));
+ film->examine_and_add_content (c);
+
+ wait_for_jobs ();
+
+ shared_ptr<Player> player = film->make_player ();
+ 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);
+}
diff --git a/test/frame_rate_test.cc b/test/frame_rate_test.cc
index fdfdcf452..2135b3738 100644
--- a/test/frame_rate_test.cc
+++ b/test/frame_rate_test.cc
@@ -47,91 +47,102 @@ BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_single)
content->_video_frame_rate = 60;
int best = film->playlist()->best_dcp_frame_rate ();
- FrameRateConversion frc = FrameRateConversion (60, best);
+ FrameRateChange frc = FrameRateChange (60, best);
BOOST_CHECK_EQUAL (best, 30);
BOOST_CHECK_EQUAL (frc.skip, true);
BOOST_CHECK_EQUAL (frc.repeat, 1);
BOOST_CHECK_EQUAL (frc.change_speed, false);
+ BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1);
content->_video_frame_rate = 50;
best = film->playlist()->best_dcp_frame_rate ();
- frc = FrameRateConversion (50, best);
+ frc = FrameRateChange (50, best);
BOOST_CHECK_EQUAL (best, 25);
BOOST_CHECK_EQUAL (frc.skip, true);
BOOST_CHECK_EQUAL (frc.repeat, 1);
BOOST_CHECK_EQUAL (frc.change_speed, false);
+ BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1);
content->_video_frame_rate = 48;
best = film->playlist()->best_dcp_frame_rate ();
- frc = FrameRateConversion (48, best);
+ frc = FrameRateChange (48, best);
BOOST_CHECK_EQUAL (best, 24);
BOOST_CHECK_EQUAL (frc.skip, true);
BOOST_CHECK_EQUAL (frc.repeat, 1);
BOOST_CHECK_EQUAL (frc.change_speed, false);
+ BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1);
content->_video_frame_rate = 30;
best = film->playlist()->best_dcp_frame_rate ();
- frc = FrameRateConversion (30, best);
+ frc = FrameRateChange (30, best);
BOOST_CHECK_EQUAL (best, 30);
BOOST_CHECK_EQUAL (frc.skip, false);
BOOST_CHECK_EQUAL (frc.repeat, 1);
BOOST_CHECK_EQUAL (frc.change_speed, false);
+ BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1);
content->_video_frame_rate = 29.97;
best = film->playlist()->best_dcp_frame_rate ();
- frc = FrameRateConversion (29.97, best);
+ frc = FrameRateChange (29.97, best);
BOOST_CHECK_EQUAL (best, 30);
BOOST_CHECK_EQUAL (frc.skip, false);
BOOST_CHECK_EQUAL (frc.repeat, 1);
BOOST_CHECK_EQUAL (frc.change_speed, true);
+ BOOST_CHECK_CLOSE (frc.speed_up, 30 / 29.97, 0.1);
content->_video_frame_rate = 25;
best = film->playlist()->best_dcp_frame_rate ();
- frc = FrameRateConversion (25, best);
+ frc = FrameRateChange (25, best);
BOOST_CHECK_EQUAL (best, 25);
BOOST_CHECK_EQUAL (frc.skip, false);
BOOST_CHECK_EQUAL (frc.repeat, 1);
BOOST_CHECK_EQUAL (frc.change_speed, false);
+ BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1);
content->_video_frame_rate = 24;
best = film->playlist()->best_dcp_frame_rate ();
- frc = FrameRateConversion (24, best);
+ frc = FrameRateChange (24, best);
BOOST_CHECK_EQUAL (best, 24);
BOOST_CHECK_EQUAL (frc.skip, false);
BOOST_CHECK_EQUAL (frc.repeat, 1);
BOOST_CHECK_EQUAL (frc.change_speed, false);
+ BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1);
content->_video_frame_rate = 14.5;
best = film->playlist()->best_dcp_frame_rate ();
- frc = FrameRateConversion (14.5, best);
+ frc = FrameRateChange (14.5, best);
BOOST_CHECK_EQUAL (best, 30);
BOOST_CHECK_EQUAL (frc.skip, false);
BOOST_CHECK_EQUAL (frc.repeat, 2);
BOOST_CHECK_EQUAL (frc.change_speed, true);
+ BOOST_CHECK_CLOSE (frc.speed_up, 15 / 14.5, 0.1);
content->_video_frame_rate = 12.6;
best = film->playlist()->best_dcp_frame_rate ();
- frc = FrameRateConversion (12.6, best);
+ frc = FrameRateChange (12.6, best);
BOOST_CHECK_EQUAL (best, 25);
BOOST_CHECK_EQUAL (frc.skip, false);
BOOST_CHECK_EQUAL (frc.repeat, 2);
BOOST_CHECK_EQUAL (frc.change_speed, true);
+ BOOST_CHECK_CLOSE (frc.speed_up, 25 / 25.2, 0.1);
content->_video_frame_rate = 12.4;
best = film->playlist()->best_dcp_frame_rate ();
- frc = FrameRateConversion (12.4, best);
+ frc = FrameRateChange (12.4, best);
BOOST_CHECK_EQUAL (best, 25);
BOOST_CHECK_EQUAL (frc.skip, false);
BOOST_CHECK_EQUAL (frc.repeat, 2);
BOOST_CHECK_EQUAL (frc.change_speed, true);
+ BOOST_CHECK_CLOSE (frc.speed_up, 25 / 24.8, 0.1);
content->_video_frame_rate = 12;
best = film->playlist()->best_dcp_frame_rate ();
- frc = FrameRateConversion (12, best);
+ frc = FrameRateChange (12, best);
BOOST_CHECK_EQUAL (best, 24);
BOOST_CHECK_EQUAL (frc.skip, false);
BOOST_CHECK_EQUAL (frc.repeat, 2);
BOOST_CHECK_EQUAL (frc.change_speed, false);
+ BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1);
/* Now add some more rates and see if it will use them
in preference to skip/repeat.
@@ -144,34 +155,38 @@ BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_single)
content->_video_frame_rate = 60;
best = film->playlist()->best_dcp_frame_rate ();
- frc = FrameRateConversion (60, best);
+ frc = FrameRateChange (60, best);
BOOST_CHECK_EQUAL (best, 60);
BOOST_CHECK_EQUAL (frc.skip, false);
BOOST_CHECK_EQUAL (frc.repeat, 1);
BOOST_CHECK_EQUAL (frc.change_speed, false);
+ BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1);
content->_video_frame_rate = 50;
best = film->playlist()->best_dcp_frame_rate ();
- frc = FrameRateConversion (50, best);
+ frc = FrameRateChange (50, best);
BOOST_CHECK_EQUAL (best, 50);
BOOST_CHECK_EQUAL (frc.skip, false);
BOOST_CHECK_EQUAL (frc.repeat, 1);
BOOST_CHECK_EQUAL (frc.change_speed, false);
+ BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1);
content->_video_frame_rate = 48;
best = film->playlist()->best_dcp_frame_rate ();
- frc = FrameRateConversion (48, best);
+ frc = FrameRateChange (48, best);
BOOST_CHECK_EQUAL (best, 48);
BOOST_CHECK_EQUAL (frc.skip, false);
BOOST_CHECK_EQUAL (frc.repeat, 1);
BOOST_CHECK_EQUAL (frc.change_speed, false);
+ BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1);
/* Check some out-there conversions (not the best) */
- frc = FrameRateConversion (14.99, 24);
+ frc = FrameRateChange (14.99, 24);
BOOST_CHECK_EQUAL (frc.skip, false);
BOOST_CHECK_EQUAL (frc.repeat, 2);
BOOST_CHECK_EQUAL (frc.change_speed, true);
+ BOOST_CHECK_CLOSE (frc.speed_up, 24 / (2 * 14.99), 0.1);
/* Check some conversions with limited DCP targets */
@@ -181,14 +196,15 @@ BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_single)
content->_video_frame_rate = 25;
best = film->playlist()->best_dcp_frame_rate ();
- frc = FrameRateConversion (25, best);
+ frc = FrameRateChange (25, best);
BOOST_CHECK_EQUAL (best, 24);
BOOST_CHECK_EQUAL (frc.skip, false);
BOOST_CHECK_EQUAL (frc.repeat, 1);
BOOST_CHECK_EQUAL (frc.change_speed, true);
+ BOOST_CHECK_CLOSE (frc.speed_up, 24.0 / 25, 0.1);
}
-/* Test Playlist::best_dcp_frame_rate and FrameRateConversion
+/* Test Playlist::best_dcp_frame_rate and FrameRateChange
with two pieces of content.
*/
BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_double)
@@ -266,7 +282,7 @@ BOOST_AUTO_TEST_CASE (audio_sampling_rate_test)
content->_video_frame_rate = 14.99;
film->set_video_frame_rate (25);
content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 16000, 0)));
- /* The FrameRateConversion within output_audio_frame_rate should choose to double-up
+ /* The FrameRateChange within output_audio_frame_rate should choose to double-up
the 14.99 fps video to 30 and then run it slow at 25.
*/
BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), rint (48000 * 2 * 14.99 / 25));
diff --git a/test/long_ffmpeg_seek_test.cc b/test/long_ffmpeg_seek_test.cc
new file mode 100644
index 000000000..5285d4481
--- /dev/null
+++ b/test/long_ffmpeg_seek_test.cc
@@ -0,0 +1,105 @@
+/*
+ Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <boost/test/unit_test.hpp>
+#include "lib/player.h"
+#include "lib/ffmpeg_decoder.h"
+#include "lib/film.h"
+#include "lib/ratio.h"
+#include "test.h"
+
+using std::cout;
+using std::string;
+using std::stringstream;
+using boost::shared_ptr;
+
+#define LONG_FFMPEG_SEEK_TEST_DEBUG 1
+
+boost::optional<DCPTime> first_video;
+boost::optional<DCPTime> first_audio;
+
+static void
+process_video (shared_ptr<PlayerImage>, Eyes, ColourConversion, bool, DCPTime t)
+{
+ if (!first_video) {
+ first_video = t;
+ }
+}
+
+static void
+process_audio (shared_ptr<const AudioBuffers>, DCPTime t)
+{
+ if (!first_audio) {
+ first_audio = t;
+ }
+}
+
+static string
+print_time (DCPTime t, float fps)
+{
+ stringstream s;
+ s << t << " " << (float(t) / TIME_HZ) << "s " << (float(t) * fps / TIME_HZ) << "f";
+ return s.str ();
+}
+
+static void
+check (shared_ptr<Player> p, DCPTime t)
+{
+ first_video.reset ();
+ first_audio.reset ();
+
+#if LONG_FFMPEG_SEEK_TEST_DEBUG == 1
+ cout << "\n-- Seek to " << print_time (t, 24) << "\n";
+#endif
+
+ p->seek (t, true);
+ while (!first_video || !first_audio) {
+ p->pass ();
+ }
+
+#if LONG_FFMPEG_SEEK_TEST_DEBUG == 1
+ cout << "First video " << print_time (first_video.get(), 24) << "\n";
+ cout << "First audio " << print_time (first_audio.get(), 24) << "\n";
+#endif
+
+ BOOST_CHECK (first_video.get() >= t);
+ BOOST_CHECK (first_audio.get() >= t);
+}
+
+BOOST_AUTO_TEST_CASE (long_ffmpeg_seek_test)
+{
+ shared_ptr<Film> film = new_test_film ("long_ffmpeg_audio_test");
+ film->set_name ("long_ffmpeg_audio_test");
+ film->set_container (Ratio::from_id ("185"));
+ shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/long_data/dolby_aurora.vob"));
+ c->set_ratio (Ratio::from_id ("185"));
+ film->examine_and_add_content (c);
+
+ wait_for_jobs ();
+
+ shared_ptr<Player> player = film->make_player ();
+ player->Video.connect (boost::bind (&process_video, _1, _2, _3, _4, _5));
+ player->Audio.connect (boost::bind (&process_audio, _1, _2));
+
+ for (float i = 0; i < 10; i += 0.1) {
+ check (player, i * TIME_HZ);
+ }
+}
+
+
diff --git a/test/play_test.cc b/test/play_test.cc
index dfa597431..54fe2699f 100644
--- a/test/play_test.cc
+++ b/test/play_test.cc
@@ -34,7 +34,7 @@ struct Video
{
boost::shared_ptr<Content> content;
boost::shared_ptr<const Image> image;
- Time time;
+ DCPTime time;
};
class PlayerWrapper
@@ -46,11 +46,11 @@ public:
_player->Video.connect (bind (&PlayerWrapper::process_video, this, _1, _2, _5));
}
- void process_video (shared_ptr<PlayerImage> i, bool, Time t)
+ void process_video (shared_ptr<PlayerImage> i, bool, DCPTime t)
{
Video v;
v.content = _player->_last_video;
- v.image = i->image ();
+ v.image = i->image (PIX_FMT_RGB24, false);
v.time = t;
_queue.push_front (v);
}
@@ -67,7 +67,7 @@ public:
return v;
}
- void seek (Time t, bool ac)
+ void seek (DCPTime t, bool ac)
{
_player->seek (t, ac);
_queue.clear ();
@@ -106,8 +106,6 @@ BOOST_AUTO_TEST_CASE (play_test)
shared_ptr<Player> player = film->make_player ();
PlayerWrapper wrap (player);
- /* Seek and audio don't get on at the moment */
- player->disable_audio ();
for (int i = 0; i < 32; ++i) {
optional<Video> v = wrap.get_video ();
@@ -119,10 +117,10 @@ BOOST_AUTO_TEST_CASE (play_test)
}
}
- player->seek (10 * TIME_HZ / 25, true);
+ player->seek (6 * TIME_HZ / 25, true);
optional<Video> v = wrap.get_video ();
BOOST_CHECK (v);
- BOOST_CHECK_EQUAL (v.get().time, 10 * TIME_HZ / 25);
+ BOOST_CHECK_EQUAL (v.get().time, 6 * TIME_HZ / 25);
}
#endif
diff --git a/test/repeat_frame_test.cc b/test/repeat_frame_test.cc
new file mode 100644
index 000000000..73b9ad615
--- /dev/null
+++ b/test/repeat_frame_test.cc
@@ -0,0 +1,50 @@
+/*
+ Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <boost/test/unit_test.hpp>
+#include "test.h"
+#include "lib/film.h"
+#include "lib/ratio.h"
+#include "lib/ffmpeg_content.h"
+#include "lib/dcp_content_type.h"
+
+using boost::shared_ptr;
+
+/* Test the repeat of frames by the player when putting a 24fps
+ source into a 48fps DCP.
+*/
+BOOST_AUTO_TEST_CASE (repeat_frame_test)
+{
+ shared_ptr<Film> film = new_test_film ("repeat_frame_test");
+ film->set_name ("repeat_frame_test");
+ film->set_container (Ratio::from_id ("185"));
+ film->set_dcp_content_type (DCPContentType::from_pretty_name ("Test"));
+ shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/red_24.mp4"));
+ c->set_ratio (Ratio::from_id ("185"));
+ film->examine_and_add_content (c);
+
+ wait_for_jobs ();
+
+ film->set_video_frame_rate (48);
+ film->make_dcp ();
+ wait_for_jobs ();
+
+ check_dcp ("test/data/repeat_frame_test", film->dir (film->dcp_name ()));
+}
+
diff --git a/test/resampler_test.cc b/test/resampler_test.cc
index 9247159a7..3be251b3a 100644
--- a/test/resampler_test.cc
+++ b/test/resampler_test.cc
@@ -34,13 +34,13 @@ resampler_test_one (int from, int to)
/* 3 hours */
int64_t const N = int64_t (from) * 60 * 60 * 3;
-
+
+ /* XXX: no longer checks anything */
for (int64_t i = 0; i < N; i += 1000) {
shared_ptr<AudioBuffers> a (new AudioBuffers (1, 1000));
a->make_silent ();
- pair<shared_ptr<const AudioBuffers>, AudioContent::Frame> r = resamp.run (a, i);
- BOOST_CHECK_EQUAL (r.second, total_out);
- total_out += r.first->frames ();
+ shared_ptr<const AudioBuffers> r = resamp.run (a);
+ total_out += r->frames ();
}
}
diff --git a/test/seek_zero_test.cc b/test/seek_zero_test.cc
new file mode 100644
index 000000000..c20c99ee7
--- /dev/null
+++ b/test/seek_zero_test.cc
@@ -0,0 +1,57 @@
+/*
+ Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+/** @file test/seek_zero_test.cc
+ * @brief Test seek to zero with a raw FFmpegDecoder (without the player
+ * confusing things as it might in ffmpeg_seek_test).
+ */
+
+#include <boost/test/unit_test.hpp>
+#include "lib/film.h"
+#include "lib/ffmpeg_content.h"
+#include "lib/ratio.h"
+#include "lib/dcp_content_type.h"
+#include "lib/ffmpeg_decoder.h"
+#include "test.h"
+
+using std::cout;
+using boost::shared_ptr;
+using boost::dynamic_pointer_cast;
+
+BOOST_AUTO_TEST_CASE (seek_zero_test)
+{
+ shared_ptr<Film> film = new_test_film ("seek_zero_test");
+ film->set_name ("seek_zero_test");
+ film->set_container (Ratio::from_id ("185"));
+ film->set_dcp_content_type (DCPContentType::from_pretty_name ("Test"));
+ shared_ptr<FFmpegContent> content (new FFmpegContent (film, "test/data/count300bd48.m2ts"));
+ content->set_ratio (Ratio::from_id ("185"));
+ film->examine_and_add_content (content);
+ wait_for_jobs ();
+
+ FFmpegDecoder decoder (film, content, true, false);
+ shared_ptr<DecodedVideo> a = dynamic_pointer_cast<DecodedVideo> (decoder.peek ());
+ decoder.seek (0, true);
+ shared_ptr<DecodedVideo> b = dynamic_pointer_cast<DecodedVideo> (decoder.peek ());
+
+ /* a will be after no seek, and b after a seek to zero, which should
+ have the same effect.
+ */
+ BOOST_CHECK_EQUAL (a->frame, b->frame);
+}
diff --git a/test/skip_frame_test.cc b/test/skip_frame_test.cc
new file mode 100644
index 000000000..4ac5192f2
--- /dev/null
+++ b/test/skip_frame_test.cc
@@ -0,0 +1,51 @@
+/*
+ Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <boost/test/unit_test.hpp>
+#include "test.h"
+#include "lib/film.h"
+#include "lib/ratio.h"
+#include "lib/ffmpeg_content.h"
+#include "lib/dcp_content_type.h"
+
+using boost::shared_ptr;
+
+/* Test the skip of frames by the player when putting a 48fps
+ source into a 24fps DCP.
+*/
+BOOST_AUTO_TEST_CASE (skip_frame_test)
+{
+ shared_ptr<Film> film = new_test_film ("skip_frame_test");
+ film->set_name ("skip_frame_test");
+ film->set_container (Ratio::from_id ("185"));
+ film->set_dcp_content_type (DCPContentType::from_pretty_name ("Test"));
+ shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/count300bd48.m2ts"));
+ c->set_ratio (Ratio::from_id ("185"));
+ film->examine_and_add_content (c);
+
+ wait_for_jobs ();
+ film->write_metadata ();
+
+ film->set_video_frame_rate (24);
+ film->make_dcp ();
+ wait_for_jobs ();
+
+ check_dcp ("test/data/skip_frame_test", film->dir (film->dcp_name ()));
+}
+
diff --git a/test/subrip_test.cc b/test/subrip_test.cc
new file mode 100644
index 000000000..12a77c1e1
--- /dev/null
+++ b/test/subrip_test.cc
@@ -0,0 +1,196 @@
+/*
+ Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <boost/test/unit_test.hpp>
+#include <libdcp/subtitle_asset.h>
+#include "lib/subrip.h"
+#include "lib/subrip_content.h"
+#include "lib/subrip_decoder.h"
+#include "lib/render_subtitles.h"
+#include "test.h"
+
+using std::list;
+using std::vector;
+using std::string;
+using boost::shared_ptr;
+using boost::dynamic_pointer_cast;
+
+/** Test SubRip::convert_time */
+BOOST_AUTO_TEST_CASE (subrip_time_test)
+{
+ BOOST_CHECK_EQUAL (SubRip::convert_time ("00:03:10,500"), rint (((3 * 60) + 10 + 0.5) * TIME_HZ));
+ BOOST_CHECK_EQUAL (SubRip::convert_time ("04:19:51,782"), rint (((4 * 3600) + (19 * 60) + 51 + 0.782) * TIME_HZ));
+}
+
+/** Test SubRip::convert_coordinate */
+BOOST_AUTO_TEST_CASE (subrip_coordinate_test)
+{
+ BOOST_CHECK_EQUAL (SubRip::convert_coordinate ("foo:42"), 42);
+ BOOST_CHECK_EQUAL (SubRip::convert_coordinate ("X1:999"), 999);
+}
+
+/** Test SubRip::convert_content */
+BOOST_AUTO_TEST_CASE (subrip_content_test)
+{
+ list<string> c;
+ list<SubRipSubtitlePiece> p;
+
+ c.push_back ("Hello world");
+ p = SubRip::convert_content (c);
+ BOOST_CHECK_EQUAL (p.size(), 1);
+ BOOST_CHECK_EQUAL (p.front().text, "Hello world");
+ c.clear ();
+
+ c.push_back ("<b>Hello world</b>");
+ p = SubRip::convert_content (c);
+ BOOST_CHECK_EQUAL (p.size(), 1);
+ BOOST_CHECK_EQUAL (p.front().text, "Hello world");
+ BOOST_CHECK_EQUAL (p.front().bold, true);
+ c.clear ();
+
+ c.push_back ("<i>Hello world</i>");
+ p = SubRip::convert_content (c);
+ BOOST_CHECK_EQUAL (p.size(), 1);
+ BOOST_CHECK_EQUAL (p.front().text, "Hello world");
+ BOOST_CHECK_EQUAL (p.front().italic, true);
+ c.clear ();
+
+ c.push_back ("<u>Hello world</u>");
+ p = SubRip::convert_content (c);
+ BOOST_CHECK_EQUAL (p.size(), 1);
+ BOOST_CHECK_EQUAL (p.front().text, "Hello world");
+ BOOST_CHECK_EQUAL (p.front().underline, true);
+ c.clear ();
+
+ c.push_back ("{b}Hello world{/b}");
+ p = SubRip::convert_content (c);
+ BOOST_CHECK_EQUAL (p.size(), 1);
+ BOOST_CHECK_EQUAL (p.front().text, "Hello world");
+ BOOST_CHECK_EQUAL (p.front().bold, true);
+ c.clear ();
+
+ c.push_back ("{i}Hello world{/i}");
+ p = SubRip::convert_content (c);
+ BOOST_CHECK_EQUAL (p.size(), 1);
+ BOOST_CHECK_EQUAL (p.front().text, "Hello world");
+ BOOST_CHECK_EQUAL (p.front().italic, true);
+ c.clear ();
+
+ c.push_back ("{u}Hello world{/u}");
+ p = SubRip::convert_content (c);
+ BOOST_CHECK_EQUAL (p.size(), 1);
+ BOOST_CHECK_EQUAL (p.front().text, "Hello world");
+ BOOST_CHECK_EQUAL (p.front().underline, true);
+ c.clear ();
+
+ c.push_back ("<b>This is <i>nesting</i> of subtitles</b>");
+ p = SubRip::convert_content (c);
+ BOOST_CHECK_EQUAL (p.size(), 3);
+ list<SubRipSubtitlePiece>::iterator i = p.begin ();
+ BOOST_CHECK_EQUAL (i->text, "This is ");
+ BOOST_CHECK_EQUAL (i->bold, true);
+ BOOST_CHECK_EQUAL (i->italic, false);
+ ++i;
+ BOOST_CHECK_EQUAL (i->text, "nesting");
+ BOOST_CHECK_EQUAL (i->bold, true);
+ BOOST_CHECK_EQUAL (i->italic, true);
+ ++i;
+ BOOST_CHECK_EQUAL (i->text, " of subtitles");
+ BOOST_CHECK_EQUAL (i->bold, true);
+ BOOST_CHECK_EQUAL (i->italic, false);
+ ++i;
+ c.clear ();
+}
+
+/** Test parsing of full SubRip file content */
+BOOST_AUTO_TEST_CASE (subrip_parse_test)
+{
+ shared_ptr<SubRipContent> content (new SubRipContent (shared_ptr<Film> (), "test/data/subrip.srt"));
+ content->examine (shared_ptr<Job> ());
+ BOOST_CHECK_EQUAL (content->full_length(), ((3 * 60) + 56.471) * TIME_HZ);
+
+ SubRip s (content);
+
+ vector<SubRipSubtitle>::const_iterator i = s._subtitles.begin();
+
+ BOOST_CHECK (i != s._subtitles.end ());
+ BOOST_CHECK_EQUAL (i->from, ((1 * 60) + 49.200) * TIME_HZ);
+ BOOST_CHECK_EQUAL (i->to, ((1 * 60) + 52.351) * TIME_HZ);
+ BOOST_CHECK_EQUAL (i->pieces.size(), 1);
+ BOOST_CHECK_EQUAL (i->pieces.front().text, "This is a subtitle, and it goes over two lines.");
+
+ ++i;
+ BOOST_CHECK (i != s._subtitles.end ());
+ BOOST_CHECK_EQUAL (i->from, ((1 * 60) + 52.440) * TIME_HZ);
+ BOOST_CHECK_EQUAL (i->to, ((1 * 60) + 54.351) * TIME_HZ);
+ BOOST_CHECK_EQUAL (i->pieces.size(), 1);
+ BOOST_CHECK_EQUAL (i->pieces.front().text, "We have emboldened this");
+ BOOST_CHECK_EQUAL (i->pieces.front().bold, true);
+
+ ++i;
+ BOOST_CHECK (i != s._subtitles.end ());
+ BOOST_CHECK_EQUAL (i->from, ((1 * 60) + 54.440) * TIME_HZ);
+ BOOST_CHECK_EQUAL (i->to, ((1 * 60) + 56.590) * TIME_HZ);
+ BOOST_CHECK_EQUAL (i->pieces.size(), 1);
+ BOOST_CHECK_EQUAL (i->pieces.front().text, "And italicised this.");
+ BOOST_CHECK_EQUAL (i->pieces.front().italic, true);
+
+ ++i;
+ BOOST_CHECK (i != s._subtitles.end ());
+ BOOST_CHECK_EQUAL (i->from, ((1 * 60) + 56.680) * TIME_HZ);
+ BOOST_CHECK_EQUAL (i->to, ((1 * 60) + 58.955) * TIME_HZ);
+ BOOST_CHECK_EQUAL (i->pieces.size(), 1);
+ BOOST_CHECK_EQUAL (i->pieces.front().text, "Shall I compare thee to a summers' day?");
+
+ ++i;
+ BOOST_CHECK (i != s._subtitles.end ());
+ BOOST_CHECK_EQUAL (i->from, ((2 * 60) + 0.840) * TIME_HZ);
+ BOOST_CHECK_EQUAL (i->to, ((2 * 60) + 3.400) * TIME_HZ);
+ BOOST_CHECK_EQUAL (i->pieces.size(), 1);
+ BOOST_CHECK_EQUAL (i->pieces.front().text, "Is this a dagger I see before me?");
+
+ ++i;
+ BOOST_CHECK (i != s._subtitles.end ());
+ BOOST_CHECK_EQUAL (i->from, ((3 * 60) + 54.560) * TIME_HZ);
+ BOOST_CHECK_EQUAL (i->to, ((3 * 60) + 56.471) * TIME_HZ);
+ BOOST_CHECK_EQUAL (i->pieces.size(), 1);
+ BOOST_CHECK_EQUAL (i->pieces.front().text, "Hello world.");
+
+ ++i;
+ BOOST_CHECK (i == s._subtitles.end ());
+}
+
+/** Test rendering of a SubRip subtitle */
+BOOST_AUTO_TEST_CASE (subrip_render_test)
+{
+ shared_ptr<SubRipContent> content (new SubRipContent (shared_ptr<Film> (), "test/data/subrip.srt"));
+ content->examine (shared_ptr<Job> ());
+ BOOST_CHECK_EQUAL (content->full_length(), ((3 * 60) + 56.471) * TIME_HZ);
+
+ shared_ptr<Film> film = new_test_film ("subrip_render_test");
+
+ shared_ptr<SubRipDecoder> decoder (new SubRipDecoder (film, content));
+ shared_ptr<DecodedTextSubtitle> dts = dynamic_pointer_cast<DecodedTextSubtitle> (decoder->peek ());
+
+ shared_ptr<Image> image;
+ Position<int> position;
+ render_subtitles (dts->subs, libdcp::Size (1998, 1080), image, position);
+ write_image (image, "build/test/subrip_render_test.png");
+ check_file ("build/test/subrip_render_test.png", "test/data/subrip_render_test.png");
+}
diff --git a/test/test.cc b/test/test.cc
index be2cf1538..e43db71ef 100644
--- a/test/test.cc
+++ b/test/test.cc
@@ -19,6 +19,7 @@
#include <vector>
#include <list>
+#include <Magick++.h>
#include <libxml++/libxml++.h>
#include <libdcp/dcp.h>
#include "lib/config.h"
@@ -29,6 +30,7 @@
#include "lib/job.h"
#include "lib/cross.h"
#include "lib/server_finder.h"
+#include "lib/image.h"
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE dcpomatic_test
#include <boost/test/unit_test.hpp>
@@ -53,15 +55,16 @@ public:
struct TestConfig
{
- TestConfig()
+ TestConfig ()
{
- dcpomatic_setup();
+ dcpomatic_setup ();
Config::instance()->set_num_local_encoding_threads (1);
Config::instance()->set_server_port_base (61920);
Config::instance()->set_default_dci_metadata (DCIMetadata ());
Config::instance()->set_default_container (static_cast<Ratio*> (0));
Config::instance()->set_default_dcp_content_type (static_cast<DCPContentType*> (0));
+ Config::instance()->set_default_audio_delay (0);
ServerFinder::instance()->disable ();
@@ -98,8 +101,8 @@ void
check_file (boost::filesystem::path ref, boost::filesystem::path check)
{
uintmax_t N = boost::filesystem::file_size (ref);
- BOOST_CHECK_EQUAL (N, boost::filesystem::file_size(check));
- FILE* ref_file = fopen_boost (ref, "rb");
+ BOOST_CHECK_EQUAL (N, boost::filesystem::file_size (check));
+ FILE* ref_file = fopen (ref.c_str(), "rb");
BOOST_CHECK (ref_file);
FILE* check_file = fopen_boost (check, "rb");
BOOST_CHECK (check_file);
@@ -135,7 +138,7 @@ note (libdcp::NoteType t, string n)
}
void
-check_dcp (string ref, string check)
+check_dcp (boost::filesystem::path ref, boost::filesystem::path check)
{
libdcp::DCP ref_dcp (ref);
ref_dcp.read ();
@@ -230,3 +233,12 @@ wait_for_jobs ()
ui_signaller->ui_idle ();
}
+
+void
+write_image (shared_ptr<const Image> image, boost::filesystem::path file)
+{
+ using namespace MagickCore;
+
+ Magick::Image m (image->size().width, image->size().height, "ARGB", CharPixel, (void *) image->data()[0]);
+ m.write (file.string ());
+}
diff --git a/test/test.h b/test/test.h
index dd007e8c9..a42b41577 100644
--- a/test/test.h
+++ b/test/test.h
@@ -20,10 +20,13 @@
#include <boost/filesystem.hpp>
class Film;
+class Image;
extern void wait_for_jobs ();
extern boost::shared_ptr<Film> new_test_film (std::string);
-extern void check_dcp (std::string, std::string);
+extern void check_dcp (boost::filesystem::path, boost::filesystem::path);
+extern void check_file (boost::filesystem::path ref, boost::filesystem::path check);
extern void check_xml (boost::filesystem::path, boost::filesystem::path, std::list<std::string>);
extern void check_file (boost::filesystem::path, boost::filesystem::path);
extern boost::filesystem::path test_film_dir (std::string);
+extern void write_image (boost::shared_ptr<const Image> image, boost::filesystem::path file);
diff --git a/test/util_test.cc b/test/util_test.cc
index 4dccb49c6..5733c7d03 100644
--- a/test/util_test.cc
+++ b/test/util_test.cc
@@ -53,3 +53,17 @@ BOOST_AUTO_TEST_CASE (md5_digest_test)
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);
+}
diff --git a/test/wscript b/test/wscript
index 676f47104..ec8dfd42c 100644
--- a/test/wscript
+++ b/test/wscript
@@ -10,7 +10,7 @@ def configure(conf):
""", msg = 'Checking for boost unit testing library', lib = 'boost_unit_test_framework%s' % boost_test_suffix, uselib_store = 'BOOST_TEST')
def build(bld):
- obj = bld(features = 'cxx cxxprogram')
+ obj = bld(features='cxx cxxprogram')
obj.name = 'unit-tests'
obj.uselib = 'BOOST_TEST BOOST_THREAD DCP OPENJPEG AVFORMAT AVFILTER AVCODEC AVUTIL SWSCALE POSTPROC CXML'
obj.use = 'libdcpomatic'
@@ -27,6 +27,7 @@ def build(bld):
ffmpeg_dcp_test.cc
ffmpeg_examiner_test.cc
ffmpeg_pts_offset.cc
+ ffmpeg_seek_test.cc
file_group_test.cc
film_metadata_test.cc
frame_rate_test.cc
@@ -36,11 +37,15 @@ def build(bld):
pixel_formats_test.cc
play_test.cc
ratio_test.cc
+ repeat_frame_test.cc
recover_test.cc
resampler_test.cc
scaling_test.cc
+ seek_zero_test.cc
silence_padding_test.cc
+ skip_frame_test.cc
stream_test.cc
+ subrip_test.cc
test.cc
threed_test.cc
util_test.cc
@@ -48,3 +53,15 @@ def build(bld):
obj.target = 'unit-tests'
obj.install_path = ''
+
+ obj = bld(features='cxx cxxprogram')
+ obj.name = 'long-unit-tests'
+ obj.uselib = 'BOOST_TEST DCP OPENJPEG AVFORMAT AVFILTER AVCODEC AVUTIL SWSCALE POSTPROC CXML'
+ obj.use = 'libdcpomatic'
+ obj.source = """
+ test.cc
+ long_ffmpeg_seek_test.cc
+ """
+
+ obj.target = 'long-unit-tests'
+ obj.install_path = ''