Clean up channels coming from ffmpeg wrt those thought to be the case.
[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                 , left_crop (0)
59                 , right_crop (0)
60                 , top_crop (0)
61                 , bottom_crop (0)
62                 , scaler (Scaler::from_id ("bicubic"))
63                 , dcp_frames (0)
64                 , dcp_trim_action (CUT)
65                 , dcp_ab (false)
66                 , audio_gain (0)
67                 , audio_delay (0)
68                 , still_duration (10)
69                 , length (0)
70                 , audio_channels (0)
71                 , audio_sample_rate (0)
72                 , audio_sample_format (AV_SAMPLE_FMT_NONE)
73         {}
74
75         std::string file (std::string f) const;
76         std::string dir (std::string d) const;
77
78         std::string content_path () const;
79         ContentType content_type () const;
80         
81         bool content_is_dvd () const;
82
83         std::string thumb_file (int) const;
84         int thumb_frame (int) const;
85
86         int bytes_per_sample () 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         /** Complete path to directory containing the film metadata;
94             must not be relative.
95         */
96         std::string directory;
97         /** Name for DVD-o-matic */
98         std::string name;
99         /** File or directory containing content; may be relative to our directory
100          *  or an absolute path.
101          */
102         std::string content;
103         /** The type of content that this Film represents (feature, trailer etc.) */
104         DCPContentType const * dcp_content_type;
105         /** Frames per second of the source */
106         float frames_per_second;
107         /** The format to present this Film in (flat, scope, etc.) */
108         Format const * format;
109         /** Number of pixels to crop from the left-hand side of the original picture */
110         int left_crop;
111         /** Number of pixels to crop from the right-hand side of the original picture */
112         int right_crop;
113         /** Number of pixels to crop from the top of the original picture */
114         int top_crop;
115         /** Number of pixels to crop from the bottom of the original picture */
116         int bottom_crop;
117         /** Video filters that should be used when generating DCPs */
118         std::vector<Filter const *> filters;
119         /** Scaler algorithm to use */
120         Scaler const * scaler;
121         /** Number of frames to put in the DCP, or 0 for all */
122         int dcp_frames;
123
124         TrimAction dcp_trim_action;
125                 
126         /** true to create an A/B comparison DCP, where the left half of the image
127             is the video without any filters or post-processing, and the right half
128             has the specified filters and post-processing.
129         */
130         bool dcp_ab;
131         /** Gain to apply to audio in dB */
132         float audio_gain;
133         /** Delay to apply to audio (positive moves audio later) in milliseconds */
134         int audio_delay;
135         /** Duration to make still-sourced films (in seconds) */
136         int still_duration;
137
138         /* Data which is cached to speed things up */
139
140         /** Vector of frame indices for each of our `thumbnails' */
141         std::vector<int> thumbs;
142         /** Size, in pixels, of the source (ignoring cropping) */
143         Size size;
144         /** Length of the source in frames */
145         int length;
146         /** Number of audio channels */
147         int audio_channels;
148         /** Sample rate of the source audio, in Hz */
149         int audio_sample_rate;
150         /** Format of the audio samples */
151         AVSampleFormat audio_sample_format;
152         /** MD5 digest of our content file */
153         std::string content_digest;
154
155 private:
156         std::string thumb_file_for_frame (int) const;
157 };
158
159 #endif