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

Side by Side Diff: webrtc/common_video/i420_buffer_pool.cc

Issue 1881933004: Introduce an IsMutable method on VideoFrameBuffer. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase. Created 4 years, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/common_video/i420_buffer_pool_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 11 matching lines...) Expand all
22 : buffer_(buffer) {} 22 : buffer_(buffer) {}
23 23
24 private: 24 private:
25 ~PooledI420Buffer() override {} 25 ~PooledI420Buffer() override {}
26 26
27 int width() const override { return buffer_->width(); } 27 int width() const override { return buffer_->width(); }
28 int height() const override { return buffer_->height(); } 28 int height() const override { return buffer_->height(); }
29 const uint8_t* data(webrtc::PlaneType type) const override { 29 const uint8_t* data(webrtc::PlaneType type) const override {
30 return buffer_->data(type); 30 return buffer_->data(type);
31 } 31 }
32 bool IsMutable() { return HasOneRef(); }
32 uint8_t* MutableData(webrtc::PlaneType type) override { 33 uint8_t* MutableData(webrtc::PlaneType type) override {
33 // Make the HasOneRef() check here instead of in |buffer_|, because the pool 34 // Make the HasOneRef() check here instead of in |buffer_|, because the pool
34 // also has a reference to |buffer_|. 35 // also has a reference to |buffer_|.
35 RTC_DCHECK(HasOneRef()); 36 RTC_DCHECK(IsMutable());
36 return const_cast<uint8_t*>(buffer_->data(type)); 37 return const_cast<uint8_t*>(buffer_->data(type));
37 } 38 }
38 int stride(webrtc::PlaneType type) const override { 39 int stride(webrtc::PlaneType type) const override {
39 return buffer_->stride(type); 40 return buffer_->stride(type);
40 } 41 }
41 void* native_handle() const override { return nullptr; } 42 void* native_handle() const override { return nullptr; }
42 43
43 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override { 44 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override {
44 RTC_NOTREACHED(); 45 RTC_NOTREACHED();
45 return nullptr; 46 return nullptr;
(...skipping 27 matching lines...) Expand all
73 else 74 else
74 ++it; 75 ++it;
75 } 76 }
76 // Look for a free buffer. 77 // Look for a free buffer.
77 for (const rtc::scoped_refptr<I420Buffer>& buffer : buffers_) { 78 for (const rtc::scoped_refptr<I420Buffer>& buffer : buffers_) {
78 // If the buffer is in use, the ref count will be 2, one from the list we 79 // If the buffer is in use, the ref count will be 2, one from the list we
79 // are looping over and one from a PooledI420Buffer returned from 80 // are looping over and one from a PooledI420Buffer returned from
80 // CreateBuffer that has not been released yet. If the ref count is 1 81 // CreateBuffer that has not been released yet. If the ref count is 1
81 // (HasOneRef), then the list we are looping over holds the only reference 82 // (HasOneRef), then the list we are looping over holds the only reference
82 // and it's safe to reuse. 83 // and it's safe to reuse.
83 if (buffer->HasOneRef()) 84 if (buffer->IsMutable())
84 return new rtc::RefCountedObject<PooledI420Buffer>(buffer); 85 return new rtc::RefCountedObject<PooledI420Buffer>(buffer);
85 } 86 }
86 // Allocate new buffer. 87 // Allocate new buffer.
87 rtc::scoped_refptr<I420Buffer> buffer = new rtc::RefCountedObject<I420Buffer>( 88 rtc::scoped_refptr<I420Buffer> buffer = new rtc::RefCountedObject<I420Buffer>(
88 width, height); 89 width, height);
89 if (zero_initialize_) 90 if (zero_initialize_)
90 buffer->InitializeData(); 91 buffer->InitializeData();
91 buffers_.push_back(buffer); 92 buffers_.push_back(buffer);
92 return new rtc::RefCountedObject<PooledI420Buffer>(buffers_.back()); 93 return new rtc::RefCountedObject<PooledI420Buffer>(buffers_.back());
93 } 94 }
94 95
95 } // namespace webrtc 96 } // namespace webrtc
OLDNEW
« 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