Revert "rtc::Buffer: Remove backwards compatibility band-aids"
This reverts commit 9e1a6d7c23
, because
Chromium for Android still isn't happy with it.
TBR=tommi@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/49869004
Cr-Commit-Position: refs/heads/master@{#9122}
This commit is contained in:
parent
9e1a6d7c23
commit
cbf0927473
@ -512,7 +512,7 @@ bool BaseChannel::SendPacket(bool rtcp, rtc::Buffer* packet,
|
||||
// Protect if needed.
|
||||
if (srtp_filter_.IsActive()) {
|
||||
bool res;
|
||||
uint8_t* data = packet->data();
|
||||
uint8_t* data = packet->data<uint8_t>();
|
||||
int len = static_cast<int>(packet->size());
|
||||
if (!rtcp) {
|
||||
// If ENABLE_EXTERNAL_AUTH flag is on then packet authentication is not done
|
||||
|
@ -40,6 +40,20 @@ struct ByteType {
|
||||
using t = decltype(F(static_cast<T*>(nullptr)));
|
||||
};
|
||||
|
||||
// Deprecated: Accept void* in addition to the byte-sized types.
|
||||
// TODO(kwiberg): Remove once Chromium doesn't need this anymore.
|
||||
template <typename T>
|
||||
struct ByteTypeOrVoid {
|
||||
private:
|
||||
static int F(uint8_t*);
|
||||
static int F(int8_t*);
|
||||
static int F(char*);
|
||||
static int F(void*);
|
||||
|
||||
public:
|
||||
using t = decltype(F(static_cast<T*>(nullptr)));
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// Basic buffer class, can be grown and shrunk dynamically.
|
||||
@ -56,10 +70,10 @@ class Buffer final {
|
||||
|
||||
// Construct a buffer and copy the specified number of bytes into it. The
|
||||
// source array may be (const) uint8_t*, int8_t*, or char*.
|
||||
template <typename T, typename internal::ByteType<T>::t = 0>
|
||||
template <typename T, typename internal::ByteTypeOrVoid<T>::t = 0>
|
||||
Buffer(const T* data, size_t size)
|
||||
: Buffer(data, size, size) {}
|
||||
template <typename T, typename internal::ByteType<T>::t = 0>
|
||||
template <typename T, typename internal::ByteTypeOrVoid<T>::t = 0>
|
||||
Buffer(const T* data, size_t size, size_t capacity)
|
||||
: Buffer(size, capacity) {
|
||||
std::memcpy(data_.get(), data, size);
|
||||
@ -72,14 +86,15 @@ class Buffer final {
|
||||
|
||||
~Buffer();
|
||||
|
||||
// Get a pointer to the data. Just .data() will give you a (const) uint8_t*,
|
||||
// but you may also use .data<int8_t>() and .data<char>().
|
||||
template <typename T = uint8_t, typename internal::ByteType<T>::t = 0>
|
||||
// Get a pointer to the data. Just .data() will give you a (const) char*,
|
||||
// but you may also use .data<int8_t>() and .data<uint8_t>().
|
||||
// TODO(kwiberg): Change default to uint8_t
|
||||
template <typename T = char, typename internal::ByteType<T>::t = 0>
|
||||
const T* data() const {
|
||||
assert(IsConsistent());
|
||||
return reinterpret_cast<T*>(data_.get());
|
||||
}
|
||||
template <typename T = uint8_t, typename internal::ByteType<T>::t = 0>
|
||||
template <typename T = char, typename internal::ByteType<T>::t = 0>
|
||||
T* data() {
|
||||
assert(IsConsistent());
|
||||
return reinterpret_cast<T*>(data_.get());
|
||||
@ -118,7 +133,7 @@ class Buffer final {
|
||||
|
||||
// Replace the contents of the buffer. Accepts the same types as the
|
||||
// constructors.
|
||||
template <typename T, typename internal::ByteType<T>::t = 0>
|
||||
template <typename T, typename internal::ByteTypeOrVoid<T>::t = 0>
|
||||
void SetData(const T* data, size_t size) {
|
||||
assert(IsConsistent());
|
||||
size_ = 0;
|
||||
@ -131,7 +146,7 @@ class Buffer final {
|
||||
void SetData(const Buffer& buf) { SetData(buf.data(), buf.size()); }
|
||||
|
||||
// Append data to the buffer. Accepts the same types as the constructors.
|
||||
template <typename T, typename internal::ByteType<T>::t = 0>
|
||||
template <typename T, typename internal::ByteTypeOrVoid<T>::t = 0>
|
||||
void AppendData(const T* data, size_t size) {
|
||||
assert(IsConsistent());
|
||||
const size_t new_size = size_ + size;
|
||||
|
@ -137,11 +137,11 @@ TEST(BufferTest, TestEnsureCapacityLarger) {
|
||||
|
||||
TEST(BufferTest, TestMoveConstruct) {
|
||||
Buffer buf1(kTestData, 3, 40);
|
||||
const uint8_t* data = buf1.data();
|
||||
const uint8_t* data = buf1.data<uint8_t>();
|
||||
Buffer buf2(buf1.Pass());
|
||||
EXPECT_EQ(buf2.size(), 3u);
|
||||
EXPECT_EQ(buf2.capacity(), 40u);
|
||||
EXPECT_EQ(buf2.data(), data);
|
||||
EXPECT_EQ(buf2.data<uint8_t>(), data);
|
||||
buf1.Clear();
|
||||
EXPECT_EQ(buf1.size(), 0u);
|
||||
EXPECT_EQ(buf1.capacity(), 0u);
|
||||
@ -150,12 +150,12 @@ TEST(BufferTest, TestMoveConstruct) {
|
||||
|
||||
TEST(BufferTest, TestMoveAssign) {
|
||||
Buffer buf1(kTestData, 3, 40);
|
||||
const uint8_t* data = buf1.data();
|
||||
const uint8_t* data = buf1.data<uint8_t>();
|
||||
Buffer buf2(kTestData);
|
||||
buf2 = buf1.Pass();
|
||||
EXPECT_EQ(buf2.size(), 3u);
|
||||
EXPECT_EQ(buf2.capacity(), 40u);
|
||||
EXPECT_EQ(buf2.data(), data);
|
||||
EXPECT_EQ(buf2.data<uint8_t>(), data);
|
||||
buf1.Clear();
|
||||
EXPECT_EQ(buf1.size(), 0u);
|
||||
EXPECT_EQ(buf1.capacity(), 0u);
|
||||
@ -165,16 +165,16 @@ TEST(BufferTest, TestMoveAssign) {
|
||||
TEST(BufferTest, TestSwap) {
|
||||
Buffer buf1(kTestData, 3);
|
||||
Buffer buf2(kTestData, 6, 40);
|
||||
uint8_t* data1 = buf1.data();
|
||||
uint8_t* data2 = buf2.data();
|
||||
uint8_t* data1 = buf1.data<uint8_t>();
|
||||
uint8_t* data2 = buf2.data<uint8_t>();
|
||||
using std::swap;
|
||||
swap(buf1, buf2);
|
||||
EXPECT_EQ(buf1.size(), 6u);
|
||||
EXPECT_EQ(buf1.capacity(), 40u);
|
||||
EXPECT_EQ(buf1.data(), data2);
|
||||
EXPECT_EQ(buf1.data<uint8_t>(), data2);
|
||||
EXPECT_EQ(buf2.size(), 3u);
|
||||
EXPECT_EQ(buf2.capacity(), 3u);
|
||||
EXPECT_EQ(buf2.data(), data1);
|
||||
EXPECT_EQ(buf2.data<uint8_t>(), data1);
|
||||
}
|
||||
|
||||
} // namespace rtc
|
||||
|
@ -82,7 +82,7 @@ class LoopbackTransportTest : public webrtc::Transport {
|
||||
packets_sent_++;
|
||||
rtc::Buffer* buffer =
|
||||
new rtc::Buffer(reinterpret_cast<const uint8_t*>(data), len);
|
||||
last_sent_packet_ = buffer->data();
|
||||
last_sent_packet_ = buffer->data<uint8_t>();
|
||||
last_sent_packet_len_ = len;
|
||||
total_bytes_sent_ += len;
|
||||
sent_packets_.push_back(buffer);
|
||||
|
Loading…
Reference in New Issue
Block a user