Clean up of 3D->2D conversion.
authorCarl Hetherington <cth@carlh.net>
Tue, 14 Jun 2016 14:07:58 +0000 (15:07 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 14 Jun 2016 14:07:58 +0000 (15:07 +0100)
It makes slightly more sense to discard 2D in the Transcoder
rather than the Encoder.  Unfortunately this requires quite
invasive changes, mainly to remove Encoder::_position and instead
derive this information from the PlayerVideo that is being handled.
This is also nicer than before, I think.

A notable change is that in player.cc; using time rather than
content_video_to_dcp().  This means we are assuming that the decoder
returns video at the time we ask it to, rather than checking
what it has returned.  I can't think of a problem with this (yet).

run/tests
src/lib/encoder.cc
src/lib/encoder.h
src/lib/player.cc
src/lib/transcode_job.cc
src/lib/transcoder.cc
src/lib/transcoder.h

index aa143e0d68f8d9911af76768426667dcd85293dc..714733bcf6bf5bfa6bf95c02f90de4eaaa273f61 100755 (executable)
--- a/run/tests
+++ b/run/tests
@@ -17,6 +17,6 @@ elif [ "$1" == "--quiet" ]; then
     shift;
     build/test/unit-tests --catch_system_errors=no $*
 else
-#    build/test/unit-tests --catch_system_errors=no --log_level=test_suite $*
-    build/test/unit-tests --catch_system_errors=no $*
+    build/test/unit-tests --catch_system_errors=no --log_level=test_suite $*
+#    build/test/unit-tests --catch_system_errors=no $*
 fi
index 38bf4e290eafabf781d32d62e1b2f8544e7f96f8..8f2aa58f70ebbe53db9fb1ef3bd3418d23af1a68 100644 (file)
@@ -58,7 +58,6 @@ int const Encoder::_history_size = 25;
 /** @param f Film that we are encoding */
 Encoder::Encoder (shared_ptr<const Film> film, shared_ptr<Writer> writer)
        : _film (film)
-       , _position (0)
        , _writer (writer)
 {
        servers_list_changed ();
@@ -140,12 +139,11 @@ Encoder::current_encoding_rate () const
        return _history_size / (seconds (now) - seconds (_time_history.back ()));
 }
 
-/** @return Number of video frames that have been sent out */
+/** @return Number of video frames that have been queued for encoding */
 int
-Encoder::video_frames_out () const
+Encoder::video_frames_enqueued () const
 {
-       boost::mutex::scoped_lock (_state_mutex);
-       return _position;
+       return _last_player_video->time().frames_floor (_film->video_frame_rate ());
 }
 
 /** Should be called when a frame has been encoded successfully.
@@ -170,27 +168,7 @@ Encoder::frame_done ()
  *  for this DCP frame.
  */
 void
-Encoder::encode (list<shared_ptr<PlayerVideo> > pv)
-{
-       BOOST_FOREACH (shared_ptr<PlayerVideo> i, pv) {
-               if (!_film->three_d()) {
-                       /* 2D DCP */
-                       if (i->eyes() == EYES_RIGHT) {
-                               /* Discard right-eye images */
-                               continue;
-                       } else if (i->eyes() == EYES_LEFT) {
-                               /* Use left-eye images for both eyes */
-                               i->set_eyes (EYES_BOTH);
-                       }
-               }
-
-               enqueue (i);
-       }
-       ++_position;
-}
-
-void
-Encoder::enqueue (shared_ptr<PlayerVideo> pv)
+Encoder::encode (shared_ptr<PlayerVideo> pv)
 {
        _waker.nudge ();
 
@@ -216,22 +194,24 @@ Encoder::enqueue (shared_ptr<PlayerVideo> pv)
        */
        rethrow ();
 
-       if (_writer->can_fake_write (_position)) {
+       Frame const position = pv->time().frames_floor(_film->video_frame_rate());
+
+       if (_writer->can_fake_write (position)) {
                /* We can fake-write this frame */
-               _writer->fake_write (_position, pv->eyes ());
+               _writer->fake_write (position, pv->eyes ());
                frame_done ();
        } else if (pv->has_j2k ()) {
                /* This frame already has JPEG2000 data, so just write it */
-               _writer->write (pv->j2k(), _position, pv->eyes ());
-       } else if (_last_player_video && _writer->can_repeat(_position) && pv->same (_last_player_video)) {
-               _writer->repeat (_position, pv->eyes ());
+               _writer->write (pv->j2k(), position, pv->eyes ());
+       } else if (_last_player_video && _writer->can_repeat(position) && pv->same (_last_player_video)) {
+               _writer->repeat (position, pv->eyes ());
        } else {
                /* Queue this new frame for encoding */
                LOG_TIMING ("add-frame-to-queue queue=%1", _queue.size ());
                _queue.push_back (shared_ptr<DCPVideo> (
                                          new DCPVideo (
                                                  pv,
-                                                 _position,
+                                                 position,
                                                  _film->video_frame_rate(),
                                                  _film->j2k_bandwidth(),
                                                  _film->resolution(),
index 6b830abba15f6585e28fc101137861cbdcae4ea7..b188e3be304ac4f8d3a04985cdd7218758d203f7 100644 (file)
@@ -60,20 +60,17 @@ public:
        /** Called to indicate that a processing run is about to begin */
        void begin ();
 
-       /** Called to pass in zero or more bits of video to be encoded
-        *  as the next DCP frame.
-        */
-       void encode (std::list<boost::shared_ptr<PlayerVideo> > f);
+       /** Called to pass a bit of video to be encoded as the next DCP frame */
+       void encode (boost::shared_ptr<PlayerVideo> f);
 
        /** Called when a processing run has finished */
        void end ();
 
        float current_encoding_rate () const;
-       int video_frames_out () const;
+       int video_frames_enqueued () const;
 
 private:
 
-       void enqueue (boost::shared_ptr<PlayerVideo> f);
        void frame_done ();
 
        void encoder_thread (boost::optional<EncodeServerDescription>);
@@ -83,7 +80,7 @@ private:
        /** Film that we are encoding */
        boost::shared_ptr<const Film> _film;
 
-       /** Mutex for _time_history and _video_frames_enqueued */
+       /** Mutex for _time_history */
        mutable boost::mutex _state_mutex;
        /** List of the times of completion of the last _history_size frames;
            first is the most recently completed.
@@ -91,8 +88,6 @@ private:
        std::list<struct timeval> _time_history;
        /** Number of frames that we should keep history for */
        static int const _history_size;
-       /** Current DCP frame index */
-       Frame _position;
 
        /** Mutex for _threads */
        mutable boost::mutex _threads_mutex;
index c70ac8852baf27b9b7c9ebbd6a7e3e9270e65517..30313d39dd23bb57445cf43ff8a45f7b9c2d8b00 100644 (file)
@@ -374,7 +374,7 @@ Player::get_video (DCPTime time, bool accurate)
                                                        shared_ptr<PlayerVideo> (
                                                                new PlayerVideo (
                                                                        i->image,
-                                                                       content_video_to_dcp (piece, i->frame.index()),
+                                                                       time,
                                                                        piece->content->video->crop (),
                                                                        piece->content->video->fade (i->frame.index()),
                                                                        image_size,
index b52d0238f3c10b1b91b9cfdc53f1a6db99b84d54..7144f70d5127242fd7dca122e94713f1b761d2ff 100644 (file)
@@ -83,7 +83,7 @@ TranscodeJob::run ()
 
                float fps = 0;
                if (finish.tv_sec != start.tv_sec) {
-                       fps = _transcoder->video_frames_out() / (finish.tv_sec - start.tv_sec);
+                       fps = _transcoder->video_frames_enqueued() / (finish.tv_sec - start.tv_sec);
                }
 
                LOG_GENERAL (N_("Transcode job completed successfully: %1 fps"), fps);
@@ -118,7 +118,7 @@ TranscodeJob::status () const
 
        if (!finished () && !_transcoder->finishing ()) {
                /// TRANSLATORS: fps here is an abbreviation for frames per second
-               s << "; " << _transcoder->video_frames_out() << "/"
+               s << "; " << _transcoder->video_frames_enqueued() << "/"
                  << _film->length().frames_round (_film->video_frame_rate ()) << " " << _("frames") << "; "
                  << fixed << setprecision (1) << fps << " " << _("fps");
        }
@@ -144,5 +144,5 @@ TranscodeJob::remaining_time () const
        }
 
        /* Compute approximate proposed length here, as it's only here that we need it */
-       return (_film->length().frames_round (_film->video_frame_rate ()) - t->video_frames_out()) / fps;
+       return (_film->length().frames_round (_film->video_frame_rate ()) - t->video_frames_enqueued()) / fps;
 }
index fd44e4df75ceb1e2f4f093e6b6dfd6aa6d8d036d..c667a1486e61ee4fd8e70337ce416ffa422c67f9 100644 (file)
@@ -36,6 +36,7 @@
 #include "compose.hpp"
 #include "referenced_reel_asset.h"
 #include "subtitle_content.h"
+#include "player_video.h"
 #include <boost/signals2.hpp>
 #include <boost/foreach.hpp>
 #include <iostream>
@@ -96,7 +97,22 @@ Transcoder::go ()
        }
 
        for (DCPTime t; t < length; t += frame) {
-               _encoder->encode (_player->get_video (t, true));
+
+               BOOST_FOREACH (shared_ptr<PlayerVideo> i, _player->get_video (t, true)) {
+                       if (!_film->three_d()) {
+                               /* 2D DCP */
+                               if (i->eyes() == EYES_RIGHT) {
+                                       /* Discard right-eye images */
+                                       continue;
+                               } else if (i->eyes() == EYES_LEFT) {
+                                       /* Use left-eye images for both eyes */
+                                       i->set_eyes (EYES_BOTH);
+                               }
+                       }
+
+                       _encoder->encode (i);
+               }
+
                _writer->write (_player->get_audio (t, frame, true));
 
                if (non_burnt_subtitles) {
@@ -126,7 +142,7 @@ Transcoder::current_encoding_rate () const
 }
 
 int
-Transcoder::video_frames_out () const
+Transcoder::video_frames_enqueued () const
 {
-       return _encoder->video_frames_out ();
+       return _encoder->video_frames_enqueued ();
 }
index 4256a5c91dfa4aa44caa2d6ebb60bc0dc13552d9..14f3636619a8303aacf2d568011df8883c5ec6de 100644 (file)
@@ -36,7 +36,7 @@ public:
        void go ();
 
        float current_encoding_rate () const;
-       int video_frames_out () const;
+       int video_frames_enqueued () const;
 
        /** @return true if we are in the process of calling Encoder::process_end */
        bool finishing () const {