1 /* 2 * Copyright (c) 2016 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_H264_PPS_PARSER_H_ 12 #define COMMON_VIDEO_H264_PPS_PARSER_H_ 13 14 #include "absl/types/optional.h" 15 16 namespace rtc { 17 class BitBuffer; 18 } 19 20 namespace webrtc { 21 22 // A class for parsing out picture parameter set (PPS) data from a H264 NALU. 23 class PpsParser { 24 public: 25 // The parsed state of the PPS. Only some select values are stored. 26 // Add more as they are actually needed. 27 struct PpsState { 28 PpsState() = default; 29 30 bool bottom_field_pic_order_in_frame_present_flag = false; 31 bool weighted_pred_flag = false; 32 bool entropy_coding_mode_flag = false; 33 uint32_t weighted_bipred_idc = false; 34 uint32_t redundant_pic_cnt_present_flag = 0; 35 int pic_init_qp_minus26 = 0; 36 uint32_t id = 0; 37 uint32_t sps_id = 0; 38 }; 39 40 // Unpack RBSP and parse PPS state from the supplied buffer. 41 static absl::optional<PpsState> ParsePps(const uint8_t* data, size_t length); 42 43 static bool ParsePpsIds(const uint8_t* data, 44 size_t length, 45 uint32_t* pps_id, 46 uint32_t* sps_id); 47 48 static absl::optional<uint32_t> ParsePpsIdFromSlice(const uint8_t* data, 49 size_t length); 50 51 protected: 52 // Parse the PPS state, for a bit buffer where RBSP decoding has already been 53 // performed. 54 static absl::optional<PpsState> ParseInternal(rtc::BitBuffer* bit_buffer); 55 static bool ParsePpsIdsInternal(rtc::BitBuffer* bit_buffer, 56 uint32_t* pps_id, 57 uint32_t* sps_id); 58 }; 59 60 } // namespace webrtc 61 62 #endif // COMMON_VIDEO_H264_PPS_PARSER_H_ 63