Replace ArrayView with std::span in common_video/ ArrayView is an alias to std::span. This change switch to use std::span directly instead of through the alias. Search&Replace MakeArrayView and ArrayView with std::span Search&Replace include "api/array_view.h" with include <span> Remove <span> include where std::span is not mentioned in the file Remove build dependencies on array_view target Bug: webrtc:439801349 Change-Id: Iabcb3e93425e1c0189e866ac3b249078fed833a9 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/460440 Auto-Submit: Danil Chapovalov <danilchap@webrtc.org> Reviewed-by: Evan Shrubsole <eshr@webrtc.org> Commit-Queue: Evan Shrubsole <eshr@webrtc.org> Cr-Commit-Position: refs/heads/main@{#47274}
diff --git a/common_video/BUILD.gn b/common_video/BUILD.gn index 527c1ee..5275321 100644 --- a/common_video/BUILD.gn +++ b/common_video/BUILD.gn
@@ -64,7 +64,6 @@ } deps = [ - "../api:array_view", "../api:make_ref_counted", "../api:scoped_refptr", "../api/units:time_delta", @@ -144,7 +143,6 @@ deps = [ ":common_video", - "../api:array_view", "../api:scoped_refptr", "../api/units:time_delta", "../api/units:timestamp",
diff --git a/common_video/h264/h264_bitstream_parser.cc b/common_video/h264/h264_bitstream_parser.cc index 1a66e5a..145e4d2 100644 --- a/common_video/h264/h264_bitstream_parser.cc +++ b/common_video/h264/h264_bitstream_parser.cc
@@ -12,9 +12,9 @@ #include <cstdint> #include <cstdlib> #include <optional> +#include <span> #include <vector> -#include "api/array_view.h" #include "common_video/h264/h264_common.h" #include "common_video/h264/pps_parser.h" #include "common_video/h264/sps_parser.h" @@ -34,7 +34,7 @@ H264BitstreamParser::~H264BitstreamParser() = default; H264BitstreamParser::Result H264BitstreamParser::ParseNonParameterSetNalu( - ArrayView<const uint8_t> source, + std::span<const uint8_t> source, uint8_t nalu_type) { if (!sps_ || !pps_) return kInvalidStream; @@ -311,7 +311,7 @@ return kOk; } -void H264BitstreamParser::ParseSlice(ArrayView<const uint8_t> slice) { +void H264BitstreamParser::ParseSlice(std::span<const uint8_t> slice) { if (slice.empty()) { return; } @@ -343,7 +343,7 @@ } } -void H264BitstreamParser::ParseBitstream(ArrayView<const uint8_t> bitstream) { +void H264BitstreamParser::ParseBitstream(std::span<const uint8_t> bitstream) { std::vector<H264::NaluIndex> nalu_indices = H264::FindNaluIndices(bitstream); for (const H264::NaluIndex& index : nalu_indices) ParseSlice(
diff --git a/common_video/h264/h264_bitstream_parser.h b/common_video/h264/h264_bitstream_parser.h index 2dafa86..810b91c 100644 --- a/common_video/h264/h264_bitstream_parser.h +++ b/common_video/h264/h264_bitstream_parser.h
@@ -14,8 +14,8 @@ #include <stdint.h> #include <optional> +#include <span> -#include "api/array_view.h" #include "api/video_codecs/bitstream_parser.h" #include "common_video/h264/pps_parser.h" #include "common_video/h264/sps_parser.h" @@ -33,7 +33,7 @@ H264BitstreamParser(); ~H264BitstreamParser() override; - void ParseBitstream(ArrayView<const uint8_t> bitstream) override; + void ParseBitstream(std::span<const uint8_t> bitstream) override; std::optional<int> GetLastSliceQp() const override; protected: @@ -42,8 +42,8 @@ kInvalidStream, kUnsupportedStream, }; - void ParseSlice(ArrayView<const uint8_t> slice); - Result ParseNonParameterSetNalu(ArrayView<const uint8_t> source, + void ParseSlice(std::span<const uint8_t> slice); + Result ParseNonParameterSetNalu(std::span<const uint8_t> source, uint8_t nalu_type); // SPS/PPS state, updated when parsing new SPS/PPS, used to parse slices.
diff --git a/common_video/h264/h264_common.cc b/common_video/h264/h264_common.cc index 4ab704c..387d360 100644 --- a/common_video/h264/h264_common.cc +++ b/common_video/h264/h264_common.cc
@@ -12,9 +12,9 @@ #include <cstddef> #include <cstdint> +#include <span> #include <vector> -#include "api/array_view.h" #include "rtc_base/buffer.h" namespace webrtc { @@ -22,7 +22,7 @@ const uint8_t kNaluTypeMask = 0x1F; -std::vector<NaluIndex> FindNaluIndices(ArrayView<const uint8_t> buffer) { +std::vector<NaluIndex> FindNaluIndices(std::span<const uint8_t> buffer) { // This is sorta like Boyer-Moore, but with only the first optimization step: // given a 3-byte sequence we're looking at, if the 3rd byte isn't 1 or 0, // skip ahead to the next 3-byte sequence. 0s and 1s are relatively rare, so @@ -72,7 +72,7 @@ return static_cast<NaluType>(data & kNaluTypeMask); } -std::vector<uint8_t> ParseRbsp(ArrayView<const uint8_t> data) { +std::vector<uint8_t> ParseRbsp(std::span<const uint8_t> data) { std::vector<uint8_t> out; out.reserve(data.size()); @@ -95,7 +95,7 @@ return out; } -void WriteRbsp(ArrayView<const uint8_t> bytes, Buffer* destination) { +void WriteRbsp(std::span<const uint8_t> bytes, Buffer* destination) { static const uint8_t kZerosInStartSequence = 2; static const uint8_t kEmulationByte = 0x03u; size_t num_consecutive_zeros = 0;
diff --git a/common_video/h264/h264_common.h b/common_video/h264/h264_common.h index 68c9504..932fb54 100644 --- a/common_video/h264/h264_common.h +++ b/common_video/h264/h264_common.h
@@ -14,9 +14,9 @@ #include <stddef.h> #include <stdint.h> +#include <span> #include <vector> -#include "api/array_view.h" #include "rtc_base/buffer.h" #include "rtc_base/system/rtc_export.h" @@ -65,7 +65,7 @@ // Returns a vector of the NALU indices in the given buffer. RTC_EXPORT std::vector<NaluIndex> FindNaluIndices( - ArrayView<const uint8_t> buffer); + std::span<const uint8_t> buffer); // Get the NAL type from the header byte immediately following start sequence. RTC_EXPORT NaluType ParseNaluType(uint8_t data); @@ -84,23 +84,23 @@ // the 03 emulation byte. // Parse the given data and remove any emulation byte escaping. -std::vector<uint8_t> ParseRbsp(ArrayView<const uint8_t> data); +std::vector<uint8_t> ParseRbsp(std::span<const uint8_t> data); // TODO: bugs.webrtc.org/42225170 - Deprecate. inline std::vector<uint8_t> ParseRbsp(const uint8_t* data, size_t length) { - return ParseRbsp(MakeArrayView(data, length)); + return ParseRbsp(std::span(data, length)); } // Write the given data to the destination buffer, inserting and emulation // bytes in order to escape any data the could be interpreted as a start // sequence. -void WriteRbsp(ArrayView<const uint8_t> bytes, Buffer* destination); +void WriteRbsp(std::span<const uint8_t> bytes, Buffer* destination); // TODO: bugs.webrtc.org/42225170 - Deprecate. inline void WriteRbsp(const uint8_t* bytes, size_t length, Buffer* destination) { - WriteRbsp(MakeArrayView(bytes, length), destination); + WriteRbsp(std::span(bytes, length), destination); } } // namespace H264 } // namespace webrtc
diff --git a/common_video/h264/pps_parser.cc b/common_video/h264/pps_parser.cc index dc36ba1..2ecfaa5 100644 --- a/common_video/h264/pps_parser.cc +++ b/common_video/h264/pps_parser.cc
@@ -13,10 +13,10 @@ #include <cstdint> #include <limits> #include <optional> +#include <span> #include <vector> #include "absl/numeric/bits.h" -#include "api/array_view.h" #include "common_video/h264/h264_common.h" #include "rtc_base/bitstream_reader.h" #include "rtc_base/checks.h" @@ -32,14 +32,14 @@ // http://www.itu.int/rec/T-REC-H.264 std::optional<PpsParser::PpsState> PpsParser::ParsePps( - ArrayView<const uint8_t> data) { + std::span<const uint8_t> data) { // First, parse out rbsp, which is basically the source buffer minus emulation // bytes (the last byte of a 0x00 0x00 0x03 sequence). RBSP is defined in // section 7.3.1 of the H.264 standard. return ParseInternal(H264::ParseRbsp(data)); } -bool PpsParser::ParsePpsIds(ArrayView<const uint8_t> data, +bool PpsParser::ParsePpsIds(std::span<const uint8_t> data, uint32_t* pps_id, uint32_t* sps_id) { RTC_DCHECK(pps_id); @@ -55,7 +55,7 @@ } std::optional<PpsParser::SliceHeader> PpsParser::ParseSliceHeader( - ArrayView<const uint8_t> data) { + std::span<const uint8_t> data) { std::vector<uint8_t> unpacked_buffer = H264::ParseRbsp(data); BitstreamReader slice_reader(unpacked_buffer); PpsParser::SliceHeader slice_header; @@ -76,7 +76,7 @@ } std::optional<PpsParser::PpsState> PpsParser::ParseInternal( - ArrayView<const uint8_t> buffer) { + std::span<const uint8_t> buffer) { BitstreamReader reader(buffer); PpsState pps; pps.id = reader.ReadExponentialGolomb();
diff --git a/common_video/h264/pps_parser.h b/common_video/h264/pps_parser.h index cdf3fb7..ef3ba21 100644 --- a/common_video/h264/pps_parser.h +++ b/common_video/h264/pps_parser.h
@@ -15,8 +15,7 @@ #include <stdint.h> #include <optional> - -#include "api/array_view.h" +#include <span> namespace webrtc { @@ -48,24 +47,24 @@ }; // Unpack RBSP and parse PPS state from the supplied buffer. - static std::optional<PpsState> ParsePps(ArrayView<const uint8_t> data); + static std::optional<PpsState> ParsePps(std::span<const uint8_t> data); // TODO: bugs.webrtc.org/42225170 - Deprecate. static inline std::optional<PpsState> ParsePps(const uint8_t* data, size_t length) { - return ParsePps(MakeArrayView(data, length)); + return ParsePps(std::span(data, length)); } - static bool ParsePpsIds(ArrayView<const uint8_t> data, + static bool ParsePpsIds(std::span<const uint8_t> data, uint32_t* pps_id, uint32_t* sps_id); static std::optional<SliceHeader> ParseSliceHeader( - ArrayView<const uint8_t> data); + std::span<const uint8_t> data); protected: // Parse the PPS state, for a buffer where RBSP decoding has already been // performed. - static std::optional<PpsState> ParseInternal(ArrayView<const uint8_t> buffer); + static std::optional<PpsState> ParseInternal(std::span<const uint8_t> buffer); }; } // namespace webrtc
diff --git a/common_video/h264/pps_parser_unittest.cc b/common_video/h264/pps_parser_unittest.cc index eb2891c..8bf1117 100644 --- a/common_video/h264/pps_parser_unittest.cc +++ b/common_video/h264/pps_parser_unittest.cc
@@ -13,9 +13,9 @@ #include <cstddef> #include <cstdint> #include <optional> +#include <span> #include <vector> -#include "api/array_view.h" #include "common_video/h264/h264_common.h" #include "rtc_base/bit_buffer.h" #include "rtc_base/buffer.h" @@ -138,7 +138,7 @@ bit_buffer.GetCurrentOffset(&byte_offset, &bit_offset); } - H264::WriteRbsp(MakeArrayView(data, byte_offset), out_buffer); + H264::WriteRbsp(std::span(data, byte_offset), out_buffer); } class PpsParserTest : public ::testing::Test { @@ -223,7 +223,7 @@ } TEST_F(PpsParserTest, ParseSliceHeader) { - ArrayView<const uint8_t> chunk(kH264BitstreamChunk); + std::span<const uint8_t> chunk(kH264BitstreamChunk); std::vector<H264::NaluIndex> nalu_indices = H264::FindNaluIndices(chunk); EXPECT_EQ(nalu_indices.size(), 3ull); for (const auto& index : nalu_indices) {
diff --git a/common_video/h264/sps_parser.cc b/common_video/h264/sps_parser.cc index 2ee431c..77945fe 100644 --- a/common_video/h264/sps_parser.cc +++ b/common_video/h264/sps_parser.cc
@@ -13,9 +13,9 @@ #include <cstddef> #include <cstdint> #include <optional> +#include <span> #include <vector> -#include "api/array_view.h" #include "common_video/h264/h264_common.h" #include "rtc_base/bitstream_reader.h" @@ -36,7 +36,7 @@ // Unpack RBSP and parse SPS state from the supplied buffer. std::optional<SpsParser::SpsState> SpsParser::ParseSps( - ArrayView<const uint8_t> data) { + std::span<const uint8_t> data) { std::vector<uint8_t> unpacked_buffer = H264::ParseRbsp(data); BitstreamReader reader(unpacked_buffer); return ParseSpsUpToVui(reader);
diff --git a/common_video/h264/sps_parser.h b/common_video/h264/sps_parser.h index b24194c..3091703 100644 --- a/common_video/h264/sps_parser.h +++ b/common_video/h264/sps_parser.h
@@ -13,8 +13,8 @@ #include <cstdint> #include <optional> +#include <span> -#include "api/array_view.h" #include "rtc_base/bitstream_reader.h" #include "rtc_base/system/rtc_export.h" @@ -45,7 +45,7 @@ }; // Unpack RBSP and parse SPS state from the supplied buffer. - static std::optional<SpsState> ParseSps(ArrayView<const uint8_t> data); + static std::optional<SpsState> ParseSps(std::span<const uint8_t> data); protected: // Parse the SPS state, up till the VUI part, for a buffer where RBSP
diff --git a/common_video/h264/sps_parser_unittest.cc b/common_video/h264/sps_parser_unittest.cc index d2396d0..6ab2152 100644 --- a/common_video/h264/sps_parser_unittest.cc +++ b/common_video/h264/sps_parser_unittest.cc
@@ -13,8 +13,8 @@ #include <cstddef> #include <cstdint> #include <optional> +#include <span> -#include "api/array_view.h" #include "common_video/h264/h264_common.h" #include "rtc_base/bit_buffer.h" #include "rtc_base/buffer.h" @@ -111,7 +111,7 @@ } out_buffer->Clear(); - H264::WriteRbsp(MakeArrayView(rbsp, byte_count), out_buffer); + H264::WriteRbsp(std::span(rbsp, byte_count), out_buffer); } TEST(H264SpsParserTest, TestSampleSPSHdLandscape) {
diff --git a/common_video/h264/sps_vui_rewriter.cc b/common_video/h264/sps_vui_rewriter.cc index 4481afd..be0cbf1 100644 --- a/common_video/h264/sps_vui_rewriter.cc +++ b/common_video/h264/sps_vui_rewriter.cc
@@ -15,9 +15,9 @@ #include <cstdint> #include <cstring> #include <optional> +#include <span> #include <vector> -#include "api/array_view.h" #include "api/video/color_space.h" #include "common_video/h264/h264_common.h" #include "common_video/h264/sps_parser.h" @@ -134,7 +134,7 @@ } SpsVuiRewriter::ParseResult SpsVuiRewriter::ParseAndRewriteSps( - ArrayView<const uint8_t> buffer, + std::span<const uint8_t> buffer, std::optional<SpsParser::SpsState>* sps, const ColorSpace* color_space, Buffer* destination) { @@ -211,7 +211,7 @@ } SpsVuiRewriter::ParseResult SpsVuiRewriter::ParseAndRewriteSps( - ArrayView<const uint8_t> buffer, + std::span<const uint8_t> buffer, std::optional<SpsParser::SpsState>* sps, const ColorSpace* color_space, Buffer* destination, @@ -223,7 +223,7 @@ } Buffer SpsVuiRewriter::ParseOutgoingBitstreamAndRewrite( - ArrayView<const uint8_t> buffer, + std::span<const uint8_t> buffer, const ColorSpace* color_space) { std::vector<H264::NaluIndex> nalus = H264::FindNaluIndices(buffer); @@ -233,10 +233,10 @@ for (const H264::NaluIndex& nalu_index : nalus) { // Copy NAL unit start code. - ArrayView<const uint8_t> start_code = buffer.subspan( + std::span<const uint8_t> start_code = buffer.subspan( nalu_index.start_offset, nalu_index.payload_start_offset - nalu_index.start_offset); - ArrayView<const uint8_t> nalu = buffer.subspan( + std::span<const uint8_t> nalu = buffer.subspan( nalu_index.payload_start_offset, nalu_index.payload_size); if (nalu.empty()) { continue;
diff --git a/common_video/h264/sps_vui_rewriter.h b/common_video/h264/sps_vui_rewriter.h index 665142f..d4e85cc 100644 --- a/common_video/h264/sps_vui_rewriter.h +++ b/common_video/h264/sps_vui_rewriter.h
@@ -16,8 +16,8 @@ #include <stdint.h> #include <optional> +#include <span> -#include "api/array_view.h" #include "api/video/color_space.h" #include "common_video/h264/sps_parser.h" #include "rtc_base/buffer.h" @@ -44,7 +44,7 @@ // SPS state. This function assumes that any previous headers // (NALU start, type, Stap-A, etc) have already been parsed and that RBSP // decoding has been performed. - static ParseResult ParseAndRewriteSps(ArrayView<const uint8_t> buffer, + static ParseResult ParseAndRewriteSps(std::span<const uint8_t> buffer, std::optional<SpsParser::SpsState>* sps, const ColorSpace* color_space, Buffer* destination, @@ -53,11 +53,11 @@ // Parses NAL units from `buffer`, strips AUD blocks and rewrites VUI in SPS // blocks if necessary. static Buffer ParseOutgoingBitstreamAndRewrite( - ArrayView<const uint8_t> buffer, + std::span<const uint8_t> buffer, const ColorSpace* color_space); private: - static ParseResult ParseAndRewriteSps(ArrayView<const uint8_t> buffer, + static ParseResult ParseAndRewriteSps(std::span<const uint8_t> buffer, std::optional<SpsParser::SpsState>* sps, const ColorSpace* color_space, Buffer* destination);
diff --git a/common_video/h264/sps_vui_rewriter_unittest.cc b/common_video/h264/sps_vui_rewriter_unittest.cc index c1ea803..ea31466 100644 --- a/common_video/h264/sps_vui_rewriter_unittest.cc +++ b/common_video/h264/sps_vui_rewriter_unittest.cc
@@ -13,9 +13,9 @@ #include <cstddef> #include <cstdint> #include <optional> +#include <span> #include <tuple> -#include "api/array_view.h" #include "api/video/color_space.h" #include "common_video/h264/h264_common.h" #include "common_video/h264/sps_parser.h" @@ -250,7 +250,7 @@ byte_count++; } - H264::WriteRbsp(MakeArrayView(rbsp, byte_count), out_buffer); + H264::WriteRbsp(std::span(rbsp, byte_count), out_buffer); } void TestSps(const VuiHeader& vui,
diff --git a/common_video/h265/h265_bitstream_parser.cc b/common_video/h265/h265_bitstream_parser.cc index b00080d..960f88c 100644 --- a/common_video/h265/h265_bitstream_parser.cc +++ b/common_video/h265/h265_bitstream_parser.cc
@@ -14,9 +14,9 @@ #include <cstdlib> #include <limits> #include <optional> +#include <span> #include <vector> -#include "api/array_view.h" #include "common_video/h265/h265_common.h" #include "common_video/h265/h265_pps_parser.h" #include "common_video/h265/h265_sps_parser.h" @@ -84,7 +84,7 @@ // section 7.3.6.1. You can find it on this page: // http://www.itu.int/rec/T-REC-H.265 H265BitstreamParser::Result H265BitstreamParser::ParseNonParameterSetNalu( - ArrayView<const uint8_t> source, + std::span<const uint8_t> source, uint8_t nalu_type) { last_slice_qp_delta_ = std::nullopt; last_slice_pps_id_ = std::nullopt; @@ -520,7 +520,7 @@ return &it->second; } -void H265BitstreamParser::ParseSlice(ArrayView<const uint8_t> slice) { +void H265BitstreamParser::ParseSlice(std::span<const uint8_t> slice) { if (slice.empty()) { RTC_LOG(LS_WARNING) << "Empty slice in H265 bitstream."; return; @@ -594,7 +594,7 @@ std::optional<uint32_t> H265BitstreamParser::ParsePpsIdFromSliceSegmentLayerRbsp( - ArrayView<const uint8_t> data, + std::span<const uint8_t> data, uint8_t nalu_type) { std::vector<uint8_t> unpacked_buffer = H265::ParseRbsp(data); BitstreamReader slice_reader(unpacked_buffer); @@ -622,7 +622,7 @@ } std::optional<bool> H265BitstreamParser::IsFirstSliceSegmentInPic( - ArrayView<const uint8_t> data) { + std::span<const uint8_t> data) { std::vector<uint8_t> unpacked_buffer = H265::ParseRbsp(data); BitstreamReader slice_reader(unpacked_buffer); @@ -635,7 +635,7 @@ return first_slice_segment_in_pic_flag; } -void H265BitstreamParser::ParseBitstream(ArrayView<const uint8_t> bitstream) { +void H265BitstreamParser::ParseBitstream(std::span<const uint8_t> bitstream) { std::vector<H265::NaluIndex> nalu_indices = H265::FindNaluIndices(bitstream); for (const H265::NaluIndex& index : nalu_indices) ParseSlice(
diff --git a/common_video/h265/h265_bitstream_parser.h b/common_video/h265/h265_bitstream_parser.h index 20eb8df..f7b1929 100644 --- a/common_video/h265/h265_bitstream_parser.h +++ b/common_video/h265/h265_bitstream_parser.h
@@ -15,8 +15,8 @@ #include <stdint.h> #include <optional> +#include <span> -#include "api/array_view.h" #include "api/video_codecs/bitstream_parser.h" #include "common_video/h265/h265_pps_parser.h" #include "common_video/h265/h265_sps_parser.h" @@ -34,19 +34,19 @@ ~H265BitstreamParser() override; // New interface. - void ParseBitstream(ArrayView<const uint8_t> bitstream) override; + void ParseBitstream(std::span<const uint8_t> bitstream) override; std::optional<int> GetLastSliceQp() const override; std::optional<uint32_t> GetLastSlicePpsId() const; static std::optional<uint32_t> ParsePpsIdFromSliceSegmentLayerRbsp( - ArrayView<const uint8_t> data, + std::span<const uint8_t> data, uint8_t nalu_type); // Returns true if the slice segment is the first in the picture; otherwise // return false. If parse failed, return nullopt. static std::optional<bool> IsFirstSliceSegmentInPic( - ArrayView<const uint8_t> data); + std::span<const uint8_t> data); protected: enum Result { @@ -54,8 +54,8 @@ kInvalidStream, kUnsupportedStream, }; - void ParseSlice(ArrayView<const uint8_t> slice); - Result ParseNonParameterSetNalu(ArrayView<const uint8_t> source, + void ParseSlice(std::span<const uint8_t> slice); + Result ParseNonParameterSetNalu(std::span<const uint8_t> source, uint8_t nalu_type); const H265PpsParser::PpsState* GetPPS(uint32_t id) const;
diff --git a/common_video/h265/h265_bitstream_parser_unittest.cc b/common_video/h265/h265_bitstream_parser_unittest.cc index 1045a47..e37b686 100644 --- a/common_video/h265/h265_bitstream_parser_unittest.cc +++ b/common_video/h265/h265_bitstream_parser_unittest.cc
@@ -13,7 +13,6 @@ #include <cstdint> #include <optional> -#include "api/array_view.h" #include "common_video/h265/h265_common.h" #include "test/gmock.h" #include "test/gtest.h"
diff --git a/common_video/h265/h265_common.cc b/common_video/h265/h265_common.cc index 332bab7..528145b 100644 --- a/common_video/h265/h265_common.cc +++ b/common_video/h265/h265_common.cc
@@ -11,9 +11,9 @@ #include "common_video/h265/h265_common.h" #include <cstdint> +#include <span> #include <vector> -#include "api/array_view.h" #include "common_video/h264/h264_common.h" #include "common_video/h265/h265_inline.h" #include "rtc_base/buffer.h" @@ -23,7 +23,7 @@ constexpr uint8_t kNaluTypeMask = 0x7E; -std::vector<NaluIndex> FindNaluIndices(ArrayView<const uint8_t> buffer) { +std::vector<NaluIndex> FindNaluIndices(std::span<const uint8_t> buffer) { std::vector<H264::NaluIndex> indices = H264::FindNaluIndices(buffer); std::vector<NaluIndex> results; results.reserve(indices.size()); @@ -39,11 +39,11 @@ return static_cast<NaluType>((data & kNaluTypeMask) >> 1); } -std::vector<uint8_t> ParseRbsp(ArrayView<const uint8_t> data) { +std::vector<uint8_t> ParseRbsp(std::span<const uint8_t> data) { return H264::ParseRbsp(data); } -void WriteRbsp(ArrayView<const uint8_t> bytes, Buffer* destination) { +void WriteRbsp(std::span<const uint8_t> bytes, Buffer* destination) { H264::WriteRbsp(bytes, destination); }
diff --git a/common_video/h265/h265_common.h b/common_video/h265/h265_common.h index 9ce9fbe..2cc83ea 100644 --- a/common_video/h265/h265_common.h +++ b/common_video/h265/h265_common.h
@@ -13,9 +13,9 @@ #include <cstddef> #include <cstdint> +#include <span> #include <vector> -#include "api/array_view.h" #include "rtc_base/buffer.h" #include "rtc_base/system/rtc_export.h" @@ -80,12 +80,12 @@ // Returns a vector of the NALU indices in the given buffer. RTC_EXPORT std::vector<NaluIndex> FindNaluIndices( - ArrayView<const uint8_t> buffer); + std::span<const uint8_t> buffer); // TODO: bugs.webrtc.org/42225170 - Deprecate. inline std::vector<NaluIndex> FindNaluIndices(const uint8_t* buffer, size_t buffer_size) { - return FindNaluIndices(MakeArrayView(buffer, buffer_size)); + return FindNaluIndices(std::span(buffer, buffer_size)); } // Get the NAL type from the header byte immediately following start sequence. @@ -105,23 +105,23 @@ // the 03 emulation byte. // Parse the given data and remove any emulation byte escaping. -std::vector<uint8_t> ParseRbsp(ArrayView<const uint8_t> data); +std::vector<uint8_t> ParseRbsp(std::span<const uint8_t> data); // TODO: bugs.webrtc.org/42225170 - Deprecate. inline std::vector<uint8_t> ParseRbsp(const uint8_t* data, size_t length) { - return ParseRbsp(MakeArrayView(data, length)); + return ParseRbsp(std::span(data, length)); } // Write the given data to the destination buffer, inserting and emulation // bytes in order to escape any data the could be interpreted as a start // sequence. -void WriteRbsp(ArrayView<const uint8_t> bytes, Buffer* destination); +void WriteRbsp(std::span<const uint8_t> bytes, Buffer* destination); // TODO: bugs.webrtc.org/42225170 - Deprecate. inline void WriteRbsp(const uint8_t* bytes, size_t length, Buffer* destination) { - WriteRbsp(MakeArrayView(bytes, length), destination); + WriteRbsp(std::span(bytes, length), destination); } uint32_t Log2Ceiling(uint32_t value);
diff --git a/common_video/h265/h265_pps_parser.cc b/common_video/h265/h265_pps_parser.cc index a5f7adb..460e936 100644 --- a/common_video/h265/h265_pps_parser.cc +++ b/common_video/h265/h265_pps_parser.cc
@@ -12,9 +12,9 @@ #include <cstdint> #include <optional> +#include <span> #include <vector> -#include "api/array_view.h" #include "common_video/h265/h265_common.h" #include "common_video/h265/h265_sps_parser.h" #include "rtc_base/bitstream_reader.h" @@ -65,7 +65,7 @@ // http://www.itu.int/rec/T-REC-H.265 std::optional<H265PpsParser::PpsState> H265PpsParser::ParsePps( - ArrayView<const uint8_t> data, + std::span<const uint8_t> data, const H265SpsParser::SpsState* sps) { // First, parse out rbsp, which is basically the source buffer minus emulation // bytes (the last byte of a 0x00 0x00 0x03 sequence). RBSP is defined in @@ -73,7 +73,7 @@ return ParseInternal(H265::ParseRbsp(data), sps); } -bool H265PpsParser::ParsePpsIds(ArrayView<const uint8_t> data, +bool H265PpsParser::ParsePpsIds(std::span<const uint8_t> data, uint32_t* pps_id, uint32_t* sps_id) { RTC_DCHECK(pps_id); @@ -91,7 +91,7 @@ } std::optional<H265PpsParser::PpsState> H265PpsParser::ParseInternal( - ArrayView<const uint8_t> buffer, + std::span<const uint8_t> buffer, const H265SpsParser::SpsState* sps) { BitstreamReader reader(buffer); PpsState pps;
diff --git a/common_video/h265/h265_pps_parser.h b/common_video/h265/h265_pps_parser.h index 2cb3f67..c73be46 100644 --- a/common_video/h265/h265_pps_parser.h +++ b/common_video/h265/h265_pps_parser.h
@@ -14,8 +14,8 @@ #include <cstddef> #include <cstdint> #include <optional> +#include <span> -#include "api/array_view.h" #include "common_video/h265/h265_sps_parser.h" #include "rtc_base/bitstream_reader.h" #include "rtc_base/system/rtc_export.h" @@ -46,17 +46,17 @@ }; // Unpack RBSP and parse PPS state from the supplied buffer. - static std::optional<PpsState> ParsePps(ArrayView<const uint8_t> data, + static std::optional<PpsState> ParsePps(std::span<const uint8_t> data, const H265SpsParser::SpsState* sps); // TODO: bugs.webrtc.org/42225170 - Deprecate. static inline std::optional<PpsState> ParsePps( const uint8_t* data, size_t length, const H265SpsParser::SpsState* sps) { - return ParsePps(MakeArrayView(data, length), sps); + return ParsePps(std::span(data, length), sps); } - static bool ParsePpsIds(ArrayView<const uint8_t> data, + static bool ParsePpsIds(std::span<const uint8_t> data, uint32_t* pps_id, uint32_t* sps_id); // TODO: bugs.webrtc.org/42225170 - Deprecate. @@ -64,14 +64,14 @@ size_t length, uint32_t* pps_id, uint32_t* sps_id) { - return ParsePpsIds(MakeArrayView(data, length), pps_id, sps_id); + return ParsePpsIds(std::span(data, length), pps_id, sps_id); } protected: // Parse the PPS state, for a bit buffer where RBSP decoding has already been // performed. static std::optional<PpsState> ParseInternal( - ArrayView<const uint8_t> buffer, + std::span<const uint8_t> buffer, const H265SpsParser::SpsState* sps); static bool ParsePpsIdsInternal(BitstreamReader& reader, uint32_t& pps_id,
diff --git a/common_video/h265/h265_pps_parser_unittest.cc b/common_video/h265/h265_pps_parser_unittest.cc index 688e9e9..668b89a 100644 --- a/common_video/h265/h265_pps_parser_unittest.cc +++ b/common_video/h265/h265_pps_parser_unittest.cc
@@ -14,8 +14,8 @@ #include <cstddef> #include <cstdint> #include <optional> +#include <span> -#include "api/array_view.h" #include "common_video/h265/h265_common.h" #include "common_video/h265/h265_sps_parser.h" #include "rtc_base/bit_buffer.h" @@ -164,7 +164,7 @@ bit_buffer.GetCurrentOffset(&byte_offset, &bit_offset); } - H265::WriteRbsp(MakeArrayView(data, byte_offset), out_buffer); + H265::WriteRbsp(std::span(data, byte_offset), out_buffer); } class H265PpsParserTest : public ::testing::Test {
diff --git a/common_video/h265/h265_sps_parser.cc b/common_video/h265/h265_sps_parser.cc index 0916de5..da6f913 100644 --- a/common_video/h265/h265_sps_parser.cc +++ b/common_video/h265/h265_sps_parser.cc
@@ -15,9 +15,9 @@ #include <cstddef> #include <cstdint> #include <optional> +#include <span> #include <vector> -#include "api/array_view.h" #include "common_video/h265/h265_common.h" #include "rtc_base/bitstream_reader.h" #include "rtc_base/logging.h" @@ -107,7 +107,7 @@ // Unpack RBSP and parse SPS state from the supplied buffer. std::optional<H265SpsParser::SpsState> H265SpsParser::ParseSps( - ArrayView<const uint8_t> data) { + std::span<const uint8_t> data) { return ParseSpsInternal(H265::ParseRbsp(data)); } @@ -388,7 +388,7 @@ } std::optional<H265SpsParser::SpsState> H265SpsParser::ParseSpsInternal( - ArrayView<const uint8_t> buffer) { + std::span<const uint8_t> buffer) { BitstreamReader reader(buffer); // Now, we need to use a bit buffer to parse through the actual H265 SPS
diff --git a/common_video/h265/h265_sps_parser.h b/common_video/h265/h265_sps_parser.h index 1bccf6a..03e588d 100644 --- a/common_video/h265/h265_sps_parser.h +++ b/common_video/h265/h265_sps_parser.h
@@ -14,9 +14,9 @@ #include <cstddef> #include <cstdint> #include <optional> +#include <span> #include <vector> -#include "api/array_view.h" #include "rtc_base/bitstream_reader.h" #include "rtc_base/system/rtc_export.h" @@ -106,11 +106,11 @@ }; // Unpack RBSP and parse SPS state from the supplied buffer. - static std::optional<SpsState> ParseSps(ArrayView<const uint8_t> data); + static std::optional<SpsState> ParseSps(std::span<const uint8_t> data); // TODO: bugs.webrtc.org/42225170 - Deprecate. static inline std::optional<SpsState> ParseSps(const uint8_t* data, size_t length) { - return ParseSps(MakeArrayView(data, length)); + return ParseSps(std::span(data, length)); } static bool ParseScalingListData(BitstreamReader& reader); @@ -131,7 +131,7 @@ // Parse the SPS state, for a bit buffer where RBSP decoding has already been // performed. static std::optional<SpsState> ParseSpsInternal( - ArrayView<const uint8_t> buffer); + std::span<const uint8_t> buffer); // From Table A.8 - General tier and level limits. static int GetMaxLumaPs(int general_level_idc);
diff --git a/common_video/h265/h265_sps_parser_unittest.cc b/common_video/h265/h265_sps_parser_unittest.cc index 1d3e1b2..5a8e051 100644 --- a/common_video/h265/h265_sps_parser_unittest.cc +++ b/common_video/h265/h265_sps_parser_unittest.cc
@@ -13,9 +13,9 @@ #include <cstddef> #include <cstdint> #include <optional> +#include <span> #include <vector> -#include "api/array_view.h" #include "common_video/h265/h265_common.h" #include "rtc_base/bit_buffer.h" #include "rtc_base/buffer.h" @@ -370,7 +370,7 @@ } out_buffer->Clear(); - H265::WriteRbsp(MakeArrayView(rbsp, byte_count), out_buffer); + H265::WriteRbsp(std::span(rbsp, byte_count), out_buffer); } class H265SpsParserTest : public ::testing::Test {
diff --git a/common_video/h265/h265_vps_parser.cc b/common_video/h265/h265_vps_parser.cc index 8ebe5f9..83821c5 100644 --- a/common_video/h265/h265_vps_parser.cc +++ b/common_video/h265/h265_vps_parser.cc
@@ -12,8 +12,8 @@ #include <cstdint> #include <optional> +#include <span> -#include "api/array_view.h" #include "common_video/h265/h265_common.h" #include "rtc_base/bitstream_reader.h" @@ -27,12 +27,12 @@ // Unpack RBSP and parse VPS state from the supplied buffer. std::optional<H265VpsParser::VpsState> H265VpsParser::ParseVps( - ArrayView<const uint8_t> data) { + std::span<const uint8_t> data) { return ParseInternal(H265::ParseRbsp(data)); } std::optional<H265VpsParser::VpsState> H265VpsParser::ParseInternal( - ArrayView<const uint8_t> buffer) { + std::span<const uint8_t> buffer) { BitstreamReader reader(buffer); // Now, we need to use a bit buffer to parse through the actual H265 VPS
diff --git a/common_video/h265/h265_vps_parser.h b/common_video/h265/h265_vps_parser.h index e890e4e..ad423d2 100644 --- a/common_video/h265/h265_vps_parser.h +++ b/common_video/h265/h265_vps_parser.h
@@ -14,8 +14,8 @@ #include <cstddef> #include <cstdint> #include <optional> +#include <span> -#include "api/array_view.h" #include "rtc_base/system/rtc_export.h" namespace webrtc { @@ -32,17 +32,17 @@ }; // Unpack RBSP and parse VPS state from the supplied buffer. - static std::optional<VpsState> ParseVps(ArrayView<const uint8_t> data); + static std::optional<VpsState> ParseVps(std::span<const uint8_t> data); // TODO: bugs.webrtc.org/42225170 - Deprecate. static inline std::optional<VpsState> ParseVps(const uint8_t* data, size_t length) { - return ParseVps(MakeArrayView(data, length)); + return ParseVps(std::span(data, length)); } protected: // Parse the VPS state, for a bit buffer where RBSP decoding has already been // performed. - static std::optional<VpsState> ParseInternal(ArrayView<const uint8_t> buffer); + static std::optional<VpsState> ParseInternal(std::span<const uint8_t> buffer); }; } // namespace webrtc