Revert "Use make_shared<>."
[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 }
85
86 string
87 VideoMXFContent::summary () const
88 {
89         return String::compose (_("%1 [video]"), path_summary());
90 }
91
92 string
93 VideoMXFContent::technical_summary () const
94 {
95         return Content::technical_summary() + " - " + video->technical_summary ();
96 }
97
98 string
99 VideoMXFContent::identifier () const
100 {
101         return Content::identifier() + "_" + video->identifier();
102 }
103
104 void
105 VideoMXFContent::as_xml (xmlpp::Node* node) const
106 {
107         node->add_child("Type")->add_child_text ("VideoMXF");
108         Content::as_xml (node);
109         video->as_xml (node);
110 }
111
112 DCPTime
113 VideoMXFContent::full_length () const
114 {
115         FrameRateChange const frc (active_video_frame_rate(), film()->video_frame_rate());
116         return DCPTime::from_frames (llrint (video->length_after_3d_combine() * frc.factor()), film()->video_frame_rate());
117 }
118
119 void
120 VideoMXFContent::add_properties (list<UserProperty>& p) const
121 {
122         video->add_properties (p);
123 }
124
125 void
126 VideoMXFContent::set_default_colour_conversion ()
127 {
128         video->unset_colour_conversion ();
129 }