Don't add fonts to SMPTE closed caption MXFs (#2505).
[dcpomatic.git] / src / lib / reel_writer.cc
index 47df4feb159ac458dc2556df203d3e9edfdc2b6e..5d9f4dae0d9a19e1af95c1dd19b08ffc10ad4fe0 100644 (file)
@@ -22,6 +22,7 @@
 #include "audio_buffers.h"
 #include "compose.hpp"
 #include "config.h"
+#include "constants.h"
 #include "cross.h"
 #include "dcpomatic_log.h"
 #include "digester.h"
@@ -161,7 +162,7 @@ ReelWriter::ReelWriter (
                }
 
                _picture_asset->set_file (asset);
-               _picture_asset_writer = _picture_asset->start_write (asset, _first_nonexistent_frame > 0);
+               _picture_asset_writer = _picture_asset->start_write(asset, _first_nonexistent_frame > 0 ? dcp::PictureAsset::Behaviour::OVERWRITE_EXISTING : dcp::PictureAsset::Behaviour::MAKE_NEW);
        } else if (!text_only) {
                /* We already have a complete picture asset that we can just re-use */
                /* XXX: what about if the encryption key changes? */
@@ -177,7 +178,8 @@ ReelWriter::ReelWriter (
                _sound_asset = make_shared<dcp::SoundAsset> (
                        dcp::Fraction(film()->video_frame_rate(), 1),
                        film()->audio_frame_rate(),
-                       film()->audio_channels(),
+                       /* Always make 16-channel sound assets for SMPTE; libdcp will pad unused channels for us */
+                       standard == dcp::Standard::SMPTE ? MAX_DCP_AUDIO_CHANNELS : film()->audio_channels(),
                        lang ? *lang : dcp::LanguageTag("en-US"),
                        standard
                        );
@@ -190,12 +192,27 @@ ReelWriter::ReelWriter (
 
                DCPOMATIC_ASSERT (film()->directory());
 
+               auto mapped = film()->mapped_audio_channels();
+               std::vector<dcp::Channel> extra_active_channels;
+               auto add_if_mapped = [mapped, &extra_active_channels](dcp::Channel channel) {
+                       if (std::find(mapped.begin(), mapped.end(), static_cast<int>(channel)) != mapped.end()) {
+                               extra_active_channels.push_back(channel);
+                       }
+               };
+
+               add_if_mapped(dcp::Channel::HI);
+               add_if_mapped(dcp::Channel::VI);
+               add_if_mapped(dcp::Channel::BSL);
+               add_if_mapped(dcp::Channel::BSR);
+
                /* Write the sound asset into the film directory so that we leave the creation
                   of the DCP directory until the last minute.
                */
                _sound_asset_writer = _sound_asset->start_write (
                        film()->directory().get() / audio_asset_filename (_sound_asset, _reel_index, _reel_count, _content_summary),
-                       film()->contains_atmos_content()
+                       extra_active_channels,
+                       film()->contains_atmos_content() ? dcp::SoundAsset::AtmosSync::ENABLED : dcp::SoundAsset::AtmosSync::DISABLED,
+                       film()->limit_to_smpte_bv20() ? dcp::SoundAsset::MCASubDescriptors::DISABLED : dcp::SoundAsset::MCASubDescriptors::ENABLED
                        );
        }
 
@@ -474,16 +491,18 @@ maybe_add_text (
        shared_ptr<Result> reel_asset;
 
        if (asset) {
-               if (film->interop()) {
-                       if (chosen_interop_font) {
-                               /* We only add one font, as Interop will ignore subsequent ones (and some validators will
-                                * complain if they are even present)
-                                */
-                               asset->add_font(fonts.get(chosen_interop_font), chosen_interop_font->data().get_value_or(default_font));
-                       }
-               } else {
-                       for (auto const& font: fonts.map()) {
-                               asset->add_font(font.second, font.first->data().get_value_or(default_font));
+               if (!std::is_same<Result, dcp::ReelClosedCaptionAsset>::value) {
+                       if (film->interop()) {
+                               if (chosen_interop_font) {
+                                       /* We only add one font, as Interop will ignore subsequent ones (and some validators will
+                                        * complain if they are even present)
+                                        */
+                                       asset->add_font(fonts.get(chosen_interop_font), chosen_interop_font->data().get_value_or(default_font));
+                               }
+                       } else {
+                               for (auto const& font: fonts.map()) {
+                                       asset->add_font(font.second, font.first->data().get_value_or(default_font));
+                               }
                        }
                }
 
@@ -820,7 +839,7 @@ ReelWriter::write (shared_ptr<const AudioBuffers> audio)
        }
 
        DCPOMATIC_ASSERT (audio);
-       _sound_asset_writer->write (audio->data(), audio->frames());
+       _sound_asset_writer->write(audio->data(), audio->channels(), audio->frames());
 }