Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: webrtc/common_video/video_frame_buffer.cc

Issue 1973873003: Delete AndroidVideoCapturer::FrameFactory. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Address nits. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 10
11 #include "webrtc/common_video/include/video_frame_buffer.h" 11 #include "webrtc/common_video/include/video_frame_buffer.h"
12 12
13 #include "webrtc/base/checks.h" 13 #include "webrtc/base/checks.h"
14 #include "webrtc/base/keep_ref_until_done.h" 14 #include "webrtc/base/keep_ref_until_done.h"
15 #include "libyuv/convert.h" 15 #include "libyuv/convert.h"
16 #include "libyuv/scale.h"
16 17
17 // Aligning pointer to 64 bytes for improved performance, e.g. use SIMD. 18 // Aligning pointer to 64 bytes for improved performance, e.g. use SIMD.
18 static const int kBufferAlignment = 64; 19 static const int kBufferAlignment = 64;
19 20
20 namespace webrtc { 21 namespace webrtc {
21 22
22 namespace { 23 namespace {
23 24
24 int I420DataSize(int height, int stride_y, int stride_u, int stride_v) { 25 int I420DataSize(int height, int stride_y, int stride_u, int stride_v) {
25 return stride_y * height + (stride_u + stride_v) * ((height + 1) / 2); 26 return stride_y * height + (stride_u + stride_v) * ((height + 1) / 2);
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 buffer->DataU(), buffer->StrideU(), 201 buffer->DataU(), buffer->StrideU(),
201 buffer->DataV(), buffer->StrideV(), 202 buffer->DataV(), buffer->StrideV(),
202 copy->MutableDataY(), copy->StrideY(), 203 copy->MutableDataY(), copy->StrideY(),
203 copy->MutableDataU(), copy->StrideU(), 204 copy->MutableDataU(), copy->StrideU(),
204 copy->MutableDataV(), copy->StrideV(), 205 copy->MutableDataV(), copy->StrideV(),
205 width, height) == 0); 206 width, height) == 0);
206 207
207 return copy; 208 return copy;
208 } 209 }
209 210
211 rtc::scoped_refptr<I420Buffer> I420Buffer::CropAndScale(
212 const rtc::scoped_refptr<VideoFrameBuffer>& buffer,
213 int offset_x,
214 int offset_y,
215 int crop_width,
216 int crop_height,
217 int dst_width,
218 int dst_height) {
219 RTC_CHECK_LE(crop_width, buffer->width());
220 RTC_CHECK_LE(crop_height, buffer->height());
221 RTC_CHECK_LE(crop_width + offset_x, buffer->width());
222 RTC_CHECK_LE(crop_height + offset_y, buffer->height());
223 RTC_CHECK_GE(offset_x, 0);
224 RTC_CHECK_GE(offset_y, 0);
225
226 rtc::scoped_refptr<I420Buffer> scaled =
227 new rtc::RefCountedObject<I420Buffer>(dst_width, dst_height);
228
229 // Make sure offset is even so that u/v plane becomes aligned.
230 const int uv_offset_x = offset_x / 2;
231 const int uv_offset_y = offset_y / 2;
232 offset_x = uv_offset_x * 2;
233 offset_y = uv_offset_y * 2;
234
235 const uint8_t* y_plane =
236 buffer->DataY() + buffer->StrideY() * offset_y + offset_x;
237 const uint8_t* u_plane =
238 buffer->DataU() + buffer->StrideU() * uv_offset_y + uv_offset_x;
239 const uint8_t* v_plane =
240 buffer->DataV() + buffer->StrideV() * uv_offset_y + uv_offset_x;
241 if (libyuv::I420Scale(y_plane, buffer->StrideY(),
242 u_plane, buffer->StrideU(),
243 v_plane, buffer->StrideV(),
244 crop_width, crop_height,
245 scaled->MutableDataY(), scaled->StrideY(),
246 scaled->MutableDataU(), scaled->StrideU(),
247 scaled->MutableDataV(), scaled->StrideV(),
248 dst_width, dst_height, libyuv::kFilterBox) < 0) {
249 return nullptr;
250 }
251 return scaled;
252 }
253
210 NativeHandleBuffer::NativeHandleBuffer(void* native_handle, 254 NativeHandleBuffer::NativeHandleBuffer(void* native_handle,
211 int width, 255 int width,
212 int height) 256 int height)
213 : native_handle_(native_handle), width_(width), height_(height) { 257 : native_handle_(native_handle), width_(width), height_(height) {
214 RTC_DCHECK(native_handle != nullptr); 258 RTC_DCHECK(native_handle != nullptr);
215 RTC_DCHECK_GT(width, 0); 259 RTC_DCHECK_GT(width, 0);
216 RTC_DCHECK_GT(height, 0); 260 RTC_DCHECK_GT(height, 0);
217 } 261 }
218 262
219 bool NativeHandleBuffer::IsMutable() { 263 bool NativeHandleBuffer::IsMutable() {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 buffer->StrideV() * uv_offset_y + uv_offset_x; 393 buffer->StrideV() * uv_offset_y + uv_offset_x;
350 return new rtc::RefCountedObject<WrappedI420Buffer>( 394 return new rtc::RefCountedObject<WrappedI420Buffer>(
351 cropped_width, cropped_height, 395 cropped_width, cropped_height,
352 y_plane, buffer->StrideY(), 396 y_plane, buffer->StrideY(),
353 u_plane, buffer->StrideU(), 397 u_plane, buffer->StrideU(),
354 v_plane, buffer->StrideV(), 398 v_plane, buffer->StrideV(),
355 rtc::KeepRefUntilDone(buffer)); 399 rtc::KeepRefUntilDone(buffer));
356 } 400 }
357 401
358 } // namespace webrtc 402 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698