From 78c27b4fa4d23d4a0a64f0398350ec5697d50551 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 9 May 2017 16:52:26 +0100 Subject: [PATCH] Slight tidy up of progress stuff in TranscodeJob. --- src/lib/dcp_transcoder.cc | 6 +++--- src/lib/dcp_transcoder.h | 4 ++-- src/lib/ffmpeg_transcoder.cc | 19 ++++++++++--------- src/lib/ffmpeg_transcoder.h | 6 +++--- src/lib/transcode_job.cc | 12 ++++++------ src/lib/transcoder.h | 6 ++++-- 6 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/lib/dcp_transcoder.cc b/src/lib/dcp_transcoder.cc index 0d5828fd8..aa3ef73b5 100644 --- a/src/lib/dcp_transcoder.cc +++ b/src/lib/dcp_transcoder.cc @@ -125,13 +125,13 @@ DCPTranscoder::subtitle (PlayerSubtitles data, DCPTimePeriod period) } float -DCPTranscoder::current_encoding_rate () const +DCPTranscoder::current_rate () const { return _encoder->current_encoding_rate (); } -int -DCPTranscoder::video_frames_enqueued () const +Frame +DCPTranscoder::frames_done () const { return _encoder->video_frames_enqueued (); } diff --git a/src/lib/dcp_transcoder.h b/src/lib/dcp_transcoder.h index 84f538bf1..724565101 100644 --- a/src/lib/dcp_transcoder.h +++ b/src/lib/dcp_transcoder.h @@ -39,8 +39,8 @@ public: void go (); - float current_encoding_rate () const; - int video_frames_enqueued () const; + float current_rate () const; + Frame frames_done () const; /** @return true if we are in the process of calling Encoder::process_end */ bool finishing () const { diff --git a/src/lib/ffmpeg_transcoder.cc b/src/lib/ffmpeg_transcoder.cc index 3ebd0e817..19c55ff7a 100644 --- a/src/lib/ffmpeg_transcoder.cc +++ b/src/lib/ffmpeg_transcoder.cc @@ -164,11 +164,7 @@ FFmpegTranscoder::video (shared_ptr video, DCPTime time) frame->width = image->size().width; frame->height = image->size().height; frame->format = _pixel_format; - { - boost::mutex::scoped_lock lm (_mutex); - _last_frame = time.frames_round(_film->video_frame_rate()); - frame->pts = _last_frame / (_film->video_frame_rate() * av_q2d (_video_stream->time_base)); - } + frame->pts = time.seconds() / av_q2d (_video_stream->time_base); AVPacket packet; av_init_packet (&packet); @@ -191,6 +187,11 @@ FFmpegTranscoder::video (shared_ptr video, DCPTime time) _history.event (); + { + boost::mutex::scoped_lock lm (_mutex); + _last_time = time; + } + shared_ptr job = _job.lock (); if (job) { job->set_progress (float(time.get()) / _film->length().get()); @@ -210,14 +211,14 @@ FFmpegTranscoder::subtitle (PlayerSubtitles subs, DCPTimePeriod period) } float -FFmpegTranscoder::current_encoding_rate () const +FFmpegTranscoder::current_rate () const { return _history.rate (); } -int -FFmpegTranscoder::video_frames_enqueued () const +Frame +FFmpegTranscoder::frames_done () const { boost::mutex::scoped_lock lm (_mutex); - return _last_frame; + return _last_time.frames_round (_film->video_frame_rate ()); } diff --git a/src/lib/ffmpeg_transcoder.h b/src/lib/ffmpeg_transcoder.h index 02f0bb82e..5380e84b0 100644 --- a/src/lib/ffmpeg_transcoder.h +++ b/src/lib/ffmpeg_transcoder.h @@ -32,8 +32,8 @@ public: void go (); - float current_encoding_rate () const; - int video_frames_enqueued () const; + float current_rate () const; + Frame frames_done () const; bool finishing () const { return false; } @@ -53,7 +53,7 @@ private: AVPixelFormat _pixel_format; mutable boost::mutex _mutex; - Frame _last_frame; + DCPTime _last_time; EventHistory _history; diff --git a/src/lib/transcode_job.cc b/src/lib/transcode_job.cc index bf878e8c2..52540c4e7 100644 --- a/src/lib/transcode_job.cc +++ b/src/lib/transcode_job.cc @@ -88,7 +88,7 @@ TranscodeJob::run () float fps = 0; if (finish.tv_sec != start.tv_sec) { - fps = _transcoder->video_frames_enqueued() / (finish.tv_sec - start.tv_sec); + fps = _transcoder->frames_done() / (finish.tv_sec - start.tv_sec); } LOG_GENERAL (N_("Transcode job completed successfully: %1 fps"), fps); @@ -119,13 +119,13 @@ TranscodeJob::status () const strncpy (buffer, Job::status().c_str(), 256); } else { snprintf ( - buffer, sizeof(buffer), "%s; %d/%" PRId64 " frames", + buffer, sizeof(buffer), "%s; %" PRId64 "/%" PRId64 " frames", Job::status().c_str(), - _transcoder->video_frames_enqueued(), + _transcoder->frames_done(), _film->length().frames_round (_film->video_frame_rate ()) ); - float const fps = _transcoder->current_encoding_rate (); + float const fps = _transcoder->current_rate (); if (fps) { char fps_buffer[64]; /// TRANSLATORS: fps here is an abbreviation for frames per second @@ -151,12 +151,12 @@ TranscodeJob::remaining_time () const /* We're encoding so guess based on the current encoding rate */ - float fps = t->current_encoding_rate (); + float fps = t->current_rate (); if (fps == 0) { return 0; } /* 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_enqueued()) / fps; + return (_film->length().frames_round (_film->video_frame_rate ()) - t->frames_done()) / fps; } diff --git a/src/lib/transcoder.h b/src/lib/transcoder.h index 37710d883..413b4d9be 100644 --- a/src/lib/transcoder.h +++ b/src/lib/transcoder.h @@ -41,8 +41,10 @@ public: virtual void go () = 0; - virtual float current_encoding_rate () const = 0; - virtual int video_frames_enqueued () const = 0; + /** @return the current frame rate over the last short while */ + virtual float current_rate () const = 0; + /** @return the number of frames that are done */ + virtual Frame frames_done () const = 0; virtual bool finishing () const = 0; protected: -- 2.30.2