Move things round a bit.
[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 <sigc++/signal.h>
33 extern "C" {
34 #include <libavcodec/avcodec.h>
35 }
36 #include "dcp_content_type.h"
37 #include "film_state.h"
38
39 class Format;
40 class Job;
41 class Filter;
42 class Log;
43 class ExamineContentJob;
44
45 /** @class Film
46  *  @brief A representation of a video with sound.
47  *
48  *  A representation of a piece of video (with sound), including naming,
49  *  the source content file, and how it should be presented in a DCP.
50  */
51 class Film
52 {
53 public:
54         Film (std::string d, bool must_exist = true);
55         Film (Film const &);
56         ~Film ();
57
58         void write_metadata () const;
59
60         /** @return complete path to directory containing the film metadata */
61         std::string directory () const {
62                 return _state.directory;
63         }
64
65         std::string content () const;
66         ContentType content_type () const;
67
68         /** @return name for DVD-o-matic */
69         std::string name () const {
70                 return _state.name;
71         }
72
73         /** @return number of pixels to crop from the top of the original picture */
74         int top_crop () const {
75                 return _state.top_crop;
76         }
77
78         /** @return number of pixels to crop from the bottom of the original picture */
79         int bottom_crop () const {
80                 return _state.bottom_crop;
81         }
82
83         /** @return number of pixels to crop from the left-hand side of the original picture */
84         int left_crop () const {
85                 return _state.left_crop;
86         }
87
88         /** @return number of pixels to crop from the right-hand side of the original picture */
89         int right_crop () const {
90                 return _state.right_crop;
91         }
92
93         /** @return the format to present this film in (flat, scope, etc.) */
94         Format const * format () const {
95                 return _state.format;
96         }
97
98         /** @return video filters that should be used when generating DCPs */
99         std::vector<Filter const *> filters () const {
100                 return _state.filters;
101         }
102
103         /** @return scaler algorithm to use */
104         Scaler const * scaler () const {
105                 return _state.scaler;
106         }
107
108         /** @return number of frames to put in the DCP, or 0 for all */
109         int dcp_frames () const {
110                 return _state.dcp_frames;
111         }
112
113         TrimAction dcp_trim_action () const {
114                 return _state.dcp_trim_action;
115         }
116
117         /** @return true to create an A/B comparison DCP, where the left half of the image
118          *  is the video without any filters or post-processing, and the right half
119          *  has the specified filters and post-processing.
120          */
121         bool dcp_ab () const {
122                 return _state.dcp_ab;
123         }
124
125         float audio_gain () const {
126                 return _state.audio_gain;
127         }
128
129         int audio_delay () const {
130                 return _state.audio_delay;
131         }
132
133         int still_duration () const {
134                 return _state.still_duration;
135         }
136         
137         void set_filters (std::vector<Filter const *> const &);
138
139         void set_scaler (Scaler const *);
140
141         /** @return the type of content that this Film represents (feature, trailer etc.) */
142         DCPContentType const * dcp_content_type () {
143                 return _state.dcp_content_type;
144         }
145
146         void set_dcp_frames (int);
147         void set_dcp_trim_action (TrimAction);
148         void set_dcp_ab (bool);
149         
150         void set_name (std::string);
151         void set_content (std::string);
152         void set_top_crop (int);
153         void set_bottom_crop (int);
154         void set_left_crop (int);
155         void set_right_crop (int);
156         void set_frames_per_second (float);
157         void set_format (Format const *);
158         void set_dcp_content_type (DCPContentType const *);
159         void set_audio_gain (float);
160         void set_audio_delay (int);
161         void set_still_duration (int);
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         std::string j2k_dir () const;
194
195         std::vector<std::string> audio_files () const;
196
197         void update_thumbs_pre_gui ();
198         void update_thumbs_post_gui ();
199         int num_thumbs () const;
200         int thumb_frame (int) const;
201         std::string thumb_file (int) const;
202
203         void copy_from_dvd_post_gui ();
204         void examine_content ();
205         void examine_content_post_gui ();
206         void send_dcp_to_tms ();
207         void copy_from_dvd ();
208
209         /** @return true if our metadata has been modified since it was last saved */
210         bool dirty () const {
211                 return _dirty;
212         }
213
214         void make_dcp (bool, int freq = 0);
215
216         enum Property {
217                 NAME,
218                 CONTENT,
219                 DCP_CONTENT_TYPE,
220                 FORMAT,
221                 LEFT_CROP,
222                 RIGHT_CROP,
223                 TOP_CROP,
224                 BOTTOM_CROP,
225                 FILTERS,
226                 SCALER,
227                 DCP_FRAMES,
228                 DCP_TRIM_ACTION,
229                 DCP_AB,
230                 AUDIO_GAIN,
231                 AUDIO_DELAY,
232                 THUMBS,
233                 SIZE,
234                 LENGTH,
235                 FRAMES_PER_SECOND,
236                 AUDIO_CHANNELS,
237                 AUDIO_SAMPLE_RATE,
238                 STILL_DURATION
239         };
240
241         boost::shared_ptr<FilmState> state_copy () const;
242
243         /** @return Logger.
244          *  It is safe to call this from any thread.
245          */
246         Log* log () const {
247                 return _log;
248         }
249
250         /** Emitted when some metadata property has changed */
251         mutable sigc::signal1<void, Property> Changed;
252         
253 private:
254         void read_metadata ();
255         std::string metadata_file () const;
256         void update_dimensions ();
257         void signal_changed (Property);
258
259         /** The majority of our state.  Kept in a separate object
260          *  so that it can easily be copied for passing onto long-running
261          *  jobs (which then have an unchanging set of parameters).
262          */
263         FilmState _state;
264
265         /** true if our metadata has changed since it was last written to disk */
266         mutable bool _dirty;
267
268         /** Log to write to */
269         Log* _log;
270
271         /** Any running ExamineContentJob, or 0 */
272         boost::shared_ptr<ExamineContentJob> _examine_content_job;
273 };
274
275 #endif