From 69ca2b2a50bed899e300029426ec477a4c7d79c8 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Tue, 10 Sep 2019 19:12:19 +1000 Subject: [PATCH] fixed bug where an unindexed video would cache a blank first frame --- app/decoder/ffmpeg/ffmpegdecoder.cpp | 4 ++++ app/node/input.cpp | 2 +- app/node/input/media/media.cpp | 5 ++--- app/node/input/media/media.h | 1 - app/node/param.cpp | 5 +++++ app/node/param.h | 1 + app/node/processor/renderer/renderer.cpp | 2 +- 7 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/decoder/ffmpeg/ffmpegdecoder.cpp b/app/decoder/ffmpeg/ffmpegdecoder.cpp index 55145aaea..20e4894ff 100644 --- a/app/decoder/ffmpeg/ffmpegdecoder.cpp +++ b/app/decoder/ffmpeg/ffmpegdecoder.cpp @@ -478,6 +478,10 @@ void FFmpegDecoder::Index() // Save index to file SaveFrameIndex(); + + // Reset state + avcodec_flush_buffers(codec_ctx_); + av_seek_frame(fmt_ctx_, avstream_->index, 0, AVSEEK_FLAG_BACKWARD); } QString FFmpegDecoder::GetIndexFilename() diff --git a/app/node/input.cpp b/app/node/input.cpp index a3f8ed9af..5c0b84334 100644 --- a/app/node/input.cpp +++ b/app/node/input.cpp @@ -77,7 +77,7 @@ QVariant NodeInput::get_value(const rational& time) // Retrieve the value if (!edges_.isEmpty()) { // A connection - use the output of the connected Node - value_ = edges_.first()->output()->get_value(time); + value_ = get_connected_output()->get_value(time); } else { // No connections - use the internal value // FIXME: Re-implement keyframing diff --git a/app/node/input/media/media.cpp b/app/node/input/media/media.cpp index a200717cc..341fa86cd 100644 --- a/app/node/input/media/media.cpp +++ b/app/node/input/media/media.cpp @@ -132,16 +132,15 @@ QVariant MediaInput::Value(NodeOutput *output, const rational &time) } // Check if we need to get a frame or not - if (frame_ == nullptr || frame_native_ts_ != decoder_->GetTimestampFromTime(time)) { + if (frame_ == nullptr || frame_->native_timestamp() != decoder_->GetTimestampFromTime(time)) { // Get frame from Decoder frame_ = decoder_->Retrieve(time); if (frame_ == nullptr) { + qDebug() << "Received a null frame while time was" << time.toDouble(); return 0; } - frame_native_ts_ = frame_->native_timestamp(); - if (color_service_ == nullptr) { // FIXME: Hardcoded values for testing color_service_ = std::make_shared("srgb", OCIO::ROLE_SCENE_LINEAR); diff --git a/app/node/input/media/media.h b/app/node/input/media/media.h index 4bd807ba8..26bb9ccd0 100644 --- a/app/node/input/media/media.h +++ b/app/node/input/media/media.h @@ -77,7 +77,6 @@ private: GLuint ocio_texture_; FramePtr frame_; - int64_t frame_native_ts_; }; diff --git a/app/node/param.cpp b/app/node/param.cpp index 53871e82f..0d9c5f37e 100644 --- a/app/node/param.cpp +++ b/app/node/param.cpp @@ -287,6 +287,11 @@ const rational &NodeParam::LastRequestedTime() return time_; } +bool NodeParam::ValueCachingEnabled() +{ + return value_caching_; +} + void NodeParam::SetValueCachingEnabled(bool enabled) { value_caching_ = enabled; diff --git a/app/node/param.h b/app/node/param.h index d5e719e7d..b4d65957b 100644 --- a/app/node/param.h +++ b/app/node/param.h @@ -255,6 +255,7 @@ public: */ const rational& LastRequestedTime(); + bool ValueCachingEnabled(); void SetValueCachingEnabled(bool enabled); virtual DataType data_type() = 0; diff --git a/app/node/processor/renderer/renderer.cpp b/app/node/processor/renderer/renderer.cpp index 3a4f78f3d..477268fcf 100644 --- a/app/node/processor/renderer/renderer.cpp +++ b/app/node/processor/renderer/renderer.cpp @@ -359,7 +359,7 @@ void RendererProcessor::CacheNext() rational cache_frame = cache_queue_.takeFirst(); - //qDebug() << "[RendererProcessor] Caching" << cache_frame.toDouble(); + qDebug() << "[RendererProcessor] Caching" << cache_frame.toDouble(); threads_.first()->Queue(NodeDependency(texture_input_->get_connected_output(), cache_frame), true);