DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerator
h265_parser.h
1 // Copyright 2016 Google Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #ifndef MEDIA_FILTERS_H265_PARSER_H_
8 #define MEDIA_FILTERS_H265_PARSER_H_
9 
10 #include <map>
11 #include <vector>
12 
13 #include "packager/base/memory/scoped_ptr.h"
14 #include "packager/media/filters/h26x_bit_reader.h"
15 
16 namespace edash_packager {
17 namespace media {
18 
19 class Nalu;
20 
21 enum H265SliceType { kBSlice = 0, kPSlice = 1, kISlice = 2 };
22 
23 const int kMaxRefPicSetCount = 16;
24 
26  int delta_poc_s0[kMaxRefPicSetCount];
27  int delta_poc_s1[kMaxRefPicSetCount];
28  bool used_by_curr_pic_s0[kMaxRefPicSetCount];
29  bool used_by_curr_pic_s1[kMaxRefPicSetCount];
30 
31  int num_negative_pics;
32  int num_positive_pics;
33  int num_delta_pocs;
34 };
35 
36 struct H265Pps {
37  H265Pps();
38  ~H265Pps();
39 
40  // Many of the fields here are required when parsing so the default here may
41  // not be valid.
42 
43  int pic_parameter_set_id = 0;
44  int seq_parameter_set_id = 0;
45 
46  bool dependent_slice_segments_enabled_flag = false;
47  bool output_flag_present_flag = false;
48  int num_extra_slice_header_bits = 0;
49  bool sign_data_hiding_enabled_flag = false;
50  bool cabac_init_present_flag = false;
51 
52  int num_ref_idx_l0_default_active_minus1 = 0;
53  int num_ref_idx_l1_default_active_minus1 = 0;
54  int init_qp_minus26 = 0;
55  bool constrained_intra_pred_flag = false;
56  bool transform_skip_enabled_flag = false;
57 
58  bool cu_qp_delta_enabled_flag = 0;
59  int diff_cu_qp_delta_depth = 0;
60  int cb_qp_offset = 0;
61  int cr_qp_offset = 0;
62 
63  bool slice_chroma_qp_offsets_present_flag = false;
64  bool weighted_pred_flag = false;
65  bool weighted_bipred_flag = false;
66  bool transquant_bypass_enabled_flag = false;
67  bool tiles_enabled_flag = false;
68  bool entropy_coding_sync_enabled_flag = false;
69 
70  int num_tile_columns_minus1 = 0;
71  int num_tile_rows_minus1 = 0;
72  bool uniform_spacing_flag = true;
73  std::vector<int> column_width_minus1;
74  std::vector<int> row_height_minus1;
75  bool loop_filter_across_tiles_enabled_flag = true;
76 
77  bool loop_filter_across_slices_enabled_flag = false;
78  bool deblocking_filter_control_present_flag = false;
79  bool deblocking_filter_override_enabled_flag = false;
80  bool deblocking_filter_disabled_flag = false;
81  int beta_offset_div2 = 0;
82  int tc_offset_div2 = 0;
83 
84  bool scaling_list_data_present_flag = false;
85  // Ignored: scaling_list_data( )
86 
87  bool lists_modification_present_flag = false;
88  int log2_parallel_merge_level_minus2 = 0;
89  bool slice_segment_header_extension_present_flag = false;
90 
91  // Incomplete: pps_range_extension:
92  bool chroma_qp_offset_list_enabled_flag = false;
93 
94  // Ignored: extensions...
95 };
96 
97 struct H265Sps {
98  H265Sps();
99  ~H265Sps();
100 
101  int GetPicSizeInCtbsY() const;
102  int GetChromaArrayType() const;
103 
104  // Many of the fields here are required when parsing so the default here may
105  // not be valid.
106 
107  int video_parameter_set_id = 0;
108  int max_sub_layers_minus1 = 0;
109  bool temporal_id_nesting_flag = false;
110  // Ignored: profile_tier_level(...)
111 
112  int seq_parameter_set_id = 0;
113 
114  int chroma_format_idc = 0;
115  bool separate_colour_plane_flag = false;
116  int pic_width_in_luma_samples = 0;
117  int pic_height_in_luma_samples = 0;
118 
119  bool conformance_window_flag = false;
120  int conf_win_left_offset = 0;
121  int conf_win_right_offset = 0;
122  int conf_win_top_offset = 0;
123  int conf_win_bottom_offset = 0;
124 
125  int bit_depth_luma_minus8 = 0;
126  int bit_depth_chroma_minus8 = 0;
127  int log2_max_pic_order_cnt_lsb_minus4 = 0;
128 
129  bool sub_layer_ordering_info_present_flag = false;
130  int max_dec_pic_buffering_minus1[8];
131  int max_num_reorder_pics[8];
132  int max_latency_increase_plus1[8];
133 
134  int log2_min_luma_coding_block_size_minus3 = 0;
135  int log2_diff_max_min_luma_coding_block_size = 0;
136  int log2_min_luma_transform_block_size_minus2 = 0;
137  int log2_diff_max_min_luma_transform_block_size = 0;
138  int max_transform_hierarchy_depth_inter = 0;
139  int max_transform_hierarchy_depth_intra = 0;
140 
141  bool scaling_list_enabled_flag = false;
142  bool scaling_list_data_present_flag = false;
143  // Ignored: scaling_list_data()
144 
145  bool amp_enabled_flag = false;
146  bool sample_adaptive_offset_enabled_flag = false;
147  bool pcm_enabled_flag = false;
148  int pcm_sample_bit_depth_luma_minus1 = 0;
149  int pcm_sample_bit_depth_chroma_minus1 = 0;
150  int log2_min_pcm_luma_coding_block_size_minus3 = 0;
151  int log2_diff_max_min_pcm_luma_coding_block_size = 0;
152  bool pcm_loop_filter_disabled_flag = false;
153 
154  int num_short_term_ref_pic_sets = 0;
155  std::vector<H265ReferencePictureSet> st_ref_pic_sets;
156 
157  bool long_term_ref_pic_present_flag = false;
158  int num_long_term_ref_pics = 0;
159  std::vector<int> lt_ref_pic_poc_lsb;
160  std::vector<bool> used_by_curr_pic_lt_flag;
161 
162  bool temporal_mvp_enabled_flag = false;
163  bool strong_intra_smoothing_enabled_flag = false;
164 
165  // Ignored: extensions...
166 };
167 
171 
172  bool ref_pic_list_modification_flag_l0 = false;
173  std::vector<int> list_entry_l0;
174 
175  bool ref_pic_list_modification_flag_l1 = false;
176  std::vector<int> list_entry_l1;
177 };
178 
180  H265SliceHeader();
181  ~H265SliceHeader();
182 
184  bool delta_poc_msb_present_flag;
185  int delta_poc_msb_cycle_lt;
186  };
187  // This is the value UsedByCurrPicLt for the current slice segment. This
188  // value is calulated from the LongTermPicsInfo during parsing.
189  int used_by_curr_pic_lt = 0;
190 
191  // Many of the fields here are required when parsing so the default here may
192  // not be valid.
193 
194  int header_bit_size = 0;
195 
196  bool first_slice_segment_in_pic_flag = false;
197  bool no_output_of_prior_pics_flag = false;
198  int pic_parameter_set_id = 0;
199 
200  bool dependent_slice_segment_flag = false;
201  int segment_address = 0;
202  int slice_type = 0;
203  bool pic_output_flag = true;
204  int colour_plane_id = 0;
205  int slice_pic_order_cnt_lsb = 0;
206 
207  bool short_term_ref_pic_set_sps_flag = false;
208  H265ReferencePictureSet st_ref_pic_set;
209  int short_term_ref_pic_set_idx = 0;
210 
211  int num_long_term_sps = 0;
212  int num_long_term_pics = 0;
213  std::vector<LongTermPicsInfo> long_term_pics_info;
214 
215  bool slice_temporal_mvp_enabled_flag = false;
216  bool slice_sao_luma_flag = false;
217  bool slice_sao_chroma_flag = false;
218 
219  bool num_ref_idx_active_override_flag = false;
220  int num_ref_idx_l0_active_minus1 = 0;
221  int num_ref_idx_l1_active_minus1 = 0;
222 
223  H265ReferencePictureListModifications ref_pic_lists_modification;
224 
225  bool mvd_l1_zero_flag = false;
226  bool cabac_init_flag = false;
227  bool collocated_from_l0 = true;
228  int collocated_ref_idx = 0;
229 
230  int five_minus_max_num_merge_cand = 0;
231  int slice_qp_delta = 0;
232  int slice_cb_qp_offset = 0;
233  int slice_cr_qp_offset = 0;
234 
235  bool cu_chroma_qp_offset_enabled_flag = false;
236  bool deblocking_filter_override_flag = false;
237  bool slice_deblocking_filter_disabled_flag = false;
238  int slice_beta_offset_div2 = 0;
239  int slice_tc_offset_div2 = 0;
240  bool slice_loop_filter_across_slices_enabled_flag = false;
241 
242  int num_entry_point_offsets = 0;
243  int offset_len_minus1 = 0;
244  std::vector<int> entry_point_offset_minus1;
245 };
246 
250 class H265Parser {
251  public:
252  enum Result {
253  kOk,
254  kInvalidStream, // error in stream
255  kUnsupportedStream, // stream not supported by the parser
256  kEOStream, // end of stream
257  };
258 
259  H265Parser();
260  ~H265Parser();
261 
265  Result ParseSliceHeader(const Nalu& nalu, H265SliceHeader* slice_header);
266 
269  Result ParsePps(const Nalu& nalu, int* pps_id);
272  Result ParseSps(const Nalu& nalu, int* sps_id);
273 
275  const H265Pps* GetPps(int pps_id);
277  const H265Sps* GetSps(int sps_id);
278 
279  private:
280  Result ParseReferencePictureSet(
281  int num_short_term_ref_pic_sets,
282  int st_rpx_idx,
283  const std::vector<H265ReferencePictureSet>& ref_pic_sets,
284  H26xBitReader* br,
285  H265ReferencePictureSet* st_ref_pic_set);
286 
287  Result SkipReferencePictureListModification(
288  const H265SliceHeader& slice_header,
289  const H265Pps& pps,
290  int num_pic_total_curr,
291  H26xBitReader* br);
292 
293  Result SkipPredictionWeightTablePart(int num_ref_idx_minus1,
294  int chroma_array_type,
295  H26xBitReader* br);
296 
297  Result SkipPredictionWeightTable(bool is_b_slice,
298  const H265Sps& sps,
299  const H265SliceHeader& slice_header,
300  H26xBitReader* br);
301 
302  Result SkipProfileTierLevel(bool profile_present,
303  int max_num_sub_layers_minus1,
304  H26xBitReader* br);
305 
306  Result SkipScalingListData(H26xBitReader* br);
307 
308  typedef std::map<int, H265Sps*> SpsById;
309  typedef std::map<int, H265Pps*> PpsById;
310 
311  SpsById active_spses_;
312  PpsById active_ppses_;
313 
314  DISALLOW_COPY_AND_ASSIGN(H265Parser);
315 };
316 
317 } // namespace media
318 } // namespace edash_packager
319 
320 #endif // MEDIA_FILTERS_H265_PARSER_H_
Result ParseSliceHeader(const Nalu &nalu, H265SliceHeader *slice_header)
Definition: h265_parser.cc:95
Result ParsePps(const Nalu &nalu, int *pps_id)
Definition: h265_parser.cc:312
Result ParseSps(const Nalu &nalu, int *sps_id)
Definition: h265_parser.cc:421
const H265Pps * GetPps(int pps_id)
Definition: h265_parser.cc:532
const H265Sps * GetSps(int sps_id)
Definition: h265_parser.cc:536