Whitespace.
[libdcp.git] / test / test.cc
index e43e5a70f9e922320a6a406cd423d137ac1ca44d..1f12bee4fcebd8dff0fb3c771f82fb3c5e9a802f 100644 (file)
 #include "smpte_subtitle_asset.h"
 #include "mono_picture_asset.h"
 #include "openjpeg_image.h"
-#include "j2k.h"
+#include "j2k_transcode.h"
 #include "picture_asset_writer.h"
 #include "reel_mono_picture_asset.h"
 #include "reel_asset.h"
 #include "test.h"
 #include "util.h"
+#include "reel_markers_asset.h"
 #include <asdcp/KM_util.h>
 #include <asdcp/KM_prng.h>
 #include <sndfile.h>
@@ -67,6 +68,7 @@ using std::string;
 using std::min;
 using std::vector;
 using std::shared_ptr;
+using std::make_shared;
 using boost::optional;
 
 
@@ -262,12 +264,19 @@ simple_picture (boost::filesystem::path path, string suffix, int frames)
        mxf_meta.product_name = "OpenDCP";
        mxf_meta.product_version = "0.0.25";
 
-       shared_ptr<dcp::MonoPictureAsset> mp (new dcp::MonoPictureAsset (dcp::Fraction (24, 1), dcp::SMPTE));
+       shared_ptr<dcp::MonoPictureAsset> mp (new dcp::MonoPictureAsset (dcp::Fraction (24, 1), dcp::Standard::SMPTE));
        mp->set_metadata (mxf_meta);
        shared_ptr<dcp::PictureAssetWriter> picture_writer = mp->start_write (path / dcp::String::compose("video%1.mxf", suffix), false);
-       dcp::ArrayData j2c ("test/data/flat_red.j2c");
+
+       dcp::Size const size (1998, 1080);
+       auto image = make_shared<dcp::OpenJPEGImage>(size);
+       for (int i = 0; i < 3; ++i) {
+               memset (image->data(i), 0, 2 * size.width * size.height);
+       }
+       auto j2c = dcp::compress_j2k (image, 100000000, 24, false, false);
+
        for (int i = 0; i < frames; ++i) {
-               picture_writer->write (j2c.data (), j2c.size ());
+               picture_writer->write (j2c.data(), j2c.size());
        }
        picture_writer->finalize ();
 
@@ -278,14 +287,14 @@ simple_picture (boost::filesystem::path path, string suffix, int frames)
 shared_ptr<dcp::SoundAsset>
 simple_sound (boost::filesystem::path path, string suffix, dcp::MXFMetadata mxf_meta, string language, int frames, int sample_rate)
 {
-       int const channels = 1;
+       int const channels = 6;
 
        /* Set a valid language, then overwrite it, so that the language parameter can be badly formed */
-       shared_ptr<dcp::SoundAsset> ms (new dcp::SoundAsset(dcp::Fraction(24, 1), sample_rate, channels, dcp::LanguageTag("en-US"), dcp::SMPTE));
+       shared_ptr<dcp::SoundAsset> ms (new dcp::SoundAsset(dcp::Fraction(24, 1), sample_rate, channels, dcp::LanguageTag("en-US"), dcp::Standard::SMPTE));
        ms->_language = language;
        ms->set_metadata (mxf_meta);
        vector<dcp::Channel> active_channels;
-       active_channels.push_back (dcp::LEFT);
+       active_channels.push_back (dcp::Channel::LEFT);
        shared_ptr<dcp::SoundAssetWriter> sound_writer = ms->start_write (path / dcp::String::compose("audio%1.mxf", suffix), active_channels);
 
        int const samples_per_frame = sample_rate / 24;
@@ -321,8 +330,8 @@ make_simple (boost::filesystem::path path, int reels, int frames)
 
        boost::filesystem::remove_all (path);
        boost::filesystem::create_directories (path);
-       shared_ptr<dcp::DCP> d (new dcp::DCP (path));
-       shared_ptr<dcp::CPL> cpl (new dcp::CPL ("A Test DCP", dcp::TRAILER));
+       auto d = make_shared<dcp::DCP>(path);
+       auto cpl = make_shared<dcp::CPL>("A Test DCP", dcp::ContentKind::TRAILER);
        cpl->set_annotation_text ("A Test DCP");
        cpl->set_issuer ("OpenDCP 0.0.25");
        cpl->set_creator ("OpenDCP 0.0.25");
@@ -330,6 +339,11 @@ 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_picture_stored_area(dcp::Size(1998, 1080));
+       cpl->set_main_picture_active_area(dcp::Size(1998, 1080));
+       cpl->set_version_number(1);
 
        for (int i = 0; i < reels; ++i) {
                string suffix = reels == 1 ? "" : dcp::String::compose("%1", i);
@@ -337,12 +351,21 @@ make_simple (boost::filesystem::path path, int reels, int frames)
                shared_ptr<dcp::MonoPictureAsset> mp = simple_picture (path, suffix, frames);
                shared_ptr<dcp::SoundAsset> ms = simple_sound (path, suffix, mxf_meta, "en-US", frames);
 
-               cpl->add (shared_ptr<dcp::Reel> (
-                                 new dcp::Reel (
-                                         shared_ptr<dcp::ReelMonoPictureAsset>(new dcp::ReelMonoPictureAsset(mp, 0)),
-                                         shared_ptr<dcp::ReelSoundAsset>(new dcp::ReelSoundAsset(ms, 0))
-                                         )
-                                 ));
+               auto reel = make_shared<dcp::Reel>(
+                       shared_ptr<dcp::ReelMonoPictureAsset>(new dcp::ReelMonoPictureAsset(mp, 0)),
+                       shared_ptr<dcp::ReelSoundAsset>(new dcp::ReelSoundAsset(ms, 0))
+                       );
+
+               auto markers = make_shared<dcp::ReelMarkersAsset>(dcp::Fraction(24, 1), frames, 0);
+               if (i == 0) {
+                       markers->set (dcp::Marker::FFOC, dcp::Time(0, 0, 0, 1, 24));
+               }
+               if (i == reels - 1) {
+                       markers->set (dcp::Marker::LFOC, dcp::Time(0, 0, 0, frames - 1, 24));
+               }
+               reel->add (markers);
+
+               cpl->add (reel);
        }
 
        d->add (cpl);
@@ -353,32 +376,40 @@ make_simple (boost::filesystem::path path, int reels, int frames)
 shared_ptr<dcp::Subtitle>
 simple_subtitle ()
 {
-       return shared_ptr<dcp::Subtitle>(
-               new dcp::SubtitleString(
-                       optional<string>(),
-                       false,
-                       false,
-                       false,
-                       dcp::Colour(255, 255, 255),
-                       42,
-                       1,
-                       dcp::Time(0, 0, 4, 0, 24),
-                       dcp::Time(0, 0, 8, 0, 24),
-                       0.5,
-                       dcp::HALIGN_CENTER,
-                       0.8,
-                       dcp::VALIGN_TOP,
-                       dcp::DIRECTION_LTR,
-                       "Hello world",
-                       dcp::NONE,
-                       dcp::Colour(255, 255, 255),
-                       dcp::Time(),
-                       dcp::Time()
-                       )
+       return make_shared<dcp::SubtitleString>(
+               optional<string>(),
+               false,
+               false,
+               false,
+               dcp::Colour(255, 255, 255),
+               42,
+               1,
+               dcp::Time(0, 0, 4, 0, 24),
+               dcp::Time(0, 0, 8, 0, 24),
+               0.5,
+               dcp::HAlign::CENTER,
+               0.8,
+               dcp::VAlign::TOP,
+               dcp::Direction::LTR,
+               "Hello world",
+               dcp::Effect::NONE,
+               dcp::Colour(255, 255, 255),
+               dcp::Time(),
+               dcp::Time()
                );
 }
 
 
+shared_ptr<dcp::ReelMarkersAsset>
+simple_markers (int frames)
+{
+       auto markers = make_shared<dcp::ReelMarkersAsset>(dcp::Fraction(24, 1), frames, 0);
+       markers->set (dcp::Marker::FFOC, dcp::Time(1, 24, 24));
+       markers->set (dcp::Marker::LFOC, dcp::Time(frames - 1, 24, 24));
+       return markers;
+}
+
+
 shared_ptr<dcp::DCP>
 make_simple_with_interop_subs (boost::filesystem::path path)
 {
@@ -471,7 +502,7 @@ black_picture_asset (boost::filesystem::path dir, int frames)
        dcp::ArrayData frame = dcp::compress_j2k (image, 100000000, 24, false, false);
        BOOST_REQUIRE (frame.size() < 230000000 / (24 * 8));
 
-       shared_ptr<dcp::MonoPictureAsset> asset(new dcp::MonoPictureAsset(dcp::Fraction(24, 1), dcp::SMPTE));
+       auto asset = make_shared<dcp::MonoPictureAsset>(dcp::Fraction(24, 1), dcp::Standard::SMPTE);
        asset->set_metadata (dcp::MXFMetadata("libdcp", "libdcp", "1.6.4devel"));
        boost::filesystem::create_directories (dir);
        shared_ptr<dcp::PictureAssetWriter> writer = asset->start_write (dir / "pic.mxf", true);
@@ -484,4 +515,19 @@ black_picture_asset (boost::filesystem::path dir, int frames)
 }
 
 
+boost::filesystem::path
+find_file (boost::filesystem::path dir, string filename_part)
+{
+       boost::optional<boost::filesystem::path> found;
+       for (auto i: boost::filesystem::directory_iterator(dir)) {
+               if (i.path().filename().string().find(filename_part) != string::npos) {
+                       BOOST_REQUIRE (!found);
+                       found = i;
+               }
+       }
+       BOOST_REQUIRE (found);
+       return *found;
+}
+
+
 BOOST_GLOBAL_FIXTURE (TestConfig);