Re: [x265] [PATCH] Encoder: separate SEI related code from encode() function
On Tue, Sep 18, 2018 at 4:34 PM wrote: > # HG changeset patch > # User Ashok Kumar Mishra > # Date 1536925687 -19800 > # Fri Sep 14 17:18:07 2018 +0530 > # Node ID 1582bba2eb394348b671c7005d965ef911a6bb40 > # Parent fa57fa584898fa3036e6748c0d7d348a9ce55b54 > Encoder: separate SEI related code from encode() function. > > diff -r fa57fa584898 -r 1582bba2eb39 source/encoder/encoder.cpp > --- a/source/encoder/encoder.cppSun Sep 09 14:57:14 2018 +0200 > +++ b/source/encoder/encoder.cppFri Sep 14 17:18:07 2018 +0530 > @@ -875,6 +875,77 @@ > } > } > > +void Encoder::copyUserSEIMessages(Frame *frame, const x265_picture* > pic_in) > +{ > +x265_sei_payload toneMap; > +toneMap.payload = NULL; > +int toneMapPayload = 0; > + > +#if ENABLE_HDR10_PLUS > +if (m_bToneMap) > +{ > +int currentPOC = m_pocLast; > +if (currentPOC < m_numCimInfo) > +{ > +int32_t i = 0; > +toneMap.payloadSize = 0; > +while (m_cim[currentPOC][i] == 0xFF) > +toneMap.payloadSize += m_cim[currentPOC][i++]; > +toneMap.payloadSize += m_cim[currentPOC][i]; > + > +toneMap.payload = (uint8_t*)x265_malloc(sizeof(uint8_t) * > toneMap.payloadSize); > +toneMap.payloadType = USER_DATA_REGISTERED_ITU_T_T35; > +memcpy(toneMap.payload, _cim[currentPOC][i + 1], > toneMap.payloadSize); > +toneMapPayload = 1; > +} > +} > +#endif > +/* seiMsg will contain SEI messages specified in a fixed file format > in POC order. > +* Format of the file : TYPE>/ */ > +x265_sei_payload seiMsg; > +seiMsg.payload = NULL; > +int userPayload = 0; > +if (m_enableNal) > +{ > +readUserSeiFile(seiMsg, m_pocLast); > +if (seiMsg.payload) > +userPayload = 1;; > +} > + > +int numPayloads = pic_in->userSEI.numPayloads + toneMapPayload + > userPayload; > +frame->m_userSEI.numPayloads = numPayloads; > + > +if (frame->m_userSEI.numPayloads) > +{ > +if (!frame->m_userSEI.payloads) > +{ > +frame->m_userSEI.payloads = new x265_sei_payload[numPayloads]; > +for (int i = 0; i < numPayloads; i++) > +frame->m_userSEI.payloads[i].payload = NULL; > +} > +for (int i = 0; i < numPayloads; i++) > +{ > +x265_sei_payload input; > +if ((i == (numPayloads - 1)) && toneMapPayload) > +input = toneMap; > +else if (m_enableNal) > +input = seiMsg; > +else > +input = pic_in->userSEI.payloads[i]; > + > +if (!frame->m_userSEI.payloads[i].payload) > +frame->m_userSEI.payloads[i].payload = new > uint8_t[input.payloadSize]; > +memcpy(frame->m_userSEI.payloads[i].payload, input.payload, > input.payloadSize); > +frame->m_userSEI.payloads[i].payloadSize = input.payloadSize; > +frame->m_userSEI.payloads[i].payloadType = input.payloadType; > +} > +if (toneMap.payload) > +x265_free(toneMap.payload); > +if (seiMsg.payload) > +x265_free(seiMsg.payload); > +} > +} > + > /** > * Feed one new input frame into the encoder, get one frame out. If > pic_in is > * NULL, a flush condition is implied and pic_in must be NULL for all > subsequent > @@ -919,32 +990,6 @@ > m_latestParam->forceFlush = 0; > } > > -x265_sei_payload toneMap; > -toneMap.payload = NULL; > -#if ENABLE_HDR10_PLUS > -if (m_bToneMap) > -{ > -int currentPOC = m_pocLast + 1; > -if (currentPOC < m_numCimInfo) > -{ > -int32_t i = 0; > -toneMap.payloadSize = 0; > -while (m_cim[currentPOC][i] == 0xFF) > -toneMap.payloadSize += m_cim[currentPOC][i++]; > -toneMap.payloadSize += m_cim[currentPOC][i]; > - > -toneMap.payload = (uint8_t*)x265_malloc(sizeof(uint8_t) * > toneMap.payloadSize); > -toneMap.payloadType = USER_DATA_REGISTERED_ITU_T_T35; > -memcpy(toneMap.payload, _cim[currentPOC][i+1], > toneMap.payloadSize); > -} > -} > -#endif > -/* seiMsg will contain SEI messages specified in a fixed file format in > POC order. > -* Format of the file : / TYPE> */ > -x265_sei_payload seiMsg; > -seiMsg.payload = NULL; > -if (m_enableNal) > -readUserSeiFile(seiMsg, m_pocLast); > if (pic_in->bitDepth < 8 || pic_in->bitDepth > 16) > { > x265_log(m_param, X265_LOG_ERROR, "Input bit depth (%d) must > be between 8 and 16\n", > @@ -1026,42 +1071,7 @@ > inFrame->m_forceqp = pic_in->forceqp; > inFrame->m_param = (m_reconfigure || m_reconfigureRc) ? > m_latestParam : m_param; > > -int toneMapEnable =
[x265] [PATCH] Encoder: separate SEI related code from encode() function
# HG changeset patch # User Ashok Kumar Mishra # Date 1536925687 -19800 # Fri Sep 14 17:18:07 2018 +0530 # Node ID 1582bba2eb394348b671c7005d965ef911a6bb40 # Parent fa57fa584898fa3036e6748c0d7d348a9ce55b54 Encoder: separate SEI related code from encode() function. diff -r fa57fa584898 -r 1582bba2eb39 source/encoder/encoder.cpp --- a/source/encoder/encoder.cppSun Sep 09 14:57:14 2018 +0200 +++ b/source/encoder/encoder.cppFri Sep 14 17:18:07 2018 +0530 @@ -875,6 +875,77 @@ } } +void Encoder::copyUserSEIMessages(Frame *frame, const x265_picture* pic_in) +{ +x265_sei_payload toneMap; +toneMap.payload = NULL; +int toneMapPayload = 0; + +#if ENABLE_HDR10_PLUS +if (m_bToneMap) +{ +int currentPOC = m_pocLast; +if (currentPOC < m_numCimInfo) +{ +int32_t i = 0; +toneMap.payloadSize = 0; +while (m_cim[currentPOC][i] == 0xFF) +toneMap.payloadSize += m_cim[currentPOC][i++]; +toneMap.payloadSize += m_cim[currentPOC][i]; + +toneMap.payload = (uint8_t*)x265_malloc(sizeof(uint8_t) * toneMap.payloadSize); +toneMap.payloadType = USER_DATA_REGISTERED_ITU_T_T35; +memcpy(toneMap.payload, _cim[currentPOC][i + 1], toneMap.payloadSize); +toneMapPayload = 1; +} +} +#endif +/* seiMsg will contain SEI messages specified in a fixed file format in POC order. +* Format of the file : / */ +x265_sei_payload seiMsg; +seiMsg.payload = NULL; +int userPayload = 0; +if (m_enableNal) +{ +readUserSeiFile(seiMsg, m_pocLast); +if (seiMsg.payload) +userPayload = 1;; +} + +int numPayloads = pic_in->userSEI.numPayloads + toneMapPayload + userPayload; +frame->m_userSEI.numPayloads = numPayloads; + +if (frame->m_userSEI.numPayloads) +{ +if (!frame->m_userSEI.payloads) +{ +frame->m_userSEI.payloads = new x265_sei_payload[numPayloads]; +for (int i = 0; i < numPayloads; i++) +frame->m_userSEI.payloads[i].payload = NULL; +} +for (int i = 0; i < numPayloads; i++) +{ +x265_sei_payload input; +if ((i == (numPayloads - 1)) && toneMapPayload) +input = toneMap; +else if (m_enableNal) +input = seiMsg; +else +input = pic_in->userSEI.payloads[i]; + +if (!frame->m_userSEI.payloads[i].payload) +frame->m_userSEI.payloads[i].payload = new uint8_t[input.payloadSize]; +memcpy(frame->m_userSEI.payloads[i].payload, input.payload, input.payloadSize); +frame->m_userSEI.payloads[i].payloadSize = input.payloadSize; +frame->m_userSEI.payloads[i].payloadType = input.payloadType; +} +if (toneMap.payload) +x265_free(toneMap.payload); +if (seiMsg.payload) +x265_free(seiMsg.payload); +} +} + /** * Feed one new input frame into the encoder, get one frame out. If pic_in is * NULL, a flush condition is implied and pic_in must be NULL for all subsequent @@ -919,32 +990,6 @@ m_latestParam->forceFlush = 0; } -x265_sei_payload toneMap; -toneMap.payload = NULL; -#if ENABLE_HDR10_PLUS -if (m_bToneMap) -{ -int currentPOC = m_pocLast + 1; -if (currentPOC < m_numCimInfo) -{ -int32_t i = 0; -toneMap.payloadSize = 0; -while (m_cim[currentPOC][i] == 0xFF) -toneMap.payloadSize += m_cim[currentPOC][i++]; -toneMap.payloadSize += m_cim[currentPOC][i]; - -toneMap.payload = (uint8_t*)x265_malloc(sizeof(uint8_t) * toneMap.payloadSize); -toneMap.payloadType = USER_DATA_REGISTERED_ITU_T_T35; -memcpy(toneMap.payload, _cim[currentPOC][i+1], toneMap.payloadSize); -} -} -#endif -/* seiMsg will contain SEI messages specified in a fixed file format in POC order. -* Format of the file : / */ -x265_sei_payload seiMsg; -seiMsg.payload = NULL; -if (m_enableNal) -readUserSeiFile(seiMsg, m_pocLast); if (pic_in->bitDepth < 8 || pic_in->bitDepth > 16) { x265_log(m_param, X265_LOG_ERROR, "Input bit depth (%d) must be between 8 and 16\n", @@ -1026,42 +1071,7 @@ inFrame->m_forceqp = pic_in->forceqp; inFrame->m_param = (m_reconfigure || m_reconfigureRc) ? m_latestParam : m_param; -int toneMapEnable = 0; -if (m_bToneMap && toneMap.payload) -toneMapEnable = 1; -int numPayloads = pic_in->userSEI.numPayloads + toneMapEnable; -if (m_enableNal && seiMsg.payload) -numPayloads += m_enableNal; -inFrame->m_userSEI.numPayloads = numPayloads; - -if