Pass options only to jobs that need them.
[dcpomatic.git] / src / lib / ab_transcode_job.cc
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 #include <stdexcept>
21 #include "ab_transcode_job.h"
22 #include "j2k_wav_encoder.h"
23 #include "film.h"
24 #include "format.h"
25 #include "filter.h"
26 #include "ab_transcoder.h"
27 #include "film_state.h"
28 #include "encoder_factory.h"
29 #include "config.h"
30
31 using namespace std;
32 using namespace boost;
33
34 /** @param s FilmState to compare (with filters and/or a non-bicubic scaler).
35  *  @param o Options.
36  *  @Param l A log that we can write to.
37  */
38 ABTranscodeJob::ABTranscodeJob (shared_ptr<const FilmState> s, shared_ptr<const Options> o, Log* l, shared_ptr<Job> req)
39         : Job (s, l, req)
40         , _opt (o)
41 {
42         _fs_b.reset (new FilmState (*_fs));
43         _fs_b->set_scaler (Config::instance()->reference_scaler ());
44         _fs_b->set_filters (Config::instance()->reference_filters ());
45 }
46
47 string
48 ABTranscodeJob::name () const
49 {
50         return String::compose ("A/B transcode %1", _fs->name());
51 }
52
53 void
54 ABTranscodeJob::run ()
55 {
56         try {
57                 /* _fs_b is the one with no filters */
58                 ABTranscoder w (_fs_b, _fs, _opt, this, _log, encoder_factory (_fs, _opt, _log));
59                 w.go ();
60                 set_progress (1);
61                 set_state (FINISHED_OK);
62
63         } catch (std::exception& e) {
64
65                 set_state (FINISHED_ERROR);
66
67         }
68 }