+ if (cleanup) {
+ cleanup->add (p);
+ }
+
+ auto film = make_shared<Film>(p);
+ film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
+ film->set_container (Ratio::from_id ("185"));
+ film->write_metadata ();
+
+ for (auto i: content) {
+ film->examine_and_add_content (i);
+ BOOST_REQUIRE (!wait_for_jobs());
+ }
+
+ return film;
+}
+
+
+void
+check_wav_file (boost::filesystem::path ref, boost::filesystem::path check)
+{
+ SF_INFO ref_info;
+ ref_info.format = 0;
+ auto ref_file = sf_open (ref.string().c_str(), SFM_READ, &ref_info);
+ BOOST_CHECK (ref_file);
+
+ SF_INFO check_info;
+ check_info.format = 0;
+ auto check_file = sf_open (check.string().c_str(), SFM_READ, &check_info);
+ BOOST_CHECK (check_file);
+
+ BOOST_CHECK_EQUAL (ref_info.frames, check_info.frames);
+ BOOST_CHECK_EQUAL (ref_info.samplerate, check_info.samplerate);
+ BOOST_CHECK_EQUAL (ref_info.channels, check_info.channels);
+ BOOST_CHECK_EQUAL (ref_info.format, check_info.format);
+
+ /* buffer_size is in frames */
+ sf_count_t const buffer_size = 65536 * ref_info.channels;
+ scoped_array<int32_t> ref_buffer (new int32_t[buffer_size]);
+ scoped_array<int32_t> check_buffer (new int32_t[buffer_size]);
+
+ sf_count_t N = ref_info.frames;
+ while (N) {
+ sf_count_t this_time = min (buffer_size, N);
+ sf_count_t r = sf_readf_int (ref_file, ref_buffer.get(), this_time);
+ BOOST_CHECK_EQUAL (r, this_time);
+ r = sf_readf_int (check_file, check_buffer.get(), this_time);
+ BOOST_CHECK_EQUAL (r, this_time);
+
+ for (sf_count_t i = 0; i < this_time; ++i) {
+ BOOST_REQUIRE_MESSAGE (
+ abs (ref_buffer[i] - check_buffer[i]) <= 65536,
+ ref << " differs from " << check << " at " << (ref_info.frames - N + i) << " of " << ref_info.frames
+ << "(" << ref_buffer[i] << " vs " << check_buffer[i] << ")"
+ );
+ }
+
+ N -= this_time;
+ }
+}
+
+
+void
+check_mxf_audio_file (boost::filesystem::path ref, boost::filesystem::path check)
+{
+ ASDCP::PCM::MXFReader ref_reader;
+ BOOST_REQUIRE (!ASDCP_FAILURE (ref_reader.OpenRead (ref.string().c_str())));
+
+ ASDCP::PCM::AudioDescriptor ref_desc;
+ BOOST_REQUIRE (!ASDCP_FAILURE (ref_reader.FillAudioDescriptor (ref_desc)));
+
+ ASDCP::PCM::MXFReader check_reader;
+ BOOST_REQUIRE (!ASDCP_FAILURE (check_reader.OpenRead (check.string().c_str())));
+
+ ASDCP::PCM::AudioDescriptor check_desc;
+ BOOST_REQUIRE (!ASDCP_FAILURE (check_reader.FillAudioDescriptor (check_desc)));
+
+ BOOST_REQUIRE_EQUAL (ref_desc.ContainerDuration, check_desc.ContainerDuration);
+
+ ASDCP::PCM::FrameBuffer ref_buffer (Kumu::Megabyte);
+ ASDCP::PCM::FrameBuffer check_buffer (Kumu::Megabyte);
+ for (size_t i = 0; i < ref_desc.ContainerDuration; ++i) {
+ ref_reader.ReadFrame (i, ref_buffer, 0);
+ check_reader.ReadFrame (i, check_buffer, 0);
+ BOOST_REQUIRE (memcmp(ref_buffer.RoData(), check_buffer.RoData(), ref_buffer.Size()) == 0);
+ }
+}
+
+
+/** @return true if the files are the same, otherwise false */
+bool
+mxf_atmos_files_same (boost::filesystem::path ref, boost::filesystem::path check, bool verbose)
+{
+ ASDCP::ATMOS::MXFReader ref_reader;
+ BOOST_REQUIRE (!ASDCP_FAILURE(ref_reader.OpenRead(ref.string().c_str())));
+
+ ASDCP::ATMOS::AtmosDescriptor ref_desc;
+ BOOST_REQUIRE (!ASDCP_FAILURE(ref_reader.FillAtmosDescriptor(ref_desc)));
+
+ ASDCP::ATMOS::MXFReader check_reader;
+ BOOST_REQUIRE (!ASDCP_FAILURE(check_reader.OpenRead(check.string().c_str())));
+
+ ASDCP::ATMOS::AtmosDescriptor check_desc;
+ BOOST_REQUIRE (!ASDCP_FAILURE(check_reader.FillAtmosDescriptor(check_desc)));
+
+ if (ref_desc.EditRate.Numerator != check_desc.EditRate.Numerator) {
+ if (verbose) {
+ std::cout << "EditRate.Numerator differs.\n";
+ }
+ return false;
+ }
+ if (ref_desc.EditRate.Denominator != check_desc.EditRate.Denominator) {
+ if (verbose) {
+ std::cout << "EditRate.Denominator differs.\n";
+ }
+ return false;
+ }
+ if (ref_desc.ContainerDuration != check_desc.ContainerDuration) {
+ if (verbose) {
+ std::cout << "EditRate.ContainerDuration differs.\n";
+ }
+ return false;
+ }
+ if (ref_desc.FirstFrame != check_desc.FirstFrame) {
+ if (verbose) {
+ std::cout << "EditRate.FirstFrame differs.\n";
+ }
+ return false;
+ }
+ if (ref_desc.MaxChannelCount != check_desc.MaxChannelCount) {
+ if (verbose) {
+ std::cout << "EditRate.MaxChannelCount differs.\n";
+ }
+ return false;
+ }
+ if (ref_desc.MaxObjectCount != check_desc.MaxObjectCount) {
+ if (verbose) {
+ std::cout << "EditRate.MaxObjectCount differs.\n";
+ }
+ return false;
+ }
+ if (ref_desc.AtmosVersion != check_desc.AtmosVersion) {
+ if (verbose) {
+ std::cout << "EditRate.AtmosVersion differs.\n";
+ }
+ return false;
+ }
+
+ ASDCP::DCData::FrameBuffer ref_buffer (Kumu::Megabyte);
+ ASDCP::DCData::FrameBuffer check_buffer (Kumu::Megabyte);
+ for (size_t i = 0; i < ref_desc.ContainerDuration; ++i) {
+ ref_reader.ReadFrame (i, ref_buffer, 0);
+ check_reader.ReadFrame (i, check_buffer, 0);
+ if (memcmp(ref_buffer.RoData(), check_buffer.RoData(), ref_buffer.Size())) {
+ if (verbose) {
+ std::cout << "data differs.\n";
+ }
+ return false;
+ }
+ }
+
+ return true;
+}
+
+
+static
+double
+rms_error (boost::filesystem::path ref, boost::filesystem::path check)
+{
+ FFmpegImageProxy ref_proxy (ref);
+ auto ref_image = ref_proxy.image(Image::Alignment::COMPACT).image;
+ FFmpegImageProxy check_proxy (check);
+ auto check_image = check_proxy.image(Image::Alignment::COMPACT).image;
+
+ BOOST_REQUIRE_EQUAL (ref_image->pixel_format(), check_image->pixel_format());
+ AVPixelFormat const format = ref_image->pixel_format();
+
+ BOOST_REQUIRE (ref_image->size() == check_image->size());
+ int const width = ref_image->size().width;
+ int const height = ref_image->size().height;
+
+ double sum_square = 0;
+ switch (format) {
+ case AV_PIX_FMT_RGBA:
+ {
+ for (int y = 0; y < height; ++y) {
+ uint8_t* p = ref_image->data()[0] + y * ref_image->stride()[0];
+ uint8_t* q = check_image->data()[0] + y * check_image->stride()[0];
+ for (int x = 0; x < width; ++x) {
+ for (int c = 0; c < 4; ++c) {
+ sum_square += pow((*p++ - *q++), 2);
+ }
+ }
+ }
+ break;
+ }
+ case AV_PIX_FMT_RGB24:
+ {
+ for (int y = 0; y < height; ++y) {
+ uint8_t* p = ref_image->data()[0] + y * ref_image->stride()[0];
+ uint8_t* q = check_image->data()[0] + y * check_image->stride()[0];
+ for (int x = 0; x < width; ++x) {
+ for (int c = 0; c < 3; ++c) {
+ sum_square += pow((*p++ - *q++), 2);
+ }
+ }
+ }
+ break;
+ }
+ case AV_PIX_FMT_RGB48BE:
+ {
+ for (int y = 0; y < height; ++y) {
+ uint16_t* p = reinterpret_cast<uint16_t*>(ref_image->data()[0] + y * ref_image->stride()[0]);
+ uint16_t* q = reinterpret_cast<uint16_t*>(check_image->data()[0] + y * check_image->stride()[0]);
+ for (int x = 0; x < width; ++x) {
+ for (int c = 0; c < 3; ++c) {
+ sum_square += pow((*p++ - *q++), 2);
+ }
+ }
+ }
+ break;
+ }
+ default:
+ BOOST_REQUIRE_MESSAGE (false, "unrecognised pixel format " << format);
+ }
+
+ return sqrt(sum_square / (height * width));
+}
+
+
+BOOST_AUTO_TEST_CASE (rms_error_test)
+{
+ BOOST_CHECK_CLOSE (rms_error("test/data/check_image0.png", "test/data/check_image0.png"), 0, 0.001);
+ BOOST_CHECK_CLOSE (rms_error("test/data/check_image0.png", "test/data/check_image1.png"), 2.2778, 0.001);
+ BOOST_CHECK_CLOSE (rms_error("test/data/check_image0.png", "test/data/check_image2.png"), 59.8896, 0.001);
+ BOOST_CHECK_CLOSE (rms_error("test/data/check_image0.png", "test/data/check_image3.png"), 0.89164, 0.001);