a5659b22f555d9c97734ba808b6f0b79c7bfe479
[dcpomatic.git] / src / lib / ab_transcoder.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 <iostream>
21 #include <boost/shared_ptr.hpp>
22 #include "ab_transcoder.h"
23 #include "film.h"
24 #include "encoder.h"
25 #include "job.h"
26 #include "image.h"
27 #include "player.h"
28 #include "combiner.h"
29
30 /** @file src/ab_transcoder.cc
31  *  @brief A transcoder which uses one Film for the left half of the screen, and a different one
32  *  for the right half (to facilitate A/B comparisons of settings)
33  */
34
35 using std::string;
36 using boost::shared_ptr;
37 using boost::dynamic_pointer_cast;
38
39 /** @param a Film to use for the left half of the screen.
40  *  @param b Film to use for the right half of the screen.
41  *  @param o Decoder options.
42  *  @param j Job that we are associated with.
43  *  @param e Encoder to use.
44  */
45
46 ABTranscoder::ABTranscoder (shared_ptr<Film> film_a, shared_ptr<Film> film_b, shared_ptr<Job> j)
47         : _player_a (film_a->player ())
48         , _player_b (film_b->player ())
49         , _job (j)
50         , _encoder (new Encoder (film_a, j))
51         , _combiner (new Combiner)
52 {
53         _player_a->Video.connect (bind (&Combiner::process_video, _combiner, _1, _2, _3));
54         _player_b->Video.connect (bind (&Combiner::process_video_b, _combiner, _1, _2, _3));
55
56         _combiner->connect_video (_encoder);
57         _player_a->connect_audio (_encoder);
58 }
59
60 void
61 ABTranscoder::go ()
62 {
63         _encoder->process_begin ();
64         while (!_player_a->pass () || !_player_b->pass ()) {}
65         _encoder->process_end ();
66 }