[x265-commits] [x265] Encoder: separate SEI related code from encode() function.

Ashok Kumar Mishra ashok at multicorewareinc.com
Wed Sep 26 01:03:03 CEST 2018


details:   http://hg.videolan.org/x265/rev/8fa8bacacb68
branches:  
changeset: 12419:8fa8bacacb68
user:      Ashok Kumar Mishra <ashok at multicorewareinc.com>
date:      Fri Sep 14 17:18:07 2018 +0530
description:
Encoder: separate SEI related code from encode() function.
Subject: [x265] remove duplicate code from FrameFilter

details:   http://hg.videolan.org/x265/rev/44240f1a545a
branches:  
changeset: 12420:44240f1a545a
user:      Ashok Kumar Mishra <ashok at multicorewareinc.com>
date:      Tue Sep 18 16:34:04 2018 +0530
description:
remove duplicate code from FrameFilter
Subject: [x265] Cleanup SEI code

details:   http://hg.videolan.org/x265/rev/bbad4e55b51a
branches:  
changeset: 12421:bbad4e55b51a
user:      Ashok Kumar Mishra <ashok at multicorewareinc.com>
date:      Tue Sep 18 16:34:04 2018 +0530
description:
Cleanup SEI code
Subject: [x265] FrameEncoder: Fix for building error

details:   http://hg.videolan.org/x265/rev/ea2990bc9776
branches:  
changeset: 12422:ea2990bc9776
user:      Ashok Kumar Mishra <ashok at multicorewareinc.com>
date:      Tue Sep 25 18:26:36 2018 +0530
description:
FrameEncoder: Fix for building error
Subject: [x265] Cleanup

details:   http://hg.videolan.org/x265/rev/fd517ae68f93
branches:  
changeset: 12423:fd517ae68f93
user:      Ashok Kumar Mishra <ashok at multicorewareinc.com>
date:      Tue Sep 25 16:02:31 2018 +0530
description:
Cleanup

diffstat:

 source/common/frame.cpp         |    9 +-
 source/common/lowres.cpp        |   12 +-
 source/common/lowres.h          |    4 +-
 source/common/param.cpp         |   13 +-
 source/encoder/analysis.cpp     |   37 +--
 source/encoder/encoder.cpp      |  167 ++++++++++----------
 source/encoder/encoder.h        |    2 +
 source/encoder/frameencoder.cpp |  325 ++++++++++++++++++---------------------
 source/encoder/frameencoder.h   |   11 +-
 source/encoder/framefilter.cpp  |   74 +--------
 source/encoder/ratecontrol.cpp  |    8 +-
 source/encoder/sei.cpp          |   54 +++---
 source/encoder/sei.h            |   88 +++++-----
 source/encoder/slicetype.cpp    |   59 ++----
 14 files changed, 372 insertions(+), 491 deletions(-)

diffs (truncated from 1357 to 300 lines):

diff -r 856f056d392e -r fd517ae68f93 source/common/frame.cpp
--- a/source/common/frame.cpp	Fri Sep 21 11:03:03 2018 +0530
+++ b/source/common/frame.cpp	Tue Sep 25 16:02:31 2018 +0530
@@ -94,7 +94,7 @@ bool Frame::create(x265_param *param, fl
         CHECKED_MALLOC_ZERO(m_classifyCount, uint32_t, size);
     }
 
-    if (m_fencPic->create(param, !!m_param->bCopyPicToFrame) && m_lowres.create(m_fencPic, param->bframes, !!param->rc.aqMode || !!param->bAQMotion, param->rc.qgSize))
+    if (m_fencPic->create(param, !!m_param->bCopyPicToFrame) && m_lowres.create(param, m_fencPic, param->rc.qgSize))
     {
         X265_CHECK((m_reconColCount == NULL), "m_reconColCount was initialized");
         m_numRows = (m_fencPic->m_picHeight + param->maxCUSize - 1)  / param->maxCUSize;
@@ -103,11 +103,8 @@ bool Frame::create(x265_param *param, fl
 
         if (quantOffsets)
         {
-            int32_t cuCount;
-            if (param->rc.qgSize == 8)
-                cuCount = m_lowres.maxBlocksInRowFullRes * m_lowres.maxBlocksInColFullRes;
-            else
-                cuCount = m_lowres.maxBlocksInRow * m_lowres.maxBlocksInCol;
+            int32_t cuCount = (param->rc.qgSize == 8) ? m_lowres.maxBlocksInRowFullRes * m_lowres.maxBlocksInColFullRes :
+                                                        m_lowres.maxBlocksInRow * m_lowres.maxBlocksInCol;
             m_quantOffsets = new float[cuCount];
         }
         return true;
diff -r 856f056d392e -r fd517ae68f93 source/common/lowres.cpp
--- a/source/common/lowres.cpp	Fri Sep 21 11:03:03 2018 +0530
+++ b/source/common/lowres.cpp	Tue Sep 25 16:02:31 2018 +0530
@@ -27,10 +27,10 @@
 
 using namespace X265_NS;
 
-bool Lowres::create(PicYuv *origPic, int _bframes, bool bAQEnabled, uint32_t qgSize)
+bool Lowres::create(x265_param* param, PicYuv *origPic, uint32_t qgSize)
 {
     isLowres = true;
-    bframes = _bframes;
+    bframes = param->bframes;
     width = origPic->m_picWidth / 2;
     lines = origPic->m_picHeight / 2;
     lumaStride = width + 2 * origPic->m_lumaMarginX;
@@ -41,11 +41,7 @@ bool Lowres::create(PicYuv *origPic, int
     maxBlocksInRowFullRes = maxBlocksInRow * 2;
     maxBlocksInColFullRes = maxBlocksInCol * 2;
     int cuCount = maxBlocksInRow * maxBlocksInCol;
-    int cuCountFullRes;
-    if (qgSize == 8)
-        cuCountFullRes = maxBlocksInRowFullRes * maxBlocksInColFullRes;
-    else
-        cuCountFullRes = cuCount;
+    int cuCountFullRes = (qgSize > 8) ? cuCount : cuCount << 2;
 
     /* rounding the width to multiple of lowres CU size */
     width = maxBlocksInRow * X265_LOWRES_CU_SIZE;
@@ -53,7 +49,7 @@ bool Lowres::create(PicYuv *origPic, int
 
     size_t planesize = lumaStride * (lines + 2 * origPic->m_lumaMarginY);
     size_t padoffset = lumaStride * origPic->m_lumaMarginY + origPic->m_lumaMarginX;
-    if (bAQEnabled)
+    if (!!param->rc.aqMode)
     {
         CHECKED_MALLOC_ZERO(qpAqOffset, double, cuCountFullRes);
         CHECKED_MALLOC_ZERO(invQscaleFactor, int, cuCountFullRes);
diff -r 856f056d392e -r fd517ae68f93 source/common/lowres.h
--- a/source/common/lowres.h	Fri Sep 21 11:03:03 2018 +0530
+++ b/source/common/lowres.h	Tue Sep 25 16:02:31 2018 +0530
@@ -152,14 +152,12 @@ struct Lowres : public ReferencePlanes
     uint32_t* blockVariance;
     uint64_t  wp_ssd[3];       // This is different than SSDY, this is sum(pixel^2) - sum(pixel)^2 for entire frame
     uint64_t  wp_sum[3];
-    uint64_t  frameVariance;
 
     /* cutree intermediate data */
     uint16_t* propagateCost;
     double    weightedCostDelta[X265_BFRAME_MAX + 2];
     ReferencePlanes weightedRef[X265_BFRAME_MAX + 2];
-
-    bool create(PicYuv *origPic, int _bframes, bool bAqEnabled, uint32_t qgSize);
+    bool create(x265_param* param, PicYuv *origPic, uint32_t qgSize);
     void destroy();
     void init(PicYuv *origPic, int poc);
 };
diff -r 856f056d392e -r fd517ae68f93 source/common/param.cpp
--- a/source/common/param.cpp	Fri Sep 21 11:03:03 2018 +0530
+++ b/source/common/param.cpp	Tue Sep 25 16:02:31 2018 +0530
@@ -1415,9 +1415,16 @@ int x265_check_params(x265_param* param)
     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 856f056d392e -r fd517ae68f93 source/encoder/analysis.cpp
--- a/source/encoder/analysis.cpp	Fri Sep 21 11:03:03 2018 +0530
+++ b/source/encoder/analysis.cpp	Tue Sep 25 16:02:31 2018 +0530
@@ -3357,13 +3357,13 @@ void Analysis::encodeResidue(const CUDat
                 primitives.chroma[m_csp].cu[sizeIdx].copy_pp(reconPic.getCbAddr(cu.m_cuAddr, absPartIdx), reconPic.m_strideC,
                                                          predU, predYuv.m_csize);
 
-             if (cu.m_cbf[2][0])
-             {
-                 bool reconPicAlign = (reconPic.m_cuOffsetC[cu.m_cuAddr] + reconPic.m_buOffsetC[absPartIdx]) % 64 == 0;
-                 bool predValign = predYuv.getChromaAddrOffset(absPartIdx) % 64 == 0;
-                 primitives.chroma[m_csp].cu[sizeIdx].add_ps[reconPicAlign && predValign && (reconPic.m_strideC % 64 == 0) && (predYuv.m_csize % 64 == 0) &&
-                     (resiYuv.m_csize % 64 == 0)](reconPic.getCrAddr(cu.m_cuAddr, absPartIdx), reconPic.m_strideC, predV, resiYuv.m_buf[2], predYuv.m_csize, resiYuv.m_csize);
-             }
+            if (cu.m_cbf[2][0])
+            {
+                bool reconPicAlign = (reconPic.m_cuOffsetC[cu.m_cuAddr] + reconPic.m_buOffsetC[absPartIdx]) % 64 == 0;
+                bool predValign = predYuv.getChromaAddrOffset(absPartIdx) % 64 == 0;
+                primitives.chroma[m_csp].cu[sizeIdx].add_ps[reconPicAlign && predValign && (reconPic.m_strideC % 64 == 0) && (predYuv.m_csize % 64 == 0) &&
+                    (resiYuv.m_csize % 64 == 0)](reconPic.getCrAddr(cu.m_cuAddr, absPartIdx), reconPic.m_strideC, predV, resiYuv.m_buf[2], predYuv.m_csize, resiYuv.m_csize);
+            }
             else
                 primitives.chroma[m_csp].cu[sizeIdx].copy_pp(reconPic.getCrAddr(cu.m_cuAddr, absPartIdx), reconPic.m_strideC,
                                                          predV, predYuv.m_csize);
@@ -3568,18 +3568,12 @@ int Analysis::calculateQpforCuSize(const
             qp += distortionData->offset[ctu.m_cuAddr];
     }
 
-    int loopIncr;
-    if (m_param->rc.qgSize == 8)
-        loopIncr = 8;
-    else
-        loopIncr = 16;
+    int loopIncr = (m_param->rc.qgSize == 8) ? 8 : 16;
+
     /* Use cuTree offsets if cuTree enabled and frame is referenced, else use AQ offsets */
     bool isReferenced = IS_REFERENCED(m_frame);
-    double *qpoffs;
-    if (complexCheck)
-        qpoffs = m_frame->m_lowres.qpAqOffset;
-    else
-        qpoffs = (isReferenced && m_param->rc.cuTree) ? m_frame->m_lowres.qpCuTreeOffset : m_frame->m_lowres.qpAqOffset;
+    double *qpoffs = (isReferenced && m_param->rc.cuTree && !complexCheck) ? m_frame->m_lowres.qpCuTreeOffset :
+                                                                             m_frame->m_lowres.qpAqOffset;
     if (qpoffs)
     {
         uint32_t width = m_frame->m_fencPic->m_picWidth;
@@ -3590,13 +3584,11 @@ int Analysis::calculateQpforCuSize(const
         uint32_t blockSize = m_param->maxCUSize >> cuGeom.depth;
         double qp_offset = 0;
         uint32_t cnt = 0;
-        uint32_t idx;
-
         for (uint32_t block_yy = block_y; block_yy < block_y + blockSize && block_yy < height; block_yy += loopIncr)
         {
             for (uint32_t block_xx = block_x; block_xx < block_x + blockSize && block_xx < width; block_xx += loopIncr)
             {
-                idx = ((block_yy / loopIncr) * (maxCols)) + (block_xx / loopIncr);
+                uint32_t idx = ((block_yy / loopIncr) * (maxCols)) + (block_xx / loopIncr);
                 qp_offset += qpoffs[idx];
                 cnt++;
             }
@@ -3609,10 +3601,7 @@ int Analysis::calculateQpforCuSize(const
             int32_t offset = (int32_t)(qp_offset * 100 + .5);
             double threshold = (1 - ((x265_ADAPT_RD_STRENGTH - m_param->dynamicRd) * 0.5));
             int32_t max_threshold = (int32_t)(threshold * 100 + .5);
-            if (offset < max_threshold)
-                return 1;
-            else
-                return 0;
+            return (offset < max_threshold);
         }
     }
 
diff -r 856f056d392e -r fd517ae68f93 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Fri Sep 21 11:03:03 2018 +0530
+++ b/source/encoder/encoder.cpp	Tue Sep 25 16:02:31 2018 +0530
@@ -875,6 +875,77 @@ void Encoder::calcRefreshInterval(Frame*
     }
 }
 
+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, &m_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 : <POC><space><PREFIX><space><NAL UNIT TYPE>/<SEI TYPE><space><SEI Payload> */
+    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 @@ int Encoder::encode(const x265_picture* 
             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, &m_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 : <POC><space><PREFIX><space><NAL UNIT TYPE>/<SEI TYPE><space><SEI Payload> */
-        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 @@ int Encoder::encode(const x265_picture* 
         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)


More information about the x265-commits mailing list