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}
This commit is contained in:
parent
b466437c7e
commit
47601ff208
@ -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",
|
||||
|
||||
@ -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::~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 @@ H264BitstreamParser::Result H264BitstreamParser::ParseNonParameterSetNalu(
|
||||
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::ParseSlice(ArrayView<const uint8_t> slice) {
|
||||
}
|
||||
}
|
||||
|
||||
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(
|
||||
|
||||
@ -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 @@ class H264BitstreamParser : public BitstreamParser {
|
||||
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 @@ class H264BitstreamParser : public BitstreamParser {
|
||||
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.
|
||||
|
||||
@ -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 @@ namespace H264 {
|
||||
|
||||
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 @@ NaluType ParseNaluType(uint8_t data) {
|
||||
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 @@ std::vector<uint8_t> ParseRbsp(ArrayView<const uint8_t> data) {
|
||||
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;
|
||||
|
||||
@ -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 @@ struct NaluIndex {
|
||||
|
||||
// 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 @@ RTC_EXPORT NaluType ParseNaluType(uint8_t data);
|
||||
// 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
|
||||
|
||||
@ -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 @@ constexpr int kMinPicInitQpDeltaValue = -26;
|
||||
// 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 @@ bool PpsParser::ParsePpsIds(ArrayView<const uint8_t> data,
|
||||
}
|
||||
|
||||
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::SliceHeader> PpsParser::ParseSliceHeader(
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
@ -15,8 +15,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "api/array_view.h"
|
||||
#include <span>
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
@ -48,24 +47,24 @@ class PpsParser {
|
||||
};
|
||||
|
||||
// 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
|
||||
|
||||
@ -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 @@ 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<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) {
|
||||
|
||||
@ -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 @@ SpsParser::SpsState::~SpsState() = default;
|
||||
|
||||
// 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);
|
||||
|
||||
@ -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 @@ class RTC_EXPORT SpsParser {
|
||||
};
|
||||
|
||||
// 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
|
||||
|
||||
@ -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 @@ 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) {
|
||||
|
||||
@ -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 @@ void SpsVuiRewriter::UpdateStats(ParseResult result, Direction direction) {
|
||||
}
|
||||
|
||||
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(
|
||||
}
|
||||
|
||||
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 @@ SpsVuiRewriter::ParseResult SpsVuiRewriter::ParseAndRewriteSps(
|
||||
}
|
||||
|
||||
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 @@ Buffer SpsVuiRewriter::ParseOutgoingBitstreamAndRewrite(
|
||||
|
||||
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;
|
||||
|
||||
@ -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 @@ 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<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 @@ class SpsVuiRewriter : private SpsParser {
|
||||
// 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);
|
||||
|
||||
@ -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 @@ 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,
|
||||
|
||||
@ -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 @@ 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<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 @@ const H265SpsParser::SpsState* H265BitstreamParser::GetSPS(uint32_t id) const {
|
||||
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 @@ void H265BitstreamParser::ParseSlice(ArrayView<const uint8_t> slice) {
|
||||
|
||||
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 @@ H265BitstreamParser::ParsePpsIdFromSliceSegmentLayerRbsp(
|
||||
}
|
||||
|
||||
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 @@ std::optional<bool> H265BitstreamParser::IsFirstSliceSegmentInPic(
|
||||
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(
|
||||
|
||||
@ -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 @@ class RTC_EXPORT H265BitstreamParser : public BitstreamParser {
|
||||
~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 @@ class RTC_EXPORT H265BitstreamParser : public BitstreamParser {
|
||||
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;
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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 @@ namespace H265 {
|
||||
|
||||
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 @@ NaluType ParseNaluType(uint8_t data) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -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 @@ struct NaluIndex {
|
||||
|
||||
// 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 @@ RTC_EXPORT NaluType ParseNaluType(uint8_t data);
|
||||
// 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);
|
||||
|
||||
@ -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 @@ constexpr int kMaxRefIdxActive = 15;
|
||||
// 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 @@ std::optional<H265PpsParser::PpsState> H265PpsParser::ParsePps(
|
||||
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 @@ bool H265PpsParser::ParsePpsIds(ArrayView<const uint8_t> data,
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@ -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 @@ class RTC_EXPORT H265PpsParser {
|
||||
};
|
||||
|
||||
// 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 @@ 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<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,
|
||||
|
||||
@ -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 @@ 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 {
|
||||
|
||||
@ -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 @@ size_t H265SpsParser::GetDpbMaxPicBuf(int general_profile_idc) {
|
||||
|
||||
// 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 @@ H265SpsParser::ParseProfileTierLevel(bool profile_present,
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@ -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 @@ class RTC_EXPORT H265SpsParser {
|
||||
};
|
||||
|
||||
// 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 @@ class RTC_EXPORT H265SpsParser {
|
||||
// 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);
|
||||
|
||||
@ -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 @@ 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 {
|
||||
|
||||
@ -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 @@ H265VpsParser::VpsState::VpsState() = default;
|
||||
|
||||
// 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
|
||||
|
||||
@ -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 @@ class RTC_EXPORT H265VpsParser {
|
||||
};
|
||||
|
||||
// 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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user