pps_parser.h (2307B)
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 <stddef.h> 15 #include <stdint.h> 16 17 #include <optional> 18 19 #include "api/array_view.h" 20 21 namespace webrtc { 22 23 // A class for parsing out picture parameter set (PPS) data from a H264 NALU. 24 class PpsParser { 25 public: 26 // The parsed state of the PPS. Only some select values are stored. 27 // Add more as they are actually needed. 28 struct PpsState { 29 PpsState() = default; 30 31 bool bottom_field_pic_order_in_frame_present_flag = false; 32 bool weighted_pred_flag = false; 33 bool entropy_coding_mode_flag = false; 34 uint32_t num_ref_idx_l0_default_active_minus1 = 0; 35 uint32_t num_ref_idx_l1_default_active_minus1 = 0; 36 uint32_t weighted_bipred_idc = false; 37 uint32_t redundant_pic_cnt_present_flag = 0; 38 int pic_init_qp_minus26 = 0; 39 uint32_t id = 0; 40 uint32_t sps_id = 0; 41 }; 42 43 struct SliceHeader { 44 SliceHeader() = default; 45 46 uint32_t first_mb_in_slice = 0; 47 uint32_t pic_parameter_set_id = 0; 48 }; 49 50 // Unpack RBSP and parse PPS state from the supplied buffer. 51 static std::optional<PpsState> ParsePps(ArrayView<const uint8_t> data); 52 // TODO: bugs.webrtc.org/42225170 - Deprecate. 53 static inline std::optional<PpsState> ParsePps(const uint8_t* data, 54 size_t length) { 55 return ParsePps(MakeArrayView(data, length)); 56 } 57 58 static bool ParsePpsIds(ArrayView<const uint8_t> data, 59 uint32_t* pps_id, 60 uint32_t* sps_id); 61 62 static std::optional<SliceHeader> ParseSliceHeader( 63 ArrayView<const uint8_t> data); 64 65 protected: 66 // Parse the PPS state, for a buffer where RBSP decoding has already been 67 // performed. 68 static std::optional<PpsState> ParseInternal(ArrayView<const uint8_t> buffer); 69 }; 70 71 } // namespace webrtc 72 73 #endif // COMMON_VIDEO_H264_PPS_PARSER_H_