Fix setup of initial colour conversion for Video MXF content.
[dcpomatic.git] / src / lib / video_mxf_content.cc
1 /*
2     Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21 #include "video_mxf_examiner.h"
22 #include "video_mxf_content.h"
23 #include "video_content.h"
24 #include "job.h"
25 #include "film.h"
26 #include "compose.hpp"
27 #include <dcp/mono_picture_asset.h>
28 #include <dcp/stereo_picture_asset.h>
29 #include <dcp/exceptions.h>
30 #include <libxml++/libxml++.h>
31
32 #include "i18n.h"
33
34 using std::list;
35 using std::string;
36 using boost::shared_ptr;
37
38 VideoMXFContent::VideoMXFContent (shared_ptr<const Film> film, boost::filesystem::path path)
39         : Content (film, path)
40 {
41
42 }
43
44 VideoMXFContent::VideoMXFContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int version)
45         : Content (film, node)
46 {
47         video = VideoContent::from_xml (this, node, version);
48 }
49
50 bool
51 VideoMXFContent::valid_mxf (boost::filesystem::path path)
52 {
53         try {
54                 shared_ptr<dcp::MonoPictureAsset> mp (new dcp::MonoPictureAsset (path));
55                 return true;
56         } catch (dcp::MXFFileError& e) {
57
58         } catch (dcp::DCPReadError& e) {
59
60         }
61
62         try {
63                 shared_ptr<dcp::StereoPictureAsset> sp (new dcp::StereoPictureAsset (path));
64                 return true;
65         } catch (dcp::MXFFileError& e) {
66
67         } catch (dcp::DCPReadError& e) {
68
69         }
70
71         return false;
72 }
73
74 void
75 VideoMXFContent::examine (shared_ptr<Job> job)
76 {
77         job->set_progress_unknown ();
78
79         Content::examine (job);
80
81         video.reset (new VideoContent (this));
82         shared_ptr<VideoMXFExaminer> examiner (new VideoMXFExaminer (shared_from_this ()));
83         video->take_from_examiner (examiner);
84         video->unset_colour_conversion ();
85 }
86
87 string
88 VideoMXFContent::summary () const
89 {
90         return String::compose (_("%1 [video]"), path_summary());
91 }
92
93 string
94 VideoMXFContent::technical_summary () const
95 {
96         return Content::technical_summary() + " - " + video->technical_summary ();
97 }
98
99 string
100 VideoMXFContent::identifier () const
101 {
102         return Content::identifier() + "_" + video->identifier();
103 }
104
105 void
106 VideoMXFContent::as_xml (xmlpp::Node* node, bool with_paths) const
107 {
108         node->add_child("Type")->add_child_text ("VideoMXF");
109         Content::as_xml (node, with_paths);
110         video->as_xml (node);
111 }
112
113 DCPTime
114 VideoMXFContent::full_length () const
115 {
116         FrameRateChange const frc (active_video_frame_rate(), film()->video_frame_rate());
117         return DCPTime::from_frames (llrint (video->length_after_3d_combine() * frc.factor()), film()->video_frame_rate());
118 }
119
120 void
121 VideoMXFContent::add_properties (list<UserProperty>& p) const
122 {
123         video->add_properties (p);
124 }