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