magjed | 712338e | 2017-05-11 05:11:57 -0700 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "api/video/video_frame_buffer.h" |
magjed | 712338e | 2017-05-11 05:11:57 -0700 | [diff] [blame] | 12 | |
magjed | eaf4a1e | 2017-05-30 01:21:59 -0700 | [diff] [blame] | 13 | #include "libyuv/convert.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "api/video/i420_buffer.h" |
| 15 | #include "rtc_base/checks.h" |
magjed | 712338e | 2017-05-11 05:11:57 -0700 | [diff] [blame] | 16 | |
| 17 | namespace webrtc { |
| 18 | |
magjed | eaf4a1e | 2017-05-30 01:21:59 -0700 | [diff] [blame] | 19 | rtc::scoped_refptr<I420BufferInterface> VideoFrameBuffer::GetI420() { |
magjed | 712338e | 2017-05-11 05:11:57 -0700 | [diff] [blame] | 20 | RTC_CHECK(type() == Type::kI420); |
Magnus Jedvert | 224e659 | 2017-06-30 12:14:42 +0000 | [diff] [blame] | 21 | return static_cast<I420BufferInterface*>(this); |
magjed | 712338e | 2017-05-11 05:11:57 -0700 | [diff] [blame] | 22 | } |
| 23 | |
magjed | 3f07549 | 2017-06-01 10:02:26 -0700 | [diff] [blame] | 24 | rtc::scoped_refptr<const I420BufferInterface> VideoFrameBuffer::GetI420() |
| 25 | const { |
| 26 | RTC_CHECK(type() == Type::kI420); |
Magnus Jedvert | 224e659 | 2017-06-30 12:14:42 +0000 | [diff] [blame] | 27 | return static_cast<const I420BufferInterface*>(this); |
magjed | 3f07549 | 2017-06-01 10:02:26 -0700 | [diff] [blame] | 28 | } |
| 29 | |
Emircan Uysaler | 574eaa4 | 2017-11-09 12:33:24 -0800 | [diff] [blame^] | 30 | I420ABufferInterface* VideoFrameBuffer::GetI420A() { |
| 31 | RTC_CHECK(type() == Type::kI420A); |
| 32 | return static_cast<I420ABufferInterface*>(this); |
| 33 | } |
| 34 | |
| 35 | const I420ABufferInterface* VideoFrameBuffer::GetI420A() const { |
| 36 | RTC_CHECK(type() == Type::kI420A); |
| 37 | return static_cast<const I420ABufferInterface*>(this); |
| 38 | } |
| 39 | |
magjed | 3f07549 | 2017-06-01 10:02:26 -0700 | [diff] [blame] | 40 | I444BufferInterface* VideoFrameBuffer::GetI444() { |
magjed | 712338e | 2017-05-11 05:11:57 -0700 | [diff] [blame] | 41 | RTC_CHECK(type() == Type::kI444); |
magjed | eaf4a1e | 2017-05-30 01:21:59 -0700 | [diff] [blame] | 42 | return static_cast<I444BufferInterface*>(this); |
magjed | 712338e | 2017-05-11 05:11:57 -0700 | [diff] [blame] | 43 | } |
| 44 | |
magjed | 3f07549 | 2017-06-01 10:02:26 -0700 | [diff] [blame] | 45 | const I444BufferInterface* VideoFrameBuffer::GetI444() const { |
| 46 | RTC_CHECK(type() == Type::kI444); |
| 47 | return static_cast<const I444BufferInterface*>(this); |
| 48 | } |
| 49 | |
magjed | eaf4a1e | 2017-05-30 01:21:59 -0700 | [diff] [blame] | 50 | VideoFrameBuffer::Type I420BufferInterface::type() const { |
| 51 | return Type::kI420; |
magjed | 712338e | 2017-05-11 05:11:57 -0700 | [diff] [blame] | 52 | } |
| 53 | |
magjed | eaf4a1e | 2017-05-30 01:21:59 -0700 | [diff] [blame] | 54 | int I420BufferInterface::ChromaWidth() const { |
| 55 | return (width() + 1) / 2; |
magjed | 712338e | 2017-05-11 05:11:57 -0700 | [diff] [blame] | 56 | } |
| 57 | |
magjed | eaf4a1e | 2017-05-30 01:21:59 -0700 | [diff] [blame] | 58 | int I420BufferInterface::ChromaHeight() const { |
| 59 | return (height() + 1) / 2; |
| 60 | } |
| 61 | |
| 62 | rtc::scoped_refptr<I420BufferInterface> I420BufferInterface::ToI420() { |
| 63 | return this; |
| 64 | } |
| 65 | |
Emircan Uysaler | 574eaa4 | 2017-11-09 12:33:24 -0800 | [diff] [blame^] | 66 | VideoFrameBuffer::Type I420ABufferInterface::type() const { |
| 67 | return Type::kI420A; |
| 68 | } |
| 69 | |
magjed | eaf4a1e | 2017-05-30 01:21:59 -0700 | [diff] [blame] | 70 | VideoFrameBuffer::Type I444BufferInterface::type() const { |
| 71 | return Type::kI444; |
| 72 | } |
| 73 | |
| 74 | int I444BufferInterface::ChromaWidth() const { |
| 75 | return width(); |
| 76 | } |
| 77 | |
| 78 | int I444BufferInterface::ChromaHeight() const { |
| 79 | return height(); |
| 80 | } |
| 81 | |
| 82 | rtc::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; |
magjed | 712338e | 2017-05-11 05:11:57 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | } // namespace webrtc |