Thumbs sort of have subs.
[dcpomatic.git] / src / lib / film_state.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_state.h
21  *  @brief The state of a Film.  This is separate from Film so that
22  *  state can easily be copied and kept around for reference
23  *  by long-running jobs.  This avoids the jobs getting confused
24  *  by the user changing Film settings during their run.
25  */
26
27 #ifndef DVDOMATIC_FILM_STATE_H
28 #define DVDOMATIC_FILM_STATE_H
29
30 extern "C" {
31 #include <libavcodec/avcodec.h>
32 #include <libswscale/swscale.h>
33 }
34 #include "scaler.h"
35 #include "util.h"
36 #include "trim_action.h"
37
38 class Format;
39 class DCPContentType;
40 class Filter;
41
42 /** @class FilmState
43  *  @brief The state of a Film.
44  *
45  *  This is separate from Film so that state can easily be copied and
46  *  kept around for reference by long-running jobs.  This avoids the
47  *  jobs getting confused by the user changing Film settings during
48  *  their run.
49  */
50
51 class FilmState
52 {
53 public:
54         FilmState ()
55                 : dcp_content_type (0)
56                 , frames_per_second (0)
57                 , format (0)
58                 , scaler (Scaler::from_id ("bicubic"))
59                 , dcp_frames (0)
60                 , dcp_trim_action (CUT)
61                 , dcp_ab (false)
62                 , audio_gain (0)
63                 , audio_delay (0)
64                 , still_duration (10)
65                 , with_subtitles (false)
66                 , length (0)
67                 , audio_channels (0)
68                 , audio_sample_rate (0)
69                 , audio_sample_format (AV_SAMPLE_FMT_NONE)
70                 , has_subtitles (false)
71         {}
72
73         std::string file (std::string f) const;
74         std::string dir (std::string d) const;
75
76         std::string content_path () const;
77         ContentType content_type () const;
78         
79         bool content_is_dvd () const;
80
81         std::string thumb_file (int) const;
82         std::string thumb_base (int) const;
83         int thumb_frame (int) const;
84
85         int bytes_per_sample () const;
86         int target_sample_rate () const;
87         
88         void write_metadata (std::ofstream &) const;
89         void read_metadata (std::string, std::string);
90
91         Size cropped_size (Size) const;
92
93         int dcp_length () const;
94
95         /** Complete path to directory containing the film metadata;
96             must not be relative.
97         */
98         std::string directory;
99         /** Name for DVD-o-matic */
100         std::string name;
101         /** File or directory containing content; may be relative to our directory
102          *  or an absolute path.
103          */
104         std::string content;
105         /** The type of content that this Film represents (feature, trailer etc.) */
106         DCPContentType const * dcp_content_type;
107         /** Frames per second of the source */
108         float frames_per_second;
109         /** The format to present this Film in (flat, scope, etc.) */
110         Format const * format;
111         Crop crop;
112         /** Video filters that should be used when generating DCPs */
113         std::vector<Filter const *> filters;
114         /** Scaler algorithm to use */
115         Scaler const * scaler;
116         /** Number of frames to put in the DCP, or 0 for all */
117         int dcp_frames;
118
119         TrimAction dcp_trim_action;
120                 
121         /** true to create an A/B comparison DCP, where the left half of the image
122             is the video without any filters or post-processing, and the right half
123             has the specified filters and post-processing.
124         */
125         bool dcp_ab;
126         /** Gain to apply to audio in dB */
127         float audio_gain;
128         /** Delay to apply to audio (positive moves audio later) in milliseconds */
129         int audio_delay;
130         /** Duration to make still-sourced films (in seconds) */
131         int still_duration;
132         bool with_subtitles;
133
134         /* Data which is cached to speed things up */
135
136         /** Vector of frame indices for each of our `thumbnails' */
137         std::vector<int> thumbs;
138         /** Size, in pixels, of the source (ignoring cropping) */
139         Size size;
140         /** Length of the source in frames */
141         int length;
142         /** Number of audio channels */
143         int audio_channels;
144         /** Sample rate of the source audio, in Hz */
145         int audio_sample_rate;
146         /** Format of the audio samples */
147         AVSampleFormat audio_sample_format;
148         /** MD5 digest of our content file */
149         std::string content_digest;
150         /** true if the source has subtitles */
151         bool has_subtitles;
152
153 private:
154         std::string thumb_file_for_frame (int) const;
155         std::string thumb_base_for_frame (int) const;
156 };
157
158 #endif