Slight tidy up of progress stuff in TranscodeJob.
authorCarl Hetherington <cth@carlh.net>
Tue, 9 May 2017 15:52:26 +0000 (16:52 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 9 May 2017 15:52:26 +0000 (16:52 +0100)
src/lib/dcp_transcoder.cc
src/lib/dcp_transcoder.h
src/lib/ffmpeg_transcoder.cc
src/lib/ffmpeg_transcoder.h
src/lib/transcode_job.cc
src/lib/transcoder.h

index 0d5828fd8bcc93dea5b91c50464c085d23502ec4..aa3ef73b58be3da713338a72df64f2e5af03942f 100644 (file)
@@ -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 ();
 }
index 84f538bf1c7eec8a204337db3544ca2173fc3c90..7245651019caf3716ebe258984e01f460e8006ae 100644 (file)
@@ -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 {
index 3ebd0e8170a9e306961ac59a5b9fc2fcf8764052..19c55ff7ab22f824940e0cdbc7808af9f0031774 100644 (file)
@@ -164,11 +164,7 @@ FFmpegTranscoder::video (shared_ptr<PlayerVideo> 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<PlayerVideo> video, DCPTime time)
 
        _history.event ();
 
+       {
+               boost::mutex::scoped_lock lm (_mutex);
+               _last_time = time;
+       }
+
        shared_ptr<Job> 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 ());
 }
index 02f0bb82e66310004628436f96ef58def2665f8a..5380e84b01802a9f1448405f5358de9dcd2f7b2a 100644 (file)
@@ -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;
 
index bf878e8c2b5e6fb5432d177e4f1febe7ed4367f1..52540c4e7eb5dde8c172263335e2c70ba0816fcd 100644 (file)
@@ -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;
 }
index 37710d8836fc6c99e65369a2e5ae4d21eadd5dc7..413b4d9bedec73de666b3b01a54d71e75c209e75 100644 (file)
@@ -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: