blob: 5c35761fbc8440f9432131bd3f707820cea4d9c0 [file] [log] [blame]
Anton Khirnovf638b672016-05-18 07:40:331/*
James Almer8c793282016-08-01 15:58:092 * This file is part of FFmpeg.
Anton Khirnovf638b672016-05-18 07:40:333 *
James Almer8c793282016-08-01 15:58:094 * FFmpeg is free software; you can redistribute it and/or
Anton Khirnovf638b672016-05-18 07:40:335 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
James Almer8c793282016-08-01 15:58:099 * FFmpeg is distributed in the hope that it will be useful,
Anton Khirnovf638b672016-05-18 07:40:3310 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
James Almer8c793282016-08-01 15:58:0915 * License along with FFmpeg; if not, write to the Free Software
Anton Khirnovf638b672016-05-18 07:40:3316 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19/**
20 * @file
21 * H.264 parameter set handling
22 */
23
24#ifndef AVCODEC_H264_PS_H
25#define AVCODEC_H264_PS_H
26
27#include <stdint.h>
28
29#include "libavutil/buffer.h"
30#include "libavutil/pixfmt.h"
31#include "libavutil/rational.h"
32
33#include "avcodec.h"
34#include "get_bits.h"
35#include "h264.h"
Andreas Rheinhardt8bf18012022-07-02 16:39:3736#include "h2645_vui.h"
Anton Khirnovf638b672016-05-18 07:40:3337
38#define MAX_SPS_COUNT 32
39#define MAX_PPS_COUNT 256
Michael Niedermayerb796c5a2018-06-10 15:02:4740#define MAX_LOG2_MAX_FRAME_NUM (12 + 4)
Anton Khirnovf638b672016-05-18 07:40:3341
42/**
43 * Sequence parameter set
44 */
45typedef struct SPS {
46 unsigned int sps_id;
47 int profile_idc;
48 int level_idc;
49 int chroma_format_idc;
50 int transform_bypass; ///< qpprime_y_zero_transform_bypass_flag
51 int log2_max_frame_num; ///< log2_max_frame_num_minus4 + 4
52 int poc_type; ///< pic_order_cnt_type
53 int log2_max_poc_lsb; ///< log2_max_pic_order_cnt_lsb_minus4
54 int delta_pic_order_always_zero_flag;
55 int offset_for_non_ref_pic;
56 int offset_for_top_to_bottom_field;
57 int poc_cycle_length; ///< num_ref_frames_in_pic_order_cnt_cycle
58 int ref_frame_count; ///< num_ref_frames
59 int gaps_in_frame_num_allowed_flag;
60 int mb_width; ///< pic_width_in_mbs_minus1 + 1
Anton Khirnova8cbe5a2016-07-02 14:48:2661 ///< (pic_height_in_map_units_minus1 + 1) * (2 - frame_mbs_only_flag)
62 int mb_height;
Anton Khirnovf638b672016-05-18 07:40:3363 int frame_mbs_only_flag;
64 int mb_aff; ///< mb_adaptive_frame_field_flag
65 int direct_8x8_inference_flag;
66 int crop; ///< frame_cropping_flag
67
68 /* those 4 are already in luma samples */
69 unsigned int crop_left; ///< frame_cropping_rect_left_offset
70 unsigned int crop_right; ///< frame_cropping_rect_right_offset
71 unsigned int crop_top; ///< frame_cropping_rect_top_offset
72 unsigned int crop_bottom; ///< frame_cropping_rect_bottom_offset
73 int vui_parameters_present_flag;
Andreas Rheinhardt8bf18012022-07-02 16:39:3774 H2645VUI vui;
Anton Khirnov6eae7e52017-07-29 20:03:5575
Anton Khirnovf638b672016-05-18 07:40:3376 int timing_info_present_flag;
77 uint32_t num_units_in_tick;
78 uint32_t time_scale;
79 int fixed_frame_rate_flag;
James Almer53cc3332019-04-10 18:26:3080 int32_t offset_for_ref_frame[256];
Anton Khirnovf638b672016-05-18 07:40:3381 int bitstream_restriction_flag;
82 int num_reorder_frames;
83 int scaling_matrix_present;
84 uint8_t scaling_matrix4[6][16];
85 uint8_t scaling_matrix8[6][64];
86 int nal_hrd_parameters_present_flag;
87 int vcl_hrd_parameters_present_flag;
88 int pic_struct_present_flag;
89 int time_offset_length;
90 int cpb_cnt; ///< See H.264 E.1.2
91 int initial_cpb_removal_delay_length; ///< initial_cpb_removal_delay_length_minus1 + 1
92 int cpb_removal_delay_length; ///< cpb_removal_delay_length_minus1 + 1
93 int dpb_output_delay_length; ///< dpb_output_delay_length_minus1 + 1
94 int bit_depth_luma; ///< bit_depth_luma_minus8 + 8
95 int bit_depth_chroma; ///< bit_depth_chroma_minus8 + 8
96 int residual_color_transform_flag; ///< residual_colour_transform_flag
97 int constraint_set_flags; ///< constraint_set[0-3]_flag
James Almer8c793282016-08-01 15:58:0998 uint8_t data[4096];
99 size_t data_size;
Anton Khirnovf638b672016-05-18 07:40:33100} SPS;
101
102/**
103 * Picture parameter set
104 */
105typedef struct PPS {
106 unsigned int sps_id;
107 int cabac; ///< entropy_coding_mode_flag
108 int pic_order_present; ///< pic_order_present_flag
109 int slice_group_count; ///< num_slice_groups_minus1 + 1
110 int mb_slice_group_map_type;
111 unsigned int ref_count[2]; ///< num_ref_idx_l0/1_active_minus1 + 1
112 int weighted_pred; ///< weighted_pred_flag
113 int weighted_bipred_idc;
114 int init_qp; ///< pic_init_qp_minus26 + 26
115 int init_qs; ///< pic_init_qs_minus26 + 26
116 int chroma_qp_index_offset[2];
117 int deblocking_filter_parameters_present; ///< deblocking_filter_parameters_present_flag
118 int constrained_intra_pred; ///< constrained_intra_pred_flag
119 int redundant_pic_cnt_present; ///< redundant_pic_cnt_present_flag
120 int transform_8x8_mode; ///< transform_8x8_mode_flag
121 uint8_t scaling_matrix4[6][16];
122 uint8_t scaling_matrix8[6][64];
James Almer8c793282016-08-01 15:58:09123 uint8_t chroma_qp_table[2][QP_MAX_NUM+1]; ///< pre-scaled (with chroma_qp_index_offset) version of qp_table
Anton Khirnovf638b672016-05-18 07:40:33124 int chroma_qp_diff;
James Almer8c793282016-08-01 15:58:09125 uint8_t data[4096];
126 size_t data_size;
Anton Khirnovf638b672016-05-18 07:40:33127
128 uint32_t dequant4_buffer[6][QP_MAX_NUM + 1][16];
129 uint32_t dequant8_buffer[6][QP_MAX_NUM + 1][64];
130 uint32_t(*dequant4_coeff[6])[16];
131 uint32_t(*dequant8_coeff[6])[64];
Anton Khirnov5e316092017-05-01 19:42:54132
133 AVBufferRef *sps_ref;
134 const SPS *sps;
Anton Khirnovf638b672016-05-18 07:40:33135} PPS;
136
137typedef struct H264ParamSets {
138 AVBufferRef *sps_list[MAX_SPS_COUNT];
139 AVBufferRef *pps_list[MAX_PPS_COUNT];
140
James Almer8c793282016-08-01 15:58:09141 AVBufferRef *pps_ref;
Anton Khirnovf638b672016-05-18 07:40:33142 /* currently active parameters sets */
143 const PPS *pps;
James Almer8c793282016-08-01 15:58:09144 const SPS *sps;
Michael Niedermayerd9751a12020-01-16 16:51:29145
146 int overread_warning_printed[2];
Anton Khirnovf638b672016-05-18 07:40:33147} H264ParamSets;
148
149/**
Andreas Rheinhardtb2421c42022-01-24 18:39:31150 * compute profile from sps
151 */
152int ff_h264_get_profile(const SPS *sps);
153
154/**
Anton Khirnovf638b672016-05-18 07:40:33155 * Decode SPS
156 */
157int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
James Almer8c793282016-08-01 15:58:09158 H264ParamSets *ps, int ignore_truncation);
Anton Khirnovf638b672016-05-18 07:40:33159
160/**
161 * Decode PPS
162 */
163int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
164 H264ParamSets *ps, int bit_length);
165
James Almer613c8622016-08-03 03:36:09166/**
167 * Uninit H264 param sets structure.
168 */
169void ff_h264_ps_uninit(H264ParamSets *ps);
170
Anton Khirnovf638b672016-05-18 07:40:33171#endif /* AVCODEC_H264_PS_H */