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

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

Issue 175223003: HW Video: Make media::VideoFrame handle the sync point of the compositor as well as webgl (Closed) Base URL: https://git.chromium.org/chromium/src.git@master
Patch Set: Focus on this CL's goal and remove wrong change Created 6 years, 9 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 const ReadPixelsCB& read_pixels_cb) { 99 const ReadPixelsCB& read_pixels_cb) {
100 scoped_refptr<VideoFrame> frame(new VideoFrame(NATIVE_TEXTURE, 100 scoped_refptr<VideoFrame> frame(new VideoFrame(NATIVE_TEXTURE,
101 coded_size, 101 coded_size,
102 visible_rect, 102 visible_rect,
103 natural_size, 103 natural_size,
104 timestamp, 104 timestamp,
105 false)); 105 false));
106 frame->mailbox_holder_ = mailbox_holder.Pass(); 106 frame->mailbox_holder_ = mailbox_holder.Pass();
107 frame->mailbox_holder_release_cb_ = mailbox_holder_release_cb; 107 frame->mailbox_holder_release_cb_ = mailbox_holder_release_cb;
108 frame->read_pixels_cb_ = read_pixels_cb; 108 frame->read_pixels_cb_ = read_pixels_cb;
109 #ifndef NDEBUG
110 frame->debug_initial_sync_point_ = frame->mailbox_holder_->sync_point;
111 #endif
109 112
110 return frame; 113 return frame;
111 } 114 }
112 115
113 void VideoFrame::ReadPixelsFromNativeTexture(const SkBitmap& pixels) { 116 void VideoFrame::ReadPixelsFromNativeTexture(const SkBitmap& pixels) {
114 DCHECK_EQ(format_, NATIVE_TEXTURE); 117 DCHECK_EQ(format_, NATIVE_TEXTURE);
115 if (!read_pixels_cb_.is_null()) 118 if (!read_pixels_cb_.is_null())
116 read_pixels_cb_.Run(pixels); 119 read_pixels_cb_.Run(pixels);
117 } 120 }
118 121
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 VideoFrame::VideoFrame(VideoFrame::Format format, 402 VideoFrame::VideoFrame(VideoFrame::Format format,
400 const gfx::Size& coded_size, 403 const gfx::Size& coded_size,
401 const gfx::Rect& visible_rect, 404 const gfx::Rect& visible_rect,
402 const gfx::Size& natural_size, 405 const gfx::Size& natural_size,
403 base::TimeDelta timestamp, 406 base::TimeDelta timestamp,
404 bool end_of_stream) 407 bool end_of_stream)
405 : format_(format), 408 : format_(format),
406 coded_size_(coded_size), 409 coded_size_(coded_size),
407 visible_rect_(visible_rect), 410 visible_rect_(visible_rect),
408 natural_size_(natural_size), 411 natural_size_(natural_size),
412 #ifndef NDEBUG
413 debug_initial_sync_point_(0),
414 #endif
409 shared_memory_handle_(base::SharedMemory::NULLHandle()), 415 shared_memory_handle_(base::SharedMemory::NULLHandle()),
410 timestamp_(timestamp), 416 timestamp_(timestamp),
411 end_of_stream_(end_of_stream) { 417 end_of_stream_(end_of_stream) {
412 memset(&strides_, 0, sizeof(strides_)); 418 memset(&strides_, 0, sizeof(strides_));
413 memset(&data_, 0, sizeof(data_)); 419 memset(&data_, 0, sizeof(data_));
414 } 420 }
415 421
416 VideoFrame::~VideoFrame() { 422 VideoFrame::~VideoFrame() {
417 if (!mailbox_holder_release_cb_.is_null()) { 423 if (!mailbox_holder_release_cb_.is_null()) {
418 base::ResetAndReturn(&mailbox_holder_release_cb_) 424 std::vector<uint32> release_sync_points;
419 .Run(mailbox_holder_.Pass()); 425 {
426 base::AutoLock locker(release_sync_point_lock_);
Ami GONE FROM CHROMIUM 2014/04/11 20:55:17 locking in a dtor is a code-smell. If anything ca
dshwang 2014/04/22 19:16:51 I reserve this code as I explained. IMO ensuring t
427 release_sync_points_.swap(release_sync_points);
428 }
429 #ifndef NDEBUG
430 // VideoFrame doesn't use |mailbox_holder_->sync_point| as release sync
431 // point because VideoFrame can have multiple clients. i.e. the compositor,
432 // webgl. So VideoFrame uses |release_sync_points_| unlike webgl.
433 // mailbox_holder_->sync_point must be not changed by clients.
434 DCHECK_EQ(debug_initial_sync_point_, mailbox_holder_->sync_point);
Ami GONE FROM CHROMIUM 2014/04/11 20:55:17 This would be even easier to guarantee if nobody h
dshwang 2014/04/22 19:16:51 That's good idea. I make mailbox_holder const. And
435 for (size_t i = 0; i < release_sync_points.size(); i++)
436 DCHECK_NE(debug_initial_sync_point_, release_sync_points[i]);
Ami GONE FROM CHROMIUM 2014/04/11 20:55:17 What guarantees that wrap-around doesn't hit this?
437 #endif
438 base::ResetAndReturn(&mailbox_holder_release_cb_).Run(release_sync_points);
420 } 439 }
421 if (!no_longer_needed_cb_.is_null()) 440 if (!no_longer_needed_cb_.is_null())
422 base::ResetAndReturn(&no_longer_needed_cb_).Run(); 441 base::ResetAndReturn(&no_longer_needed_cb_).Run();
423 } 442 }
424 443
425 bool VideoFrame::IsValidPlane(size_t plane) const { 444 bool VideoFrame::IsValidPlane(size_t plane) const {
426 return (plane < NumPlanes(format_)); 445 return (plane < NumPlanes(format_));
427 } 446 }
428 447
429 int VideoFrame::stride(size_t plane) const { 448 int VideoFrame::stride(size_t plane) const {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 509
491 gpu::MailboxHolder* VideoFrame::mailbox_holder() const { 510 gpu::MailboxHolder* VideoFrame::mailbox_holder() const {
492 DCHECK_EQ(format_, NATIVE_TEXTURE); 511 DCHECK_EQ(format_, NATIVE_TEXTURE);
493 return mailbox_holder_.get(); 512 return mailbox_holder_.get();
494 } 513 }
495 514
496 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const { 515 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const {
497 return shared_memory_handle_; 516 return shared_memory_handle_;
498 } 517 }
499 518
519 void VideoFrame::AppendReleaseSyncPoint(uint32 sync_point) {
520 DCHECK_EQ(format_, NATIVE_TEXTURE);
521 if (!sync_point)
Ami GONE FROM CHROMIUM 2014/04/11 20:55:17 OOC where does it say that a sync_point of zero me
danakj 2014/04/14 13:19:31 Hm, it's a convention we follow to return 0 when w
dshwang 2014/04/22 19:16:51 Thank you for kind explanation. I agree, so I rese
522 return;
523 base::AutoLock locker(release_sync_point_lock_);
524 release_sync_points_.push_back(sync_point);
525 }
526
500 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { 527 void VideoFrame::HashFrameForTesting(base::MD5Context* context) {
501 for (int plane = 0; plane < kMaxPlanes; ++plane) { 528 for (int plane = 0; plane < kMaxPlanes; ++plane) {
502 if (!IsValidPlane(plane)) 529 if (!IsValidPlane(plane))
503 break; 530 break;
504 for (int row = 0; row < rows(plane); ++row) { 531 for (int row = 0; row < rows(plane); ++row) {
505 base::MD5Update(context, base::StringPiece( 532 base::MD5Update(context, base::StringPiece(
506 reinterpret_cast<char*>(data(plane) + stride(plane) * row), 533 reinterpret_cast<char*>(data(plane) + stride(plane) * row),
507 row_bytes(plane))); 534 row_bytes(plane)));
508 } 535 }
509 } 536 }
510 } 537 }
511 538
512 } // namespace media 539 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698