Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Unified Diff: webrtc/common_video/i420_buffer_pool.cc

Issue 2009193002: Delete IsMutable and IsExclusive methods. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Delete redundant RefCountedObject wrapping. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | webrtc/common_video/i420_buffer_pool_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/common_video/i420_buffer_pool.cc
diff --git a/webrtc/common_video/i420_buffer_pool.cc b/webrtc/common_video/i420_buffer_pool.cc
index 8896260fc0ecf4500e195757ac6b0390dee948ba..bdc0e821c6011b52b66fa832e0f26b6f5f72afd3 100644
--- a/webrtc/common_video/i420_buffer_pool.cc
+++ b/webrtc/common_video/i420_buffer_pool.cc
@@ -12,60 +12,11 @@
#include "webrtc/base/checks.h"
-namespace {
-
-// One extra indirection is needed to make |HasOneRef| work.
-class PooledI420Buffer : public webrtc::VideoFrameBuffer {
- public:
- explicit PooledI420Buffer(
- const rtc::scoped_refptr<webrtc::I420Buffer>& buffer)
- : buffer_(buffer) {}
-
- private:
- ~PooledI420Buffer() override {}
-
- int width() const override { return buffer_->width(); }
- int height() const override { return buffer_->height(); }
- const uint8_t* DataY() const override { return buffer_->DataY(); }
- const uint8_t* DataU() const override { return buffer_->DataU(); }
- const uint8_t* DataV() const override { return buffer_->DataV(); }
-
- bool IsMutable() override { return HasOneRef(); }
- // Make the IsMutable() check here instead of in |buffer_|, because the pool
- // also has a reference to |buffer_|.
- uint8_t* MutableDataY() override {
- RTC_DCHECK(IsMutable());
- return const_cast<uint8_t*>(buffer_->DataY());
- }
- uint8_t* MutableDataU() override {
- RTC_DCHECK(IsMutable());
- return const_cast<uint8_t*>(buffer_->DataU());
- }
- uint8_t* MutableDataV() override {
- RTC_DCHECK(IsMutable());
- return const_cast<uint8_t*>(buffer_->DataV());
- }
- int StrideY() const override { return buffer_->StrideY(); }
- int StrideU() const override { return buffer_->StrideU(); }
- int StrideV() const override { return buffer_->StrideV(); }
- void* native_handle() const override { return nullptr; }
-
- rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override {
- RTC_NOTREACHED();
- return nullptr;
- }
-
- friend class rtc::RefCountedObject<PooledI420Buffer>;
- rtc::scoped_refptr<webrtc::I420Buffer> buffer_;
-};
-
-} // namespace
-
namespace webrtc {
I420BufferPool::I420BufferPool(bool zero_initialize)
: zero_initialize_(zero_initialize) {
- Release();
+ thread_checker_.DetachFromThread();
}
void I420BufferPool::Release() {
@@ -73,8 +24,8 @@ void I420BufferPool::Release() {
buffers_.clear();
}
-rtc::scoped_refptr<VideoFrameBuffer> I420BufferPool::CreateBuffer(int width,
- int height) {
+rtc::scoped_refptr<I420Buffer> I420BufferPool::CreateBuffer(int width,
+ int height) {
RTC_DCHECK(thread_checker_.CalledOnValidThread());
// Release buffers with wrong resolution.
for (auto it = buffers_.begin(); it != buffers_.end();) {
@@ -84,22 +35,21 @@ rtc::scoped_refptr<VideoFrameBuffer> I420BufferPool::CreateBuffer(int width,
++it;
}
// Look for a free buffer.
- for (const rtc::scoped_refptr<I420Buffer>& buffer : buffers_) {
- // If the buffer is in use, the ref count will be 2, one from the list we
- // are looping over and one from a PooledI420Buffer returned from
- // CreateBuffer that has not been released yet. If the ref count is 1
- // (HasOneRef), then the list we are looping over holds the only reference
- // and it's safe to reuse.
- if (buffer->IsMutable())
- return new rtc::RefCountedObject<PooledI420Buffer>(buffer);
+ for (const rtc::scoped_refptr<PooledI420Buffer>& buffer : buffers_) {
+ // If the buffer is in use, the ref count will be >= 2, one from the list we
+ // are looping over and one from the application. If the ref count is 1,
+ // then the list we are looping over holds the only reference and it's safe
+ // to reuse.
+ if (buffer->HasOneRef())
+ return buffer;
}
// Allocate new buffer.
- rtc::scoped_refptr<I420Buffer> buffer = new rtc::RefCountedObject<I420Buffer>(
- width, height);
+ rtc::scoped_refptr<PooledI420Buffer> buffer =
+ new PooledI420Buffer(width, height);
if (zero_initialize_)
buffer->InitializeData();
buffers_.push_back(buffer);
- return new rtc::RefCountedObject<PooledI420Buffer>(buffers_.back());
+ return buffer;
}
} // namespace webrtc
« no previous file with comments | « no previous file | webrtc/common_video/i420_buffer_pool_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698