X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=test%2Ftest.cc;h=2dac199fe316f62aa9115e5cfb683e0a27eb5ee3;hb=2cb2078282c8b799d7a0d0016e1518f1a4b55af1;hp=c48ecffe013e07a3ad3abb7cefe4af0182852b5d;hpb=3370a67e8a9aeaec45911ba1c714a0d259781fdf;p=libdcp.git diff --git a/test/test.cc b/test/test.cc index c48ecffe..2dac199f 100644 --- a/test/test.cc +++ b/test/test.cc @@ -37,6 +37,7 @@ #include "cpl.h" #include "dcp.h" #include "interop_subtitle_asset.h" +#include "file.h" #include "j2k_transcode.h" #include "mono_picture_asset.h" #include "mono_picture_asset.h" @@ -45,11 +46,12 @@ #include "picture_asset_writer.h" #include "reel.h" #include "reel_asset.h" -#include "reel_closed_caption_asset.h" +#include "reel_interop_closed_caption_asset.h" #include "reel_interop_subtitle_asset.h" #include "reel_markers_asset.h" #include "reel_mono_picture_asset.h" #include "reel_mono_picture_asset.h" +#include "reel_smpte_closed_caption_asset.h" #include "reel_smpte_subtitle_asset.h" #include "reel_sound_asset.h" #include "smpte_subtitle_asset.h" @@ -57,10 +59,15 @@ #include "sound_asset_writer.h" #include "test.h" #include "util.h" +#include "warnings.h" +LIBDCP_DISABLE_WARNINGS #include #include +LIBDCP_ENABLE_WARNINGS #include +LIBDCP_DISABLE_WARNINGS #include +LIBDCP_ENABLE_WARNINGS #include #include #include @@ -204,25 +211,25 @@ check_file (boost::filesystem::path ref, boost::filesystem::path check) { uintmax_t size = boost::filesystem::file_size (ref); BOOST_CHECK_EQUAL (size, boost::filesystem::file_size(check)); - auto ref_file = dcp::fopen_boost (ref, "rb"); + dcp::File ref_file(ref, "rb"); BOOST_REQUIRE (ref_file); - auto check_file = dcp::fopen_boost (check, "rb"); + dcp::File check_file(check, "rb"); BOOST_REQUIRE (check_file); int const buffer_size = 65536; - auto ref_buffer = new uint8_t[buffer_size]; - auto check_buffer = new uint8_t[buffer_size]; + std::vector ref_buffer(buffer_size); + std::vector check_buffer(buffer_size); uintmax_t pos = 0; while (pos < size) { uintmax_t this_time = min (uintmax_t(buffer_size), size - pos); - size_t r = fread (ref_buffer, 1, this_time, ref_file); + size_t r = ref_file.read(ref_buffer.data(), 1, this_time); BOOST_CHECK_EQUAL (r, this_time); - r = fread (check_buffer, 1, this_time, check_file); + r = check_file.read(check_buffer.data(), 1, this_time); BOOST_CHECK_EQUAL (r, this_time); - if (memcmp(ref_buffer, check_buffer, this_time) != 0) { + if (memcmp(ref_buffer.data(), check_buffer.data(), this_time) != 0) { for (int i = 0; i < buffer_size; ++i) { if (ref_buffer[i] != check_buffer[i]) { BOOST_CHECK_MESSAGE ( @@ -237,12 +244,6 @@ check_file (boost::filesystem::path ref, boost::filesystem::path check) pos += this_time; } - - delete[] ref_buffer; - delete[] check_buffer; - - fclose (ref_file); - fclose (check_file); } @@ -260,16 +261,19 @@ RNGFixer::~RNGFixer () shared_ptr -simple_picture (boost::filesystem::path path, string suffix, int frames) +simple_picture (boost::filesystem::path path, string suffix, int frames, optional key) { dcp::MXFMetadata mxf_meta; mxf_meta.company_name = "OpenDCP"; mxf_meta.product_name = "OpenDCP"; mxf_meta.product_version = "0.0.25"; - shared_ptr mp (new dcp::MonoPictureAsset (dcp::Fraction (24, 1), dcp::Standard::SMPTE)); + auto mp = make_shared(dcp::Fraction (24, 1), dcp::Standard::SMPTE); mp->set_metadata (mxf_meta); - shared_ptr picture_writer = mp->start_write (path / dcp::String::compose("video%1.mxf", suffix), false); + if (key) { + mp->set_key (*key); + } + auto picture_writer = mp->start_write(path / dcp::String::compose("video%1.mxf", suffix), dcp::PictureAsset::Behaviour::MAKE_NEW); dcp::Size const size (1998, 1080); auto image = make_shared(size); @@ -288,15 +292,16 @@ simple_picture (boost::filesystem::path path, string suffix, int frames) shared_ptr -simple_sound (boost::filesystem::path path, string suffix, dcp::MXFMetadata mxf_meta, string language, int frames, int sample_rate) +simple_sound(boost::filesystem::path path, string suffix, dcp::MXFMetadata mxf_meta, string language, int frames, int sample_rate, optional key, int channels) { - int const channels = 6; - /* Set a valid language, then overwrite it, so that the language parameter can be badly formed */ - shared_ptr ms (new dcp::SoundAsset(dcp::Fraction(24, 1), sample_rate, channels, dcp::LanguageTag("en-US"), dcp::Standard::SMPTE)); + auto ms = make_shared(dcp::Fraction(24, 1), sample_rate, channels, dcp::LanguageTag("en-US"), dcp::Standard::SMPTE); + if (key) { + ms->set_key (*key); + } ms->_language = language; ms->set_metadata (mxf_meta); - shared_ptr sound_writer = ms->start_write (path / dcp::String::compose("audio%1.mxf", suffix)); + auto sound_writer = ms->start_write(path / dcp::String::compose("audio%1.mxf", suffix), {}, dcp::SoundAsset::AtmosSync::DISABLED, dcp::SoundAsset::MCASubDescriptors::ENABLED); int const samples_per_frame = sample_rate / 24; @@ -307,7 +312,7 @@ simple_sound (boost::filesystem::path path, string suffix, dcp::MXFMetadata mxf_ } for (auto i = 0; i < frames; ++i) { - sound_writer->write (silence, samples_per_frame); + sound_writer->write(silence, channels, samples_per_frame); } sound_writer->finalize (); @@ -321,7 +326,7 @@ simple_sound (boost::filesystem::path path, string suffix, dcp::MXFMetadata mxf_ shared_ptr -make_simple (boost::filesystem::path path, int reels, int frames) +make_simple (boost::filesystem::path path, int reels, int frames, dcp::Standard standard, optional key) { /* Some known metadata */ dcp::MXFMetadata mxf_meta; @@ -329,10 +334,12 @@ make_simple (boost::filesystem::path path, int reels, int frames) mxf_meta.product_name = "OpenDCP"; mxf_meta.product_version = "0.0.25"; + auto constexpr sample_rate = 48000; + boost::filesystem::remove_all (path); boost::filesystem::create_directories (path); auto d = make_shared(path); - auto cpl = make_shared("A Test DCP", dcp::ContentKind::TRAILER); + auto cpl = make_shared("A Test DCP", dcp::ContentKind::TRAILER, standard); cpl->set_annotation_text ("A Test DCP"); cpl->set_issuer ("OpenDCP 0.0.25"); cpl->set_creator ("OpenDCP 0.0.25"); @@ -340,8 +347,8 @@ make_simple (boost::filesystem::path path, int reels, int frames) cpl->set_content_version ( dcp::ContentVersion("urn:uuid:75ac29aa-42ac-1234-ecae-49251abefd11", "content-version-label-text") ); - cpl->set_main_sound_configuration("51/L,R,C,LFE,Ls,Rs"); - cpl->set_main_sound_sample_rate(48000); + cpl->set_main_sound_configuration(dcp::MainSoundConfiguration("51/L,R,C,LFE,Ls,Rs")); + cpl->set_main_sound_sample_rate(sample_rate); cpl->set_main_picture_stored_area(dcp::Size(1998, 1080)); cpl->set_main_picture_active_area(dcp::Size(1998, 1080)); cpl->set_version_number(1); @@ -349,15 +356,15 @@ make_simple (boost::filesystem::path path, int reels, int frames) for (int i = 0; i < reels; ++i) { string suffix = reels == 1 ? "" : dcp::String::compose("%1", i); - shared_ptr mp = simple_picture (path, suffix, frames); - shared_ptr ms = simple_sound (path, suffix, mxf_meta, "en-US", frames); + auto mp = simple_picture (path, suffix, frames, key); + auto ms = simple_sound (path, suffix, mxf_meta, "en-US", frames, sample_rate, key); auto reel = make_shared( shared_ptr(new dcp::ReelMonoPictureAsset(mp, 0)), shared_ptr(new dcp::ReelSoundAsset(ms, 0)) ); - auto markers = make_shared(dcp::Fraction(24, 1), frames, 0); + auto markers = make_shared(dcp::Fraction(24, 1), frames); if (i == 0) { markers->set (dcp::Marker::FFOC, dcp::Time(0, 0, 0, 1, 24)); } @@ -377,7 +384,7 @@ make_simple (boost::filesystem::path path, int reels, int frames) shared_ptr simple_subtitle () { - return make_shared( + return std::make_shared( optional(), false, false, @@ -391,12 +398,14 @@ simple_subtitle () dcp::HAlign::CENTER, 0.8, dcp::VAlign::TOP, + 0, dcp::Direction::LTR, "Hello world", dcp::Effect::NONE, dcp::Colour(255, 255, 255), dcp::Time(), - dcp::Time() + dcp::Time(), + 0 ); } @@ -404,7 +413,7 @@ simple_subtitle () shared_ptr simple_markers (int frames) { - auto markers = make_shared(dcp::Fraction(24, 1), frames, 0); + auto markers = make_shared(dcp::Fraction(24, 1), frames); markers->set (dcp::Marker::FFOC, dcp::Time(1, 24, 24)); markers->set (dcp::Marker::LFOC, dcp::Time(frames - 1, 24, 24)); return markers; @@ -414,13 +423,14 @@ simple_markers (int frames) shared_ptr make_simple_with_interop_subs (boost::filesystem::path path) { - shared_ptr dcp = make_simple (path); + auto dcp = make_simple (path, 1, 24, dcp::Standard::INTEROP); - shared_ptr subs(new dcp::InteropSubtitleAsset()); + auto subs = make_shared(); subs->add (simple_subtitle()); boost::filesystem::create_directory (path / "subs"); dcp::ArrayData data(4096); + memset(data.data(), 0, data.size()); subs->add_font ("afont", data); subs->write (path / "subs" / "subs.xml"); @@ -434,9 +444,9 @@ make_simple_with_interop_subs (boost::filesystem::path path) shared_ptr make_simple_with_smpte_subs (boost::filesystem::path path) { - shared_ptr dcp = make_simple (path, 1, 192); + auto dcp = make_simple (path, 1, 192); - shared_ptr subs(new dcp::SMPTESubtitleAsset()); + auto subs = make_shared(); subs->set_language (dcp::LanguageTag("de-DE")); subs->set_start_time (dcp::Time()); subs->add (simple_subtitle()); @@ -453,14 +463,14 @@ make_simple_with_smpte_subs (boost::filesystem::path path) shared_ptr make_simple_with_interop_ccaps (boost::filesystem::path path) { - shared_ptr dcp = make_simple (path); + auto dcp = make_simple (path, 1, 24, dcp::Standard::INTEROP); - shared_ptr subs(new dcp::InteropSubtitleAsset()); + auto subs = make_shared(); subs->add (simple_subtitle()); subs->write (path / "ccap.xml"); - shared_ptr reel_caps(new dcp::ReelClosedCaptionAsset(subs, dcp::Fraction(24, 1), 240, 0)); - dcp->cpls().front()->reels().front()->add (reel_caps); + auto reel_caps = make_shared(subs, dcp::Fraction(24, 1), 240, 0); + dcp->cpls()[0]->reels()[0]->add (reel_caps); return dcp; } @@ -469,16 +479,16 @@ make_simple_with_interop_ccaps (boost::filesystem::path path) shared_ptr make_simple_with_smpte_ccaps (boost::filesystem::path path) { - shared_ptr dcp = make_simple (path, 1, 192); + auto dcp = make_simple (path, 1, 192); - shared_ptr subs(new dcp::SMPTESubtitleAsset()); + auto subs = make_shared(); subs->set_language (dcp::LanguageTag("de-DE")); subs->set_start_time (dcp::Time()); subs->add (simple_subtitle()); subs->write (path / "ccap.mxf"); - shared_ptr reel_caps(new dcp::ReelClosedCaptionAsset(subs, dcp::Fraction(24, 1), 192, 0)); - dcp->cpls().front()->reels().front()->add (reel_caps); + auto reel_caps = make_shared(subs, dcp::Fraction(24, 1), 192, 0); + dcp->cpls()[0]->reels()[0]->add(reel_caps); return dcp; } @@ -487,7 +497,7 @@ make_simple_with_smpte_ccaps (boost::filesystem::path path) shared_ptr black_image (dcp::Size size) { - shared_ptr image(new dcp::OpenJPEGImage(size)); + auto image = make_shared(size); int const pixels = size.width * size.height; for (int i = 0; i < 3; ++i) { memset (image->data(i), 0, pixels * sizeof(int)); @@ -499,20 +509,20 @@ black_image (dcp::Size size) shared_ptr black_picture_asset (boost::filesystem::path dir, int frames) { - shared_ptr image = black_image (); - dcp::ArrayData frame = dcp::compress_j2k (image, 100000000, 24, false, false); + auto image = black_image (); + auto frame = dcp::compress_j2k (image, 100000000, 24, false, false); BOOST_REQUIRE (frame.size() < 230000000 / (24 * 8)); auto asset = make_shared(dcp::Fraction(24, 1), dcp::Standard::SMPTE); asset->set_metadata (dcp::MXFMetadata("libdcp", "libdcp", "1.6.4devel")); boost::filesystem::create_directories (dir); - shared_ptr writer = asset->start_write (dir / "pic.mxf", true); + auto writer = asset->start_write(dir / "pic.mxf", dcp::PictureAsset::Behaviour::MAKE_NEW); for (int i = 0; i < frames; ++i) { writer->write (frame.data(), frame.size()); } writer->finalize (); - return shared_ptr(new dcp::ReelMonoPictureAsset(asset, 0)); + return make_shared(asset, 0); }