More automated renaming.
[dcpomatic.git] / src / lib / content.h
1 /*
2     Copyright (C) 2013-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 /** @file  src/lib/content.h
22  *  @brief Content class.
23  */
24
25 #ifndef DCPOMATIC_CONTENT_H
26 #define DCPOMATIC_CONTENT_H
27
28 #include "types.h"
29 #include "signaller.h"
30 #include "dcpomatic_time.h"
31 #include "user_property.h"
32 #include <libcxml/cxml.h>
33 #include <boost/filesystem.hpp>
34 #include <boost/signals2.hpp>
35 #include <boost/thread/mutex.hpp>
36 #include <boost/enable_shared_from_this.hpp>
37
38 namespace xmlpp {
39         class Node;
40 }
41
42 namespace cxml {
43         class Node;
44 }
45
46 class Job;
47 class Film;
48
49 class ContentProperty
50 {
51 public:
52         static int const PATH;
53         static int const POSITION;
54         static int const LENGTH;
55         static int const TRIM_START;
56         static int const TRIM_END;
57         static int const VIDEO_FRAME_RATE;
58 };
59
60 /** @class Content
61  *  @brief A piece of content represented by one or more files on disk.
62  */
63 class Content : public boost::enable_shared_from_this<Content>, public Signaller, public boost::noncopyable
64 {
65 public:
66         explicit Content (boost::shared_ptr<const Film>);
67         Content (boost::shared_ptr<const Film>, DCPTime);
68         Content (boost::shared_ptr<const Film>, boost::filesystem::path);
69         Content (boost::shared_ptr<const Film>, cxml::ConstNodePtr);
70         Content (boost::shared_ptr<const Film>, std::vector<boost::shared_ptr<Content> >);
71         virtual ~Content () {}
72
73         /** Examine the content to establish digest, frame rates and any other
74          *  useful metadata.
75          *  @param job Job to use to report progress, or 0.
76          */
77         virtual void examine (boost::shared_ptr<Job> job);
78
79         virtual void take_settings_from (boost::shared_ptr<const Content> c);
80
81         /** @return Quick one-line summary of the content, as will be presented in the
82          *  film editor.
83          */
84         virtual std::string summary () const = 0;
85
86         /** @return Technical details of this content; these are written to logs to
87          *  help with debugging.
88          */
89         virtual std::string technical_summary () const;
90
91         virtual void as_xml (xmlpp::Node *, bool with_paths) const;
92         virtual DCPTime full_length () const = 0;
93         virtual std::string identifier () const;
94         /** @return points at which to split this content when
95          *  REELTYPE_BY_VIDEO_CONTENT is in use.
96          */
97         virtual std::list<DCPTime> reel_split_points () const;
98
99         boost::shared_ptr<Content> clone () const;
100
101         void set_path (boost::filesystem::path);
102         void set_paths (std::vector<boost::filesystem::path> paths);
103
104         std::string path_summary () const;
105
106         std::vector<boost::filesystem::path> paths () const {
107                 boost::mutex::scoped_lock lm (_mutex);
108                 return _paths;
109         }
110
111         size_t number_of_paths () const {
112                 boost::mutex::scoped_lock lm (_mutex);
113                 return _paths.size ();
114         }
115
116         boost::filesystem::path path (size_t i) const {
117                 boost::mutex::scoped_lock lm (_mutex);
118                 return _paths[i];
119         }
120
121         bool paths_valid () const;
122
123         /** @return Digest of the content's file(s).  Note: this is
124          *  not a complete MD5-or-whatever hash, but a sort of poor
125          *  man's version (see comments in examine()).
126          */
127         std::string digest () const {
128                 boost::mutex::scoped_lock lm (_mutex);
129                 return _digest;
130         }
131
132         void set_position (DCPTime);
133
134         /** DCPTime that this content starts; i.e. the time that the first
135          *  bit of the content (trimmed or not) will happen.
136          */
137         DCPTime position () const {
138                 boost::mutex::scoped_lock lm (_mutex);
139                 return _position;
140         }
141
142         void set_trim_start (ContentTime);
143
144         ContentTime trim_start () const {
145                 boost::mutex::scoped_lock lm (_mutex);
146                 return _trim_start;
147         }
148
149         void set_trim_end (ContentTime);
150
151         ContentTime trim_end () const {
152                 boost::mutex::scoped_lock lm (_mutex);
153                 return _trim_end;
154         }
155
156         /** @return Time immediately after the last thing in this content */
157         DCPTime end () const {
158                 return position() + length_after_trim();
159         }
160
161         DCPTime length_after_trim () const;
162
163         boost::optional<double> video_frame_rate () const {
164                 boost::mutex::scoped_lock lm (_mutex);
165                 return _video_frame_rate;
166         }
167
168         void set_video_frame_rate (double r);
169         void unset_video_frame_rate ();
170
171         double active_video_frame_rate () const;
172
173         void set_change_signals_frequent (bool f) {
174                 _change_signals_frequent = f;
175         }
176
177         boost::shared_ptr<const Film> film () const;
178
179         std::list<UserProperty> user_properties () const;
180
181         boost::signals2::signal<void (boost::weak_ptr<Content>, int, bool)> Changed;
182
183         boost::shared_ptr<VideoContent> video;
184         boost::shared_ptr<AudioContent> audio;
185         std::list<boost::shared_ptr<TextContent> > caption;
186
187         boost::shared_ptr<TextContent> only_caption () const;
188         boost::shared_ptr<TextContent> caption_of_original_type (TextType type) const;
189
190         void signal_changed (int);
191
192 protected:
193
194         virtual void add_properties (std::list<UserProperty> &) const;
195
196         boost::weak_ptr<const Film> _film;
197
198         /** _mutex which should be used to protect accesses, as examine
199          *  jobs can update content state in threads other than the main one.
200          */
201         mutable boost::mutex _mutex;
202
203         /** Paths of our data files */
204         std::vector<boost::filesystem::path> _paths;
205
206 private:
207         friend struct ffmpeg_pts_offset_test;
208         friend struct best_dcp_frame_rate_test_single;
209         friend struct best_dcp_frame_rate_test_double;
210         friend struct audio_sampling_rate_test;
211
212         std::string _digest;
213         DCPTime _position;
214         ContentTime _trim_start;
215         ContentTime _trim_end;
216         /** The video frame rate that this content is or was prepared to be used with,
217          *  or empty if the effective rate of this content should be dictated by something
218          *  else (either some video happening at the same time, or the rate of the DCP).
219          */
220         boost::optional<double> _video_frame_rate;
221         bool _change_signals_frequent;
222 };
223
224 #endif