2 Copyright (C) 2012 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 using boost::shared_ptr;
22 shared_ptr<const Image> trimmer_test_last_video;
23 int trimmer_test_video_frames = 0;
24 shared_ptr<const AudioBuffers> trimmer_test_last_audio;
27 trimmer_test_video_helper (shared_ptr<const Image> image, bool, shared_ptr<Subtitle>)
29 trimmer_test_last_video = image;
30 ++trimmer_test_video_frames;
34 trimmer_test_audio_helper (shared_ptr<const AudioBuffers> audio)
36 trimmer_test_last_audio = audio;
39 BOOST_AUTO_TEST_CASE (trimmer_passthrough_test)
41 Trimmer trimmer (shared_ptr<Log> (), 0, 0, 200, 48000, 25, 25);
42 trimmer.Video.connect (bind (&trimmer_test_video_helper, _1, _2, _3));
43 trimmer.Audio.connect (bind (&trimmer_test_audio_helper, _1));
45 shared_ptr<SimpleImage> video (new SimpleImage (PIX_FMT_RGB24, libdcp::Size (1998, 1080), true));
46 shared_ptr<AudioBuffers> audio (new AudioBuffers (6, 42 * 1920));
48 trimmer.process_video (video, false, shared_ptr<Subtitle> ());
49 trimmer.process_audio (audio);
51 BOOST_CHECK_EQUAL (video.get(), trimmer_test_last_video.get());
52 BOOST_CHECK_EQUAL (audio.get(), trimmer_test_last_audio.get());
53 BOOST_CHECK_EQUAL (audio->frames(), trimmer_test_last_audio->frames());
57 /** Test the audio handling of the Trimmer */
58 BOOST_AUTO_TEST_CASE (trimmer_audio_test)
60 Trimmer trimmer (shared_ptr<Log> (), 25, 75, 200, 48000, 25, 25);
62 trimmer.Audio.connect (bind (&trimmer_test_audio_helper, _1));
64 /* 21 video frames-worth of audio frames; should be completely stripped */
65 trimmer_test_last_audio.reset ();
66 shared_ptr<AudioBuffers> audio (new AudioBuffers (6, 21 * 1920));
67 trimmer.process_audio (audio);
68 BOOST_CHECK (trimmer_test_last_audio == 0);
70 /* 42 more video frames-worth, 4 should be stripped from the start */
71 audio.reset (new AudioBuffers (6, 42 * 1920));
72 trimmer.process_audio (audio);
73 BOOST_CHECK (trimmer_test_last_audio);
74 BOOST_CHECK_EQUAL (trimmer_test_last_audio->frames(), 38 * 1920);
76 /* 42 more video frames-worth, should be kept as-is */
77 trimmer_test_last_audio.reset ();
78 audio.reset (new AudioBuffers (6, 42 * 1920));
79 trimmer.process_audio (audio);
80 BOOST_CHECK (trimmer_test_last_audio);
81 BOOST_CHECK_EQUAL (trimmer_test_last_audio->frames(), 42 * 1920);
83 /* 25 more video frames-worth, 5 should be trimmed from the end */
84 trimmer_test_last_audio.reset ();
85 audio.reset (new AudioBuffers (6, 25 * 1920));
86 trimmer.process_audio (audio);
87 BOOST_CHECK (trimmer_test_last_audio);
88 BOOST_CHECK_EQUAL (trimmer_test_last_audio->frames(), 20 * 1920);
90 /* Now some more; all should be trimmed */
91 trimmer_test_last_audio.reset ();
92 audio.reset (new AudioBuffers (6, 100 * 1920));
93 trimmer.process_audio (audio);
94 BOOST_CHECK (trimmer_test_last_audio == 0);
97 BOOST_AUTO_TEST_CASE (trim_end_test)
99 Trimmer trimmer (shared_ptr<Log> (), 0, 75, 200, 48000, 25, 25);
101 shared_ptr<SimpleImage> image (new SimpleImage (PIX_FMT_RGB24, libdcp::Size (256, 256), true));
103 trimmer.Video.connect (bind (&trimmer_test_video_helper, _1, _2, _3));
104 trimmer_test_video_frames = 0;
105 for (int i = 0; i < 200; ++i) {
106 trimmer.process_video (image, false, shared_ptr<Subtitle> ());
109 BOOST_CHECK_EQUAL (trimmer_test_video_frames, 125);