tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

h265_bitstream_parser.h (2522B)


      1 /*
      2 *  Copyright (c) 2023 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_H265_H265_BITSTREAM_PARSER_H_
     12 #define COMMON_VIDEO_H265_H265_BITSTREAM_PARSER_H_
     13 
     14 #include <stddef.h>
     15 #include <stdint.h>
     16 
     17 #include <optional>
     18 
     19 #include "api/array_view.h"
     20 #include "api/video_codecs/bitstream_parser.h"
     21 #include "common_video/h265/h265_pps_parser.h"
     22 #include "common_video/h265/h265_sps_parser.h"
     23 #include "common_video/h265/h265_vps_parser.h"
     24 #include "rtc_base/containers/flat_map.h"
     25 #include "rtc_base/system/rtc_export.h"
     26 
     27 namespace webrtc {
     28 
     29 // Stateful H265 bitstream parser (due to VPS/SPS/PPS). Used to parse out QP
     30 // values from the bitstream.
     31 class RTC_EXPORT H265BitstreamParser : public BitstreamParser {
     32 public:
     33  H265BitstreamParser();
     34  ~H265BitstreamParser() override;
     35 
     36  // New interface.
     37  void ParseBitstream(ArrayView<const uint8_t> bitstream) override;
     38  std::optional<int> GetLastSliceQp() const override;
     39 
     40  std::optional<uint32_t> GetLastSlicePpsId() const;
     41 
     42  static std::optional<uint32_t> ParsePpsIdFromSliceSegmentLayerRbsp(
     43      ArrayView<const uint8_t> data,
     44      uint8_t nalu_type);
     45 
     46  // Returns true if the slice segment is the first in the picture; otherwise
     47  // return false. If parse failed, return nullopt.
     48  static std::optional<bool> IsFirstSliceSegmentInPic(
     49      ArrayView<const uint8_t> data);
     50 
     51 protected:
     52  enum Result {
     53    kOk,
     54    kInvalidStream,
     55    kUnsupportedStream,
     56  };
     57  void ParseSlice(ArrayView<const uint8_t> slice);
     58  Result ParseNonParameterSetNalu(ArrayView<const uint8_t> source,
     59                                  uint8_t nalu_type);
     60 
     61  const H265PpsParser::PpsState* GetPPS(uint32_t id) const;
     62  const H265SpsParser::SpsState* GetSPS(uint32_t id) const;
     63 
     64  // VPS/SPS/PPS state, updated when parsing new VPS/SPS/PPS, used to parse
     65  // slices.
     66  flat_map<uint32_t, H265VpsParser::VpsState> vps_;
     67  flat_map<uint32_t, H265SpsParser::SpsState> sps_;
     68  flat_map<uint32_t, H265PpsParser::PpsState> pps_;
     69 
     70  // Last parsed slice QP.
     71  std::optional<int32_t> last_slice_qp_delta_;
     72  std::optional<uint32_t> last_slice_pps_id_;
     73 };
     74 
     75 }  // namespace webrtc
     76 
     77 #endif  // COMMON_VIDEO_H265_H265_BITSTREAM_PARSER_H_