2017-05-11 05:11:57 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2017 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "api/video/video_frame_buffer.h"
|
2017-05-11 05:11:57 -07:00
|
|
|
|
2020-10-08 14:36:33 +00:00
|
|
|
#include "api/video/i420_buffer.h"
|
2022-03-25 09:04:09 +01:00
|
|
|
#include "api/video/i422_buffer.h"
|
2022-02-08 07:00:16 -08:00
|
|
|
#include "api/video/i444_buffer.h"
|
2021-03-22 10:22:54 +01:00
|
|
|
#include "api/video/nv12_buffer.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/checks.h"
|
2017-05-11 05:11:57 -07:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2020-10-08 14:36:33 +00:00
|
|
|
rtc::scoped_refptr<VideoFrameBuffer> VideoFrameBuffer::CropAndScale(
|
|
|
|
|
int offset_x,
|
|
|
|
|
int offset_y,
|
|
|
|
|
int crop_width,
|
|
|
|
|
int crop_height,
|
|
|
|
|
int scaled_width,
|
|
|
|
|
int scaled_height) {
|
|
|
|
|
rtc::scoped_refptr<I420Buffer> result =
|
|
|
|
|
I420Buffer::Create(scaled_width, scaled_height);
|
|
|
|
|
result->CropAndScaleFrom(*this->ToI420(), offset_x, offset_y, crop_width,
|
|
|
|
|
crop_height);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 11:39:26 +02:00
|
|
|
const I420BufferInterface* VideoFrameBuffer::GetI420() const {
|
|
|
|
|
// Overridden by subclasses that can return an I420 buffer without any
|
|
|
|
|
// conversion, in particular, I420BufferInterface.
|
|
|
|
|
return nullptr;
|
2017-11-09 12:33:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const I420ABufferInterface* VideoFrameBuffer::GetI420A() const {
|
|
|
|
|
RTC_CHECK(type() == Type::kI420A);
|
|
|
|
|
return static_cast<const I420ABufferInterface*>(this);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-01 10:02:26 -07:00
|
|
|
const I444BufferInterface* VideoFrameBuffer::GetI444() const {
|
|
|
|
|
RTC_CHECK(type() == Type::kI444);
|
|
|
|
|
return static_cast<const I444BufferInterface*>(this);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-25 09:04:09 +01:00
|
|
|
const I422BufferInterface* VideoFrameBuffer::GetI422() const {
|
|
|
|
|
RTC_CHECK(type() == Type::kI422);
|
|
|
|
|
return static_cast<const I422BufferInterface*>(this);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-26 12:22:38 -07:00
|
|
|
const I010BufferInterface* VideoFrameBuffer::GetI010() const {
|
|
|
|
|
RTC_CHECK(type() == Type::kI010);
|
|
|
|
|
return static_cast<const I010BufferInterface*>(this);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-17 11:48:14 +02:00
|
|
|
const I210BufferInterface* VideoFrameBuffer::GetI210() const {
|
|
|
|
|
RTC_CHECK(type() == Type::kI210);
|
|
|
|
|
return static_cast<const I210BufferInterface*>(this);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-09 16:14:19 +02:00
|
|
|
const NV12BufferInterface* VideoFrameBuffer::GetNV12() const {
|
|
|
|
|
RTC_CHECK(type() == Type::kNV12);
|
|
|
|
|
return static_cast<const NV12BufferInterface*>(this);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-08 14:56:45 +02:00
|
|
|
rtc::scoped_refptr<VideoFrameBuffer> VideoFrameBuffer::GetMappedFrameBuffer(
|
|
|
|
|
rtc::ArrayView<Type> types) {
|
|
|
|
|
RTC_CHECK(type() == Type::kNative);
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-30 01:21:59 -07:00
|
|
|
VideoFrameBuffer::Type I420BufferInterface::type() const {
|
|
|
|
|
return Type::kI420;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-08 14:56:45 +02:00
|
|
|
const char* VideoFrameBufferTypeToString(VideoFrameBuffer::Type type) {
|
|
|
|
|
switch (type) {
|
|
|
|
|
case VideoFrameBuffer::Type::kNative:
|
|
|
|
|
return "kNative";
|
|
|
|
|
case VideoFrameBuffer::Type::kI420:
|
|
|
|
|
return "kI420";
|
|
|
|
|
case VideoFrameBuffer::Type::kI420A:
|
|
|
|
|
return "kI420A";
|
|
|
|
|
case VideoFrameBuffer::Type::kI444:
|
|
|
|
|
return "kI444";
|
2022-03-25 09:04:09 +01:00
|
|
|
case VideoFrameBuffer::Type::kI422:
|
|
|
|
|
return "kI422";
|
2020-10-08 14:56:45 +02:00
|
|
|
case VideoFrameBuffer::Type::kI010:
|
|
|
|
|
return "kI010";
|
2022-06-17 11:48:14 +02:00
|
|
|
case VideoFrameBuffer::Type::kI210:
|
|
|
|
|
return "kI210";
|
2020-10-08 14:56:45 +02:00
|
|
|
case VideoFrameBuffer::Type::kNV12:
|
|
|
|
|
return "kNV12";
|
|
|
|
|
default:
|
2021-11-15 16:57:07 +01:00
|
|
|
RTC_DCHECK_NOTREACHED();
|
2020-10-08 14:56:45 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-30 01:21:59 -07:00
|
|
|
int I420BufferInterface::ChromaWidth() const {
|
|
|
|
|
return (width() + 1) / 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int I420BufferInterface::ChromaHeight() const {
|
|
|
|
|
return (height() + 1) / 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rtc::scoped_refptr<I420BufferInterface> I420BufferInterface::ToI420() {
|
2022-01-12 10:06:55 +01:00
|
|
|
return rtc::scoped_refptr<I420BufferInterface>(this);
|
2017-05-30 01:21:59 -07:00
|
|
|
}
|
|
|
|
|
|
2019-05-03 11:39:26 +02:00
|
|
|
const I420BufferInterface* I420BufferInterface::GetI420() const {
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-09 12:33:24 -08:00
|
|
|
VideoFrameBuffer::Type I420ABufferInterface::type() const {
|
|
|
|
|
return Type::kI420A;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-30 01:21:59 -07:00
|
|
|
VideoFrameBuffer::Type I444BufferInterface::type() const {
|
|
|
|
|
return Type::kI444;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int I444BufferInterface::ChromaWidth() const {
|
|
|
|
|
return width();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int I444BufferInterface::ChromaHeight() const {
|
|
|
|
|
return height();
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-08 07:00:16 -08:00
|
|
|
rtc::scoped_refptr<VideoFrameBuffer> I444BufferInterface::CropAndScale(
|
|
|
|
|
int offset_x,
|
|
|
|
|
int offset_y,
|
|
|
|
|
int crop_width,
|
|
|
|
|
int crop_height,
|
|
|
|
|
int scaled_width,
|
|
|
|
|
int scaled_height) {
|
|
|
|
|
rtc::scoped_refptr<I444Buffer> result =
|
|
|
|
|
I444Buffer::Create(scaled_width, scaled_height);
|
2022-03-25 09:04:09 +01:00
|
|
|
result->CropAndScaleFrom(*this, offset_x, offset_y, crop_width, crop_height);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VideoFrameBuffer::Type I422BufferInterface::type() const {
|
|
|
|
|
return Type::kI422;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int I422BufferInterface::ChromaWidth() const {
|
|
|
|
|
return (width() + 1) / 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int I422BufferInterface::ChromaHeight() const {
|
|
|
|
|
return height();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rtc::scoped_refptr<VideoFrameBuffer> I422BufferInterface::CropAndScale(
|
|
|
|
|
int offset_x,
|
|
|
|
|
int offset_y,
|
|
|
|
|
int crop_width,
|
|
|
|
|
int crop_height,
|
|
|
|
|
int scaled_width,
|
|
|
|
|
int scaled_height) {
|
|
|
|
|
rtc::scoped_refptr<I422Buffer> result =
|
|
|
|
|
I422Buffer::Create(scaled_width, scaled_height);
|
2022-02-08 07:00:16 -08:00
|
|
|
result->CropAndScaleFrom(*this, offset_x, offset_y, crop_width, crop_height);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-26 12:22:38 -07:00
|
|
|
VideoFrameBuffer::Type I010BufferInterface::type() const {
|
|
|
|
|
return Type::kI010;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int I010BufferInterface::ChromaWidth() const {
|
|
|
|
|
return (width() + 1) / 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int I010BufferInterface::ChromaHeight() const {
|
|
|
|
|
return (height() + 1) / 2;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-17 11:48:14 +02:00
|
|
|
VideoFrameBuffer::Type I210BufferInterface::type() const {
|
|
|
|
|
return Type::kI210;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int I210BufferInterface::ChromaWidth() const {
|
|
|
|
|
return (width() + 1) / 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int I210BufferInterface::ChromaHeight() const {
|
|
|
|
|
return height();
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-09 16:14:19 +02:00
|
|
|
VideoFrameBuffer::Type NV12BufferInterface::type() const {
|
|
|
|
|
return Type::kNV12;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int NV12BufferInterface::ChromaWidth() const {
|
|
|
|
|
return (width() + 1) / 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int NV12BufferInterface::ChromaHeight() const {
|
|
|
|
|
return (height() + 1) / 2;
|
|
|
|
|
}
|
2021-03-22 10:22:54 +01:00
|
|
|
|
|
|
|
|
rtc::scoped_refptr<VideoFrameBuffer> NV12BufferInterface::CropAndScale(
|
|
|
|
|
int offset_x,
|
|
|
|
|
int offset_y,
|
|
|
|
|
int crop_width,
|
|
|
|
|
int crop_height,
|
|
|
|
|
int scaled_width,
|
|
|
|
|
int scaled_height) {
|
|
|
|
|
rtc::scoped_refptr<NV12Buffer> result =
|
|
|
|
|
NV12Buffer::Create(scaled_width, scaled_height);
|
|
|
|
|
result->CropAndScaleFrom(*this, offset_x, offset_y, crop_width, crop_height);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-11 05:11:57 -07:00
|
|
|
} // namespace webrtc
|