OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_MODULES_VIDEO_CODING_UTILITY_H264_BITSTREAM_PARSER_H_ | 11 #ifndef WEBRTC_MODULES_VIDEO_CODING_UTILITY_H264_BITSTREAM_PARSER_H_ |
12 #define WEBRTC_MODULES_VIDEO_CODING_UTILITY_H264_BITSTREAM_PARSER_H_ | 12 #define WEBRTC_MODULES_VIDEO_CODING_UTILITY_H264_BITSTREAM_PARSER_H_ |
13 | |
14 #include <stddef.h> | 13 #include <stddef.h> |
15 #include <stdint.h> | 14 #include <stdint.h> |
16 | 15 |
| 16 #include "webrtc/base/optional.h" |
| 17 #include "webrtc/common_video/h264/pps_parser.h" |
| 18 #include "webrtc/common_video/h264/sps_parser.h" |
| 19 |
17 namespace rtc { | 20 namespace rtc { |
18 class BitBuffer; | 21 class BitBufferWriter; |
19 } | 22 } |
20 | 23 |
21 namespace webrtc { | 24 namespace webrtc { |
22 | 25 |
23 // Stateful H264 bitstream parser (due to SPS/PPS). Used to parse out QP values | 26 // Stateful H264 bitstream parser (due to SPS/PPS). Used to parse out QP values |
24 // from the bitstream. | 27 // from the bitstream. |
25 // TODO(pbos): Unify with RTP SPS parsing and only use one H264 parser. | 28 // TODO(pbos): Unify with RTP SPS parsing and only use one H264 parser. |
26 // TODO(pbos): If/when this gets used on the receiver side CHECKs must be | 29 // TODO(pbos): If/when this gets used on the receiver side CHECKs must be |
27 // removed and gracefully abort as we have no control over receive-side | 30 // removed and gracefully abort as we have no control over receive-side |
28 // bitstreams. | 31 // bitstreams. |
29 class H264BitstreamParser { | 32 class H264BitstreamParser { |
30 public: | 33 public: |
| 34 H264BitstreamParser(); |
| 35 virtual ~H264BitstreamParser(); |
| 36 |
31 // Parse an additional chunk of H264 bitstream. | 37 // Parse an additional chunk of H264 bitstream. |
32 void ParseBitstream(const uint8_t* bitstream, size_t length); | 38 void ParseBitstream(const uint8_t* bitstream, size_t length); |
33 | 39 |
34 // Get the last extracted QP value from the parsed bitstream. | 40 // Get the last extracted QP value from the parsed bitstream. |
35 bool GetLastSliceQp(int* qp) const; | 41 bool GetLastSliceQp(int* qp) const; |
36 | 42 |
37 private: | 43 protected: |
38 // Captured in SPS and used when parsing slice NALUs. | |
39 struct SpsState { | |
40 SpsState(); | |
41 | |
42 uint32_t delta_pic_order_always_zero_flag = 0; | |
43 uint32_t separate_colour_plane_flag = 0; | |
44 uint32_t frame_mbs_only_flag = 0; | |
45 uint32_t log2_max_frame_num_minus4 = 0; | |
46 uint32_t log2_max_pic_order_cnt_lsb_minus4 = 0; | |
47 uint32_t pic_order_cnt_type = 0; | |
48 }; | |
49 | |
50 struct PpsState { | |
51 PpsState(); | |
52 | |
53 bool bottom_field_pic_order_in_frame_present_flag = false; | |
54 bool weighted_pred_flag = false; | |
55 uint32_t weighted_bipred_idc = false; | |
56 uint32_t redundant_pic_cnt_present_flag = 0; | |
57 int pic_init_qp_minus26 = 0; | |
58 }; | |
59 | |
60 void ParseSlice(const uint8_t* slice, size_t length); | 44 void ParseSlice(const uint8_t* slice, size_t length); |
61 bool ParseSpsNalu(const uint8_t* sps_nalu, size_t length); | |
62 bool ParsePpsNalu(const uint8_t* pps_nalu, size_t length); | |
63 bool ParseNonParameterSetNalu(const uint8_t* source, | 45 bool ParseNonParameterSetNalu(const uint8_t* source, |
64 size_t source_length, | 46 size_t source_length, |
65 uint8_t nalu_type); | 47 uint8_t nalu_type); |
66 | 48 |
67 // SPS/PPS state, updated when parsing new SPS/PPS, used to parse slices. | 49 // SPS/PPS state, updated when parsing new SPS/PPS, used to parse slices. |
68 bool sps_parsed_ = false; | 50 rtc::Optional<SpsParser::SpsState> sps_; |
69 SpsState sps_; | 51 rtc::Optional<PpsParser::PpsState> pps_; |
70 bool pps_parsed_ = false; | |
71 PpsState pps_; | |
72 | 52 |
73 // Last parsed slice QP. | 53 // Last parsed slice QP. |
74 bool last_slice_qp_delta_parsed_ = false; | 54 rtc::Optional<int32_t> last_slice_qp_delta_; |
75 int32_t last_slice_qp_delta_ = 0; | |
76 }; | 55 }; |
77 | 56 |
78 } // namespace webrtc | 57 } // namespace webrtc |
79 | 58 |
80 #endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_H264_BITSTREAM_PARSER_H_ | 59 #endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_H264_BITSTREAM_PARSER_H_ |
OLD | NEW |