[x265] [PATCH] remove duplicate code from FrameFilter

Ashok Kumar Mishra ashok at multicorewareinc.com
Tue Sep 25 11:02:48 CEST 2018


On Tue, Sep 18, 2018 at 4:35 PM <ashok at multicorewareinc.com> wrote:

> # HG changeset patch
> # User Ashok Kumar Mishra <ashok at multicorewareinc.com>
> # 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(&m_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(&m_state[0]);
> -
> -            updateMD5Plane(m_state[0], reconPic->m_picOrg[0], width,
> height, stride);
> -
> -            if (m_param->internalCsp != X265_CSP_I400)
> -            {
> -                MD5Init(&m_state[1]);
> -                MD5Init(&m_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] = 0xffff;
> -
> -            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] = 0xffff;
> -
> -                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 = m_frame->m_encData->getPicCTU(sliceAddr);
> -            //const int sliceQp = ctu->m_qp[0];
>              if (m_param->bOptRefListLengthPPS)
>              {
>                  ScopedLock refIdxLock(m_top->m_sliceRefIdxLock);
> @@ -1095,36 +1064,8 @@
>      if (isSei && m_param->bSingleSeiNal)
>          m_bs.resetBits();
>
> -    if (m_param->decodedPictureHashSEI)
> -    {
> -        int planes = (m_frame->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(&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_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_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);
> -    }
> +    if (m_param->decodedPictureHashSEI)
> +        writeTrailingSEIMessages();
>
>      uint64_t bytes = 0;
>      for (uint32_t i = 0; i < m_nalList.m_numNal; i++)
> @@ -1216,6 +1157,78 @@
>      m_endFrameTime = x265_mdate();
>  }
>
> +void FrameEncoder::initDecodedPictureHashSEI(int row, int cuAddr, int
> height)
> +{
> +    PicYuv *reconPic = m_frame->m_reconPic;
> +    uint32_t width = reconPic->m_picWidth;
> +    intptr_t stride = reconPic->m_stride;
> +    uint32_t maxCUHeight = m_param->maxCUSize;
> +
> +    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)
> +    {
> +        if (!row)
> +            MD5Init(&m_seiReconPictureDigest.m_state[0]);
> +
> +        updateMD5Plane(m_seiReconPictureDigest.m_state[0],
> reconPic->getLumaAddr(cuAddr), width, height, stride);
> +        if (m_param->internalCsp != X265_CSP_I400)
> +        {
> +            if (!row)
> +            {
> +                MD5Init(&m_seiReconPictureDigest.m_state[1]);
> +                MD5Init(&m_seiReconPictureDigest.m_state[2]);
> +            }
> +
> +            width >>= hChromaShift;
> +            height >>= vChromaShift;
> +            stride = reconPic->m_strideC;
> +
> +            updateMD5Plane(m_seiReconPictureDigest.m_state[1],
> reconPic->getCbAddr(cuAddr), width, height, stride);
> +            updateMD5Plane(m_seiReconPictureDigest.m_state[2],
> reconPic->getCrAddr(cuAddr), width, height, stride);
> +        }
> +    }
> +    else if (m_param->decodedPictureHashSEI == 2)
> +    {
> +
> +        if (!row)
> +            m_seiReconPictureDigest.m_crc[0] = 0xffff;
> +
> +        updateCRC(reconPic->getLumaAddr(cuAddr),
> m_seiReconPictureDigest.m_crc[0], height, width, stride);
> +        if (m_param->internalCsp != X265_CSP_I400)
> +        {
> +            width >>= hChromaShift;
> +            height >>= vChromaShift;
> +            stride = reconPic->m_strideC;
> +            m_seiReconPictureDigest.m_crc[1] =
> m_seiReconPictureDigest.m_crc[2] = 0xffff;
> +
> +            updateCRC(reconPic->getCbAddr(cuAddr),
> m_seiReconPictureDigest.m_crc[1], height, width, stride);
> +            updateCRC(reconPic->getCrAddr(cuAddr),
> m_seiReconPictureDigest.m_crc[2], height, width, stride);
> +        }
> +    }
> +    else if (m_param->decodedPictureHashSEI == 3)
> +    {
> +        if (!row)
> +            m_seiReconPictureDigest.m_checksum[0] = 0;
> +
> +        updateChecksum(reconPic->m_picOrg[0],
> m_seiReconPictureDigest.m_checksum[0], height, width, stride, row,
> maxCUHeight);
> +        if (m_param->internalCsp != X265_CSP_I400)
> +        {
> +            width >>= hChromaShift;
> +            height >>= vChromaShift;
> +            stride = reconPic->m_strideC;
> +            maxCUHeight >>= vChromaShift;
> +
> +            if (!row)
> +                m_seiReconPictureDigest.m_checksum[1] =
> m_seiReconPictureDigest.m_checksum[2] = 0;
> +
> +            updateChecksum(reconPic->m_picOrg[1],
> m_seiReconPictureDigest.m_checksum[1], height, width, stride, row,
> maxCUHeight);
> +            updateChecksum(reconPic->m_picOrg[2],
> m_seiReconPictureDigest.m_checksum[2], height, width, stride, row,
> maxCUHeight);
> +        }
> +    }
> +}
> +
>  void FrameEncoder::encodeSlice(uint32_t sliceAddr)
>  {
>      Slice* slice = m_frame->m_encData->m_slice;
> diff -r 1582bba2eb39 -r 6426e22f479f source/encoder/frameencoder.h
> --- a/source/encoder/frameencoder.h     Fri Sep 14 17:18:07 2018 +0530
> +++ b/source/encoder/frameencoder.h     Tue Sep 18 16:34:04 2018 +0530
> @@ -129,6 +129,8 @@
>      /* blocks until worker thread is done, returns access unit */
>      Frame *getEncodedPicture(NALList& list);
>
> +    void initDecodedPictureHashSEI(int row, int cuAddr, int height);
> +
>      Event                    m_enable;
>      Event                    m_done;
>      Event                    m_completionEvent;
> @@ -161,9 +163,6 @@
>      double                   m_ssim;
>      uint64_t                 m_accessUnitBits;
>      uint32_t                 m_ssimCnt;
> -    MD5Context               m_state[3];
> -    uint32_t                 m_crc[3];
> -    uint32_t                 m_checksum[3];
>
>      volatile int             m_activeWorkerCount;        // count of
> workers currently encoding or filtering CTUs
>      volatile int             m_totalActiveWorkerCount;   // sum of
> m_activeWorkerCount sampled at end of each CTU
> @@ -230,7 +229,7 @@
>      void threadMain();
>      int  collectCTUStatistics(const CUData& ctu, FrameStats* frameLog);
>      void noiseReductionUpdate();
> -    void computeAvgTrainingData();
> +    void writeTrailingSEIMessages();
>
>      /* Called by WaveFront::findJob() */
>      virtual void processRow(int row, int threadId);
> @@ -243,8 +242,9 @@
>  #if ENABLE_LIBVMAF
>      void vmafFrameLevelScore();
>  #endif
> -    void collectDynDataRow(CUData& ctu, FrameStats* rowStats);
>      void collectDynDataFrame();
> +    void computeAvgTrainingData();
> +    void collectDynDataRow(CUData& ctu, FrameStats* rowStats);
>  };
>  }
>
> diff -r 1582bba2eb39 -r 6426e22f479f source/encoder/framefilter.cpp
> --- a/source/encoder/framefilter.cpp    Fri Sep 14 17:18:07 2018 +0530
> +++ b/source/encoder/framefilter.cpp    Tue Sep 18 16:34:04 2018 +0530
> @@ -712,78 +712,8 @@
>
>      if (m_param->maxSlices == 1)
>      {
> -        if (m_param->decodedPictureHashSEI == 1)
> -        {
> -            uint32_t height = m_parallelFilter[row].getCUHeight();
> -            uint32_t width = reconPic->m_picWidth;
> -            intptr_t stride = reconPic->m_stride;
> -
> -            if (!row)
> -                MD5Init(&m_frameEncoder->m_state[0]);
> -
> -            updateMD5Plane(m_frameEncoder->m_state[0],
> reconPic->getLumaAddr(cuAddr), width, height, stride);
> -            if (m_param->internalCsp != X265_CSP_I400)
> -            {
> -                if (!row)
> -                {
> -                    MD5Init(&m_frameEncoder->m_state[1]);
> -                    MD5Init(&m_frameEncoder->m_state[2]);
> -                }
> -
> -                width >>= m_hChromaShift;
> -                height >>= m_vChromaShift;
> -                stride = reconPic->m_strideC;
> -
> -                updateMD5Plane(m_frameEncoder->m_state[1],
> reconPic->getCbAddr(cuAddr), width, height, stride);
> -                updateMD5Plane(m_frameEncoder->m_state[2],
> reconPic->getCrAddr(cuAddr), width, height, stride);
> -            }
> -        }
> -        else if (m_param->decodedPictureHashSEI == 2)
> -        {
> -            uint32_t height = m_parallelFilter[row].getCUHeight();
> -            uint32_t width = reconPic->m_picWidth;
> -            intptr_t stride = reconPic->m_stride;
> -
> -            if (!row)
> -                m_frameEncoder->m_crc[0] = 0xffff;
> -
> -            updateCRC(reconPic->getLumaAddr(cuAddr),
> m_frameEncoder->m_crc[0], height, width, stride);
> -            if (m_param->internalCsp != X265_CSP_I400)
> -            {
> -                width >>= m_hChromaShift;
> -                height >>= m_vChromaShift;
> -                stride = reconPic->m_strideC;
> -                m_frameEncoder->m_crc[1] = m_frameEncoder->m_crc[2] =
> 0xffff;
> -
> -                updateCRC(reconPic->getCbAddr(cuAddr),
> m_frameEncoder->m_crc[1], height, width, stride);
> -                updateCRC(reconPic->getCrAddr(cuAddr),
> m_frameEncoder->m_crc[2], height, width, stride);
> -            }
> -        }
> -        else if (m_param->decodedPictureHashSEI == 3)
> -        {
> -            uint32_t width = reconPic->m_picWidth;
> -            uint32_t height = m_parallelFilter[row].getCUHeight();
> -            intptr_t stride = reconPic->m_stride;
> -            uint32_t cuHeight = m_param->maxCUSize;
> -
> -            if (!row)
> -                m_frameEncoder->m_checksum[0] = 0;
> -
> -            updateChecksum(reconPic->m_picOrg[0],
> m_frameEncoder->m_checksum[0], height, width, stride, row, cuHeight);
> -            if (m_param->internalCsp != X265_CSP_I400)
> -            {
> -                width >>= m_hChromaShift;
> -                height >>= m_vChromaShift;
> -                stride = reconPic->m_strideC;
> -                cuHeight >>= m_vChromaShift;
> -
> -                if (!row)
> -                    m_frameEncoder->m_checksum[1] =
> m_frameEncoder->m_checksum[2] = 0;
> -
> -                updateChecksum(reconPic->m_picOrg[1],
> m_frameEncoder->m_checksum[1], height, width, stride, row, cuHeight);
> -                updateChecksum(reconPic->m_picOrg[2],
> m_frameEncoder->m_checksum[2], height, width, stride, row, cuHeight);
> -            }
> -        }
> +        uint32_t height = m_parallelFilter[row].getCUHeight();
> +        m_frameEncoder->initDecodedPictureHashSEI(row, cuAddr, height);
>      } // end of (m_param->maxSlices == 1)
>
>      if (ATOMIC_INC(&m_frameEncoder->m_completionCount) == 2 *
> (int)m_frameEncoder->m_numRows)
> diff -r 1582bba2eb39 -r 6426e22f479f source/encoder/sei.h
> --- a/source/encoder/sei.h      Fri Sep 14 17:18:07 2018 +0530
> +++ b/source/encoder/sei.h      Tue Sep 18 16:34:04 2018 +0530
> @@ -28,6 +28,7 @@
>  #include "bitstream.h"
>  #include "slice.h"
>  #include "nal.h"
> +#include "md5.h"
>
>  namespace X265_NS {
>  // private namespace
> @@ -136,7 +137,12 @@
>          CRC,
>          CHECKSUM,
>      } m_method;
> -    uint8_t m_digest[3][16];
> +
> +    MD5Context m_state[3];
> +    uint32_t   m_crc[3];
> +    uint32_t   m_checksum[3];
> +    uint8_t    m_digest[3][16];
> +
>      void writeSEI(const SPS& sps)
>      {
>          int planes = (sps.chromaFormatIdc != X265_CSP_I400) ? 3 : 1;
>

Pushed to default.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20180925/5f637640/attachment-0001.html>


More information about the x265-devel mailing list