h264_ps.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * 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. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * 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
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. /**
  19. * @file
  20. * H.264 parameter set handling
  21. */
  22. #ifndef AVCODEC_H264_PS_H
  23. #define AVCODEC_H264_PS_H
  24. #include <stdint.h>
  25. #include "libavutil/buffer.h"
  26. #include "libavutil/pixfmt.h"
  27. #include "libavutil/rational.h"
  28. #include "avcodec.h"
  29. #include "get_bits.h"
  30. #include "h264.h"
  31. #define MAX_SPS_COUNT 32
  32. #define MAX_PPS_COUNT 256
  33. #define MAX_LOG2_MAX_FRAME_NUM (12 + 4)
  34. /**
  35. * Sequence parameter set
  36. */
  37. typedef struct SPS {
  38. unsigned int sps_id;
  39. int profile_idc;
  40. int level_idc;
  41. int chroma_format_idc;
  42. int transform_bypass; ///< qpprime_y_zero_transform_bypass_flag
  43. int log2_max_frame_num; ///< log2_max_frame_num_minus4 + 4
  44. int poc_type; ///< pic_order_cnt_type
  45. int log2_max_poc_lsb; ///< log2_max_pic_order_cnt_lsb_minus4
  46. int delta_pic_order_always_zero_flag;
  47. int offset_for_non_ref_pic;
  48. int offset_for_top_to_bottom_field;
  49. int poc_cycle_length; ///< num_ref_frames_in_pic_order_cnt_cycle
  50. int ref_frame_count; ///< num_ref_frames
  51. int gaps_in_frame_num_allowed_flag;
  52. int mb_width; ///< pic_width_in_mbs_minus1 + 1
  53. ///< (pic_height_in_map_units_minus1 + 1) * (2 - frame_mbs_only_flag)
  54. int mb_height;
  55. int frame_mbs_only_flag;
  56. int mb_aff; ///< mb_adaptive_frame_field_flag
  57. int direct_8x8_inference_flag;
  58. int crop; ///< frame_cropping_flag
  59. /* those 4 are already in luma samples */
  60. unsigned int crop_left; ///< frame_cropping_rect_left_offset
  61. unsigned int crop_right; ///< frame_cropping_rect_right_offset
  62. unsigned int crop_top; ///< frame_cropping_rect_top_offset
  63. unsigned int crop_bottom; ///< frame_cropping_rect_bottom_offset
  64. int vui_parameters_present_flag;
  65. AVRational sar;
  66. int video_signal_type_present_flag;
  67. int full_range;
  68. int colour_description_present_flag;
  69. enum AVColorPrimaries color_primaries;
  70. enum AVColorTransferCharacteristic color_trc;
  71. enum AVColorSpace colorspace;
  72. enum AVChromaLocation chroma_location;
  73. int timing_info_present_flag;
  74. uint32_t num_units_in_tick;
  75. uint32_t time_scale;
  76. int fixed_frame_rate_flag;
  77. int32_t offset_for_ref_frame[256];
  78. int bitstream_restriction_flag;
  79. int num_reorder_frames;
  80. int scaling_matrix_present;
  81. uint8_t scaling_matrix4[6][16];
  82. uint8_t scaling_matrix8[6][64];
  83. int nal_hrd_parameters_present_flag;
  84. int vcl_hrd_parameters_present_flag;
  85. int pic_struct_present_flag;
  86. int time_offset_length;
  87. int cpb_cnt; ///< See H.264 E.1.2
  88. int initial_cpb_removal_delay_length; ///< initial_cpb_removal_delay_length_minus1 + 1
  89. int cpb_removal_delay_length; ///< cpb_removal_delay_length_minus1 + 1
  90. int dpb_output_delay_length; ///< dpb_output_delay_length_minus1 + 1
  91. int bit_depth_luma; ///< bit_depth_luma_minus8 + 8
  92. int bit_depth_chroma; ///< bit_depth_chroma_minus8 + 8
  93. int residual_color_transform_flag; ///< residual_colour_transform_flag
  94. int constraint_set_flags; ///< constraint_set[0-3]_flag
  95. uint8_t data[4096];
  96. size_t data_size;
  97. } SPS;
  98. /**
  99. * Picture parameter set
  100. */
  101. typedef struct PPS {
  102. unsigned int sps_id;
  103. int cabac; ///< entropy_coding_mode_flag
  104. int pic_order_present; ///< pic_order_present_flag
  105. int slice_group_count; ///< num_slice_groups_minus1 + 1
  106. int mb_slice_group_map_type;
  107. unsigned int ref_count[2]; ///< num_ref_idx_l0/1_active_minus1 + 1
  108. int weighted_pred; ///< weighted_pred_flag
  109. int weighted_bipred_idc;
  110. int init_qp; ///< pic_init_qp_minus26 + 26
  111. int init_qs; ///< pic_init_qs_minus26 + 26
  112. int chroma_qp_index_offset[2];
  113. int deblocking_filter_parameters_present; ///< deblocking_filter_parameters_present_flag
  114. int constrained_intra_pred; ///< constrained_intra_pred_flag
  115. int redundant_pic_cnt_present; ///< redundant_pic_cnt_present_flag
  116. int transform_8x8_mode; ///< transform_8x8_mode_flag
  117. uint8_t scaling_matrix4[6][16];
  118. uint8_t scaling_matrix8[6][64];
  119. uint8_t chroma_qp_table[2][QP_MAX_NUM+1]; ///< pre-scaled (with chroma_qp_index_offset) version of qp_table
  120. int chroma_qp_diff;
  121. uint8_t data[4096];
  122. size_t data_size;
  123. uint32_t dequant4_buffer[6][QP_MAX_NUM + 1][16];
  124. uint32_t dequant8_buffer[6][QP_MAX_NUM + 1][64];
  125. uint32_t(*dequant4_coeff[6])[16];
  126. uint32_t(*dequant8_coeff[6])[64];
  127. AVBufferRef *sps_ref;
  128. const SPS *sps;
  129. } PPS;
  130. typedef struct H264ParamSets {
  131. AVBufferRef *sps_list[MAX_SPS_COUNT];
  132. AVBufferRef *pps_list[MAX_PPS_COUNT];
  133. AVBufferRef *pps_ref;
  134. /* currently active parameters sets */
  135. const PPS *pps;
  136. const SPS *sps;
  137. int overread_warning_printed[2];
  138. } H264ParamSets;
  139. /**
  140. * Decode SPS
  141. */
  142. int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
  143. H264ParamSets *ps, int ignore_truncation);
  144. /**
  145. * Decode PPS
  146. */
  147. int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
  148. H264ParamSets *ps, int bit_length);
  149. /**
  150. * Uninit H264 param sets structure.
  151. */
  152. void ff_h264_ps_uninit(H264ParamSets *ps);
  153. #endif /* AVCODEC_H264_PS_H */