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