| OLD | NEW |
| 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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 | 279 |
| 280 // static | 280 // static |
| 281 scoped_refptr<VideoFrame> VideoFrame::WrapExternalPackedMemory( | 281 scoped_refptr<VideoFrame> VideoFrame::WrapExternalPackedMemory( |
| 282 Format format, | 282 Format format, |
| 283 const gfx::Size& coded_size, | 283 const gfx::Size& coded_size, |
| 284 const gfx::Rect& visible_rect, | 284 const gfx::Rect& visible_rect, |
| 285 const gfx::Size& natural_size, | 285 const gfx::Size& natural_size, |
| 286 uint8* data, | 286 uint8* data, |
| 287 size_t data_size, | 287 size_t data_size, |
| 288 base::SharedMemoryHandle handle, | 288 base::SharedMemoryHandle handle, |
| 289 size_t data_offset, |
| 289 base::TimeDelta timestamp, | 290 base::TimeDelta timestamp, |
| 290 const base::Closure& no_longer_needed_cb) { | 291 const base::Closure& no_longer_needed_cb) { |
| 291 const gfx::Size new_coded_size = AdjustCodedSize(format, coded_size); | 292 const gfx::Size new_coded_size = AdjustCodedSize(format, coded_size); |
| 292 | 293 |
| 293 if (!IsValidConfig(format, new_coded_size, visible_rect, natural_size)) | 294 if (!IsValidConfig(format, new_coded_size, visible_rect, natural_size)) |
| 294 return NULL; | 295 return NULL; |
| 295 if (data_size < AllocationSize(format, new_coded_size)) | 296 if (data_size < AllocationSize(format, new_coded_size)) |
| 296 return NULL; | 297 return NULL; |
| 297 | 298 |
| 298 switch (format) { | 299 switch (format) { |
| 299 case VideoFrame::I420: { | 300 case VideoFrame::I420: { |
| 300 scoped_refptr<VideoFrame> frame( | 301 scoped_refptr<VideoFrame> frame( |
| 301 new VideoFrame(format, | 302 new VideoFrame(format, |
| 302 new_coded_size, | 303 new_coded_size, |
| 303 visible_rect, | 304 visible_rect, |
| 304 natural_size, | 305 natural_size, |
| 305 scoped_ptr<gpu::MailboxHolder>(), | 306 scoped_ptr<gpu::MailboxHolder>(), |
| 306 timestamp, | 307 timestamp, |
| 307 false)); | 308 false)); |
| 308 frame->shared_memory_handle_ = handle; | 309 frame->shared_memory_handle_ = handle; |
| 310 frame->shared_memory_offset_ = data_offset; |
| 309 frame->strides_[kYPlane] = new_coded_size.width(); | 311 frame->strides_[kYPlane] = new_coded_size.width(); |
| 310 frame->strides_[kUPlane] = new_coded_size.width() / 2; | 312 frame->strides_[kUPlane] = new_coded_size.width() / 2; |
| 311 frame->strides_[kVPlane] = new_coded_size.width() / 2; | 313 frame->strides_[kVPlane] = new_coded_size.width() / 2; |
| 312 frame->data_[kYPlane] = data; | 314 frame->data_[kYPlane] = data; |
| 313 frame->data_[kUPlane] = data + new_coded_size.GetArea(); | 315 frame->data_[kUPlane] = data + new_coded_size.GetArea(); |
| 314 frame->data_[kVPlane] = data + (new_coded_size.GetArea() * 5 / 4); | 316 frame->data_[kVPlane] = data + (new_coded_size.GetArea() * 5 / 4); |
| 315 frame->no_longer_needed_cb_ = no_longer_needed_cb; | 317 frame->no_longer_needed_cb_ = no_longer_needed_cb; |
| 316 return frame; | 318 return frame; |
| 317 } | 319 } |
| 318 default: | 320 default: |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 const gfx::Size& natural_size, | 680 const gfx::Size& natural_size, |
| 679 scoped_ptr<gpu::MailboxHolder> mailbox_holder, | 681 scoped_ptr<gpu::MailboxHolder> mailbox_holder, |
| 680 base::TimeDelta timestamp, | 682 base::TimeDelta timestamp, |
| 681 bool end_of_stream) | 683 bool end_of_stream) |
| 682 : format_(format), | 684 : format_(format), |
| 683 coded_size_(coded_size), | 685 coded_size_(coded_size), |
| 684 visible_rect_(visible_rect), | 686 visible_rect_(visible_rect), |
| 685 natural_size_(natural_size), | 687 natural_size_(natural_size), |
| 686 mailbox_holder_(mailbox_holder.Pass()), | 688 mailbox_holder_(mailbox_holder.Pass()), |
| 687 shared_memory_handle_(base::SharedMemory::NULLHandle()), | 689 shared_memory_handle_(base::SharedMemory::NULLHandle()), |
| 690 shared_memory_offset_(0), |
| 688 timestamp_(timestamp), | 691 timestamp_(timestamp), |
| 689 release_sync_point_(0), | 692 release_sync_point_(0), |
| 690 end_of_stream_(end_of_stream), | 693 end_of_stream_(end_of_stream), |
| 691 allow_overlay_(false) { | 694 allow_overlay_(false) { |
| 692 DCHECK(IsValidConfig(format_, coded_size_, visible_rect_, natural_size_)); | 695 DCHECK(IsValidConfig(format_, coded_size_, visible_rect_, natural_size_)); |
| 693 | 696 |
| 694 memset(&strides_, 0, sizeof(strides_)); | 697 memset(&strides_, 0, sizeof(strides_)); |
| 695 memset(&data_, 0, sizeof(data_)); | 698 memset(&data_, 0, sizeof(data_)); |
| 696 } | 699 } |
| 697 | 700 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 | 787 |
| 785 const gpu::MailboxHolder* VideoFrame::mailbox_holder() const { | 788 const gpu::MailboxHolder* VideoFrame::mailbox_holder() const { |
| 786 DCHECK_EQ(format_, NATIVE_TEXTURE); | 789 DCHECK_EQ(format_, NATIVE_TEXTURE); |
| 787 return mailbox_holder_.get(); | 790 return mailbox_holder_.get(); |
| 788 } | 791 } |
| 789 | 792 |
| 790 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const { | 793 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const { |
| 791 return shared_memory_handle_; | 794 return shared_memory_handle_; |
| 792 } | 795 } |
| 793 | 796 |
| 797 size_t VideoFrame::shared_memory_offset() const { |
| 798 return shared_memory_offset_; |
| 799 } |
| 800 |
| 794 void VideoFrame::UpdateReleaseSyncPoint(SyncPointClient* client) { | 801 void VideoFrame::UpdateReleaseSyncPoint(SyncPointClient* client) { |
| 795 DCHECK_EQ(format_, NATIVE_TEXTURE); | 802 DCHECK_EQ(format_, NATIVE_TEXTURE); |
| 796 base::AutoLock locker(release_sync_point_lock_); | 803 base::AutoLock locker(release_sync_point_lock_); |
| 797 // Must wait on the previous sync point before inserting a new sync point so | 804 // Must wait on the previous sync point before inserting a new sync point so |
| 798 // that |mailbox_holder_release_cb_| guarantees the previous sync point | 805 // that |mailbox_holder_release_cb_| guarantees the previous sync point |
| 799 // occurred when it waits on |release_sync_point_|. | 806 // occurred when it waits on |release_sync_point_|. |
| 800 if (release_sync_point_) | 807 if (release_sync_point_) |
| 801 client->WaitSyncPoint(release_sync_point_); | 808 client->WaitSyncPoint(release_sync_point_); |
| 802 release_sync_point_ = client->InsertSyncPoint(); | 809 release_sync_point_ = client->InsertSyncPoint(); |
| 803 } | 810 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 818 for (size_t plane = 0; plane < NumPlanes(format_); ++plane) { | 825 for (size_t plane = 0; plane < NumPlanes(format_); ++plane) { |
| 819 for (int row = 0; row < rows(plane); ++row) { | 826 for (int row = 0; row < rows(plane); ++row) { |
| 820 base::MD5Update(context, base::StringPiece( | 827 base::MD5Update(context, base::StringPiece( |
| 821 reinterpret_cast<char*>(data(plane) + stride(plane) * row), | 828 reinterpret_cast<char*>(data(plane) + stride(plane) * row), |
| 822 row_bytes(plane))); | 829 row_bytes(plane))); |
| 823 } | 830 } |
| 824 } | 831 } |
| 825 } | 832 } |
| 826 | 833 |
| 827 } // namespace media | 834 } // namespace media |
| OLD | NEW |