summaryrefslogtreecommitdiff
path: root/src/lib/film_state.h
blob: 12d44cdce23797557aac7c23a8229b5835094298 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

/** @file src/film_state.h
 *  @brief The state of a Film.  This is separate from Film so that
 *  state can easily be copied and kept around for reference
 *  by long-running jobs.  This avoids the jobs getting confused
 *  by the user changing Film settings during their run.
 */

#ifndef DVDOMATIC_FILM_STATE_H
#define DVDOMATIC_FILM_STATE_H

extern "C" {
#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>
}
#include "scaler.h"
#include "util.h"
#include "trim_action.h"

class Format;
class DCPContentType;
class Filter;

/** @class FilmState
 *  @brief The state of a Film.
 *
 *  This is separate from Film so that state can easily be copied and
 *  kept around for reference by long-running jobs.  This avoids the
 *  jobs getting confused by the user changing Film settings during
 *  their run.
 */

class FilmState
{
public:
	FilmState ()
		: dcp_content_type (0)
		, frames_per_second (0)
		, format (0)
		, scaler (Scaler::from_id ("bicubic"))
		, dcp_frames (0)
		, dcp_trim_action (CUT)
		, dcp_ab (false)
		, audio_gain (0)
		, audio_delay (0)
		, still_duration (10)
		, length (0)
		, audio_channels (0)
		, audio_sample_rate (0)
		, audio_sample_format (AV_SAMPLE_FMT_NONE)
	{}

	std::string file (std::string f) const;
	std::string dir (std::string d) const;

	std::string content_path () const;
	ContentType content_type () const;
	
	bool content_is_dvd () const;

	std::string thumb_file (int) const;
	int thumb_frame (int) const;

	int bytes_per_sample () const;
	
	void write_metadata (std::ofstream &) const;
	void read_metadata (std::string, std::string);

	Size cropped_size (Size) const;

	/** Complete path to directory containing the film metadata;
	    must not be relative.
	*/
	std::string directory;
	/** Name for DVD-o-matic */
	std::string name;
	/** File or directory containing content; may be relative to our directory
	 *  or an absolute path.
	 */
	std::string content;
	/** The type of content that this Film represents (feature, trailer etc.) */
	DCPContentType const * dcp_content_type;
	/** Frames per second of the source */
	float frames_per_second;
	/** The format to present this Film in (flat, scope, etc.) */
	Format const * format;
	Crop crop;
	/** Video filters that should be used when generating DCPs */
	std::vector<Filter const *> filters;
	/** Scaler algorithm to use */
	Scaler const * scaler;
	/** Number of frames to put in the DCP, or 0 for all */
	int dcp_frames;

	TrimAction dcp_trim_action;
		
	/** true to create an A/B comparison DCP, where the left half of the image
	    is the video without any filters or post-processing, and the right half
	    has the specified filters and post-processing.
	*/
	bool dcp_ab;
	/** Gain to apply to audio in dB */
	float audio_gain;
	/** Delay to apply to audio (positive moves audio later) in milliseconds */
	int audio_delay;
	/** Duration to make still-sourced films (in seconds) */
	int still_duration;

	/* Data which is cached to speed things up */

	/** Vector of frame indices for each of our `thumbnails' */
	std::vector<int> thumbs;
	/** Size, in pixels, of the source (ignoring cropping) */
	Size size;
	/** Length of the source in frames */
	int length;
	/** Number of audio channels */
	int audio_channels;
	/** Sample rate of the source audio, in Hz */
	int audio_sample_rate;
	/** Format of the audio samples */
	AVSampleFormat audio_sample_format;
	/** MD5 digest of our content file */
	std::string content_digest;

private:
	std::string thumb_file_for_frame (int) const;
};

#endif