X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Ftranscoder.cc;h=3002ef61c9c0f776d3b714bf326cb14ff7073d97;hb=2ee5d40d5ce7406ce4f1975c4fbf88f70dbe2106;hp=f53fc4001204ec09a74a75ecb74aed55a9495e2d;hpb=70447e72a5595fa03eb0a82b5e93247fcc5cad2b;p=dcpomatic.git diff --git a/src/lib/transcoder.cc b/src/lib/transcoder.cc index f53fc4001..3002ef61c 100644 --- a/src/lib/transcoder.cc +++ b/src/lib/transcoder.cc @@ -28,60 +28,65 @@ #include #include "transcoder.h" #include "encoder.h" -#include "decoder_factory.h" #include "film.h" -#include "matcher.h" -#include "delay_line.h" +#include "video_decoder.h" +#include "audio_decoder.h" +#include "player.h" +#include "job.h" using std::string; using boost::shared_ptr; +using boost::weak_ptr; +using boost::dynamic_pointer_cast; + +static void +video_proxy (weak_ptr encoder, shared_ptr image, Eyes eyes, bool same) +{ + shared_ptr e = encoder.lock (); + if (e) { + e->process_video (image, eyes, same); + } +} + +static void +audio_proxy (weak_ptr encoder, shared_ptr audio) +{ + shared_ptr e = encoder.lock (); + if (e) { + e->process_audio (audio); + } +} /** Construct a transcoder using a Decoder that we create and a supplied Encoder. * @param f Film that we are transcoding. - * @param o Options. * @param j Job that we are running under, or 0. * @param e Encoder to use. */ -Transcoder::Transcoder (shared_ptr f, shared_ptr o, Job* j, shared_ptr e) +Transcoder::Transcoder (shared_ptr f, shared_ptr j) : _job (j) - , _encoder (e) - , _decoder (decoder_factory (f, o, j)) + , _player (f->make_player ()) + , _encoder (new Encoder (f, j)) { - assert (_encoder); - - AudioStream st = f->audio_stream().get(); - - _matcher.reset (new Matcher (f->log(), st.sample_rate(), f->frames_per_second())); - _delay_line.reset (new DelayLine (f->log(), st.channels(), f->audio_delay() * st.sample_rate() / 1000)); - - /* Set up the decoder to use the film's set streams */ - _decoder->set_audio_stream (f->audio_stream ()); - _decoder->set_subtitle_stream (f->subtitle_stream ()); - - _decoder->connect_video (_matcher); - _matcher->connect_video (_encoder); - - _decoder->connect_audio (_delay_line); - _delay_line->connect_audio (_matcher); - _matcher->connect_audio (_delay_line); + _player->Video.connect (bind (video_proxy, _encoder, _1, _2, _3)); + _player->Audio.connect (bind (audio_proxy, _encoder, _1)); } -/** Run the decoder, passing its output to the encoder, until the decoder - * has no more data to present. - */ void Transcoder::go () { _encoder->process_begin (); - try { - _decoder->go (); - } catch (...) { - /* process_end() is important as the decoder may have worker - threads that need to be cleaned up. - */ - _encoder->process_end (); - throw; - } - + while (!_player->pass ()) {} _encoder->process_end (); } + +float +Transcoder::current_encoding_rate () const +{ + return _encoder->current_encoding_rate (); +} + +int +Transcoder::video_frames_out () const +{ + return _encoder->video_frames_out (); +}