2 Copyright (C) 2014 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>
35 using boost::shared_ptr;
36 using boost::optional;
38 int const DCPContentProperty::CAN_BE_PLAYED = 600;
40 DCPContent::DCPContent (shared_ptr<const Film> film, boost::filesystem::path p)
43 , SingleStreamAudioContent (film)
44 , SubtitleContent (film)
45 , _has_subtitles (false)
50 /* Default to no colour conversion for DCPs */
51 unset_colour_conversion (false);
54 DCPContent::DCPContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int version)
55 : Content (film, node)
56 , VideoContent (film, node, version)
57 , SingleStreamAudioContent (film, node, version)
58 , SubtitleContent (film, node, version)
60 _name = node->string_child ("Name");
61 _has_subtitles = node->bool_child ("HasSubtitles");
62 _encrypted = node->bool_child ("Encrypted");
63 if (node->optional_node_child ("KDM")) {
64 _kdm = dcp::EncryptedKDM (node->string_child ("KDM"));
66 _kdm_valid = node->bool_child ("KDMValid");
70 DCPContent::read_directory (boost::filesystem::path p)
72 for (boost::filesystem::directory_iterator i(p); i != boost::filesystem::directory_iterator(); ++i) {
73 if (boost::filesystem::is_regular_file (i->path ())) {
74 _paths.push_back (i->path ());
75 } else if (boost::filesystem::is_directory (i->path ())) {
76 read_directory (i->path ());
82 DCPContent::examine (shared_ptr<Job> job)
84 bool const could_be_played = can_be_played ();
86 job->set_progress_unknown ();
87 Content::examine (job);
89 shared_ptr<DCPExaminer> examiner (new DCPExaminer (shared_from_this ()));
90 take_from_video_examiner (examiner);
91 take_from_audio_examiner (examiner);
94 boost::mutex::scoped_lock lm (_mutex);
95 _name = examiner->name ();
96 _has_subtitles = examiner->has_subtitles ();
97 _encrypted = examiner->encrypted ();
98 _kdm_valid = examiner->kdm_valid ();
101 if (could_be_played != can_be_played ()) {
102 signal_changed (DCPContentProperty::CAN_BE_PLAYED);
107 DCPContent::summary () const
109 boost::mutex::scoped_lock lm (_mutex);
110 return String::compose (_("%1 [DCP]"), _name);
114 DCPContent::technical_summary () const
116 return Content::technical_summary() + " - "
117 + VideoContent::technical_summary() + " - "
118 + AudioContent::technical_summary() + " - ";
122 DCPContent::as_xml (xmlpp::Node* node) const
124 node->add_child("Type")->add_child_text ("DCP");
126 Content::as_xml (node);
127 VideoContent::as_xml (node);
128 SingleStreamAudioContent::as_xml (node);
129 SubtitleContent::as_xml (node);
131 boost::mutex::scoped_lock lm (_mutex);
132 node->add_child("Name")->add_child_text (_name);
133 node->add_child("HasSubtitles")->add_child_text (_has_subtitles ? "1" : "0");
134 node->add_child("Encrypted")->add_child_text (_encrypted ? "1" : "0");
136 node->add_child("KDM")->add_child_text (_kdm->as_xml ());
138 node->add_child("KDMValid")->add_child_text (_kdm_valid ? "1" : "0");
142 DCPContent::full_length () const
144 shared_ptr<const Film> film = _film.lock ();
145 DCPOMATIC_ASSERT (film);
146 FrameRateChange const frc (video_frame_rate (), film->video_frame_rate ());
147 return DCPTime::from_frames (rint (video_length () * frc.factor ()), film->video_frame_rate ());
151 DCPContent::identifier () const
153 return SubtitleContent::identifier ();
157 DCPContent::add_kdm (dcp::EncryptedKDM k)
163 DCPContent::can_be_played () const
165 boost::mutex::scoped_lock lm (_mutex);
166 return !_encrypted || _kdm_valid;
169 boost::filesystem::path
170 DCPContent::directory () const
172 optional<size_t> smallest;
173 boost::filesystem::path dir;
174 for (size_t i = 0; i < number_of_paths(); ++i) {
175 boost::filesystem::path const p = path (i).parent_path ();
176 size_t const d = distance (p.begin(), p.end());
177 if (!smallest || d < smallest.get ()) {