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 14 matching lines...) Expand all Loading... |
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 uint8_t* MutableData(webrtc::PlaneType type) override { | 32 uint8_t* MutableData(webrtc::PlaneType type) override { |
33 // 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 |
34 // also has a reference to |buffer_|. | 34 // also has a reference to |buffer_|. |
35 DCHECK(HasOneRef()); | 35 RTC_DCHECK(HasOneRef()); |
36 return const_cast<uint8_t*>(buffer_->data(type)); | 36 return const_cast<uint8_t*>(buffer_->data(type)); |
37 } | 37 } |
38 int stride(webrtc::PlaneType type) const override { | 38 int stride(webrtc::PlaneType type) const override { |
39 return buffer_->stride(type); | 39 return buffer_->stride(type); |
40 } | 40 } |
41 void* native_handle() const override { return nullptr; } | 41 void* native_handle() const override { return nullptr; } |
42 | 42 |
43 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override { | 43 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override { |
44 RTC_NOTREACHED(); | 44 RTC_NOTREACHED(); |
45 return nullptr; | 45 return nullptr; |
(...skipping 11 matching lines...) Expand all Loading... |
57 Release(); | 57 Release(); |
58 } | 58 } |
59 | 59 |
60 void I420BufferPool::Release() { | 60 void I420BufferPool::Release() { |
61 thread_checker_.DetachFromThread(); | 61 thread_checker_.DetachFromThread(); |
62 buffers_.clear(); | 62 buffers_.clear(); |
63 } | 63 } |
64 | 64 |
65 rtc::scoped_refptr<VideoFrameBuffer> I420BufferPool::CreateBuffer(int width, | 65 rtc::scoped_refptr<VideoFrameBuffer> I420BufferPool::CreateBuffer(int width, |
66 int height) { | 66 int height) { |
67 DCHECK(thread_checker_.CalledOnValidThread()); | 67 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
68 // Release buffers with wrong resolution. | 68 // Release buffers with wrong resolution. |
69 for (auto it = buffers_.begin(); it != buffers_.end();) { | 69 for (auto it = buffers_.begin(); it != buffers_.end();) { |
70 if ((*it)->width() != width || (*it)->height() != height) | 70 if ((*it)->width() != width || (*it)->height() != height) |
71 it = buffers_.erase(it); | 71 it = buffers_.erase(it); |
72 else | 72 else |
73 ++it; | 73 ++it; |
74 } | 74 } |
75 // Look for a free buffer. | 75 // Look for a free buffer. |
76 for (const rtc::scoped_refptr<I420Buffer>& buffer : buffers_) { | 76 for (const rtc::scoped_refptr<I420Buffer>& buffer : buffers_) { |
77 // If the buffer is in use, the ref count will be 2, one from the list we | 77 // If the buffer is in use, the ref count will be 2, one from the list we |
78 // are looping over and one from a PooledI420Buffer returned from | 78 // are looping over and one from a PooledI420Buffer returned from |
79 // CreateBuffer that has not been released yet. If the ref count is 1 | 79 // CreateBuffer that has not been released yet. If the ref count is 1 |
80 // (HasOneRef), then the list we are looping over holds the only reference | 80 // (HasOneRef), then the list we are looping over holds the only reference |
81 // and it's safe to reuse. | 81 // and it's safe to reuse. |
82 if (buffer->HasOneRef()) | 82 if (buffer->HasOneRef()) |
83 return new rtc::RefCountedObject<PooledI420Buffer>(buffer); | 83 return new rtc::RefCountedObject<PooledI420Buffer>(buffer); |
84 } | 84 } |
85 // Allocate new buffer. | 85 // Allocate new buffer. |
86 buffers_.push_back(new rtc::RefCountedObject<I420Buffer>(width, height)); | 86 buffers_.push_back(new rtc::RefCountedObject<I420Buffer>(width, height)); |
87 return new rtc::RefCountedObject<PooledI420Buffer>(buffers_.back()); | 87 return new rtc::RefCountedObject<PooledI420Buffer>(buffers_.back()); |
88 } | 88 } |
89 | 89 |
90 } // namespace webrtc | 90 } // namespace webrtc |
OLD | NEW |