diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-01-15 21:23:33 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-01-15 21:23:33 +0000 |
| commit | 8353a009aae1a604251c0160193c39741c2fa27c (patch) | |
| tree | 558d2b1951f2b4f05f0ab93b46d10afd0ebee929 /test | |
| parent | d0bca7d33b8101cd87f78d5a76b2512dea3988f8 (diff) | |
| parent | 4e5d5c7dcc6470b8dc918d03a00e30c07df60efe (diff) | |
Merge 1.0-seek and subtitle-content.
Diffstat (limited to 'test')
| -rw-r--r-- | test/ffmpeg_audio_test.cc | 4 | ||||
| -rw-r--r-- | test/ffmpeg_pts_offset.cc | 15 | ||||
| -rw-r--r-- | test/ffmpeg_seek_test.cc | 117 | ||||
| -rw-r--r-- | test/frame_rate_test.cc | 52 | ||||
| -rw-r--r-- | test/long_ffmpeg_seek_test.cc | 105 | ||||
| -rw-r--r-- | test/play_test.cc | 14 | ||||
| -rw-r--r-- | test/ratio_test.cc | 2 | ||||
| -rw-r--r-- | test/repeat_frame_test.cc | 50 | ||||
| -rw-r--r-- | test/resampler_test.cc | 7 | ||||
| -rw-r--r-- | test/seek_zero_test.cc | 57 | ||||
| -rw-r--r-- | test/skip_frame_test.cc | 51 | ||||
| -rw-r--r-- | test/subrip_test.cc | 15 | ||||
| -rw-r--r-- | test/test.cc | 11 | ||||
| -rw-r--r-- | test/test.h | 4 | ||||
| -rw-r--r-- | test/util_test.cc | 14 | ||||
| -rw-r--r-- | test/wscript | 18 |
16 files changed, 476 insertions, 60 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 2090e517b..53303f154 100644 --- a/test/ffmpeg_pts_offset.cc +++ b/test/ffmpeg_pts_offset.cc @@ -37,8 +37,7 @@ BOOST_AUTO_TEST_CASE (ffmpeg_pts_offset_test) content->_first_video = 0; content->_audio_stream->first_audio = 0; FFmpegDecoder decoder (film, content, true, true); - BOOST_CHECK_EQUAL (decoder._video_pts_offset, 0); - BOOST_CHECK_EQUAL (decoder._audio_pts_offset, 0); + BOOST_CHECK_EQUAL (decoder._pts_offset, 0); } { @@ -46,8 +45,7 @@ BOOST_AUTO_TEST_CASE (ffmpeg_pts_offset_test) content->_first_video = 600; content->_audio_stream->first_audio = 600; FFmpegDecoder decoder (film, content, true, true); - BOOST_CHECK_EQUAL (decoder._video_pts_offset, -600); - BOOST_CHECK_EQUAL (decoder._audio_pts_offset, -600); + BOOST_CHECK_EQUAL (decoder._pts_offset, -600); } { @@ -55,8 +53,7 @@ BOOST_AUTO_TEST_CASE (ffmpeg_pts_offset_test) content->_first_video = 1.0 / 24.0; content->_audio_stream->first_audio = 0; FFmpegDecoder decoder (film, content, true, true); - BOOST_CHECK_EQUAL (decoder._video_pts_offset, 0); - BOOST_CHECK_EQUAL (decoder._audio_pts_offset, 0); + BOOST_CHECK_EQUAL (decoder._pts_offset, 0); } { @@ -65,8 +62,7 @@ BOOST_AUTO_TEST_CASE (ffmpeg_pts_offset_test) content->_first_video = frame + 0.0215; content->_audio_stream->first_audio = 0; FFmpegDecoder decoder (film, content, true, true); - BOOST_CHECK_CLOSE (decoder._video_pts_offset, (frame - 0.0215), 0.00001); - BOOST_CHECK_CLOSE (decoder._audio_pts_offset, (frame - 0.0215), 0.00001); + BOOST_CHECK_CLOSE (decoder._pts_offset, (frame - 0.0215), 0.00001); } { @@ -75,7 +71,6 @@ BOOST_AUTO_TEST_CASE (ffmpeg_pts_offset_test) content->_first_video = frame + 0.0215 + 4.1; content->_audio_stream->first_audio = 4.1; FFmpegDecoder decoder (film, content, true, true); - BOOST_CHECK_EQUAL (decoder._video_pts_offset, (frame - 0.0215) - 4.1); - BOOST_CHECK_EQUAL (decoder._audio_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/ratio_test.cc b/test/ratio_test.cc index 082a6ff11..f3cbb504f 100644 --- a/test/ratio_test.cc +++ b/test/ratio_test.cc @@ -42,7 +42,7 @@ BOOST_AUTO_TEST_CASE (ratio_test) Ratio const * r = Ratio::from_id ("119"); BOOST_CHECK (r); - BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (1285, 1080)); + BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (1290, 1080)); r = Ratio::from_id ("133"); BOOST_CHECK (r); 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 1ef69b0c2..5bee3603b 100644 --- a/test/resampler_test.cc +++ b/test/resampler_test.cc @@ -34,13 +34,14 @@ resampler_test_one (int from, int to) /* 3 hours */ int64_t const N = 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 index 0dbf6d310..12a77c1e1 100644 --- a/test/subrip_test.cc +++ b/test/subrip_test.cc @@ -29,6 +29,7 @@ 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) @@ -175,15 +176,6 @@ BOOST_AUTO_TEST_CASE (subrip_parse_test) BOOST_CHECK (i == s._subtitles.end ()); } -static list<libdcp::Subtitle> subtitles; - -static void -process_subtitle (list<libdcp::Subtitle> s) -{ - subtitles = s; -} - - /** Test rendering of a SubRip subtitle */ BOOST_AUTO_TEST_CASE (subrip_render_test) { @@ -194,12 +186,11 @@ BOOST_AUTO_TEST_CASE (subrip_render_test) shared_ptr<Film> film = new_test_film ("subrip_render_test"); shared_ptr<SubRipDecoder> decoder (new SubRipDecoder (film, content)); - decoder->TextSubtitle.connect (boost::bind (&process_subtitle, _1)); - decoder->pass (); + shared_ptr<DecodedTextSubtitle> dts = dynamic_pointer_cast<DecodedTextSubtitle> (decoder->peek ()); shared_ptr<Image> image; Position<int> position; - render_subtitles (subtitles, libdcp::Size (1998, 1080), image, 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 e76c98d8b..f9d761da3 100644 --- a/test/test.cc +++ b/test/test.cc @@ -55,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 (); @@ -97,10 +98,10 @@ new_test_film (string name) } void -check_file (string ref, string check) +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)); + 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 (check.c_str(), "rb"); @@ -137,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 (); diff --git a/test/test.h b/test/test.h index 8b302b119..b6347a5ca 100644 --- a/test/test.h +++ b/test/test.h @@ -24,8 +24,8 @@ 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_file (std::string ref, std::string check); +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 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 834491e19..de9e9f25a 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 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,9 +37,12 @@ def build(bld): pixel_formats_test.cc play_test.cc ratio_test.cc + repeat_frame_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 @@ -48,3 +52,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 = '' |
