a1cf26bc61896f8ac15620cf11c6a5ac06ab10a1
[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 name to give the DCP */
75         std::string dcp_name () const {
76                 return _state.dcp_name ();
77         }
78
79         bool use_dci_name () const {
80                 return _state.use_dci_name;
81         }
82
83         /** @return number of pixels to crop from the sides of the original picture */
84         Crop crop () const {
85                 return _state.crop;
86         }
87
88         /** @return the format to present this film in (flat, scope, etc.) */
89         Format const * format () const {
90                 return _state.format;
91         }
92
93         /** @return video filters that should be used when generating DCPs */
94         std::vector<Filter const *> filters () const {
95                 return _state.filters;
96         }
97
98         /** @return scaler algorithm to use */
99         Scaler const * scaler () const {
100                 return _state.scaler;
101         }
102
103         /** @return number of frames to put in the DCP, or 0 for all */
104         int dcp_frames () const {
105                 return _state.dcp_frames;
106         }
107
108         TrimAction dcp_trim_action () const {
109                 return _state.dcp_trim_action;
110         }
111
112         /** @return true to create an A/B comparison DCP, where the left half of the image
113          *  is the video without any filters or post-processing, and the right half
114          *  has the specified filters and post-processing.
115          */
116         bool dcp_ab () const {
117                 return _state.dcp_ab;
118         }
119
120         float audio_gain () const {
121                 return _state.audio_gain;
122         }
123
124         int audio_delay () const {
125                 return _state.audio_delay;
126         }
127
128         int still_duration () const {
129                 return _state.still_duration;
130         }
131
132         bool with_subtitles () const {
133                 return _state.with_subtitles;
134         }
135
136         int subtitle_offset () const {
137                 return _state.subtitle_offset;
138         }
139
140         float subtitle_scale () const {
141                 return _state.subtitle_scale;
142         }
143         
144         void set_filters (std::vector<Filter const *> const &);
145
146         void set_scaler (Scaler const *);
147
148         /** @return the type of content that this Film represents (feature, trailer etc.) */
149         DCPContentType const * dcp_content_type () {
150                 return _state.dcp_content_type;
151         }
152
153         void set_dcp_frames (int);
154         void set_dcp_trim_action (TrimAction);
155         void set_dcp_ab (bool);
156         
157         void set_name (std::string);
158         void set_use_dci_name (bool);
159         void set_content (std::string);
160         void set_top_crop (int);
161         void set_bottom_crop (int);
162         void set_left_crop (int);
163         void set_right_crop (int);
164         void set_format (Format const *);
165         void set_dcp_content_type (DCPContentType const *);
166         void set_audio_gain (float);
167         void set_audio_delay (int);
168         void set_still_duration (int);
169         void set_with_subtitles (bool);
170         void set_subtitle_offset (int);
171         void set_subtitle_scale (float);
172         void set_audio_language (std::string);
173         void set_subtitle_language (std::string);
174         void set_territory (std::string);
175         void set_rating (std::string);
176         void set_studio (std::string);
177         void set_facility (std::string);
178         void set_package_type (std::string);
179
180         /** @return size, in pixels, of the source (ignoring cropping) */
181         Size size () const {
182                 return _state.size;
183         }
184
185         /** @return length, in video frames */
186         int length () const {
187                 return _state.length;
188         }
189
190         /** @return nnumber of video frames per second */
191         float frames_per_second () const {
192                 return _state.frames_per_second;
193         }
194
195         /** @return number of audio channels */
196         int audio_channels () const {
197                 return _state.audio_channels;
198         }
199
200         /** @return audio sample rate, in Hz */
201         int audio_sample_rate () const {
202                 return _state.audio_sample_rate;
203         }
204
205         /** @return format of the audio samples */
206         AVSampleFormat audio_sample_format () const {
207                 return _state.audio_sample_format;
208         }
209
210         bool has_subtitles () const {
211                 return _state.has_subtitles;
212         }
213
214         std::string audio_language () const {
215                 return _state.audio_language;
216         }
217
218         std::string subtitle_language () const {
219                 return _state.subtitle_language;
220         }
221         
222         std::string territory () const {
223                 return _state.territory;
224         }
225
226         std::string rating () const {
227                 return _state.rating;
228         }
229
230         std::string studio () const {
231                 return _state.studio;
232         }
233
234         std::string facility () const {
235                 return _state.facility;
236         }
237
238         std::string package_type () const {
239                 return _state.package_type;
240         }
241
242         std::string j2k_dir () const;
243
244         std::vector<std::string> audio_files () const;
245
246         void update_thumbs_pre_gui ();
247         void update_thumbs_post_gui ();
248         int num_thumbs () const;
249         int thumb_frame (int) const;
250         std::string thumb_file (int) const;
251         std::pair<Position, std::string> thumb_subtitle (int) const;
252
253         void copy_from_dvd_post_gui ();
254         void examine_content ();
255         void examine_content_post_gui ();
256         void send_dcp_to_tms ();
257         void copy_from_dvd ();
258
259         /** @return true if our metadata has been modified since it was last saved */
260         bool dirty () const {
261                 return _dirty;
262         }
263
264         void make_dcp (bool, int freq = 0);
265
266         enum Property {
267                 NONE,
268                 NAME,
269                 CONTENT,
270                 DCP_CONTENT_TYPE,
271                 FORMAT,
272                 CROP,
273                 FILTERS,
274                 SCALER,
275                 DCP_FRAMES,
276                 DCP_TRIM_ACTION,
277                 DCP_AB,
278                 AUDIO_GAIN,
279                 AUDIO_DELAY,
280                 THUMBS,
281                 SIZE,
282                 LENGTH,
283                 FRAMES_PER_SECOND,
284                 AUDIO_CHANNELS,
285                 AUDIO_SAMPLE_RATE,
286                 STILL_DURATION,
287                 WITH_SUBTITLES,
288                 SUBTITLE_OFFSET,
289                 SUBTITLE_SCALE,
290                 USE_DCI_NAME,
291                 DCI_METADATA
292         };
293
294         boost::shared_ptr<FilmState> state_copy () const;
295
296         /** @return Logger.
297          *  It is safe to call this from any thread.
298          */
299         Log* log () const {
300                 return _log;
301         }
302
303         int encoded_frames () const;
304
305         /** Emitted when some metadata property has changed */
306         mutable sigc::signal1<void, Property> Changed;
307         
308 private:
309         void read_metadata ();
310         std::string metadata_file () const;
311         void update_dimensions ();
312         void signal_changed (Property);
313
314         /** The majority of our state.  Kept in a separate object
315          *  so that it can easily be copied for passing onto long-running
316          *  jobs (which then have an unchanging set of parameters).
317          */
318         FilmState _state;
319
320         /** true if our metadata has changed since it was last written to disk */
321         mutable bool _dirty;
322
323         /** Log to write to */
324         Log* _log;
325
326         /** Any running ExamineContentJob, or 0 */
327         boost::shared_ptr<ExamineContentJob> _examine_content_job;
328 };
329
330 #endif