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 | 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 | 15 |
16 // Aligning pointer to 64 bytes for improved performance, e.g. use SIMD. | 16 // Aligning pointer to 64 bytes for improved performance, e.g. use SIMD. |
17 static const int kBufferAlignment = 64; | 17 static const int kBufferAlignment = 64; |
18 | 18 |
19 namespace webrtc { | 19 namespace webrtc { |
20 | 20 |
| 21 namespace { |
| 22 |
| 23 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 } |
| 26 |
| 27 } // namespace |
| 28 |
21 uint8_t* VideoFrameBuffer::MutableData(PlaneType type) { | 29 uint8_t* VideoFrameBuffer::MutableData(PlaneType type) { |
22 RTC_NOTREACHED(); | 30 RTC_NOTREACHED(); |
23 return nullptr; | 31 return nullptr; |
24 } | 32 } |
25 | 33 |
26 VideoFrameBuffer::~VideoFrameBuffer() {} | 34 VideoFrameBuffer::~VideoFrameBuffer() {} |
27 | 35 |
28 I420Buffer::I420Buffer(int width, int height) | 36 I420Buffer::I420Buffer(int width, int height) |
29 : I420Buffer(width, height, width, (width + 1) / 2, (width + 1) / 2) { | 37 : I420Buffer(width, height, width, (width + 1) / 2, (width + 1) / 2) { |
30 } | 38 } |
31 | 39 |
32 I420Buffer::I420Buffer(int width, | 40 I420Buffer::I420Buffer(int width, |
33 int height, | 41 int height, |
34 int stride_y, | 42 int stride_y, |
35 int stride_u, | 43 int stride_u, |
36 int stride_v) | 44 int stride_v) |
37 : width_(width), | 45 : width_(width), |
38 height_(height), | 46 height_(height), |
39 stride_y_(stride_y), | 47 stride_y_(stride_y), |
40 stride_u_(stride_u), | 48 stride_u_(stride_u), |
41 stride_v_(stride_v), | 49 stride_v_(stride_v), |
42 data_(static_cast<uint8_t*>(AlignedMalloc( | 50 data_(static_cast<uint8_t*>(AlignedMalloc( |
43 stride_y * height + (stride_u + stride_v) * ((height + 1) / 2), | 51 I420DataSize(height, stride_y, stride_u, stride_v), |
44 kBufferAlignment))) { | 52 kBufferAlignment))) { |
45 RTC_DCHECK_GT(width, 0); | 53 RTC_DCHECK_GT(width, 0); |
46 RTC_DCHECK_GT(height, 0); | 54 RTC_DCHECK_GT(height, 0); |
47 RTC_DCHECK_GE(stride_y, width); | 55 RTC_DCHECK_GE(stride_y, width); |
48 RTC_DCHECK_GE(stride_u, (width + 1) / 2); | 56 RTC_DCHECK_GE(stride_u, (width + 1) / 2); |
49 RTC_DCHECK_GE(stride_v, (width + 1) / 2); | 57 RTC_DCHECK_GE(stride_v, (width + 1) / 2); |
50 } | 58 } |
51 | 59 |
52 I420Buffer::~I420Buffer() { | 60 I420Buffer::~I420Buffer() { |
53 } | 61 } |
54 | 62 |
| 63 void I420Buffer::InitializeData() { |
| 64 memset(data_.get(), 0, |
| 65 I420DataSize(height_, stride_y_, stride_u_, stride_v_)); |
| 66 } |
| 67 |
55 int I420Buffer::width() const { | 68 int I420Buffer::width() const { |
56 return width_; | 69 return width_; |
57 } | 70 } |
58 | 71 |
59 int I420Buffer::height() const { | 72 int I420Buffer::height() const { |
60 return height_; | 73 return height_; |
61 } | 74 } |
62 | 75 |
63 const uint8_t* I420Buffer::data(PlaneType type) const { | 76 const uint8_t* I420Buffer::data(PlaneType type) const { |
64 switch (type) { | 77 switch (type) { |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 buffer->stride(kVPlane) * uv_offset_y + uv_offset_x; | 242 buffer->stride(kVPlane) * uv_offset_y + uv_offset_x; |
230 return new rtc::RefCountedObject<WrappedI420Buffer>( | 243 return new rtc::RefCountedObject<WrappedI420Buffer>( |
231 cropped_width, cropped_height, | 244 cropped_width, cropped_height, |
232 y_plane, buffer->stride(kYPlane), | 245 y_plane, buffer->stride(kYPlane), |
233 u_plane, buffer->stride(kUPlane), | 246 u_plane, buffer->stride(kUPlane), |
234 v_plane, buffer->stride(kVPlane), | 247 v_plane, buffer->stride(kVPlane), |
235 rtc::KeepRefUntilDone(buffer)); | 248 rtc::KeepRefUntilDone(buffer)); |
236 } | 249 } |
237 | 250 |
238 } // namespace webrtc | 251 } // namespace webrtc |
OLD | NEW |