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;
43 int const DCPContentProperty::REFERENCE_VIDEO = 601;
44 int const DCPContentProperty::REFERENCE_AUDIO = 602;
45 int const DCPContentProperty::REFERENCE_SUBTITLE = 603;
47 DCPContent::DCPContent (shared_ptr<const Film> film, boost::filesystem::path p)
50 , SingleStreamAudioContent (film)
51 , SubtitleContent (film)
52 , _has_subtitles (false)
55 , _reference_video (false)
56 , _reference_audio (false)
57 , _reference_subtitle (false)
62 DCPContent::DCPContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int version)
63 : Content (film, node)
64 , VideoContent (film, node, version)
65 , SingleStreamAudioContent (film, node, version)
66 , SubtitleContent (film, node, version)
68 _name = node->string_child ("Name");
69 _has_subtitles = node->bool_child ("HasSubtitles");
70 _encrypted = node->bool_child ("Encrypted");
71 if (node->optional_node_child ("KDM")) {
72 _kdm = dcp::EncryptedKDM (node->string_child ("KDM"));
74 _kdm_valid = node->bool_child ("KDMValid");
75 _reference_video = node->optional_bool_child ("ReferenceVideo").get_value_or (false);
76 _reference_audio = node->optional_bool_child ("ReferenceAudio").get_value_or (false);
77 _reference_subtitle = node->optional_bool_child ("ReferenceSubtitle").get_value_or (false);
81 DCPContent::read_directory (boost::filesystem::path p)
83 for (boost::filesystem::directory_iterator i(p); i != boost::filesystem::directory_iterator(); ++i) {
84 if (boost::filesystem::is_regular_file (i->path ())) {
85 _paths.push_back (i->path ());
86 } else if (boost::filesystem::is_directory (i->path ())) {
87 read_directory (i->path ());
93 DCPContent::examine (shared_ptr<Job> job)
95 bool const could_be_played = can_be_played ();
97 job->set_progress_unknown ();
98 Content::examine (job);
100 shared_ptr<DCPExaminer> examiner (new DCPExaminer (shared_from_this ()));
101 take_from_video_examiner (examiner);
102 take_from_audio_examiner (examiner);
105 boost::mutex::scoped_lock lm (_mutex);
106 _name = examiner->name ();
107 _has_subtitles = examiner->has_subtitles ();
108 _encrypted = examiner->encrypted ();
109 _kdm_valid = examiner->kdm_valid ();
112 if (could_be_played != can_be_played ()) {
113 signal_changed (DCPContentProperty::CAN_BE_PLAYED);
118 DCPContent::summary () const
120 boost::mutex::scoped_lock lm (_mutex);
121 return String::compose (_("%1 [DCP]"), _name);
125 DCPContent::technical_summary () const
127 return Content::technical_summary() + " - "
128 + VideoContent::technical_summary() + " - "
129 + AudioContent::technical_summary() + " - ";
133 DCPContent::as_xml (xmlpp::Node* node) const
135 node->add_child("Type")->add_child_text ("DCP");
137 Content::as_xml (node);
138 VideoContent::as_xml (node);
139 SingleStreamAudioContent::as_xml (node);
140 SubtitleContent::as_xml (node);
142 boost::mutex::scoped_lock lm (_mutex);
143 node->add_child("Name")->add_child_text (_name);
144 node->add_child("HasSubtitles")->add_child_text (_has_subtitles ? "1" : "0");
145 node->add_child("Encrypted")->add_child_text (_encrypted ? "1" : "0");
147 node->add_child("KDM")->add_child_text (_kdm->as_xml ());
149 node->add_child("KDMValid")->add_child_text (_kdm_valid ? "1" : "0");
150 node->add_child("ReferenceVideo")->add_child_text (_reference_video ? "1" : "0");
151 node->add_child("ReferenceAudio")->add_child_text (_reference_audio ? "1" : "0");
152 node->add_child("ReferenceSubtitle")->add_child_text (_reference_subtitle ? "1" : "0");
156 DCPContent::full_length () const
158 shared_ptr<const Film> film = _film.lock ();
159 DCPOMATIC_ASSERT (film);
160 FrameRateChange const frc (video_frame_rate (), film->video_frame_rate ());
161 return DCPTime::from_frames (llrint (video_length () * frc.factor ()), film->video_frame_rate ());
165 DCPContent::identifier () const
168 s << VideoContent::identifier() << "_" << SubtitleContent::identifier () << " "
169 << (_reference_video ? "1" : "0")
170 << (_reference_subtitle ? "1" : "0");
175 DCPContent::add_kdm (dcp::EncryptedKDM k)
181 DCPContent::can_be_played () const
183 boost::mutex::scoped_lock lm (_mutex);
184 return !_encrypted || _kdm_valid;
187 boost::filesystem::path
188 DCPContent::directory () const
190 optional<size_t> smallest;
191 boost::filesystem::path dir;
192 for (size_t i = 0; i < number_of_paths(); ++i) {
193 boost::filesystem::path const p = path (i).parent_path ();
194 size_t const d = distance (p.begin(), p.end());
195 if (!smallest || d < smallest.get ()) {
204 DCPContent::add_properties (list<pair<string, string> >& p) const
206 SingleStreamAudioContent::add_properties (p);
210 DCPContent::set_default_colour_conversion ()
212 /* Default to no colour conversion for DCPs */
213 unset_colour_conversion ();
217 DCPContent::set_reference_video (bool r)
220 boost::mutex::scoped_lock lm (_mutex);
221 _reference_video = r;
224 signal_changed (DCPContentProperty::REFERENCE_VIDEO);
228 DCPContent::set_reference_audio (bool r)
231 boost::mutex::scoped_lock lm (_mutex);
232 _reference_audio = r;
235 signal_changed (DCPContentProperty::REFERENCE_AUDIO);
239 DCPContent::set_reference_subtitle (bool r)
242 boost::mutex::scoped_lock lm (_mutex);
243 _reference_subtitle = r;
246 signal_changed (DCPContentProperty::REFERENCE_SUBTITLE);