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 | |
| 11 | #include "webrtc/api/video/video_frame_buffer.h" |
| 12 | |
magjed | eaf4a1e | 2017-05-30 01:21:59 -0700 | [diff] [blame] | 13 | #include "libyuv/convert.h" |
magjed | 712338e | 2017-05-11 05:11:57 -0700 | [diff] [blame] | 14 | #include "webrtc/api/video/i420_buffer.h" |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame] | 15 | #include "webrtc/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 | |
| 30 | I444BufferInterface* VideoFrameBuffer::GetI444() { |
magjed | 712338e | 2017-05-11 05:11:57 -0700 | [diff] [blame] | 31 | RTC_CHECK(type() == Type::kI444); |
magjed | eaf4a1e | 2017-05-30 01:21:59 -0700 | [diff] [blame] | 32 | return static_cast<I444BufferInterface*>(this); |
magjed | 712338e | 2017-05-11 05:11:57 -0700 | [diff] [blame] | 33 | } |
| 34 | |
magjed | 3f07549 | 2017-06-01 10:02:26 -0700 | [diff] [blame] | 35 | const I444BufferInterface* VideoFrameBuffer::GetI444() const { |
| 36 | RTC_CHECK(type() == Type::kI444); |
| 37 | return static_cast<const I444BufferInterface*>(this); |
| 38 | } |
| 39 | |
magjed | eaf4a1e | 2017-05-30 01:21:59 -0700 | [diff] [blame] | 40 | VideoFrameBuffer::Type I420BufferInterface::type() const { |
| 41 | return Type::kI420; |
magjed | 712338e | 2017-05-11 05:11:57 -0700 | [diff] [blame] | 42 | } |
| 43 | |
magjed | eaf4a1e | 2017-05-30 01:21:59 -0700 | [diff] [blame] | 44 | int I420BufferInterface::ChromaWidth() const { |
| 45 | return (width() + 1) / 2; |
magjed | 712338e | 2017-05-11 05:11:57 -0700 | [diff] [blame] | 46 | } |
| 47 | |
magjed | eaf4a1e | 2017-05-30 01:21:59 -0700 | [diff] [blame] | 48 | int I420BufferInterface::ChromaHeight() const { |
| 49 | return (height() + 1) / 2; |
| 50 | } |
| 51 | |
| 52 | rtc::scoped_refptr<I420BufferInterface> I420BufferInterface::ToI420() { |
| 53 | return this; |
| 54 | } |
| 55 | |
| 56 | VideoFrameBuffer::Type I444BufferInterface::type() const { |
| 57 | return Type::kI444; |
| 58 | } |
| 59 | |
| 60 | int I444BufferInterface::ChromaWidth() const { |
| 61 | return width(); |
| 62 | } |
| 63 | |
| 64 | int I444BufferInterface::ChromaHeight() const { |
| 65 | return height(); |
| 66 | } |
| 67 | |
| 68 | rtc::scoped_refptr<I420BufferInterface> I444BufferInterface::ToI420() { |
| 69 | rtc::scoped_refptr<I420Buffer> i420_buffer = |
| 70 | I420Buffer::Create(width(), height()); |
| 71 | libyuv::I444ToI420(DataY(), StrideY(), DataU(), StrideU(), DataV(), StrideV(), |
| 72 | i420_buffer->MutableDataY(), i420_buffer->StrideY(), |
| 73 | i420_buffer->MutableDataU(), i420_buffer->StrideU(), |
| 74 | i420_buffer->MutableDataV(), i420_buffer->StrideV(), |
| 75 | width(), height()); |
| 76 | return i420_buffer; |
magjed | 712338e | 2017-05-11 05:11:57 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | } // namespace webrtc |