From 0b6f2d7b04819711228ed5fbc5d299b58cef997e Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 14 Jun 2016 15:07:58 +0100 Subject: [PATCH] Clean up of 3D->2D conversion. 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 | 4 ++-- src/lib/encoder.cc | 44 +++++++++++----------------------------- src/lib/encoder.h | 13 ++++-------- src/lib/player.cc | 2 +- src/lib/transcode_job.cc | 6 +++--- src/lib/transcoder.cc | 22 +++++++++++++++++--- src/lib/transcoder.h | 2 +- 7 files changed, 42 insertions(+), 51 deletions(-) diff --git a/run/tests b/run/tests index aa143e0d6..714733bcf 100755 --- 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 diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc index 38bf4e290..8f2aa58f7 100644 --- a/src/lib/encoder.cc +++ b/src/lib/encoder.cc @@ -58,7 +58,6 @@ int const Encoder::_history_size = 25; /** @param f Film that we are encoding */ Encoder::Encoder (shared_ptr film, shared_ptr 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 > pv) -{ - BOOST_FOREACH (shared_ptr 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 pv) +Encoder::encode (shared_ptr pv) { _waker.nudge (); @@ -216,22 +194,24 @@ Encoder::enqueue (shared_ptr 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 ( new DCPVideo ( pv, - _position, + position, _film->video_frame_rate(), _film->j2k_bandwidth(), _film->resolution(), diff --git a/src/lib/encoder.h b/src/lib/encoder.h index 6b830abba..b188e3be3 100644 --- a/src/lib/encoder.h +++ b/src/lib/encoder.h @@ -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 > f); + /** Called to pass a bit of video to be encoded as the next DCP frame */ + void encode (boost::shared_ptr 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 f); void frame_done (); void encoder_thread (boost::optional); @@ -83,7 +80,7 @@ private: /** Film that we are encoding */ boost::shared_ptr _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 _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; diff --git a/src/lib/player.cc b/src/lib/player.cc index c70ac8852..30313d39d 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -374,7 +374,7 @@ Player::get_video (DCPTime time, bool accurate) shared_ptr ( 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, diff --git a/src/lib/transcode_job.cc b/src/lib/transcode_job.cc index b52d0238f..7144f70d5 100644 --- a/src/lib/transcode_job.cc +++ b/src/lib/transcode_job.cc @@ -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; } diff --git a/src/lib/transcoder.cc b/src/lib/transcoder.cc index fd44e4df7..c667a1486 100644 --- a/src/lib/transcoder.cc +++ b/src/lib/transcoder.cc @@ -36,6 +36,7 @@ #include "compose.hpp" #include "referenced_reel_asset.h" #include "subtitle_content.h" +#include "player_video.h" #include #include #include @@ -96,7 +97,22 @@ Transcoder::go () } for (DCPTime t; t < length; t += frame) { - _encoder->encode (_player->get_video (t, true)); + + BOOST_FOREACH (shared_ptr 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 (); } diff --git a/src/lib/transcoder.h b/src/lib/transcoder.h index 4256a5c91..14f363661 100644 --- a/src/lib/transcoder.h +++ b/src/lib/transcoder.h @@ -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 { -- 2.30.2