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 "api/video/video_frame_buffer.h"
12 
13 #include "rtc_base/checks.h"
14 
15 namespace webrtc {
16 
GetI420()17 rtc::scoped_refptr<I420BufferInterface> VideoFrameBuffer::GetI420() {
18   RTC_CHECK(type() == Type::kI420);
19   return static_cast<I420BufferInterface*>(this);
20 }
21 
GetI420() const22 rtc::scoped_refptr<const I420BufferInterface> VideoFrameBuffer::GetI420()
23     const {
24   RTC_CHECK(type() == Type::kI420);
25   return static_cast<const I420BufferInterface*>(this);
26 }
27 
GetI420A()28 I420ABufferInterface* VideoFrameBuffer::GetI420A() {
29   RTC_CHECK(type() == Type::kI420A);
30   return static_cast<I420ABufferInterface*>(this);
31 }
32 
GetI420A() const33 const I420ABufferInterface* VideoFrameBuffer::GetI420A() const {
34   RTC_CHECK(type() == Type::kI420A);
35   return static_cast<const I420ABufferInterface*>(this);
36 }
37 
GetI444()38 I444BufferInterface* VideoFrameBuffer::GetI444() {
39   RTC_CHECK(type() == Type::kI444);
40   return static_cast<I444BufferInterface*>(this);
41 }
42 
GetI444() const43 const I444BufferInterface* VideoFrameBuffer::GetI444() const {
44   RTC_CHECK(type() == Type::kI444);
45   return static_cast<const I444BufferInterface*>(this);
46 }
47 
type() const48 VideoFrameBuffer::Type I420BufferInterface::type() const {
49   return Type::kI420;
50 }
51 
ChromaWidth() const52 int I420BufferInterface::ChromaWidth() const {
53   return (width() + 1) / 2;
54 }
55 
ChromaHeight() const56 int I420BufferInterface::ChromaHeight() const {
57   return (height() + 1) / 2;
58 }
59 
ToI420()60 rtc::scoped_refptr<I420BufferInterface> I420BufferInterface::ToI420() {
61   return this;
62 }
63 
type() const64 VideoFrameBuffer::Type I420ABufferInterface::type() const {
65   return Type::kI420A;
66 }
67 
type() const68 VideoFrameBuffer::Type I444BufferInterface::type() const {
69   return Type::kI444;
70 }
71 
ChromaWidth() const72 int I444BufferInterface::ChromaWidth() const {
73   return width();
74 }
75 
ChromaHeight() const76 int I444BufferInterface::ChromaHeight() const {
77   return height();
78 }
79 
80 }  // namespace webrtc
81