X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fdcp_content.cc;h=8698c4ecd8325ef712b59ad600333290d3e5d67f;hb=d8a19dca28268e3ac92f117d00c1064c0b06515c;hp=57c103e03113f931ae8c56249ab3d7b44329b705;hpb=1d68fe1e3ad1a9aa85fa7fc6071a0b8c64973953;p=dcpomatic.git diff --git a/src/lib/dcp_content.cc b/src/lib/dcp_content.cc index 57c103e03..8698c4ecd 100644 --- a/src/lib/dcp_content.cc +++ b/src/lib/dcp_content.cc @@ -22,10 +22,17 @@ #include "job.h" #include "film.h" #include "config.h" +#include "overlaps.h" #include "compose.hpp" +#include "dcp_decoder.h" #include #include +#include +#include +#include +#include #include +#include #include "i18n.h" @@ -35,9 +42,13 @@ using std::distance; using std::pair; using std::list; using boost::shared_ptr; +using boost::scoped_ptr; using boost::optional; -int const DCPContentProperty::CAN_BE_PLAYED = 600; +int const DCPContentProperty::CAN_BE_PLAYED = 600; +int const DCPContentProperty::REFERENCE_VIDEO = 601; +int const DCPContentProperty::REFERENCE_AUDIO = 602; +int const DCPContentProperty::REFERENCE_SUBTITLE = 603; DCPContent::DCPContent (shared_ptr film, boost::filesystem::path p) : Content (film) @@ -47,10 +58,11 @@ DCPContent::DCPContent (shared_ptr film, boost::filesystem::path p) , _has_subtitles (false) , _encrypted (false) , _kdm_valid (false) + , _reference_video (false) + , _reference_audio (false) + , _reference_subtitle (false) { read_directory (p); - /* Default to no colour conversion for DCPs */ - unset_colour_conversion (false); } DCPContent::DCPContent (shared_ptr film, cxml::ConstNodePtr node, int version) @@ -66,6 +78,9 @@ DCPContent::DCPContent (shared_ptr film, cxml::ConstNodePtr node, in _kdm = dcp::EncryptedKDM (node->string_child ("KDM")); } _kdm_valid = node->bool_child ("KDMValid"); + _reference_video = node->optional_bool_child ("ReferenceVideo").get_value_or (false); + _reference_audio = node->optional_bool_child ("ReferenceAudio").get_value_or (false); + _reference_subtitle = node->optional_bool_child ("ReferenceSubtitle").get_value_or (false); } void @@ -138,21 +153,26 @@ DCPContent::as_xml (xmlpp::Node* node) const node->add_child("KDM")->add_child_text (_kdm->as_xml ()); } node->add_child("KDMValid")->add_child_text (_kdm_valid ? "1" : "0"); + node->add_child("ReferenceVideo")->add_child_text (_reference_video ? "1" : "0"); + node->add_child("ReferenceAudio")->add_child_text (_reference_audio ? "1" : "0"); + node->add_child("ReferenceSubtitle")->add_child_text (_reference_subtitle ? "1" : "0"); } DCPTime DCPContent::full_length () const { - shared_ptr film = _film.lock (); - DCPOMATIC_ASSERT (film); - FrameRateChange const frc (video_frame_rate (), film->video_frame_rate ()); - return DCPTime::from_frames (llrint (video_length () * frc.factor ()), film->video_frame_rate ()); + FrameRateChange const frc (video_frame_rate (), film()->video_frame_rate ()); + return DCPTime::from_frames (llrint (video_length () * frc.factor ()), film()->video_frame_rate ()); } string DCPContent::identifier () const { - return SubtitleContent::identifier (); + SafeStringStream s; + s << VideoContent::identifier() << "_" << SubtitleContent::identifier () << " " + << (_reference_video ? "1" : "0") + << (_reference_subtitle ? "1" : "0"); + return s.str (); } void @@ -185,7 +205,139 @@ DCPContent::directory () const } void -DCPContent::add_properties (list >& p) const +DCPContent::add_properties (list& p) const { SingleStreamAudioContent::add_properties (p); } + +void +DCPContent::set_default_colour_conversion () +{ + /* Default to no colour conversion for DCPs */ + unset_colour_conversion (); +} + +void +DCPContent::set_reference_video (bool r) +{ + { + boost::mutex::scoped_lock lm (_mutex); + _reference_video = r; + } + + signal_changed (DCPContentProperty::REFERENCE_VIDEO); +} + +void +DCPContent::set_reference_audio (bool r) +{ + { + boost::mutex::scoped_lock lm (_mutex); + _reference_audio = r; + } + + signal_changed (DCPContentProperty::REFERENCE_AUDIO); +} + +void +DCPContent::set_reference_subtitle (bool r) +{ + { + boost::mutex::scoped_lock lm (_mutex); + _reference_subtitle = r; + } + + signal_changed (DCPContentProperty::REFERENCE_SUBTITLE); +} + +list +DCPContent::reels () const +{ + list p; + scoped_ptr decoder; + try { + decoder.reset (new DCPDecoder (shared_from_this(), false)); + } catch (...) { + /* Could not load the DCP; guess reels */ + list p; + p.push_back (DCPTimePeriod (position(), end())); + return p; + } + + DCPTime from = position (); + BOOST_FOREACH (shared_ptr i, decoder->reels()) { + DCPTime const to = from + DCPTime::from_frames (i->main_picture()->duration(), film()->video_frame_rate()); + p.push_back (DCPTimePeriod (from, to)); + from = to; + } + + return p; +} + +list +DCPContent::reel_split_points () const +{ + list s; + BOOST_FOREACH (DCPTimePeriod i, reels()) { + s.push_back (i.from); + } + return s; +} + +template +bool +DCPContent::can_reference (string overlapping, list& why_not) const +{ + list const fr = film()->reels (); + /* fr must contain reels(). It can also contain other reels, but it must at + least contain reels(). + */ + BOOST_FOREACH (DCPTimePeriod i, reels()) { + if (find (fr.begin(), fr.end(), i) == fr.end ()) { + why_not.push_back (_("Reel lengths in the project differ from those in the DCP; set the reel mode to 'split by video content'.")); + return false; + } + } + + list > a = overlaps (film()->content(), position(), end()); + if (a.size() != 1 || a.front().get() != this) { + why_not.push_back (overlapping); + return false; + } + + return true; +} + +bool +DCPContent::can_reference_video (list& why_not) const +{ + return can_reference (_("There is other video content overlapping this DCP; remove it."), why_not); +} + +bool +DCPContent::can_reference_audio (list& why_not) const +{ + DCPDecoder decoder (shared_from_this(), false); + BOOST_FOREACH (shared_ptr i, decoder.reels()) { + if (!i->main_sound()) { + why_not.push_back (_("The DCP does not have sound in all reels.")); + return false; + } + } + + return can_reference (_("There is other audio content overlapping this DCP; remove it."), why_not); +} + +bool +DCPContent::can_reference_subtitle (list& why_not) const +{ + DCPDecoder decoder (shared_from_this(), false); + BOOST_FOREACH (shared_ptr i, decoder.reels()) { + if (!i->main_subtitle()) { + why_not.push_back (_("The DCP does not have subtitles in all reels.")); + return false; + } + } + + return can_reference (_("There is other subtitle content overlapping this DCP; remove it."), why_not); +}