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 |
(...skipping 30 matching lines...) Expand all Loading... |
41 int stride_u, | 41 int stride_u, |
42 int stride_v) | 42 int stride_v) |
43 : width_(width), | 43 : width_(width), |
44 height_(height), | 44 height_(height), |
45 stride_y_(stride_y), | 45 stride_y_(stride_y), |
46 stride_u_(stride_u), | 46 stride_u_(stride_u), |
47 stride_v_(stride_v), | 47 stride_v_(stride_v), |
48 data_(static_cast<uint8_t*>(AlignedMalloc( | 48 data_(static_cast<uint8_t*>(AlignedMalloc( |
49 stride_y * height + (stride_u + stride_v) * ((height + 1) / 2), | 49 stride_y * height + (stride_u + stride_v) * ((height + 1) / 2), |
50 kBufferAlignment))) { | 50 kBufferAlignment))) { |
51 DCHECK_GT(width, 0); | 51 RTC_DCHECK_GT(width, 0); |
52 DCHECK_GT(height, 0); | 52 RTC_DCHECK_GT(height, 0); |
53 DCHECK_GE(stride_y, width); | 53 RTC_DCHECK_GE(stride_y, width); |
54 DCHECK_GE(stride_u, (width + 1) / 2); | 54 RTC_DCHECK_GE(stride_u, (width + 1) / 2); |
55 DCHECK_GE(stride_v, (width + 1) / 2); | 55 RTC_DCHECK_GE(stride_v, (width + 1) / 2); |
56 } | 56 } |
57 | 57 |
58 I420Buffer::~I420Buffer() { | 58 I420Buffer::~I420Buffer() { |
59 } | 59 } |
60 | 60 |
61 int I420Buffer::width() const { | 61 int I420Buffer::width() const { |
62 return width_; | 62 return width_; |
63 } | 63 } |
64 | 64 |
65 int I420Buffer::height() const { | 65 int I420Buffer::height() const { |
66 return height_; | 66 return height_; |
67 } | 67 } |
68 | 68 |
69 const uint8_t* I420Buffer::data(PlaneType type) const { | 69 const uint8_t* I420Buffer::data(PlaneType type) const { |
70 switch (type) { | 70 switch (type) { |
71 case kYPlane: | 71 case kYPlane: |
72 return data_.get(); | 72 return data_.get(); |
73 case kUPlane: | 73 case kUPlane: |
74 return data_.get() + stride_y_ * height_; | 74 return data_.get() + stride_y_ * height_; |
75 case kVPlane: | 75 case kVPlane: |
76 return data_.get() + stride_y_ * height_ + | 76 return data_.get() + stride_y_ * height_ + |
77 stride_u_ * ((height_ + 1) / 2); | 77 stride_u_ * ((height_ + 1) / 2); |
78 default: | 78 default: |
79 RTC_NOTREACHED(); | 79 RTC_NOTREACHED(); |
80 return nullptr; | 80 return nullptr; |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 uint8_t* I420Buffer::MutableData(PlaneType type) { | 84 uint8_t* I420Buffer::MutableData(PlaneType type) { |
85 DCHECK(HasOneRef()); | 85 RTC_DCHECK(HasOneRef()); |
86 return const_cast<uint8_t*>( | 86 return const_cast<uint8_t*>( |
87 static_cast<const VideoFrameBuffer*>(this)->data(type)); | 87 static_cast<const VideoFrameBuffer*>(this)->data(type)); |
88 } | 88 } |
89 | 89 |
90 int I420Buffer::stride(PlaneType type) const { | 90 int I420Buffer::stride(PlaneType type) const { |
91 switch (type) { | 91 switch (type) { |
92 case kYPlane: | 92 case kYPlane: |
93 return stride_y_; | 93 return stride_y_; |
94 case kUPlane: | 94 case kUPlane: |
95 return stride_u_; | 95 return stride_u_; |
(...skipping 11 matching lines...) Expand all Loading... |
107 | 107 |
108 rtc::scoped_refptr<VideoFrameBuffer> I420Buffer::NativeToI420Buffer() { | 108 rtc::scoped_refptr<VideoFrameBuffer> I420Buffer::NativeToI420Buffer() { |
109 RTC_NOTREACHED(); | 109 RTC_NOTREACHED(); |
110 return nullptr; | 110 return nullptr; |
111 } | 111 } |
112 | 112 |
113 NativeHandleBuffer::NativeHandleBuffer(void* native_handle, | 113 NativeHandleBuffer::NativeHandleBuffer(void* native_handle, |
114 int width, | 114 int width, |
115 int height) | 115 int height) |
116 : native_handle_(native_handle), width_(width), height_(height) { | 116 : native_handle_(native_handle), width_(width), height_(height) { |
117 DCHECK(native_handle != nullptr); | 117 RTC_DCHECK(native_handle != nullptr); |
118 DCHECK_GT(width, 0); | 118 RTC_DCHECK_GT(width, 0); |
119 DCHECK_GT(height, 0); | 119 RTC_DCHECK_GT(height, 0); |
120 } | 120 } |
121 | 121 |
122 int NativeHandleBuffer::width() const { | 122 int NativeHandleBuffer::width() const { |
123 return width_; | 123 return width_; |
124 } | 124 } |
125 | 125 |
126 int NativeHandleBuffer::height() const { | 126 int NativeHandleBuffer::height() const { |
127 return height_; | 127 return height_; |
128 } | 128 } |
129 | 129 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 | 207 |
208 rtc::scoped_refptr<VideoFrameBuffer> WrappedI420Buffer::NativeToI420Buffer() { | 208 rtc::scoped_refptr<VideoFrameBuffer> WrappedI420Buffer::NativeToI420Buffer() { |
209 RTC_NOTREACHED(); | 209 RTC_NOTREACHED(); |
210 return nullptr; | 210 return nullptr; |
211 } | 211 } |
212 | 212 |
213 rtc::scoped_refptr<VideoFrameBuffer> ShallowCenterCrop( | 213 rtc::scoped_refptr<VideoFrameBuffer> ShallowCenterCrop( |
214 const rtc::scoped_refptr<VideoFrameBuffer>& buffer, | 214 const rtc::scoped_refptr<VideoFrameBuffer>& buffer, |
215 int cropped_width, | 215 int cropped_width, |
216 int cropped_height) { | 216 int cropped_height) { |
217 CHECK(buffer->native_handle() == nullptr); | 217 RTC_CHECK(buffer->native_handle() == nullptr); |
218 CHECK_LE(cropped_width, buffer->width()); | 218 RTC_CHECK_LE(cropped_width, buffer->width()); |
219 CHECK_LE(cropped_height, buffer->height()); | 219 RTC_CHECK_LE(cropped_height, buffer->height()); |
220 if (buffer->width() == cropped_width && buffer->height() == cropped_height) | 220 if (buffer->width() == cropped_width && buffer->height() == cropped_height) |
221 return buffer; | 221 return buffer; |
222 | 222 |
223 // Center crop to |cropped_width| x |cropped_height|. | 223 // Center crop to |cropped_width| x |cropped_height|. |
224 // Make sure offset is even so that u/v plane becomes aligned. | 224 // Make sure offset is even so that u/v plane becomes aligned. |
225 const int uv_offset_x = (buffer->width() - cropped_width) / 4; | 225 const int uv_offset_x = (buffer->width() - cropped_width) / 4; |
226 const int uv_offset_y = (buffer->height() - cropped_height) / 4; | 226 const int uv_offset_y = (buffer->height() - cropped_height) / 4; |
227 const int offset_x = uv_offset_x * 2; | 227 const int offset_x = uv_offset_x * 2; |
228 const int offset_y = uv_offset_y * 2; | 228 const int offset_y = uv_offset_y * 2; |
229 | 229 |
230 const uint8_t* y_plane = buffer->data(kYPlane) + | 230 const uint8_t* y_plane = buffer->data(kYPlane) + |
231 buffer->stride(kYPlane) * offset_y + offset_x; | 231 buffer->stride(kYPlane) * offset_y + offset_x; |
232 const uint8_t* u_plane = buffer->data(kUPlane) + | 232 const uint8_t* u_plane = buffer->data(kUPlane) + |
233 buffer->stride(kUPlane) * uv_offset_y + uv_offset_x; | 233 buffer->stride(kUPlane) * uv_offset_y + uv_offset_x; |
234 const uint8_t* v_plane = buffer->data(kVPlane) + | 234 const uint8_t* v_plane = buffer->data(kVPlane) + |
235 buffer->stride(kVPlane) * uv_offset_y + uv_offset_x; | 235 buffer->stride(kVPlane) * uv_offset_y + uv_offset_x; |
236 return new rtc::RefCountedObject<WrappedI420Buffer>( | 236 return new rtc::RefCountedObject<WrappedI420Buffer>( |
237 cropped_width, cropped_height, | 237 cropped_width, cropped_height, |
238 y_plane, buffer->stride(kYPlane), | 238 y_plane, buffer->stride(kYPlane), |
239 u_plane, buffer->stride(kUPlane), | 239 u_plane, buffer->stride(kUPlane), |
240 v_plane, buffer->stride(kVPlane), | 240 v_plane, buffer->stride(kVPlane), |
241 rtc::Bind(&NoLongerUsedCallback, buffer)); | 241 rtc::Bind(&NoLongerUsedCallback, buffer)); |
242 } | 242 } |
243 | 243 |
244 } // namespace webrtc | 244 } // namespace webrtc |
OLD | NEW |