Delete unused FifoBuffer methods

Unused since https://webrtc-review.googlesource.com/c/src/+/186665

Bug: webrtc:11988, webrtc:6424
Change-Id: Ib09e6b862f7550d07d5adf8ce82b74698419730a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/233081
Reviewed-by: Tommi <tommi@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35097}
This commit is contained in:
Niels Möller
2021-09-27 11:51:17 +02:00
committed by WebRTC LUCI CQ
parent 1ac4f2a29e
commit acf4f55df3
3 changed files with 21 additions and 160 deletions

View File

@ -44,41 +44,6 @@ bool FifoBuffer::GetBuffered(size_t* size) const {
return true;
}
bool FifoBuffer::SetCapacity(size_t size) {
webrtc::MutexLock lock(&mutex_);
if (data_length_ > size) {
return false;
}
if (size != buffer_length_) {
char* buffer = new char[size];
const size_t copy = data_length_;
const size_t tail_copy = std::min(copy, buffer_length_ - read_position_);
memcpy(buffer, &buffer_[read_position_], tail_copy);
memcpy(buffer + tail_copy, &buffer_[0], copy - tail_copy);
buffer_.reset(buffer);
read_position_ = 0;
buffer_length_ = size;
}
return true;
}
StreamResult FifoBuffer::ReadOffset(void* buffer,
size_t bytes,
size_t offset,
size_t* bytes_read) {
webrtc::MutexLock lock(&mutex_);
return ReadOffsetLocked(buffer, bytes, offset, bytes_read);
}
StreamResult FifoBuffer::WriteOffset(const void* buffer,
size_t bytes,
size_t offset,
size_t* bytes_written) {
webrtc::MutexLock lock(&mutex_);
return WriteOffsetLocked(buffer, bytes, offset, bytes_written);
}
StreamState FifoBuffer::GetState() const {
webrtc::MutexLock lock(&mutex_);
return state_;
@ -91,7 +56,7 @@ StreamResult FifoBuffer::Read(void* buffer,
webrtc::MutexLock lock(&mutex_);
const bool was_writable = data_length_ < buffer_length_;
size_t copy = 0;
StreamResult result = ReadOffsetLocked(buffer, bytes, 0, &copy);
StreamResult result = ReadLocked(buffer, bytes, &copy);
if (result == SR_SUCCESS) {
// If read was successful then adjust the read position and number of
@ -118,7 +83,7 @@ StreamResult FifoBuffer::Write(const void* buffer,
const bool was_readable = (data_length_ > 0);
size_t copy = 0;
StreamResult result = WriteOffsetLocked(buffer, bytes, 0, &copy);
StreamResult result = WriteLocked(buffer, bytes, &copy);
if (result == SR_SUCCESS) {
// If write was successful then adjust the number of readable bytes.
@ -189,22 +154,15 @@ void FifoBuffer::ConsumeWriteBuffer(size_t size) {
}
}
bool FifoBuffer::GetWriteRemaining(size_t* size) const {
webrtc::MutexLock lock(&mutex_);
*size = buffer_length_ - data_length_;
return true;
}
StreamResult FifoBuffer::ReadOffsetLocked(void* buffer,
StreamResult FifoBuffer::ReadLocked(void* buffer,
size_t bytes,
size_t offset,
size_t* bytes_read) {
if (offset >= data_length_) {
if (data_length_ == 0) {
return (state_ != SS_CLOSED) ? SR_BLOCK : SR_EOS;
}
const size_t available = data_length_ - offset;
const size_t read_position = (read_position_ + offset) % buffer_length_;
const size_t available = data_length_;
const size_t read_position = read_position_ % buffer_length_;
const size_t copy = std::min(bytes, available);
const size_t tail_copy = std::min(copy, buffer_length_ - read_position);
char* const p = static_cast<char*>(buffer);
@ -217,21 +175,20 @@ StreamResult FifoBuffer::ReadOffsetLocked(void* buffer,
return SR_SUCCESS;
}
StreamResult FifoBuffer::WriteOffsetLocked(const void* buffer,
StreamResult FifoBuffer::WriteLocked(const void* buffer,
size_t bytes,
size_t offset,
size_t* bytes_written) {
if (state_ == SS_CLOSED) {
return SR_EOS;
}
if (data_length_ + offset >= buffer_length_) {
if (data_length_ >= buffer_length_) {
return SR_BLOCK;
}
const size_t available = buffer_length_ - data_length_ - offset;
const size_t available = buffer_length_ - data_length_;
const size_t write_position =
(read_position_ + data_length_ + offset) % buffer_length_;
(read_position_ + data_length_) % buffer_length_;
const size_t copy = std::min(bytes, available);
const size_t tail_copy = std::min(copy, buffer_length_ - write_position);
const char* const p = static_cast<const char*>(buffer);

View File

@ -31,26 +31,6 @@ class FifoBuffer final : public StreamInterface {
~FifoBuffer() override;
// Gets the amount of data currently readable from the buffer.
bool GetBuffered(size_t* data_len) const;
// Resizes the buffer to the specified capacity. Fails if data_length_ > size
bool SetCapacity(size_t length);
// Read into `buffer` with an offset from the current read position, offset
// is specified in number of bytes.
// This method doesn't adjust read position nor the number of available
// bytes, user has to call ConsumeReadData() to do this.
StreamResult ReadOffset(void* buffer,
size_t bytes,
size_t offset,
size_t* bytes_read);
// Write `buffer` with an offset from the current write position, offset is
// specified in number of bytes.
// This method doesn't adjust the number of buffered bytes, user has to call
// ConsumeWriteBuffer() to do this.
StreamResult WriteOffset(const void* buffer,
size_t bytes,
size_t offset,
size_t* bytes_written);
// StreamInterface methods
StreamState GetState() const override;
@ -95,10 +75,6 @@ class FifoBuffer final : public StreamInterface {
void* GetWriteBuffer(size_t* buf_len);
void ConsumeWriteBuffer(size_t used);
// Return the number of Write()-able bytes remaining before end-of-stream.
// Returns false if not known.
bool GetWriteRemaining(size_t* size) const;
private:
void PostEvent(int events, int err) {
owner_->PostTask(webrtc::ToQueuedTask(task_safety_, [this, events, err]() {
@ -106,19 +82,15 @@ class FifoBuffer final : public StreamInterface {
}));
}
// Helper method that implements ReadOffset. Caller must acquire a lock
// Helper method that implements Read. Caller must acquire a lock
// when calling this method.
StreamResult ReadOffsetLocked(void* buffer,
size_t bytes,
size_t offset,
size_t* bytes_read)
StreamResult ReadLocked(void* buffer, size_t bytes, size_t* bytes_read)
RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Helper method that implements WriteOffset. Caller must acquire a lock
// Helper method that implements Write. Caller must acquire a lock
// when calling this method.
StreamResult WriteOffsetLocked(const void* buffer,
StreamResult WriteLocked(const void* buffer,
size_t bytes,
size_t offset,
size_t* bytes_written)
RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
@ -129,7 +101,7 @@ class FifoBuffer final : public StreamInterface {
// the allocated buffer
std::unique_ptr<char[]> buffer_ RTC_GUARDED_BY(mutex_);
// size of the allocated buffer
size_t buffer_length_ RTC_GUARDED_BY(mutex_);
const size_t buffer_length_;
// amount of readable data in the buffer
size_t data_length_ RTC_GUARDED_BY(mutex_);
// offset to the readable data

View File

@ -202,25 +202,6 @@ TEST(FifoBufferTest, TestAll) {
// Check that the stream is now empty
EXPECT_EQ(SR_BLOCK, buf.Read(out, kSize, &bytes, nullptr));
// Try growing the buffer
EXPECT_EQ(SR_SUCCESS, buf.Write(in, kSize, &bytes, nullptr));
EXPECT_EQ(kSize, bytes);
EXPECT_TRUE(buf.SetCapacity(kSize * 2));
EXPECT_EQ(SR_SUCCESS, buf.Write(in + kSize, kSize, &bytes, nullptr));
EXPECT_EQ(kSize, bytes);
EXPECT_EQ(SR_SUCCESS, buf.Read(out, kSize * 2, &bytes, nullptr));
EXPECT_EQ(kSize * 2, bytes);
EXPECT_EQ(0, memcmp(in, out, kSize * 2));
// Try shrinking the buffer
EXPECT_EQ(SR_SUCCESS, buf.Write(in, kSize, &bytes, nullptr));
EXPECT_EQ(kSize, bytes);
EXPECT_TRUE(buf.SetCapacity(kSize));
EXPECT_EQ(SR_BLOCK, buf.Write(in, kSize, &bytes, nullptr));
EXPECT_EQ(SR_SUCCESS, buf.Read(out, kSize, &bytes, nullptr));
EXPECT_EQ(kSize, bytes);
EXPECT_EQ(0, memcmp(in, out, kSize));
// Write to the stream, close it, read the remaining bytes
EXPECT_EQ(SR_SUCCESS, buf.Write(in, kSize / 2, &bytes, nullptr));
buf.Close();
@ -240,53 +221,4 @@ TEST(FifoBufferTest, FullBufferCheck) {
EXPECT_EQ(0U, free);
}
TEST(FifoBufferTest, WriteOffsetAndReadOffset) {
const size_t kSize = 16;
const char in[kSize * 2 + 1] = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
char out[kSize * 2];
FifoBuffer buf(kSize);
// Write 14 bytes.
EXPECT_EQ(SR_SUCCESS, buf.Write(in, 14, nullptr, nullptr));
// Make sure data is in `buf`.
size_t buffered;
EXPECT_TRUE(buf.GetBuffered(&buffered));
EXPECT_EQ(14u, buffered);
// Read 10 bytes.
buf.ConsumeReadData(10);
// There should be now 12 bytes of available space.
size_t remaining;
EXPECT_TRUE(buf.GetWriteRemaining(&remaining));
EXPECT_EQ(12u, remaining);
// Write at offset 12, this should fail.
EXPECT_EQ(SR_BLOCK, buf.WriteOffset(in, 10, 12, nullptr));
// Write 8 bytes at offset 4, this wraps around the buffer.
EXPECT_EQ(SR_SUCCESS, buf.WriteOffset(in, 8, 4, nullptr));
// Number of available space remains the same until we call
// ConsumeWriteBuffer().
EXPECT_TRUE(buf.GetWriteRemaining(&remaining));
EXPECT_EQ(12u, remaining);
buf.ConsumeWriteBuffer(12);
// There's 4 bytes bypassed and 4 bytes no read so skip them and verify the
// 8 bytes written.
size_t read;
EXPECT_EQ(SR_SUCCESS, buf.ReadOffset(out, 8, 8, &read));
EXPECT_EQ(8u, read);
EXPECT_EQ(0, memcmp(out, in, 8));
// There should still be 16 bytes available for reading.
EXPECT_TRUE(buf.GetBuffered(&buffered));
EXPECT_EQ(16u, buffered);
// Read at offset 16, this should fail since we don't have that much data.
EXPECT_EQ(SR_BLOCK, buf.ReadOffset(out, 10, 16, nullptr));
}
} // namespace rtc