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

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

Issue 1304143003: VideoFrameBuffer: Make non-const data access explicit (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase Created 5 years, 3 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/interface/video_frame_buffer.h" 11 #include "webrtc/common_video/interface/video_frame_buffer.h"
12 12
13 #include "webrtc/base/bind.h" 13 #include "webrtc/base/bind.h"
14 #include "webrtc/base/checks.h" 14 #include "webrtc/base/checks.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 namespace { 20 namespace {
21 21
22 // Used in rtc::Bind to keep a buffer alive until destructor is called. 22 // Used in rtc::Bind to keep a buffer alive until destructor is called.
23 static void NoLongerUsedCallback(rtc::scoped_refptr<VideoFrameBuffer> dummy) {} 23 static void NoLongerUsedCallback(rtc::scoped_refptr<VideoFrameBuffer> dummy) {}
24 24
25 } // anonymous namespace 25 } // anonymous namespace
26 26
27 uint8_t* VideoFrameBuffer::MutableData(PlaneType type) {
28 RTC_NOTREACHED();
29 return nullptr;
30 }
31
27 VideoFrameBuffer::~VideoFrameBuffer() {} 32 VideoFrameBuffer::~VideoFrameBuffer() {}
28 33
29 I420Buffer::I420Buffer(int width, int height) 34 I420Buffer::I420Buffer(int width, int height)
30 : I420Buffer(width, height, width, (width + 1) / 2, (width + 1) / 2) { 35 : I420Buffer(width, height, width, (width + 1) / 2, (width + 1) / 2) {
31 } 36 }
32 37
33 I420Buffer::I420Buffer(int width, 38 I420Buffer::I420Buffer(int width,
34 int height, 39 int height,
35 int stride_y, 40 int stride_y,
36 int stride_u, 41 int stride_u,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 return data_.get() + stride_y_ * height_; 74 return data_.get() + stride_y_ * height_;
70 case kVPlane: 75 case kVPlane:
71 return data_.get() + stride_y_ * height_ + 76 return data_.get() + stride_y_ * height_ +
72 stride_u_ * ((height_ + 1) / 2); 77 stride_u_ * ((height_ + 1) / 2);
73 default: 78 default:
74 RTC_NOTREACHED(); 79 RTC_NOTREACHED();
75 return nullptr; 80 return nullptr;
76 } 81 }
77 } 82 }
78 83
79 uint8_t* I420Buffer::data(PlaneType type) { 84 uint8_t* I420Buffer::MutableData(PlaneType type) {
80 DCHECK(HasOneRef()); 85 DCHECK(HasOneRef());
81 return const_cast<uint8_t*>( 86 return const_cast<uint8_t*>(
82 static_cast<const VideoFrameBuffer*>(this)->data(type)); 87 static_cast<const VideoFrameBuffer*>(this)->data(type));
83 } 88 }
84 89
85 int I420Buffer::stride(PlaneType type) const { 90 int I420Buffer::stride(PlaneType type) const {
86 switch (type) { 91 switch (type) {
87 case kYPlane: 92 case kYPlane:
88 return stride_y_; 93 return stride_y_;
89 case kUPlane: 94 case kUPlane:
(...skipping 30 matching lines...) Expand all
120 125
121 int NativeHandleBuffer::height() const { 126 int NativeHandleBuffer::height() const {
122 return height_; 127 return height_;
123 } 128 }
124 129
125 const uint8_t* NativeHandleBuffer::data(PlaneType type) const { 130 const uint8_t* NativeHandleBuffer::data(PlaneType type) const {
126 RTC_NOTREACHED(); // Should not be called. 131 RTC_NOTREACHED(); // Should not be called.
127 return nullptr; 132 return nullptr;
128 } 133 }
129 134
130 uint8_t* NativeHandleBuffer::data(PlaneType type) {
131 RTC_NOTREACHED(); // Should not be called.
132 return nullptr;
133 }
134
135 int NativeHandleBuffer::stride(PlaneType type) const { 135 int NativeHandleBuffer::stride(PlaneType type) const {
136 RTC_NOTREACHED(); // Should not be called. 136 RTC_NOTREACHED(); // Should not be called.
137 return 0; 137 return 0;
138 } 138 }
139 139
140 void* NativeHandleBuffer::native_handle() const { 140 void* NativeHandleBuffer::native_handle() const {
141 return native_handle_; 141 return native_handle_;
142 } 142 }
143 143
144 WrappedI420Buffer::WrappedI420Buffer(int width, 144 WrappedI420Buffer::WrappedI420Buffer(int width,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 case kUPlane: 180 case kUPlane:
181 return u_plane_; 181 return u_plane_;
182 case kVPlane: 182 case kVPlane:
183 return v_plane_; 183 return v_plane_;
184 default: 184 default:
185 RTC_NOTREACHED(); 185 RTC_NOTREACHED();
186 return nullptr; 186 return nullptr;
187 } 187 }
188 } 188 }
189 189
190 uint8_t* WrappedI420Buffer::data(PlaneType type) {
191 RTC_NOTREACHED();
192 return nullptr;
193 }
194
195 int WrappedI420Buffer::stride(PlaneType type) const { 190 int WrappedI420Buffer::stride(PlaneType type) const {
196 switch (type) { 191 switch (type) {
197 case kYPlane: 192 case kYPlane:
198 return y_stride_; 193 return y_stride_;
199 case kUPlane: 194 case kUPlane:
200 return u_stride_; 195 return u_stride_;
201 case kVPlane: 196 case kVPlane:
202 return v_stride_; 197 return v_stride_;
203 default: 198 default:
204 RTC_NOTREACHED(); 199 RTC_NOTREACHED();
(...skipping 20 matching lines...) Expand all
225 if (buffer->width() == cropped_width && buffer->height() == cropped_height) 220 if (buffer->width() == cropped_width && buffer->height() == cropped_height)
226 return buffer; 221 return buffer;
227 222
228 // Center crop to |cropped_width| x |cropped_height|. 223 // Center crop to |cropped_width| x |cropped_height|.
229 // 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.
230 const int uv_offset_x = (buffer->width() - cropped_width) / 4; 225 const int uv_offset_x = (buffer->width() - cropped_width) / 4;
231 const int uv_offset_y = (buffer->height() - cropped_height) / 4; 226 const int uv_offset_y = (buffer->height() - cropped_height) / 4;
232 const int offset_x = uv_offset_x * 2; 227 const int offset_x = uv_offset_x * 2;
233 const int offset_y = uv_offset_y * 2; 228 const int offset_y = uv_offset_y * 2;
234 229
235 // Const cast to call the correct const-version of data(). 230 const uint8_t* y_plane = buffer->data(kYPlane) +
236 const VideoFrameBuffer* const_buffer(buffer.get());
237 const uint8_t* y_plane = const_buffer->data(kYPlane) +
238 buffer->stride(kYPlane) * offset_y + offset_x; 231 buffer->stride(kYPlane) * offset_y + offset_x;
239 const uint8_t* u_plane = const_buffer->data(kUPlane) + 232 const uint8_t* u_plane = buffer->data(kUPlane) +
240 buffer->stride(kUPlane) * uv_offset_y + uv_offset_x; 233 buffer->stride(kUPlane) * uv_offset_y + uv_offset_x;
241 const uint8_t* v_plane = const_buffer->data(kVPlane) + 234 const uint8_t* v_plane = buffer->data(kVPlane) +
242 buffer->stride(kVPlane) * uv_offset_y + uv_offset_x; 235 buffer->stride(kVPlane) * uv_offset_y + uv_offset_x;
243 return new rtc::RefCountedObject<WrappedI420Buffer>( 236 return new rtc::RefCountedObject<WrappedI420Buffer>(
244 cropped_width, cropped_height, 237 cropped_width, cropped_height,
245 y_plane, buffer->stride(kYPlane), 238 y_plane, buffer->stride(kYPlane),
246 u_plane, buffer->stride(kUPlane), 239 u_plane, buffer->stride(kUPlane),
247 v_plane, buffer->stride(kVPlane), 240 v_plane, buffer->stride(kVPlane),
248 rtc::Bind(&NoLongerUsedCallback, buffer)); 241 rtc::Bind(&NoLongerUsedCallback, buffer));
249 } 242 }
250 243
251 } // namespace webrtc 244 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/common_video/video_frame.cc ('k') | webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698