<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Tue, Sep 18, 2018 at 4:34 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 1536925687 -19800<br>
# Fri Sep 14 17:18:07 2018 +0530<br>
# Node ID 1582bba2eb394348b671c7005d965ef911a6bb40<br>
# Parent fa57fa584898fa3036e6748c0d7d348a9ce55b54<br>
Encoder: separate SEI related code from encode() function.<br>
<br>
diff -r fa57fa584898 -r 1582bba2eb39 source/encoder/encoder.cpp<br>
--- a/source/encoder/encoder.cpp Sun Sep 09 14:57:14 2018 +0200<br>
+++ b/source/encoder/encoder.cpp Fri Sep 14 17:18:07 2018 +0530<br>
@@ -875,6 +875,77 @@<br>
}<br>
}<br>
<br>
+void Encoder::copyUserSEIMessages(Frame *frame, const x265_picture* pic_in)<br>
+{<br>
+ x265_sei_payload toneMap;<br>
+ toneMap.payload = NULL;<br>
+ int toneMapPayload = 0;<br>
+<br>
+#if ENABLE_HDR10_PLUS<br>
+ if (m_bToneMap)<br>
+ {<br>
+ int currentPOC = m_pocLast;<br>
+ if (currentPOC < m_numCimInfo)<br>
+ {<br>
+ int32_t i = 0;<br>
+ toneMap.payloadSize = 0;<br>
+ while (m_cim[currentPOC][i] == 0xFF)<br>
+ toneMap.payloadSize += m_cim[currentPOC][i++];<br>
+ toneMap.payloadSize += m_cim[currentPOC][i];<br>
+<br>
+ toneMap.payload = (uint8_t*)x265_malloc(sizeof(uint8_t) * toneMap.payloadSize);<br>
+ toneMap.payloadType = USER_DATA_REGISTERED_ITU_T_T35;<br>
+ memcpy(toneMap.payload, &m_cim[currentPOC][i + 1], toneMap.payloadSize);<br>
+ toneMapPayload = 1;<br>
+ }<br>
+ }<br>
+#endif<br>
+ /* seiMsg will contain SEI messages specified in a fixed file format in POC order.<br>
+ * Format of the file : <POC><space><PREFIX><space><NAL UNIT TYPE>/<SEI TYPE><space><SEI Payload> */<br>
+ x265_sei_payload seiMsg;<br>
+ seiMsg.payload = NULL;<br>
+ int userPayload = 0;<br>
+ if (m_enableNal)<br>
+ {<br>
+ readUserSeiFile(seiMsg, m_pocLast);<br>
+ if (seiMsg.payload)<br>
+ userPayload = 1;;<br>
+ }<br>
+<br>
+ int numPayloads = pic_in->userSEI.numPayloads + toneMapPayload + userPayload;<br>
+ frame->m_userSEI.numPayloads = numPayloads;<br>
+<br>
+ if (frame->m_userSEI.numPayloads)<br>
+ {<br>
+ if (!frame->m_userSEI.payloads)<br>
+ {<br>
+ frame->m_userSEI.payloads = new x265_sei_payload[numPayloads];<br>
+ for (int i = 0; i < numPayloads; i++)<br>
+ frame->m_userSEI.payloads[i].payload = NULL;<br>
+ }<br>
+ for (int i = 0; i < numPayloads; i++)<br>
+ {<br>
+ x265_sei_payload input;<br>
+ if ((i == (numPayloads - 1)) && toneMapPayload)<br>
+ input = toneMap;<br>
+ else if (m_enableNal)<br>
+ input = seiMsg;<br>
+ else<br>
+ input = pic_in->userSEI.payloads[i];<br>
+<br>
+ if (!frame->m_userSEI.payloads[i].payload)<br>
+ frame->m_userSEI.payloads[i].payload = new uint8_t[input.payloadSize];<br>
+ memcpy(frame->m_userSEI.payloads[i].payload, input.payload, input.payloadSize);<br>
+ frame->m_userSEI.payloads[i].payloadSize = input.payloadSize;<br>
+ frame->m_userSEI.payloads[i].payloadType = input.payloadType;<br>
+ }<br>
+ if (toneMap.payload)<br>
+ x265_free(toneMap.payload);<br>
+ if (seiMsg.payload)<br>
+ x265_free(seiMsg.payload);<br>
+ }<br>
+}<br>
+<br>
/**<br>
* Feed one new input frame into the encoder, get one frame out. If pic_in is<br>
* NULL, a flush condition is implied and pic_in must be NULL for all subsequent<br>
@@ -919,32 +990,6 @@<br>
m_latestParam->forceFlush = 0;<br>
}<br>
<br>
- x265_sei_payload toneMap;<br>
- toneMap.payload = NULL;<br>
-#if ENABLE_HDR10_PLUS<br>
- if (m_bToneMap)<br>
- {<br>
- int currentPOC = m_pocLast + 1;<br>
- if (currentPOC < m_numCimInfo)<br>
- {<br>
- int32_t i = 0;<br>
- toneMap.payloadSize = 0;<br>
- while (m_cim[currentPOC][i] == 0xFF)<br>
- toneMap.payloadSize += m_cim[currentPOC][i++];<br>
- toneMap.payloadSize += m_cim[currentPOC][i];<br>
-<br>
- toneMap.payload = (uint8_t*)x265_malloc(sizeof(uint8_t) * toneMap.payloadSize);<br>
- toneMap.payloadType = USER_DATA_REGISTERED_ITU_T_T35;<br>
- memcpy(toneMap.payload, &m_cim[currentPOC][i+1], toneMap.payloadSize);<br>
- }<br>
- }<br>
-#endif<br>
-/* seiMsg will contain SEI messages specified in a fixed file format in POC order.<br>
-* Format of the file : <POC><space><PREFIX><space><NAL UNIT TYPE>/<SEI TYPE><space><SEI Payload> */<br>
- x265_sei_payload seiMsg;<br>
- seiMsg.payload = NULL;<br>
- if (m_enableNal)<br>
- readUserSeiFile(seiMsg, m_pocLast);<br>
if (pic_in->bitDepth < 8 || pic_in->bitDepth > 16)<br>
{<br>
x265_log(m_param, X265_LOG_ERROR, "Input bit depth (%d) must be between 8 and 16\n",<br>
@@ -1026,42 +1071,7 @@<br>
inFrame->m_forceqp = pic_in->forceqp;<br>
inFrame->m_param = (m_reconfigure || m_reconfigureRc) ? m_latestParam : m_param;<br>
<br>
- int toneMapEnable = 0;<br>
- if (m_bToneMap && toneMap.payload)<br>
- toneMapEnable = 1;<br>
- int numPayloads = pic_in->userSEI.numPayloads + toneMapEnable;<br>
- if (m_enableNal && seiMsg.payload)<br>
- numPayloads += m_enableNal;<br>
- inFrame->m_userSEI.numPayloads = numPayloads;<br>
-<br>
- if (inFrame->m_userSEI.numPayloads)<br>
- {<br>
- if (!inFrame->m_userSEI.payloads)<br>
- {<br>
- inFrame->m_userSEI.payloads = new x265_sei_payload[numPayloads];<br>
- for (int i = 0; i < numPayloads; i++)<br>
- inFrame->m_userSEI.payloads[i].payload = NULL;<br>
- }<br>
- for (int i = 0; i < numPayloads; i++)<br>
- {<br>
- x265_sei_payload input;<br>
- if ((i == (numPayloads - 1)) && toneMapEnable)<br>
- input = toneMap;<br>
- else if (m_enableNal)<br>
- input = seiMsg;<br>
- else<br>
- input = pic_in->userSEI.payloads[i];<br>
- int size = inFrame->m_userSEI.payloads[i].payloadSize = input.payloadSize;<br>
- inFrame->m_userSEI.payloads[i].payloadType = input.payloadType;<br>
- if (!inFrame->m_userSEI.payloads[i].payload)<br>
- inFrame->m_userSEI.payloads[i].payload = new uint8_t[size];<br>
- memcpy(inFrame->m_userSEI.payloads[i].payload, input.payload, size);<br>
- }<br>
- if (toneMap.payload)<br>
- x265_free(toneMap.payload);<br>
- if (seiMsg.payload)<br>
- x265_free(seiMsg.payload);<br>
- }<br>
+ copyUserSEIMessages(inFrame, pic_in);<br>
<br>
if (pic_in->quantOffsets != NULL)<br>
{<br>
@@ -4524,7 +4534,7 @@<br>
char *base64Decode = SEI::base64Decode(base64Encode, base64EncodeLength);<br>
if (nalType == NAL_UNIT_PREFIX_SEI && (!strcmp(prefix, "PREFIX")))<br>
{<br>
- int currentPOC = curPoc + 1;<br>
+ int currentPOC = curPoc;<br>
if (currentPOC == poc)<br>
{<br>
seiMsg.payloadSize = (base64EncodeLength / 4) * 3;<br>
diff -r fa57fa584898 -r 1582bba2eb39 source/encoder/encoder.h<br>
--- a/source/encoder/encoder.h Sun Sep 09 14:57:14 2018 +0200<br>
+++ b/source/encoder/encoder.h Fri Sep 14 17:18:07 2018 +0530<br>
@@ -302,6 +302,8 @@<br>
void updateRefIdx();<br>
bool computeSPSRPSIndex();<br>
<br>
+ void copyUserSEIMessages(Frame *frame, const x265_picture* pic_in);<br>
+<br>
protected:<br>
<br>
void initVPS(VPS *vps);<br></blockquote><div><br></div><div>Pushed to default. </div></div></div>