870fca56ed8c5c753eeccd61bcdb69d473dc7652
[dcpomatic.git] / src / lib / atmos_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 "atmos_mxf_content.h"
22 #include "job.h"
23 #include "film.h"
24 #include "compose.hpp"
25 #include <dcp/atmos_asset.h>
26 #include <dcp/exceptions.h>
27 #include <libxml++/libxml++.h>
28 #include <boost/make_shared.hpp>
29
30 #include "i18n.h"
31
32 using std::list;
33 using std::string;
34 using boost::shared_ptr;
35 using boost::make_shared;
36
37 AtmosMXFContent::AtmosMXFContent (shared_ptr<const Film> film, boost::filesystem::path path)
38         : Content (film, path)
39 {
40
41 }
42
43 AtmosMXFContent::AtmosMXFContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int)
44         : Content (film, node)
45 {
46
47 }
48
49 bool
50 AtmosMXFContent::valid_mxf (boost::filesystem::path path)
51 {
52         try {
53                 shared_ptr<dcp::AtmosAsset> a = make_shared<dcp::AtmosAsset> (path);
54                 return true;
55         } catch (dcp::MXFFileError& e) {
56
57         } catch (dcp::DCPReadError& e) {
58
59         }
60
61         return false;
62 }
63
64 void
65 AtmosMXFContent::examine (shared_ptr<Job> job)
66 {
67         job->set_progress_unknown ();
68         Content::examine (job);
69         shared_ptr<dcp::AtmosAsset> a = make_shared<dcp::AtmosAsset> (path(0));
70
71         {
72                 boost::mutex::scoped_lock lm (_mutex);
73                 _length = a->intrinsic_duration ();
74         }
75 }
76
77 string
78 AtmosMXFContent::summary () const
79 {
80         return String::compose (_("%1 [Atmos]"), path_summary());
81 }
82
83 void
84 AtmosMXFContent::as_xml (xmlpp::Node* node) const
85 {
86         node->add_child("Type")->add_child_text ("AtmosMXF");
87         Content::as_xml (node);
88 }
89
90 DCPTime
91 AtmosMXFContent::full_length () const
92 {
93         FrameRateChange const frc (active_video_frame_rate(), film()->video_frame_rate());
94         return DCPTime::from_frames (llrint (_length * frc.factor()), film()->video_frame_rate());
95 }