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