From 47601ff208f695fb04ba146fb1d854895b8f0058 Mon Sep 17 00:00:00 2001 From: Danil Chapovalov Date: Thu, 26 Mar 2026 16:20:25 +0100 Subject: [PATCH] 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 Remove 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 Reviewed-by: Evan Shrubsole Commit-Queue: Evan Shrubsole Cr-Commit-Position: refs/heads/main@{#47274} --- common_video/BUILD.gn | 2 -- common_video/h264/h264_bitstream_parser.cc | 8 ++++---- common_video/h264/h264_bitstream_parser.h | 8 ++++---- common_video/h264/h264_common.cc | 8 ++++---- common_video/h264/h264_common.h | 12 ++++++------ common_video/h264/pps_parser.cc | 10 +++++----- common_video/h264/pps_parser.h | 13 ++++++------- common_video/h264/pps_parser_unittest.cc | 6 +++--- common_video/h264/sps_parser.cc | 4 ++-- common_video/h264/sps_parser.h | 4 ++-- common_video/h264/sps_parser_unittest.cc | 4 ++-- common_video/h264/sps_vui_rewriter.cc | 12 ++++++------ common_video/h264/sps_vui_rewriter.h | 8 ++++---- common_video/h264/sps_vui_rewriter_unittest.cc | 4 ++-- common_video/h265/h265_bitstream_parser.cc | 12 ++++++------ common_video/h265/h265_bitstream_parser.h | 12 ++++++------ .../h265/h265_bitstream_parser_unittest.cc | 1 - common_video/h265/h265_common.cc | 8 ++++---- common_video/h265/h265_common.h | 14 +++++++------- common_video/h265/h265_pps_parser.cc | 8 ++++---- common_video/h265/h265_pps_parser.h | 12 ++++++------ common_video/h265/h265_pps_parser_unittest.cc | 4 ++-- common_video/h265/h265_sps_parser.cc | 6 +++--- common_video/h265/h265_sps_parser.h | 8 ++++---- common_video/h265/h265_sps_parser_unittest.cc | 4 ++-- common_video/h265/h265_vps_parser.cc | 6 +++--- common_video/h265/h265_vps_parser.h | 8 ++++---- 27 files changed, 101 insertions(+), 105 deletions(-) diff --git a/common_video/BUILD.gn b/common_video/BUILD.gn index 527c1ee4ae..52753212af 100644 --- a/common_video/BUILD.gn +++ b/common_video/BUILD.gn @@ -64,7 +64,6 @@ rtc_library("common_video") { } deps = [ - "../api:array_view", "../api:make_ref_counted", "../api:scoped_refptr", "../api/units:time_delta", @@ -144,7 +143,6 @@ if (rtc_include_tests && !build_with_chromium) { 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 1a66e5a88a..145e4d2d8d 100644 --- a/common_video/h264/h264_bitstream_parser.cc +++ b/common_video/h264/h264_bitstream_parser.cc @@ -12,9 +12,9 @@ #include #include #include +#include #include -#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::~H264BitstreamParser() = default; H264BitstreamParser::Result H264BitstreamParser::ParseNonParameterSetNalu( - ArrayView source, + std::span source, uint8_t nalu_type) { if (!sps_ || !pps_) return kInvalidStream; @@ -311,7 +311,7 @@ H264BitstreamParser::Result H264BitstreamParser::ParseNonParameterSetNalu( return kOk; } -void H264BitstreamParser::ParseSlice(ArrayView slice) { +void H264BitstreamParser::ParseSlice(std::span slice) { if (slice.empty()) { return; } @@ -343,7 +343,7 @@ void H264BitstreamParser::ParseSlice(ArrayView slice) { } } -void H264BitstreamParser::ParseBitstream(ArrayView bitstream) { +void H264BitstreamParser::ParseBitstream(std::span bitstream) { std::vector 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 2dafa86185..810b91cbdd 100644 --- a/common_video/h264/h264_bitstream_parser.h +++ b/common_video/h264/h264_bitstream_parser.h @@ -14,8 +14,8 @@ #include #include +#include -#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 @@ class H264BitstreamParser : public BitstreamParser { H264BitstreamParser(); ~H264BitstreamParser() override; - void ParseBitstream(ArrayView bitstream) override; + void ParseBitstream(std::span bitstream) override; std::optional GetLastSliceQp() const override; protected: @@ -42,8 +42,8 @@ class H264BitstreamParser : public BitstreamParser { kInvalidStream, kUnsupportedStream, }; - void ParseSlice(ArrayView slice); - Result ParseNonParameterSetNalu(ArrayView source, + void ParseSlice(std::span slice); + Result ParseNonParameterSetNalu(std::span 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 4ab704c4eb..387d360d4a 100644 --- a/common_video/h264/h264_common.cc +++ b/common_video/h264/h264_common.cc @@ -12,9 +12,9 @@ #include #include +#include #include -#include "api/array_view.h" #include "rtc_base/buffer.h" namespace webrtc { @@ -22,7 +22,7 @@ namespace H264 { const uint8_t kNaluTypeMask = 0x1F; -std::vector FindNaluIndices(ArrayView buffer) { +std::vector FindNaluIndices(std::span 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 @@ NaluType ParseNaluType(uint8_t data) { return static_cast(data & kNaluTypeMask); } -std::vector ParseRbsp(ArrayView data) { +std::vector ParseRbsp(std::span data) { std::vector out; out.reserve(data.size()); @@ -95,7 +95,7 @@ std::vector ParseRbsp(ArrayView data) { return out; } -void WriteRbsp(ArrayView bytes, Buffer* destination) { +void WriteRbsp(std::span 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 68c9504107..932fb54604 100644 --- a/common_video/h264/h264_common.h +++ b/common_video/h264/h264_common.h @@ -14,9 +14,9 @@ #include #include +#include #include -#include "api/array_view.h" #include "rtc_base/buffer.h" #include "rtc_base/system/rtc_export.h" @@ -65,7 +65,7 @@ struct NaluIndex { // Returns a vector of the NALU indices in the given buffer. RTC_EXPORT std::vector FindNaluIndices( - ArrayView buffer); + std::span buffer); // Get the NAL type from the header byte immediately following start sequence. RTC_EXPORT NaluType ParseNaluType(uint8_t data); @@ -84,23 +84,23 @@ RTC_EXPORT NaluType ParseNaluType(uint8_t data); // the 03 emulation byte. // Parse the given data and remove any emulation byte escaping. -std::vector ParseRbsp(ArrayView data); +std::vector ParseRbsp(std::span data); // TODO: bugs.webrtc.org/42225170 - Deprecate. inline std::vector 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 bytes, Buffer* destination); +void WriteRbsp(std::span 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 dc36ba1d10..2ecfaa55a1 100644 --- a/common_video/h264/pps_parser.cc +++ b/common_video/h264/pps_parser.cc @@ -13,10 +13,10 @@ #include #include #include +#include #include #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 @@ constexpr int kMinPicInitQpDeltaValue = -26; // http://www.itu.int/rec/T-REC-H.264 std::optional PpsParser::ParsePps( - ArrayView data) { + std::span 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 data, +bool PpsParser::ParsePpsIds(std::span data, uint32_t* pps_id, uint32_t* sps_id) { RTC_DCHECK(pps_id); @@ -55,7 +55,7 @@ bool PpsParser::ParsePpsIds(ArrayView data, } std::optional PpsParser::ParseSliceHeader( - ArrayView data) { + std::span data) { std::vector unpacked_buffer = H264::ParseRbsp(data); BitstreamReader slice_reader(unpacked_buffer); PpsParser::SliceHeader slice_header; @@ -76,7 +76,7 @@ std::optional PpsParser::ParseSliceHeader( } std::optional PpsParser::ParseInternal( - ArrayView buffer) { + std::span 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 cdf3fb79a0..ef3ba21859 100644 --- a/common_video/h264/pps_parser.h +++ b/common_video/h264/pps_parser.h @@ -15,8 +15,7 @@ #include #include - -#include "api/array_view.h" +#include namespace webrtc { @@ -48,24 +47,24 @@ class PpsParser { }; // Unpack RBSP and parse PPS state from the supplied buffer. - static std::optional ParsePps(ArrayView data); + static std::optional ParsePps(std::span data); // TODO: bugs.webrtc.org/42225170 - Deprecate. static inline std::optional ParsePps(const uint8_t* data, size_t length) { - return ParsePps(MakeArrayView(data, length)); + return ParsePps(std::span(data, length)); } - static bool ParsePpsIds(ArrayView data, + static bool ParsePpsIds(std::span data, uint32_t* pps_id, uint32_t* sps_id); static std::optional ParseSliceHeader( - ArrayView data); + std::span data); protected: // Parse the PPS state, for a buffer where RBSP decoding has already been // performed. - static std::optional ParseInternal(ArrayView buffer); + static std::optional ParseInternal(std::span buffer); }; } // namespace webrtc diff --git a/common_video/h264/pps_parser_unittest.cc b/common_video/h264/pps_parser_unittest.cc index eb2891c8cb..8bf1117bf5 100644 --- a/common_video/h264/pps_parser_unittest.cc +++ b/common_video/h264/pps_parser_unittest.cc @@ -13,9 +13,9 @@ #include #include #include +#include #include -#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 @@ void WritePps(const PpsParser::PpsState& pps, 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, MaxPps) { } TEST_F(PpsParserTest, ParseSliceHeader) { - ArrayView chunk(kH264BitstreamChunk); + std::span chunk(kH264BitstreamChunk); std::vector 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 2ee431c7e5..77945fe308 100644 --- a/common_video/h264/sps_parser.cc +++ b/common_video/h264/sps_parser.cc @@ -13,9 +13,9 @@ #include #include #include +#include #include -#include "api/array_view.h" #include "common_video/h264/h264_common.h" #include "rtc_base/bitstream_reader.h" @@ -36,7 +36,7 @@ SpsParser::SpsState::~SpsState() = default; // Unpack RBSP and parse SPS state from the supplied buffer. std::optional SpsParser::ParseSps( - ArrayView data) { + std::span data) { std::vector 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 b24194c6e9..3091703a21 100644 --- a/common_video/h264/sps_parser.h +++ b/common_video/h264/sps_parser.h @@ -13,8 +13,8 @@ #include #include +#include -#include "api/array_view.h" #include "rtc_base/bitstream_reader.h" #include "rtc_base/system/rtc_export.h" @@ -45,7 +45,7 @@ class RTC_EXPORT SpsParser { }; // Unpack RBSP and parse SPS state from the supplied buffer. - static std::optional ParseSps(ArrayView data); + static std::optional ParseSps(std::span 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 d2396d016a..6ab2152725 100644 --- a/common_video/h264/sps_parser_unittest.cc +++ b/common_video/h264/sps_parser_unittest.cc @@ -13,8 +13,8 @@ #include #include #include +#include -#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 @@ void GenerateFakeSps(uint16_t width, } 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 4481afdd37..be0cbf123d 100644 --- a/common_video/h264/sps_vui_rewriter.cc +++ b/common_video/h264/sps_vui_rewriter.cc @@ -15,9 +15,9 @@ #include #include #include +#include #include -#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 @@ void SpsVuiRewriter::UpdateStats(ParseResult result, Direction direction) { } SpsVuiRewriter::ParseResult SpsVuiRewriter::ParseAndRewriteSps( - ArrayView buffer, + std::span buffer, std::optional* sps, const ColorSpace* color_space, Buffer* destination) { @@ -211,7 +211,7 @@ SpsVuiRewriter::ParseResult SpsVuiRewriter::ParseAndRewriteSps( } SpsVuiRewriter::ParseResult SpsVuiRewriter::ParseAndRewriteSps( - ArrayView buffer, + std::span buffer, std::optional* sps, const ColorSpace* color_space, Buffer* destination, @@ -223,7 +223,7 @@ SpsVuiRewriter::ParseResult SpsVuiRewriter::ParseAndRewriteSps( } Buffer SpsVuiRewriter::ParseOutgoingBitstreamAndRewrite( - ArrayView buffer, + std::span buffer, const ColorSpace* color_space) { std::vector nalus = H264::FindNaluIndices(buffer); @@ -233,10 +233,10 @@ Buffer SpsVuiRewriter::ParseOutgoingBitstreamAndRewrite( for (const H264::NaluIndex& nalu_index : nalus) { // Copy NAL unit start code. - ArrayView start_code = buffer.subspan( + std::span start_code = buffer.subspan( nalu_index.start_offset, nalu_index.payload_start_offset - nalu_index.start_offset); - ArrayView nalu = buffer.subspan( + std::span 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 665142f3a0..d4e85cc9f4 100644 --- a/common_video/h264/sps_vui_rewriter.h +++ b/common_video/h264/sps_vui_rewriter.h @@ -16,8 +16,8 @@ #include #include +#include -#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 @@ class SpsVuiRewriter : private SpsParser { // 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 buffer, + static ParseResult ParseAndRewriteSps(std::span buffer, std::optional* sps, const ColorSpace* color_space, Buffer* destination, @@ -53,11 +53,11 @@ class SpsVuiRewriter : private SpsParser { // Parses NAL units from `buffer`, strips AUD blocks and rewrites VUI in SPS // blocks if necessary. static Buffer ParseOutgoingBitstreamAndRewrite( - ArrayView buffer, + std::span buffer, const ColorSpace* color_space); private: - static ParseResult ParseAndRewriteSps(ArrayView buffer, + static ParseResult ParseAndRewriteSps(std::span buffer, std::optional* 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 c1ea8038a3..ea31466a97 100644 --- a/common_video/h264/sps_vui_rewriter_unittest.cc +++ b/common_video/h264/sps_vui_rewriter_unittest.cc @@ -13,9 +13,9 @@ #include #include #include +#include #include -#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 @@ void GenerateFakeSps(const VuiHeader& vui, Buffer* out_buffer) { 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 b00080dae6..960f88c9c8 100644 --- a/common_video/h265/h265_bitstream_parser.cc +++ b/common_video/h265/h265_bitstream_parser.cc @@ -14,9 +14,9 @@ #include #include #include +#include #include -#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 @@ H265BitstreamParser::~H265BitstreamParser() = default; // 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 source, + std::span source, uint8_t nalu_type) { last_slice_qp_delta_ = std::nullopt; last_slice_pps_id_ = std::nullopt; @@ -520,7 +520,7 @@ const H265SpsParser::SpsState* H265BitstreamParser::GetSPS(uint32_t id) const { return &it->second; } -void H265BitstreamParser::ParseSlice(ArrayView slice) { +void H265BitstreamParser::ParseSlice(std::span slice) { if (slice.empty()) { RTC_LOG(LS_WARNING) << "Empty slice in H265 bitstream."; return; @@ -594,7 +594,7 @@ void H265BitstreamParser::ParseSlice(ArrayView slice) { std::optional H265BitstreamParser::ParsePpsIdFromSliceSegmentLayerRbsp( - ArrayView data, + std::span data, uint8_t nalu_type) { std::vector unpacked_buffer = H265::ParseRbsp(data); BitstreamReader slice_reader(unpacked_buffer); @@ -622,7 +622,7 @@ H265BitstreamParser::ParsePpsIdFromSliceSegmentLayerRbsp( } std::optional H265BitstreamParser::IsFirstSliceSegmentInPic( - ArrayView data) { + std::span data) { std::vector unpacked_buffer = H265::ParseRbsp(data); BitstreamReader slice_reader(unpacked_buffer); @@ -635,7 +635,7 @@ std::optional H265BitstreamParser::IsFirstSliceSegmentInPic( return first_slice_segment_in_pic_flag; } -void H265BitstreamParser::ParseBitstream(ArrayView bitstream) { +void H265BitstreamParser::ParseBitstream(std::span bitstream) { std::vector 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 20eb8dfb74..f7b19297fe 100644 --- a/common_video/h265/h265_bitstream_parser.h +++ b/common_video/h265/h265_bitstream_parser.h @@ -15,8 +15,8 @@ #include #include +#include -#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 @@ class RTC_EXPORT H265BitstreamParser : public BitstreamParser { ~H265BitstreamParser() override; // New interface. - void ParseBitstream(ArrayView bitstream) override; + void ParseBitstream(std::span bitstream) override; std::optional GetLastSliceQp() const override; std::optional GetLastSlicePpsId() const; static std::optional ParsePpsIdFromSliceSegmentLayerRbsp( - ArrayView data, + std::span 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 IsFirstSliceSegmentInPic( - ArrayView data); + std::span data); protected: enum Result { @@ -54,8 +54,8 @@ class RTC_EXPORT H265BitstreamParser : public BitstreamParser { kInvalidStream, kUnsupportedStream, }; - void ParseSlice(ArrayView slice); - Result ParseNonParameterSetNalu(ArrayView source, + void ParseSlice(std::span slice); + Result ParseNonParameterSetNalu(std::span 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 1045a47ebd..e37b686f01 100644 --- a/common_video/h265/h265_bitstream_parser_unittest.cc +++ b/common_video/h265/h265_bitstream_parser_unittest.cc @@ -13,7 +13,6 @@ #include #include -#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 332bab7acc..528145b055 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 +#include #include -#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 @@ namespace H265 { constexpr uint8_t kNaluTypeMask = 0x7E; -std::vector FindNaluIndices(ArrayView buffer) { +std::vector FindNaluIndices(std::span buffer) { std::vector indices = H264::FindNaluIndices(buffer); std::vector results; results.reserve(indices.size()); @@ -39,11 +39,11 @@ NaluType ParseNaluType(uint8_t data) { return static_cast((data & kNaluTypeMask) >> 1); } -std::vector ParseRbsp(ArrayView data) { +std::vector ParseRbsp(std::span data) { return H264::ParseRbsp(data); } -void WriteRbsp(ArrayView bytes, Buffer* destination) { +void WriteRbsp(std::span bytes, Buffer* destination) { H264::WriteRbsp(bytes, destination); } diff --git a/common_video/h265/h265_common.h b/common_video/h265/h265_common.h index 9ce9fbee58..2cc83ea5ec 100644 --- a/common_video/h265/h265_common.h +++ b/common_video/h265/h265_common.h @@ -13,9 +13,9 @@ #include #include +#include #include -#include "api/array_view.h" #include "rtc_base/buffer.h" #include "rtc_base/system/rtc_export.h" @@ -80,12 +80,12 @@ struct NaluIndex { // Returns a vector of the NALU indices in the given buffer. RTC_EXPORT std::vector FindNaluIndices( - ArrayView buffer); + std::span buffer); // TODO: bugs.webrtc.org/42225170 - Deprecate. inline std::vector 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 @@ RTC_EXPORT NaluType ParseNaluType(uint8_t data); // the 03 emulation byte. // Parse the given data and remove any emulation byte escaping. -std::vector ParseRbsp(ArrayView data); +std::vector ParseRbsp(std::span data); // TODO: bugs.webrtc.org/42225170 - Deprecate. inline std::vector 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 bytes, Buffer* destination); +void WriteRbsp(std::span 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 a5f7adb7f9..460e936a50 100644 --- a/common_video/h265/h265_pps_parser.cc +++ b/common_video/h265/h265_pps_parser.cc @@ -12,9 +12,9 @@ #include #include +#include #include -#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 @@ constexpr int kMaxRefIdxActive = 15; // http://www.itu.int/rec/T-REC-H.265 std::optional H265PpsParser::ParsePps( - ArrayView data, + std::span 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 @@ std::optional H265PpsParser::ParsePps( return ParseInternal(H265::ParseRbsp(data), sps); } -bool H265PpsParser::ParsePpsIds(ArrayView data, +bool H265PpsParser::ParsePpsIds(std::span data, uint32_t* pps_id, uint32_t* sps_id) { RTC_DCHECK(pps_id); @@ -91,7 +91,7 @@ bool H265PpsParser::ParsePpsIds(ArrayView data, } std::optional H265PpsParser::ParseInternal( - ArrayView buffer, + std::span 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 2cb3f67dab..c73be46bce 100644 --- a/common_video/h265/h265_pps_parser.h +++ b/common_video/h265/h265_pps_parser.h @@ -14,8 +14,8 @@ #include #include #include +#include -#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 @@ class RTC_EXPORT H265PpsParser { }; // Unpack RBSP and parse PPS state from the supplied buffer. - static std::optional ParsePps(ArrayView data, + static std::optional ParsePps(std::span data, const H265SpsParser::SpsState* sps); // TODO: bugs.webrtc.org/42225170 - Deprecate. static inline std::optional 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 data, + static bool ParsePpsIds(std::span data, uint32_t* pps_id, uint32_t* sps_id); // TODO: bugs.webrtc.org/42225170 - Deprecate. @@ -64,14 +64,14 @@ class RTC_EXPORT H265PpsParser { 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 ParseInternal( - ArrayView buffer, + std::span 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 688e9e98d7..668b89ace4 100644 --- a/common_video/h265/h265_pps_parser_unittest.cc +++ b/common_video/h265/h265_pps_parser_unittest.cc @@ -14,8 +14,8 @@ #include #include #include +#include -#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 @@ void WritePps(const H265PpsParser::PpsState& pps, 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 0916de5ad3..da6f913f3c 100644 --- a/common_video/h265/h265_sps_parser.cc +++ b/common_video/h265/h265_sps_parser.cc @@ -15,9 +15,9 @@ #include #include #include +#include #include -#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 @@ size_t H265SpsParser::GetDpbMaxPicBuf(int general_profile_idc) { // Unpack RBSP and parse SPS state from the supplied buffer. std::optional H265SpsParser::ParseSps( - ArrayView data) { + std::span data) { return ParseSpsInternal(H265::ParseRbsp(data)); } @@ -388,7 +388,7 @@ H265SpsParser::ParseProfileTierLevel(bool profile_present, } std::optional H265SpsParser::ParseSpsInternal( - ArrayView buffer) { + std::span 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 1bccf6adcc..03e588d267 100644 --- a/common_video/h265/h265_sps_parser.h +++ b/common_video/h265/h265_sps_parser.h @@ -14,9 +14,9 @@ #include #include #include +#include #include -#include "api/array_view.h" #include "rtc_base/bitstream_reader.h" #include "rtc_base/system/rtc_export.h" @@ -106,11 +106,11 @@ class RTC_EXPORT H265SpsParser { }; // Unpack RBSP and parse SPS state from the supplied buffer. - static std::optional ParseSps(ArrayView data); + static std::optional ParseSps(std::span data); // TODO: bugs.webrtc.org/42225170 - Deprecate. static inline std::optional 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 @@ class RTC_EXPORT H265SpsParser { // Parse the SPS state, for a bit buffer where RBSP decoding has already been // performed. static std::optional ParseSpsInternal( - ArrayView buffer); + std::span 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 1d3e1b2859..5a8e051554 100644 --- a/common_video/h265/h265_sps_parser_unittest.cc +++ b/common_video/h265/h265_sps_parser_unittest.cc @@ -13,9 +13,9 @@ #include #include #include +#include #include -#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 @@ void WriteSps(uint16_t width, } 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 8ebe5f96a1..83821c5ad3 100644 --- a/common_video/h265/h265_vps_parser.cc +++ b/common_video/h265/h265_vps_parser.cc @@ -12,8 +12,8 @@ #include #include +#include -#include "api/array_view.h" #include "common_video/h265/h265_common.h" #include "rtc_base/bitstream_reader.h" @@ -27,12 +27,12 @@ H265VpsParser::VpsState::VpsState() = default; // Unpack RBSP and parse VPS state from the supplied buffer. std::optional H265VpsParser::ParseVps( - ArrayView data) { + std::span data) { return ParseInternal(H265::ParseRbsp(data)); } std::optional H265VpsParser::ParseInternal( - ArrayView buffer) { + std::span 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 e890e4e64f..ad423d22f7 100644 --- a/common_video/h265/h265_vps_parser.h +++ b/common_video/h265/h265_vps_parser.h @@ -14,8 +14,8 @@ #include #include #include +#include -#include "api/array_view.h" #include "rtc_base/system/rtc_export.h" namespace webrtc { @@ -32,17 +32,17 @@ class RTC_EXPORT H265VpsParser { }; // Unpack RBSP and parse VPS state from the supplied buffer. - static std::optional ParseVps(ArrayView data); + static std::optional ParseVps(std::span data); // TODO: bugs.webrtc.org/42225170 - Deprecate. static inline std::optional 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 ParseInternal(ArrayView buffer); + static std::optional ParseInternal(std::span buffer); }; } // namespace webrtc