📄 h264.h
字号:
/* * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *//** * @file libavcodec/h264.h * H.264 / AVC / MPEG4 part10 codec. * @author Michael Niedermayer <michaelni@gmx.at> */#ifndef AVCODEC_H264_H#define AVCODEC_H264_H#include "dsputil.h"#include "cabac.h"#include "mpegvideo.h"#include "h264pred.h"#define interlaced_dct interlaced_dct_is_a_bad_name#define mb_intra mb_intra_is_not_initialized_see_mb_type#define LUMA_DC_BLOCK_INDEX 25#define CHROMA_DC_BLOCK_INDEX 26#define CHROMA_DC_COEFF_TOKEN_VLC_BITS 8#define COEFF_TOKEN_VLC_BITS 8#define TOTAL_ZEROS_VLC_BITS 9#define CHROMA_DC_TOTAL_ZEROS_VLC_BITS 3#define RUN_VLC_BITS 3#define RUN7_VLC_BITS 6#define MAX_SPS_COUNT 32#define MAX_PPS_COUNT 256#define MAX_MMCO_COUNT 66#define MAX_DELAYED_PIC_COUNT 16/* Compiling in interlaced support reduces the speed * of progressive decoding by about 2%. */#define ALLOW_INTERLACE#define ALLOW_NOCHROMA/** * The maximum number of slices supported by the decoder. * must be a power of 2 */#define MAX_SLICES 16#ifdef ALLOW_INTERLACE#define MB_MBAFF h->mb_mbaff#define MB_FIELD h->mb_field_decoding_flag#define FRAME_MBAFF h->mb_aff_frame#define FIELD_PICTURE (s->picture_structure != PICT_FRAME)#else#define MB_MBAFF 0#define MB_FIELD 0#define FRAME_MBAFF 0#define FIELD_PICTURE 0#undef IS_INTERLACED#define IS_INTERLACED(mb_type) 0#endif#define FIELD_OR_MBAFF_PICTURE (FRAME_MBAFF || FIELD_PICTURE)#ifdef ALLOW_NOCHROMA#define CHROMA h->sps.chroma_format_idc#else#define CHROMA 1#endif#define EXTENDED_SAR 255#define MB_TYPE_REF0 MB_TYPE_ACPRED //dirty but it fits in 16 bit#define MB_TYPE_8x8DCT 0x01000000#define IS_REF0(a) ((a) & MB_TYPE_REF0)#define IS_8x8DCT(a) ((a) & MB_TYPE_8x8DCT)/* NAL unit types */enum { NAL_SLICE=1, NAL_DPA, NAL_DPB, NAL_DPC, NAL_IDR_SLICE, NAL_SEI, NAL_SPS, NAL_PPS, NAL_AUD, NAL_END_SEQUENCE, NAL_END_STREAM, NAL_FILLER_DATA, NAL_SPS_EXT, NAL_AUXILIARY_SLICE=19};/** * SEI message types */typedef enum { SEI_BUFFERING_PERIOD = 0, ///< buffering period (H.264, D.1.1) SEI_TYPE_PIC_TIMING = 1, ///< picture timing SEI_TYPE_USER_DATA_UNREGISTERED = 5, ///< unregistered user data SEI_TYPE_RECOVERY_POINT = 6 ///< recovery point (frame # to decoder sync)} SEI_Type;/** * pic_struct in picture timing SEI message */typedef enum { SEI_PIC_STRUCT_FRAME = 0, ///< 0: %frame SEI_PIC_STRUCT_TOP_FIELD = 1, ///< 1: top field SEI_PIC_STRUCT_BOTTOM_FIELD = 2, ///< 2: bottom field SEI_PIC_STRUCT_TOP_BOTTOM = 3, ///< 3: top field, bottom field, in that order SEI_PIC_STRUCT_BOTTOM_TOP = 4, ///< 4: bottom field, top field, in that order SEI_PIC_STRUCT_TOP_BOTTOM_TOP = 5, ///< 5: top field, bottom field, top field repeated, in that order SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM = 6, ///< 6: bottom field, top field, bottom field repeated, in that order SEI_PIC_STRUCT_FRAME_DOUBLING = 7, ///< 7: %frame doubling SEI_PIC_STRUCT_FRAME_TRIPLING = 8 ///< 8: %frame tripling} SEI_PicStructType;/** * Sequence parameter set */typedef struct SPS{ int profile_idc; int level_idc; int chroma_format_idc; int transform_bypass; ///< qpprime_y_zero_transform_bypass_flag int log2_max_frame_num; ///< log2_max_frame_num_minus4 + 4 int poc_type; ///< pic_order_cnt_type int log2_max_poc_lsb; ///< log2_max_pic_order_cnt_lsb_minus4 int delta_pic_order_always_zero_flag; int offset_for_non_ref_pic; int offset_for_top_to_bottom_field; int poc_cycle_length; ///< num_ref_frames_in_pic_order_cnt_cycle int ref_frame_count; ///< num_ref_frames int gaps_in_frame_num_allowed_flag; int mb_width; ///< pic_width_in_mbs_minus1 + 1 int mb_height; ///< pic_height_in_map_units_minus1 + 1 int frame_mbs_only_flag; int mb_aff; ///<mb_adaptive_frame_field_flag int direct_8x8_inference_flag; int crop; ///< frame_cropping_flag unsigned int crop_left; ///< frame_cropping_rect_left_offset unsigned int crop_right; ///< frame_cropping_rect_right_offset unsigned int crop_top; ///< frame_cropping_rect_top_offset unsigned int crop_bottom; ///< frame_cropping_rect_bottom_offset int vui_parameters_present_flag; AVRational sar; int timing_info_present_flag; uint32_t num_units_in_tick; uint32_t time_scale; int fixed_frame_rate_flag; short offset_for_ref_frame[256]; //FIXME dyn aloc? int bitstream_restriction_flag; int num_reorder_frames; int scaling_matrix_present; uint8_t scaling_matrix4[6][16]; uint8_t scaling_matrix8[2][64]; int nal_hrd_parameters_present_flag; int vcl_hrd_parameters_present_flag; int pic_struct_present_flag; int time_offset_length; int cpb_cnt; ///< See H.264 E.1.2 int initial_cpb_removal_delay_length; ///< initial_cpb_removal_delay_length_minus1 +1 int cpb_removal_delay_length; ///< cpb_removal_delay_length_minus1 + 1 int dpb_output_delay_length; ///< dpb_output_delay_length_minus1 + 1 int bit_depth_luma; ///< bit_depth_luma_minus8 + 8 int bit_depth_chroma; ///< bit_depth_chroma_minus8 + 8 int residual_color_transform_flag; ///< residual_colour_transform_flag}SPS;/** * Picture parameter set */typedef struct PPS{ unsigned int sps_id; int cabac; ///< entropy_coding_mode_flag int pic_order_present; ///< pic_order_present_flag int slice_group_count; ///< num_slice_groups_minus1 + 1 int mb_slice_group_map_type; unsigned int ref_count[2]; ///< num_ref_idx_l0/1_active_minus1 + 1 int weighted_pred; ///< weighted_pred_flag int weighted_bipred_idc; int init_qp; ///< pic_init_qp_minus26 + 26 int init_qs; ///< pic_init_qs_minus26 + 26 int chroma_qp_index_offset[2]; int deblocking_filter_parameters_present; ///< deblocking_filter_parameters_present_flag int constrained_intra_pred; ///< constrained_intra_pred_flag int redundant_pic_cnt_present; ///< redundant_pic_cnt_present_flag int transform_8x8_mode; ///< transform_8x8_mode_flag uint8_t scaling_matrix4[6][16]; uint8_t scaling_matrix8[2][64]; uint8_t chroma_qp_table[2][64]; ///< pre-scaled (with chroma_qp_index_offset) version of qp_table int chroma_qp_diff;}PPS;/** * Memory management control operation opcode. */typedef enum MMCOOpcode{ MMCO_END=0, MMCO_SHORT2UNUSED, MMCO_LONG2UNUSED, MMCO_SHORT2LONG, MMCO_SET_MAX_LONG, MMCO_RESET, MMCO_LONG,} MMCOOpcode;/** * Memory management control operation. */typedef struct MMCO{ MMCOOpcode opcode; int short_pic_num; ///< pic_num without wrapping (pic_num & max_pic_num) int long_arg; ///< index, pic_num, or num long refs depending on opcode} MMCO;/** * H264Context */typedef struct H264Context{ MpegEncContext s; int nal_ref_idc; int nal_unit_type; uint8_t *rbsp_buffer[2]; unsigned int rbsp_buffer_size[2]; /** * Used to parse AVC variant of h264 */ int is_avc; ///< this flag is != 0 if codec is avc1 int got_avcC; ///< flag used to parse avcC data only once int nal_length_size; ///< Number of bytes used for nal length (1, 2 or 4) int chroma_qp[2]; //QPc int prev_mb_skipped; int next_mb_skipped; //prediction stuff int chroma_pred_mode; int intra16x16_pred_mode; int top_mb_xy; int left_mb_xy[2]; int8_t intra4x4_pred_mode_cache[5*8]; int8_t (*intra4x4_pred_mode)[8]; H264PredContext hpc; unsigned int topleft_samples_available; unsigned int top_samples_available; unsigned int topright_samples_available; unsigned int left_samples_available; uint8_t (*top_borders[2])[16+2*8]; uint8_t left_border[2*(17+2*9)]; /** * non zero coeff count cache. * is 64 if not available. */ DECLARE_ALIGNED_8(uint8_t, non_zero_count_cache[6*8]); uint8_t (*non_zero_count)[16];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -