From 3ec9d23e57db758f8ad35f7a38e81ca04c9d2ecb Mon Sep 17 00:00:00 2001
From: Brian Heng <brian.heng@broadcom.com>
Date: Thu, 12 Nov 2020 12:10:31 -0800
Subject: [PATCH] Fix decoded picture hash SEI message syntax

   - See ticket #1405
---
 source/Lib/CommonLib/SEI.h           | 1 +
 source/Lib/DecoderLib/SEIread.cpp    | 4 ++++
 source/Lib/EncoderLib/SEIEncoder.cpp | 1 +
 source/Lib/EncoderLib/SEIwrite.cpp   | 2 ++
 4 files changed, 8 insertions(+)

diff --git a/source/Lib/CommonLib/SEI.h b/source/Lib/CommonLib/SEI.h
index a77a94e2b..0c5944e0b 100644
--- a/source/Lib/CommonLib/SEI.h
+++ b/source/Lib/CommonLib/SEI.h
@@ -244,6 +244,7 @@ public:
   virtual ~SEIDecodedPictureHash() {}
 
   HashType method;
+  bool     singleCompFlag;
 
   PictureHash m_pictureHash;
 };
diff --git a/source/Lib/DecoderLib/SEIread.cpp b/source/Lib/DecoderLib/SEIread.cpp
index a5df827f2..b4f80914d 100644
--- a/source/Lib/DecoderLib/SEIread.cpp
+++ b/source/Lib/DecoderLib/SEIread.cpp
@@ -440,6 +440,10 @@ void SEIReader::xParseSEIDecodedPictureHash(SEIDecodedPictureHash& sei, uint32_t
   uint32_t val;
   sei_read_code( pDecodedMessageOutputStream, 8, val, "dph_sei_hash_type");
   sei.method = static_cast<HashType>(val); bytesRead++;
+  sei_read_code( pDecodedMessageOutputStream, 1, val, "dph_sei_single_component_flag");
+  sei.singleCompFlag = val;
+  sei_read_code( pDecodedMessageOutputStream, 7, val, "dph_sei_reserved_zero_7bits");
+  bytesRead++;
 
   const char *traceString="\0";
   switch (sei.method)
diff --git a/source/Lib/EncoderLib/SEIEncoder.cpp b/source/Lib/EncoderLib/SEIEncoder.cpp
index a9ecad7ca..f3011b7a8 100644
--- a/source/Lib/EncoderLib/SEIEncoder.cpp
+++ b/source/Lib/EncoderLib/SEIEncoder.cpp
@@ -460,6 +460,7 @@ void SEIEncoder::initDecodedPictureHashSEI(SEIDecodedPictureHash *decodedPicture
   CHECK(!(decodedPictureHashSEI!=NULL), "Unspecified error");
 
   decodedPictureHashSEI->method = m_pcCfg->getDecodedPictureHashSEIType();
+  decodedPictureHashSEI->singleCompFlag = (m_pcCfg->getChromaFormatIdc() == 0);
   switch (m_pcCfg->getDecodedPictureHashSEIType())
   {
     case HASHTYPE_MD5:
diff --git a/source/Lib/EncoderLib/SEIwrite.cpp b/source/Lib/EncoderLib/SEIwrite.cpp
index d8e7f9065..03dbe98af 100644
--- a/source/Lib/EncoderLib/SEIwrite.cpp
+++ b/source/Lib/EncoderLib/SEIwrite.cpp
@@ -228,6 +228,8 @@ void SEIWriter::xWriteSEIDecodedPictureHash(const SEIDecodedPictureHash& sei)
   if (traceString != 0) //use of this variable is needed to avoid a compiler error with G++ 4.6.1
   {
     WRITE_CODE(sei.method, 8, "dph_sei_hash_type");
+    WRITE_CODE(sei.singleCompFlag, 1, "dph_sei_single_component_flag");
+    WRITE_CODE(0, 7, "dph_sei_reserved_zero_7bits");
     for(uint32_t i=0; i<uint32_t(sei.m_pictureHash.hash.size()); i++)
     {
       WRITE_CODE(sei.m_pictureHash.hash[i], 8, traceString);
-- 
GitLab