Various fixes.
[dcpomatic.git] / src / lib / options.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/options.h
21  *  @brief Options for a transcoding operation.
22  */
23
24 #include <string>
25 #include <iomanip>
26 #include <sstream>
27 #include <boost/optional.hpp>
28 #include "util.h"
29
30 /** @class Options
31  *  @brief Options for a transcoding operation.
32  *
33  *  These are settings which may be different, in different circumstances, for
34  *  the same film; ie they are options for a particular transcode operation.
35  */
36 class Options
37 {
38 public:
39
40         Options (std::string f, std::string e, std::string m)
41                 : padding (0)
42                 , apply_crop (true)
43                 , decode_video_skip (0)
44                 , decode_audio (true)
45                 , decode_subtitles (false)
46                 , decoder_alignment (true)
47                 , _frame_out_path (f)
48                 , _frame_out_extension (e)
49                 , _multichannel_audio_out_path (m)
50         {}
51
52         /** @return The path to write video frames to */
53         std::string frame_out_path () const {
54                 return _frame_out_path;
55         }
56
57         /** @param f Source frame index.
58          *  @param t true to return a temporary file path, otherwise a permanent one.
59          *  @return The path to write this video frame to.
60          */
61         std::string frame_out_path (SourceFrame f, bool t, std::string e = "") const {
62                 if (e.empty ()) {
63                         e = _frame_out_extension;
64                 }
65                 
66                 std::stringstream s;
67                 s << _frame_out_path << "/";
68                 s.width (8);
69                 s << std::setfill('0') << f << e;
70
71                 if (t) {
72                         s << ".tmp";
73                 }
74
75                 return s.str ();
76         }
77
78         /** @return Path to write multichannel audio data to */
79         std::string multichannel_audio_out_path () const {
80                 return _multichannel_audio_out_path;
81         }
82
83         /** @param c Audio channel index.
84          *  @param t true to return a temporary file path, otherwise a permanent one.
85          *  @return The path to write this audio file to.
86          */
87         std::string multichannel_audio_out_path (int c, bool t) const {
88                 std::stringstream s;
89                 s << _multichannel_audio_out_path << "/" << (c + 1) << ".wav";
90                 if (t) {
91                         s << ".tmp";
92                 }
93
94                 return s.str ();
95         }
96
97         Size out_size;              ///< size of output images
98         float ratio;                ///< ratio of the wanted output image (not considering padding)
99         int padding;                ///< number of pixels of padding (in terms of the output size) each side of the image
100         bool apply_crop;            ///< true to apply cropping
101
102         /** Range of video frames to decode */
103         boost::optional<std::pair<SourceFrame, SourceFrame> > video_decode_range;
104         /** Range of audio frames to decode */
105         boost::optional<std::pair<int64_t, int64_t> > audio_decode_range;
106         
107         /** Skip frames such that we don't decode any frame where (index % decode_video_skip) != 0; e.g.
108          *  1 for every frame, 2 for every other frame, etc.
109          */
110         SourceFrame decode_video_skip; 
111         bool decode_audio;          ///< true to decode audio, otherwise false
112         bool decode_subtitles;
113
114         bool decoder_alignment;
115
116 private:
117         /** Path of the directory to write video frames to */
118         std::string _frame_out_path;
119         /** Extension to use for video frame files (including the leading .) */
120         std::string _frame_out_extension;
121         /** Path of the directory to write audio files to */
122         std::string _multichannel_audio_out_path;
123 };