Add VideoMXFContent (part of #803).
[dcpomatic.git] / src / lib / video_mxf_content.cc
1 /*
2     Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "video_mxf_examiner.h"
21 #include "video_mxf_content.h"
22 #include "video_content.h"
23 #include "job.h"
24 #include "film.h"
25 #include "compose.hpp"
26 #include <dcp/mono_picture_asset.h>
27 #include <dcp/stereo_picture_asset.h>
28 #include <dcp/exceptions.h>
29 #include <libxml++/libxml++.h>
30
31 #include "i18n.h"
32
33 using std::list;
34 using std::string;
35 using boost::shared_ptr;
36
37 VideoMXFContent::VideoMXFContent (shared_ptr<const Film> film, boost::filesystem::path path)
38         : Content (film, path)
39 {
40
41 }
42
43 VideoMXFContent::VideoMXFContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int version)
44         : Content (film, node)
45 {
46         video = VideoContent::from_xml (this, node, version);
47 }
48
49 bool
50 VideoMXFContent::valid_mxf (boost::filesystem::path path)
51 {
52         try {
53                 shared_ptr<dcp::MonoPictureAsset> mp (new dcp::MonoPictureAsset (path));
54                 return true;
55         } catch (dcp::MXFFileError& e) {
56
57         } catch (dcp::DCPReadError& e) {
58
59         }
60
61         try {
62                 shared_ptr<dcp::StereoPictureAsset> sp (new dcp::StereoPictureAsset (path));
63                 return true;
64         } catch (dcp::MXFFileError& e) {
65
66         } catch (dcp::DCPReadError& e) {
67
68         }
69
70         return false;
71 }
72
73 void
74 VideoMXFContent::examine (shared_ptr<Job> job)
75 {
76         job->set_progress_unknown ();
77
78         Content::examine (job);
79
80         video.reset (new VideoContent (this));
81         shared_ptr<VideoMXFExaminer> examiner (new VideoMXFExaminer (shared_from_this ()));
82         video->take_from_examiner (examiner);
83 }
84
85 string
86 VideoMXFContent::summary () const
87 {
88         return String::compose (_("%1 [video]"), path_summary());
89 }
90
91 string
92 VideoMXFContent::technical_summary () const
93 {
94         return Content::technical_summary() + " - " + video->technical_summary ();
95 }
96
97 string
98 VideoMXFContent::identifier () const
99 {
100         return Content::identifier() + "_" + video->identifier();
101 }
102
103 void
104 VideoMXFContent::as_xml (xmlpp::Node* node) const
105 {
106         node->add_child("Type")->add_child_text ("VideoMXF");
107         Content::as_xml (node);
108         video->as_xml (node);
109 }
110
111 DCPTime
112 VideoMXFContent::full_length () const
113 {
114         FrameRateChange const frc (active_video_frame_rate(), film()->video_frame_rate());
115         return DCPTime::from_frames (llrint (video->length_after_3d_combine() * frc.factor()), film()->video_frame_rate());
116 }
117
118 void
119 VideoMXFContent::add_properties (list<UserProperty>& p) const
120 {
121         video->add_properties (p);
122 }
123
124 void
125 VideoMXFContent::set_default_colour_conversion ()
126 {
127         video->unset_colour_conversion ();
128 }