OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 #include "webrtc/common_video/include/video_frame_buffer.h" | 10 #include "webrtc/common_video/include/video_frame_buffer.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 RTC_DCHECK_GT(width, 0); | 54 RTC_DCHECK_GT(width, 0); |
55 RTC_DCHECK_GT(height, 0); | 55 RTC_DCHECK_GT(height, 0); |
56 RTC_DCHECK_GE(stride_y, width); | 56 RTC_DCHECK_GE(stride_y, width); |
57 RTC_DCHECK_GE(stride_u, (width + 1) / 2); | 57 RTC_DCHECK_GE(stride_u, (width + 1) / 2); |
58 RTC_DCHECK_GE(stride_v, (width + 1) / 2); | 58 RTC_DCHECK_GE(stride_v, (width + 1) / 2); |
59 } | 59 } |
60 | 60 |
61 I420Buffer::~I420Buffer() { | 61 I420Buffer::~I420Buffer() { |
62 } | 62 } |
63 | 63 |
64 // static | |
64 rtc::scoped_refptr<I420Buffer> I420Buffer::Create(int width, int height) { | 65 rtc::scoped_refptr<I420Buffer> I420Buffer::Create(int width, int height) { |
65 return new rtc::RefCountedObject<I420Buffer>(width, height); | 66 return new rtc::RefCountedObject<I420Buffer>(width, height); |
66 } | 67 } |
67 | 68 |
69 // static | |
68 rtc::scoped_refptr<I420Buffer> I420Buffer::Create(int width, | 70 rtc::scoped_refptr<I420Buffer> I420Buffer::Create(int width, |
69 int height, | 71 int height, |
70 int stride_y, | 72 int stride_y, |
71 int stride_u, | 73 int stride_u, |
72 int stride_v) { | 74 int stride_v) { |
73 return new rtc::RefCountedObject<I420Buffer>( | 75 return new rtc::RefCountedObject<I420Buffer>( |
74 width, height, stride_y, stride_u, stride_v); | 76 width, height, stride_y, stride_u, stride_v); |
75 } | 77 } |
76 | 78 |
79 // static | |
80 rtc::scoped_refptr<I420Buffer> I420Buffer::Copy( | |
81 const VideoFrameBuffer& source) { | |
82 return Copy(source.width(), source.height(), | |
83 source.DataY(), source.StrideY(), | |
84 source.DataU(), source.StrideU(), | |
85 source.DataV(), source.StrideV()); | |
86 } | |
87 | |
88 // static | |
89 rtc::scoped_refptr<I420Buffer> I420Buffer::Copy( | |
90 int width, int height, | |
91 const uint8_t* data_y, int stride_y, | |
92 const uint8_t* data_u, int stride_u, | |
93 const uint8_t* data_v, int stride_v) { | |
94 // Note: May use different strides than the input data. | |
95 rtc::scoped_refptr<I420Buffer> buffer = Create(width, height); | |
96 RTC_CHECK_EQ(0, libyuv::I420Copy(data_y, stride_y, | |
97 data_u, stride_u, | |
98 data_v, stride_v, | |
99 buffer->MutableDataY(), buffer->StrideY(), | |
100 buffer->MutableDataU(), buffer->StrideU(), | |
101 buffer->MutableDataV(), buffer->StrideV(), | |
102 width, height)); | |
103 return buffer; | |
104 } | |
105 | |
106 // static | |
107 rtc::scoped_refptr<VideoFrameBuffer> I420Buffer::Rotate( | |
108 rtc::scoped_refptr<VideoFrameBuffer> src, | |
109 VideoRotation rotation) { | |
110 RTC_CHECK(src->DataY()); | |
nisse-webrtc
2016/11/28 09:44:54
I also changed these from DCHECK to CHECK. I think
| |
111 RTC_CHECK(src->DataU()); | |
112 RTC_CHECK(src->DataV()); | |
113 | |
114 if (rotation == webrtc::kVideoRotation_0) { | |
115 return src; | |
116 } | |
117 | |
118 int rotated_width = src->width(); | |
119 int rotated_height = src->height(); | |
120 if (rotation == webrtc::kVideoRotation_90 || | |
121 rotation == webrtc::kVideoRotation_270) { | |
122 std::swap(rotated_width, rotated_height); | |
123 } | |
124 | |
125 rtc::scoped_refptr<webrtc::I420Buffer> buffer = | |
126 I420Buffer::Create(rotated_width, rotated_height); | |
127 | |
128 RTC_CHECK_EQ(0, libyuv::I420Rotate( | |
nisse-webrtc
2016/11/28 09:44:54
And this is changed from res = ...; RTC_DCHECK_EQ(
| |
129 src->DataY(), src->StrideY(), | |
130 src->DataU(), src->StrideU(), | |
131 src->DataV(), src->StrideV(), | |
132 buffer->MutableDataY(), buffer->StrideY(), buffer->MutableDataU(), | |
133 buffer->StrideU(), buffer->MutableDataV(), buffer->StrideV(), | |
134 src->width(), src->height(), | |
135 static_cast<libyuv::RotationMode>(rotation))); | |
136 | |
137 return buffer; | |
138 } | |
139 | |
77 void I420Buffer::InitializeData() { | 140 void I420Buffer::InitializeData() { |
78 memset(data_.get(), 0, | 141 memset(data_.get(), 0, |
79 I420DataSize(height_, stride_y_, stride_u_, stride_v_)); | 142 I420DataSize(height_, stride_y_, stride_u_, stride_v_)); |
80 } | 143 } |
81 | 144 |
82 int I420Buffer::width() const { | 145 int I420Buffer::width() const { |
83 return width_; | 146 return width_; |
84 } | 147 } |
85 | 148 |
86 int I420Buffer::height() const { | 149 int I420Buffer::height() const { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 | 182 |
120 void* I420Buffer::native_handle() const { | 183 void* I420Buffer::native_handle() const { |
121 return nullptr; | 184 return nullptr; |
122 } | 185 } |
123 | 186 |
124 rtc::scoped_refptr<VideoFrameBuffer> I420Buffer::NativeToI420Buffer() { | 187 rtc::scoped_refptr<VideoFrameBuffer> I420Buffer::NativeToI420Buffer() { |
125 RTC_NOTREACHED(); | 188 RTC_NOTREACHED(); |
126 return nullptr; | 189 return nullptr; |
127 } | 190 } |
128 | 191 |
129 // static | |
130 rtc::scoped_refptr<I420Buffer> I420Buffer::Copy( | |
131 const VideoFrameBuffer& source) { | |
132 int width = source.width(); | |
133 int height = source.height(); | |
134 rtc::scoped_refptr<I420Buffer> target = I420Buffer::Create(width, height); | |
135 RTC_CHECK(libyuv::I420Copy(source.DataY(), source.StrideY(), | |
136 source.DataU(), source.StrideU(), | |
137 source.DataV(), source.StrideV(), | |
138 target->MutableDataY(), target->StrideY(), | |
139 target->MutableDataU(), target->StrideU(), | |
140 target->MutableDataV(), target->StrideV(), | |
141 width, height) == 0); | |
142 | |
143 return target; | |
144 } | |
145 | |
146 void I420Buffer::SetToBlack() { | 192 void I420Buffer::SetToBlack() { |
147 RTC_CHECK(libyuv::I420Rect(MutableDataY(), StrideY(), | 193 RTC_CHECK(libyuv::I420Rect(MutableDataY(), StrideY(), |
148 MutableDataU(), StrideU(), | 194 MutableDataU(), StrideU(), |
149 MutableDataV(), StrideV(), | 195 MutableDataV(), StrideV(), |
150 0, 0, width(), height(), | 196 0, 0, width(), height(), |
151 0, 128, 128) == 0); | 197 0, 128, 128) == 0); |
152 } | 198 } |
153 | 199 |
154 void I420Buffer::CropAndScaleFrom( | 200 void I420Buffer::CropAndScaleFrom( |
155 const VideoFrameBuffer& src, | 201 const VideoFrameBuffer& src, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 CropAndScaleFrom( | 244 CropAndScaleFrom( |
199 src, | 245 src, |
200 (src.width() - crop_width) / 2, (src.height() - crop_height) / 2, | 246 (src.width() - crop_width) / 2, (src.height() - crop_height) / 2, |
201 crop_width, crop_height); | 247 crop_width, crop_height); |
202 } | 248 } |
203 | 249 |
204 void I420Buffer::ScaleFrom(const VideoFrameBuffer& src) { | 250 void I420Buffer::ScaleFrom(const VideoFrameBuffer& src) { |
205 CropAndScaleFrom(src, 0, 0, src.width(), src.height()); | 251 CropAndScaleFrom(src, 0, 0, src.width(), src.height()); |
206 } | 252 } |
207 | 253 |
208 // static | |
209 rtc::scoped_refptr<VideoFrameBuffer> I420Buffer::Rotate( | |
210 rtc::scoped_refptr<VideoFrameBuffer> src, | |
211 VideoRotation rotation) { | |
212 RTC_DCHECK(src->DataY()); | |
213 RTC_DCHECK(src->DataU()); | |
214 RTC_DCHECK(src->DataV()); | |
215 | |
216 if (rotation == webrtc::kVideoRotation_0) { | |
217 return src; | |
218 } | |
219 | |
220 int rotated_width = src->width(); | |
221 int rotated_height = src->height(); | |
222 if (rotation == webrtc::kVideoRotation_90 || | |
223 rotation == webrtc::kVideoRotation_270) { | |
224 std::swap(rotated_width, rotated_height); | |
225 } | |
226 | |
227 rtc::scoped_refptr<webrtc::I420Buffer> buffer = | |
228 I420Buffer::Create(rotated_width, rotated_height); | |
229 | |
230 int res = libyuv::I420Rotate( | |
231 src->DataY(), src->StrideY(), | |
232 src->DataU(), src->StrideU(), | |
233 src->DataV(), src->StrideV(), | |
234 buffer->MutableDataY(), buffer->StrideY(), buffer->MutableDataU(), | |
235 buffer->StrideU(), buffer->MutableDataV(), buffer->StrideV(), | |
236 src->width(), src->height(), | |
237 static_cast<libyuv::RotationMode>(rotation)); | |
238 RTC_DCHECK_EQ(res, 0); | |
239 | |
240 return buffer; | |
241 } | |
242 | |
243 NativeHandleBuffer::NativeHandleBuffer(void* native_handle, | 254 NativeHandleBuffer::NativeHandleBuffer(void* native_handle, |
244 int width, | 255 int width, |
245 int height) | 256 int height) |
246 : native_handle_(native_handle), width_(width), height_(height) { | 257 : native_handle_(native_handle), width_(width), height_(height) { |
247 RTC_DCHECK(native_handle != nullptr); | 258 RTC_DCHECK(native_handle != nullptr); |
248 RTC_DCHECK_GT(width, 0); | 259 RTC_DCHECK_GT(width, 0); |
249 RTC_DCHECK_GT(height, 0); | 260 RTC_DCHECK_GT(height, 0); |
250 } | 261 } |
251 | 262 |
252 int NativeHandleBuffer::width() const { | 263 int NativeHandleBuffer::width() const { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
342 void* WrappedI420Buffer::native_handle() const { | 353 void* WrappedI420Buffer::native_handle() const { |
343 return nullptr; | 354 return nullptr; |
344 } | 355 } |
345 | 356 |
346 rtc::scoped_refptr<VideoFrameBuffer> WrappedI420Buffer::NativeToI420Buffer() { | 357 rtc::scoped_refptr<VideoFrameBuffer> WrappedI420Buffer::NativeToI420Buffer() { |
347 RTC_NOTREACHED(); | 358 RTC_NOTREACHED(); |
348 return nullptr; | 359 return nullptr; |
349 } | 360 } |
350 | 361 |
351 } // namespace webrtc | 362 } // namespace webrtc |
OLD | NEW |