OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/api/video/video_frame_buffer.h" | 11 #include "webrtc/api/video/video_frame_buffer.h" |
12 | 12 |
13 #include "libyuv/convert.h" | 13 #include "libyuv/convert.h" |
14 #include "webrtc/api/video/i420_buffer.h" | 14 #include "webrtc/api/video/i420_buffer.h" |
15 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
16 | 16 |
17 namespace webrtc { | 17 namespace webrtc { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 // TODO(magjed): Remove this class. It is only used for providing a default | 21 // TODO(magjed): Remove this class. It is only used for providing a default |
22 // implementation of ToI420() until external clients are updated. ToI420() will | 22 // implementation of ToI420() until external clients are updated. ToI420() will |
23 // then be made pure virtual. This adapter adapts a VideoFrameBuffer (which is | 23 // then be made pure virtual. This adapter adapts a VideoFrameBuffer (which is |
24 // expected to be in I420 format) to I420BufferInterface. The reason this is | 24 // expected to be in I420 format) to I420BufferInterface. The reason this is |
25 // needed is because of the return type mismatch in NativeToI420Buffer (returns | 25 // needed is because of the return type mismatch in NativeToI420Buffer (returns |
26 // VideoFrameBuffer) vs ToI420 (returns I420BufferInterface). | 26 // VideoFrameBuffer) vs ToI420 (returns I420BufferInterface). |
27 class I420InterfaceAdapter : public I420BufferInterface { | 27 class I420InterfaceAdapter : public I420BufferInterface { |
28 public: | 28 public: |
29 explicit I420InterfaceAdapter(rtc::scoped_refptr<VideoFrameBuffer> buffer) | 29 explicit I420InterfaceAdapter(const VideoFrameBuffer* buffer) |
30 : buffer_(buffer) {} | 30 : buffer_(buffer) {} |
31 | 31 |
32 int width() const override { return buffer_->width(); } | 32 int width() const override { return buffer_->width(); } |
33 int height() const override { return buffer_->height(); } | 33 int height() const override { return buffer_->height(); } |
34 | 34 |
35 const uint8_t* DataY() const override { return buffer_->DataY(); } | 35 const uint8_t* DataY() const override { return buffer_->DataY(); } |
36 const uint8_t* DataU() const override { return buffer_->DataU(); } | 36 const uint8_t* DataU() const override { return buffer_->DataU(); } |
37 const uint8_t* DataV() const override { return buffer_->DataV(); } | 37 const uint8_t* DataV() const override { return buffer_->DataV(); } |
38 | 38 |
39 int StrideY() const override { return buffer_->StrideY(); } | 39 int StrideY() const override { return buffer_->StrideY(); } |
40 int StrideU() const override { return buffer_->StrideU(); } | 40 int StrideU() const override { return buffer_->StrideU(); } |
41 int StrideV() const override { return buffer_->StrideV(); } | 41 int StrideV() const override { return buffer_->StrideV(); } |
42 | 42 |
43 private: | 43 private: |
44 rtc::scoped_refptr<VideoFrameBuffer> buffer_; | 44 rtc::scoped_refptr<const VideoFrameBuffer> buffer_; |
45 }; | 45 }; |
46 | 46 |
47 } // namespace | 47 } // namespace |
48 | 48 |
49 // TODO(magjed): The default implementations in VideoFrameBuffer are provided in | 49 // TODO(magjed): The default implementations in VideoFrameBuffer are provided in |
50 // order to support the deprecated interface until external clients are updated. | 50 // order to support the deprecated interface until external clients are updated. |
51 // Remove once done. | 51 // Remove once done. |
52 VideoFrameBuffer::Type VideoFrameBuffer::type() const { | 52 VideoFrameBuffer::Type VideoFrameBuffer::type() const { |
53 return native_handle() ? Type::kNative : Type::kI420; | 53 return native_handle() ? Type::kNative : Type::kI420; |
54 } | 54 } |
55 | 55 |
56 const uint8_t* VideoFrameBuffer::DataY() const { | 56 const uint8_t* VideoFrameBuffer::DataY() const { |
57 return const_cast<VideoFrameBuffer*>(this)->GetI420()->DataY(); | 57 return GetI420()->DataY(); |
58 } | 58 } |
59 | 59 |
60 const uint8_t* VideoFrameBuffer::DataU() const { | 60 const uint8_t* VideoFrameBuffer::DataU() const { |
61 return const_cast<VideoFrameBuffer*>(this)->GetI420()->DataU(); | 61 return GetI420()->DataU(); |
62 } | 62 } |
63 | 63 |
64 const uint8_t* VideoFrameBuffer::DataV() const { | 64 const uint8_t* VideoFrameBuffer::DataV() const { |
65 return const_cast<VideoFrameBuffer*>(this)->GetI420()->DataV(); | 65 return GetI420()->DataV(); |
66 } | 66 } |
67 | 67 |
68 // Returns the number of bytes between successive rows for a given plane. | 68 // Returns the number of bytes between successive rows for a given plane. |
69 int VideoFrameBuffer::StrideY() const { | 69 int VideoFrameBuffer::StrideY() const { |
70 return const_cast<VideoFrameBuffer*>(this)->GetI420()->StrideY(); | 70 return GetI420()->StrideY(); |
71 } | 71 } |
72 | 72 |
73 int VideoFrameBuffer::StrideU() const { | 73 int VideoFrameBuffer::StrideU() const { |
74 return const_cast<VideoFrameBuffer*>(this)->GetI420()->StrideU(); | 74 return GetI420()->StrideU(); |
75 } | 75 } |
76 | 76 |
77 int VideoFrameBuffer::StrideV() const { | 77 int VideoFrameBuffer::StrideV() const { |
78 return const_cast<VideoFrameBuffer*>(this)->GetI420()->StrideV(); | 78 return GetI420()->StrideV(); |
79 } | 79 } |
80 | 80 |
81 void* VideoFrameBuffer::native_handle() const { | 81 void* VideoFrameBuffer::native_handle() const { |
82 RTC_DCHECK(type() != Type::kNative); | 82 RTC_DCHECK(type() != Type::kNative); |
83 return nullptr; | 83 return nullptr; |
84 } | 84 } |
85 | 85 |
86 rtc::scoped_refptr<VideoFrameBuffer> VideoFrameBuffer::NativeToI420Buffer() { | 86 rtc::scoped_refptr<VideoFrameBuffer> VideoFrameBuffer::NativeToI420Buffer() { |
87 return ToI420(); | 87 return ToI420(); |
88 } | 88 } |
89 | 89 |
90 rtc::scoped_refptr<I420BufferInterface> VideoFrameBuffer::ToI420() { | 90 rtc::scoped_refptr<I420BufferInterface> VideoFrameBuffer::ToI420() { |
91 return new rtc::RefCountedObject<I420InterfaceAdapter>(NativeToI420Buffer()); | 91 return new rtc::RefCountedObject<I420InterfaceAdapter>(NativeToI420Buffer()); |
92 } | 92 } |
93 | 93 |
94 rtc::scoped_refptr<I420BufferInterface> VideoFrameBuffer::GetI420() { | 94 rtc::scoped_refptr<I420BufferInterface> VideoFrameBuffer::GetI420() { |
95 RTC_CHECK(type() == Type::kI420); | 95 RTC_CHECK(type() == Type::kI420); |
96 // TODO(magjed): static_cast to I420BufferInterface instead once external | 96 // TODO(magjed): static_cast to I420BufferInterface instead once external |
97 // clients are updated. | 97 // clients are updated. |
98 return new rtc::RefCountedObject<I420InterfaceAdapter>(this); | 98 return new rtc::RefCountedObject<I420InterfaceAdapter>(this); |
99 } | 99 } |
100 | 100 |
101 rtc::scoped_refptr<I444BufferInterface> VideoFrameBuffer::GetI444() { | 101 rtc::scoped_refptr<const I420BufferInterface> VideoFrameBuffer::GetI420() |
| 102 const { |
| 103 RTC_CHECK(type() == Type::kI420); |
| 104 // TODO(magjed): static_cast to I420BufferInterface instead once external |
| 105 // clients are updated. |
| 106 return new rtc::RefCountedObject<I420InterfaceAdapter>(this); |
| 107 } |
| 108 |
| 109 I444BufferInterface* VideoFrameBuffer::GetI444() { |
102 RTC_CHECK(type() == Type::kI444); | 110 RTC_CHECK(type() == Type::kI444); |
103 return static_cast<I444BufferInterface*>(this); | 111 return static_cast<I444BufferInterface*>(this); |
104 } | 112 } |
105 | 113 |
| 114 const I444BufferInterface* VideoFrameBuffer::GetI444() const { |
| 115 RTC_CHECK(type() == Type::kI444); |
| 116 return static_cast<const I444BufferInterface*>(this); |
| 117 } |
| 118 |
106 VideoFrameBuffer::Type I420BufferInterface::type() const { | 119 VideoFrameBuffer::Type I420BufferInterface::type() const { |
107 return Type::kI420; | 120 return Type::kI420; |
108 } | 121 } |
109 | 122 |
110 int I420BufferInterface::ChromaWidth() const { | 123 int I420BufferInterface::ChromaWidth() const { |
111 return (width() + 1) / 2; | 124 return (width() + 1) / 2; |
112 } | 125 } |
113 | 126 |
114 int I420BufferInterface::ChromaHeight() const { | 127 int I420BufferInterface::ChromaHeight() const { |
115 return (height() + 1) / 2; | 128 return (height() + 1) / 2; |
(...skipping 20 matching lines...) Expand all Loading... |
136 I420Buffer::Create(width(), height()); | 149 I420Buffer::Create(width(), height()); |
137 libyuv::I444ToI420(DataY(), StrideY(), DataU(), StrideU(), DataV(), StrideV(), | 150 libyuv::I444ToI420(DataY(), StrideY(), DataU(), StrideU(), DataV(), StrideV(), |
138 i420_buffer->MutableDataY(), i420_buffer->StrideY(), | 151 i420_buffer->MutableDataY(), i420_buffer->StrideY(), |
139 i420_buffer->MutableDataU(), i420_buffer->StrideU(), | 152 i420_buffer->MutableDataU(), i420_buffer->StrideU(), |
140 i420_buffer->MutableDataV(), i420_buffer->StrideV(), | 153 i420_buffer->MutableDataV(), i420_buffer->StrideV(), |
141 width(), height()); | 154 width(), height()); |
142 return i420_buffer; | 155 return i420_buffer; |
143 } | 156 } |
144 | 157 |
145 } // namespace webrtc | 158 } // namespace webrtc |
OLD | NEW |