From 53551246da5c1afa2c40bc5dd94bcbe673b7f989 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Wed, 19 Feb 2020 12:19:42 +1100 Subject: [PATCH] decoder: signal indexing progress Better UI interactions, actually shows the progress of the index function in the task manager now. --- app/codec/decoder.cpp | 7 +++++++ app/codec/decoder.h | 8 ++++++++ app/codec/ffmpeg/ffmpegdecoder.cpp | 4 ++++ app/task/index/index.cpp | 2 ++ 4 files changed, 21 insertions(+) diff --git a/app/codec/decoder.cpp b/app/codec/decoder.cpp index 742c378f9..88a824a1f 100644 --- a/app/codec/decoder.cpp +++ b/app/codec/decoder.cpp @@ -180,3 +180,10 @@ void Decoder::Conform(const AudioRenderingParams ¶ms, const QAtomicInt* canc void Decoder::Index(const QAtomicInt *cancelled) { } + +void Decoder::SignalIndexProgress(const int64_t &ts) +{ + if (stream()->duration() != AV_NOPTS_VALUE && stream()->duration() != 0) { + emit IndexProgress(qRound(100.0 * static_cast(ts) / static_cast(stream()->duration()))); + } +} diff --git a/app/codec/decoder.h b/app/codec/decoder.h index 488f17110..3524ce599 100644 --- a/app/codec/decoder.h +++ b/app/codec/decoder.h @@ -234,7 +234,15 @@ public: */ virtual void Index(const QAtomicInt* cancelled); +signals: + /** + * @brief While indexing, this signal will provide progress as a percentage (0-100 inclusive) if available + */ + void IndexProgress(int); + protected: + void SignalIndexProgress(const int64_t& ts); + bool open_; private: diff --git a/app/codec/ffmpeg/ffmpegdecoder.cpp b/app/codec/ffmpeg/ffmpegdecoder.cpp index dfca2fd0c..2f890b446 100644 --- a/app/codec/ffmpeg/ffmpegdecoder.cpp +++ b/app/codec/ffmpeg/ffmpegdecoder.cpp @@ -868,6 +868,8 @@ void FFmpegDecoder::UnconditionalAudioIndex(AVPacket *pkt, AVFrame *frame, const if (data_frame != frame) { av_frame_free(&data_frame); } + + SignalIndexProgress(frame->pts); } } @@ -917,6 +919,8 @@ void FFmpegDecoder::UnconditionalVideoIndex(AVPacket* pkt, AVFrame* frame, const //CacheFrameToDisk(frame); video_stream->append_frame_index(frame->pts); + + SignalIndexProgress(frame->pts); } else { // Assume we've reached the end of the file break; diff --git a/app/task/index/index.cpp b/app/task/index/index.cpp index d240b80e4..aceb322b6 100644 --- a/app/task/index/index.cpp +++ b/app/task/index/index.cpp @@ -17,6 +17,8 @@ void IndexTask::Action() decoder->set_stream(stream_); + connect(decoder.get(), &Decoder::IndexProgress, this, &IndexTask::ProgressChanged); + decoder->Open(); decoder->Index(&IsCancelled()); decoder->Close();