Remove thumbnailing stuff.
[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 <boost/signals2.hpp>
34 #include <boost/enable_shared_from_this.hpp>
35 extern "C" {
36 #include <libavcodec/avcodec.h>
37 }
38 #include "dcp_content_type.h"
39 #include "util.h"
40 #include "stream.h"
41
42 class Format;
43 class Job;
44 class Filter;
45 class Log;
46 class ExamineContentJob;
47 class ExternalAudioStream;
48
49 /** @class Film
50  *  @brief A representation of a video with sound.
51  *
52  *  A representation of a piece of video (with sound), including naming,
53  *  the source content file, and how it should be presented in a DCP.
54  */
55 class Film : public boost::enable_shared_from_this<Film>
56 {
57 public:
58         Film (std::string d, bool must_exist = true);
59         Film (Film const &);
60         ~Film ();
61
62         std::string j2k_dir () const;
63         std::vector<std::string> audio_files () const;
64
65         void examine_content ();
66         void send_dcp_to_tms ();
67
68         void make_dcp (bool);
69
70         /** @return Logger.
71          *  It is safe to call this from any thread.
72          */
73         Log* log () const {
74                 return _log;
75         }
76
77         int encoded_frames () const;
78         
79         std::string file (std::string f) const;
80         std::string dir (std::string d) const;
81
82         std::string content_path () const;
83         ContentType content_type () const;
84         
85         int target_audio_sample_rate () const;
86         
87         void write_metadata () const;
88         void read_metadata ();
89
90         Size cropped_size (Size) const;
91         boost::optional<SourceFrame> dcp_length () const;
92         std::string dci_name () const;
93         std::string dcp_name () const;
94
95         bool dirty () const {
96                 return _dirty;
97         }
98
99         int audio_channels () const;
100
101         void set_dci_date_today ();
102
103         enum Property {
104                 NONE,
105                 NAME,
106                 USE_DCI_NAME,
107                 CONTENT,
108                 DCP_CONTENT_TYPE,
109                 FORMAT,
110                 CROP,
111                 FILTERS,
112                 SCALER,
113                 DCP_TRIM_START,
114                 DCP_TRIM_END,
115                 DCP_AB,
116                 CONTENT_AUDIO_STREAM,
117                 EXTERNAL_AUDIO,
118                 USE_CONTENT_AUDIO,
119                 AUDIO_GAIN,
120                 AUDIO_DELAY,
121                 STILL_DURATION,
122                 SUBTITLE_STREAM,
123                 WITH_SUBTITLES,
124                 SUBTITLE_OFFSET,
125                 SUBTITLE_SCALE,
126                 DCI_METADATA,
127                 SIZE,
128                 LENGTH,
129                 CONTENT_AUDIO_STREAMS,
130                 SUBTITLE_STREAMS,
131                 FRAMES_PER_SECOND,
132         };
133
134
135         /* GET */
136
137         std::string directory () const {
138                 boost::mutex::scoped_lock lm (_directory_mutex);
139                 return _directory;
140         }
141
142         std::string name () const {
143                 boost::mutex::scoped_lock lm (_state_mutex);
144                 return _name;
145         }
146
147         bool use_dci_name () const {
148                 boost::mutex::scoped_lock lm (_state_mutex);
149                 return _use_dci_name;
150         }
151
152         std::string content () const {
153                 boost::mutex::scoped_lock lm (_state_mutex);
154                 return _content;
155         }
156
157         DCPContentType const * dcp_content_type () const {
158                 boost::mutex::scoped_lock lm (_state_mutex);
159                 return _dcp_content_type;
160         }
161
162         Format const * format () const {
163                 boost::mutex::scoped_lock lm (_state_mutex);
164                 return _format;
165         }
166
167         Crop crop () const {
168                 boost::mutex::scoped_lock lm (_state_mutex);
169                 return _crop;
170         }
171
172         std::vector<Filter const *> filters () const {
173                 boost::mutex::scoped_lock lm (_state_mutex);
174                 return _filters;
175         }
176
177         Scaler const * scaler () const {
178                 boost::mutex::scoped_lock lm (_state_mutex);
179                 return _scaler;
180         }
181
182         SourceFrame dcp_trim_start () const {
183                 boost::mutex::scoped_lock lm (_state_mutex);
184                 return _dcp_trim_start;
185         }
186
187         SourceFrame dcp_trim_end () const {
188                 boost::mutex::scoped_lock lm (_state_mutex);
189                 return _dcp_trim_end;
190         }
191         
192         bool dcp_ab () const {
193                 boost::mutex::scoped_lock lm (_state_mutex);
194                 return _dcp_ab;
195         }
196
197         boost::shared_ptr<AudioStream> content_audio_stream () const {
198                 boost::mutex::scoped_lock lm (_state_mutex);
199                 return _content_audio_stream;
200         }
201
202         std::vector<std::string> external_audio () const {
203                 boost::mutex::scoped_lock lm (_state_mutex);
204                 return _external_audio;
205         }
206
207         bool use_content_audio () const {
208                 boost::mutex::scoped_lock lm (_state_mutex);
209                 return _use_content_audio;
210         }
211         
212         float audio_gain () const {
213                 boost::mutex::scoped_lock lm (_state_mutex);
214                 return _audio_gain;
215         }
216
217         int audio_delay () const {
218                 boost::mutex::scoped_lock lm (_state_mutex);
219                 return _audio_delay;
220         }
221
222         int still_duration () const {
223                 boost::mutex::scoped_lock lm (_state_mutex);
224                 return _still_duration;
225         }
226
227         boost::shared_ptr<SubtitleStream> subtitle_stream () const {
228                 boost::mutex::scoped_lock lm (_state_mutex);
229                 return _subtitle_stream;
230         }
231
232         bool with_subtitles () const {
233                 boost::mutex::scoped_lock lm (_state_mutex);
234                 return _with_subtitles;
235         }
236
237         int subtitle_offset () const {
238                 boost::mutex::scoped_lock lm (_state_mutex);
239                 return _subtitle_offset;
240         }
241
242         float subtitle_scale () const {
243                 boost::mutex::scoped_lock lm (_state_mutex);
244                 return _subtitle_scale;
245         }
246
247         std::string audio_language () const {
248                 boost::mutex::scoped_lock lm (_state_mutex);
249                 return _audio_language;
250         }
251         
252         std::string subtitle_language () const {
253                 boost::mutex::scoped_lock lm (_state_mutex);
254                 return _subtitle_language;
255         }
256         
257         std::string territory () const {
258                 boost::mutex::scoped_lock lm (_state_mutex);
259                 return _territory;
260         }
261         
262         std::string rating () const {
263                 boost::mutex::scoped_lock lm (_state_mutex);
264                 return _rating;
265         }
266         
267         std::string studio () const {
268                 boost::mutex::scoped_lock lm (_state_mutex);
269                 return _studio;
270         }
271         
272         std::string facility () const {
273                 boost::mutex::scoped_lock lm (_state_mutex);
274                 return _facility;
275         }
276         
277         std::string package_type () const {
278                 boost::mutex::scoped_lock lm (_state_mutex);
279                 return _package_type;
280         }
281
282         Size size () const {
283                 boost::mutex::scoped_lock lm (_state_mutex);
284                 return _size;
285         }
286
287         boost::optional<SourceFrame> length () const {
288                 boost::mutex::scoped_lock lm (_state_mutex);
289                 return _length;
290         }
291         
292         std::string content_digest () const {
293                 boost::mutex::scoped_lock lm (_state_mutex);
294                 return _content_digest;
295         }
296         
297         std::vector<boost::shared_ptr<AudioStream> > content_audio_streams () const {
298                 boost::mutex::scoped_lock lm (_state_mutex);
299                 return _content_audio_streams;
300         }
301
302         std::vector<boost::shared_ptr<SubtitleStream> > subtitle_streams () const {
303                 boost::mutex::scoped_lock lm (_state_mutex);
304                 return _subtitle_streams;
305         }
306         
307         float frames_per_second () const {
308                 boost::mutex::scoped_lock lm (_state_mutex);
309                 return _frames_per_second;
310         }
311
312         boost::shared_ptr<AudioStream> audio_stream () const;
313
314         
315         /* SET */
316
317         void set_directory (std::string);
318         void set_name (std::string);
319         void set_use_dci_name (bool);
320         void set_content (std::string);
321         void set_dcp_content_type (DCPContentType const *);
322         void set_format (Format const *);
323         void set_crop (Crop);
324         void set_left_crop (int);
325         void set_right_crop (int);
326         void set_top_crop (int);
327         void set_bottom_crop (int);
328         void set_filters (std::vector<Filter const *>);
329         void set_scaler (Scaler const *);
330         void set_dcp_trim_start (int);
331         void set_dcp_trim_end (int);
332         void set_dcp_ab (bool);
333         void set_content_audio_stream (boost::shared_ptr<AudioStream>);
334         void set_external_audio (std::vector<std::string>);
335         void set_use_content_audio (bool);
336         void set_audio_gain (float);
337         void set_audio_delay (int);
338         void set_still_duration (int);
339         void set_subtitle_stream (boost::shared_ptr<SubtitleStream>);
340         void set_with_subtitles (bool);
341         void set_subtitle_offset (int);
342         void set_subtitle_scale (float);
343         void set_audio_language (std::string);
344         void set_subtitle_language (std::string);
345         void set_territory (std::string);
346         void set_rating (std::string);
347         void set_studio (std::string);
348         void set_facility (std::string);
349         void set_package_type (std::string);
350         void set_size (Size);
351         void set_length (SourceFrame);
352         void unset_length ();
353         void set_content_digest (std::string);
354         void set_content_audio_streams (std::vector<boost::shared_ptr<AudioStream> >);
355         void set_subtitle_streams (std::vector<boost::shared_ptr<SubtitleStream> >);
356         void set_frames_per_second (float);
357
358         /** Emitted when some property has changed */
359         mutable boost::signals2::signal<void (Property)> Changed;
360
361         /** Current version number of the state file */
362         static int const state_version;
363
364 private:
365         
366         /** Log to write to */
367         Log* _log;
368
369         /** Any running ExamineContentJob, or 0 */
370         boost::shared_ptr<ExamineContentJob> _examine_content_job;
371
372         /** The date that we should use in a DCI name */
373         boost::gregorian::date _dci_date;
374
375         void signal_changed (Property);
376         void examine_content_finished ();
377
378         /** Complete path to directory containing the film metadata;
379          *  must not be relative.
380          */
381         std::string _directory;
382         /** Mutex for _directory */
383         mutable boost::mutex _directory_mutex;
384         
385         /** Name for DVD-o-matic */
386         std::string _name;
387         /** True if a auto-generated DCI-compliant name should be used for our DCP */
388         bool _use_dci_name;
389         /** File or directory containing content; may be relative to our directory
390          *  or an absolute path.
391          */
392         std::string _content;
393         /** The type of content that this Film represents (feature, trailer etc.) */
394         DCPContentType const * _dcp_content_type;
395         /** The format to present this Film in (flat, scope, etc.) */
396         Format const * _format;
397         /** The crop to apply to the source */
398         Crop _crop;
399         /** Video filters that should be used when generating DCPs */
400         std::vector<Filter const *> _filters;
401         /** Scaler algorithm to use */
402         Scaler const * _scaler;
403         /** Frames to trim off the start of the source */
404         SourceFrame _dcp_trim_start;
405         /** Frames to trim off the end of the source */
406         SourceFrame _dcp_trim_end;
407         /** true to create an A/B comparison DCP, where the left half of the image
408             is the video without any filters or post-processing, and the right half
409             has the specified filters and post-processing.
410         */
411         bool _dcp_ab;
412         /** The audio stream to use from our content */
413         boost::shared_ptr<AudioStream> _content_audio_stream;
414         /** List of filenames of external audio files, in channel order
415             (L, R, C, Lfe, Ls, Rs)
416         */
417         std::vector<std::string> _external_audio;
418         /** true to use audio from our content file; false to use external audio */
419         bool _use_content_audio;
420         /** Gain to apply to audio in dB */
421         float _audio_gain;
422         /** Delay to apply to audio (positive moves audio later) in milliseconds */
423         int _audio_delay;
424         /** Duration to make still-sourced films (in seconds) */
425         int _still_duration;
426         boost::shared_ptr<SubtitleStream> _subtitle_stream;
427         /** True if subtitles should be shown for this film */
428         bool _with_subtitles;
429         /** y offset for placing subtitles, in source pixels; +ve is further down
430             the frame, -ve is further up.
431         */
432         int _subtitle_offset;
433         /** scale factor to apply to subtitles */
434         float _subtitle_scale;
435
436         /* DCI naming stuff */
437         std::string _audio_language;
438         std::string _subtitle_language;
439         std::string _territory;
440         std::string _rating;
441         std::string _studio;
442         std::string _facility;
443         std::string _package_type;
444
445         /* Data which are cached to speed things up */
446
447         /** Size, in pixels, of the source (ignoring cropping) */
448         Size _size;
449         /** Actual length of the source (in video frames) from examining it */
450         boost::optional<SourceFrame> _length;
451         /** MD5 digest of our content file */
452         std::string _content_digest;
453         /** The audio streams in our content */
454         std::vector<boost::shared_ptr<AudioStream> > _content_audio_streams;
455         /** A stream to represent possible external audio (will always exist) */
456         boost::shared_ptr<AudioStream> _external_audio_stream;
457         /** the subtitle streams that we can use */
458         std::vector<boost::shared_ptr<SubtitleStream> > _subtitle_streams;
459         /** Frames per second of the source */
460         float _frames_per_second;
461
462         /** true if our state has changed since we last saved it */
463         mutable bool _dirty;
464
465         /** Mutex for all state except _directory */
466         mutable boost::mutex _state_mutex;
467
468         friend class paths_test;
469 };
470
471 #endif