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.
21 #include <dcp/exceptions.h>
22 #include "dcp_content.h"
23 #include "dcp_examiner.h"
27 #include "compose.hpp"
33 using boost::shared_ptr;
34 using boost::optional;
36 int const DCPContentProperty::CAN_BE_PLAYED = 600;
38 DCPContent::DCPContent (shared_ptr<const Film> f, boost::filesystem::path p)
41 , SingleStreamAudioContent (f)
43 , _has_subtitles (false)
51 DCPContent::DCPContent (shared_ptr<const Film> f, cxml::ConstNodePtr node, int version)
53 , VideoContent (f, node, version)
54 , SingleStreamAudioContent (f, node, version)
55 , SubtitleContent (f, node, version)
57 _name = node->string_child ("Name");
58 _has_subtitles = node->bool_child ("HasSubtitles");
59 _directory = node->string_child ("Directory");
60 _encrypted = node->bool_child ("Encrypted");
61 _kdm_valid = node->bool_child ("KDMValid");
65 DCPContent::read_directory (boost::filesystem::path p)
67 for (boost::filesystem::directory_iterator i(p); i != boost::filesystem::directory_iterator(); ++i) {
68 if (boost::filesystem::is_regular_file (i->path ())) {
69 _paths.push_back (i->path ());
70 } else if (boost::filesystem::is_directory (i->path ())) {
71 read_directory (i->path ());
77 DCPContent::examine (shared_ptr<Job> job)
79 bool const could_be_played = can_be_played ();
81 job->set_progress_unknown ();
82 Content::examine (job);
84 shared_ptr<DCPExaminer> examiner (new DCPExaminer (shared_from_this ()));
85 take_from_video_examiner (examiner);
86 take_from_audio_examiner (examiner);
88 boost::mutex::scoped_lock lm (_mutex);
89 _name = examiner->name ();
90 _has_subtitles = examiner->has_subtitles ();
91 _encrypted = examiner->encrypted ();
92 _kdm_valid = examiner->kdm_valid ();
94 if (could_be_played != can_be_played ()) {
95 signal_changed (DCPContentProperty::CAN_BE_PLAYED);
100 DCPContent::summary () const
102 boost::mutex::scoped_lock lm (_mutex);
103 return String::compose (_("%1 [DCP]"), _name);
107 DCPContent::technical_summary () const
109 return Content::technical_summary() + " - "
110 + VideoContent::technical_summary() + " - "
111 + AudioContent::technical_summary() + " - ";
115 DCPContent::as_xml (xmlpp::Node* node) const
117 node->add_child("Type")->add_child_text ("DCP");
119 Content::as_xml (node);
120 VideoContent::as_xml (node);
121 SingleStreamAudioContent::as_xml (node);
122 SubtitleContent::as_xml (node);
124 boost::mutex::scoped_lock lm (_mutex);
125 node->add_child("Name")->add_child_text (_name);
126 node->add_child("HasSubtitles")->add_child_text (_has_subtitles ? "1" : "0");
127 node->add_child("Encrypted")->add_child_text (_encrypted ? "1" : "0");
128 node->add_child("Directory")->add_child_text (_directory.string ());
130 node->add_child("KDMValid")->add_child_text (_kdm_valid ? "1" : "0");
134 DCPContent::full_length () const
136 shared_ptr<const Film> film = _film.lock ();
138 return DCPTime (video_length (), FrameRateChange (video_frame_rate (), film->video_frame_rate ()));
142 DCPContent::identifier () const
144 return SubtitleContent::identifier ();
148 DCPContent::add_kdm (dcp::EncryptedKDM k)
154 DCPContent::can_be_played () const
156 return !_encrypted || _kdm_valid;