2 Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #include "dcp_content.h"
22 #include "video_content.h"
23 #include "audio_content.h"
24 #include "dcp_examiner.h"
29 #include "compose.hpp"
30 #include "dcp_decoder.h"
31 #include "subtitle_content.h"
33 #include <dcp/raw_convert.h>
34 #include <dcp/exceptions.h>
35 #include <dcp/reel_picture_asset.h>
37 #include <libxml++/libxml++.h>
38 #include <boost/foreach.hpp>
50 using boost::shared_ptr;
51 using boost::scoped_ptr;
52 using boost::optional;
53 using boost::function;
54 using dcp::raw_convert;
56 int const DCPContentProperty::CAN_BE_PLAYED = 600;
57 int const DCPContentProperty::REFERENCE_VIDEO = 601;
58 int const DCPContentProperty::REFERENCE_AUDIO = 602;
59 int const DCPContentProperty::REFERENCE_SUBTITLE = 603;
61 DCPContent::DCPContent (shared_ptr<const Film> film, boost::filesystem::path p)
64 , _needs_assets (false)
66 , _reference_video (false)
67 , _reference_audio (false)
68 , _reference_subtitle (false)
71 video.reset (new VideoContent (this));
72 audio.reset (new AudioContent (this));
75 set_default_colour_conversion ();
78 DCPContent::DCPContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int version)
79 : Content (film, node)
81 video = VideoContent::from_xml (this, node, version);
82 audio = AudioContent::from_xml (this, node, version);
83 subtitle = SubtitleContent::from_xml (this, node, version);
88 node->number_child<int> ("AudioFrameRate"),
89 /* AudioLength was not present in some old metadata versions */
90 node->optional_number_child<Frame>("AudioLength").get_value_or (
91 video->length() * node->number_child<int>("AudioFrameRate") / video_frame_rate().get()
93 AudioMapping (node->node_child ("AudioMapping"), version)
98 _name = node->string_child ("Name");
99 _encrypted = node->bool_child ("Encrypted");
100 _needs_assets = node->bool_child ("NeedsAssets");
101 if (node->optional_node_child ("KDM")) {
102 _kdm = dcp::EncryptedKDM (node->string_child ("KDM"));
104 _kdm_valid = node->bool_child ("KDMValid");
105 _reference_video = node->optional_bool_child ("ReferenceVideo").get_value_or (false);
106 _reference_audio = node->optional_bool_child ("ReferenceAudio").get_value_or (false);
107 _reference_subtitle = node->optional_bool_child ("ReferenceSubtitle").get_value_or (false);
108 if (node->optional_string_child("Standard")) {
109 string const s = node->optional_string_child("Standard").get();
110 if (s == "Interop") {
111 _standard = dcp::INTEROP;
112 } else if (s == "SMPTE") {
113 _standard = dcp::SMPTE;
115 DCPOMATIC_ASSERT (false);
118 _three_d = node->optional_bool_child("ThreeD").get_value_or (false);
119 _cpl = node->optional_string_child("CPL");
123 DCPContent::read_directory (boost::filesystem::path p)
125 for (boost::filesystem::directory_iterator i(p); i != boost::filesystem::directory_iterator(); ++i) {
126 if (boost::filesystem::is_regular_file (i->path ())) {
127 _paths.push_back (i->path ());
128 } else if (boost::filesystem::is_directory (i->path ())) {
129 read_directory (i->path ());
135 DCPContent::examine (shared_ptr<Job> job)
137 bool const could_be_played = can_be_played ();
139 job->set_progress_unknown ();
140 Content::examine (job);
142 shared_ptr<DCPExaminer> examiner (new DCPExaminer (shared_from_this ()));
143 video->take_from_examiner (examiner);
144 set_default_colour_conversion ();
147 boost::mutex::scoped_lock lm (_mutex);
149 AudioStreamPtr as (new AudioStream (examiner->audio_frame_rate(), examiner->audio_length(), examiner->audio_channels()));
150 audio->set_stream (as);
151 AudioMapping m = as->mapping ();
152 film()->make_audio_mapping_default (m);
156 signal_changed (AudioContentProperty::STREAMS);
159 boost::mutex::scoped_lock lm (_mutex);
160 _name = examiner->name ();
161 if (examiner->has_subtitles ()) {
162 subtitle.reset (new SubtitleContent (this));
164 _encrypted = examiner->encrypted ();
165 _needs_assets = examiner->needs_assets ();
166 _kdm_valid = examiner->kdm_valid ();
167 _standard = examiner->standard ();
168 _three_d = examiner->three_d ();
169 _cpl = examiner->cpl ();
172 if (could_be_played != can_be_played ()) {
173 signal_changed (DCPContentProperty::CAN_BE_PLAYED);
176 video->set_frame_type (_three_d ? VIDEO_FRAME_TYPE_3D : VIDEO_FRAME_TYPE_2D);
180 DCPContent::summary () const
182 boost::mutex::scoped_lock lm (_mutex);
183 return String::compose (_("%1 [DCP]"), _name);
187 DCPContent::technical_summary () const
189 return Content::technical_summary() + " - "
190 + video->technical_summary() + " - "
191 + audio->technical_summary() + " - ";
195 DCPContent::as_xml (xmlpp::Node* node, bool with_paths) const
197 node->add_child("Type")->add_child_text ("DCP");
199 Content::as_xml (node);
202 video->as_xml (node);
206 audio->as_xml (node);
207 node->add_child("AudioFrameRate")->add_child_text (raw_convert<string> (audio->stream()->frame_rate()));
208 node->add_child("AudioLength")->add_child_text (raw_convert<string> (audio->stream()->length()));
209 audio->stream()->mapping().as_xml (node->add_child("AudioMapping"));
213 subtitle->as_xml (node);
216 boost::mutex::scoped_lock lm (_mutex);
217 node->add_child("Name")->add_child_text (_name);
218 node->add_child("Encrypted")->add_child_text (_encrypted ? "1" : "0");
219 node->add_child("NeedsAssets")->add_child_text (_needs_assets ? "1" : "0");
221 node->add_child("KDM")->add_child_text (_kdm->as_xml ());
223 node->add_child("KDMValid")->add_child_text (_kdm_valid ? "1" : "0");
224 node->add_child("ReferenceVideo")->add_child_text (_reference_video ? "1" : "0");
225 node->add_child("ReferenceAudio")->add_child_text (_reference_audio ? "1" : "0");
226 node->add_child("ReferenceSubtitle")->add_child_text (_reference_subtitle ? "1" : "0");
228 switch (_standard.get ()) {
230 node->add_child("Standard")->add_child_text ("Interop");
233 node->add_child("Standard")->add_child_text ("SMPTE");
236 DCPOMATIC_ASSERT (false);
239 node->add_child("ThreeD")->add_child_text (_three_d ? "1" : "0");
241 node->add_child("CPL")->add_child_text (_cpl.get ());
246 DCPContent::full_length () const
248 FrameRateChange const frc (active_video_frame_rate (), film()->video_frame_rate ());
249 return DCPTime::from_frames (llrint (video->length () * frc.factor ()), film()->video_frame_rate ());
253 DCPContent::identifier () const
255 string s = Content::identifier() + "_" + video->identifier() + "_";
257 s += subtitle->identifier () + " ";
260 s += string (_reference_video ? "1" : "0") + string (_reference_subtitle ? "1" : "0");
265 DCPContent::add_kdm (dcp::EncryptedKDM k)
271 DCPContent::add_ov (boost::filesystem::path ov)
277 DCPContent::can_be_played () const
279 return !needs_kdm() && !needs_assets();
283 DCPContent::needs_kdm () const
285 boost::mutex::scoped_lock lm (_mutex);
286 return _encrypted && !_kdm_valid;
290 DCPContent::needs_assets () const
292 boost::mutex::scoped_lock lm (_mutex);
293 return _needs_assets;
296 vector<boost::filesystem::path>
297 DCPContent::directories () const
299 return dcp::DCP::directories_from_files (paths ());
303 DCPContent::add_properties (list<UserProperty>& p) const
305 Content::add_properties (p);
306 video->add_properties (p);
307 audio->add_properties (p);
311 DCPContent::set_default_colour_conversion ()
313 /* Default to no colour conversion for DCPs */
314 video->unset_colour_conversion ();
318 DCPContent::set_reference_video (bool r)
321 boost::mutex::scoped_lock lm (_mutex);
322 _reference_video = r;
325 signal_changed (DCPContentProperty::REFERENCE_VIDEO);
329 DCPContent::set_reference_audio (bool r)
332 boost::mutex::scoped_lock lm (_mutex);
333 _reference_audio = r;
336 signal_changed (DCPContentProperty::REFERENCE_AUDIO);
340 DCPContent::set_reference_subtitle (bool r)
343 boost::mutex::scoped_lock lm (_mutex);
344 _reference_subtitle = r;
347 signal_changed (DCPContentProperty::REFERENCE_SUBTITLE);
351 DCPContent::reels () const
353 list<DCPTimePeriod> p;
354 scoped_ptr<DCPDecoder> decoder;
356 decoder.reset (new DCPDecoder (shared_from_this(), film()->log()));
358 /* Could not load the DCP; guess reels */
359 list<DCPTimePeriod> p;
360 p.push_back (DCPTimePeriod (position(), end()));
364 DCPTime from = position ();
365 BOOST_FOREACH (shared_ptr<dcp::Reel> i, decoder->reels()) {
366 DCPTime const to = from + DCPTime::from_frames (i->main_picture()->duration(), film()->video_frame_rate());
367 p.push_back (DCPTimePeriod (from, to));
375 DCPContent::reel_split_points () const
378 BOOST_FOREACH (DCPTimePeriod i, reels()) {
379 s.push_back (i.from);
385 DCPContent::can_reference (function<shared_ptr<ContentPart> (shared_ptr<const Content>)> part, string overlapping, list<string>& why_not) const
387 /* We must be using the same standard as the film */
389 if (_standard.get() == dcp::INTEROP && !film()->interop()) {
390 why_not.push_back (_("The film is set to SMPTE and this DCP is Interop."));
392 } else if (_standard.get() == dcp::SMPTE && film()->interop()) {
393 why_not.push_back (_("The film is set to Interop and this DCP is SMPTE."));
398 list<DCPTimePeriod> const fr = film()->reels ();
399 /* fr must contain reels(). It can also contain other reels, but it must at
400 least contain reels().
402 BOOST_FOREACH (DCPTimePeriod i, reels()) {
403 if (find (fr.begin(), fr.end(), i) == fr.end ()) {
404 why_not.push_back (_("The reel lengths in the film differ from those in the DCP; set the reel mode to 'split by video content'."));
409 ContentList a = overlaps (film()->content(), part, position(), end());
410 if (a.size() != 1 || a.front().get() != this) {
411 why_not.push_back (overlapping);
419 DCPContent::can_reference_video (list<string>& why_not) const
421 return can_reference (bind (&Content::video, _1), _("There is other video content overlapping this DCP; remove it."), why_not);
425 DCPContent::can_reference_audio (list<string>& why_not) const
427 DCPDecoder decoder (shared_from_this(), film()->log());
428 BOOST_FOREACH (shared_ptr<dcp::Reel> i, decoder.reels()) {
429 if (!i->main_sound()) {
430 why_not.push_back (_("The DCP does not have sound in all reels."));
435 return can_reference (bind (&Content::audio, _1), _("There is other audio content overlapping this DCP; remove it."), why_not);
439 DCPContent::can_reference_subtitle (list<string>& why_not) const
441 DCPDecoder decoder (shared_from_this(), film()->log());
442 BOOST_FOREACH (shared_ptr<dcp::Reel> i, decoder.reels()) {
443 if (!i->main_subtitle()) {
444 why_not.push_back (_("The DCP does not have subtitles in all reels."));
449 return can_reference (bind (&Content::subtitle, _1), _("There is other subtitle content overlapping this DCP; remove it."), why_not);