X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Freel_writer.cc;h=658de0a62953bbd5b498c8f58f09f9a7e198e8ae;hb=86b88c37c34de9cd0c51e0825d28b6258e2451d2;hp=47df4feb159ac458dc2556df203d3e9edfdc2b6e;hpb=5e7ec41119961114a9b4df90d1c9ced580667f54;p=dcpomatic.git diff --git a/src/lib/reel_writer.cc b/src/lib/reel_writer.cc index 47df4feb1..658de0a62 100644 --- a/src/lib/reel_writer.cc +++ b/src/lib/reel_writer.cc @@ -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::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 extra_active_channels; + auto add_if_mapped = [mapped, &extra_active_channels](dcp::Channel channel) { + if (std::find(mapped.begin(), mapped.end(), static_cast(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 ); } @@ -460,9 +477,6 @@ maybe_add_text ( int reel_count, optional content_summary, list const & refs, - FontIdMap const& fonts, - shared_ptr chosen_interop_font, - dcp::ArrayData default_font, shared_ptr film, DCPTimePeriod period, boost::filesystem::path output_dcp, @@ -474,19 +488,6 @@ maybe_add_text ( shared_ptr 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 (auto interop = dynamic_pointer_cast(asset)) { auto directory = output_dcp / interop->id (); boost::filesystem::create_directories (directory); @@ -644,8 +645,6 @@ void ReelWriter::create_reel_text ( shared_ptr reel, list const & refs, - FontIdMap const& fonts, - shared_ptr chosen_interop_font, int64_t duration, boost::filesystem::path output_dcp, bool ensure_subtitles, @@ -653,7 +652,7 @@ ReelWriter::create_reel_text ( ) const { auto subtitle = maybe_add_text ( - _subtitle_asset, duration, reel, _reel_index, _reel_count, _content_summary, refs, fonts, chosen_interop_font, _default_font, film(), _period, output_dcp, _text_only + _subtitle_asset, duration, reel, _reel_index, _reel_count, _content_summary, refs, film(), _period, output_dcp, _text_only ); if (subtitle) { @@ -671,9 +670,6 @@ ReelWriter::create_reel_text ( _reel_count, _content_summary, refs, - fonts, - chosen_interop_font, - _default_font, film(), _period, output_dcp, @@ -683,7 +679,7 @@ ReelWriter::create_reel_text ( for (auto const& i: _closed_caption_assets) { auto a = maybe_add_text ( - i.second, duration, reel, _reel_index, _reel_count, _content_summary, refs, fonts, chosen_interop_font, _default_font, film(), _period, output_dcp, _text_only + i.second, duration, reel, _reel_index, _reel_count, _content_summary, refs, film(), _period, output_dcp, _text_only ); DCPOMATIC_ASSERT (a); a->set_annotation_text (i.first.name); @@ -704,9 +700,6 @@ ReelWriter::create_reel_text ( _reel_count, _content_summary, refs, - fonts, - chosen_interop_font, - _default_font, film(), _period, output_dcp, @@ -751,8 +744,6 @@ ReelWriter::create_reel_markers (shared_ptr reel) const shared_ptr ReelWriter::create_reel ( list const & refs, - FontIdMap const & fonts, - shared_ptr chosen_interop_font, boost::filesystem::path output_dcp, bool ensure_subtitles, set ensure_closed_captions @@ -771,10 +762,12 @@ ReelWriter::create_reel ( auto reel_picture_asset = create_reel_picture (reel, refs); duration = reel_picture_asset->actual_duration (); create_reel_sound (reel, refs); - create_reel_markers (reel); + if (!film()->interop()) { + create_reel_markers(reel); + } } - create_reel_text (reel, refs, fonts, chosen_interop_font, duration, output_dcp, ensure_subtitles, ensure_closed_captions); + create_reel_text(reel, refs, duration, output_dcp, ensure_subtitles, ensure_closed_captions); if (_atmos_asset) { reel->add (make_shared(_atmos_asset, 0)); @@ -820,7 +813,7 @@ ReelWriter::write (shared_ptr audio) } DCPOMATIC_ASSERT (audio); - _sound_asset_writer->write (audio->data(), audio->frames()); + _sound_asset_writer->write(audio->data(), audio->channels(), audio->frames()); } @@ -920,7 +913,7 @@ ReelWriter::convert_vertical_position(StringText const& subtitle, dcp::SubtitleS void -ReelWriter::write (PlayerText subs, TextType type, optional track, DCPTimePeriod period, FontIdMap const& fonts) +ReelWriter::write(PlayerText subs, TextType type, optional track, DCPTimePeriod period, FontIdMap const& fonts, shared_ptr chosen_interop_font) { shared_ptr asset; @@ -960,10 +953,18 @@ ReelWriter::write (PlayerText subs, TextType type, optional track, i.set_out (dcp::Time(period.to.seconds() - _period.from.seconds(), tcr)); i.set_v_position(convert_vertical_position(i, film()->interop() ? dcp::SubtitleStandard::INTEROP : dcp::SubtitleStandard::SMPTE_2014)); auto sub = make_shared(i); - if (type == TextType::OPEN_SUBTITLE) { - sub->set_font(fonts.get(i.font)); - } + /* i.font is a shared_ptr which uniquely identifies the font we want, + * though if we are Interop we can only have one font, so we'll use the chosen + * one instead. + */ + auto font = film()->interop() ? chosen_interop_font : i.font; + /* We can get the corresponding ID from fonts */ + auto const font_id_to_use = fonts.get(font); + /* Give this subtitle the correct font ID */ + sub->set_font(font_id_to_use); asset->add(sub); + /* Make sure the asset LoadFonts the font we just asked for */ + asset->ensure_font(font_id_to_use, font->data().get_value_or(_default_font)); } for (auto i: subs.bitmap) {