webrtc_m130/common_video/include/video_frame_buffer_pool.h
Ilya Nikolaevskiy 54f377308f Revert "Added support for H264 YUV444 (I444) decoding."
This reverts commit 7d8ed3437295bcad945dab69f042cf52a05c0985.

Reason for revert: Breaks internal builds

Original change's description:
> Added support for H264 YUV444 (I444) decoding.
>
> Added Nutanix Inc. to the AUTHORS file.
>
> Bug: chromium:1251096
> Change-Id: Ib47c2b1f94797afb6c5090f3c46eae6f13110992
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/234540
> Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
> Reviewed-by: Stefan Holmer <stefan@webrtc.org>
> Reviewed-by: Niels Moller <nisse@webrtc.org>
> Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
> Cr-Commit-Position: refs/heads/main@{#35200}

TBR=ilnik@webrtc.org,nisse@webrtc.org,stefan@webrtc.org,peterhanspers@webrtc.org,webrtc-scoped@luci-project-accounts.iam.gserviceaccount.com,stefan.mitic@nutanix.com

Change-Id: I3048c353a2b6b4f3d4e5e53a88f48b456f1ce593
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: chromium:1251096
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/235203
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Artem Titov <titovartem@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35207}
2021-10-14 12:59:29 +00:00

76 lines
3.1 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.
*/
#ifndef COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_POOL_H_
#define COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_POOL_H_
#include <stddef.h>
#include <list>
#include "api/scoped_refptr.h"
#include "api/video/i420_buffer.h"
#include "api/video/nv12_buffer.h"
#include "rtc_base/race_checker.h"
#include "rtc_base/ref_counted_object.h"
namespace webrtc {
// Simple buffer pool to avoid unnecessary allocations of video frame buffers.
// The pool manages the memory of the I420Buffer/NV12Buffer returned from
// Create(I420|NV12)Buffer. When the buffer is destructed, the memory is
// returned to the pool for use by subsequent calls to Create(I420|NV12)Buffer.
// If the resolution passed to Create(I420|NV12)Buffer changes or requested
// pixel format changes, old buffers will be purged from the pool.
// Note that Create(I420|NV12)Buffer will crash if more than
// kMaxNumberOfFramesBeforeCrash are created. This is to prevent memory leaks
// where frames are not returned.
class VideoFrameBufferPool {
public:
VideoFrameBufferPool();
explicit VideoFrameBufferPool(bool zero_initialize);
VideoFrameBufferPool(bool zero_initialize, size_t max_number_of_buffers);
~VideoFrameBufferPool();
// Returns a buffer from the pool. If no suitable buffer exist in the pool
// and there are less than `max_number_of_buffers` pending, a buffer is
// created. Returns null otherwise.
rtc::scoped_refptr<I420Buffer> CreateI420Buffer(int width, int height);
rtc::scoped_refptr<NV12Buffer> CreateNV12Buffer(int width, int height);
// Changes the max amount of buffers in the pool to the new value.
// Returns true if change was successful and false if the amount of already
// allocated buffers is bigger than new value.
bool Resize(size_t max_number_of_buffers);
// Clears buffers_ and detaches the thread checker so that it can be reused
// later from another thread.
void Release();
private:
rtc::scoped_refptr<VideoFrameBuffer>
GetExistingBuffer(int width, int height, VideoFrameBuffer::Type type);
rtc::RaceChecker race_checker_;
std::list<rtc::scoped_refptr<VideoFrameBuffer>> buffers_;
// If true, newly allocated buffers are zero-initialized. Note that recycled
// buffers are not zero'd before reuse. This is required of buffers used by
// FFmpeg according to http://crbug.com/390941, which only requires it for the
// initial allocation (as shown by FFmpeg's own buffer allocation code). It
// has to do with "Use-of-uninitialized-value" on "Linux_msan_chrome".
const bool zero_initialize_;
// Max number of buffers this pool can have pending.
size_t max_number_of_buffers_;
};
} // namespace webrtc
#endif // COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_POOL_H_