Some tidying up. Do encode progress in the writer to improve progress bar movement...
authorCarl Hetherington <cth@carlh.net>
Wed, 8 May 2013 19:37:53 +0000 (20:37 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 8 May 2013 19:37:53 +0000 (20:37 +0100)
src/lib/ab_transcoder.cc
src/lib/ab_transcoder.h
src/lib/encoder.cc
src/lib/encoder.h
src/lib/player.cc
src/lib/player.h
src/lib/transcoder.cc
src/lib/transcoder.h
src/lib/writer.cc
src/lib/writer.h

index 2e0d41e7de08f24c4bc83b6fb615cecf9cf9a0de..f75491dced81a1a47032e7df471fa758b5807a34 100644 (file)
@@ -47,27 +47,25 @@ using boost::dynamic_pointer_cast;
  *  @param e Encoder to use.
  */
 
-ABTranscoder::ABTranscoder (shared_ptr<Film> a, shared_ptr<Film> b, shared_ptr<Job> j)
-       : _film_a (a)
-       , _film_b (b)
-       , _player_a (_film_a->player ())
-       , _player_b (_film_b->player ())
+ABTranscoder::ABTranscoder (shared_ptr<Film> film_a, shared_ptr<Film> film_b, shared_ptr<Job> j)
+       : _player_a (film_a->player ())
+       , _player_b (film_b->player ())
        , _job (j)
-       , _encoder (new Encoder (_film_a))
-       , _combiner (new Combiner (a->log()))
+       , _encoder (new Encoder (film_a, j))
+       , _combiner (new Combiner (film_a->log()))
 {
-       _matcher.reset (new Matcher (_film_a->log(), _film_a->audio_frame_rate(), _film_a->video_frame_rate()));
-       _delay_line.reset (new DelayLine (_film_a->log(), _film_a->audio_delay() * _film_a->audio_frame_rate() / 1000));
-       _gain.reset (new Gain (_film_a->log(), _film_a->audio_gain()));
+       _matcher.reset (new Matcher (film_a->log(), film_a->audio_frame_rate(), film_a->video_frame_rate()));
+       _delay_line.reset (new DelayLine (film_a->log(), film_a->audio_delay() * film_a->audio_frame_rate() / 1000));
+       _gain.reset (new Gain (film_a->log(), film_a->audio_gain()));
 
        _player_a->Video.connect (bind (&Combiner::process_video, _combiner, _1, _2, _3, _4));
        _player_b->Video.connect (bind (&Combiner::process_video_b, _combiner, _1, _2, _3, _4));
 
-       int const trim_start = _film_a->trim_type() == Film::ENCODE ? _film_a->trim_start() : 0;
-       int const trim_end = _film_a->trim_type() == Film::ENCODE ? _film_a->trim_end() : 0;
+       int const trim_start = film_a->trim_type() == Film::ENCODE ? film_a->trim_start() : 0;
+       int const trim_end = film_a->trim_type() == Film::ENCODE ? film_a->trim_end() : 0;
        _trimmer.reset (new Trimmer (
-                               _film_a->log(), trim_start, trim_end, _film_a->content_length(),
-                               _film_a->audio_frame_rate(), _film_a->video_frame_rate(), _film_a->dcp_frame_rate()
+                               film_a->log(), trim_start, trim_end, film_a->content_length(),
+                               film_a->audio_frame_rate(), film_a->video_frame_rate(), film_a->dcp_frame_rate()
                                ));
        
 
@@ -88,20 +86,7 @@ ABTranscoder::go ()
 {
        _encoder->process_begin ();
 
-       bool done[2] = { false, false };
-       
-       while (1) {
-               done[0] = _player_a->pass ();
-               done[1] = _player_b->pass ();
-
-               if (_job) {
-                       _player_a->set_progress (_job);
-               }
-
-               if (done[0] && done[1]) {
-                       break;
-               }
-       }
+       while (!_player_a->pass () || !_player_b->pass ()) {}
                
        _delay_line->process_end ();
        _matcher->process_end ();
index 1fef66b8870a3ae72de2d8a645e056d656239350..134bce3e48a9c36c4fe133c3a4ded95f437277e1 100644 (file)
@@ -54,8 +54,6 @@ public:
        void go ();
 
 private:
-       boost::shared_ptr<Film> _film_a;
-       boost::shared_ptr<Film> _film_b;
        boost::shared_ptr<Player> _player_a;
        boost::shared_ptr<Player> _player_b;
        boost::shared_ptr<Job> _job;
index c1d1041ae539f9cdab1f087291eb2d8d7104abbb..d25e0d0f8d7dde5a2870e39ba1719b0c5ec77084 100644 (file)
@@ -55,8 +55,9 @@ using boost::optional;
 int const Encoder::_history_size = 25;
 
 /** @param f Film that we are encoding */
-Encoder::Encoder (shared_ptr<Film> f)
+Encoder::Encoder (shared_ptr<Film> f, shared_ptr<Job> j)
        : _film (f)
+       , _job (j)
        , _video_frames_in (0)
        , _video_frames_out (0)
 #ifdef HAVE_SWRESAMPLE   
@@ -127,7 +128,7 @@ Encoder::process_begin ()
                }
        }
 
-       _writer.reset (new Writer (_film));
+       _writer.reset (new Writer (_film, _job));
 }
 
 
index f95d42661b1ed5d50442beed89c7238fa614f675..6cf5540c598a81e879f4a1f88d9845ad43785cfe 100644 (file)
@@ -51,6 +51,7 @@ class ServerDescription;
 class DCPVideoFrame;
 class EncodedData;
 class Writer;
+class Job;
 
 /** @class Encoder
  *  @brief Encoder to J2K and WAV for DCP.
@@ -62,11 +63,11 @@ class Writer;
 class Encoder : public VideoSink, public AudioSink
 {
 public:
-       Encoder (boost::shared_ptr<Film> f);
+       Encoder (boost::shared_ptr<Film> f, boost::shared_ptr<Job>);
        virtual ~Encoder ();
 
        /** Called to indicate that a processing run is about to begin */
-       virtual void process_begin ();
+       void process_begin ();
 
        /** Call with a frame of video.
         *  @param i Video frame image.
@@ -79,7 +80,7 @@ public:
        void process_audio (boost::shared_ptr<const AudioBuffers>);
 
        /** Called when a processing run has finished */
-       virtual void process_end ();
+       void process_end ();
 
        float current_encoding_rate () const;
        int video_frames_out () const;
@@ -93,6 +94,7 @@ private:
 
        /** Film that we are encoding */
        boost::shared_ptr<Film> _film;
+       boost::shared_ptr<Job> _job;
 
        /** Mutex for _time_history and _last_frame */
        mutable boost::mutex _history_mutex;
index 68a962cddb56f545d10eb75b0147c224f42da959..95036cfe0ae18f1ca24ffebea6a8f2a899eb61c6 100644 (file)
@@ -121,18 +121,6 @@ Player::pass ()
        return done;
 }
 
-void
-Player::set_progress (shared_ptr<Job> job)
-{
-       /* Assume progress can be divined from how far through the video we are */
-
-       if (_video_decoder >= _video_decoders.size() || !_playlist->video_length()) {
-               return;
-       }
-
-       job->set_progress ((_video_start[_video_decoder] + _video_decoders[_video_decoder]->video_frame()) / _playlist->video_length ());
-}
-
 void
 Player::process_video (shared_ptr<const Image> i, bool same, shared_ptr<Subtitle> s, double t)
 {
index 20b83bfdb7c2468e702409fbc500286937553ec5..b6fb41f6e9eae15f04e58720ec4e9b2a5ace6847 100644 (file)
@@ -49,7 +49,6 @@ public:
        void disable_subtitles ();
 
        bool pass ();
-       void set_progress (boost::shared_ptr<Job>);
        bool seek (double);
        void seek_back ();
        void seek_forward ();
index 2e33931bd50872cc5edbb16c274af19e336a5bb1..f8fe0c8d5934715844cc1790c789f200a08294ef 100644 (file)
@@ -36,6 +36,7 @@
 #include "audio_decoder.h"
 #include "player.h"
 #include "trimmer.h"
+#include "job.h"
 
 using std::string;
 using boost::shared_ptr;
@@ -49,7 +50,7 @@ using boost::dynamic_pointer_cast;
 Transcoder::Transcoder (shared_ptr<Film> f, shared_ptr<Job> j)
        : _job (j)
        , _player (f->player ())
-       , _encoder (new Encoder (f))
+       , _encoder (new Encoder (f, j))
 {
        _matcher.reset (new Matcher (f->log(), f->audio_frame_rate(), f->video_frame_rate()));
        _delay_line.reset (new DelayLine (f->log(), f->audio_delay() * f->audio_frame_rate() / 1000));
@@ -82,13 +83,9 @@ void
 Transcoder::go ()
 {
        _encoder->process_begin ();
-       while (1) {
-               if (_player->pass ()) {
-                       break;
-               }
-               _player->set_progress (_job);
-       }
 
+       while (!_player->pass ()) {}
+       
        _delay_line->process_end ();
        if (_matcher) {
                _matcher->process_end ();
index 97ecaabfc2a54b9ff48ae7dd8d7640da59fd489c..48b453fe4d64033521034fac1088e3a278e588ac 100644 (file)
@@ -17,6 +17,8 @@
 
 */
 
+#include "types.h"
+
 /** @file  src/transcoder.h
  *
  *  A decoder is selected according to the content type, and the encoder can be specified
@@ -51,7 +53,7 @@ public:
        float current_encoding_rate () const;
        int video_frames_out () const;
 
-protected:
+private:
        /** A Job that is running this Transcoder, or 0 */
        boost::shared_ptr<Job> _job;
        boost::shared_ptr<Player> _player;
index b545848cbcc7d871d7d2b0aaa1e234d20c38cd80..c7d2cf8b4a0ddb61c9fb44cfaa308b53f6de4e6a 100644 (file)
@@ -34,6 +34,7 @@
 #include "player.h"
 #include "audio_mapping.h"
 #include "config.h"
+#include "job.h"
 
 #include "i18n.h"
 
@@ -47,8 +48,9 @@ using boost::shared_ptr;
 
 int const Writer::_maximum_frames_in_memory = 8;
 
-Writer::Writer (shared_ptr<Film> f)
+Writer::Writer (shared_ptr<Film> f, shared_ptr<Job> j)
        : _film (f)
+       , _job (j)
        , _first_nonexistant_frame (0)
        , _thread (0)
        , _finish (false)
@@ -202,6 +204,10 @@ try
                        }
                        }
                        lock.lock ();
+                       
+                       if (_film->video_length ()) {
+                               _job->set_progress (float(_full_written + _fake_written + _repeat_written) / _film->video_length());
+                       }
 
                        ++_last_written_frame;
                }
index beb16c7b9107da1972bcbd5f92a2dc07d3b1b701..62714edf39f675e6354510434618e695a214576c 100644 (file)
@@ -26,6 +26,7 @@
 class Film;
 class EncodedData;
 class AudioBuffers;
+class Job;
 
 namespace libdcp {
        class MonoPictureAsset;
@@ -63,7 +64,7 @@ bool operator== (QueueItem const & a, QueueItem const & b);
 class Writer : public ExceptionStore
 {
 public:
-       Writer (boost::shared_ptr<Film>);
+       Writer (boost::shared_ptr<Film>, boost::shared_ptr<Job>);
 
        bool can_fake_write (int) const;
        
@@ -80,6 +81,7 @@ private:
 
        /** our Film */
        boost::shared_ptr<Film> _film;
+       boost::shared_ptr<Job> _job;
        /** the first frame index that does not already exist in our MXF */
        int _first_nonexistant_frame;