Remove join function; the code is long and I don't think anybody
[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         virtual ~Content () {}
71
72         /** Examine the content to establish digest, frame rates and any other
73          *  useful metadata.
74          *  @param job Job to use to report progress, or 0.
75          */
76         virtual void examine (boost::shared_ptr<Job> job);
77
78         virtual void take_settings_from (boost::shared_ptr<const Content> c);
79
80         /** @return Quick one-line summary of the content, as will be presented in the
81          *  film editor.
82          */
83         virtual std::string summary () const = 0;
84
85         /** @return Technical details of this content; these are written to logs to
86          *  help with debugging.
87          */
88         virtual std::string technical_summary () const;
89
90         virtual void as_xml (xmlpp::Node *, bool with_paths) const;
91         virtual DCPTime full_length () const = 0;
92         virtual std::string identifier () const;
93         /** @return points at which to split this content when
94          *  REELTYPE_BY_VIDEO_CONTENT is in use.
95          */
96         virtual std::list<DCPTime> reel_split_points () const;
97
98         boost::shared_ptr<Content> clone () const;
99
100         void set_path (boost::filesystem::path);
101         void set_paths (std::vector<boost::filesystem::path> paths);
102
103         std::string path_summary () const;
104
105         std::vector<boost::filesystem::path> paths () const {
106                 boost::mutex::scoped_lock lm (_mutex);
107                 return _paths;
108         }
109
110         size_t number_of_paths () const {
111                 boost::mutex::scoped_lock lm (_mutex);
112                 return _paths.size ();
113         }
114
115         boost::filesystem::path path (size_t i) const {
116                 boost::mutex::scoped_lock lm (_mutex);
117                 return _paths[i];
118         }
119
120         bool paths_valid () const;
121
122         /** @return Digest of the content's file(s).  Note: this is
123          *  not a complete MD5-or-whatever hash, but a sort of poor
124          *  man's version (see comments in examine()).
125          */
126         std::string digest () const {
127                 boost::mutex::scoped_lock lm (_mutex);
128                 return _digest;
129         }
130
131         void set_position (DCPTime);
132
133         /** DCPTime that this content starts; i.e. the time that the first
134          *  bit of the content (trimmed or not) will happen.
135          */
136         DCPTime position () const {
137                 boost::mutex::scoped_lock lm (_mutex);
138                 return _position;
139         }
140
141         void set_trim_start (ContentTime);
142
143         ContentTime trim_start () const {
144                 boost::mutex::scoped_lock lm (_mutex);
145                 return _trim_start;
146         }
147
148         void set_trim_end (ContentTime);
149
150         ContentTime trim_end () const {
151                 boost::mutex::scoped_lock lm (_mutex);
152                 return _trim_end;
153         }
154
155         /** @return Time immediately after the last thing in this content */
156         DCPTime end () const {
157                 return position() + length_after_trim();
158         }
159
160         DCPTime length_after_trim () const;
161
162         boost::optional<double> video_frame_rate () const {
163                 boost::mutex::scoped_lock lm (_mutex);
164                 return _video_frame_rate;
165         }
166
167         void set_video_frame_rate (double r);
168         void unset_video_frame_rate ();
169
170         double active_video_frame_rate () const;
171
172         void set_change_signals_frequent (bool f) {
173                 _change_signals_frequent = f;
174         }
175
176         boost::shared_ptr<const Film> film () const;
177
178         std::list<UserProperty> user_properties () const;
179
180         boost::signals2::signal<void (boost::weak_ptr<Content>, int, bool)> Changed;
181
182         boost::shared_ptr<VideoContent> video;
183         boost::shared_ptr<AudioContent> audio;
184         boost::shared_ptr<CaptionContent> caption;
185
186         void signal_changed (int);
187
188 protected:
189
190         virtual void add_properties (std::list<UserProperty> &) const;
191
192         boost::weak_ptr<const Film> _film;
193
194         /** _mutex which should be used to protect accesses, as examine
195          *  jobs can update content state in threads other than the main one.
196          */
197         mutable boost::mutex _mutex;
198
199         /** Paths of our data files */
200         std::vector<boost::filesystem::path> _paths;
201
202 private:
203         friend struct ffmpeg_pts_offset_test;
204         friend struct best_dcp_frame_rate_test_single;
205         friend struct best_dcp_frame_rate_test_double;
206         friend struct audio_sampling_rate_test;
207
208         std::string _digest;
209         DCPTime _position;
210         ContentTime _trim_start;
211         ContentTime _trim_end;
212         /** The video frame rate that this content is or was prepared to be used with,
213          *  or empty if the effective rate of this content should be dictated by something
214          *  else (either some video happening at the same time, or the rate of the DCP).
215          */
216         boost::optional<double> _video_frame_rate;
217         bool _change_signals_frequent;
218 };
219
220 #endif