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

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

Issue 1822283002: New method I420Buffer::Copy. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 9 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 16
16 // Aligning pointer to 64 bytes for improved performance, e.g. use SIMD. 17 // Aligning pointer to 64 bytes for improved performance, e.g. use SIMD.
17 static const int kBufferAlignment = 64; 18 static const int kBufferAlignment = 64;
18 19
19 namespace webrtc { 20 namespace webrtc {
20 21
21 namespace { 22 namespace {
22 23
23 int I420DataSize(int height, int stride_y, int stride_u, int stride_v) { 24 int I420DataSize(int height, int stride_y, int stride_u, int stride_v) {
24 return stride_y * height + (stride_u + stride_v) * ((height + 1) / 2); 25 return stride_y * height + (stride_u + stride_v) * ((height + 1) / 2);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 111
111 void* I420Buffer::native_handle() const { 112 void* I420Buffer::native_handle() const {
112 return nullptr; 113 return nullptr;
113 } 114 }
114 115
115 rtc::scoped_refptr<VideoFrameBuffer> I420Buffer::NativeToI420Buffer() { 116 rtc::scoped_refptr<VideoFrameBuffer> I420Buffer::NativeToI420Buffer() {
116 RTC_NOTREACHED(); 117 RTC_NOTREACHED();
117 return nullptr; 118 return nullptr;
118 } 119 }
119 120
121 rtc::scoped_refptr<I420Buffer> I420Buffer::Copy() {
122 rtc::scoped_refptr<I420Buffer> copy =
123 new rtc::RefCountedObject<I420Buffer>(width(), height());
124 RTC_CHECK(0 == libyuv::I420Copy(
125 data(kYPlane), stride(kYPlane),
126 data(kUPlane), stride(kUPlane),
127 data(kVPlane), stride(kVPlane),
128 copy->MutableData(kYPlane), copy->stride(kYPlane),
129 copy->MutableData(kUPlane), copy->stride(kUPlane),
130 copy->MutableData(kVPlane), copy->stride(kVPlane),
131 width(), height()));
132
133 return copy;
134 }
135
120 NativeHandleBuffer::NativeHandleBuffer(void* native_handle, 136 NativeHandleBuffer::NativeHandleBuffer(void* native_handle,
121 int width, 137 int width,
122 int height) 138 int height)
123 : native_handle_(native_handle), width_(width), height_(height) { 139 : native_handle_(native_handle), width_(width), height_(height) {
124 RTC_DCHECK(native_handle != nullptr); 140 RTC_DCHECK(native_handle != nullptr);
125 RTC_DCHECK_GT(width, 0); 141 RTC_DCHECK_GT(width, 0);
126 RTC_DCHECK_GT(height, 0); 142 RTC_DCHECK_GT(height, 0);
127 } 143 }
128 144
129 int NativeHandleBuffer::width() const { 145 int NativeHandleBuffer::width() const {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 buffer->stride(kVPlane) * uv_offset_y + uv_offset_x; 258 buffer->stride(kVPlane) * uv_offset_y + uv_offset_x;
243 return new rtc::RefCountedObject<WrappedI420Buffer>( 259 return new rtc::RefCountedObject<WrappedI420Buffer>(
244 cropped_width, cropped_height, 260 cropped_width, cropped_height,
245 y_plane, buffer->stride(kYPlane), 261 y_plane, buffer->stride(kYPlane),
246 u_plane, buffer->stride(kUPlane), 262 u_plane, buffer->stride(kUPlane),
247 v_plane, buffer->stride(kVPlane), 263 v_plane, buffer->stride(kVPlane),
248 rtc::KeepRefUntilDone(buffer)); 264 rtc::KeepRefUntilDone(buffer));
249 } 265 }
250 266
251 } // namespace webrtc 267 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698