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

Side by Side Diff: media/base/video_frame.cc

Issue 48113011: Remove media::VideoFrame from media::VideoCaptureDevice::Client interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@git-svn
Patch Set: 8c5b9836 Nits. Created 7 years, 1 month 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/base/video_frame.h" 5 #include "media/base/video_frame.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 return frame; 110 return frame;
111 } 111 }
112 112
113 void VideoFrame::ReadPixelsFromNativeTexture(const SkBitmap& pixels) { 113 void VideoFrame::ReadPixelsFromNativeTexture(const SkBitmap& pixels) {
114 DCHECK_EQ(format_, NATIVE_TEXTURE); 114 DCHECK_EQ(format_, NATIVE_TEXTURE);
115 if (!read_pixels_cb_.is_null()) 115 if (!read_pixels_cb_.is_null())
116 read_pixels_cb_.Run(pixels); 116 read_pixels_cb_.Run(pixels);
117 } 117 }
118 118
119 // static 119 // static
120 scoped_refptr<VideoFrame> VideoFrame::WrapExternalSharedMemory( 120 scoped_refptr<VideoFrame> VideoFrame::WrapExternalPackedMemory(
121 Format format, 121 Format format,
122 const gfx::Size& coded_size, 122 const gfx::Size& coded_size,
123 const gfx::Rect& visible_rect, 123 const gfx::Rect& visible_rect,
124 const gfx::Size& natural_size, 124 const gfx::Size& natural_size,
125 uint8* data, 125 uint8* data,
126 size_t data_size, 126 size_t data_size,
127 base::SharedMemoryHandle handle, 127 base::SharedMemoryHandle handle,
128 base::TimeDelta timestamp, 128 base::TimeDelta timestamp,
129 const base::Closure& no_longer_needed_cb) { 129 const base::Closure& no_longer_needed_cb) {
130 if (data_size < AllocationSize(format, coded_size)) 130 if (data_size < AllocationSize(format, coded_size))
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 } 248 }
249 249
250 static inline size_t RoundUp(size_t value, size_t alignment) { 250 static inline size_t RoundUp(size_t value, size_t alignment) {
251 // Check that |alignment| is a power of 2. 251 // Check that |alignment| is a power of 2.
252 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1))); 252 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1)));
253 return ((value + (alignment - 1)) & ~(alignment-1)); 253 return ((value + (alignment - 1)) & ~(alignment-1));
254 } 254 }
255 255
256 // static 256 // static
257 size_t VideoFrame::AllocationSize(Format format, const gfx::Size& coded_size) { 257 size_t VideoFrame::AllocationSize(Format format, const gfx::Size& coded_size) {
258 size_t total = 0;
259 for (size_t i = 0; i < NumPlanes(format); ++i)
260 total += PlaneAllocationSize(format, i, coded_size);
261 return total;
262 }
263
264 // static
265 size_t VideoFrame::PlaneAllocationSize(Format format,
266 size_t plane,
267 const gfx::Size& coded_size) {
258 switch (format) { 268 switch (format) {
259 case VideoFrame::YV12: 269 case VideoFrame::YV12:
260 case VideoFrame::I420: { 270 case VideoFrame::I420: {
261 const size_t rounded_size = 271 const size_t area =
262 RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2); 272 RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2);
Ami GONE FROM CHROMIUM 2013/11/19 21:01:52 Any reason for this not to be outside the outer sw
ncarter (slow) 2013/11/19 21:32:22 Making the switch statement RoundUp-ready would no
sheu 2013/11/19 21:35:16 communicate with care
263 return rounded_size * 3 / 2; 273 switch (plane) {
274 case VideoFrame::kYPlane:
275 return area;
276 case VideoFrame::kUPlane:
277 case VideoFrame::kVPlane:
278 return area / 4;
279 default:
280 break;
281 }
264 } 282 }
265 case VideoFrame::YV12A: { 283 case VideoFrame::YV12A: {
266 const size_t rounded_size = 284 const size_t area =
267 RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2); 285 RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2);
268 return rounded_size * 5 / 2; 286 switch (plane) {
287 case VideoFrame::kYPlane:
288 case VideoFrame::kAPlane:
289 return area;
290 case VideoFrame::kUPlane:
291 case VideoFrame::kVPlane:
292 return area / 4;
293 default:
294 break;
295 }
269 } 296 }
270 case VideoFrame::YV16: { 297 case VideoFrame::YV16: {
271 const size_t rounded_size = 298 const size_t area =
272 RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2); 299 RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2);
273 return rounded_size * 2; 300 switch (plane) {
301 case VideoFrame::kYPlane:
302 return area;
303 case VideoFrame::kUPlane:
304 case VideoFrame::kVPlane:
305 return area / 2;
306 default:
307 break;
308 }
274 } 309 }
275 case VideoFrame::UNKNOWN: 310 case VideoFrame::UNKNOWN:
276 case VideoFrame::NATIVE_TEXTURE: 311 case VideoFrame::NATIVE_TEXTURE:
277 case VideoFrame::HISTOGRAM_MAX: 312 case VideoFrame::HISTOGRAM_MAX:
278 #if defined(GOOGLE_TV) 313 #if defined(GOOGLE_TV)
279 case VideoFrame::HOLE: 314 case VideoFrame::HOLE:
280 #endif 315 #endif
281 break; 316 break;
282 } 317 }
283 NOTREACHED() << "Unsupported video frame format: " << format; 318 NOTREACHED() << "Unsupported video frame format/plane: "
319 << format << "/" << plane;
284 return 0; 320 return 0;
285 } 321 }
286 322
287 // Release data allocated by AllocateYUV(). 323 // Release data allocated by AllocateYUV().
288 static void ReleaseData(uint8* data) { 324 static void ReleaseData(uint8* data) {
289 DCHECK(data); 325 DCHECK(data);
290 base::AlignedFree(data); 326 base::AlignedFree(data);
291 } 327 }
292 328
293 void VideoFrame::AllocateYUV() { 329 void VideoFrame::AllocateYUV() {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 : mailbox_(mailbox), 501 : mailbox_(mailbox),
466 sync_point_(sync_point), 502 sync_point_(sync_point),
467 release_callback_(release_callback) {} 503 release_callback_(release_callback) {}
468 504
469 VideoFrame::MailboxHolder::~MailboxHolder() { 505 VideoFrame::MailboxHolder::~MailboxHolder() {
470 if (!release_callback_.is_null()) 506 if (!release_callback_.is_null())
471 release_callback_.Run(sync_point_); 507 release_callback_.Run(sync_point_);
472 } 508 }
473 509
474 } // namespace media 510 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698