webrtc_m130/webrtc/common_video/i420_buffer_pool.cc
perkj 4e417b242a Reland of Switch to use SequencedTaskChecker instead of ThreadChecker where needed.
(patchset #1 id:1 of https://codereview.webrtc.org/2149553002/ )"
This reverts commit efd902cb1d9bbd81247a3e168f2080beae761d78.

Originally reviewed in https://codereview.webrtc.org/2149553002

The uptream problem should be fixed by https://codereview.webrtc.org/2145393003/

BUG=webrtc:5687
TBR=tommi@webrtc.org

Review-Url: https://codereview.webrtc.org/2152013002
Cr-Commit-Position: refs/heads/master@{#13483}
2016-07-15 06:36:00 +00:00

56 lines
1.8 KiB
C++

/*
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/common_video/include/i420_buffer_pool.h"
#include "webrtc/base/checks.h"
namespace webrtc {
I420BufferPool::I420BufferPool(bool zero_initialize)
: zero_initialize_(zero_initialize) {
sequenced_checker_.Detach();
}
void I420BufferPool::Release() {
sequenced_checker_.Detach();
buffers_.clear();
}
rtc::scoped_refptr<I420Buffer> I420BufferPool::CreateBuffer(int width,
int height) {
RTC_DCHECK(sequenced_checker_.CalledSequentially());
// Release buffers with wrong resolution.
for (auto it = buffers_.begin(); it != buffers_.end();) {
if ((*it)->width() != width || (*it)->height() != height)
it = buffers_.erase(it);
else
++it;
}
// Look for a free buffer.
for (const rtc::scoped_refptr<PooledI420Buffer>& buffer : buffers_) {
// If the buffer is in use, the ref count will be >= 2, one from the list we
// are looping over and one from the application. If the ref count is 1,
// then the list we are looping over holds the only reference and it's safe
// to reuse.
if (buffer->HasOneRef())
return buffer;
}
// Allocate new buffer.
rtc::scoped_refptr<PooledI420Buffer> buffer =
new PooledI420Buffer(width, height);
if (zero_initialize_)
buffer->InitializeData();
buffers_.push_back(buffer);
return buffer;
}
} // namespace webrtc