Use dcp::file_to_string().
[dcpomatic.git] / src / lib / video_mxf_content.cc
1 /*
2     Copyright (C) 2016-2021 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
22 #include "video_mxf_examiner.h"
23 #include "video_mxf_content.h"
24 #include "video_content.h"
25 #include "job.h"
26 #include "film.h"
27 #include "compose.hpp"
28 #include <asdcp/KM_log.h>
29 #include <dcp/mono_picture_asset.h>
30 #include <dcp/stereo_picture_asset.h>
31 #include <dcp/exceptions.h>
32 #include <libxml++/libxml++.h>
33
34 #include "i18n.h"
35
36
37 using std::list;
38 using std::string;
39 using std::shared_ptr;
40 using std::make_shared;
41 using namespace dcpomatic;
42
43
44 VideoMXFContent::VideoMXFContent (boost::filesystem::path path)
45         : Content (path)
46 {
47
48 }
49
50
51 VideoMXFContent::VideoMXFContent (cxml::ConstNodePtr node, int version)
52         : Content (node)
53 {
54         video = VideoContent::from_xml (this, node, version);
55 }
56
57
58 bool
59 VideoMXFContent::valid_mxf (boost::filesystem::path path)
60 {
61         Kumu::DefaultLogSink().UnsetFilterFlag(Kumu::LOG_ALLOW_ALL);
62
63         try {
64                 dcp::MonoPictureAsset mp (path);
65                 return true;
66         } catch (dcp::MXFFileError& e) {
67
68         } catch (dcp::ReadError& e) {
69
70         }
71
72         try {
73                 Kumu::DefaultLogSink().SetFilterFlag(0);
74                 dcp::StereoPictureAsset sp (path);
75                 return true;
76         } catch (dcp::MXFFileError& e) {
77
78         } catch (dcp::ReadError& e) {
79
80         }
81
82         Kumu::DefaultLogSink().SetFilterFlag(Kumu::LOG_ALLOW_ALL);
83
84         return false;
85 }
86
87
88 void
89 VideoMXFContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job)
90 {
91         job->set_progress_unknown ();
92
93         Content::examine (film, job);
94
95         video.reset (new VideoContent (this));
96         auto examiner = make_shared<VideoMXFExaminer>(shared_from_this());
97         video->take_from_examiner (examiner);
98         video->unset_colour_conversion ();
99 }
100
101
102 string
103 VideoMXFContent::summary () const
104 {
105         return String::compose (_("%1 [video]"), path_summary());
106 }
107
108
109 string
110 VideoMXFContent::technical_summary () const
111 {
112         return Content::technical_summary() + " - " + video->technical_summary();
113 }
114
115
116 string
117 VideoMXFContent::identifier () const
118 {
119         return Content::identifier() + "_" + video->identifier();
120 }
121
122
123 void
124 VideoMXFContent::as_xml (xmlpp::Node* node, bool with_paths) const
125 {
126         node->add_child("Type")->add_child_text("VideoMXF");
127         Content::as_xml (node, with_paths);
128         video->as_xml (node);
129 }
130
131
132 DCPTime
133 VideoMXFContent::full_length (shared_ptr<const Film> film) const
134 {
135         FrameRateChange const frc (film, shared_from_this());
136         return DCPTime::from_frames (llrint(video->length_after_3d_combine() * frc.factor()), film->video_frame_rate());
137 }
138
139
140 DCPTime
141 VideoMXFContent::approximate_length () const
142 {
143         return DCPTime::from_frames (video->length_after_3d_combine(), 24);
144 }
145
146
147 void
148 VideoMXFContent::add_properties (shared_ptr<const Film> film, list<UserProperty>& p) const
149 {
150         Content::add_properties (film, p);
151         video->add_properties (p);
152 }