#include "audio_buffers.h"
#include "compose.hpp"
#include "config.h"
+#include "constants.h"
#include "cross.h"
#include "dcpomatic_log.h"
#include "digester.h"
, _content_summary (film()->content_summary(period))
, _job (job)
, _text_only (text_only)
+ , _font_metrics(film()->frame_size().height)
{
/* Create or find our picture asset in a subdirectory, named
according to those film's parameters which affect the video
}
_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? */
_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
);
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
);
}
int reel_count,
optional<string> content_summary,
list<ReferencedReelAsset> const & refs,
- FontIdMap const& fonts,
- shared_ptr<dcpomatic::Font> chosen_interop_font,
- dcp::ArrayData default_font,
shared_ptr<const Film> film,
DCPTimePeriod period,
boost::filesystem::path output_dcp,
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 (auto interop = dynamic_pointer_cast<dcp::InteropSubtitleAsset>(asset)) {
auto directory = output_dcp / interop->id ();
boost::filesystem::create_directories (directory);
ReelWriter::create_reel_text (
shared_ptr<dcp::Reel> reel,
list<ReferencedReelAsset> const & refs,
- FontIdMap const& fonts,
- shared_ptr<dcpomatic::Font> chosen_interop_font,
int64_t duration,
boost::filesystem::path output_dcp,
bool ensure_subtitles,
) const
{
auto subtitle = maybe_add_text<dcp::ReelInteropSubtitleAsset, dcp::ReelSMPTESubtitleAsset, dcp::ReelSubtitleAsset> (
- _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) {
_reel_count,
_content_summary,
refs,
- fonts,
- chosen_interop_font,
- _default_font,
film(),
_period,
output_dcp,
for (auto const& i: _closed_caption_assets) {
auto a = maybe_add_text<dcp::ReelInteropClosedCaptionAsset, dcp::ReelSMPTEClosedCaptionAsset, dcp::ReelClosedCaptionAsset> (
- 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);
_reel_count,
_content_summary,
refs,
- fonts,
- chosen_interop_font,
- _default_font,
film(),
_period,
output_dcp,
shared_ptr<dcp::Reel>
ReelWriter::create_reel (
list<ReferencedReelAsset> const & refs,
- FontIdMap const & fonts,
- shared_ptr<dcpomatic::Font> chosen_interop_font,
boost::filesystem::path output_dcp,
bool ensure_subtitles,
set<DCPTextTrack> ensure_closed_captions
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<dcp::ReelAtmosAsset>(_atmos_asset, 0));
}
DCPOMATIC_ASSERT (audio);
- _sound_asset_writer->write (audio->data(), audio->frames());
+ _sound_asset_writer->write(audio->data(), audio->channels(), audio->frames());
}
if (film()->encrypted()) {
s->set_key (film()->key());
}
- if (with_dummy) {
- s->add (
- std::make_shared<dcp::SubtitleString>(
- optional<std::string>(),
- false,
- false,
- false,
- dcp::Colour(),
- 42,
- 1.0,
- dcp::Time(0, 0, 0, 0, 24),
- dcp::Time(0, 0, 1, 0, 24),
- 0.5,
- dcp::HAlign::CENTER,
- 0.5,
- dcp::VAlign::CENTER,
- dcp::Direction::LTR,
- " ",
- dcp::Effect::NONE,
- dcp::Colour(),
- dcp::Time(),
- dcp::Time(),
- 0
- )
- );
- }
asset = s;
}
+ if (with_dummy) {
+ asset->add(
+ std::make_shared<dcp::SubtitleString>(
+ optional<std::string>(),
+ false,
+ false,
+ false,
+ dcp::Colour(),
+ 42,
+ 1.0,
+ dcp::Time(0, 0, 0, 0, 24),
+ dcp::Time(0, 0, 1, 0, 24),
+ 0.5,
+ dcp::HAlign::CENTER,
+ 0.5,
+ dcp::VAlign::CENTER,
+ 0,
+ dcp::Direction::LTR,
+ " ",
+ dcp::Effect::NONE,
+ dcp::Colour(),
+ dcp::Time(),
+ dcp::Time(),
+ 0
+ )
+ );
+ }
+
return asset;
}
+float
+ReelWriter::convert_vertical_position(StringText const& subtitle, dcp::SubtitleStandard to) const
+{
+ if (dcp::uses_baseline(subtitle.valign_standard) == dcp::uses_baseline(to)) {
+ /* The from and to standards use the same alignment reference */
+ return subtitle.v_position();
+ }
+
+ auto const baseline_to_bottom = _font_metrics.baseline_to_bottom(subtitle);
+ auto const height = _font_metrics.height(subtitle);
+
+ float correction = 0;
+ switch (subtitle.v_align()) {
+ case dcp::VAlign::TOP:
+ correction = height - baseline_to_bottom;
+ break;
+ case dcp::VAlign::CENTER:
+ correction = (height / 2) - baseline_to_bottom;
+ break;
+ case dcp::VAlign::BOTTOM:
+ correction = baseline_to_bottom;
+ break;
+ }
+
+ return subtitle.v_position() + (dcp::uses_bounding_box(subtitle.valign_standard) ? correction : -correction);
+}
+
+
void
-ReelWriter::write (PlayerText subs, TextType type, optional<DCPTextTrack> track, DCPTimePeriod period, FontIdMap const& fonts)
+ReelWriter::write(PlayerText subs, TextType type, optional<DCPTextTrack> track, DCPTimePeriod period, FontIdMap const& fonts, shared_ptr<dcpomatic::Font> chosen_interop_font)
{
shared_ptr<dcp::SubtitleAsset> asset;
for (auto i: subs.string) {
i.set_in (dcp::Time(period.from.seconds() - _period.from.seconds(), tcr));
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<dcp::SubtitleString>(i);
- if (type == TextType::OPEN_SUBTITLE) {
- sub->set_font(fonts.get(i.font));
- }
+ /* i.font is a shared_ptr<Font> 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) {
image_as_png(i.image),
dcp::Time(period.from.seconds() - _period.from.seconds(), tcr),
dcp::Time(period.to.seconds() - _period.from.seconds(), tcr),
- i.rectangle.x, dcp::HAlign::LEFT, i.rectangle.y, dcp::VAlign::TOP,
+ i.rectangle.x, dcp::HAlign::LEFT, i.rectangle.y, dcp::VAlign::TOP, 0,
dcp::Time(), dcp::Time()
)
);