Chromium Code Reviews| 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 | 19 |
| 20 void I420BufferPool::Release() { | 20 void I420BufferPool::Release() { |
| 21 buffers_.clear(); | 21 buffers_.clear(); |
| 22 } | 22 } |
| 23 | 23 |
| 24 rtc::scoped_refptr<I420Buffer> I420BufferPool::CreateBuffer(int width, | 24 rtc::scoped_refptr<I420Buffer> I420BufferPool::CreateBuffer(int width, |
| 25 int height) { | 25 int height) { |
| 26 RTC_DCHECK_RUNS_SERIALIZED(&race_checker_); | 26 RTC_DCHECK_RUNS_SERIALIZED(&race_checker_); |
| 27 RTC_CHECK(buffers_.size() < kMaxNumberOfFramesBeforeCrash); | |
|
magjed_webrtc
2016/09/26 14:50:55
nit: Use RTC_CHECK_LT (even if it must crash exact
perkj_webrtc
2016/09/27 07:41:41
Done.
| |
| 27 // Release buffers with wrong resolution. | 28 // Release buffers with wrong resolution. |
| 28 for (auto it = buffers_.begin(); it != buffers_.end();) { | 29 for (auto it = buffers_.begin(); it != buffers_.end();) { |
| 29 if ((*it)->width() != width || (*it)->height() != height) | 30 if ((*it)->width() != width || (*it)->height() != height) |
| 30 it = buffers_.erase(it); | 31 it = buffers_.erase(it); |
| 31 else | 32 else |
| 32 ++it; | 33 ++it; |
| 33 } | 34 } |
| 34 // Look for a free buffer. | 35 // Look for a free buffer. |
| 35 for (const rtc::scoped_refptr<PooledI420Buffer>& buffer : buffers_) { | 36 for (const rtc::scoped_refptr<PooledI420Buffer>& buffer : buffers_) { |
| 36 // If the buffer is in use, the ref count will be >= 2, one from the list we | 37 // If the buffer is in use, the ref count will be >= 2, one from the list we |
| 37 // are looping over and one from the application. If the ref count is 1, | 38 // are looping over and one from the application. If the ref count is 1, |
| 38 // then the list we are looping over holds the only reference and it's safe | 39 // then the list we are looping over holds the only reference and it's safe |
| 39 // to reuse. | 40 // to reuse. |
| 40 if (buffer->HasOneRef()) | 41 if (buffer->HasOneRef()) |
| 41 return buffer; | 42 return buffer; |
| 42 } | 43 } |
| 43 // Allocate new buffer. | 44 // Allocate new buffer. |
| 44 rtc::scoped_refptr<PooledI420Buffer> buffer = | 45 rtc::scoped_refptr<PooledI420Buffer> buffer = |
| 45 new PooledI420Buffer(width, height); | 46 new PooledI420Buffer(width, height); |
| 46 if (zero_initialize_) | 47 if (zero_initialize_) |
| 47 buffer->InitializeData(); | 48 buffer->InitializeData(); |
| 48 buffers_.push_back(buffer); | 49 buffers_.push_back(buffer); |
| 49 return buffer; | 50 return buffer; |
| 50 } | 51 } |
| 51 | 52 |
| 52 } // namespace webrtc | 53 } // namespace webrtc |
| OLD | NEW |