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