ffmpeg重要結構體之HEVCContext和HEVCFrame


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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章