Move things round a bit.
[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)
39         : Job (s, o, l)
40 {
41         _fs_b.reset (new FilmState (*_fs));
42         _fs_b->scaler = Config::instance()->reference_scaler ();
43         _fs_b->filters = Config::instance()->reference_filters ();
44 }
45
46 string
47 ABTranscodeJob::name () const
48 {
49         stringstream s;
50         s << "A/B transcode " << _fs->name;
51         return s.str ();
52 }
53
54 void
55 ABTranscodeJob::run ()
56 {
57         try {
58                 /* _fs_b is the one with no filters */
59                 ABTranscoder w (_fs_b, _fs, _opt, this, _log, encoder_factory (_fs, _opt, _log));
60                 w.go ();
61                 set_progress (1);
62                 set_state (FINISHED_OK);
63
64         } catch (std::exception& e) {
65
66                 set_state (FINISHED_ERROR);
67
68         }
69 }