h264_bitstream_parser.h (1918B)
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 <optional> 17 18 #include "api/array_view.h" 19 #include "api/video_codecs/bitstream_parser.h" 20 #include "common_video/h264/pps_parser.h" 21 #include "common_video/h264/sps_parser.h" 22 23 namespace webrtc { 24 25 // Stateful H264 bitstream parser (due to SPS/PPS). Used to parse out QP values 26 // from the bitstream. 27 // TODO(pbos): Unify with RTP SPS parsing and only use one H264 parser. 28 // TODO(pbos): If/when this gets used on the receiver side CHECKs must be 29 // removed and gracefully abort as we have no control over receive-side 30 // bitstreams. 31 class H264BitstreamParser : public BitstreamParser { 32 public: 33 H264BitstreamParser(); 34 ~H264BitstreamParser() override; 35 36 void ParseBitstream(ArrayView<const uint8_t> bitstream) override; 37 std::optional<int> GetLastSliceQp() const override; 38 39 protected: 40 enum Result { 41 kOk, 42 kInvalidStream, 43 kUnsupportedStream, 44 }; 45 void ParseSlice(ArrayView<const uint8_t> slice); 46 Result ParseNonParameterSetNalu(ArrayView<const uint8_t> source, 47 uint8_t nalu_type); 48 49 // SPS/PPS state, updated when parsing new SPS/PPS, used to parse slices. 50 std::optional<SpsParser::SpsState> sps_; 51 std::optional<PpsParser::PpsState> pps_; 52 53 // Last parsed slice QP. 54 std::optional<int32_t> last_slice_qp_delta_; 55 }; 56 57 } // namespace webrtc 58 59 #endif // COMMON_VIDEO_H264_H264_BITSTREAM_PARSER_H_