From 22bfff2c62e0266cd285b5aed2bad2dfbe9efc6b Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Mon, 4 May 2020 01:53:47 +1000 Subject: [PATCH] proxy: improved progress signalling Signals once cache to disk is fully complete (rather than signalling on decode and then sitting at 100% for ages until the disk saving is done). --- app/codec/ffmpeg/ffmpegdecoder.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/app/codec/ffmpeg/ffmpegdecoder.cpp b/app/codec/ffmpeg/ffmpegdecoder.cpp index 1f5e4d422..abea45088 100644 --- a/app/codec/ffmpeg/ffmpegdecoder.cpp +++ b/app/codec/ffmpeg/ffmpegdecoder.cpp @@ -152,7 +152,7 @@ FramePtr FFmpegDecoder::RetrieveVideo(const rational &timecode, const int &divid VideoStreamPtr vs = std::static_pointer_cast(stream()); - if (vs->using_proxy()) { + if (use_proxies && vs->using_proxy()) { QString proxy_fn = GetProxyFilename(vs->using_proxy()); int64_t index_ts = vs->get_closest_timestamp_in_frame_index(target_ts); @@ -636,7 +636,8 @@ void FFmpegDecoder::Error(const QString &s) } QMutex scaler_lock; -void SaveCacheFrame(SwsContext* scaler, +void SaveCacheFrame(FFmpegDecoder* decoder, + SwsContext* scaler, AVFrame* frame, VideoRenderingParams params, QString dst_fn) @@ -719,6 +720,7 @@ bool FFmpegDecoder::ProxyVideo(const QAtomicInt *cancelled, int divider) AVPacket* pkt = av_packet_alloc(); QVector frame_index; QVector< QFuture > futures; + int finished_futures = 0; VideoRenderingParams converted_params(divided_width, divided_height, @@ -750,19 +752,29 @@ bool FFmpegDecoder::ProxyVideo(const QAtomicInt *cancelled, int divider) } frame_index.append(frame->pts); - SignalProcessingProgress(frame->pts); QFuture future = QtConcurrent::run(SaveCacheFrame, + this, scaler, frame, converted_params, GetProxyFrameFilename(frame->pts, divider)); futures.append(future); + + while (finished_futures < futures.size()) { + if (!futures.at(finished_futures).isFinished()) { + SignalProcessingProgress(frame_index.at(finished_futures)); + break; + } + + finished_futures++; + } } // Wait for all conversions to finish - for (int i=0;i