Front-end to set up referencing of DCPs.
[dcpomatic.git] / src / lib / dcp_content.cc
index b1c9e3815fd916b8edb57ee7e9bad8576052a3c6..cb9dcf53d6dc184caaa47f098fb3954b2a3eec8a 100644 (file)
@@ -25,7 +25,9 @@
 #include "compose.hpp"
 #include <dcp/dcp.h>
 #include <dcp/exceptions.h>
+#include <libxml++/libxml++.h>
 #include <iterator>
+#include <iostream>
 
 #include "i18n.h"
 
@@ -37,7 +39,10 @@ using std::list;
 using boost::shared_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<const Film> film, boost::filesystem::path p)
        : Content (film)
@@ -47,10 +52,11 @@ DCPContent::DCPContent (shared_ptr<const Film> 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<const Film> film, cxml::ConstNodePtr node, int version)
@@ -66,6 +72,9 @@ DCPContent::DCPContent (shared_ptr<const Film> 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,6 +147,9 @@ 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
@@ -146,13 +158,17 @@ DCPContent::full_length () const
        shared_ptr<const Film> film = _film.lock ();
        DCPOMATIC_ASSERT (film);
        FrameRateChange const frc (video_frame_rate (), film->video_frame_rate ());
-       return DCPTime::from_frames (rint (video_length () * frc.factor ()), 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
@@ -189,3 +205,43 @@ DCPContent::add_properties (list<pair<string, string> >& 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);
+}