1 /* 2 * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef COMMON_VIDEO_H265_PPS_PARSER_H_ 12 #define COMMON_VIDEO_H265_PPS_PARSER_H_ 13 14 #include <cstdint> 15 16 #include "absl/types/optional.h" 17 18 namespace rtc { 19 class BitBuffer; 20 } 21 22 namespace webrtc { 23 24 // A class for parsing out picture parameter set (PPS) data from a H265 NALU. 25 class H265PpsParser { 26 public: 27 // The parsed state of the PPS. Only some select values are stored. 28 // Add more as they are actually needed. 29 struct PpsState { 30 PpsState() = default; 31 32 uint32_t dependent_slice_segments_enabled_flag = 0; 33 uint32_t cabac_init_present_flag = 0; 34 uint32_t output_flag_present_flag = 0; 35 uint32_t num_extra_slice_header_bits = 0; 36 uint32_t num_ref_idx_l0_default_active_minus1 = 0; 37 uint32_t num_ref_idx_l1_default_active_minus1 = 0; 38 int32_t pic_init_qp_minus26 = 0; 39 uint32_t weighted_pred_flag = 0; 40 uint32_t weighted_bipred_flag = 0; 41 uint32_t lists_modification_present_flag = 0; 42 uint32_t id = 0; 43 uint32_t sps_id = 0; 44 }; 45 46 // Unpack RBSP and parse PPS state from the supplied buffer. 47 static absl::optional<PpsState> ParsePps(const uint8_t* data, size_t length); 48 49 static bool ParsePpsIds(const uint8_t* data, 50 size_t length, 51 uint32_t* pps_id, 52 uint32_t* sps_id); 53 54 static absl::optional<uint32_t> ParsePpsIdFromSliceSegmentLayerRbsp( 55 const uint8_t* data, 56 size_t length, 57 uint8_t nalu_type); 58 59 protected: 60 // Parse the PPS state, for a bit buffer where RBSP decoding has already been 61 // performed. 62 static absl::optional<PpsState> ParseInternal(rtc::BitBuffer* bit_buffer); 63 static bool ParsePpsIdsInternal(rtc::BitBuffer* bit_buffer, 64 uint32_t* pps_id, 65 uint32_t* sps_id); 66 }; 67 68 } // namespace webrtc 69 70 #endif // COMMON_VIDEO_H265_PPS_PARSER_H_ 71