From 2f7dd3ddf6ce679023f54cf5ceb075b5ea754629 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Thu, 4 Jun 2020 12:31:44 +0300
Subject: [PATCH] Fix for not recreating encoder with tile change

---
 components/codecs/include/ftl/codecs/nvpipe_decoder.hpp | 2 ++
 components/codecs/src/nvpipe_decoder.cpp                | 6 +++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/components/codecs/include/ftl/codecs/nvpipe_decoder.hpp b/components/codecs/include/ftl/codecs/nvpipe_decoder.hpp
index bb966c130..e663c8551 100644
--- a/components/codecs/include/ftl/codecs/nvpipe_decoder.hpp
+++ b/components/codecs/include/ftl/codecs/nvpipe_decoder.hpp
@@ -30,6 +30,8 @@ class NvPipeDecoder : public ftl::codecs::Decoder {
 	cv::cuda::GpuMat tmp_;
 	int width_;
 	int height_;
+	int last_width_;
+	int last_height_;
 	int n_;
 
 	bool _create(const ftl::codecs::Packet &pkt);
diff --git a/components/codecs/src/nvpipe_decoder.cpp b/components/codecs/src/nvpipe_decoder.cpp
index a64a009a2..3317a0c00 100644
--- a/components/codecs/src/nvpipe_decoder.cpp
+++ b/components/codecs/src/nvpipe_decoder.cpp
@@ -66,7 +66,9 @@ bool NvPipeDecoder::_create(const ftl::codecs::Packet &pkt) {
 	bool is_float_frame = pkt.flags & ftl::codecs::kFlagFloat;
 
 	// Check existing decoder is valid first and remove if not
-	if (nv_decoder_ != nullptr && (last_definition_ != pkt.definition || last_codec_ != pkt.codec || is_float_channel_ != is_float_frame)) {
+	if (nv_decoder_ != nullptr && (last_definition_ != pkt.definition ||
+			last_codec_ != pkt.codec || is_float_channel_ != is_float_frame ||
+			width_ != last_width_ || height_ != last_height_)) {
 		delete nv_decoder_;
 		nv_decoder_ = nullptr;
 	}
@@ -163,6 +165,8 @@ bool NvPipeDecoder::decode(const ftl::codecs::Packet &pkt, cv::cuda::GpuMat &out
 	is_float_channel_ = is_float_frame;
 	last_definition_ = pkt.definition;
 	last_codec_ = pkt.codec;
+	last_width_ = width_;
+	last_height_ = height_;
 
 	// Build a decoder instance of the correct kind
 	/*if (nv_decoder_ == nullptr) {
-- 
GitLab