[x265] [PATCH] Expose WeightParam, analysis_inter_data, analysis_intra_data and analysisDistortionData structures in API

Ashok Kumar Mishra ashok at multicorewareinc.com
Fri Jul 20 17:26:37 CEST 2018


On Fri, Jul 20, 2018 at 2:23 PM, <aasaipriya at multicorewareinc.com> wrote:

> # HG changeset patch
> # User Aasaipriya Chandran <aasaipriya at multicorewareinc.com>
> # Date 1532075633 -19800
> #      Fri Jul 20 14:03:53 2018 +0530
> # Node ID 9694dfbe83ac404bce0c88ca19ed06decd93c71d
> # Parent  fb1530b0e1b4ebd179b8098015213baeeb37c8d2
> Expose WeightParam, analysis_inter_data, analysis_intra_data and
> analysisDistortionData structures in API
>
> diff -r fb1530b0e1b4 -r 9694dfbe83ac source/common/framedata.h
> --- a/source/common/framedata.h Fri Jul 20 14:20:22 2018 +0530
> +++ b/source/common/framedata.h Fri Jul 20 14:03:53 2018 +0530
> @@ -179,42 +179,5 @@
>      inline CUData* getPicCTU(uint32_t ctuAddr) { return
> &m_picCTU[ctuAddr]; }
>  };
>
> -/* Stores intra analysis data for a single frame. This struct needs
> better packing */
> -struct analysis_intra_data
> -{
> -    uint8_t*  depth;
> -    uint8_t*  modes;
> -    char*     partSizes;
> -    uint8_t*  chromaModes;
> -};
> -
> -/* Stores inter analysis data for a single frame */
> -struct analysis_inter_data
> -{
> -    int32_t*    ref;
> -    uint8_t*    depth;
> -    uint8_t*    modes;
> -    uint8_t*    partSize;
> -    uint8_t*    mergeFlag;
> -    uint8_t*    interDir;
> -    uint8_t*    mvpIdx[2];
> -    int8_t*     refIdx[2];
> -    MV*         mv[2];
> -   int64_t*     sadCost;
> -};
> -
> -struct analysisDistortionData
> -{
> -    sse_t*        distortion;
> -    sse_t*        ctuDistortion;
> -    double*       scaledDistortion;
> -    double        averageDistortion;
> -    double        sdDistortion;
> -    uint32_t      highDistortionCtuCount;
> -    uint32_t      lowDistortionCtuCount;
> -    double*       offset;
> -    double*       threshold;
> -};
> -
>  }
>  #endif // ifndef X265_FRAMEDATA_H
> diff -r fb1530b0e1b4 -r 9694dfbe83ac source/encoder/analysis.cpp
> --- a/source/encoder/analysis.cpp       Fri Jul 20 14:20:22 2018 +0530
> +++ b/source/encoder/analysis.cpp       Fri Jul 20 14:03:53 2018 +0530
> @@ -37,7 +37,7 @@
>  using namespace X265_NS;
>
>  /* An explanation of rate distortion levels (--rd-level)
> - *
> + *
>   * rd-level 0 generates no recon per CU (NO RDO or Quant)
>   *
>   *   sa8d selection between merge / skip / inter / intra and split
> @@ -70,6 +70,12 @@
>   * rd-level 5,6 does RDO for each inter mode
>   */
>
> +#define COPY_TO_MV(s1, s2, d1, d2)\
> +    {\
> +        d1 = s1; \
> +        d2 = s2; \
> +    }
> +
>  Analysis::Analysis()
>  {
>      m_reuseInterDataCTU = NULL;
> @@ -190,7 +196,7 @@
>      if (m_param->analysisMultiPassRefine && m_param->rc.bStatRead &&
> (m_slice->m_sliceType != I_SLICE))
>      {
>          int numPredDir = m_slice->isInterP() ? 1 : 2;
> -        m_reuseInterDataCTU = (analysis_inter_data*)m_frame-
> >m_analysisData.interData;
> +        m_reuseInterDataCTU = m_frame->m_analysisData.interData;
>          for (int dir = 0; dir < numPredDir; dir++)
>          {
>              m_reuseMv[dir] = &m_reuseInterDataCTU->mv[dir][ctu.m_cuAddr
> * ctu.m_numPartitions];
> @@ -204,7 +210,7 @@
>      if ((m_param->analysisSave || m_param->analysisLoad) &&
> m_slice->m_sliceType != I_SLICE && m_param->analysisReuseLevel > 1 &&
> m_param->analysisReuseLevel < 10)
>      {
>          int numPredDir = m_slice->isInterP() ? 1 : 2;
> -        m_reuseInterDataCTU = (analysis_inter_data*)m_frame-
> >m_analysisData.interData;
> +        m_reuseInterDataCTU = m_frame->m_analysisData.interData;
>          m_reuseRef = &m_reuseInterDataCTU->ref [ctu.m_cuAddr *
> X265_MAX_PRED_MODE_PER_CTU * numPredDir];
>          m_reuseDepth = &m_reuseInterDataCTU->depth[ctu.m_cuAddr *
> ctu.m_numPartitions];
>          m_reuseModes = &m_reuseInterDataCTU->modes[ctu.m_cuAddr *
> ctu.m_numPartitions];
> @@ -221,7 +227,7 @@
>
>      if (m_slice->m_sliceType == I_SLICE)
>      {
> -        analysis_intra_data* intraDataCTU = (analysis_intra_data*)m_frame-
> >m_analysisData.intraData;
> +        x265_analysis_intra_data* intraDataCTU = m_frame->m_analysisData.
> intraData;
>          if (m_param->analysisLoad && m_param->analysisReuseLevel > 1)
>          {
>              memcpy(ctu.m_cuDepth, &intraDataCTU->depth[ctu.m_cuAddr *
> numPartition], sizeof(uint8_t) * numPartition);
> @@ -240,7 +246,7 @@
>
>          if (bCopyAnalysis)
>          {
> -            analysis_inter_data* interDataCTU =
> (analysis_inter_data*)m_frame->m_analysisData.interData;
> +            x265_analysis_inter_data* interDataCTU =
> m_frame->m_analysisData.interData;
>              int posCTU = ctu.m_cuAddr * numPartition;
>              memcpy(ctu.m_cuDepth, &interDataCTU->depth[posCTU],
> sizeof(uint8_t) * numPartition);
>              memcpy(ctu.m_predMode, &interDataCTU->modes[posCTU],
> sizeof(uint8_t) * numPartition);
> @@ -250,7 +256,7 @@
>
>              if ((m_slice->m_sliceType == P_SLICE ||
> m_param->bIntraInBFrames) && !m_param->bMVType)
>              {
> -                analysis_intra_data* intraDataCTU =
> (analysis_intra_data*)m_frame->m_analysisData.intraData;
> +                x265_analysis_intra_data* intraDataCTU =
> m_frame->m_analysisData.intraData;
>                  memcpy(ctu.m_lumaIntraDir, &intraDataCTU->modes[posCTU],
> sizeof(uint8_t) * numPartition);
>                  memcpy(ctu.m_chromaIntraDir, &intraDataCTU->chromaModes[posCTU],
> sizeof(uint8_t) * numPartition);
>              }
> @@ -276,14 +282,14 @@
>          }
>          else if ((m_param->analysisLoad && m_param->analysisReuseLevel ==
> 10) || ((m_param->bMVType == AVC_INFO) && m_param->analysisReuseLevel >= 7
> && ctu.m_numPartitions <= 16))
>          {
> -            analysis_inter_data* interDataCTU =
> (analysis_inter_data*)m_frame->m_analysisData.interData;
> +            x265_analysis_inter_data* interDataCTU =
> m_frame->m_analysisData.interData;
>              int posCTU = ctu.m_cuAddr * numPartition;
>              memcpy(ctu.m_cuDepth, &interDataCTU->depth[posCTU],
> sizeof(uint8_t) * numPartition);
>              memcpy(ctu.m_predMode, &interDataCTU->modes[posCTU],
> sizeof(uint8_t) * numPartition);
>              memcpy(ctu.m_partSize, &interDataCTU->partSize[posCTU],
> sizeof(uint8_t) * numPartition);
>              if ((m_slice->m_sliceType == P_SLICE ||
> m_param->bIntraInBFrames) && !(m_param->bMVType == AVC_INFO))
>              {
> -                analysis_intra_data* intraDataCTU =
> (analysis_intra_data*)m_frame->m_analysisData.intraData;
> +                x265_analysis_intra_data* intraDataCTU =
> m_frame->m_analysisData.intraData;
>                  memcpy(ctu.m_lumaIntraDir, &intraDataCTU->modes[posCTU],
> sizeof(uint8_t) * numPartition);
>                  memcpy(ctu.m_chromaIntraDir, &intraDataCTU->chromaModes[posCTU],
> sizeof(uint8_t) * numPartition);
>              }
> @@ -2455,13 +2461,15 @@
>                  PredictionUnit pu(mode.cu, cuGeom, part);
>                  if ((m_param->analysisLoad && m_param->analysisReuseLevel
> == 10) || (m_param->bMVType == AVC_INFO && m_param->analysisReuseLevel >=
> 7))
>                  {
> -                    analysis_inter_data* interDataCTU =
> (analysis_inter_data*)m_frame->m_analysisData.interData;
> +                    x265_analysis_inter_data* interDataCTU =
> m_frame->m_analysisData.interData;
>                      int cuIdx = (mode.cu.m_cuAddr *
> parentCTU.m_numPartitions) + cuGeom.absPartIdx;
>                      mode.cu.m_mergeFlag[pu.puAbsPartIdx] =
> interDataCTU->mergeFlag[cuIdx + part];
>                      mode.cu.setPUInterDir(interDataCTU->interDir[cuIdx +
> part], pu.puAbsPartIdx, part);
>                      for (int list = 0; list < m_slice->isInterB() + 1;
> list++)
>                      {
> -                        mode.cu.setPUMv(list,
> interDataCTU->mv[list][cuIdx + part], pu.puAbsPartIdx, part);
> +                        MV dst; x265_analysis_MV src =
> interDataCTU->mv[list][cuIdx + part];
> +                        COPY_TO_MV(src.x, src.y, dst.x, dst.y);
> +                        mode.cu.setPUMv(list, dst, pu.puAbsPartIdx, part);
>                          mode.cu.setPURefIdx(list,
> interDataCTU->refIdx[list][cuIdx + part], pu.puAbsPartIdx, part);
>                          mode.cu.m_mvpIdx[list][pu.puAbsPartIdx] =
> interDataCTU->mvpIdx[list][cuIdx + part];
>                      }
> @@ -2483,7 +2491,10 @@
>                              if (m_param->interRefine != 1)
>                                  mvp = mode.amvpCand[list][ref][mode.
> cu.m_mvpIdx[list][pu.puAbsPartIdx]];
>                              else
> -                                mvp = interDataCTU->mv[list][cuIdx +
> part];
> +                            {
> +                                x265_analysis_MV src =
> interDataCTU->mv[list][cuIdx + part];
> +                                COPY_TO_MV(src.x, src.y, mvp.x, mvp.y);
> +                            }
>                              if (m_param->mvRefine || m_param->interRefine
> == 1)
>                              {
>                                  MV outmv;
> @@ -3021,8 +3032,9 @@
>              for (int32_t i = 0; i < numPredDir; i++)
>              {
>                  int* ref = &m_reuseRef[i * m_frame->m_analysisData.numPartitions
> * m_frame->m_analysisData.numCUsInFrame];
> +                x265_analysis_MV src = m_reuseMv[i][cuGeom.absPartIdx];
> MV dst = bestME[i].mv;
>                  bestME[i].ref = ref[cuGeom.absPartIdx];
> -                bestME[i].mv = m_reuseMv[i][cuGeom.absPartIdx];
> +                COPY_TO_MV(src.x, src.y, dst.x, dst.y);
>                  bestME[i].mvpIdx = m_reuseMvpIdx[i][cuGeom.absPartIdx];
>              }
>          }
> @@ -3085,9 +3097,10 @@
>              MotionData* bestME = interMode.bestME[part];
>              for (int32_t i = 0; i < numPredDir; i++)
>              {
> +                x265_analysis_MV src = m_reuseMv[i][cuGeom.absPartIdx];
> MV dst = bestME[i].mv;
>                  int* ref = &m_reuseRef[i * m_frame->m_analysisData.numPartitions
> * m_frame->m_analysisData.numCUsInFrame];
>                  bestME[i].ref = ref[cuGeom.absPartIdx];
> -                bestME[i].mv = m_reuseMv[i][cuGeom.absPartIdx];
> +                COPY_TO_MV(src.x, src.y, dst.x, dst.y);
>                  bestME[i].mvpIdx = m_reuseMvpIdx[i][cuGeom.absPartIdx];
>              }
>          }
> @@ -3562,7 +3575,7 @@
>
>      if (m_param->analysisMultiPassDistortion && m_param->rc.bStatRead)
>      {
> -        analysisDistortionData* distortionData =
> (analysisDistortionData*)m_frame->m_analysisData.distortionData;
> +        x265_analysis_distortion_data* distortionData =
> m_frame->m_analysisData.distortionData;
>          if ((distortionData->threshold[ctu.m_cuAddr] < 0.9 ||
> distortionData->threshold[ctu.m_cuAddr] > 1.1)
>              && distortionData->highDistortionCtuCount && distortionData->
> lowDistortionCtuCount)
>              qp += distortionData->offset[ctu.m_cuAddr];
> diff -r fb1530b0e1b4 -r 9694dfbe83ac source/encoder/analysis.h
> --- a/source/encoder/analysis.h Fri Jul 20 14:20:22 2018 +0530
> +++ b/source/encoder/analysis.h Fri Jul 20 14:03:53 2018 +0530
> @@ -123,13 +123,13 @@
>
>  protected:
>      /* Analysis data for save/load mode, writes/reads data based on
> absPartIdx */
> -    analysis_inter_data* m_reuseInterDataCTU;
> -    int32_t*             m_reuseRef;
> -    uint8_t*             m_reuseDepth;
> -    uint8_t*             m_reuseModes;
> -    uint8_t*             m_reusePartSize;
> -    uint8_t*             m_reuseMergeFlag;
> -    MV*                  m_reuseMv[2];
> +    x265_analysis_inter_data*  m_reuseInterDataCTU;
> +    int32_t*                   m_reuseRef;
> +    uint8_t*                   m_reuseDepth;
> +    uint8_t*                   m_reuseModes;
> +    uint8_t*                   m_reusePartSize;
> +    uint8_t*                   m_reuseMergeFlag;
> +    x265_analysis_MV*          m_reuseMv[2];
>      uint8_t*             m_reuseMvpIdx[2];
>
>      uint32_t             m_splitRefIdx[4];
> diff -r fb1530b0e1b4 -r 9694dfbe83ac source/encoder/api.cpp
> --- a/source/encoder/api.cpp    Fri Jul 20 14:20:22 2018 +0530
> +++ b/source/encoder/api.cpp    Fri Jul 20 14:03:53 2018 +0530
> @@ -406,14 +406,16 @@
>  void x265_alloc_analysis_data(x265_param *param, x265_analysis_data*
> analysis)
>  {
>      X265_CHECK(analysis->sliceType, "invalid slice type\n");
> -    analysis->interData = analysis->intraData = analysis->distortionData
> = NULL;
> +    analysis->interData = NULL;
> +    analysis->intraData = NULL;
> +    analysis->distortionData = NULL;
>      bool isVbv = param->rc.vbvMaxBitrate > 0 && param->rc.vbvBufferSize >
> 0;
>      int numDir = 2; //irrespective of P or B slices set direction as 2
>      uint32_t numPlanes = param->internalCsp == X265_CSP_I400 ? 1 : 3;
>
>      //Allocate memory for distortionData pointer
> -    analysisDistortionData *distortionData = (analysisDistortionData*)
> analysis->distortionData;
> -    CHECKED_MALLOC_ZERO(distortionData, analysisDistortionData, 1);
> +    x265_analysis_distortion_data *distortionData =
> analysis->distortionData;
> +    CHECKED_MALLOC_ZERO(distortionData, x265_analysis_distortion_data,
> 1);
>      CHECKED_MALLOC_ZERO(distortionData->distortion, sse_t,
> analysis->numPartitions * analysis->numCUsInFrame);
>      if (param->rc.bStatRead)
>      {
> @@ -434,14 +436,14 @@
>
>      //Allocate memory for weightParam pointer
>      if (!(param->bMVType == AVC_INFO))
> -        CHECKED_MALLOC_ZERO(analysis->wt, WeightParam, numPlanes *
> numDir);
> +        CHECKED_MALLOC_ZERO(analysis->wt, x265_weight_param, numPlanes *
> numDir);
>
>      if (param->analysisReuseLevel < 2)
>          return;
>
>      //Allocate memory for intraData pointer
> -    analysis_intra_data *intraData = (analysis_intra_data*)
> analysis->intraData;
> -    CHECKED_MALLOC_ZERO(intraData, analysis_intra_data, 1);
> +    x265_analysis_intra_data *intraData = analysis->intraData;
> +    CHECKED_MALLOC_ZERO(intraData, x265_analysis_intra_data, 1);
>      CHECKED_MALLOC(intraData->depth, uint8_t, analysis->numPartitions *
> analysis->numCUsInFrame);
>      CHECKED_MALLOC(intraData->modes, uint8_t, analysis->numPartitions *
> analysis->numCUsInFrame);
>      CHECKED_MALLOC(intraData->partSizes, char, analysis->numPartitions *
> analysis->numCUsInFrame);
> @@ -449,15 +451,15 @@
>      analysis->intraData = intraData;
>
>      //Allocate memory for interData pointer based on ReuseLevels
> -    analysis_inter_data *interData = (analysis_inter_data*)
> analysis->interData;
> -    CHECKED_MALLOC_ZERO(interData, analysis_inter_data, 1);
> +    x265_analysis_inter_data *interData = analysis->interData;
> +    CHECKED_MALLOC_ZERO(interData, x265_analysis_inter_data, 1);
>      CHECKED_MALLOC(interData->depth, uint8_t, analysis->numPartitions *
> analysis->numCUsInFrame);
>      CHECKED_MALLOC(interData->modes, uint8_t, analysis->numPartitions *
> analysis->numCUsInFrame);
>
>      CHECKED_MALLOC_ZERO(interData->mvpIdx[0], uint8_t,
> analysis->numPartitions * analysis->numCUsInFrame);
>      CHECKED_MALLOC_ZERO(interData->mvpIdx[1], uint8_t,
> analysis->numPartitions * analysis->numCUsInFrame);
> -    CHECKED_MALLOC_ZERO(interData->mv[0], MV, analysis->numPartitions *
> analysis->numCUsInFrame);
> -    CHECKED_MALLOC_ZERO(interData->mv[1], MV, analysis->numPartitions *
> analysis->numCUsInFrame);
> +    CHECKED_MALLOC_ZERO(interData->mv[0], x265_analysis_MV,
> analysis->numPartitions * analysis->numCUsInFrame);
> +    CHECKED_MALLOC_ZERO(interData->mv[1], x265_analysis_MV,
> analysis->numPartitions * analysis->numCUsInFrame);
>
>      if (param->analysisReuseLevel > 4)
>      {
> @@ -506,13 +508,13 @@
>      //Free memory for distortionData pointers
>      if (analysis->distortionData)
>      {
> -        X265_FREE(((analysisDistortionData*)analysis->distortionData)->
> distortion);
> +        X265_FREE((analysis->distortionData)->distortion);
>          if (param->rc.bStatRead)
>          {
> -            X265_FREE(((analysisDistortionData*)
> analysis->distortionData)->ctuDistortion);
> -            X265_FREE(((analysisDistortionData*)
> analysis->distortionData)->scaledDistortion);
> -            X265_FREE(((analysisDistortionData*)
> analysis->distortionData)->offset);
> -            X265_FREE(((analysisDistortionData*)
> analysis->distortionData)->threshold);
> +            X265_FREE((analysis->distortionData)->ctuDistortion);
> +            X265_FREE((analysis->distortionData)->scaledDistortion);
> +            X265_FREE((analysis->distortionData)->offset);
> +            X265_FREE((analysis->distortionData)->threshold);
>          }
>          X265_FREE(analysis->distortionData);
>      }
> @@ -527,10 +529,10 @@
>      //Free memory for intraData pointers
>      if (analysis->intraData)
>      {
> -        X265_FREE(((analysis_intra_data*)analysis->intraData)->depth);
> -        X265_FREE(((analysis_intra_data*)analysis->intraData)->modes);
> -        X265_FREE(((analysis_intra_data*)analysis->intraData)->
> partSizes);
> -        X265_FREE(((analysis_intra_data*)analysis->intraData)->
> chromaModes);
> +        X265_FREE((analysis->intraData)->depth);
> +        X265_FREE((analysis->intraData)->modes);
> +        X265_FREE((analysis->intraData)->partSizes);
> +        X265_FREE((analysis->intraData)->chromaModes);
>          X265_FREE(analysis->intraData);
>          analysis->intraData = NULL;
>      }
> @@ -538,26 +540,26 @@
>      //Free interData pointers
>      if (analysis->interData)
>      {
> -        X265_FREE(((analysis_inter_data*)analysis->interData)->depth);
> -        X265_FREE(((analysis_inter_data*)analysis->interData)->modes);
> -        X265_FREE(((analysis_inter_data*)analysis->interData)->
> mvpIdx[0]);
> -        X265_FREE(((analysis_inter_data*)analysis->interData)->
> mvpIdx[1]);
> -        X265_FREE(((analysis_inter_data*)analysis->interData)->mv[0]);
> -        X265_FREE(((analysis_inter_data*)analysis->interData)->mv[1]);
> +        X265_FREE((analysis->interData)->depth);
> +        X265_FREE((analysis->interData)->modes);
> +        X265_FREE((analysis->interData)->mvpIdx[0]);
> +        X265_FREE((analysis->interData)->mvpIdx[1]);
> +        X265_FREE((analysis->interData)->mv[0]);
> +        X265_FREE((analysis->interData)->mv[1]);
>
>          if (param->analysisReuseLevel > 4)
>          {
> -            X265_FREE(((analysis_inter_data*)analysis->interData)->
> mergeFlag);
> -            X265_FREE(((analysis_inter_data*)analysis->interData)->
> partSize);
> +            X265_FREE((analysis->interData)->mergeFlag);
> +            X265_FREE((analysis->interData)->partSize);
>          }
>          if (param->analysisReuseLevel >= 7)
>          {
>              int numDir = 2;
> -            X265_FREE(((analysis_inter_data*)analysis->interData)->
> interDir);
> -            X265_FREE(((analysis_inter_data*)analysis->interData)->
> sadCost);
> +            X265_FREE((analysis->interData)->interDir);
> +            X265_FREE((analysis->interData)->sadCost);
>              for (int dir = 0; dir < numDir; dir++)
>              {
> -                X265_FREE(((analysis_inter_data*)analysis->interData)->
> refIdx[dir]);
> +                X265_FREE((analysis->interData)->refIdx[dir]);
>                  if (analysis->modeFlag[dir] != NULL)
>                  {
>                      X265_FREE(analysis->modeFlag[dir]);
> @@ -566,7 +568,7 @@
>              }
>          }
>          else
> -            X265_FREE(((analysis_inter_data*)analysis->interData)->ref);
> +            X265_FREE((analysis->interData)->ref);
>          X265_FREE(analysis->interData);
>          analysis->interData = NULL;
>      }
> diff -r fb1530b0e1b4 -r 9694dfbe83ac source/encoder/encoder.cpp
> --- a/source/encoder/encoder.cpp        Fri Jul 20 14:20:22 2018 +0530
> +++ b/source/encoder/encoder.cpp        Fri Jul 20 14:03:53 2018 +0530
> @@ -546,8 +546,8 @@
>          curFrame->m_analysisData.numPartitions =
> m_param->num4x4Partitions;
>          int num16x16inCUWidth = m_param->maxCUSize >> 4;
>          uint32_t ctuAddr, offset, cuPos;
> -        analysis_intra_data * intraData = (analysis_intra_data
> *)curFrame->m_analysisData.intraData;
> -        analysis_intra_data * srcIntraData = (analysis_intra_data
> *)analysis_data->intraData;
> +        x265_analysis_intra_data * intraData = curFrame->m_analysisData.
> intraData;
> +        x265_analysis_intra_data * srcIntraData =
> analysis_data->intraData;
>          for (int i = 0; i < mbImageHeight; i++)
>          {
>              for (int j = 0; j < mbImageWidth; j++)
> @@ -576,8 +576,8 @@
>          curFrame->m_analysisData.numPartitions =
> m_param->num4x4Partitions;
>          int num16x16inCUWidth = m_param->maxCUSize >> 4;
>          uint32_t ctuAddr, offset, cuPos;
> -        analysis_inter_data * interData = (analysis_inter_data
> *)curFrame->m_analysisData.interData;
> -        analysis_inter_data * srcInterData = (analysis_inter_data*)
> analysis_data->interData;
> +        x265_analysis_inter_data * interData = curFrame->m_analysisData.
> interData;
> +        x265_analysis_inter_data * srcInterData =
> analysis_data->interData;
>          for (int i = 0; i < mbImageHeight; i++)
>          {
>              for (int j = 0; j < mbImageWidth; j++)
> @@ -652,8 +652,8 @@
>
>                  curFrame->m_analysisData.numPartitions =
> m_param->num4x4Partitions;
>                  size_t count = 0;
> -                analysis_intra_data * currIntraData =
> (analysis_intra_data *)curFrame->m_analysisData.intraData;
> -                analysis_intra_data * intraData = (analysis_intra_data
> *)analysis_data->intraData;
> +                x265_analysis_intra_data * currIntraData =
> curFrame->m_analysisData.intraData;
> +                x265_analysis_intra_data * intraData =
> analysis_data->intraData;
>                  for (uint32_t d = 0; d < cuBytes; d++)
>                  {
>                      int bytes = curFrame->m_analysisData.numPartitions
> >> ((intraData)->depth[d] * 2);
> @@ -673,14 +673,14 @@
>
>                  curFrame->m_analysisData.numPartitions =
> m_param->num4x4Partitions;
>                  size_t count = 0;
> -                analysis_inter_data * currInterData =
> (analysis_inter_data *)curFrame->m_analysisData.interData;
> -                analysis_inter_data * interData = (analysis_inter_data
> *)analysis_data->interData;
> +                x265_analysis_inter_data * currInterData =
> curFrame->m_analysisData.interData;
> +                x265_analysis_inter_data * interData =
> analysis_data->interData;
>                  for (uint32_t d = 0; d < cuBytes; d++)
>                  {
>                      int bytes = curFrame->m_analysisData.numPartitions
> >> ((interData)->depth[d] * 2);
>                      memset(&(currInterData)->depth[count],
> (interData)->depth[d], bytes);
>                      memset(&(currInterData)->modes[count],
> (interData)->modes[d], bytes);
> -                    memcpy(&(currInterData)->sadCost[count],
> &((analysis_inter_data*)analysis_data->interData)->sadCost[d], bytes);
> +                    memcpy(&(currInterData)->sadCost[count],
> &(analysis_data->interData)->sadCost[d], bytes);
>                      if (m_param->analysisReuseLevel > 4)
>                      {
>                          memset(&(currInterData)->partSize[count],
> (interData)->partSize[d], bytes);
> @@ -3203,8 +3203,8 @@
>      if (m_param->bUseAnalysisFile)
>          fseeko(m_analysisFileIn, totalConsumedBytes + paramBytes,
> SEEK_SET);
>      const x265_analysis_data *picData = &(picIn->analysisData);
> -    analysis_intra_data *intraPic = (analysis_intra_data
> *)picData->intraData;
> -    analysis_inter_data *interPic = (analysis_inter_data
> *)picData->interData;
> +    x265_analysis_intra_data *intraPic = picData->intraData;
> +    x265_analysis_inter_data *interPic = picData->interData;
>
>      int poc; uint32_t frameRecordSize;
>      X265_FREAD(&frameRecordSize, sizeof(uint32_t), 1, m_analysisFileIn,
> &(picData->frameRecordSize));
> @@ -3305,22 +3305,22 @@
>                  if (partSizes[d] == SIZE_NxN)
>                      partSizes[d] = SIZE_2Nx2N;
>              }
> -            memset(&((analysis_intra_data *)analysis->intraData)->depth[count],
> depthBuf[d], bytes);
> -            memset(&((analysis_intra_data *)analysis->intraData)->chromaModes[count],
> modeBuf[d], bytes);
> -            memset(&((analysis_intra_data *)analysis->intraData)->partSizes[count],
> partSizes[d], bytes);
> +            memset(&(analysis->intraData)->depth[count], depthBuf[d],
> bytes);
> +            memset(&(analysis->intraData)->chromaModes[count],
> modeBuf[d], bytes);
> +            memset(&(analysis->intraData)->partSizes[count],
> partSizes[d], bytes);
>              count += bytes;
>          }
>
>          if (!m_param->scaleFactor)
>          {
> -            X265_FREAD(((analysis_intra_data
> *)analysis->intraData)->modes, sizeof(uint8_t), analysis->numCUsInFrame *
> analysis->numPartitions, m_analysisFileIn, intraPic->modes);
> +            X265_FREAD((analysis->intraData)->modes, sizeof(uint8_t),
> analysis->numCUsInFrame * analysis->numPartitions, m_analysisFileIn,
> intraPic->modes);
>          }
>          else
>          {
>              uint8_t *tempLumaBuf = X265_MALLOC(uint8_t,
> analysis->numCUsInFrame * scaledNumPartition);
>              X265_FREAD(tempLumaBuf, sizeof(uint8_t),
> analysis->numCUsInFrame * scaledNumPartition, m_analysisFileIn,
> intraPic->modes);
>              for (uint32_t ctu32Idx = 0, cnt = 0; ctu32Idx <
> analysis->numCUsInFrame * scaledNumPartition; ctu32Idx++, cnt += factor)
> -                memset(&((analysis_intra_data
> *)analysis->intraData)->modes[cnt], tempLumaBuf[ctu32Idx], factor);
> +                memset(&(analysis->intraData)->modes[cnt],
> tempLumaBuf[ctu32Idx], factor);
>              X265_FREE(tempLumaBuf);
>          }
>          X265_FREE(tempBuf);
> @@ -3390,36 +3390,36 @@
>              int bytes = analysis->numPartitions >> (depthBuf[d] * 2);
>              if (m_param->scaleFactor && modeBuf[d] == MODE_INTRA &&
> depthBuf[d] == 0)
>                  depthBuf[d] = 1;
> -            memset(&((analysis_inter_data *)analysis->interData)->depth[count],
> depthBuf[d], bytes);
> -            memset(&((analysis_inter_data *)analysis->interData)->modes[count],
> modeBuf[d], bytes);
> +            memset(&(analysis->interData)->depth[count], depthBuf[d],
> bytes);
> +            memset(&(analysis->interData)->modes[count], modeBuf[d],
> bytes);
>              if (m_param->analysisReuseLevel > 4)
>              {
>                  if (m_param->scaleFactor && modeBuf[d] == MODE_INTRA &&
> partSize[d] == SIZE_NxN)
>                      partSize[d] = SIZE_2Nx2N;
> -                memset(&((analysis_inter_data *)analysis->interData)->partSize[count],
> partSize[d], bytes);
> +                memset(&(analysis->interData)->partSize[count],
> partSize[d], bytes);
>                  int numPU = (modeBuf[d] == MODE_INTRA) ? 1 :
> nbPartsTable[(int)partSize[d]];
>                  for (int pu = 0; pu < numPU; pu++)
>                  {
>                      if (pu) d++;
> -                    ((analysis_inter_data *)analysis->interData)->mergeFlag[count
> + pu] = mergeFlag[d];
> +                    (analysis->interData)->mergeFlag[count + pu] =
> mergeFlag[d];
>                      if (m_param->analysisReuseLevel == 10)
>                      {
> -                        ((analysis_inter_data *)analysis->interData)->interDir[count
> + pu] = interDir[d];
> +                        (analysis->interData)->interDir[count + pu] =
> interDir[d];
>                          for (uint32_t i = 0; i < numDir; i++)
>                          {
> -                            ((analysis_inter_data *)analysis->interData)->mvpIdx[i][count
> + pu] = mvpIdx[i][d];
> -                            ((analysis_inter_data *)analysis->interData)->refIdx[i][count
> + pu] = refIdx[i][d];
> +                            (analysis->interData)->mvpIdx[i][count + pu]
> = mvpIdx[i][d];
> +                            (analysis->interData)->refIdx[i][count + pu]
> = refIdx[i][d];
>                              if (m_param->scaleFactor)
>                              {
>                                  mv[i][d].x *=
> (int16_t)m_param->scaleFactor;
>                                  mv[i][d].y *=
> (int16_t)m_param->scaleFactor;
>                              }
> -                            memcpy(&((analysis_inter_data
> *)analysis->interData)->mv[i][count + pu], &mv[i][d], sizeof(MV));
> +                            memcpy(&(analysis->interData)->mv[i][count +
> pu], &mv[i][d], sizeof(MV));
>                          }
>                      }
>                  }
>                  if (m_param->analysisReuseLevel == 10 && bIntraInInter)
> -                    memset(&((analysis_intra_data *)analysis->intraData)->chromaModes[count],
> chromaDir[d], bytes);
> +                    memset(&(analysis->intraData)->chromaModes[count],
> chromaDir[d], bytes);
>              }
>              count += bytes;
>          }
> @@ -3438,20 +3438,20 @@
>              {
>                  if (!m_param->scaleFactor)
>                  {
> -                    X265_FREAD(((analysis_intra_data
> *)analysis->intraData)->modes, sizeof(uint8_t), analysis->numCUsInFrame *
> analysis->numPartitions, m_analysisFileIn, intraPic->modes);
> +                    X265_FREAD((analysis->intraData)->modes,
> sizeof(uint8_t), analysis->numCUsInFrame * analysis->numPartitions,
> m_analysisFileIn, intraPic->modes);
>                  }
>                  else
>                  {
>                      uint8_t *tempLumaBuf = X265_MALLOC(uint8_t,
> analysis->numCUsInFrame * scaledNumPartition);
>                      X265_FREAD(tempLumaBuf, sizeof(uint8_t),
> analysis->numCUsInFrame * scaledNumPartition, m_analysisFileIn,
> intraPic->modes);
>                      for (uint32_t ctu32Idx = 0, cnt = 0; ctu32Idx <
> analysis->numCUsInFrame * scaledNumPartition; ctu32Idx++, cnt += factor)
> -                        memset(&((analysis_intra_data
> *)analysis->intraData)->modes[cnt], tempLumaBuf[ctu32Idx], factor);
> +                        memset(&(analysis->intraData)->modes[cnt],
> tempLumaBuf[ctu32Idx], factor);
>                      X265_FREE(tempLumaBuf);
>                  }
>              }
>          }
>          else
> -            X265_FREAD(((analysis_inter_data
> *)analysis->interData)->ref, sizeof(int32_t), analysis->numCUsInFrame *
> X265_MAX_PRED_MODE_PER_CTU * numDir, m_analysisFileIn, interPic->ref);
> +            X265_FREAD((analysis->interData)->ref, sizeof(int32_t),
> analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU * numDir,
> m_analysisFileIn, interPic->ref);
>
>          consumedBytes += frameRecordSize;
>          if (numDir == 1)
> @@ -3482,8 +3482,8 @@
>          fseeko(m_analysisFileIn, totalConsumedBytes + paramBytes,
> SEEK_SET);
>
>      const x265_analysis_data *picData = &(picIn->analysisData);
> -    analysis_intra_data *intraPic = (analysis_intra_data
> *)picData->intraData;
> -    analysis_inter_data *interPic = (analysis_inter_data
> *)picData->interData;
> +    x265_analysis_intra_data *intraPic = picData->intraData;
> +    x265_analysis_inter_data *interPic = picData->interData;
>
>      int poc; uint32_t frameRecordSize;
>      X265_FREAD(&frameRecordSize, sizeof(uint32_t), 1, m_analysisFileIn,
> &(picData->frameRecordSize));
> @@ -3629,9 +3629,9 @@
>
>              for (int numCTU = 0; numCTU < numCTUCopied; numCTU++)
>              {
> -                memset(&((analysis_intra_data
> *)analysis->intraData)->depth[count], depthBuf[d], bytes);
> -                memset(&((analysis_intra_data *)analysis->intraData)->chromaModes[count],
> modeBuf[d], bytes);
> -                memset(&((analysis_intra_data *)analysis->intraData)->partSizes[count],
> partSizes[d], bytes);
> +                memset(&(analysis->intraData)->depth[count],
> depthBuf[d], bytes);
> +                memset(&(analysis->intraData)->chromaModes[count],
> modeBuf[d], bytes);
> +                memset(&(analysis->intraData)->partSizes[count],
> partSizes[d], bytes);
>                  count += bytes;
>                  d += getCUIndex(&cuLoc, &count, bytes, 1);
>              }
> @@ -3645,7 +3645,7 @@
>          uint32_t cnt = 0;
>          for (uint32_t ctu32Idx = 0; ctu32Idx < analysis->numCUsInFrame *
> scaledNumPartition; ctu32Idx++)
>          {
> -            memset(&((analysis_intra_data *)analysis->intraData)->modes[cnt],
> tempLumaBuf[ctu32Idx], factor);
> +            memset(&(analysis->intraData)->modes[cnt],
> tempLumaBuf[ctu32Idx], factor);
>              cnt += factor;
>              ctu32Idx += getCUIndex(&cuLoc, &cnt, factor, 0);
>          }
> @@ -3728,10 +3728,10 @@
>
>              for (int numCTU = 0; numCTU < numCTUCopied; numCTU++)
>              {
> -                memset(&((analysis_inter_data
> *)analysis->interData)->depth[count], writeDepth, bytes);
> -                memset(&((analysis_inter_data
> *)analysis->interData)->modes[count], modeBuf[d], bytes);
> +                memset(&(analysis->interData)->depth[count], writeDepth,
> bytes);
> +                memset(&(analysis->interData)->modes[count], modeBuf[d],
> bytes);
>                  if (m_param->analysisReuseLevel == 10 && bIntraInInter)
> -                    memset(&((analysis_intra_data *)analysis->intraData)->chromaModes[count],
> chromaDir[d], bytes);
> +                    memset(&(analysis->intraData)->chromaModes[count],
> chromaDir[d], bytes);
>
>                  if (m_param->analysisReuseLevel > 4)
>                  {
> @@ -3742,7 +3742,7 @@
>                      int partitionSize = partSize[d];
>                      if (isScaledMaxCUSize && partSize[d] != SIZE_2Nx2N)
>                          partitionSize = getPuShape(&puOrient,
> partSize[d], numCTU);
> -                    memset(&((analysis_inter_data *)analysis->interData)->partSize[count],
> partitionSize, bytes);
> +                    memset(&(analysis->interData)->partSize[count],
> partitionSize, bytes);
>                      int numPU = (modeBuf[d] == MODE_INTRA) ? 1 :
> nbPartsTable[(int)partSize[d]];
>                      for (int pu = 0; pu < numPU; pu++)
>                      {
> @@ -3758,18 +3758,18 @@
>                          if (puOrient.isAmp && pu)
>                              d++;
>
> -                        ((analysis_inter_data *)analysis->interData)->mergeFlag[count
> + pu] = mergeFlag[d];
> +                        (analysis->interData)->mergeFlag[count + pu] =
> mergeFlag[d];
>                          if (m_param->analysisReuseLevel == 10)
>                          {
> -                            ((analysis_inter_data *)analysis->interData)->interDir[count
> + pu] = interDir[d];
> +                            (analysis->interData)->interDir[count + pu]
> = interDir[d];
>                              MV mvCopy[2];
>                              for (uint32_t i = 0; i < numDir; i++)
>                              {
> -                                ((analysis_inter_data
> *)analysis->interData)->mvpIdx[i][count + pu] = mvpIdx[i][d];
> -                                ((analysis_inter_data
> *)analysis->interData)->refIdx[i][count + pu] = refIdx[i][d];
> +                                (analysis->interData)->mvpIdx[i][count +
> pu] = mvpIdx[i][d];
> +                                (analysis->interData)->refIdx[i][count +
> pu] = refIdx[i][d];
>                                  mvCopy[i].x = mv[i][d].x *
> (int16_t)m_param->scaleFactor;
>                                  mvCopy[i].y = mv[i][d].y *
> (int16_t)m_param->scaleFactor;
> -                                memcpy(&((analysis_inter_data
> *)analysis->interData)->mv[i][count + pu], &mvCopy[i], sizeof(MV));
> +                                memcpy(&(analysis->interData)->mv[i][count
> + pu], &mvCopy[i], sizeof(MV));
>                              }
>                          }
>                          d = restoreD; // Restore d value after copying
> each of the 4 64x64 CTUs
> @@ -3810,7 +3810,7 @@
>                  uint32_t cnt = 0;
>                  for (uint32_t ctu32Idx = 0; ctu32Idx <
> analysis->numCUsInFrame * scaledNumPartition; ctu32Idx++)
>                  {
> -                    memset(&((analysis_intra_data
> *)analysis->intraData)->modes[cnt], tempLumaBuf[ctu32Idx], factor);
> +                    memset(&(analysis->intraData)->modes[cnt],
> tempLumaBuf[ctu32Idx], factor);
>                      cnt += factor;
>                      ctu32Idx += getCUIndex(&cuLoc, &cnt, factor, 0);
>                  }
> @@ -3818,7 +3818,7 @@
>              }
>          }
>          else
> -            X265_FREAD(((analysis_inter_data
> *)analysis->interData)->ref, sizeof(int32_t), analysis->numCUsInFrame *
> X265_MAX_PRED_MODE_PER_CTU * numDir, m_analysisFileIn, interPic->ref);
> +            X265_FREAD((analysis->interData)->ref, sizeof(int32_t),
> analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU * numDir,
> m_analysisFileIn, interPic->ref);
>
>          consumedBytes += frameRecordSize;
>          if (numDir == 1)
> @@ -4078,9 +4078,9 @@
>      depthBuf = tempBuf;
>      distortionBuf = tempdistBuf;
>      x265_analysis_data *analysisData = (x265_analysis_data*)analysis;
> -    analysis_intra_data *intraData = (analysis_intra_data
> *)analysisData->intraData;
> -    analysis_inter_data *interData = (analysis_inter_data
> *)analysisData->interData;
> -    analysisDistortionData *distortionData = (analysisDistortionData
> *)analysisData->distortionData;
> +    x265_analysis_intra_data *intraData = analysisData->intraData;
> +    x265_analysis_inter_data *interData = analysisData->interData;
> +    x265_analysis_distortion_data *distortionData =
> analysisData->distortionData;
>
>      size_t count = 0;
>      uint32_t ctuCount = 0;
> @@ -4147,15 +4147,15 @@
>              size_t bytes = analysis->numPartitions >> (depthBuf[d] * 2);
>              for (int i = 0; i < numDir; i++)
>              {
> -                int32_t* ref = &((analysis_inter_data*)analysis->interData)->ref[i
> * analysis->numPartitions * analysis->numCUsInFrame];
> +                int32_t* ref = &(analysis->interData)->ref[i *
> analysis->numPartitions * analysis->numCUsInFrame];
>                  for (size_t j = count, k = 0; k < bytes; j++, k++)
>                  {
> -                    memcpy(&((analysis_inter_data*
> )analysis->interData)->mv[i][j], MVBuf[i] + d, sizeof(MV));
> -                    memcpy(&((analysis_inter_data*
> )analysis->interData)->mvpIdx[i][j], mvpBuf[i] + d, sizeof(uint8_t));
> +                    memcpy(&(analysis->interData)->mv[i][j], MVBuf[i] +
> d, sizeof(MV));
> +                    memcpy(&(analysis->interData)->mvpIdx[i][j],
> mvpBuf[i] + d, sizeof(uint8_t));
>                      memcpy(&ref[j], refBuf + (i * depthBytes) + d,
> sizeof(int32_t));
>                  }
>              }
> -            memset(&((analysis_inter_data *)analysis->interData)->modes[count],
> modeBuf[d], bytes);
> +            memset(&(analysis->interData)->modes[count], modeBuf[d],
> bytes);
>              count += bytes;
>          }
>
> @@ -4219,7 +4219,7 @@
>                  uint8_t partSize = 0;
>
>                  CUData* ctu = curEncData.getPicCTU(cuAddr);
> -                analysis_intra_data* intraDataCTU = (analysis_intra_data*)
> analysis->intraData;
> +                x265_analysis_intra_data* intraDataCTU =
> analysis->intraData;
>
>                  for (uint32_t absPartIdx = 0; absPartIdx <
> ctu->m_numPartitions; depthBytes++)
>                  {
> @@ -4247,8 +4247,8 @@
>                  uint8_t partSize = 0;
>
>                  CUData* ctu = curEncData.getPicCTU(cuAddr);
> -                analysis_inter_data* interDataCTU = (analysis_inter_data*)
> analysis->interData;
> -                analysis_intra_data* intraDataCTU = (analysis_intra_data*)
> analysis->intraData;
> +                x265_analysis_inter_data* interDataCTU =
> analysis->interData;
> +                x265_analysis_intra_data* intraDataCTU =
> analysis->intraData;
>
>                  for (uint32_t absPartIdx = 0; absPartIdx <
> ctu->m_numPartitions; depthBytes++)
>                  {
> @@ -4281,7 +4281,9 @@
>                                  {
>                                      interDataCTU->mvpIdx[dir][depthBytes]
> = ctu->m_mvpIdx[dir][puabsPartIdx];
>                                      interDataCTU->refIdx[dir][depthBytes]
> = ctu->m_refIdx[dir][puabsPartIdx];
> -                                    interDataCTU->mv[dir][depthBytes] =
> ctu->m_mv[dir][puabsPartIdx];
> +                                    interDataCTU->mv[dir][depthBytes].x
> = ctu->m_mv[dir][puabsPartIdx].x;
> +                                    interDataCTU->mv[dir][depthBytes].y
> = ctu->m_mv[dir][puabsPartIdx].y;
> +                                    interDataCTU->mv[dir][depthBytes].word
> = ctu->m_mv[dir][puabsPartIdx].word;
>                                  }
>                              }
>                          }
> @@ -4339,35 +4341,35 @@
>
>      if (analysis->sliceType == X265_TYPE_IDR || analysis->sliceType ==
> X265_TYPE_I)
>      {
> -        X265_FWRITE(((analysis_intra_data*)analysis->intraData)->depth,
> sizeof(uint8_t), depthBytes, m_analysisFileOut);
> -        X265_FWRITE(((analysis_intra_data*)analysis->intraData)->chromaModes,
> sizeof(uint8_t), depthBytes, m_analysisFileOut);
> -        X265_FWRITE(((analysis_intra_data*)analysis->intraData)->partSizes,
> sizeof(char), depthBytes, m_analysisFileOut);
> -        X265_FWRITE(((analysis_intra_data*)analysis->intraData)->modes,
> sizeof(uint8_t), analysis->numCUsInFrame * analysis->numPartitions,
> m_analysisFileOut);
> +        X265_FWRITE((analysis->intraData)->depth, sizeof(uint8_t),
> depthBytes, m_analysisFileOut);
> +        X265_FWRITE((analysis->intraData)->chromaModes, sizeof(uint8_t),
> depthBytes, m_analysisFileOut);
> +        X265_FWRITE((analysis->intraData)->partSizes, sizeof(char),
> depthBytes, m_analysisFileOut);
> +        X265_FWRITE((analysis->intraData)->modes, sizeof(uint8_t),
> analysis->numCUsInFrame * analysis->numPartitions, m_analysisFileOut);
>      }
>      else
>      {
> -        X265_FWRITE(((analysis_inter_data*)analysis->interData)->depth,
> sizeof(uint8_t), depthBytes, m_analysisFileOut);
> -        X265_FWRITE(((analysis_inter_data*)analysis->interData)->modes,
> sizeof(uint8_t), depthBytes, m_analysisFileOut);
> +        X265_FWRITE((analysis->interData)->depth, sizeof(uint8_t),
> depthBytes, m_analysisFileOut);
> +        X265_FWRITE((analysis->interData)->modes, sizeof(uint8_t),
> depthBytes, m_analysisFileOut);
>          if (m_param->analysisReuseLevel > 4)
>          {
> -            X265_FWRITE(((analysis_inter_data*)analysis->interData)->partSize,
> sizeof(uint8_t), depthBytes, m_analysisFileOut);
> -            X265_FWRITE(((analysis_inter_data*)analysis->interData)->mergeFlag,
> sizeof(uint8_t), depthBytes, m_analysisFileOut);
> +            X265_FWRITE((analysis->interData)->partSize,
> sizeof(uint8_t), depthBytes, m_analysisFileOut);
> +            X265_FWRITE((analysis->interData)->mergeFlag,
> sizeof(uint8_t), depthBytes, m_analysisFileOut);
>              if (m_param->analysisReuseLevel == 10)
>              {
> -                X265_FWRITE(((analysis_inter_data*)analysis->interData)->interDir,
> sizeof(uint8_t), depthBytes, m_analysisFileOut);
> -                if (bIntraInInter) X265_FWRITE(((analysis_intra_
> data*)analysis->intraData)->chromaModes, sizeof(uint8_t), depthBytes,
> m_analysisFileOut);
> +                X265_FWRITE((analysis->interData)->interDir,
> sizeof(uint8_t), depthBytes, m_analysisFileOut);
> +                if (bIntraInInter) X265_FWRITE((analysis->intraData)->chromaModes,
> sizeof(uint8_t), depthBytes, m_analysisFileOut);
>                  for (uint32_t dir = 0; dir < numDir; dir++)
>                  {
> -                    X265_FWRITE(((analysis_inter_
> data*)analysis->interData)->mvpIdx[dir], sizeof(uint8_t), depthBytes,
> m_analysisFileOut);
> -                    X265_FWRITE(((analysis_inter_
> data*)analysis->interData)->refIdx[dir], sizeof(int8_t), depthBytes,
> m_analysisFileOut);
> -                    X265_FWRITE(((analysis_inter_
> data*)analysis->interData)->mv[dir], sizeof(MV), depthBytes,
> m_analysisFileOut);
> +                    X265_FWRITE((analysis->interData)->mvpIdx[dir],
> sizeof(uint8_t), depthBytes, m_analysisFileOut);
> +                    X265_FWRITE((analysis->interData)->refIdx[dir],
> sizeof(int8_t), depthBytes, m_analysisFileOut);
> +                    X265_FWRITE((analysis->interData)->mv[dir],
> sizeof(MV), depthBytes, m_analysisFileOut);
>                  }
>                  if (bIntraInInter)
> -                    X265_FWRITE(((analysis_intra_
> data*)analysis->intraData)->modes, sizeof(uint8_t),
> analysis->numCUsInFrame * analysis->numPartitions, m_analysisFileOut);
> +                    X265_FWRITE((analysis->intraData)->modes,
> sizeof(uint8_t), analysis->numCUsInFrame * analysis->numPartitions,
> m_analysisFileOut);
>              }
>          }
>          if (m_param->analysisReuseLevel != 10)
> -            X265_FWRITE(((analysis_inter_data*)analysis->interData)->ref,
> sizeof(int32_t), analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU *
> numDir, m_analysisFileOut);
> +            X265_FWRITE((analysis->interData)->ref, sizeof(int32_t),
> analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU * numDir,
> m_analysisFileOut);
>
>      }
>  #undef X265_FWRITE
> @@ -4386,10 +4388,9 @@
>
>      uint32_t depthBytes = 0;
>      x265_analysis_data *analysisData = (x265_analysis_data*)analysis;
> -    analysis_intra_data *intraData = (analysis_intra_data
> *)analysisData->intraData;
> -    analysis_inter_data *interData = (analysis_inter_data
> *)analysisData->interData;
> -    analysisDistortionData *distortionData = (analysisDistortionData
> *)analysisData->distortionData;
> -
> +    x265_analysis_intra_data *intraData = analysisData->intraData;
> +    x265_analysis_inter_data *interData = analysisData->interData;
> +    x265_analysis_distortion_data *distortionData =
> analysisData->distortionData;
>
>      for (uint32_t cuAddr = 0; cuAddr < analysis->numCUsInFrame; cuAddr++)
>      {
> @@ -4412,8 +4413,8 @@
>      if (curEncData.m_slice->m_sliceType != I_SLICE)
>      {
>          int32_t* ref[2];
> -        ref[0] = ((analysis_inter_data*)analysis->interData)->ref;
> -        ref[1] = &((analysis_inter_data*)analysis->interData)->ref[analysis->numPartitions
> * analysis->numCUsInFrame];
> +        ref[0] = (analysis->interData)->ref;
> +        ref[1] = &(analysis->interData)->ref[analysis->numPartitions *
> analysis->numCUsInFrame];
>          depthBytes = 0;
>          for (uint32_t cuAddr = 0; cuAddr < analysis->numCUsInFrame;
> cuAddr++)
>          {
> @@ -4424,13 +4425,17 @@
>              for (uint32_t absPartIdx = 0; absPartIdx <
> ctu->m_numPartitions; depthBytes++)
>              {
>                  depth = ctu->m_cuDepth[absPartIdx];
> -                interData->mv[0][depthBytes] = ctu->m_mv[0][absPartIdx];
> +                interData->mv[0][depthBytes].x =
> ctu->m_mv[0][absPartIdx].x;
> +                interData->mv[0][depthBytes].y =
> ctu->m_mv[0][absPartIdx].y;
> +                interData->mv[0][depthBytes].word =
> ctu->m_mv[0][absPartIdx].word;
>                  interData->mvpIdx[0][depthBytes] =
> ctu->m_mvpIdx[0][absPartIdx];
>                  ref[0][depthBytes] = ctu->m_refIdx[0][absPartIdx];
>                  predMode = ctu->m_predMode[absPartIdx];
>                  if (ctu->m_refIdx[1][absPartIdx] != -1)
>                  {
> -                    interData->mv[1][depthBytes] =
> ctu->m_mv[1][absPartIdx];
> +                    interData->mv[1][depthBytes].x =
> ctu->m_mv[1][absPartIdx].x;
> +                    interData->mv[1][depthBytes].y =
> ctu->m_mv[1][absPartIdx].y;
> +                    interData->mv[1][depthBytes].word =
> ctu->m_mv[1][absPartIdx].word;
>                      interData->mvpIdx[1][depthBytes] =
> ctu->m_mvpIdx[1][absPartIdx];
>                      ref[1][depthBytes] = ctu->m_refIdx[1][absPartIdx];
>                      predMode = 4; // used as indiacator if the block is
> coded as bidir
> @@ -4459,11 +4464,11 @@
>      X265_FWRITE(&analysis->poc, sizeof(uint32_t), 1, m_analysisFileOut);
>      if (curEncData.m_slice->m_sliceType == I_SLICE)
>      {
> -        X265_FWRITE(((analysis_intra_data*)analysis->intraData)->depth,
> sizeof(uint8_t), depthBytes, m_analysisFileOut);
> +        X265_FWRITE((analysis->intraData)->depth, sizeof(uint8_t),
> depthBytes, m_analysisFileOut);
>      }
>      else
>      {
> -        X265_FWRITE(((analysis_inter_data*)analysis->interData)->depth,
> sizeof(uint8_t), depthBytes, m_analysisFileOut);
> +        X265_FWRITE((analysis->interData)->depth, sizeof(uint8_t),
> depthBytes, m_analysisFileOut);
>      }
>      X265_FWRITE(distortionData->distortion, sizeof(sse_t), depthBytes,
> m_analysisFileOut);
>      if (curEncData.m_slice->m_sliceType != I_SLICE)
> @@ -4471,12 +4476,12 @@
>          int numDir = curEncData.m_slice->m_sliceType == P_SLICE ? 1 : 2;
>          for (int i = 0; i < numDir; i++)
>          {
> -            int32_t* ref = &((analysis_inter_data*)analysis->interData)->ref[i
> * analysis->numPartitions * analysis->numCUsInFrame];
> +            int32_t* ref = &(analysis->interData)->ref[i *
> analysis->numPartitions * analysis->numCUsInFrame];
>              X265_FWRITE(interData->mv[i], sizeof(MV), depthBytes,
> m_analysisFileOut);
>              X265_FWRITE(interData->mvpIdx[i], sizeof(uint8_t),
> depthBytes, m_analysisFileOut);
>              X265_FWRITE(ref, sizeof(int32_t), depthBytes,
> m_analysisFileOut);
>          }
> -        X265_FWRITE(((analysis_inter_data*)analysis->interData)->modes,
> sizeof(uint8_t), depthBytes, m_analysisFileOut);
> +        X265_FWRITE((analysis->interData)->modes, sizeof(uint8_t),
> depthBytes, m_analysisFileOut);
>      }
>  #undef X265_FWRITE
>  }
> diff -r fb1530b0e1b4 -r 9694dfbe83ac source/encoder/search.cpp
> --- a/source/encoder/search.cpp Fri Jul 20 14:20:22 2018 +0530
> +++ b/source/encoder/search.cpp Fri Jul 20 14:03:53 2018 +0530
> @@ -2178,12 +2178,12 @@
>          PredictionUnit pu(cu, cuGeom, puIdx);
>          m_me.setSourcePU(*interMode.fencYuv, pu.ctuAddr,
> pu.cuAbsPartIdx, pu.puAbsPartIdx, pu.width, pu.height,
> m_param->searchMethod, m_param->subpelRefine, bChromaMC);
>          useAsMVP = false;
> -        analysis_inter_data* interDataCTU = NULL;
> +        x265_analysis_inter_data* interDataCTU = NULL;
>          int cuIdx;
>          cuIdx = (interMode.cu.m_cuAddr * m_param->num4x4Partitions) +
> cuGeom.absPartIdx;
>          if (m_param->analysisReuseLevel == 10 && m_param->interRefine > 1)
>          {
> -            interDataCTU = (analysis_inter_data*)m_frame-
> >m_analysisData.interData;
> +            interDataCTU = m_frame->m_analysisData.interData;
>              if ((cu.m_predMode[pu.puAbsPartIdx] ==
> interDataCTU->modes[cuIdx + pu.puAbsPartIdx])
>                  && (cu.m_partSize[pu.puAbsPartIdx] ==
> interDataCTU->partSize[cuIdx + pu.puAbsPartIdx])
>                  && !(interDataCTU->mergeFlag[cuIdx + puIdx])
> @@ -2225,7 +2225,9 @@
>                  MV mvmin, mvmax, outmv, mvp;
>                  if (useAsMVP)
>                  {
> -                    mvp = interDataCTU->mv[list][cuIdx + puIdx];
> +                    mvp.x = interDataCTU->mv[list][cuIdx + puIdx].x;
> +                    mvp.y = interDataCTU->mv[list][cuIdx + puIdx].y;
> +                    mvp.word = interDataCTU->mv[list][cuIdx + puIdx].word;
>                      mvpIdx = interDataCTU->mvpIdx[list][cuIdx + puIdx];
>                  }
>                  else
> diff -r fb1530b0e1b4 -r 9694dfbe83ac source/x265.h
> --- a/source/x265.h     Fri Jul 20 14:20:22 2018 +0530
> +++ b/source/x265.h     Fri Jul 20 14:03:53 2018 +0530
> @@ -26,11 +26,16 @@
>  #define X265_H
>  #include <stdint.h>
>  #include <stdio.h>
> +#include <stdbool.h>
>  #include "x265_config.h"
>  #ifdef __cplusplus
>  extern "C" {
>  #endif
>
> +#if _MSC_VER
> +#pragma warning(disable: 4201) // non-standard extension used (nameless
> struct/union)
> +#endif
> +
>  /* x265_encoder:
>   *      opaque handler for encoder */
>  typedef struct x265_encoder x265_encoder;
> @@ -127,25 +132,85 @@
>      int     chunkEnd;
>  }x265_analysis_validate;
>
> +/* Stores intra analysis data for a single frame. This struct needs
> better packing */
> +typedef struct x265_analysis_intra_data
> +{
> +    uint8_t*  depth;
> +    uint8_t*  modes;
> +    char*     partSizes;
> +    uint8_t*  chromaModes;
> +}x265_analysis_intra_data;
> +
> +typedef struct x265_analysis_MV
> +{
> +    union{
> +        struct { int16_t x, y; };
> +
> +        int32_t word;
> +    };
> +}x265_analysis_MV;
> +
> +/* Stores inter analysis data for a single frame */
> +typedef struct x265_analysis_inter_data
> +{
> +    int32_t*    ref;
> +    uint8_t*    depth;
> +    uint8_t*    modes;
> +    uint8_t*    partSize;
> +    uint8_t*    mergeFlag;
> +    uint8_t*    interDir;
> +    uint8_t*    mvpIdx[2];
> +    int8_t*     refIdx[2];
> +    x265_analysis_MV*         mv[2];
> +    int64_t*     sadCost;
> +}x265_analysis_inter_data;
> +
> +typedef struct x265_weight_param
> +{
> +    uint32_t log2WeightDenom;
> +    int      inputWeight;
> +    int      inputOffset;
> +    bool     bPresentFlag;
> +}x265_weight_param;
> +
> +#if X265_DEPTH < 10
> +typedef uint32_t sse_t;
> +#else
> +typedef uint64_t sse_t;
> +#endif
> +
> +typedef struct x265_analysis_distortion_data
> +{
> +    sse_t*        distortion;
> +    sse_t*        ctuDistortion;
> +    double*       scaledDistortion;
> +    double        averageDistortion;
> +    double        sdDistortion;
> +    uint32_t      highDistortionCtuCount;
> +    uint32_t      lowDistortionCtuCount;
> +    double*       offset;
> +    double*       threshold;
> +}x265_analysis_distortion_data;
> +
>  /* Stores all analysis data for a single frame */
>  typedef struct x265_analysis_data
>  {
> -    int64_t          satdCost;
> -    uint32_t         frameRecordSize;
> -    uint32_t         poc;
> -    uint32_t         sliceType;
> -    uint32_t         numCUsInFrame;
> -    uint32_t         numPartitions;
> -    uint32_t         depthBytes;
> -    int              bScenecut;
> -    void*            wt;
> -    void*            interData;
> -    void*            intraData;
> -    uint32_t         numCuInHeight;
> -    x265_lookahead_data lookahead;
> -    uint8_t*         modeFlag[2];
> -    x265_analysis_validate saveParam;
> -    void*            distortionData;
> +    int64_t                           satdCost;
> +    uint32_t                          frameRecordSize;
> +    uint32_t                          poc;
> +    uint32_t                          sliceType;
> +    uint32_t                          numCUsInFrame;
> +    uint32_t                          numPartitions;
> +    uint32_t                          depthBytes;
> +    int                               bScenecut;
> +    x265_weight_param*                wt;
> +    x265_analysis_inter_data*         interData;
> +    x265_analysis_intra_data*         intraData;
> +    uint32_t                          numCuInHeight;
> +    x265_lookahead_data               lookahead;
> +    uint8_t*                          modeFlag[2];
> +    x265_analysis_validate            saveParam;
> +    x265_analysis_distortion_data*    distortionData;
>  } x265_analysis_data;
>
>  /* cu statistics */
> @@ -1756,7 +1821,7 @@
>  /* x265_build_info:
>   *      A static string describing the compiler and target architecture */
>  X265_API extern const char *x265_build_info_str;
> -
> +
>  /* x265_alloc_analysis_data:
>  *     Allocate memory for the x265_analysis_data object's internal
> structures. */
>  void x265_alloc_analysis_data(x265_param *param, x265_analysis_data*
> analysis);
>
> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
>
>
Pushed to default.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20180720/f1cdc7d5/attachment-0001.html>


More information about the x265-devel mailing list