Merge branch 'master' of /home/carl/git/dvdomatic
[dcpomatic.git] / src / lib / film.h
1 /*
2     Copyright (C) 2012 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/film.h
21  *  @brief A representation of a piece of video (with sound), including naming,
22  *  the source content file, and how it should be presented in a DCP.
23  */
24
25 #ifndef DVDOMATIC_FILM_H
26 #define DVDOMATIC_FILM_H
27
28 #include <string>
29 #include <vector>
30 #include <inttypes.h>
31 #include <boost/thread/mutex.hpp>
32 #include <boost/thread.hpp>
33 #include <sigc++/signal.h>
34 extern "C" {
35 #include <libavcodec/avcodec.h>
36 }
37 #include "dcp_content_type.h"
38 #include "film_state.h"
39
40 class Format;
41 class Job;
42 class Filter;
43 class Log;
44 class ExamineContentJob;
45
46 /** @class Film
47  *  @brief A representation of a video with sound.
48  *
49  *  A representation of a piece of video (with sound), including naming,
50  *  the source content file, and how it should be presented in a DCP.
51  */
52 class Film
53 {
54 public:
55         Film (std::string d, bool must_exist = true);
56         Film (Film const &);
57         ~Film ();
58
59         void write_metadata () const;
60
61         /** @return complete path to directory containing the film metadata */
62         std::string directory () const {
63                 return _state.directory;
64         }
65
66         std::string content () const;
67         ContentType content_type () const;
68
69         /** @return name for DVD-o-matic */
70         std::string name () const {
71                 return _state.name;
72         }
73
74         /** @return number of pixels to crop from the sides of the original picture */
75         Crop crop () const {
76                 return _state.crop;
77         }
78
79         /** @return the format to present this film in (flat, scope, etc.) */
80         Format const * format () const {
81                 return _state.format;
82         }
83
84         /** @return video filters that should be used when generating DCPs */
85         std::vector<Filter const *> filters () const {
86                 return _state.filters;
87         }
88
89         /** @return scaler algorithm to use */
90         Scaler const * scaler () const {
91                 return _state.scaler;
92         }
93
94         /** @return number of frames to put in the DCP, or 0 for all */
95         int dcp_frames () const {
96                 return _state.dcp_frames;
97         }
98
99         TrimAction dcp_trim_action () const {
100                 return _state.dcp_trim_action;
101         }
102
103         /** @return true to create an A/B comparison DCP, where the left half of the image
104          *  is the video without any filters or post-processing, and the right half
105          *  has the specified filters and post-processing.
106          */
107         bool dcp_ab () const {
108                 return _state.dcp_ab;
109         }
110
111         float audio_gain () const {
112                 return _state.audio_gain;
113         }
114
115         int audio_delay () const {
116                 return _state.audio_delay;
117         }
118
119         int still_duration () const {
120                 return _state.still_duration;
121         }
122
123         bool with_subtitles () const {
124                 return _state.with_subtitles;
125         }
126
127         int subtitle_offset () const {
128                 return _state.subtitle_offset;
129         }
130
131         float subtitle_scale () const {
132                 return _state.subtitle_scale;
133         }
134         
135         void set_filters (std::vector<Filter const *> const &);
136
137         void set_scaler (Scaler const *);
138
139         /** @return the type of content that this Film represents (feature, trailer etc.) */
140         DCPContentType const * dcp_content_type () {
141                 return _state.dcp_content_type;
142         }
143
144         void set_dcp_frames (int);
145         void set_dcp_trim_action (TrimAction);
146         void set_dcp_ab (bool);
147         
148         void set_name (std::string);
149         void set_content (std::string);
150         void set_top_crop (int);
151         void set_bottom_crop (int);
152         void set_left_crop (int);
153         void set_right_crop (int);
154         void set_format (Format const *);
155         void set_dcp_content_type (DCPContentType const *);
156         void set_audio_gain (float);
157         void set_audio_delay (int);
158         void set_still_duration (int);
159         void set_with_subtitles (bool);
160         void set_subtitle_offset (int);
161         void set_subtitle_scale (float);
162
163         /** @return size, in pixels, of the source (ignoring cropping) */
164         Size size () const {
165                 return _state.size;
166         }
167
168         /** @return length, in video frames */
169         int length () const {
170                 return _state.length;
171         }
172
173         /** @return nnumber of video frames per second */
174         float frames_per_second () const {
175                 return _state.frames_per_second;
176         }
177
178         /** @return number of audio channels */
179         int audio_channels () const {
180                 return _state.audio_channels;
181         }
182
183         /** @return audio sample rate, in Hz */
184         int audio_sample_rate () const {
185                 return _state.audio_sample_rate;
186         }
187
188         /** @return format of the audio samples */
189         AVSampleFormat audio_sample_format () const {
190                 return _state.audio_sample_format;
191         }
192
193         bool has_subtitles () const {
194                 return _state.has_subtitles;
195         }
196         
197         std::string j2k_dir () const;
198
199         std::vector<std::string> audio_files () const;
200
201         void update_thumbs_pre_gui ();
202         void update_thumbs_post_gui ();
203         int num_thumbs () const;
204         int thumb_frame (int) const;
205         std::string thumb_file (int) const;
206         std::list<std::pair<Position, std::string> > thumb_subtitles (int) const;
207
208         void copy_from_dvd_post_gui ();
209         void examine_content ();
210         void examine_content_post_gui ();
211         void send_dcp_to_tms ();
212         void copy_from_dvd ();
213
214         /** @return true if our metadata has been modified since it was last saved */
215         bool dirty () const {
216                 return _dirty;
217         }
218
219         void make_dcp (bool, int freq = 0);
220
221         enum Property {
222                 NONE,
223                 NAME,
224                 CONTENT,
225                 DCP_CONTENT_TYPE,
226                 FORMAT,
227                 CROP,
228                 FILTERS,
229                 SCALER,
230                 DCP_FRAMES,
231                 DCP_TRIM_ACTION,
232                 DCP_AB,
233                 AUDIO_GAIN,
234                 AUDIO_DELAY,
235                 THUMBS,
236                 SIZE,
237                 LENGTH,
238                 FRAMES_PER_SECOND,
239                 AUDIO_CHANNELS,
240                 AUDIO_SAMPLE_RATE,
241                 STILL_DURATION,
242                 WITH_SUBTITLES,
243                 SUBTITLE_OFFSET,
244                 SUBTITLE_SCALE
245         };
246
247         boost::shared_ptr<FilmState> state_copy () const;
248
249         /** @return Logger.
250          *  It is safe to call this from any thread.
251          */
252         Log* log () const {
253                 return _log;
254         }
255
256         int encoded_frames () const;
257
258         /** Emitted when some metadata property has changed */
259         mutable sigc::signal1<void, Property> Changed;
260         
261 private:
262         void read_metadata ();
263         std::string metadata_file () const;
264         void update_dimensions ();
265         void signal_changed (Property);
266
267         /** The majority of our state.  Kept in a separate object
268          *  so that it can easily be copied for passing onto long-running
269          *  jobs (which then have an unchanging set of parameters).
270          */
271         FilmState _state;
272
273         /** true if our metadata has changed since it was last written to disk */
274         mutable bool _dirty;
275
276         /** Log to write to */
277         Log* _log;
278
279         /** Any running ExamineContentJob, or 0 */
280         boost::shared_ptr<ExamineContentJob> _examine_content_job;
281 };
282
283 #endif