+
+/* Check that Image::make_black works, and doesn't use values which crash
+ sws_scale().
+*/
+BOOST_AUTO_TEST_CASE (make_black_test)
+{
+ /* This needs to happen in the first test */
+ dcpomatic_setup ();
+
+ libdcp::Size in_size (512, 512);
+ libdcp::Size out_size (1024, 1024);
+
+ list<AVPixelFormat> pix_fmts;
+ pix_fmts.push_back (AV_PIX_FMT_RGB24);
+ pix_fmts.push_back (AV_PIX_FMT_YUV420P);
+ pix_fmts.push_back (AV_PIX_FMT_YUV422P10LE);
+ pix_fmts.push_back (AV_PIX_FMT_YUV444P9LE);
+ pix_fmts.push_back (AV_PIX_FMT_YUV444P9BE);
+ pix_fmts.push_back (AV_PIX_FMT_YUV444P10LE);
+ pix_fmts.push_back (AV_PIX_FMT_YUV444P10BE);
+ pix_fmts.push_back (AV_PIX_FMT_UYVY422);
+
+ int N = 0;
+ for (list<AVPixelFormat>::const_iterator i = pix_fmts.begin(); i != pix_fmts.end(); ++i) {
+ boost::shared_ptr<Image> foo (new SimpleImage (*i, in_size, true));
+ foo->make_black ();
+ boost::shared_ptr<Image> bar = foo->scale_and_convert_to_rgb (out_size, 0, Scaler::from_id ("bicubic"), true);
+
+ uint8_t* p = bar->data()[0];
+ for (int y = 0; y < bar->size().height; ++y) {
+ uint8_t* q = p;
+ for (int x = 0; x < bar->line_size()[0]; ++x) {
+ BOOST_CHECK_EQUAL (*q++, 0);
+ }
+ p += bar->stride()[0];
+ }
+
+ ++N;
+ }
+}
+
+shared_ptr<AudioBuffers> trimmer_test_last;
+
+void
+trimmer_test_helper (shared_ptr<AudioBuffers> audio)
+{
+ trimmer_test_last = audio;
+}
+
+/** Test the audio handling of the Trimmer */
+BOOST_AUTO_TEST_CASE (trimmer_test)
+{
+ Trimmer trimmer (shared_ptr<Log> (), 25, 75, 200, 48000, 25, 25);
+
+ trimmer.Audio.connect (bind (&trimmer_test_helper, _1));
+
+ /* 21 video frames-worth of audio frames; should be completely stripped */
+ trimmer_test_last.reset ();
+ shared_ptr<AudioBuffers> audio (new AudioBuffers (6, 21 * 1920));
+ trimmer.process_audio (audio);
+ BOOST_CHECK (trimmer_test_last == 0);
+
+ /* 42 more video frames-worth, 4 should be stripped from the start */
+ audio.reset (new AudioBuffers (6, 42 * 1920));
+ trimmer.process_audio (audio);
+ BOOST_CHECK (trimmer_test_last);
+ BOOST_CHECK_EQUAL (trimmer_test_last->frames(), 38 * 1920);
+
+ /* 42 more video frames-worth, should be kept as-is */
+ trimmer_test_last.reset ();
+ audio.reset (new AudioBuffers (6, 42 * 1920));
+ trimmer.process_audio (audio);
+ BOOST_CHECK (trimmer_test_last);
+ BOOST_CHECK_EQUAL (trimmer_test_last->frames(), 42 * 1920);
+
+ /* 25 more video frames-worth, 5 should be trimmed from the end */
+ trimmer_test_last.reset ();
+ audio.reset (new AudioBuffers (6, 25 * 1920));
+ trimmer.process_audio (audio);
+ BOOST_CHECK (trimmer_test_last);
+ BOOST_CHECK_EQUAL (trimmer_test_last->frames(), 20 * 1920);
+
+ /* Now some more; all should be trimmed */
+ trimmer_test_last.reset ();
+ audio.reset (new AudioBuffers (6, 100 * 1920));
+ trimmer.process_audio (audio);
+ BOOST_CHECK (trimmer_test_last == 0);
+}
+
+