webrtc_m130/api/video/nv12_buffer.cc
Ilya Nikolaevskiy 441dbf9a56 Revert "Add scaling interface to VideoFrameBuffer"
This reverts commit c79f1d8cfb48c348692320b05fa31598ed7067ca.

Reason for revert: Breaks downstream project.

Original change's description:
> Add scaling interface to VideoFrameBuffer
>
> This can be overriden for kNative frame types to perform scaling efficiently.
>
> Default implementations for existing buffer types require actual
> buffer implementation, thus this CL also merges "video_frame"
> with "video_frame_I420" build targets.
>
> Bug: webrtc:11976, chromium:1132299
> Change-Id: I3bf5f6bf179db5e7ab165b1c2301980043a08765
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/186303
> Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
> Reviewed-by: Stefan Holmer <stefan@webrtc.org>
> Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
> Reviewed-by: Niels Moller <nisse@webrtc.org>
> Reviewed-by: Evan Shrubsole <eshr@google.com>
> Cr-Commit-Position: refs/heads/master@{#32352}

TBR=mbonadei@webrtc.org,sakal@webrtc.org,ilnik@webrtc.org,nisse@webrtc.org,stefan@webrtc.org,eshr@google.com

Change-Id: I86ac697bf963ef7e2c4f2ed34c3a7bf04f4f1ce1
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:11976
Bug: chromium:1132299
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/187344
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32354}
2020-10-08 14:16:23 +00:00

126 lines
3.7 KiB
C++

/*
* Copyright (c) 2020 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 "api/video/nv12_buffer.h"
#include "api/video/i420_buffer.h"
#include "rtc_base/checks.h"
#include "rtc_base/ref_counted_object.h"
#include "third_party/libyuv/include/libyuv/convert.h"
namespace webrtc {
namespace {
static const int kBufferAlignment = 64;
int NV12DataSize(int height, int stride_y, int stride_uv) {
return stride_y * height + stride_uv * ((height + 1) / 2);
}
} // namespace
NV12Buffer::NV12Buffer(int width, int height)
: NV12Buffer(width, height, width, width + width % 2) {}
NV12Buffer::NV12Buffer(int width, int height, int stride_y, int stride_uv)
: width_(width),
height_(height),
stride_y_(stride_y),
stride_uv_(stride_uv),
data_(static_cast<uint8_t*>(
AlignedMalloc(NV12DataSize(height_, stride_y_, stride_uv),
kBufferAlignment))) {
RTC_DCHECK_GT(width, 0);
RTC_DCHECK_GT(height, 0);
RTC_DCHECK_GE(stride_y, width);
RTC_DCHECK_GE(stride_uv, (width + width % 2));
}
NV12Buffer::~NV12Buffer() = default;
// static
rtc::scoped_refptr<NV12Buffer> NV12Buffer::Create(int width, int height) {
return new rtc::RefCountedObject<NV12Buffer>(width, height);
}
// static
rtc::scoped_refptr<NV12Buffer> NV12Buffer::Create(int width,
int height,
int stride_y,
int stride_uv) {
return new rtc::RefCountedObject<NV12Buffer>(width, height, stride_y,
stride_uv);
}
// static
rtc::scoped_refptr<NV12Buffer> NV12Buffer::Copy(
const I420BufferInterface& i420_buffer) {
rtc::scoped_refptr<NV12Buffer> buffer =
NV12Buffer::Create(i420_buffer.width(), i420_buffer.height());
libyuv::I420ToNV12(
i420_buffer.DataY(), i420_buffer.StrideY(), i420_buffer.DataU(),
i420_buffer.StrideU(), i420_buffer.DataV(), i420_buffer.StrideV(),
buffer->MutableDataY(), buffer->StrideY(), buffer->MutableDataUV(),
buffer->StrideUV(), buffer->width(), buffer->height());
return buffer;
}
rtc::scoped_refptr<I420BufferInterface> NV12Buffer::ToI420() {
rtc::scoped_refptr<I420Buffer> i420_buffer =
I420Buffer::Create(width(), height());
libyuv::NV12ToI420(DataY(), StrideY(), DataUV(), StrideUV(),
i420_buffer->MutableDataY(), i420_buffer->StrideY(),
i420_buffer->MutableDataU(), i420_buffer->StrideU(),
i420_buffer->MutableDataV(), i420_buffer->StrideV(),
width(), height());
return i420_buffer;
}
int NV12Buffer::width() const {
return width_;
}
int NV12Buffer::height() const {
return height_;
}
int NV12Buffer::StrideY() const {
return stride_y_;
}
int NV12Buffer::StrideUV() const {
return stride_uv_;
}
const uint8_t* NV12Buffer::DataY() const {
return data_.get();
}
const uint8_t* NV12Buffer::DataUV() const {
return data_.get() + UVOffset();
}
uint8_t* NV12Buffer::MutableDataY() {
return data_.get();
}
uint8_t* NV12Buffer::MutableDataUV() {
return data_.get() + UVOffset();
}
size_t NV12Buffer::UVOffset() const {
return stride_y_ * height_;
}
void NV12Buffer::InitializeData() {
memset(data_.get(), 0, NV12DataSize(height_, stride_y_, stride_uv_));
}
} // namespace webrtc