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> f, boost::filesystem::path p)
43 , SingleStreamAudioContent (f)
45 , _has_subtitles (false)
52 DCPContent::DCPContent (shared_ptr<const Film> f, cxml::ConstNodePtr node, int version)
54 , VideoContent (f, node, version)
55 , SingleStreamAudioContent (f, node, version)
56 , SubtitleContent (f, node, version)
58 _name = node->string_child ("Name");
59 _has_subtitles = node->bool_child ("HasSubtitles");
60 _encrypted = node->bool_child ("Encrypted");
61 if (node->optional_node_child ("KDM")) {
62 _kdm = dcp::EncryptedKDM (node->string_child ("KDM"));
64 _kdm_valid = node->bool_child ("KDMValid");
68 DCPContent::read_directory (boost::filesystem::path p)
70 for (boost::filesystem::directory_iterator i(p); i != boost::filesystem::directory_iterator(); ++i) {
71 if (boost::filesystem::is_regular_file (i->path ())) {
72 _paths.push_back (i->path ());
73 } else if (boost::filesystem::is_directory (i->path ())) {
74 read_directory (i->path ());
80 DCPContent::examine (shared_ptr<Job> job)
82 bool const could_be_played = can_be_played ();
84 job->set_progress_unknown ();
85 Content::examine (job);
87 shared_ptr<DCPExaminer> examiner (new DCPExaminer (shared_from_this ()));
88 take_from_video_examiner (examiner);
89 take_from_audio_examiner (examiner);
91 boost::mutex::scoped_lock lm (_mutex);
92 _name = examiner->name ();
93 _has_subtitles = examiner->has_subtitles ();
94 _encrypted = examiner->encrypted ();
95 _kdm_valid = examiner->kdm_valid ();
97 if (could_be_played != can_be_played ()) {
98 signal_changed (DCPContentProperty::CAN_BE_PLAYED);
103 DCPContent::summary () const
105 boost::mutex::scoped_lock lm (_mutex);
106 return String::compose (_("%1 [DCP]"), _name);
110 DCPContent::technical_summary () const
112 return Content::technical_summary() + " - "
113 + VideoContent::technical_summary() + " - "
114 + AudioContent::technical_summary() + " - ";
118 DCPContent::as_xml (xmlpp::Node* node) const
120 node->add_child("Type")->add_child_text ("DCP");
122 Content::as_xml (node);
123 VideoContent::as_xml (node);
124 SingleStreamAudioContent::as_xml (node);
125 SubtitleContent::as_xml (node);
127 boost::mutex::scoped_lock lm (_mutex);
128 node->add_child("Name")->add_child_text (_name);
129 node->add_child("HasSubtitles")->add_child_text (_has_subtitles ? "1" : "0");
130 node->add_child("Encrypted")->add_child_text (_encrypted ? "1" : "0");
132 node->add_child("KDM")->add_child_text (_kdm->as_xml ());
134 node->add_child("KDMValid")->add_child_text (_kdm_valid ? "1" : "0");
138 DCPContent::full_length () const
140 shared_ptr<const Film> film = _film.lock ();
141 DCPOMATIC_ASSERT (film);
142 return DCPTime (video_length (), FrameRateChange (video_frame_rate (), film->video_frame_rate ()));
146 DCPContent::identifier () const
148 return SubtitleContent::identifier ();
152 DCPContent::add_kdm (dcp::EncryptedKDM k)
158 DCPContent::can_be_played () const
160 return !_encrypted || _kdm_valid;
163 boost::filesystem::path
164 DCPContent::directory () const
166 optional<size_t> smallest;
167 boost::filesystem::path dir;
168 for (size_t i = 0; i < number_of_paths(); ++i) {
169 boost::filesystem::path const p = path (i).parent_path ();
170 size_t const d = distance (p.begin(), p.end());
171 if (!smallest || d < smallest.get ()) {