[x265] [PATCH] Cleanup SEI code
# HG changeset patch # User Ashok Kumar Mishra # Date 1537268644 -19800 # Tue Sep 18 16:34:04 2018 +0530 # Node ID f3c175d92ec248fc6b3388c6f70c1f3ea365d539 # Parent 6426e22f479f10a07d606119dede0da844fb5015 Cleanup SEI code diff -r 6426e22f479f -r f3c175d92ec2 source/common/param.cpp --- a/source/common/param.cpp Tue Sep 18 16:34:04 2018 +0530 +++ b/source/common/param.cpp Tue Sep 18 16:34:04 2018 +0530 @@ -1415,9 +1415,16 @@ if (param->masteringDisplayColorVolume || param->maxFALL || param->maxCLL) param->bEmitHDRSEI = 1; -bool isSingleSEI = ((param->bEmitHRDSEI || param->bEmitInfoSEI || param->decodedPictureHashSEI || - param->masteringDisplayColorVolume || param->maxCLL || param->maxFALL || - param->bEmitHDRSEI || param->bEmitIDRRecoverySEI)); +bool isSingleSEI = (param->bRepeatHeaders + || param->bEmitHRDSEI + || param->bEmitInfoSEI + || param->bEmitHDRSEI + || param->bEmitIDRRecoverySEI + || !!param->interlaceMode + || param->preferredTransferCharacteristics > 1 + || param->toneMapFile + || param->naluFile); + if (!isSingleSEI && param->bSingleSeiNal) { param->bSingleSeiNal = 0; diff -r 6426e22f479f -r f3c175d92ec2 source/encoder/encoder.cpp --- a/source/encoder/encoder.cppTue Sep 18 16:34:04 2018 +0530 +++ b/source/encoder/encoder.cppTue Sep 18 16:34:04 2018 +0530 @@ -2374,27 +2374,22 @@ sbacCoder.codePPS(m_pps, (m_param->maxSlices <= 1), m_iPPSQpMinus26); bs.writeByteAlignment(); list.serialize(NAL_UNIT_PPS, bs); + if (m_param->bSingleSeiNal) bs.resetBits(); + if (m_param->bEmitHDRSEI) { SEIContentLightLevel cllsei; cllsei.max_content_light_level = m_param->maxCLL; cllsei.max_pic_average_light_level = m_param->maxFALL; -if (!m_param->bSingleSeiNal) -bs.resetBits(); -cllsei.write(bs, m_sps); -cllsei.alignAndSerialize(bs, false, m_param->bSingleSeiNal, NAL_UNIT_PREFIX_SEI, list); +cllsei.writeSEImessages(bs, m_sps, NAL_UNIT_PREFIX_SEI, list, m_param->bSingleSeiNal); + if (m_param->masteringDisplayColorVolume) { SEIMasteringDisplayColorVolume mdsei; if (mdsei.parse(m_param->masteringDisplayColorVolume)) -{ -if (!m_param->bSingleSeiNal) -bs.resetBits(); -mdsei.write(bs, m_sps); -mdsei.alignAndSerialize(bs, false, m_param->bSingleSeiNal, NAL_UNIT_PREFIX_SEI, list); -} +mdsei.writeSEImessages(bs, m_sps, NAL_UNIT_PREFIX_SEI, list, m_param->bSingleSeiNal); else x265_log(m_param, X265_LOG_WARNING, "unable to parse mastering display color volume info\n"); } @@ -2413,13 +2408,12 @@ "Copyright 2013-2018 (c) Multicoreware, Inc - " "http://x265.org - options: %s", X265_BUILD, PFX(version_str), PFX(build_info_str), opts); -if (!m_param->bSingleSeiNal) -bs.resetBits(); + SEIuserDataUnregistered idsei; idsei.m_userData = (uint8_t*)buffer; idsei.setSize((uint32_t)strlen(buffer)); -idsei.write(bs, m_sps); -idsei.alignAndSerialize(bs, false, m_param->bSingleSeiNal, NAL_UNIT_PREFIX_SEI, list); +idsei.writeSEImessages(bs, m_sps, NAL_UNIT_PREFIX_SEI, list, m_param->bSingleSeiNal); + X265_FREE(buffer); } @@ -2433,12 +2427,7 @@ SEIActiveParameterSets sei; sei.m_selfContainedCvsFlag = true; sei.m_noParamSetUpdateFlag = true; -if (!m_param->bSingleSeiNal) -bs.resetBits(); -int payloadSize = sei.countPayloadSize(m_sps); -sei.setSize(payloadSize); -sei.write(bs, m_sps); -sei.alignAndSerialize(bs, false, m_param->bSingleSeiNal, NAL_UNIT_PREFIX_SEI, list); +sei.writeSEImessages(bs, m_sps, NAL_UNIT_PREFIX_SEI, list, m_param->bSingleSeiNal); } } @@ -2521,7 +2510,7 @@ vui.defaultDisplayWindow.bottomOffset = m_param->vui.defDispWinBottomOffset; vui.defaultDisplayWindow.leftOffset = m_param->vui.defDispWinLeftOffset; - vui.frameFieldInfoPresentFlag = !!m_param->interlaceMode || (m_param->pictureStructure >= 0); +vui.frameFieldInfoPresentFlag = !!m_param->interlaceMode || (m_param->pictureStructure >= 0); vui.fieldSeqFlag = !!m_param->interlaceMode; vui.hrdParametersPresentFlag = m_param->bEmitHRDSEI; diff -r 6426e22f479f -r f3c175d92ec2 source/encoder/frameencoder.cpp --- a/source/encoder/frameencoder.cpp Tue Sep 18 16:34:04 2018 +0530 +++ b/source/encoder/frameencoder.cpp Tue Sep 18 16:34:04 2018
[x265] [PATCH] remove duplicate code from FrameFilter
# HG changeset patch # User Ashok Kumar Mishra # Date 1537268644 -19800 # Tue Sep 18 16:34:04 2018 +0530 # Node ID 6426e22f479f10a07d606119dede0da844fb5015 # Parent 1582bba2eb394348b671c7005d965ef911a6bb40 remove duplicate code from FrameFilter diff -r 1582bba2eb39 -r 6426e22f479f source/encoder/frameencoder.cpp --- a/source/encoder/frameencoder.cpp Fri Sep 14 17:18:07 2018 +0530 +++ b/source/encoder/frameencoder.cpp Tue Sep 18 16:34:04 2018 +0530 @@ -365,6 +365,40 @@ return length; } +void FrameEncoder::writeTrailingSEIMessages() +{ +Slice* slice = m_frame->m_encData->m_slice; +int planes = (m_param->internalCsp != X265_CSP_I400) ? 3 : 1; +int32_t payloadSize = 0; + +if (m_param->decodedPictureHashSEI == 1) +{ +m_seiReconPictureDigest.m_method = SEIDecodedPictureHash::MD5; +for (int i = 0; i < planes; i++) +MD5Final(_seiReconPictureDigest.m_state[i], m_seiReconPictureDigest.m_digest[i]); +payloadSize = 1 + 16 * planes; +} +else if (m_param->decodedPictureHashSEI == 2) +{ +m_seiReconPictureDigest.m_method = SEIDecodedPictureHash::CRC; +for (int i = 0; i < planes; i++) +crcFinish(m_seiReconPictureDigest.m_crc[i], m_seiReconPictureDigest.m_digest[i]); +payloadSize = 1 + 2 * planes; +} +else if (m_param->decodedPictureHashSEI == 3) +{ +m_seiReconPictureDigest.m_method = SEIDecodedPictureHash::CHECKSUM; +for (int i = 0; i < planes; i++) +checksumFinish(m_seiReconPictureDigest.m_checksum[i], m_seiReconPictureDigest.m_digest[i]); +payloadSize = 1 + 4 * planes; +} + +m_bs.resetBits(); +m_seiReconPictureDigest.setSize(payloadSize); +m_seiReconPictureDigest.write(m_bs, *slice->m_sps); +m_seiReconPictureDigest.alignAndSerialize(m_bs, true, m_param->bSingleSeiNal, NAL_UNIT_SUFFIX_SEI, m_nalList); +} + void FrameEncoder::compressFrame() { ProfileScopeEvent(frameThread); @@ -890,71 +924,8 @@ { PicYuv *reconPic = m_frame->m_reconPic; uint32_t height = reconPic->m_picHeight; -uint32_t width = reconPic->m_picWidth; -intptr_t stride = reconPic->m_stride; -const uint32_t hChromaShift = CHROMA_H_SHIFT(m_param->internalCsp); -const uint32_t vChromaShift = CHROMA_V_SHIFT(m_param->internalCsp); - -if (m_param->decodedPictureHashSEI == 1) -{ - -MD5Init(_state[0]); - -updateMD5Plane(m_state[0], reconPic->m_picOrg[0], width, height, stride); - -if (m_param->internalCsp != X265_CSP_I400) -{ -MD5Init(_state[1]); -MD5Init(_state[2]); - -width >>= hChromaShift; -height >>= vChromaShift; -stride = reconPic->m_strideC; - -updateMD5Plane(m_state[1], reconPic->m_picOrg[1], width, height, stride); -updateMD5Plane(m_state[2], reconPic->m_picOrg[2], width, height, stride); -} -} -// TODO: NOT verify code in below mode -else if (m_param->decodedPictureHashSEI == 2) -{ -m_crc[0] = 0x; - -updateCRC(reconPic->m_picOrg[0], m_crc[0], height, width, stride); - -if (m_param->internalCsp != X265_CSP_I400) -{ -width >>= hChromaShift; -height >>= vChromaShift; -stride = reconPic->m_strideC; -m_crc[1] = m_crc[2] = 0x; - -updateCRC(reconPic->m_picOrg[1], m_crc[1], height, width, stride); -updateCRC(reconPic->m_picOrg[2], m_crc[2], height, width, stride); -} -} -else if (m_param->decodedPictureHashSEI == 3) -{ -uint32_t cuHeight = m_param->maxCUSize; - -m_checksum[0] = 0; - -updateChecksum(reconPic->m_picOrg[0], m_checksum[0], height, width, stride, 0, cuHeight); - -if (m_param->internalCsp != X265_CSP_I400) -{ -width >>= hChromaShift; -height >>= vChromaShift; -stride = reconPic->m_strideC; -cuHeight >>= vChromaShift; - -m_checksum[1] = m_checksum[2] = 0; - -updateChecksum(reconPic->m_picOrg[1], m_checksum[1], height, width, stride, 0, cuHeight); -updateChecksum(reconPic->m_picOrg[2], m_checksum[2], height, width, stride, 0, cuHeight); -} -} -} // end of (m_param->maxSlices > 1) +initDecodedPictureHashSEI(0, 0, height); +} if (m_param->bDynamicRefine && m_top->m_startPoint <= m_frame->m_encodeOrder) //Avoid collecting data that will not be used by future frames. collectDynDataFrame(); @@ -1045,8 +1016,6 @@ m_bs.resetBits(); const uint32_t sliceAddr = nextSliceRow * m_numCols; -//CUData* ctu =
[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