blob: b231745e11dd2c8c75f083a8e1585a3db779d41b [file] [log] [blame]
magjed712338e2017-05-11 05:11:57 -07001/*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "api/video/video_frame_buffer.h"
magjed712338e2017-05-11 05:11:57 -070012
magjedeaf4a1e2017-05-30 01:21:59 -070013#include "libyuv/convert.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "api/video/i420_buffer.h"
15#include "rtc_base/checks.h"
magjed712338e2017-05-11 05:11:57 -070016
17namespace webrtc {
18
magjedeaf4a1e2017-05-30 01:21:59 -070019rtc::scoped_refptr<I420BufferInterface> VideoFrameBuffer::GetI420() {
magjed712338e2017-05-11 05:11:57 -070020 RTC_CHECK(type() == Type::kI420);
Magnus Jedvert224e6592017-06-30 12:14:42 +000021 return static_cast<I420BufferInterface*>(this);
magjed712338e2017-05-11 05:11:57 -070022}
23
magjed3f075492017-06-01 10:02:26 -070024rtc::scoped_refptr<const I420BufferInterface> VideoFrameBuffer::GetI420()
25 const {
26 RTC_CHECK(type() == Type::kI420);
Magnus Jedvert224e6592017-06-30 12:14:42 +000027 return static_cast<const I420BufferInterface*>(this);
magjed3f075492017-06-01 10:02:26 -070028}
29
Emircan Uysaler574eaa42017-11-09 12:33:24 -080030I420ABufferInterface* VideoFrameBuffer::GetI420A() {
31 RTC_CHECK(type() == Type::kI420A);
32 return static_cast<I420ABufferInterface*>(this);
33}
34
35const I420ABufferInterface* VideoFrameBuffer::GetI420A() const {
36 RTC_CHECK(type() == Type::kI420A);
37 return static_cast<const I420ABufferInterface*>(this);
38}
39
magjed3f075492017-06-01 10:02:26 -070040I444BufferInterface* VideoFrameBuffer::GetI444() {
magjed712338e2017-05-11 05:11:57 -070041 RTC_CHECK(type() == Type::kI444);
magjedeaf4a1e2017-05-30 01:21:59 -070042 return static_cast<I444BufferInterface*>(this);
magjed712338e2017-05-11 05:11:57 -070043}
44
magjed3f075492017-06-01 10:02:26 -070045const I444BufferInterface* VideoFrameBuffer::GetI444() const {
46 RTC_CHECK(type() == Type::kI444);
47 return static_cast<const I444BufferInterface*>(this);
48}
49
magjedeaf4a1e2017-05-30 01:21:59 -070050VideoFrameBuffer::Type I420BufferInterface::type() const {
51 return Type::kI420;
magjed712338e2017-05-11 05:11:57 -070052}
53
magjedeaf4a1e2017-05-30 01:21:59 -070054int I420BufferInterface::ChromaWidth() const {
55 return (width() + 1) / 2;
magjed712338e2017-05-11 05:11:57 -070056}
57
magjedeaf4a1e2017-05-30 01:21:59 -070058int I420BufferInterface::ChromaHeight() const {
59 return (height() + 1) / 2;
60}
61
62rtc::scoped_refptr<I420BufferInterface> I420BufferInterface::ToI420() {
63 return this;
64}
65
Emircan Uysaler574eaa42017-11-09 12:33:24 -080066VideoFrameBuffer::Type I420ABufferInterface::type() const {
67 return Type::kI420A;
68}
69
magjedeaf4a1e2017-05-30 01:21:59 -070070VideoFrameBuffer::Type I444BufferInterface::type() const {
71 return Type::kI444;
72}
73
74int I444BufferInterface::ChromaWidth() const {
75 return width();
76}
77
78int I444BufferInterface::ChromaHeight() const {
79 return height();
80}
81
82rtc::scoped_refptr<I420BufferInterface> I444BufferInterface::ToI420() {
83 rtc::scoped_refptr<I420Buffer> i420_buffer =
84 I420Buffer::Create(width(), height());
85 libyuv::I444ToI420(DataY(), StrideY(), DataU(), StrideU(), DataV(), StrideV(),
86 i420_buffer->MutableDataY(), i420_buffer->StrideY(),
87 i420_buffer->MutableDataU(), i420_buffer->StrideU(),
88 i420_buffer->MutableDataV(), i420_buffer->StrideV(),
89 width(), height());
90 return i420_buffer;
magjed712338e2017-05-11 05:11:57 -070091}
92
93} // namespace webrtc