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 |
11 #include "webrtc/common_video/include/i420_buffer_pool.h" | 11 #include "webrtc/common_video/include/i420_buffer_pool.h" |
12 | 12 |
13 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
14 | 14 |
15 namespace webrtc { | 15 namespace webrtc { |
16 | 16 |
17 I420BufferPool::I420BufferPool(bool zero_initialize) | 17 I420BufferPool::I420BufferPool(bool zero_initialize) |
18 : zero_initialize_(zero_initialize) { | 18 : zero_initialize_(zero_initialize) { |
19 sequenced_checker_.Detach(); | 19 thread_checker_.DetachFromThread(); |
20 } | 20 } |
21 | 21 |
22 void I420BufferPool::Release() { | 22 void I420BufferPool::Release() { |
23 sequenced_checker_.Detach(); | 23 thread_checker_.DetachFromThread(); |
24 buffers_.clear(); | 24 buffers_.clear(); |
25 } | 25 } |
26 | 26 |
27 rtc::scoped_refptr<I420Buffer> I420BufferPool::CreateBuffer(int width, | 27 rtc::scoped_refptr<I420Buffer> I420BufferPool::CreateBuffer(int width, |
28 int height) { | 28 int height) { |
29 RTC_DCHECK(sequenced_checker_.CalledSequentially()); | 29 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
30 // Release buffers with wrong resolution. | 30 // Release buffers with wrong resolution. |
31 for (auto it = buffers_.begin(); it != buffers_.end();) { | 31 for (auto it = buffers_.begin(); it != buffers_.end();) { |
32 if ((*it)->width() != width || (*it)->height() != height) | 32 if ((*it)->width() != width || (*it)->height() != height) |
33 it = buffers_.erase(it); | 33 it = buffers_.erase(it); |
34 else | 34 else |
35 ++it; | 35 ++it; |
36 } | 36 } |
37 // Look for a free buffer. | 37 // Look for a free buffer. |
38 for (const rtc::scoped_refptr<PooledI420Buffer>& buffer : buffers_) { | 38 for (const rtc::scoped_refptr<PooledI420Buffer>& buffer : buffers_) { |
39 // If the buffer is in use, the ref count will be >= 2, one from the list we | 39 // If the buffer is in use, the ref count will be >= 2, one from the list we |
40 // are looping over and one from the application. If the ref count is 1, | 40 // are looping over and one from the application. If the ref count is 1, |
41 // then the list we are looping over holds the only reference and it's safe | 41 // then the list we are looping over holds the only reference and it's safe |
42 // to reuse. | 42 // to reuse. |
43 if (buffer->HasOneRef()) | 43 if (buffer->HasOneRef()) |
44 return buffer; | 44 return buffer; |
45 } | 45 } |
46 // Allocate new buffer. | 46 // Allocate new buffer. |
47 rtc::scoped_refptr<PooledI420Buffer> buffer = | 47 rtc::scoped_refptr<PooledI420Buffer> buffer = |
48 new PooledI420Buffer(width, height); | 48 new PooledI420Buffer(width, height); |
49 if (zero_initialize_) | 49 if (zero_initialize_) |
50 buffer->InitializeData(); | 50 buffer->InitializeData(); |
51 buffers_.push_back(buffer); | 51 buffers_.push_back(buffer); |
52 return buffer; | 52 return buffer; |
53 } | 53 } |
54 | 54 |
55 } // namespace webrtc | 55 } // namespace webrtc |
OLD | NEW |