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

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

Issue 1117423002: media: Let VideoFrame carry more than one native texture. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Fix bot failures. Created 5 years, 7 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 // 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 NOTIMPLEMENTED(); 133 NOTIMPLEMENTED();
134 return nullptr; 134 return nullptr;
135 } 135 }
136 136
137 // Since we're creating a new YUV frame (and allocating memory for it 137 // Since we're creating a new YUV frame (and allocating memory for it
138 // ourselves), we can pad the requested |coded_size| if necessary if the 138 // ourselves), we can pad the requested |coded_size| if necessary if the
139 // request does not line up on sample boundaries. 139 // request does not line up on sample boundaries.
140 const gfx::Size new_coded_size = AdjustCodedSize(format, coded_size); 140 const gfx::Size new_coded_size = AdjustCodedSize(format, coded_size);
141 DCHECK(IsValidConfig(format, new_coded_size, visible_rect, natural_size)); 141 DCHECK(IsValidConfig(format, new_coded_size, visible_rect, natural_size));
142 142
143 gpu::MailboxHolder mailboxes[kMaxPlanes];
143 scoped_refptr<VideoFrame> frame( 144 scoped_refptr<VideoFrame> frame(
144 new VideoFrame(format, 145 new VideoFrame(format, new_coded_size, visible_rect, natural_size,
145 new_coded_size, 146 mailboxes, TEXTURE_RGBA, timestamp, false));
mcasas 2015/05/04 16:23:41 Although this is more Chromium-style, I'd rather l
Daniele Castagna 2015/05/04 17:59:59 This was done by "git cl format". dalecurtis@ seem
146 visible_rect,
147 natural_size,
148 scoped_ptr<gpu::MailboxHolder>(),
149 timestamp,
150 false));
151 frame->AllocateYUV(); 147 frame->AllocateYUV();
152 return frame; 148 return frame;
153 } 149 }
154 150
155 // static 151 // static
156 std::string VideoFrame::FormatToString(VideoFrame::Format format) { 152 std::string VideoFrame::FormatToString(VideoFrame::Format format) {
157 switch (format) { 153 switch (format) {
158 case VideoFrame::UNKNOWN: 154 case VideoFrame::UNKNOWN:
159 return "UNKNOWN"; 155 return "UNKNOWN";
160 case VideoFrame::YV12: 156 case VideoFrame::YV12:
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 const gfx::Size& natural_size) { 189 const gfx::Size& natural_size) {
194 // Check maximum limits for all formats. 190 // Check maximum limits for all formats.
195 if (coded_size.GetArea() > limits::kMaxCanvas || 191 if (coded_size.GetArea() > limits::kMaxCanvas ||
196 coded_size.width() > limits::kMaxDimension || 192 coded_size.width() > limits::kMaxDimension ||
197 coded_size.height() > limits::kMaxDimension || 193 coded_size.height() > limits::kMaxDimension ||
198 visible_rect.x() < 0 || visible_rect.y() < 0 || 194 visible_rect.x() < 0 || visible_rect.y() < 0 ||
199 visible_rect.right() > coded_size.width() || 195 visible_rect.right() > coded_size.width() ||
200 visible_rect.bottom() > coded_size.height() || 196 visible_rect.bottom() > coded_size.height() ||
201 natural_size.GetArea() > limits::kMaxCanvas || 197 natural_size.GetArea() > limits::kMaxCanvas ||
202 natural_size.width() > limits::kMaxDimension || 198 natural_size.width() > limits::kMaxDimension ||
203 natural_size.height() > limits::kMaxDimension) 199 natural_size.height() > limits::kMaxDimension)
DaleCurtis 2015/05/04 16:12:06 I think you should keep the checks here.
Daniele Castagna 2015/05/04 17:59:59 What can we check now if texture_format is always
DaleCurtis 2015/05/04 18:12:54 IsValid() checks like this are sometimes used to v
204 return false; 200 return false;
205 201
206 // Check format-specific width/height requirements. 202 // Check format-specific width/height requirements.
207 switch (format) { 203 switch (format) {
208 case VideoFrame::UNKNOWN: 204 case VideoFrame::UNKNOWN:
209 return (coded_size.IsEmpty() && visible_rect.IsEmpty() && 205 return (coded_size.IsEmpty() && visible_rect.IsEmpty() &&
210 natural_size.IsEmpty()); 206 natural_size.IsEmpty());
211 207
212 // NATIVE_TEXTURE and HOLE have no software-allocated buffers and are 208 // NATIVE_TEXTURE and HOLE have no software-allocated buffers and are
213 // allowed to skip the below check. 209 // allowed to skip the below check.
(...skipping 22 matching lines...) Expand all
236 !coded_size.IsEmpty() && !visible_rect.IsEmpty() && 232 !coded_size.IsEmpty() && !visible_rect.IsEmpty() &&
237 !natural_size.IsEmpty(); 233 !natural_size.IsEmpty();
238 } 234 }
239 235
240 NOTREACHED(); 236 NOTREACHED();
241 return false; 237 return false;
242 } 238 }
243 239
244 // static 240 // static
245 scoped_refptr<VideoFrame> VideoFrame::WrapNativeTexture( 241 scoped_refptr<VideoFrame> VideoFrame::WrapNativeTexture(
246 scoped_ptr<gpu::MailboxHolder> mailbox_holder, 242 const gpu::MailboxHolder& mailbox_holder,
247 const ReleaseMailboxCB& mailbox_holder_release_cb, 243 const ReleaseMailboxCB& mailbox_holder_release_cb,
248 const gfx::Size& coded_size, 244 const gfx::Size& coded_size,
249 const gfx::Rect& visible_rect, 245 const gfx::Rect& visible_rect,
250 const gfx::Size& natural_size, 246 const gfx::Size& natural_size,
251 base::TimeDelta timestamp, 247 base::TimeDelta timestamp,
252 bool allow_overlay) { 248 bool allow_overlay) {
253 scoped_refptr<VideoFrame> frame(new VideoFrame(NATIVE_TEXTURE, 249 gpu::MailboxHolder mailbox_holders[kMaxPlanes];
254 coded_size, 250 mailbox_holders[kARGBPlane] = mailbox_holder;
255 visible_rect, 251 scoped_refptr<VideoFrame> frame(
256 natural_size, 252 new VideoFrame(NATIVE_TEXTURE, coded_size, visible_rect, natural_size,
257 mailbox_holder.Pass(), 253 mailbox_holders, TEXTURE_RGBA, timestamp, false));
mcasas 2015/05/04 16:23:41 Idem, please align parameters one per line (again,
DaleCurtis 2015/05/04 16:31:30 I'm fine with git cl format on this :)
Daniele Castagna 2015/05/04 17:59:59 Tnx, I find it really time wasting to have to run
258 timestamp, 254 frame->mailbox_holders_release_cb_ = mailbox_holder_release_cb;
259 false));
260 frame->mailbox_holder_release_cb_ = mailbox_holder_release_cb;
261 frame->allow_overlay_ = allow_overlay; 255 frame->allow_overlay_ = allow_overlay;
262
263 return frame; 256 return frame;
264 } 257 }
265 258
259 // static
260 scoped_refptr<VideoFrame> VideoFrame::WrapYUV420NativeTextures(
261 const gpu::MailboxHolder& y_mailbox_holder,
262 const gpu::MailboxHolder& u_mailbox_holder,
263 const gpu::MailboxHolder& v_mailbox_holder,
264 const ReleaseMailboxCB& mailbox_holder_release_cb,
265 const gfx::Size& coded_size,
266 const gfx::Rect& visible_rect,
267 const gfx::Size& natural_size,
268 base::TimeDelta timestamp,
269 bool allow_overlay) {
270 gpu::MailboxHolder mailbox_holders[kMaxPlanes];
271 mailbox_holders[kYPlane] = y_mailbox_holder;
272 mailbox_holders[kUPlane] = u_mailbox_holder;
273 mailbox_holders[kVPlane] = v_mailbox_holder;
274 scoped_refptr<VideoFrame> frame(
275 new VideoFrame(NATIVE_TEXTURE, coded_size, visible_rect, natural_size,
276 mailbox_holders, TEXTURE_YUV_420, timestamp, false));
277 frame->mailbox_holders_release_cb_ = mailbox_holder_release_cb;
278 frame->allow_overlay_ = allow_overlay;
279 return frame;
280 }
281
266 // static 282 // static
267 scoped_refptr<VideoFrame> VideoFrame::WrapExternalPackedMemory( 283 scoped_refptr<VideoFrame> VideoFrame::WrapExternalPackedMemory(
268 Format format, 284 Format format,
269 const gfx::Size& coded_size, 285 const gfx::Size& coded_size,
270 const gfx::Rect& visible_rect, 286 const gfx::Rect& visible_rect,
271 const gfx::Size& natural_size, 287 const gfx::Size& natural_size,
272 uint8* data, 288 uint8* data,
273 size_t data_size, 289 size_t data_size,
274 base::SharedMemoryHandle handle, 290 base::SharedMemoryHandle handle,
275 size_t data_offset, 291 size_t data_offset,
276 base::TimeDelta timestamp, 292 base::TimeDelta timestamp,
277 const base::Closure& no_longer_needed_cb) { 293 const base::Closure& no_longer_needed_cb) {
278 const gfx::Size new_coded_size = AdjustCodedSize(format, coded_size); 294 const gfx::Size new_coded_size = AdjustCodedSize(format, coded_size);
279 295
280 if (!IsValidConfig(format, new_coded_size, visible_rect, natural_size)) 296 if (!IsValidConfig(format, new_coded_size, visible_rect, natural_size))
281 return NULL; 297 return NULL;
282 if (data_size < AllocationSize(format, new_coded_size)) 298 if (data_size < AllocationSize(format, new_coded_size))
283 return NULL; 299 return NULL;
284 300
285 switch (format) { 301 switch (format) {
286 case VideoFrame::I420: { 302 case VideoFrame::I420: {
303 gpu::MailboxHolder mailbox_holders[kMaxPlanes];
287 scoped_refptr<VideoFrame> frame( 304 scoped_refptr<VideoFrame> frame(
288 new VideoFrame(format, 305 new VideoFrame(format, new_coded_size, visible_rect, natural_size,
289 new_coded_size, 306 mailbox_holders, TEXTURE_RGBA, timestamp, false));
290 visible_rect,
291 natural_size,
292 scoped_ptr<gpu::MailboxHolder>(),
293 timestamp,
294 false));
295 frame->shared_memory_handle_ = handle; 307 frame->shared_memory_handle_ = handle;
296 frame->shared_memory_offset_ = data_offset; 308 frame->shared_memory_offset_ = data_offset;
297 frame->strides_[kYPlane] = new_coded_size.width(); 309 frame->strides_[kYPlane] = new_coded_size.width();
298 frame->strides_[kUPlane] = new_coded_size.width() / 2; 310 frame->strides_[kUPlane] = new_coded_size.width() / 2;
299 frame->strides_[kVPlane] = new_coded_size.width() / 2; 311 frame->strides_[kVPlane] = new_coded_size.width() / 2;
300 frame->data_[kYPlane] = data; 312 frame->data_[kYPlane] = data;
301 frame->data_[kUPlane] = data + new_coded_size.GetArea(); 313 frame->data_[kUPlane] = data + new_coded_size.GetArea();
302 frame->data_[kVPlane] = data + (new_coded_size.GetArea() * 5 / 4); 314 frame->data_[kVPlane] = data + (new_coded_size.GetArea() * 5 / 4);
303 frame->no_longer_needed_cb_ = no_longer_needed_cb; 315 frame->no_longer_needed_cb_ = no_longer_needed_cb;
304 return frame; 316 return frame;
(...skipping 14 matching lines...) Expand all
319 int32 u_stride, 331 int32 u_stride,
320 int32 v_stride, 332 int32 v_stride,
321 uint8* y_data, 333 uint8* y_data,
322 uint8* u_data, 334 uint8* u_data,
323 uint8* v_data, 335 uint8* v_data,
324 base::TimeDelta timestamp, 336 base::TimeDelta timestamp,
325 const base::Closure& no_longer_needed_cb) { 337 const base::Closure& no_longer_needed_cb) {
326 const gfx::Size new_coded_size = AdjustCodedSize(format, coded_size); 338 const gfx::Size new_coded_size = AdjustCodedSize(format, coded_size);
327 CHECK(IsValidConfig(format, new_coded_size, visible_rect, natural_size)); 339 CHECK(IsValidConfig(format, new_coded_size, visible_rect, natural_size));
328 340
341 gpu::MailboxHolder mailbox_holders[kMaxPlanes];
329 scoped_refptr<VideoFrame> frame( 342 scoped_refptr<VideoFrame> frame(
330 new VideoFrame(format, 343 new VideoFrame(format, new_coded_size, visible_rect, natural_size,
331 new_coded_size, 344 mailbox_holders, TEXTURE_RGBA, timestamp, false));
332 visible_rect,
333 natural_size,
334 scoped_ptr<gpu::MailboxHolder>(),
335 timestamp,
336 false));
337 frame->strides_[kYPlane] = y_stride; 345 frame->strides_[kYPlane] = y_stride;
338 frame->strides_[kUPlane] = u_stride; 346 frame->strides_[kUPlane] = u_stride;
339 frame->strides_[kVPlane] = v_stride; 347 frame->strides_[kVPlane] = v_stride;
340 frame->data_[kYPlane] = y_data; 348 frame->data_[kYPlane] = y_data;
341 frame->data_[kUPlane] = u_data; 349 frame->data_[kUPlane] = u_data;
342 frame->data_[kVPlane] = v_data; 350 frame->data_[kVPlane] = v_data;
343 frame->no_longer_needed_cb_ = no_longer_needed_cb; 351 frame->no_longer_needed_cb_ = no_longer_needed_cb;
344 return frame; 352 return frame;
345 } 353 }
346 354
(...skipping 10 matching lines...) Expand all
357 if (!IsValidConfig(format, coded_size, visible_rect, natural_size)) 365 if (!IsValidConfig(format, coded_size, visible_rect, natural_size))
358 return NULL; 366 return NULL;
359 367
360 // TODO(posciak): This is not exactly correct, it's possible for one 368 // TODO(posciak): This is not exactly correct, it's possible for one
361 // buffer to contain more than one plane. 369 // buffer to contain more than one plane.
362 if (dmabuf_fds.size() != NumPlanes(format)) { 370 if (dmabuf_fds.size() != NumPlanes(format)) {
363 LOG(FATAL) << "Not enough dmabuf fds provided!"; 371 LOG(FATAL) << "Not enough dmabuf fds provided!";
364 return NULL; 372 return NULL;
365 } 373 }
366 374
375 gpu::MailboxHolder mailbox_holders[kMaxPlanes];
367 scoped_refptr<VideoFrame> frame( 376 scoped_refptr<VideoFrame> frame(
368 new VideoFrame(format, 377 new VideoFrame(format, coded_size, visible_rect, natural_size,
369 coded_size, 378 mailbox_holders, TEXTURE_RGBA, timestamp, false));
370 visible_rect,
371 natural_size,
372 scoped_ptr<gpu::MailboxHolder>(),
373 timestamp,
374 false));
375 379
376 for (size_t i = 0; i < dmabuf_fds.size(); ++i) { 380 for (size_t i = 0; i < dmabuf_fds.size(); ++i) {
377 int duped_fd = HANDLE_EINTR(dup(dmabuf_fds[i])); 381 int duped_fd = HANDLE_EINTR(dup(dmabuf_fds[i]));
378 if (duped_fd == -1) { 382 if (duped_fd == -1) {
379 // The already-duped in previous iterations fds will be closed when 383 // The already-duped in previous iterations fds will be closed when
380 // the partially-created frame drops out of scope here. 384 // the partially-created frame drops out of scope here.
381 DLOG(ERROR) << "Failed duplicating a dmabuf fd"; 385 DLOG(ERROR) << "Failed duplicating a dmabuf fd";
382 return NULL; 386 return NULL;
383 } 387 }
384 388
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 return NULL; 421 return NULL;
418 } 422 }
419 423
420 const gfx::Size coded_size(CVImageBufferGetEncodedSize(cv_pixel_buffer)); 424 const gfx::Size coded_size(CVImageBufferGetEncodedSize(cv_pixel_buffer));
421 const gfx::Rect visible_rect(CVImageBufferGetCleanRect(cv_pixel_buffer)); 425 const gfx::Rect visible_rect(CVImageBufferGetCleanRect(cv_pixel_buffer));
422 const gfx::Size natural_size(CVImageBufferGetDisplaySize(cv_pixel_buffer)); 426 const gfx::Size natural_size(CVImageBufferGetDisplaySize(cv_pixel_buffer));
423 427
424 if (!IsValidConfig(format, coded_size, visible_rect, natural_size)) 428 if (!IsValidConfig(format, coded_size, visible_rect, natural_size))
425 return NULL; 429 return NULL;
426 430
431 gpu::MailboxHolder mailbox_holders[kMaxPlanes];
427 scoped_refptr<VideoFrame> frame( 432 scoped_refptr<VideoFrame> frame(
428 new VideoFrame(format, 433 new VideoFrame(format, coded_size, visible_rect, natural_size,
429 coded_size, 434 mailbox_holders, TEXTURE_RGBA, timestamp, false));
430 visible_rect,
431 natural_size,
432 scoped_ptr<gpu::MailboxHolder>(),
433 timestamp,
434 false));
435 435
436 frame->cv_pixel_buffer_.reset(cv_pixel_buffer, base::scoped_policy::RETAIN); 436 frame->cv_pixel_buffer_.reset(cv_pixel_buffer, base::scoped_policy::RETAIN);
437 return frame; 437 return frame;
438 } 438 }
439 #endif 439 #endif
440 440
441 // static 441 // static
442 scoped_refptr<VideoFrame> VideoFrame::WrapVideoFrame( 442 scoped_refptr<VideoFrame> VideoFrame::WrapVideoFrame(
443 const scoped_refptr<VideoFrame>& frame, 443 const scoped_refptr<VideoFrame>& frame,
444 const gfx::Rect& visible_rect, 444 const gfx::Rect& visible_rect,
445 const gfx::Size& natural_size, 445 const gfx::Size& natural_size,
446 const base::Closure& no_longer_needed_cb) { 446 const base::Closure& no_longer_needed_cb) {
447 // NATIVE_TEXTURE frames need mailbox info propagated, and there's no support 447 // NATIVE_TEXTURE frames need mailbox info propagated, and there's no support
448 // for that here yet, see http://crbug/362521. 448 // for that here yet, see http://crbug/362521.
449 CHECK_NE(frame->format(), NATIVE_TEXTURE); 449 CHECK_NE(frame->format(), NATIVE_TEXTURE);
450 450
451 DCHECK(frame->visible_rect().Contains(visible_rect)); 451 DCHECK(frame->visible_rect().Contains(visible_rect));
452 gpu::MailboxHolder mailbox_holders[kMaxPlanes];
452 scoped_refptr<VideoFrame> wrapped_frame( 453 scoped_refptr<VideoFrame> wrapped_frame(
453 new VideoFrame(frame->format(), 454 new VideoFrame(frame->format(), frame->coded_size(), visible_rect,
454 frame->coded_size(), 455 natural_size, mailbox_holders, TEXTURE_RGBA,
455 visible_rect, 456 frame->timestamp(), frame->end_of_stream()));
456 natural_size,
457 scoped_ptr<gpu::MailboxHolder>(),
458 frame->timestamp(),
459 frame->end_of_stream()));
460 457
461 for (size_t i = 0; i < NumPlanes(frame->format()); ++i) { 458 for (size_t i = 0; i < NumPlanes(frame->format()); ++i) {
462 wrapped_frame->strides_[i] = frame->stride(i); 459 wrapped_frame->strides_[i] = frame->stride(i);
463 wrapped_frame->data_[i] = frame->data(i); 460 wrapped_frame->data_[i] = frame->data(i);
464 } 461 }
465 462
466 wrapped_frame->no_longer_needed_cb_ = no_longer_needed_cb; 463 wrapped_frame->no_longer_needed_cb_ = no_longer_needed_cb;
467 return wrapped_frame; 464 return wrapped_frame;
468 } 465 }
469 466
470 // static 467 // static
471 scoped_refptr<VideoFrame> VideoFrame::CreateEOSFrame() { 468 scoped_refptr<VideoFrame> VideoFrame::CreateEOSFrame() {
472 return new VideoFrame(VideoFrame::UNKNOWN, 469 gpu::MailboxHolder mailbox_holders[kMaxPlanes];
473 gfx::Size(), 470 return new VideoFrame(VideoFrame::UNKNOWN, gfx::Size(), gfx::Rect(),
474 gfx::Rect(), 471 gfx::Size(), mailbox_holders, TEXTURE_RGBA,
475 gfx::Size(), 472 kNoTimestamp(), true);
476 scoped_ptr<gpu::MailboxHolder>(),
477 kNoTimestamp(),
478 true);
479 } 473 }
480 474
481 // static 475 // static
482 scoped_refptr<VideoFrame> VideoFrame::CreateColorFrame( 476 scoped_refptr<VideoFrame> VideoFrame::CreateColorFrame(
483 const gfx::Size& size, 477 const gfx::Size& size,
484 uint8 y, uint8 u, uint8 v, 478 uint8 y, uint8 u, uint8 v,
485 base::TimeDelta timestamp) { 479 base::TimeDelta timestamp) {
486 scoped_refptr<VideoFrame> frame = VideoFrame::CreateFrame( 480 scoped_refptr<VideoFrame> frame = VideoFrame::CreateFrame(
487 VideoFrame::YV12, size, gfx::Rect(size), size, timestamp); 481 VideoFrame::YV12, size, gfx::Rect(size), size, timestamp);
488 FillYUV(frame.get(), y, u, v); 482 FillYUV(frame.get(), y, u, v);
(...skipping 26 matching lines...) Expand all
515 // maintained by the general compositor team. Please contact the following 509 // maintained by the general compositor team. Please contact the following
516 // people instead: 510 // people instead:
517 // 511 //
518 // wonsik@chromium.org 512 // wonsik@chromium.org
519 // ycheo@chromium.org 513 // ycheo@chromium.org
520 514
521 // static 515 // static
522 scoped_refptr<VideoFrame> VideoFrame::CreateHoleFrame( 516 scoped_refptr<VideoFrame> VideoFrame::CreateHoleFrame(
523 const gfx::Size& size) { 517 const gfx::Size& size) {
524 DCHECK(IsValidConfig(VideoFrame::HOLE, size, gfx::Rect(size), size)); 518 DCHECK(IsValidConfig(VideoFrame::HOLE, size, gfx::Rect(size), size));
519 gpu::MailboxHolder mailboxes[kMaxPlanes];
525 scoped_refptr<VideoFrame> frame( 520 scoped_refptr<VideoFrame> frame(
526 new VideoFrame(VideoFrame::HOLE, 521 new VideoFrame(VideoFrame::HOLE, size, gfx::Rect(size), size, mailboxes,
527 size, 522 TEXTURE_RGBA, base::TimeDelta(), false));
528 gfx::Rect(size),
529 size,
530 scoped_ptr<gpu::MailboxHolder>(),
531 base::TimeDelta(),
532 false));
533 return frame; 523 return frame;
534 } 524 }
535 #endif // defined(VIDEO_HOLE) 525 #endif // defined(VIDEO_HOLE)
536 526
537 // static 527 // static
538 size_t VideoFrame::NumPlanes(Format format) { 528 size_t VideoFrame::NumPlanes(Format format) {
539 switch (format) { 529 switch (format) {
540 case VideoFrame::NATIVE_TEXTURE: 530 case VideoFrame::NATIVE_TEXTURE:
541 #if defined(VIDEO_HOLE) 531 #if defined(VIDEO_HOLE)
542 case VideoFrame::HOLE: 532 case VideoFrame::HOLE:
(...skipping 12 matching lines...) Expand all
555 return 3; 545 return 3;
556 case VideoFrame::YV12A: 546 case VideoFrame::YV12A:
557 return 4; 547 return 4;
558 case VideoFrame::UNKNOWN: 548 case VideoFrame::UNKNOWN:
559 break; 549 break;
560 } 550 }
561 NOTREACHED() << "Unsupported video frame format: " << format; 551 NOTREACHED() << "Unsupported video frame format: " << format;
562 return 0; 552 return 0;
563 } 553 }
564 554
555 // static
556 size_t VideoFrame::NumTextures(TextureFormat texture_format) {
557 switch (texture_format) {
558 case TEXTURE_RGBA:
559 return 1;
560 case TEXTURE_YUV_420:
561 return 3;
DaleCurtis 2015/05/04 16:12:06 Should be 2 I think. But 1 if you switch to 0,1 sc
Daniele Castagna 2015/05/04 17:59:59 I'm afraid I don't understand what you mean. This
DaleCurtis 2015/05/04 18:12:54 Derp, I though this was converting the enum value.
562 }
563
564 NOTREACHED();
565 return 0;
566 }
565 567
566 // static 568 // static
567 size_t VideoFrame::AllocationSize(Format format, const gfx::Size& coded_size) { 569 size_t VideoFrame::AllocationSize(Format format, const gfx::Size& coded_size) {
568 size_t total = 0; 570 size_t total = 0;
569 for (size_t i = 0; i < NumPlanes(format); ++i) 571 for (size_t i = 0; i < NumPlanes(format); ++i)
570 total += PlaneAllocationSize(format, i, coded_size); 572 total += PlaneAllocationSize(format, i, coded_size);
571 return total; 573 return total;
572 } 574 }
573 575
574 // static 576 // static
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 for (size_t plane = 0; plane < VideoFrame::NumPlanes(format_); ++plane) 659 for (size_t plane = 0; plane < VideoFrame::NumPlanes(format_); ++plane)
658 data_[plane] = data + offset[plane]; 660 data_[plane] = data + offset[plane];
659 661
660 no_longer_needed_cb_ = base::Bind(&ReleaseData, data); 662 no_longer_needed_cb_ = base::Bind(&ReleaseData, data);
661 } 663 }
662 664
663 VideoFrame::VideoFrame(VideoFrame::Format format, 665 VideoFrame::VideoFrame(VideoFrame::Format format,
664 const gfx::Size& coded_size, 666 const gfx::Size& coded_size,
665 const gfx::Rect& visible_rect, 667 const gfx::Rect& visible_rect,
666 const gfx::Size& natural_size, 668 const gfx::Size& natural_size,
667 scoped_ptr<gpu::MailboxHolder> mailbox_holder, 669 const gpu::MailboxHolder(&mailbox_holders)[kMaxPlanes],
670 VideoFrame::TextureFormat texture_format,
668 base::TimeDelta timestamp, 671 base::TimeDelta timestamp,
669 bool end_of_stream) 672 bool end_of_stream)
670 : format_(format), 673 : format_(format),
674 texture_format_(texture_format),
671 coded_size_(coded_size), 675 coded_size_(coded_size),
672 visible_rect_(visible_rect), 676 visible_rect_(visible_rect),
673 natural_size_(natural_size), 677 natural_size_(natural_size),
674 mailbox_holder_(mailbox_holder.Pass()),
675 shared_memory_handle_(base::SharedMemory::NULLHandle()), 678 shared_memory_handle_(base::SharedMemory::NULLHandle()),
676 shared_memory_offset_(0), 679 shared_memory_offset_(0),
677 timestamp_(timestamp), 680 timestamp_(timestamp),
678 release_sync_point_(0), 681 release_sync_point_(0),
679 end_of_stream_(end_of_stream), 682 end_of_stream_(end_of_stream),
680 allow_overlay_(false) { 683 allow_overlay_(false) {
681 DCHECK(IsValidConfig(format_, coded_size_, visible_rect_, natural_size_)); 684 DCHECK(IsValidConfig(format_, coded_size_, visible_rect_, natural_size_));
682 685 memcpy(&mailbox_holders_, mailbox_holders, sizeof(mailbox_holders_));
683 memset(&strides_, 0, sizeof(strides_)); 686 memset(&strides_, 0, sizeof(strides_));
684 memset(&data_, 0, sizeof(data_)); 687 memset(&data_, 0, sizeof(data_));
685 } 688 }
686 689
687 VideoFrame::~VideoFrame() { 690 VideoFrame::~VideoFrame() {
688 if (!mailbox_holder_release_cb_.is_null()) { 691 if (!mailbox_holders_release_cb_.is_null()) {
689 uint32 release_sync_point; 692 uint32 release_sync_point;
690 { 693 {
691 // To ensure that changes to |release_sync_point_| are visible on this 694 // To ensure that changes to |release_sync_point_| are visible on this
692 // thread (imply a memory barrier). 695 // thread (imply a memory barrier).
693 base::AutoLock locker(release_sync_point_lock_); 696 base::AutoLock locker(release_sync_point_lock_);
694 release_sync_point = release_sync_point_; 697 release_sync_point = release_sync_point_;
695 } 698 }
696 base::ResetAndReturn(&mailbox_holder_release_cb_).Run(release_sync_point); 699 base::ResetAndReturn(&mailbox_holders_release_cb_).Run(release_sync_point);
697 } 700 }
698 if (!no_longer_needed_cb_.is_null()) 701 if (!no_longer_needed_cb_.is_null())
699 base::ResetAndReturn(&no_longer_needed_cb_).Run(); 702 base::ResetAndReturn(&no_longer_needed_cb_).Run();
700 } 703 }
701 704
702 // static 705 // static
703 bool VideoFrame::IsValidPlane(size_t plane, VideoFrame::Format format) { 706 bool VideoFrame::IsValidPlane(size_t plane, VideoFrame::Format format) {
704 return (plane < NumPlanes(format)); 707 return (plane < NumPlanes(format));
705 } 708 }
706 709
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 stride(plane) * (offset.y() / subsample.height()) + // Row offset. 767 stride(plane) * (offset.y() / subsample.height()) + // Row offset.
765 BytesPerElement(format_, plane) * // Column offset. 768 BytesPerElement(format_, plane) * // Column offset.
766 (offset.x() / subsample.width()); 769 (offset.x() / subsample.width());
767 } 770 }
768 771
769 uint8* VideoFrame::visible_data(size_t plane) { 772 uint8* VideoFrame::visible_data(size_t plane) {
770 return const_cast<uint8*>( 773 return const_cast<uint8*>(
771 static_cast<const VideoFrame*>(this)->visible_data(plane)); 774 static_cast<const VideoFrame*>(this)->visible_data(plane));
772 } 775 }
773 776
774 const gpu::MailboxHolder* VideoFrame::mailbox_holder() const { 777 const gpu::MailboxHolder& VideoFrame::mailbox_holder(size_t texture) const {
775 DCHECK_EQ(format_, NATIVE_TEXTURE); 778 DCHECK_EQ(format_, NATIVE_TEXTURE);
776 return mailbox_holder_.get(); 779 DCHECK_LT(texture, NumTextures(texture_format_));
780 return mailbox_holders_[texture];
777 } 781 }
778 782
779 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const { 783 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const {
780 return shared_memory_handle_; 784 return shared_memory_handle_;
781 } 785 }
782 786
783 size_t VideoFrame::shared_memory_offset() const { 787 size_t VideoFrame::shared_memory_offset() const {
784 return shared_memory_offset_; 788 return shared_memory_offset_;
785 } 789 }
786 790
787 void VideoFrame::UpdateReleaseSyncPoint(SyncPointClient* client) { 791 void VideoFrame::UpdateReleaseSyncPoint(SyncPointClient* client) {
788 DCHECK_EQ(format_, NATIVE_TEXTURE); 792 DCHECK_EQ(format_, NATIVE_TEXTURE);
789 base::AutoLock locker(release_sync_point_lock_); 793 base::AutoLock locker(release_sync_point_lock_);
790 // Must wait on the previous sync point before inserting a new sync point so 794 // Must wait on the previous sync point before inserting a new sync point so
791 // that |mailbox_holder_release_cb_| guarantees the previous sync point 795 // that |mailbox_holders_release_cb_| guarantees the previous sync point
792 // occurred when it waits on |release_sync_point_|. 796 // occurred when it waits on |release_sync_point_|.
793 if (release_sync_point_) 797 if (release_sync_point_)
794 client->WaitSyncPoint(release_sync_point_); 798 client->WaitSyncPoint(release_sync_point_);
795 release_sync_point_ = client->InsertSyncPoint(); 799 release_sync_point_ = client->InsertSyncPoint();
796 } 800 }
797 801
798 #if defined(OS_POSIX) 802 #if defined(OS_POSIX)
799 int VideoFrame::dmabuf_fd(size_t plane) const { 803 int VideoFrame::dmabuf_fd(size_t plane) const {
800 return dmabuf_fds_[plane].get(); 804 return dmabuf_fds_[plane].get();
801 } 805 }
802 #endif 806 #endif
803 807
804 #if defined(OS_MACOSX) 808 #if defined(OS_MACOSX)
805 CVPixelBufferRef VideoFrame::cv_pixel_buffer() const { 809 CVPixelBufferRef VideoFrame::cv_pixel_buffer() const {
806 return cv_pixel_buffer_.get(); 810 return cv_pixel_buffer_.get();
807 } 811 }
808 #endif 812 #endif
809 813
810 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { 814 void VideoFrame::HashFrameForTesting(base::MD5Context* context) {
811 for (size_t plane = 0; plane < NumPlanes(format_); ++plane) { 815 for (size_t plane = 0; plane < NumPlanes(format_); ++plane) {
812 for (int row = 0; row < rows(plane); ++row) { 816 for (int row = 0; row < rows(plane); ++row) {
813 base::MD5Update(context, base::StringPiece( 817 base::MD5Update(context, base::StringPiece(
814 reinterpret_cast<char*>(data(plane) + stride(plane) * row), 818 reinterpret_cast<char*>(data(plane) + stride(plane) * row),
815 row_bytes(plane))); 819 row_bytes(plane)));
816 } 820 }
817 } 821 }
818 } 822 }
819 823
820 } // namespace media 824 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698