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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 } | 46 } |
47 | 47 |
48 friend class rtc::RefCountedObject<PooledI420Buffer>; | 48 friend class rtc::RefCountedObject<PooledI420Buffer>; |
49 rtc::scoped_refptr<webrtc::I420Buffer> buffer_; | 49 rtc::scoped_refptr<webrtc::I420Buffer> buffer_; |
50 }; | 50 }; |
51 | 51 |
52 } // namespace | 52 } // namespace |
53 | 53 |
54 namespace webrtc { | 54 namespace webrtc { |
55 | 55 |
56 I420BufferPool::I420BufferPool() { | 56 I420BufferPool::I420BufferPool(bool zero_initialize) |
| 57 : zero_initialize_(zero_initialize) { |
57 Release(); | 58 Release(); |
58 } | 59 } |
59 | 60 |
60 void I420BufferPool::Release() { | 61 void I420BufferPool::Release() { |
61 thread_checker_.DetachFromThread(); | 62 thread_checker_.DetachFromThread(); |
62 buffers_.clear(); | 63 buffers_.clear(); |
63 } | 64 } |
64 | 65 |
65 rtc::scoped_refptr<VideoFrameBuffer> I420BufferPool::CreateBuffer(int width, | 66 rtc::scoped_refptr<VideoFrameBuffer> I420BufferPool::CreateBuffer(int width, |
66 int height) { | 67 int height) { |
67 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 68 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
68 // Release buffers with wrong resolution. | 69 // Release buffers with wrong resolution. |
69 for (auto it = buffers_.begin(); it != buffers_.end();) { | 70 for (auto it = buffers_.begin(); it != buffers_.end();) { |
70 if ((*it)->width() != width || (*it)->height() != height) | 71 if ((*it)->width() != width || (*it)->height() != height) |
71 it = buffers_.erase(it); | 72 it = buffers_.erase(it); |
72 else | 73 else |
73 ++it; | 74 ++it; |
74 } | 75 } |
75 // Look for a free buffer. | 76 // Look for a free buffer. |
76 for (const rtc::scoped_refptr<I420Buffer>& buffer : buffers_) { | 77 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 | 78 // 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 | 79 // are looping over and one from a PooledI420Buffer returned from |
79 // 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 |
80 // (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 |
81 // and it's safe to reuse. | 82 // and it's safe to reuse. |
82 if (buffer->HasOneRef()) | 83 if (buffer->HasOneRef()) |
83 return new rtc::RefCountedObject<PooledI420Buffer>(buffer); | 84 return new rtc::RefCountedObject<PooledI420Buffer>(buffer); |
84 } | 85 } |
85 // Allocate new buffer. | 86 // Allocate new buffer. |
86 buffers_.push_back(new rtc::RefCountedObject<I420Buffer>(width, height)); | 87 rtc::scoped_refptr<I420Buffer> buffer = new rtc::RefCountedObject<I420Buffer>( |
| 88 width, height); |
| 89 if (zero_initialize_) |
| 90 buffer->InitializeData(); |
| 91 buffers_.push_back(buffer); |
87 return new rtc::RefCountedObject<PooledI420Buffer>(buffers_.back()); | 92 return new rtc::RefCountedObject<PooledI420Buffer>(buffers_.back()); |
88 } | 93 } |
89 | 94 |
90 } // namespace webrtc | 95 } // namespace webrtc |
OLD | NEW |