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 shared_ptr<const AudioBuffers> trimmer_test_last_audio;
26 trimmer_test_video_helper (shared_ptr<const Image> image, bool, shared_ptr<Subtitle>)
28 trimmer_test_last_video = image;
32 trimmer_test_audio_helper (shared_ptr<const AudioBuffers> audio)
34 trimmer_test_last_audio = audio;
37 BOOST_AUTO_TEST_CASE (trimmer_passthrough_test)
39 Trimmer trimmer (shared_ptr<Log> (), 0, 0, 200, 48000, 25, 25);
40 trimmer.Video.connect (bind (&trimmer_test_video_helper, _1, _2, _3));
41 trimmer.Audio.connect (bind (&trimmer_test_audio_helper, _1));
43 shared_ptr<SimpleImage> video (new SimpleImage (PIX_FMT_RGB24, libdcp::Size (1998, 1080), true));
44 shared_ptr<AudioBuffers> audio (new AudioBuffers (6, 42 * 1920));
46 trimmer.process_video (video, false, shared_ptr<Subtitle> ());
47 trimmer.process_audio (audio);
49 BOOST_CHECK_EQUAL (video.get(), trimmer_test_last_video.get());
50 BOOST_CHECK_EQUAL (audio.get(), trimmer_test_last_audio.get());
51 BOOST_CHECK_EQUAL (audio->frames(), trimmer_test_last_audio->frames());
55 /** Test the audio handling of the Trimmer */
56 BOOST_AUTO_TEST_CASE (trimmer_audio_test)
58 Trimmer trimmer (shared_ptr<Log> (), 25, 75, 200, 48000, 25, 25);
60 trimmer.Audio.connect (bind (&trimmer_test_audio_helper, _1));
62 /* 21 video frames-worth of audio frames; should be completely stripped */
63 trimmer_test_last_audio.reset ();
64 shared_ptr<AudioBuffers> audio (new AudioBuffers (6, 21 * 1920));
65 trimmer.process_audio (audio);
66 BOOST_CHECK (trimmer_test_last_audio == 0);
68 /* 42 more video frames-worth, 4 should be stripped from the start */
69 audio.reset (new AudioBuffers (6, 42 * 1920));
70 trimmer.process_audio (audio);
71 BOOST_CHECK (trimmer_test_last_audio);
72 BOOST_CHECK_EQUAL (trimmer_test_last_audio->frames(), 38 * 1920);
74 /* 42 more video frames-worth, should be kept as-is */
75 trimmer_test_last_audio.reset ();
76 audio.reset (new AudioBuffers (6, 42 * 1920));
77 trimmer.process_audio (audio);
78 BOOST_CHECK (trimmer_test_last_audio);
79 BOOST_CHECK_EQUAL (trimmer_test_last_audio->frames(), 42 * 1920);
81 /* 25 more video frames-worth, 5 should be trimmed from the end */
82 trimmer_test_last_audio.reset ();
83 audio.reset (new AudioBuffers (6, 25 * 1920));
84 trimmer.process_audio (audio);
85 BOOST_CHECK (trimmer_test_last_audio);
86 BOOST_CHECK_EQUAL (trimmer_test_last_audio->frames(), 20 * 1920);
88 /* Now some more; all should be trimmed */
89 trimmer_test_last_audio.reset ();
90 audio.reset (new AudioBuffers (6, 100 * 1920));
91 trimmer.process_audio (audio);
92 BOOST_CHECK (trimmer_test_last_audio == 0);