Split audio; builds.
[dcpomatic.git] / src / lib / content.h
1 /*
2     Copyright (C) 2013-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 /** @file  src/lib/content.h
21  *  @brief Content class.
22  */
23
24 #ifndef DCPOMATIC_CONTENT_H
25 #define DCPOMATIC_CONTENT_H
26
27 #include "types.h"
28 #include "signaller.h"
29 #include "dcpomatic_time.h"
30 #include "raw_convert.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 };
58
59 /** @class Content
60  *  @brief A piece of content represented by one or more files on disk.
61  */
62 class Content : public boost::enable_shared_from_this<Content>, public Signaller, public boost::noncopyable
63 {
64 public:
65         Content (boost::shared_ptr<const Film>);
66         Content (boost::shared_ptr<const Film>, DCPTime);
67         Content (boost::shared_ptr<const Film>, boost::filesystem::path);
68         Content (boost::shared_ptr<const Film>, cxml::ConstNodePtr);
69         Content (boost::shared_ptr<const Film>, std::vector<boost::shared_ptr<Content> >);
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         /** @return Quick one-line summary of the content, as will be presented in the
79          *  film editor.
80          */
81         virtual std::string summary () const = 0;
82
83         /** @return Technical details of this content; these are written to logs to
84          *  help with debugging.
85          */
86         virtual std::string technical_summary () const;
87
88         virtual void as_xml (xmlpp::Node *) const;
89         virtual DCPTime full_length () const = 0;
90         virtual std::string identifier () const;
91         /** @return points at which to split this content when
92          *  REELTYPE_BY_VIDEO_CONTENT is in use.
93          */
94         virtual std::list<DCPTime> reel_split_points () const;
95
96         virtual void changed (int) {}
97
98         boost::shared_ptr<Content> clone () const;
99
100         void set_path (boost::filesystem::path);
101
102         std::string path_summary () const;
103
104         std::vector<boost::filesystem::path> paths () const {
105                 boost::mutex::scoped_lock lm (_mutex);
106                 return _paths;
107         }
108
109         size_t number_of_paths () const {
110                 boost::mutex::scoped_lock lm (_mutex);
111                 return _paths.size ();
112         }
113
114         boost::filesystem::path path (size_t i) const {
115                 boost::mutex::scoped_lock lm (_mutex);
116                 return _paths[i];
117         }
118
119         bool paths_valid () const;
120
121         /** @return Digest of the content's file(s).  Note: this is
122          *  not a complete MD5-or-whatever hash, but a sort of poor
123          *  man's version (see comments in ::examine).
124          */
125         std::string digest () const {
126                 boost::mutex::scoped_lock lm (_mutex);
127                 return _digest;
128         }
129
130         void set_position (DCPTime);
131
132         /** DCPTime that this content starts; i.e. the time that the first
133          *  bit of the content (trimmed or not) will happen.
134          */
135         DCPTime position () const {
136                 boost::mutex::scoped_lock lm (_mutex);
137                 return _position;
138         }
139
140         void set_trim_start (ContentTime);
141
142         ContentTime trim_start () const {
143                 boost::mutex::scoped_lock lm (_mutex);
144                 return _trim_start;
145         }
146
147         void set_trim_end (ContentTime);
148
149         ContentTime trim_end () const {
150                 boost::mutex::scoped_lock lm (_mutex);
151                 return _trim_end;
152         }
153
154         /** @return Time immediately after the last thing in this content */
155         DCPTime end () const {
156                 return position() + length_after_trim();
157         }
158
159         DCPTime length_after_trim () const;
160
161         void set_change_signals_frequent (bool f) {
162                 _change_signals_frequent = f;
163         }
164
165         boost::shared_ptr<const Film> film () const;
166
167         std::list<UserProperty> user_properties () const;
168
169         boost::signals2::signal<void (boost::weak_ptr<Content>, int, bool)> Changed;
170
171         boost::shared_ptr<VideoContent> video;
172         boost::shared_ptr<AudioContent> audio;
173         boost::shared_ptr<SubtitleContent> subtitle;
174
175         void signal_changed (int);
176
177 protected:
178
179         virtual void add_properties (std::list<UserProperty> &) const {}
180
181         boost::weak_ptr<const Film> _film;
182
183         /** _mutex which should be used to protect accesses, as examine
184          *  jobs can update content state in threads other than the main one.
185          */
186         mutable boost::mutex _mutex;
187
188         /** Paths of our data files */
189         std::vector<boost::filesystem::path> _paths;
190
191 private:
192         std::string _digest;
193         DCPTime _position;
194         ContentTime _trim_start;
195         ContentTime _trim_end;
196         bool _change_signals_frequent;
197 };
198
199 #endif