2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
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.
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.
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.
21 #include <boost/shared_ptr.hpp>
22 #include "ab_transcoder.h"
24 #include "video_decoder.h"
25 #include "audio_decoder.h"
30 #include "decoder_factory.h"
32 #include "delay_line.h"
36 /** @file src/ab_transcoder.cc
37 * @brief A transcoder which uses one Film for the left half of the screen, and a different one
38 * for the right half (to facilitate A/B comparisons of settings)
42 using boost::shared_ptr;
43 using boost::dynamic_pointer_cast;
45 /** @param a Film to use for the left half of the screen.
46 * @param b Film to use for the right half of the screen.
47 * @param o Decoder options.
48 * @param j Job that we are associated with.
49 * @param e Encoder to use.
52 ABTranscoder::ABTranscoder (
53 shared_ptr<Film> a, shared_ptr<Film> b, DecodeOptions o, Job* j, shared_ptr<Encoder> e)
58 , _combiner (new Combiner (a->log()))
60 _da = decoder_factory (_film_a, o);
61 _db = decoder_factory (_film_b, o);
63 shared_ptr<AudioStream> st = _film_a->audio_stream();
64 _matcher.reset (new Matcher (_film_a->log(), st->sample_rate(), _film_a->source_frame_rate()));
65 _delay_line.reset (new DelayLine (_film_a->log(), _film_a->audio_delay() / 1000.0f));
66 _gain.reset (new Gain (_film_a->log(), _film_a->audio_gain()));
68 /* Set up the decoder to use the film's set streams */
69 _da.video->set_subtitle_stream (_film_a->subtitle_stream ());
70 _db.video->set_subtitle_stream (_film_a->subtitle_stream ());
71 _da.audio->set_audio_stream (_film_a->audio_stream ());
73 _da.video->Video.connect (bind (&Combiner::process_video, _combiner, _1, _2, _3));
74 _db.video->Video.connect (bind (&Combiner::process_video_b, _combiner, _1, _2, _3));
76 _combiner->connect_video (_delay_line);
77 _delay_line->connect_video (_matcher);
78 _matcher->connect_video (_encoder);
80 _da.audio->connect_audio (_delay_line);
81 _delay_line->connect_audio (_matcher);
82 _matcher->connect_audio (_gain);
83 _gain->connect_audio (_encoder);
89 _encoder->process_begin ();
91 bool done[3] = { false, false, false };
94 done[0] = _da.video->pass ();
95 done[1] = _db.video->pass ();
97 if (!done[2] && _da.audio && dynamic_pointer_cast<Decoder> (_da.audio) != dynamic_pointer_cast<Decoder> (_da.video)) {
98 done[2] = _da.audio->pass ();
104 _da.video->set_progress (_job);
107 if (done[0] && done[1] && done[2]) {
113 _delay_line->process_end ();
116 _matcher->process_end ();
119 _gain->process_end ();
121 _encoder->process_end ();