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>
37 using boost::shared_ptr;
38 using boost::optional;
40 int const DCPContentProperty::CAN_BE_PLAYED = 600;
42 DCPContent::DCPContent (shared_ptr<const Film> film, boost::filesystem::path p)
45 , SingleStreamAudioContent (film)
46 , SubtitleContent (film)
47 , _has_subtitles (false)
52 /* Default to no colour conversion for DCPs */
53 unset_colour_conversion (false);
56 DCPContent::DCPContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int version)
57 : Content (film, node)
58 , VideoContent (film, node, version)
59 , SingleStreamAudioContent (film, node, version)
60 , SubtitleContent (film, node, version)
62 _name = node->string_child ("Name");
63 _has_subtitles = node->bool_child ("HasSubtitles");
64 _encrypted = node->bool_child ("Encrypted");
65 if (node->optional_node_child ("KDM")) {
66 _kdm = dcp::EncryptedKDM (node->string_child ("KDM"));
68 _kdm_valid = node->bool_child ("KDMValid");
72 DCPContent::read_directory (boost::filesystem::path p)
74 for (boost::filesystem::directory_iterator i(p); i != boost::filesystem::directory_iterator(); ++i) {
75 if (boost::filesystem::is_regular_file (i->path ())) {
76 _paths.push_back (i->path ());
77 } else if (boost::filesystem::is_directory (i->path ())) {
78 read_directory (i->path ());
84 DCPContent::examine (shared_ptr<Job> job)
86 bool const could_be_played = can_be_played ();
88 job->set_progress_unknown ();
89 Content::examine (job);
91 shared_ptr<DCPExaminer> examiner (new DCPExaminer (shared_from_this ()));
92 take_from_video_examiner (examiner);
93 take_from_audio_examiner (examiner);
96 boost::mutex::scoped_lock lm (_mutex);
97 _name = examiner->name ();
98 _has_subtitles = examiner->has_subtitles ();
99 _encrypted = examiner->encrypted ();
100 _kdm_valid = examiner->kdm_valid ();
103 if (could_be_played != can_be_played ()) {
104 signal_changed (DCPContentProperty::CAN_BE_PLAYED);
109 DCPContent::summary () const
111 boost::mutex::scoped_lock lm (_mutex);
112 return String::compose (_("%1 [DCP]"), _name);
116 DCPContent::technical_summary () const
118 return Content::technical_summary() + " - "
119 + VideoContent::technical_summary() + " - "
120 + AudioContent::technical_summary() + " - ";
124 DCPContent::as_xml (xmlpp::Node* node) const
126 node->add_child("Type")->add_child_text ("DCP");
128 Content::as_xml (node);
129 VideoContent::as_xml (node);
130 SingleStreamAudioContent::as_xml (node);
131 SubtitleContent::as_xml (node);
133 boost::mutex::scoped_lock lm (_mutex);
134 node->add_child("Name")->add_child_text (_name);
135 node->add_child("HasSubtitles")->add_child_text (_has_subtitles ? "1" : "0");
136 node->add_child("Encrypted")->add_child_text (_encrypted ? "1" : "0");
138 node->add_child("KDM")->add_child_text (_kdm->as_xml ());
140 node->add_child("KDMValid")->add_child_text (_kdm_valid ? "1" : "0");
144 DCPContent::full_length () const
146 shared_ptr<const Film> film = _film.lock ();
147 DCPOMATIC_ASSERT (film);
148 FrameRateChange const frc (video_frame_rate (), film->video_frame_rate ());
149 return DCPTime::from_frames (rint (video_length () * frc.factor ()), film->video_frame_rate ());
153 DCPContent::identifier () const
155 return SubtitleContent::identifier ();
159 DCPContent::add_kdm (dcp::EncryptedKDM k)
165 DCPContent::can_be_played () const
167 boost::mutex::scoped_lock lm (_mutex);
168 return !_encrypted || _kdm_valid;
171 boost::filesystem::path
172 DCPContent::directory () const
174 optional<size_t> smallest;
175 boost::filesystem::path dir;
176 for (size_t i = 0; i < number_of_paths(); ++i) {
177 boost::filesystem::path const p = path (i).parent_path ();
178 size_t const d = distance (p.begin(), p.end());
179 if (!smallest || d < smallest.get ()) {
188 DCPContent::add_properties (list<pair<string, string> >& p) const
190 SingleStreamAudioContent::add_properties (p);