You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
5.7KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav 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. * Libav 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 Libav; 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. /**
  34. * Sequence parameter set
  35. */
  36. typedef struct SPS {
  37. unsigned int sps_id;
  38. int profile_idc;
  39. int level_idc;
  40. int chroma_format_idc;
  41. int transform_bypass; ///< qpprime_y_zero_transform_bypass_flag
  42. int log2_max_frame_num; ///< log2_max_frame_num_minus4 + 4
  43. int poc_type; ///< pic_order_cnt_type
  44. int log2_max_poc_lsb; ///< log2_max_pic_order_cnt_lsb_minus4
  45. int delta_pic_order_always_zero_flag;
  46. int offset_for_non_ref_pic;
  47. int offset_for_top_to_bottom_field;
  48. int poc_cycle_length; ///< num_ref_frames_in_pic_order_cnt_cycle
  49. int ref_frame_count; ///< num_ref_frames
  50. int gaps_in_frame_num_allowed_flag;
  51. int mb_width; ///< pic_width_in_mbs_minus1 + 1
  52. int mb_height; ///< pic_height_in_map_units_minus1 + 1
  53. int frame_mbs_only_flag;
  54. int mb_aff; ///< mb_adaptive_frame_field_flag
  55. int direct_8x8_inference_flag;
  56. int crop; ///< frame_cropping_flag
  57. /* those 4 are already in luma samples */
  58. unsigned int crop_left; ///< frame_cropping_rect_left_offset
  59. unsigned int crop_right; ///< frame_cropping_rect_right_offset
  60. unsigned int crop_top; ///< frame_cropping_rect_top_offset
  61. unsigned int crop_bottom; ///< frame_cropping_rect_bottom_offset
  62. int vui_parameters_present_flag;
  63. AVRational sar;
  64. int video_signal_type_present_flag;
  65. int full_range;
  66. int colour_description_present_flag;
  67. enum AVColorPrimaries color_primaries;
  68. enum AVColorTransferCharacteristic color_trc;
  69. enum AVColorSpace colorspace;
  70. int timing_info_present_flag;
  71. uint32_t num_units_in_tick;
  72. uint32_t time_scale;
  73. int fixed_frame_rate_flag;
  74. short offset_for_ref_frame[256]; // FIXME dyn aloc?
  75. int bitstream_restriction_flag;
  76. int num_reorder_frames;
  77. int scaling_matrix_present;
  78. uint8_t scaling_matrix4[6][16];
  79. uint8_t scaling_matrix8[6][64];
  80. int nal_hrd_parameters_present_flag;
  81. int vcl_hrd_parameters_present_flag;
  82. int pic_struct_present_flag;
  83. int time_offset_length;
  84. int cpb_cnt; ///< See H.264 E.1.2
  85. int initial_cpb_removal_delay_length; ///< initial_cpb_removal_delay_length_minus1 + 1
  86. int cpb_removal_delay_length; ///< cpb_removal_delay_length_minus1 + 1
  87. int dpb_output_delay_length; ///< dpb_output_delay_length_minus1 + 1
  88. int bit_depth_luma; ///< bit_depth_luma_minus8 + 8
  89. int bit_depth_chroma; ///< bit_depth_chroma_minus8 + 8
  90. int residual_color_transform_flag; ///< residual_colour_transform_flag
  91. int constraint_set_flags; ///< constraint_set[0-3]_flag
  92. } SPS;
  93. /**
  94. * Picture parameter set
  95. */
  96. typedef struct PPS {
  97. unsigned int sps_id;
  98. int cabac; ///< entropy_coding_mode_flag
  99. int pic_order_present; ///< pic_order_present_flag
  100. int slice_group_count; ///< num_slice_groups_minus1 + 1
  101. int mb_slice_group_map_type;
  102. unsigned int ref_count[2]; ///< num_ref_idx_l0/1_active_minus1 + 1
  103. int weighted_pred; ///< weighted_pred_flag
  104. int weighted_bipred_idc;
  105. int init_qp; ///< pic_init_qp_minus26 + 26
  106. int init_qs; ///< pic_init_qs_minus26 + 26
  107. int chroma_qp_index_offset[2];
  108. int deblocking_filter_parameters_present; ///< deblocking_filter_parameters_present_flag
  109. int constrained_intra_pred; ///< constrained_intra_pred_flag
  110. int redundant_pic_cnt_present; ///< redundant_pic_cnt_present_flag
  111. int transform_8x8_mode; ///< transform_8x8_mode_flag
  112. uint8_t scaling_matrix4[6][16];
  113. uint8_t scaling_matrix8[6][64];
  114. uint8_t chroma_qp_table[2][64]; ///< pre-scaled (with chroma_qp_index_offset) version of qp_table
  115. int chroma_qp_diff;
  116. uint32_t dequant4_buffer[6][QP_MAX_NUM + 1][16];
  117. uint32_t dequant8_buffer[6][QP_MAX_NUM + 1][64];
  118. uint32_t(*dequant4_coeff[6])[16];
  119. uint32_t(*dequant8_coeff[6])[64];
  120. } PPS;
  121. typedef struct H264ParamSets {
  122. AVBufferRef *sps_list[MAX_SPS_COUNT];
  123. AVBufferRef *pps_list[MAX_PPS_COUNT];
  124. /* currently active parameters sets */
  125. const PPS *pps;
  126. // FIXME this should properly be const
  127. SPS *sps;
  128. } H264ParamSets;
  129. /**
  130. * Decode SPS
  131. */
  132. int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
  133. H264ParamSets *ps);
  134. /**
  135. * Decode PPS
  136. */
  137. int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
  138. H264ParamSets *ps, int bit_length);
  139. #endif /* AVCODEC_H264_PS_H */