OLD | NEW |
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 Loading... |
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(); } | |
33 uint8_t* MutableData(webrtc::PlaneType type) override { | 32 uint8_t* MutableData(webrtc::PlaneType type) override { |
34 // Make the HasOneRef() check here instead of in |buffer_|, because the pool | 33 // Make the HasOneRef() check here instead of in |buffer_|, because the pool |
35 // also has a reference to |buffer_|. | 34 // also has a reference to |buffer_|. |
36 RTC_DCHECK(IsMutable()); | 35 RTC_DCHECK(HasOneRef()); |
37 return const_cast<uint8_t*>(buffer_->data(type)); | 36 return const_cast<uint8_t*>(buffer_->data(type)); |
38 } | 37 } |
39 int stride(webrtc::PlaneType type) const override { | 38 int stride(webrtc::PlaneType type) const override { |
40 return buffer_->stride(type); | 39 return buffer_->stride(type); |
41 } | 40 } |
42 void* native_handle() const override { return nullptr; } | 41 void* native_handle() const override { return nullptr; } |
43 | 42 |
44 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override { | 43 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override { |
45 RTC_NOTREACHED(); | 44 RTC_NOTREACHED(); |
46 return nullptr; | 45 return nullptr; |
(...skipping 27 matching lines...) Expand all Loading... |
74 else | 73 else |
75 ++it; | 74 ++it; |
76 } | 75 } |
77 // Look for a free buffer. | 76 // Look for a free buffer. |
78 for (const rtc::scoped_refptr<I420Buffer>& buffer : buffers_) { | 77 for (const rtc::scoped_refptr<I420Buffer>& buffer : buffers_) { |
79 // If the buffer is in use, the ref count will be 2, one from the list we | 78 // If the buffer is in use, the ref count will be 2, one from the list we |
80 // are looping over and one from a PooledI420Buffer returned from | 79 // are looping over and one from a PooledI420Buffer returned from |
81 // CreateBuffer that has not been released yet. If the ref count is 1 | 80 // CreateBuffer that has not been released yet. If the ref count is 1 |
82 // (HasOneRef), then the list we are looping over holds the only reference | 81 // (HasOneRef), then the list we are looping over holds the only reference |
83 // and it's safe to reuse. | 82 // and it's safe to reuse. |
84 if (buffer->IsMutable()) | 83 if (buffer->HasOneRef()) |
85 return new rtc::RefCountedObject<PooledI420Buffer>(buffer); | 84 return new rtc::RefCountedObject<PooledI420Buffer>(buffer); |
86 } | 85 } |
87 // Allocate new buffer. | 86 // Allocate new buffer. |
88 rtc::scoped_refptr<I420Buffer> buffer = new rtc::RefCountedObject<I420Buffer>( | 87 rtc::scoped_refptr<I420Buffer> buffer = new rtc::RefCountedObject<I420Buffer>( |
89 width, height); | 88 width, height); |
90 if (zero_initialize_) | 89 if (zero_initialize_) |
91 buffer->InitializeData(); | 90 buffer->InitializeData(); |
92 buffers_.push_back(buffer); | 91 buffers_.push_back(buffer); |
93 return new rtc::RefCountedObject<PooledI420Buffer>(buffers_.back()); | 92 return new rtc::RefCountedObject<PooledI420Buffer>(buffers_.back()); |
94 } | 93 } |
95 | 94 |
96 } // namespace webrtc | 95 } // namespace webrtc |
OLD | NEW |