From 3ee7933b1399d049f25cb0f75748aba3a7cf3747 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Sat, 12 Oct 2019 08:56:06 +0300
Subject: [PATCH] Skip p-frames

---
 components/rgbd-sources/src/file_source.cpp | 17 +++++++++++++++++
 components/rgbd-sources/src/file_source.hpp |  1 +
 2 files changed, 18 insertions(+)

diff --git a/components/rgbd-sources/src/file_source.cpp b/components/rgbd-sources/src/file_source.cpp
index f5e0e7b30..33fa1ab77 100644
--- a/components/rgbd-sources/src/file_source.cpp
+++ b/components/rgbd-sources/src/file_source.cpp
@@ -34,6 +34,12 @@ FileSource::FileSource(ftl::rgbd::Source *s, ftl::codecs::Reader *r, int sid) :
 			params_ = *camera;
 			has_calibration_ = true;
 		} else {
+			if (pkt.codec == codec_t::HEVC) {
+				// Obtain NAL unit type
+				int nal_type = (pkt.data[4] >> 1) & 0x3F;
+				// A type of 32 = VPS unit, hence I-Frame in this case so skip past packets
+				if (nal_type == 32) _removeChannel(spkt.channel);
+			}
 			cache_[cache_write_].emplace_back();
 			auto &c = cache_[cache_write_].back();
 
@@ -48,6 +54,17 @@ FileSource::~FileSource() {
 
 }
 
+void FileSource::_removeChannel(int channel) {
+	int c = 0;
+	for (auto i=cache_[cache_write_].begin(); i != cache_[cache_write_].end(); ++i) {
+		if ((*i).spkt.channel == channel) {
+			++c;
+			i = cache_[cache_write_].erase(i);
+		}
+	}
+	DLOG(INFO) << "Skipped " << c << " packets";
+}
+
 bool FileSource::capture(int64_t ts) {
     timestamp_ = ts;
     return true;
diff --git a/components/rgbd-sources/src/file_source.hpp b/components/rgbd-sources/src/file_source.hpp
index 06f824884..727dc3599 100644
--- a/components/rgbd-sources/src/file_source.hpp
+++ b/components/rgbd-sources/src/file_source.hpp
@@ -41,6 +41,7 @@ class FileSource : public detail::Source {
 
 	ftl::codecs::Decoder *decoders_[2];
 
+	void _removeChannel(int channel);
 	void _createDecoder(int ix, const ftl::codecs::Packet &pkt);
 };
 
-- 
GitLab