2 Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "dcp_content.h"
21 #include "dcp_examiner.h"
25 #include "compose.hpp"
27 #include <dcp/exceptions.h>
28 #include <libxml++/libxml++.h>
39 using boost::shared_ptr;
40 using boost::optional;
42 int const DCPContentProperty::CAN_BE_PLAYED = 600;
44 DCPContent::DCPContent (shared_ptr<const Film> film, boost::filesystem::path p)
47 , SingleStreamAudioContent (film)
48 , SubtitleContent (film)
49 , _has_subtitles (false)
52 , _reference_video (false)
53 , _reference_audio (false)
54 , _reference_subtitle (false)
59 DCPContent::DCPContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int version)
60 : Content (film, node)
61 , VideoContent (film, node, version)
62 , SingleStreamAudioContent (film, node, version)
63 , SubtitleContent (film, node, version)
65 _name = node->string_child ("Name");
66 _has_subtitles = node->bool_child ("HasSubtitles");
67 _encrypted = node->bool_child ("Encrypted");
68 if (node->optional_node_child ("KDM")) {
69 _kdm = dcp::EncryptedKDM (node->string_child ("KDM"));
71 _kdm_valid = node->bool_child ("KDMValid");
72 _reference_video = node->optional_bool_child ("ReferenceVideo").get_value_or (false);
73 _reference_audio = node->optional_bool_child ("ReferenceAudio").get_value_or (false);
74 _reference_subtitle = node->optional_bool_child ("ReferenceSubtitle").get_value_or (false);
78 DCPContent::read_directory (boost::filesystem::path p)
80 for (boost::filesystem::directory_iterator i(p); i != boost::filesystem::directory_iterator(); ++i) {
81 if (boost::filesystem::is_regular_file (i->path ())) {
82 _paths.push_back (i->path ());
83 } else if (boost::filesystem::is_directory (i->path ())) {
84 read_directory (i->path ());
90 DCPContent::examine (shared_ptr<Job> job)
92 bool const could_be_played = can_be_played ();
94 job->set_progress_unknown ();
95 Content::examine (job);
97 shared_ptr<DCPExaminer> examiner (new DCPExaminer (shared_from_this ()));
98 take_from_video_examiner (examiner);
99 take_from_audio_examiner (examiner);
102 boost::mutex::scoped_lock lm (_mutex);
103 _name = examiner->name ();
104 _has_subtitles = examiner->has_subtitles ();
105 _encrypted = examiner->encrypted ();
106 _kdm_valid = examiner->kdm_valid ();
109 if (could_be_played != can_be_played ()) {
110 signal_changed (DCPContentProperty::CAN_BE_PLAYED);
115 DCPContent::summary () const
117 boost::mutex::scoped_lock lm (_mutex);
118 return String::compose (_("%1 [DCP]"), _name);
122 DCPContent::technical_summary () const
124 return Content::technical_summary() + " - "
125 + VideoContent::technical_summary() + " - "
126 + AudioContent::technical_summary() + " - ";
130 DCPContent::as_xml (xmlpp::Node* node) const
132 node->add_child("Type")->add_child_text ("DCP");
134 Content::as_xml (node);
135 VideoContent::as_xml (node);
136 SingleStreamAudioContent::as_xml (node);
137 SubtitleContent::as_xml (node);
139 boost::mutex::scoped_lock lm (_mutex);
140 node->add_child("Name")->add_child_text (_name);
141 node->add_child("HasSubtitles")->add_child_text (_has_subtitles ? "1" : "0");
142 node->add_child("Encrypted")->add_child_text (_encrypted ? "1" : "0");
144 node->add_child("KDM")->add_child_text (_kdm->as_xml ());
146 node->add_child("KDMValid")->add_child_text (_kdm_valid ? "1" : "0");
147 node->add_child("ReferenceVideo")->add_child_text (_reference_video ? "1" : "0");
148 node->add_child("ReferenceAudio")->add_child_text (_reference_audio ? "1" : "0");
149 node->add_child("ReferenceSubtitle")->add_child_text (_reference_subtitle ? "1" : "0");
153 DCPContent::full_length () const
155 shared_ptr<const Film> film = _film.lock ();
156 DCPOMATIC_ASSERT (film);
157 FrameRateChange const frc (video_frame_rate (), film->video_frame_rate ());
158 return DCPTime::from_frames (llrint (video_length () * frc.factor ()), film->video_frame_rate ());
162 DCPContent::identifier () const
165 s << VideoContent::identifier() << "_" << SubtitleContent::identifier () << " "
166 << (_reference_video ? "1" : "0")
167 << (_reference_subtitle ? "1" : "0");
172 DCPContent::add_kdm (dcp::EncryptedKDM k)
178 DCPContent::can_be_played () const
180 boost::mutex::scoped_lock lm (_mutex);
181 return !_encrypted || _kdm_valid;
184 boost::filesystem::path
185 DCPContent::directory () const
187 optional<size_t> smallest;
188 boost::filesystem::path dir;
189 for (size_t i = 0; i < number_of_paths(); ++i) {
190 boost::filesystem::path const p = path (i).parent_path ();
191 size_t const d = distance (p.begin(), p.end());
192 if (!smallest || d < smallest.get ()) {
201 DCPContent::add_properties (list<pair<string, string> >& p) const
203 SingleStreamAudioContent::add_properties (p);
207 DCPContent::set_default_colour_conversion ()
209 /* Default to no colour conversion for DCPs */
210 unset_colour_conversion ();