HEVCContext和HEVCFrame是ffmpeg的HEVC解码中非常重要的结构体。
首先来看下HEVCContext,定义位于libavcodec\Hevc.h中。代码如下:
typedef struct HEVCContext { const AVClass *c; // needed by private avoptions AVCodecContext *avctx; struct HEVCContext *sList[MAX_NB_THREADS]; HEVCLocalContext *HEVClcList[MAX_NB_THREADS]; HEVCLocalContext *HEVClc; uint8_t threads_type; uint8_t threads_number; int width; int height; uint8_t *cabac_state; /** 1 if the independent slice segment header was successfully parsed */ uint8_t slice_initialized; AVFrame *frame; AVFrame *output_frame; uint8_t *sao_pixel_buffer_h[3]; uint8_t *sao_pixel_buffer_v[3]; HEVCParamSets ps; AVBufferPool *tab_mvf_pool; AVBufferPool *rpl_tab_pool; ///< candidate references for the current frame RefPicList rps[5]; SliceHeader sh; SAOParams *sao; DBParams *deblock; enum NALUnitType nal_unit_type; int temporal_id; ///< temporal_id_plus1 - 1 HEVCFrame *ref; HEVCFrame DPB[32]; int poc; int pocTid0; int slice_idx; ///< number of the slice being currently decoded int eos; ///< current packet contains an EOS/EOB NAL int last_eos; ///< last packet contains an EOS/EOB NAL int max_ra; int bs_width; int bs_height; int is_decoded; int no_rasl_output_flag; HEVCPredContext hpc; HEVCDSPContext hevcdsp; VideoDSPContext vdsp; BswapDSPContext bdsp; int8_t *qp_y_tab; uint8_t *horizontal_bs; uint8_t *vertical_bs; int32_t *tab_slice_address; // CU uint8_t *skip_flag; uint8_t *tab_ct_depth; // PU uint8_t *tab_ipm; uint8_t *cbf_luma; // cbf_luma of colocated TU uint8_t *is_pcm; // CTB-level flags affecting loop filter operation uint8_t *filter_slice_edges; /** used on BE to byteswap the lines for checksumming */ uint8_t *checksum_buf; int checksum_buf_size; /** * Sequence counters for decoded and output frames, so that old * frames are output first after a POC reset */ uint16_t seq_decode; uint16_t seq_output; int enable_parallel_tiles; int wpp_err; const uint8_t *data; HEVCPacket pkt; // type of the first VCL NAL of the current frame enum NALUnitType first_nal_type; // for checking the frame checksums struct AVMD5 *md5_ctx; uint8_t md5[3][16]; uint8_t is_md5; uint8_t context_initialized; uint8_t is_nalff; ///< this flag is != 0 if bitstream is encapsulated ///< as a format defined in 14496-15 int apply_defdispwin; int active_seq_parameter_set_id; int nal_length_size; ///< Number of bytes used for nal length (1, 2 or 4) int nuh_layer_id; /** frame packing arrangement variables */ int sei_frame_packing_present; int frame_packing_arrangement_type; int content_interpretation_type; int quincunx_subsampling; /** display orientation */ int sei_display_orientation_present; int sei_anticlockwise_rotation; int sei_hflip, sei_vflip; int picture_struct; } HEVCContext;
AVCodecContext *avctx:对应的codec上下文。
int width,height:图像宽高。
uint8_t *cabac_state:cabac的状态,算数编码相关。
uint8_t slice_initialized:根据注释,当解码到independent slice segment header时,置为1。
AVFrame *frame,*output_frame:图像存储结构体。
uint8_t *sao_pixel_buffer_h[3],sao_pixel_buffer_v[3]:SAO相关。
HEVCParamSets ps:HEVC参数集。成员包括存储VPS,SPS和PPS的buffer,和当前激活的VPS,SPS和PPS。
AVBufferPool *tab_mvf_pool:运动向量相关的buffer pool。
AVBufferPool *rpl_tab_pool:reference picture list的buffer pool。
RefPicList rps[5]:5个refPicList的candidate表格,在rps计算中使用。
SliceHeader sh:slice header结构体,存储slice header的信息。
SAOParams *sao:SAO的相关参数。
DBParams *deblock:Deblock的相关参数。
enum NALUnitType nal_unit_type:当前NAL的类型。
HEVCFrame *ref:存放参考帧,有待进一步的研究。
HEVCFrame DPB[32]:DecodePicBuffer。
int poc:picture order count
HEVCPredContext hpc:帧内预测上下文,包含intra pred的相关函数,之后会详细分析。
HEVCDSPContext hevcdsp:编解码计算上下文,包括变换,差值,滤波,SAO等的相关函数。
int8_t *qp_y_tab:存放亮度QP
uint8_t *horizontal_bs,*vertical_bs:水平和垂直方向的滤波强度。
int32_t *tab_slice_address:slice地址。
uint8_t *skip_flag:CU是否skip。
uint8_t *tab_ct_depth:CU的depth。
uint8_t *tab_ipm:存放intra pred mode
HEVCPacket pkt:存放packet信息的结构体,其中包含成员HEVCNAL *nals,存放packet中所有的nalu的信息。
enum NALUnitType first_nal_type:当前帧的第一个nal的类型。
结构体HECVFrame位于位于libavcodec\Hevc.h中。代码如下:
typedef struct HEVCFrame { AVFrame *frame; ThreadFrame tf; MvField *tab_mvf; RefPicList *refPicList; RefPicListTab **rpl_tab; int ctb_count; int poc; struct HEVCFrame *collocated_ref; HEVCWindow window; AVBufferRef *tab_mvf_buf; AVBufferRef *rpl_tab_buf; AVBufferRef *rpl_buf; AVBufferRef *hwaccel_priv_buf; void *hwaccel_picture_private; /** * A sequence counter, so that old frames are output first * after a POC reset */ uint16_t sequence; /** * A combination of HEVC_FRAME_FLAG_* */ uint8_t flags; } HEVCFrame;
MvField *tab_mvf:运动向量的tab
RefPicList *refPicList:备选参考帧的list
RefPicListTab **rpl_tab:备选参考帧的tab,(一个tab含有list0,list1)
int ctb_count:coding tree block的计数。
struct HEVCFrame *collocated_ref:collocated的参考帧
int poc:当前帧的poc