Split Options into encode / decode.
[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 EncodeOptions
31  *  @brief EncodeOptions for an encoding 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 operation.
35  */
36 class EncodeOptions
37 {
38 public:
39
40         EncodeOptions (std::string f, std::string e, std::string m)
41                 : padding (0)
42                 , video_skip (0)
43                 , _frame_out_path (f)
44                 , _frame_out_extension (e)
45                 , _multichannel_audio_out_path (m)
46         {}
47
48         /** @return The path to write video frames to */
49         std::string frame_out_path () const {
50                 return _frame_out_path;
51         }
52
53         /** @param f Source frame index.
54          *  @param t true to return a temporary file path, otherwise a permanent one.
55          *  @return The path to write this video frame to.
56          */
57         std::string frame_out_path (SourceFrame f, bool t, std::string e = "") const {
58                 if (e.empty ()) {
59                         e = _frame_out_extension;
60                 }
61                 
62                 std::stringstream s;
63                 s << _frame_out_path << "/";
64                 s.width (8);
65                 s << std::setfill('0') << f << e;
66
67                 if (t) {
68                         s << ".tmp";
69                 }
70
71                 return s.str ();
72         }
73
74         /** @return Path to write multichannel audio data to */
75         std::string multichannel_audio_out_path () const {
76                 return _multichannel_audio_out_path;
77         }
78
79         /** @param c Audio channel index.
80          *  @param t true to return a temporary file path, otherwise a permanent one.
81          *  @return The path to write this audio file to.
82          */
83         std::string multichannel_audio_out_path (int c, bool t) const {
84                 std::stringstream s;
85                 s << _multichannel_audio_out_path << "/" << (c + 1) << ".wav";
86                 if (t) {
87                         s << ".tmp";
88                 }
89
90                 return s.str ();
91         }
92
93         Size out_size;              ///< size of output images
94         int padding;                ///< number of pixels of padding (in terms of the output size) each side of the image
95
96         /** Range of video frames to decode */
97         boost::optional<std::pair<SourceFrame, SourceFrame> > video_range;
98         /** Range of audio frames to decode */
99         boost::optional<std::pair<int64_t, int64_t> > audio_range;
100         
101         /** Skip frames such that we don't decode any frame where (index % decode_video_skip) != 0; e.g.
102          *  1 for every frame, 2 for every other frame, etc.
103          */
104         SourceFrame video_skip; 
105
106 private:
107         /** Path of the directory to write video frames to */
108         std::string _frame_out_path;
109         /** Extension to use for video frame files (including the leading .) */
110         std::string _frame_out_extension;
111         /** Path of the directory to write audio files to */
112         std::string _multichannel_audio_out_path;
113 };
114
115
116 class DecodeOptions
117 {
118 public:
119         DecodeOptions ()
120                 : decode_audio (true)
121                 , decode_subtitles (false)
122                 , video_sync (true)
123         {}
124         
125         bool decode_audio;
126         bool decode_subtitles;
127         bool video_sync;
128 };