转:x264 MB 宏块接口提取

一、X264_t 结构体(在x264的整个编码过程都存在)

大概分一下几个部分

1、  x264_param_t结构体 编码参数 包括默认参数和用户输入参数

2、  out_t substruct  bit 流的输出信息例如nal 打包,文件大小,数据的首地址

3、  同步信息  例如 frame number/poc

4、  X264_sps_t 只有一个 视频序列参数信息

5、  X264_pps_t 同上 视频图像参数集

6、  编码解码 量化矩阵指针数组

7、  亮度量化信息到色度量化信息的映射表格

8、  Slice header 条带头 包含条带的共同信息 例如条带类型 、图像参数id

9、  CABAC 编码context (不用可以删掉)

10、  frames substructure 信息包括 current、next、unused  最近的IDR

11、  fenc fdec 指向当前编码 重建帧的地址

12、  参考列表fref0 fref1 的相关信息

13、  MB DCT coeffs  (DCT矩阵)

14、  宏块信息 MB的包括当前帧的宏块信息、当前块的宏块信息(待会详细介绍)

15、  X264-ratecontrol_t 码率控制信息只有编码的时候用到

16、  编码器的状态值(stats) 例如当前帧的状态 mb-count 、mb_type_count 、cost slice info (slice_qp、 PSRN、)

17、  CPU函数 *_function_t (pixf 、mc 、zigzag、dctf、loopf)

二、MB 接口分离

1、  编码一个宏块需要的写入bit stream的信息

Mb_type 、cbp、 mb_qp、 luma_pred-mode 、chroma_pred_ mode 、subMB (sub –mb-type 、sub-pred-pre-mode 、reflist (0,1))(帧间) ref-list(0,1)

2、  MB 结构体的定义

struct

    {

        int     i_mb_count;     当前帧或slice中宏块的总数

 

        /* Strides */

        int     i_mb_stride;//以16x16宏块为宽度的图像的宽度 (就是图像一行有几个宏块)

        int     i_b8_stride;

        int     i_b4_stride;

 

        /* Current index */

        int     i_mb_x;   当前宏块在X坐标上的位置

        int     i_mb_y;    当前宏块在Y坐标轴上的位置

        int     i_mb_xy;    当前宏块是第几个宏块

        int     i_b8_xy;    以8X8的时候是第几个宏块 (目的是为了计算出他相邻的宏块的位置,找到相邻宏块的相关信息,以此来估计当前宏块的处理方式)

        int     i_b4_xy;(同上)

 

        /* Search parameters */

        int     i_me_method; luma运动估计方法

        int     i_subpel_refine;  运动估计的精度

        int     b_chroma_me;  色度是否进行运动估计

        int     b_trellis;//  ?

        int     b_noise_reduction;//  是否进行降噪处理

        int     i_psy_rd; /* Psy RD strength--fixed point value*/ ?

        int     i_psy_trellis; /* Psy trellis strength--fixed point value*/?

 

        int     b_interlaced; 是否进行宏块级帧场自适应编码

 

        /* Allowed qpel MV range to stay within the picture + emulated edge pixels */

        int     mv_min[2];       MV的范围

        int     mv_max[2];

        /* Subpel MV range for motion search.

         * same mv_min/max but includes levels' i_mv_range. */

        int     mv_min_spel[2];    半像素的范围

        int     mv_max_spel[2];

        /* Fullpel MV range for motion search */

        int     mv_min_fpel[2];     整像素的搜索范围

        int     mv_max_fpel[2];

 

        /* neighboring MBs */    相邻宏块的信息 是否可用

        unsigned int i_neighbour;

        unsigned int i_neighbour8[4];       /* neighbours of each 8x8 or 4x4 block that are available */

        unsigned int i_neighbour4[16];      /* at the time the block is coded */

        int     i_mb_type_top;

        int     i_mb_type_left;

        int     i_mb_type_topleft;

        int     i_mb_type_topright;

        int     i_mb_prev_xy;

        int     i_mb_top_xy;

 

        /**** thread synchronization ends here ****/

        /* subsequent variables are either thread-local or constant,

         * and won't be copied from one thread to another */

 

        /* mb table */

       int8_t  *type; 指向一个存储其他已经确定宏块类型的宏块类型表格   /* mb type */

        int8_t  *qp;     同上,不过这里是存储的量化参数 /* mb qp */

        int16_t *cbp;   同上 这里是宏块残差的编码方式  /* mb cbp: 0x0?: luma, 0x?0: chroma, 0x100: luma dc, 0x0200 and 0x0400: chroma dc  (all set for PCM)*/

        int8_t  (*intra4x4_pred_mode)[8]; 每个宏块预测模式  /* intra4x4 pred mode. for non I4x4 set to I_PRED_4x4_DC(2) actually has only 7 entries; set to 8 for write-combining optimizations */

        uint8_t (*non_zero_count)[16+4+4]; 每个宏块的非零系数 /* nzc. for I_PCM set to 16 */

        int8_t  *chroma_pred_mode;   每个宏块色度的预测模式/* chroma_pred_mode. cabac only. for non intra I_PRED_CHROMA_DC(0) */

帧间时用到的运动估计的向量

        int16_t (*mv[2])[2];  每个 实际的mv   /* mb mv. set to 0 for intra mb */

        int16_t (*mvd[2])[2];  每个 残差             /* mb mv difference with predict. set to 0 if intra. cabac only */

        int8_t   *ref[2];   参考列表的指针  /* mb ref. set to -1 if non used (intra or Lx only) */

        int16_t (*mvr[2][32])[2];           /* 16x16 mv for each possible ref */

        int8_t  *skipbp;         /* block pattern for SKIP or DIRECT (sub)mbs. B-frames + cabac only */

        int8_t  *mb_transform_size;         /* transform_size_8x8_flag of each mb */

        uint8_t *intra_border_backup[2][3]; /* bottom pixels of the previous mb row, used for intra prediction after the framebuffer has been deblocked */

        uint8_t (*nnz_backup)[16];          /* when using cavlc + 8x8dct, the deblocker uses a modified nnz */

以上是每个宏块都有的

        /* current value */

        int     i_type; //当前宏块的类型

        int     i_partition;// 当前宏块的划分模式

        DECLARE_ALIGNED_4( uint8_t i_sub_partition[4] );子宏块的划分模式

        int     b_transform_8x8; 是否8X8变化

 

        int     i_cbp_luma;  /*亮度数据残差编码模式*/

        int     i_cbp_chroma; 当前宏块的色度残差编码模式

 

        int     i_intra16x16_pred_mode;// 当前宏块帧内预测模式

        int     i_chroma_pred_mode; //

 

        /* skip flags for i4x4 and i8x8

         * 0 = encode as normal.

         * 1 (non-RD only) = the DCT is still in h->dct, restore fdec and skip reconstruction.

         * 2 (RD only) = the DCT has since been overwritten by RD; restore that too. */

        int i_skip_intra;  帧内跳编

        /* skip flag for motion compensation */

        /* if we've already done MC, we don't need to do it again */

        int b_skip_mc; sikp的运动补偿

 

        struct

        {

            /* space for p_fenc and p_fdec */

#define FENC_STRIDE 16

#define FDEC_STRIDE 32

            DECLARE_ALIGNED_16( uint8_t fenc_buf[24*FENC_STRIDE] );

            DECLARE_ALIGNED_16( uint8_t fdec_buf[27*FDEC_STRIDE] );

 

            /* i4x4 and i8x8 backup data, for skipping the encode stage when possible */备份数据 不知道什么时候用暂且不考虑

            DECLARE_ALIGNED_16( uint8_t i4x4_fdec_buf[16*16] );

            DECLARE_ALIGNED_16( uint8_t i8x8_fdec_buf[16*16] );

            DECLARE_ALIGNED_16( int16_t i8x8_dct_buf[3][64] );

            DECLARE_ALIGNED_16( int16_t i4x4_dct_buf[15][16] );

            uint32_t i4x4_nnz_buf[4];

            uint32_t i8x8_nnz_buf[4];

            int i4x4_cbp;

            int i8x8_cbp;

 

            /* Psy trellis DCT data */

            DECLARE_ALIGNED_16( int16_t fenc_dct8[4][64] );

            DECLARE_ALIGNED_16( int16_t fenc_dct4[16][16] );

 

            /* Psy RD SATD scores */  计算cost的时候用到的中间变量

            int fenc_satd[4][4];

            int fenc_satd_sum;

            int fenc_sa8d[2][2];

            int fenc_sa8d_sum;

 

            /* pointer over mb of the frame to be compressed */

            uint8_t *p_fenc[3];  将要编码的宏块的指针

            /* pointer to the actual source frame, not a block copy */

            uint8_t *p_fenc_plane[3]; 元数据

 

            /* pointer over mb of the frame to be reconstructed  */

            uint8_t *p_fdec[3]; 重建宏块的的存储地址

 

           /* pointer over mb of the references */   指向参考帧的参考宏块的指针

            int i_fref[2];

            uint8_t *p_fref[2][32][4+2]; /* last: lN, lH, lV, lHV, cU, cV */

            uint16_t *p_integral[2][16];

 

            /* fref stride */

            int     i_stride[3];

        } pic;

 

        /* cache */进行预测模式选择的时候需要的缓存空间

        struct

        {

            /* real intra4x4_pred_mode if I_4X4 or I_8X8, I_PRED_4x4_DC if mb available, -1 if not */

            int8_t  intra4x4_pred_mode[X264_SCAN8_SIZE];

 

            /* i_non_zero_count if available else 0x80 */

            uint8_t non_zero_count[X264_SCAN8_SIZE];

 

            /* -1 if unused, -2 if unavailable */

            DECLARE_ALIGNED_4( int8_t ref[2][X264_SCAN8_SIZE] );

 

            /* 0 if not available */

            DECLARE_ALIGNED_16( int16_t mv[2][X264_SCAN8_SIZE][2] );

            DECLARE_ALIGNED_8( int16_t mvd[2][X264_SCAN8_SIZE][2] );

 

            /* 1 if SKIP or DIRECT. set only for B-frames + CABAC */

            DECLARE_ALIGNED_4( int8_t skip[X264_SCAN8_SIZE] );

 

            DECLARE_ALIGNED_16( int16_t direct_mv[2][X264_SCAN8_SIZE][2] );

            DECLARE_ALIGNED_4( int8_t  direct_ref[2][X264_SCAN8_SIZE] );

            DECLARE_ALIGNED_4( int16_t pskip_mv[2] );

 

            /* number of neighbors (top and left) that used 8x8 dct */

            int     i_neighbour_transform_size;

            int     i_neighbour_interlaced; 帧场自适应编码

 

          

            int     i_cbp_top;  // 邻居的残差数据编码模式

            int     i_cbp_left;

        } cache;

 

        /* 码率控制*/   量化参数

        int     i_qp;       /* current qp */

        int     i_chroma_qp;

        int     i_last_qp;  /* last qp */ 上一量化参数

        int     i_last_dqp; /* last delta qp */  量化参数差

        int     b_variable_qp; /* whether qp is allowed to vary per macroblock */

        int     b_lossless;  是否无损编码

        int     b_direct_auto_read; /* take stats for --direct auto from the 2pass log */

        int     b_direct_auto_write; /* analyse direct modes, to use and/or save */

 

        /* B_direct and weighted prediction */

        int16_t dist_scale_factor[16][2];   加权预测

        int16_t bipred_weight[32][4];

        /* maps fref1[0]'s ref indices into the current list0 */

        int8_t  map_col_to_list0_buf[2]; // for negative indices

        int8_t  map_col_to_list0[16];

    } mb;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值