h265_pps_parser.h (2974B)
1 /* 2 * Copyright (c) 2023 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_H265_PPS_PARSER_H_ 12 #define COMMON_VIDEO_H265_H265_PPS_PARSER_H_ 13 14 #include <cstddef> 15 #include <cstdint> 16 #include <optional> 17 18 #include "api/array_view.h" 19 #include "common_video/h265/h265_sps_parser.h" 20 #include "rtc_base/bitstream_reader.h" 21 #include "rtc_base/system/rtc_export.h" 22 23 namespace webrtc { 24 25 // A class for parsing out picture parameter set (PPS) data from a H265 NALU. 26 class RTC_EXPORT H265PpsParser { 27 public: 28 // The parsed state of the PPS. Only some select values are stored. 29 // Add more as they are actually needed. 30 struct PpsState { 31 PpsState() = default; 32 33 bool dependent_slice_segments_enabled_flag = false; 34 bool cabac_init_present_flag = false; 35 bool output_flag_present_flag = false; 36 uint32_t num_extra_slice_header_bits = 0; 37 uint32_t num_ref_idx_l0_default_active_minus1 = 0; 38 uint32_t num_ref_idx_l1_default_active_minus1 = 0; 39 int init_qp_minus26 = 0; 40 bool weighted_pred_flag = false; 41 bool weighted_bipred_flag = false; 42 bool lists_modification_present_flag = false; 43 uint32_t pps_id = 0; 44 uint32_t sps_id = 0; 45 int qp_bd_offset_y = 0; 46 }; 47 48 // Unpack RBSP and parse PPS state from the supplied buffer. 49 static std::optional<PpsState> ParsePps(ArrayView<const uint8_t> data, 50 const H265SpsParser::SpsState* sps); 51 // TODO: bugs.webrtc.org/42225170 - Deprecate. 52 static inline std::optional<PpsState> ParsePps( 53 const uint8_t* data, 54 size_t length, 55 const H265SpsParser::SpsState* sps) { 56 return ParsePps(MakeArrayView(data, length), sps); 57 } 58 59 static bool ParsePpsIds(ArrayView<const uint8_t> data, 60 uint32_t* pps_id, 61 uint32_t* sps_id); 62 // TODO: bugs.webrtc.org/42225170 - Deprecate. 63 static inline bool ParsePpsIds(const uint8_t* data, 64 size_t length, 65 uint32_t* pps_id, 66 uint32_t* sps_id) { 67 return ParsePpsIds(MakeArrayView(data, length), pps_id, sps_id); 68 } 69 70 protected: 71 // Parse the PPS state, for a bit buffer where RBSP decoding has already been 72 // performed. 73 static std::optional<PpsState> ParseInternal( 74 ArrayView<const uint8_t> buffer, 75 const H265SpsParser::SpsState* sps); 76 static bool ParsePpsIdsInternal(BitstreamReader& reader, 77 uint32_t& pps_id, 78 uint32_t& sps_id); 79 }; 80 81 } // namespace webrtc 82 83 #endif // COMMON_VIDEO_H265_H265_PPS_PARSER_H_