C++11 tidying.
[dcpomatic.git] / src / lib / atmos_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 "atmos_content.h"
23 #include "atmos_mxf_content.h"
24 #include "compose.hpp"
25 #include "film.h"
26 #include "job.h"
27 #include <asdcp/KM_log.h>
28 #include <dcp/atmos_asset.h>
29 #include <dcp/exceptions.h>
30 #include <dcp/raw_convert.h>
31 #include <libxml++/libxml++.h>
32
33 #include "i18n.h"
34
35
36 using std::list;
37 using std::make_shared;
38 using std::string;
39 using std::shared_ptr;
40 using namespace dcpomatic;
41
42
43 AtmosMXFContent::AtmosMXFContent (boost::filesystem::path path)
44         : Content (path)
45 {
46
47 }
48
49
50 AtmosMXFContent::AtmosMXFContent (cxml::ConstNodePtr node, int)
51         : Content (node)
52 {
53         atmos = AtmosContent::from_xml (this, node);
54 }
55
56
57 bool
58 AtmosMXFContent::valid_mxf (boost::filesystem::path path)
59 {
60         Kumu::DefaultLogSink().UnsetFilterFlag(Kumu::LOG_ALLOW_ALL);
61
62         try {
63                 dcp::AtmosAsset a (path);
64                 return true;
65         } catch (dcp::MXFFileError& e) {
66
67         } catch (dcp::ReadError& e) {
68
69         }
70
71         Kumu::DefaultLogSink().SetFilterFlag(Kumu::LOG_ALLOW_ALL);
72
73         return false;
74 }
75
76
77 void
78 AtmosMXFContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job)
79 {
80         job->set_progress_unknown ();
81         Content::examine (film, job);
82         auto a = make_shared<dcp::AtmosAsset>(path(0));
83
84         {
85                 boost::mutex::scoped_lock lm (_mutex);
86                 atmos = make_shared<AtmosContent>(this);
87                 atmos->set_length (a->intrinsic_duration());
88                 atmos->set_edit_rate (a->edit_rate());
89         }
90 }
91
92
93 string
94 AtmosMXFContent::summary () const
95 {
96         return String::compose (_("%1 [Atmos]"), path_summary());
97 }
98
99
100 void
101 AtmosMXFContent::as_xml (xmlpp::Node* node, bool with_paths) const
102 {
103         node->add_child("Type")->add_child_text("AtmosMXF");
104         Content::as_xml (node, with_paths);
105         atmos->as_xml (node);
106 }
107
108
109 DCPTime
110 AtmosMXFContent::full_length (shared_ptr<const Film> film) const
111 {
112         FrameRateChange const frc (film, shared_from_this());
113         return DCPTime::from_frames (llrint(atmos->length() * frc.factor()), film->video_frame_rate());
114 }
115
116
117 DCPTime
118 AtmosMXFContent::approximate_length () const
119 {
120         return DCPTime::from_frames (atmos->length(), 24);
121 }