Only add fonts to assets when they are required.
[dcpomatic.git] / src / lib / writer.cc
index 2dd46f0b2324f4516364b319ab2a1561542cba26..d42b23478f469e68e4c650f03b5606c918e2ec57 100644 (file)
@@ -23,6 +23,7 @@
 #include "audio_mapping.h"
 #include "compose.hpp"
 #include "config.h"
+#include "constants.h"
 #include "cross.h"
 #include "dcp_content_type.h"
 #include "dcp_video.h"
@@ -153,19 +154,11 @@ Writer::write (shared_ptr<const Data> encoded, Frame frame, Eyes eyes)
        qi.reel = video_reel (frame);
        qi.frame = frame - _reels[qi.reel].start ();
 
-       if (film()->three_d() && eyes == Eyes::BOTH) {
-               /* 2D material in a 3D DCP; fake the 3D */
-               qi.eyes = Eyes::LEFT;
-               _queue.push_back (qi);
-               ++_queued_full_in_memory;
-               qi.eyes = Eyes::RIGHT;
-               _queue.push_back (qi);
-               ++_queued_full_in_memory;
-       } else {
-               qi.eyes = eyes;
-               _queue.push_back (qi);
-               ++_queued_full_in_memory;
-       }
+       DCPOMATIC_ASSERT((film()->three_d() && eyes != Eyes::BOTH) || (!film()->three_d() && eyes == Eyes::BOTH));
+
+       qi.eyes = eyes;
+       _queue.push_back(qi);
+       ++_queued_full_in_memory;
 
        /* Now there's something to do: wake anything wait()ing on _empty_condition */
        _empty_condition.notify_all ();
@@ -239,17 +232,12 @@ Writer::fake_write (Frame frame, Eyes eyes)
                qi.size = _reels[reel].read_frame_info(info_file, frame_in_reel, eyes).size;
        }
 
+       DCPOMATIC_ASSERT((film()->three_d() && eyes != Eyes::BOTH) || (!film()->three_d() && eyes == Eyes::BOTH));
+
        qi.reel = reel;
        qi.frame = frame_in_reel;
-       if (film()->three_d() && eyes == Eyes::BOTH) {
-               qi.eyes = Eyes::LEFT;
-               _queue.push_back (qi);
-               qi.eyes = Eyes::RIGHT;
-               _queue.push_back (qi);
-       } else {
-               qi.eyes = eyes;
-               _queue.push_back (qi);
-       }
+       qi.eyes = eyes;
+       _queue.push_back(qi);
 
        /* Now there's something to do: wake anything wait()ing on _empty_condition */
        _empty_condition.notify_all ();
@@ -605,7 +593,7 @@ Writer::finish (boost::filesystem::path output_dcp)
        /* Add reels */
 
        for (auto& i: _reels) {
-               cpl->add (i.create_reel(_reel_assets, _fonts, _chosen_interop_font, output_dcp, _have_subtitles, _have_closed_captions));
+               cpl->add(i.create_reel(_reel_assets, output_dcp, _have_subtitles, _have_closed_captions));
        }
 
        /* Add metadata */
@@ -657,27 +645,26 @@ Writer::finish (boost::filesystem::path output_dcp)
                cpl->set_sign_language_video_language (*film()->sign_language_video_language());
        }
 
-       auto ac = film()->mapped_audio_channels();
-       dcp::MCASoundField field = (
-               find(ac.begin(), ac.end(), static_cast<int>(dcp::Channel::BSL)) != ac.end() ||
-               find(ac.begin(), ac.end(), static_cast<int>(dcp::Channel::BSR)) != ac.end()
-               ) ? dcp::MCASoundField::SEVEN_POINT_ONE : dcp::MCASoundField::FIVE_POINT_ONE;
+       dcp::MCASoundField field;
+       if (film()->audio_channels() <= 6) {
+               field = dcp::MCASoundField::FIVE_POINT_ONE;
+       } else {
+               field = dcp::MCASoundField::SEVEN_POINT_ONE;
+       }
 
-       dcp::MainSoundConfiguration msc (field, film()->audio_channels());
-       for (auto i: ac) {
-               if (static_cast<int>(i) < film()->audio_channels()) {
-                       msc.set_mapping (i, static_cast<dcp::Channel>(i));
-               }
+       dcp::MainSoundConfiguration msc(field, MAX_DCP_AUDIO_CHANNELS);
+       for (auto i: film()->mapped_audio_channels()) {
+               msc.set_mapping(i, static_cast<dcp::Channel>(i));
        }
 
-       cpl->set_main_sound_configuration (msc.to_string());
+       cpl->set_main_sound_configuration(msc);
        cpl->set_main_sound_sample_rate (film()->audio_frame_rate());
        cpl->set_main_picture_stored_area (film()->frame_size());
 
        auto active_area = film()->active_area();
        if (active_area.width > 0 && active_area.height > 0) {
-               /* It's not allowed to have a zero active area width or height */
-               cpl->set_main_picture_active_area (active_area);
+               /* It's not allowed to have a zero active area width or height, and the sizes must be multiples of 2 */
+               cpl->set_main_picture_active_area({ active_area.width & ~1, active_area.height & ~1});
        }
 
        auto sl = film()->subtitle_languages().second;
@@ -696,7 +683,7 @@ Writer::finish (boost::filesystem::path output_dcp)
        dcp.set_creator(creator);
        dcp.set_annotation_text(film()->dcp_name());
 
-       dcp.write_xml (signer, Config::instance()->dcp_metadata_filename_format());
+       dcp.write_xml(signer, !film()->limit_to_smpte_bv20(), Config::instance()->dcp_metadata_filename_format());
 
        LOG_GENERAL (
                N_("Wrote %1 FULL, %2 FAKE, %3 REPEAT, %4 pushed to disk"), _full_written, _fake_written, _repeat_written, _pushed_to_disk
@@ -855,7 +842,7 @@ Writer::write (PlayerText text, TextType type, optional<DCPTextTrack> track, DCP
                period = back_off(period);
        }
 
-       (*reel)->write(text, type, track, period, _fonts);
+       (*reel)->write(text, type, track, period, _fonts, _chosen_interop_font);
 }
 
 
@@ -1029,7 +1016,7 @@ Writer::write_hanging_text (ReelWriter& reel)
        vector<HangingText> new_hanging_texts;
        for (auto i: _hanging_texts) {
                if (i.period.from == reel.period().from) {
-                       reel.write (i.text, i.type, i.track, i.period, _fonts);
+                       reel.write(i.text, i.type, i.track, i.period, _fonts, _chosen_interop_font);
                } else {
                        new_hanging_texts.push_back (i);
                }