Use uchardet to guess encoding of subtitle files and reject non-UTF-8.
[dcpomatic.git] / src / lib / dcp_content.cc
index 3c3d4983ee33a960bcbfe4ced86b17b6952b874e..cb9dcf53d6dc184caaa47f098fb3954b2a3eec8a 100644 (file)
@@ -27,6 +27,7 @@
 #include <dcp/exceptions.h>
 #include <libxml++/libxml++.h>
 #include <iterator>
+#include <iostream>
 
 #include "i18n.h"
 
@@ -38,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)
@@ -48,6 +52,9 @@ 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);
 }
@@ -65,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
@@ -137,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
@@ -152,7 +165,9 @@ string
 DCPContent::identifier () const
 {
        SafeStringStream s;
-       s << VideoContent::identifier() << "_" << SubtitleContent::identifier ();
+       s << VideoContent::identifier() << "_" << SubtitleContent::identifier () << " "
+         << (_reference_video ? "1" : "0")
+         << (_reference_subtitle ? "1" : "0");
        return s.str ();
 }
 
@@ -197,3 +212,36 @@ 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);
+}