| Index: webrtc/api/video/video_frame_buffer.cc
|
| diff --git a/webrtc/api/video/video_frame_buffer.cc b/webrtc/api/video/video_frame_buffer.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..0adad9a28b25e53fe3ee4ede98207633fdde9cdf
|
| --- /dev/null
|
| +++ b/webrtc/api/video/video_frame_buffer.cc
|
| @@ -0,0 +1,125 @@
|
| +/*
|
| + * 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.
|
| + */
|
| +
|
| +#include "webrtc/api/video/video_frame_buffer.h"
|
| +
|
| +#include "libyuv/convert_from.h"
|
| +#include "webrtc/api/video/i420_buffer.h"
|
| +#include "webrtc/base/checks.h"
|
| +
|
| +namespace webrtc {
|
| +
|
| +namespace {
|
| +
|
| +// Class for handling legacy implementations of NativeToI420Buffer() and
|
| +// adapting them into the new ToI420() function.
|
| +class LegacyI420Wrapper : public I420BufferInterface {
|
| + public:
|
| + explicit LegacyI420Wrapper(rtc::scoped_refptr<VideoFrameBuffer> buffer)
|
| + : buffer_(buffer) {}
|
| +
|
| + int width() const override { return buffer_->width(); }
|
| + int height() const override { return buffer_->height(); }
|
| +
|
| + const uint8_t* DataY() const override { return buffer_->DataY(); }
|
| + const uint8_t* DataU() const override { return buffer_->DataU(); }
|
| + const uint8_t* DataV() const override { return buffer_->DataV(); }
|
| +
|
| + int StrideY() const override { return buffer_->StrideY(); }
|
| + int StrideU() const override { return buffer_->StrideU(); }
|
| + int StrideV() const override { return buffer_->StrideV(); }
|
| +
|
| + private:
|
| + rtc::scoped_refptr<VideoFrameBuffer> buffer_;
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +// TODO(magjed): The default implementations in VideoFrameBuffer are provided in
|
| +// order to support the deprecated interface until external clients are updated.
|
| +// Remove once done.
|
| +VideoFrameBuffer::PixelFormat VideoFrameBuffer::Format() const {
|
| + return native_handle() ? PixelFormat::kNative : PixelFormat::kI420;
|
| +}
|
| +
|
| +const uint8_t* VideoFrameBuffer::DataY() const {
|
| + return const_cast<VideoFrameBuffer*>(this)->ToI420()->DataY();
|
| +}
|
| +
|
| +const uint8_t* VideoFrameBuffer::DataU() const {
|
| + return const_cast<VideoFrameBuffer*>(this)->ToI420()->DataU();
|
| +}
|
| +
|
| +const uint8_t* VideoFrameBuffer::DataV() const {
|
| + return const_cast<VideoFrameBuffer*>(this)->ToI420()->DataV();
|
| +}
|
| +
|
| +// Returns the number of bytes between successive rows for a given plane.
|
| +int VideoFrameBuffer::StrideY() const {
|
| + return const_cast<VideoFrameBuffer*>(this)->ToI420()->StrideY();
|
| +}
|
| +
|
| +int VideoFrameBuffer::StrideU() const {
|
| + return const_cast<VideoFrameBuffer*>(this)->ToI420()->StrideU();
|
| +}
|
| +
|
| +int VideoFrameBuffer::StrideV() const {
|
| + return const_cast<VideoFrameBuffer*>(this)->ToI420()->StrideV();
|
| +}
|
| +
|
| +void* VideoFrameBuffer::native_handle() const {
|
| + RTC_DCHECK(Format() != PixelFormat::kNative);
|
| + return nullptr;
|
| +}
|
| +
|
| +rtc::scoped_refptr<VideoFrameBuffer> VideoFrameBuffer::NativeToI420Buffer() {
|
| + return ToI420();
|
| +}
|
| +
|
| +rtc::scoped_refptr<I420BufferInterface> VideoFrameBuffer::ToI420() {
|
| + return new rtc::RefCountedObject<LegacyI420Wrapper>(NativeToI420Buffer());
|
| +}
|
| +
|
| +rtc::scoped_refptr<I444BufferInterface> VideoFrameBuffer::ToI444() {
|
| + RTC_NOTREACHED();
|
| + return nullptr;
|
| +}
|
| +
|
| +VideoFrameBuffer::PixelFormat I420BufferInterface::Format() const {
|
| + return PixelFormat::kI420;
|
| +}
|
| +
|
| +rtc::scoped_refptr<I420BufferInterface> I420BufferInterface::ToI420() {
|
| + return this;
|
| +}
|
| +
|
| +VideoFrameBuffer::PixelFormat I444BufferInterface::Format() const {
|
| + return PixelFormat::kI444;
|
| +}
|
| +
|
| +rtc::scoped_refptr<I420BufferInterface> I444BufferInterface::ToI420() {
|
| + rtc::scoped_refptr<I420Buffer> i420_buffer =
|
| + I420Buffer::Create(width(), height());
|
| + libyuv::I420ToI444(
|
| + DataY(), StrideY(),
|
| + DataU(), StrideU(),
|
| + DataV(), StrideV(),
|
| + i420_buffer->MutableDataY(), i420_buffer->StrideY(),
|
| + i420_buffer->MutableDataU(), i420_buffer->StrideU(),
|
| + i420_buffer->MutableDataV(), i420_buffer->StrideV(),
|
| + width(), height());
|
| + return i420_buffer;
|
| +}
|
| +
|
| +rtc::scoped_refptr<I444BufferInterface> I444BufferInterface::ToI444() {
|
| + return this;
|
| +}
|
| +
|
| +} // namespace webrtc
|
|
|