1 /* 2 * Copyright (c) 2015 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_H264_BITSTREAM_PARSER_H_ 12 #define COMMON_VIDEO_H264_H264_BITSTREAM_PARSER_H_ 13 #include <stddef.h> 14 #include <stdint.h> 15 16 #include "absl/types/optional.h" 17 #include "api/video_codecs/bitstream_parser.h" 18 #include "common_video/h264/pps_parser.h" 19 #include "common_video/h264/sps_parser.h" 20 21 namespace webrtc { 22 23 // Stateful H264 bitstream parser (due to SPS/PPS). Used to parse out QP values 24 // from the bitstream. 25 // 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 27 // removed and gracefully abort as we have no control over receive-side 28 // bitstreams. 29 class H264BitstreamParser : public BitstreamParser { 30 public: 31 H264BitstreamParser(); 32 ~H264BitstreamParser() override; 33 34 // These are here for backwards-compatability for the time being. 35 void ParseBitstream(const uint8_t* bitstream, size_t length); 36 bool GetLastSliceQp(int* qp) const; 37 38 // New interface. 39 void ParseBitstream(rtc::ArrayView<const uint8_t> bitstream) override; 40 absl::optional<int> GetLastSliceQp() const override; 41 42 protected: 43 enum Result { 44 kOk, 45 kInvalidStream, 46 kUnsupportedStream, 47 }; 48 void ParseSlice(const uint8_t* slice, size_t length); 49 Result ParseNonParameterSetNalu(const uint8_t* source, 50 size_t source_length, 51 uint8_t nalu_type); 52 53 // SPS/PPS state, updated when parsing new SPS/PPS, used to parse slices. 54 absl::optional<SpsParser::SpsState> sps_; 55 absl::optional<PpsParser::PpsState> pps_; 56 57 // Last parsed slice QP. 58 absl::optional<int32_t> last_slice_qp_delta_; 59 }; 60 61 } // namespace webrtc 62 63 #endif // COMMON_VIDEO_H264_H264_BITSTREAM_PARSER_H_ 64