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

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

Issue 877283004: MediaStreamRemoteVideoSource: Wrap cricket::VideoFrame instead of copying. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Introduce |is_read_only_| to media::VideoFrame Created 5 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
« media/base/video_frame.h ('K') | « media/base/video_frame.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 frame->strides_[kYPlane] = y_stride; 337 frame->strides_[kYPlane] = y_stride;
338 frame->strides_[kUPlane] = u_stride; 338 frame->strides_[kUPlane] = u_stride;
339 frame->strides_[kVPlane] = v_stride; 339 frame->strides_[kVPlane] = v_stride;
340 frame->data_[kYPlane] = y_data; 340 frame->data_[kYPlane] = y_data;
341 frame->data_[kUPlane] = u_data; 341 frame->data_[kUPlane] = u_data;
342 frame->data_[kVPlane] = v_data; 342 frame->data_[kVPlane] = v_data;
343 frame->no_longer_needed_cb_ = no_longer_needed_cb; 343 frame->no_longer_needed_cb_ = no_longer_needed_cb;
344 return frame; 344 return frame;
345 } 345 }
346 346
347 // static
348 scoped_refptr<VideoFrame> VideoFrame::WrapExternalYuvConstData(
349 Format format,
350 const gfx::Size& coded_size,
351 const gfx::Rect& visible_rect,
352 const gfx::Size& natural_size,
353 int32 y_stride,
354 int32 u_stride,
355 int32 v_stride,
356 const uint8* y_data,
357 const uint8* u_data,
358 const uint8* v_data,
359 base::TimeDelta timestamp,
360 const base::Closure& no_longer_needed_cb) {
361 // Const cast is ok because the pointers will be protected by |is_read_only_|.
362 scoped_refptr<VideoFrame> frame = WrapExternalYuvData(
363 format, coded_size, visible_rect, natural_size, y_stride, u_stride,
364 v_stride, const_cast<uint8*>(y_data), const_cast<uint8*>(u_data),
365 const_cast<uint8*>(v_data), timestamp, no_longer_needed_cb);
366 frame->is_read_only_ = true;
367 return frame;
368 }
369
347 #if defined(OS_POSIX) 370 #if defined(OS_POSIX)
348 // static 371 // static
349 scoped_refptr<VideoFrame> VideoFrame::WrapExternalDmabufs( 372 scoped_refptr<VideoFrame> VideoFrame::WrapExternalDmabufs(
350 Format format, 373 Format format,
351 const gfx::Size& coded_size, 374 const gfx::Size& coded_size,
352 const gfx::Rect& visible_rect, 375 const gfx::Rect& visible_rect,
353 const gfx::Size& natural_size, 376 const gfx::Size& natural_size,
354 const std::vector<int> dmabuf_fds, 377 const std::vector<int> dmabuf_fds,
355 base::TimeDelta timestamp, 378 base::TimeDelta timestamp,
356 const base::Closure& no_longer_needed_cb) { 379 const base::Closure& no_longer_needed_cb) {
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 const gfx::Size& coded_size, 687 const gfx::Size& coded_size,
665 const gfx::Rect& visible_rect, 688 const gfx::Rect& visible_rect,
666 const gfx::Size& natural_size, 689 const gfx::Size& natural_size,
667 scoped_ptr<gpu::MailboxHolder> mailbox_holder, 690 scoped_ptr<gpu::MailboxHolder> mailbox_holder,
668 base::TimeDelta timestamp, 691 base::TimeDelta timestamp,
669 bool end_of_stream) 692 bool end_of_stream)
670 : format_(format), 693 : format_(format),
671 coded_size_(coded_size), 694 coded_size_(coded_size),
672 visible_rect_(visible_rect), 695 visible_rect_(visible_rect),
673 natural_size_(natural_size), 696 natural_size_(natural_size),
697 is_read_only_(false),
674 mailbox_holder_(mailbox_holder.Pass()), 698 mailbox_holder_(mailbox_holder.Pass()),
675 shared_memory_handle_(base::SharedMemory::NULLHandle()), 699 shared_memory_handle_(base::SharedMemory::NULLHandle()),
676 shared_memory_offset_(0), 700 shared_memory_offset_(0),
677 timestamp_(timestamp), 701 timestamp_(timestamp),
678 release_sync_point_(0), 702 release_sync_point_(0),
679 end_of_stream_(end_of_stream), 703 end_of_stream_(end_of_stream),
680 allow_overlay_(false) { 704 allow_overlay_(false) {
681 DCHECK(IsValidConfig(format_, coded_size_, visible_rect_, natural_size_)); 705 DCHECK(IsValidConfig(format_, coded_size_, visible_rect_, natural_size_));
682 706
683 memset(&strides_, 0, sizeof(strides_)); 707 memset(&strides_, 0, sizeof(strides_));
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 return Rows(plane, format_, coded_size_.height()); 763 return Rows(plane, format_, coded_size_.height());
740 } 764 }
741 765
742 const uint8* VideoFrame::data(size_t plane) const { 766 const uint8* VideoFrame::data(size_t plane) const {
743 DCHECK(IsValidPlane(plane, format_)); 767 DCHECK(IsValidPlane(plane, format_));
744 return data_[plane]; 768 return data_[plane];
745 } 769 }
746 770
747 uint8* VideoFrame::data(size_t plane) { 771 uint8* VideoFrame::data(size_t plane) {
748 DCHECK(IsValidPlane(plane, format_)); 772 DCHECK(IsValidPlane(plane, format_));
773 DCHECK(!is_read_only_);
749 return data_[plane]; 774 return data_[plane];
750 } 775 }
751 776
752 const uint8* VideoFrame::visible_data(size_t plane) const { 777 const uint8* VideoFrame::visible_data(size_t plane) const {
753 DCHECK(IsValidPlane(plane, format_)); 778 DCHECK(IsValidPlane(plane, format_));
754 779
755 // Calculate an offset that is properly aligned for all planes. 780 // Calculate an offset that is properly aligned for all planes.
756 const gfx::Size alignment = CommonAlignment(format_); 781 const gfx::Size alignment = CommonAlignment(format_);
757 const gfx::Point offset(RoundDown(visible_rect_.x(), alignment.width()), 782 const gfx::Point offset(RoundDown(visible_rect_.x(), alignment.width()),
758 RoundDown(visible_rect_.y(), alignment.height())); 783 RoundDown(visible_rect_.y(), alignment.height()));
759 784
760 const gfx::Size subsample = SampleSize(format_, plane); 785 const gfx::Size subsample = SampleSize(format_, plane);
761 DCHECK(offset.x() % subsample.width() == 0); 786 DCHECK(offset.x() % subsample.width() == 0);
762 DCHECK(offset.y() % subsample.height() == 0); 787 DCHECK(offset.y() % subsample.height() == 0);
763 return data(plane) + 788 return data(plane) +
764 stride(plane) * (offset.y() / subsample.height()) + // Row offset. 789 stride(plane) * (offset.y() / subsample.height()) + // Row offset.
765 BytesPerElement(format_, plane) * // Column offset. 790 BytesPerElement(format_, plane) * // Column offset.
766 (offset.x() / subsample.width()); 791 (offset.x() / subsample.width());
767 } 792 }
768 793
769 uint8* VideoFrame::visible_data(size_t plane) { 794 uint8* VideoFrame::visible_data(size_t plane) {
795 DCHECK(!is_read_only_);
770 return const_cast<uint8*>( 796 return const_cast<uint8*>(
771 static_cast<const VideoFrame*>(this)->visible_data(plane)); 797 static_cast<const VideoFrame*>(this)->visible_data(plane));
772 } 798 }
773 799
774 const gpu::MailboxHolder* VideoFrame::mailbox_holder() const { 800 const gpu::MailboxHolder* VideoFrame::mailbox_holder() const {
775 DCHECK_EQ(format_, NATIVE_TEXTURE); 801 DCHECK_EQ(format_, NATIVE_TEXTURE);
776 return mailbox_holder_.get(); 802 return mailbox_holder_.get();
777 } 803 }
778 804
779 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const { 805 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 for (size_t plane = 0; plane < NumPlanes(format_); ++plane) { 837 for (size_t plane = 0; plane < NumPlanes(format_); ++plane) {
812 for (int row = 0; row < rows(plane); ++row) { 838 for (int row = 0; row < rows(plane); ++row) {
813 base::MD5Update(context, base::StringPiece( 839 base::MD5Update(context, base::StringPiece(
814 reinterpret_cast<char*>(data(plane) + stride(plane) * row), 840 reinterpret_cast<char*>(data(plane) + stride(plane) * row),
815 row_bytes(plane))); 841 row_bytes(plane)));
816 } 842 }
817 } 843 }
818 } 844 }
819 845
820 } // namespace media 846 } // namespace media
OLDNEW
« media/base/video_frame.h ('K') | « media/base/video_frame.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698