<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Tue, Sep 18, 2018 at 4:35 PM <<a href="mailto:ashok@multicorewareinc.com">ashok@multicorewareinc.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"># HG changeset patch<br>
# User Ashok Kumar Mishra <<a href="mailto:ashok@multicorewareinc.com" target="_blank">ashok@multicorewareinc.com</a>><br>
# Date 1537268644 -19800<br>
# Tue Sep 18 16:34:04 2018 +0530<br>
# Node ID 6426e22f479f10a07d606119dede0da844fb5015<br>
# Parent 1582bba2eb394348b671c7005d965ef911a6bb40<br>
remove duplicate code from FrameFilter<br>
<br>
diff -r 1582bba2eb39 -r 6426e22f479f source/encoder/frameencoder.cpp<br>
--- a/source/encoder/frameencoder.cpp Fri Sep 14 17:18:07 2018 +0530<br>
+++ b/source/encoder/frameencoder.cpp Tue Sep 18 16:34:04 2018 +0530<br>
@@ -365,6 +365,40 @@<br>
return length;<br>
}<br>
<br>
+void FrameEncoder::writeTrailingSEIMessages()<br>
+{<br>
+ Slice* slice = m_frame->m_encData->m_slice;<br>
+ int planes = (m_param->internalCsp != X265_CSP_I400) ? 3 : 1;<br>
+ int32_t payloadSize = 0;<br>
+<br>
+ if (m_param->decodedPictureHashSEI == 1)<br>
+ {<br>
+ m_seiReconPictureDigest.m_method = SEIDecodedPictureHash::MD5;<br>
+ for (int i = 0; i < planes; i++)<br>
+ MD5Final(&m_seiReconPictureDigest.m_state[i], m_seiReconPictureDigest.m_digest[i]);<br>
+ payloadSize = 1 + 16 * planes;<br>
+ }<br>
+ else if (m_param->decodedPictureHashSEI == 2)<br>
+ {<br>
+ m_seiReconPictureDigest.m_method = SEIDecodedPictureHash::CRC;<br>
+ for (int i = 0; i < planes; i++)<br>
+ crcFinish(m_seiReconPictureDigest.m_crc[i], m_seiReconPictureDigest.m_digest[i]);<br>
+ payloadSize = 1 + 2 * planes;<br>
+ }<br>
+ else if (m_param->decodedPictureHashSEI == 3)<br>
+ {<br>
+ m_seiReconPictureDigest.m_method = SEIDecodedPictureHash::CHECKSUM;<br>
+ for (int i = 0; i < planes; i++)<br>
+ checksumFinish(m_seiReconPictureDigest.m_checksum[i], m_seiReconPictureDigest.m_digest[i]);<br>
+ payloadSize = 1 + 4 * planes;<br>
+ }<br>
+<br>
+ m_bs.resetBits();<br>
+ m_seiReconPictureDigest.setSize(payloadSize);<br>
+ m_seiReconPictureDigest.write(m_bs, *slice->m_sps);<br>
+ m_seiReconPictureDigest.alignAndSerialize(m_bs, true, m_param->bSingleSeiNal, NAL_UNIT_SUFFIX_SEI, m_nalList);<br>
+}<br>
+<br>
void FrameEncoder::compressFrame()<br>
{<br>
ProfileScopeEvent(frameThread);<br>
@@ -890,71 +924,8 @@<br>
{<br>
PicYuv *reconPic = m_frame->m_reconPic;<br>
uint32_t height = reconPic->m_picHeight;<br>
- uint32_t width = reconPic->m_picWidth;<br>
- intptr_t stride = reconPic->m_stride;<br>
- const uint32_t hChromaShift = CHROMA_H_SHIFT(m_param->internalCsp);<br>
- const uint32_t vChromaShift = CHROMA_V_SHIFT(m_param->internalCsp);<br>
-<br>
- if (m_param->decodedPictureHashSEI == 1)<br>
- {<br>
-<br>
- MD5Init(&m_state[0]);<br>
-<br>
- updateMD5Plane(m_state[0], reconPic->m_picOrg[0], width, height, stride);<br>
-<br>
- if (m_param->internalCsp != X265_CSP_I400)<br>
- {<br>
- MD5Init(&m_state[1]);<br>
- MD5Init(&m_state[2]);<br>
-<br>
- width >>= hChromaShift;<br>
- height >>= vChromaShift;<br>
- stride = reconPic->m_strideC;<br>
-<br>
- updateMD5Plane(m_state[1], reconPic->m_picOrg[1], width, height, stride);<br>
- updateMD5Plane(m_state[2], reconPic->m_picOrg[2], width, height, stride);<br>
- }<br>
- }<br>
- // TODO: NOT verify code in below mode<br>
- else if (m_param->decodedPictureHashSEI == 2)<br>
- {<br>
- m_crc[0] = 0xffff;<br>
-<br>
- updateCRC(reconPic->m_picOrg[0], m_crc[0], height, width, stride);<br>
-<br>
- if (m_param->internalCsp != X265_CSP_I400)<br>
- {<br>
- width >>= hChromaShift;<br>
- height >>= vChromaShift;<br>
- stride = reconPic->m_strideC;<br>
- m_crc[1] = m_crc[2] = 0xffff;<br>
-<br>
- updateCRC(reconPic->m_picOrg[1], m_crc[1], height, width, stride);<br>
- updateCRC(reconPic->m_picOrg[2], m_crc[2], height, width, stride);<br>
- }<br>
- }<br>
- else if (m_param->decodedPictureHashSEI == 3)<br>
- {<br>
- uint32_t cuHeight = m_param->maxCUSize;<br>
-<br>
- m_checksum[0] = 0;<br>
-<br>
- updateChecksum(reconPic->m_picOrg[0], m_checksum[0], height, width, stride, 0, cuHeight);<br>
-<br>
- if (m_param->internalCsp != X265_CSP_I400)<br>
- {<br>
- width >>= hChromaShift;<br>
- height >>= vChromaShift;<br>
- stride = reconPic->m_strideC;<br>
- cuHeight >>= vChromaShift;<br>
-<br>
- m_checksum[1] = m_checksum[2] = 0;<br>
-<br>
- updateChecksum(reconPic->m_picOrg[1], m_checksum[1], height, width, stride, 0, cuHeight);<br>
- updateChecksum(reconPic->m_picOrg[2], m_checksum[2], height, width, stride, 0, cuHeight);<br>
- }<br>
- } <br>
- } // end of (m_param->maxSlices > 1)<br>
+ initDecodedPictureHashSEI(0, 0, height);<br>
+ } <br>
<br>
if (m_param->bDynamicRefine && m_top->m_startPoint <= m_frame->m_encodeOrder) //Avoid collecting data that will not be used by future frames.<br>
collectDynDataFrame();<br>
@@ -1045,8 +1016,6 @@<br>
m_bs.resetBits();<br>
<br>
const uint32_t sliceAddr = nextSliceRow * m_numCols;<br>
- //CUData* ctu = m_frame->m_encData->getPicCTU(sliceAddr);<br>
- //const int sliceQp = ctu->m_qp[0];<br>
if (m_param->bOptRefListLengthPPS)<br>
{<br>
ScopedLock refIdxLock(m_top->m_sliceRefIdxLock);<br>
@@ -1095,36 +1064,8 @@<br>
if (isSei && m_param->bSingleSeiNal)<br>
m_bs.resetBits();<br>
<br>
- if (m_param->decodedPictureHashSEI)<br>
- {<br>
- int planes = (m_frame->m_param->internalCsp != X265_CSP_I400) ? 3 : 1;<br>
- int32_t payloadSize = 0;<br>
- if (m_param->decodedPictureHashSEI == 1)<br>
- {<br>
- m_seiReconPictureDigest.m_method = SEIDecodedPictureHash::MD5;<br>
- for (int i = 0; i < planes; i++)<br>
- MD5Final(&m_state[i], m_seiReconPictureDigest.m_digest[i]);<br>
- payloadSize = 1 + 16 * planes;<br>
- }<br>
- else if (m_param->decodedPictureHashSEI == 2)<br>
- {<br>
- m_seiReconPictureDigest.m_method = SEIDecodedPictureHash::CRC;<br>
- for (int i = 0; i < planes; i++)<br>
- crcFinish(m_crc[i], m_seiReconPictureDigest.m_digest[i]);<br>
- payloadSize = 1 + 2 * planes;<br>
- }<br>
- else if (m_param->decodedPictureHashSEI == 3)<br>
- {<br>
- m_seiReconPictureDigest.m_method = SEIDecodedPictureHash::CHECKSUM;<br>
- for (int i = 0; i < planes; i++)<br>
- checksumFinish(m_checksum[i], m_seiReconPictureDigest.m_digest[i]);<br>
- payloadSize = 1 + 4 * planes;<br>
- }<br>
- m_bs.resetBits();<br>
- m_seiReconPictureDigest.setSize(payloadSize);<br>
- m_seiReconPictureDigest.write(m_bs, *slice->m_sps);<br>
- m_seiReconPictureDigest.alignAndSerialize(m_bs, true, m_param->bSingleSeiNal, NAL_UNIT_SUFFIX_SEI, m_nalList);<br>
- }<br>
+ if (m_param->decodedPictureHashSEI) <br>
+ writeTrailingSEIMessages();<br>
<br>
uint64_t bytes = 0;<br>
for (uint32_t i = 0; i < m_nalList.m_numNal; i++)<br>
@@ -1216,6 +1157,78 @@<br>
m_endFrameTime = x265_mdate(); <br>
}<br>
<br>
+void FrameEncoder::initDecodedPictureHashSEI(int row, int cuAddr, int height)<br>
+{<br>
+ PicYuv *reconPic = m_frame->m_reconPic;<br>
+ uint32_t width = reconPic->m_picWidth; <br>
+ intptr_t stride = reconPic->m_stride;<br>
+ uint32_t maxCUHeight = m_param->maxCUSize;<br>
+<br>
+ const uint32_t hChromaShift = CHROMA_H_SHIFT(m_param->internalCsp);<br>
+ const uint32_t vChromaShift = CHROMA_V_SHIFT(m_param->internalCsp);<br>
+<br>
+ if (m_param->decodedPictureHashSEI == 1)<br>
+ {<br>
+ if (!row)<br>
+ MD5Init(&m_seiReconPictureDigest.m_state[0]);<br>
+<br>
+ updateMD5Plane(m_seiReconPictureDigest.m_state[0], reconPic->getLumaAddr(cuAddr), width, height, stride);<br>
+ if (m_param->internalCsp != X265_CSP_I400)<br>
+ {<br>
+ if (!row)<br>
+ {<br>
+ MD5Init(&m_seiReconPictureDigest.m_state[1]);<br>
+ MD5Init(&m_seiReconPictureDigest.m_state[2]);<br>
+ }<br>
+<br>
+ width >>= hChromaShift;<br>
+ height >>= vChromaShift;<br>
+ stride = reconPic->m_strideC;<br>
+<br>
+ updateMD5Plane(m_seiReconPictureDigest.m_state[1], reconPic->getCbAddr(cuAddr), width, height, stride);<br>
+ updateMD5Plane(m_seiReconPictureDigest.m_state[2], reconPic->getCrAddr(cuAddr), width, height, stride);<br>
+ }<br>
+ }<br>
+ else if (m_param->decodedPictureHashSEI == 2)<br>
+ {<br>
+<br>
+ if (!row)<br>
+ m_seiReconPictureDigest.m_crc[0] = 0xffff;<br>
+<br>
+ updateCRC(reconPic->getLumaAddr(cuAddr), m_seiReconPictureDigest.m_crc[0], height, width, stride);<br>
+ if (m_param->internalCsp != X265_CSP_I400)<br>
+ {<br>
+ width >>= hChromaShift;<br>
+ height >>= vChromaShift;<br>
+ stride = reconPic->m_strideC;<br>
+ m_seiReconPictureDigest.m_crc[1] = m_seiReconPictureDigest.m_crc[2] = 0xffff;<br>
+<br>
+ updateCRC(reconPic->getCbAddr(cuAddr), m_seiReconPictureDigest.m_crc[1], height, width, stride);<br>
+ updateCRC(reconPic->getCrAddr(cuAddr), m_seiReconPictureDigest.m_crc[2], height, width, stride);<br>
+ }<br>
+ }<br>
+ else if (m_param->decodedPictureHashSEI == 3)<br>
+ {<br>
+ if (!row)<br>
+ m_seiReconPictureDigest.m_checksum[0] = 0;<br>
+<br>
+ updateChecksum(reconPic->m_picOrg[0], m_seiReconPictureDigest.m_checksum[0], height, width, stride, row, maxCUHeight);<br>
+ if (m_param->internalCsp != X265_CSP_I400)<br>
+ {<br>
+ width >>= hChromaShift;<br>
+ height >>= vChromaShift;<br>
+ stride = reconPic->m_strideC;<br>
+ maxCUHeight >>= vChromaShift;<br>
+<br>
+ if (!row)<br>
+ m_seiReconPictureDigest.m_checksum[1] = m_seiReconPictureDigest.m_checksum[2] = 0;<br>
+<br>
+ updateChecksum(reconPic->m_picOrg[1], m_seiReconPictureDigest.m_checksum[1], height, width, stride, row, maxCUHeight);<br>
+ updateChecksum(reconPic->m_picOrg[2], m_seiReconPictureDigest.m_checksum[2], height, width, stride, row, maxCUHeight);<br>
+ }<br>
+ }<br>
+}<br>
+<br>
void FrameEncoder::encodeSlice(uint32_t sliceAddr)<br>
{<br>
Slice* slice = m_frame->m_encData->m_slice;<br>
diff -r 1582bba2eb39 -r 6426e22f479f source/encoder/frameencoder.h<br>
--- a/source/encoder/frameencoder.h Fri Sep 14 17:18:07 2018 +0530<br>
+++ b/source/encoder/frameencoder.h Tue Sep 18 16:34:04 2018 +0530<br>
@@ -129,6 +129,8 @@<br>
/* blocks until worker thread is done, returns access unit */<br>
Frame *getEncodedPicture(NALList& list);<br>
<br>
+ void initDecodedPictureHashSEI(int row, int cuAddr, int height);<br>
+<br>
Event m_enable;<br>
Event m_done;<br>
Event m_completionEvent;<br>
@@ -161,9 +163,6 @@<br>
double m_ssim;<br>
uint64_t m_accessUnitBits;<br>
uint32_t m_ssimCnt;<br>
- MD5Context m_state[3];<br>
- uint32_t m_crc[3];<br>
- uint32_t m_checksum[3];<br>
<br>
volatile int m_activeWorkerCount; // count of workers currently encoding or filtering CTUs<br>
volatile int m_totalActiveWorkerCount; // sum of m_activeWorkerCount sampled at end of each CTU<br>
@@ -230,7 +229,7 @@<br>
void threadMain();<br>
int collectCTUStatistics(const CUData& ctu, FrameStats* frameLog);<br>
void noiseReductionUpdate();<br>
- void computeAvgTrainingData();<br>
+ void writeTrailingSEIMessages();<br>
<br>
/* Called by WaveFront::findJob() */<br>
virtual void processRow(int row, int threadId);<br>
@@ -243,8 +242,9 @@<br>
#if ENABLE_LIBVMAF<br>
void vmafFrameLevelScore();<br>
#endif<br>
- void collectDynDataRow(CUData& ctu, FrameStats* rowStats);<br>
void collectDynDataFrame();<br>
+ void computeAvgTrainingData();<br>
+ void collectDynDataRow(CUData& ctu, FrameStats* rowStats); <br>
};<br>
}<br>
<br>
diff -r 1582bba2eb39 -r 6426e22f479f source/encoder/framefilter.cpp<br>
--- a/source/encoder/framefilter.cpp Fri Sep 14 17:18:07 2018 +0530<br>
+++ b/source/encoder/framefilter.cpp Tue Sep 18 16:34:04 2018 +0530<br>
@@ -712,78 +712,8 @@<br>
<br>
if (m_param->maxSlices == 1)<br>
{<br>
- if (m_param->decodedPictureHashSEI == 1)<br>
- {<br>
- uint32_t height = m_parallelFilter[row].getCUHeight();<br>
- uint32_t width = reconPic->m_picWidth;<br>
- intptr_t stride = reconPic->m_stride;<br>
-<br>
- if (!row)<br>
- MD5Init(&m_frameEncoder->m_state[0]);<br>
-<br>
- updateMD5Plane(m_frameEncoder->m_state[0], reconPic->getLumaAddr(cuAddr), width, height, stride);<br>
- if (m_param->internalCsp != X265_CSP_I400)<br>
- {<br>
- if (!row)<br>
- {<br>
- MD5Init(&m_frameEncoder->m_state[1]);<br>
- MD5Init(&m_frameEncoder->m_state[2]);<br>
- }<br>
-<br>
- width >>= m_hChromaShift;<br>
- height >>= m_vChromaShift;<br>
- stride = reconPic->m_strideC;<br>
-<br>
- updateMD5Plane(m_frameEncoder->m_state[1], reconPic->getCbAddr(cuAddr), width, height, stride);<br>
- updateMD5Plane(m_frameEncoder->m_state[2], reconPic->getCrAddr(cuAddr), width, height, stride);<br>
- }<br>
- }<br>
- else if (m_param->decodedPictureHashSEI == 2)<br>
- {<br>
- uint32_t height = m_parallelFilter[row].getCUHeight();<br>
- uint32_t width = reconPic->m_picWidth;<br>
- intptr_t stride = reconPic->m_stride;<br>
-<br>
- if (!row)<br>
- m_frameEncoder->m_crc[0] = 0xffff;<br>
-<br>
- updateCRC(reconPic->getLumaAddr(cuAddr), m_frameEncoder->m_crc[0], height, width, stride);<br>
- if (m_param->internalCsp != X265_CSP_I400)<br>
- {<br>
- width >>= m_hChromaShift;<br>
- height >>= m_vChromaShift;<br>
- stride = reconPic->m_strideC;<br>
- m_frameEncoder->m_crc[1] = m_frameEncoder->m_crc[2] = 0xffff;<br>
-<br>
- updateCRC(reconPic->getCbAddr(cuAddr), m_frameEncoder->m_crc[1], height, width, stride);<br>
- updateCRC(reconPic->getCrAddr(cuAddr), m_frameEncoder->m_crc[2], height, width, stride);<br>
- }<br>
- }<br>
- else if (m_param->decodedPictureHashSEI == 3)<br>
- {<br>
- uint32_t width = reconPic->m_picWidth;<br>
- uint32_t height = m_parallelFilter[row].getCUHeight();<br>
- intptr_t stride = reconPic->m_stride;<br>
- uint32_t cuHeight = m_param->maxCUSize;<br>
-<br>
- if (!row)<br>
- m_frameEncoder->m_checksum[0] = 0;<br>
-<br>
- updateChecksum(reconPic->m_picOrg[0], m_frameEncoder->m_checksum[0], height, width, stride, row, cuHeight);<br>
- if (m_param->internalCsp != X265_CSP_I400)<br>
- {<br>
- width >>= m_hChromaShift;<br>
- height >>= m_vChromaShift;<br>
- stride = reconPic->m_strideC;<br>
- cuHeight >>= m_vChromaShift;<br>
-<br>
- if (!row)<br>
- m_frameEncoder->m_checksum[1] = m_frameEncoder->m_checksum[2] = 0;<br>
-<br>
- updateChecksum(reconPic->m_picOrg[1], m_frameEncoder->m_checksum[1], height, width, stride, row, cuHeight);<br>
- updateChecksum(reconPic->m_picOrg[2], m_frameEncoder->m_checksum[2], height, width, stride, row, cuHeight);<br>
- }<br>
- }<br>
+ uint32_t height = m_parallelFilter[row].getCUHeight();<br>
+ m_frameEncoder->initDecodedPictureHashSEI(row, cuAddr, height);<br>
} // end of (m_param->maxSlices == 1)<br>
<br>
if (ATOMIC_INC(&m_frameEncoder->m_completionCount) == 2 * (int)m_frameEncoder->m_numRows)<br>
diff -r 1582bba2eb39 -r 6426e22f479f source/encoder/sei.h<br>
--- a/source/encoder/sei.h Fri Sep 14 17:18:07 2018 +0530<br>
+++ b/source/encoder/sei.h Tue Sep 18 16:34:04 2018 +0530<br>
@@ -28,6 +28,7 @@<br>
#include "bitstream.h"<br>
#include "slice.h"<br>
#include "nal.h"<br>
+#include "md5.h"<br>
<br>
namespace X265_NS {<br>
// private namespace<br>
@@ -136,7 +137,12 @@<br>
CRC,<br>
CHECKSUM,<br>
} m_method;<br>
- uint8_t m_digest[3][16];<br>
+<br>
+ MD5Context m_state[3];<br>
+ uint32_t m_crc[3];<br>
+ uint32_t m_checksum[3];<br>
+ uint8_t m_digest[3][16];<br>
+<br>
void writeSEI(const SPS& sps)<br>
{<br>
int planes = (sps.chromaFormatIdc != X265_CSP_I400) ? 3 : 1;<br></blockquote><div><br></div><div>Pushed to default. </div></div></div>