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