From 9e81a7907feaf674defebf53366155aab81412a4 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Sat, 26 Oct 2019 11:00:16 +0300
Subject: [PATCH] Fix version 2 flag clear bug

---
 components/codecs/include/ftl/codecs/packet.hpp | 2 +-
 components/codecs/include/ftl/codecs/reader.hpp | 1 +
 components/codecs/src/reader.cpp                | 7 +++++++
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/components/codecs/include/ftl/codecs/packet.hpp b/components/codecs/include/ftl/codecs/packet.hpp
index 89df44f9e..f2fa53c8f 100644
--- a/components/codecs/include/ftl/codecs/packet.hpp
+++ b/components/codecs/include/ftl/codecs/packet.hpp
@@ -16,7 +16,7 @@ namespace codecs {
  */
 struct Header {
 	const char magic[4] = {'F','T','L','F'};
-	uint8_t version = 2;
+	uint8_t version = 3;
 };
 
 /**
diff --git a/components/codecs/include/ftl/codecs/reader.hpp b/components/codecs/include/ftl/codecs/reader.hpp
index cdc50cad3..69e19f0a5 100644
--- a/components/codecs/include/ftl/codecs/reader.hpp
+++ b/components/codecs/include/ftl/codecs/reader.hpp
@@ -49,6 +49,7 @@ class Reader {
 	bool has_data_;
 	int64_t timestart_;
 	bool playing_;
+	int version_;
 
 	MUTEX mtx_;
 
diff --git a/components/codecs/src/reader.cpp b/components/codecs/src/reader.cpp
index 53225519a..3727bdd38 100644
--- a/components/codecs/src/reader.cpp
+++ b/components/codecs/src/reader.cpp
@@ -27,6 +27,8 @@ bool Reader::begin() {
 		(*stream_).read((char*)&ih, sizeof(ih));
 	}
 
+	version_ = h.version;
+
 	// Capture current time to adjust timestamps
 	timestart_ = (ftl::timer::get_time() / ftl::timer::getInterval()) * ftl::timer::getInterval();
 	playing_ = true;
@@ -86,6 +88,11 @@ bool Reader::read(int64_t ts, const std::function<void(const ftl::codecs::Stream
 		// Adjust timestamp
 		get<0>(data).timestamp += timestart_;
 
+		// Fix to clear flags for version 2.
+		if (version_ == 2) {
+			get<1>(data).flags = 0;
+		}
+
 		// TODO: Need to read ahead a few frames because there may be a
 		// smaller timestamp after this one... requires a buffer. Ideally this
 		// should be resolved during the write process.
-- 
GitLab