| 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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/aligned_memory.h" | 12 #include "base/memory/aligned_memory.h" |
| 13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
| 14 #include "gpu/command_buffer/common/mailbox_holder.h" | 14 #include "gpu/command_buffer/common/mailbox_holder.h" |
| 15 #include "media/base/limits.h" | 15 #include "media/base/limits.h" |
| 16 #include "media/base/video_util.h" | 16 #include "media/base/video_util.h" |
| 17 #include "ui/gfx/geometry/point.h" | 17 #include "ui/gfx/geometry/point.h" |
| 18 | 18 |
| 19 #if !defined(MEDIA_FOR_CAST_IOS) | |
| 20 #include "third_party/skia/include/core/SkBitmap.h" | |
| 21 #endif | |
| 22 | |
| 23 namespace media { | 19 namespace media { |
| 24 | 20 |
| 25 static bool IsPowerOfTwo(size_t x) { | 21 static bool IsPowerOfTwo(size_t x) { |
| 26 return x != 0 && (x & (x - 1)) == 0; | 22 return x != 0 && (x & (x - 1)) == 0; |
| 27 } | 23 } |
| 28 | 24 |
| 29 static inline size_t RoundUp(size_t value, size_t alignment) { | 25 static inline size_t RoundUp(size_t value, size_t alignment) { |
| 30 DCHECK(IsPowerOfTwo(alignment)); | 26 DCHECK(IsPowerOfTwo(alignment)); |
| 31 return ((value + (alignment - 1)) & ~(alignment - 1)); | 27 return ((value + (alignment - 1)) & ~(alignment - 1)); |
| 32 } | 28 } |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 return false; | 236 return false; |
| 241 } | 237 } |
| 242 | 238 |
| 243 // static | 239 // static |
| 244 scoped_refptr<VideoFrame> VideoFrame::WrapNativeTexture( | 240 scoped_refptr<VideoFrame> VideoFrame::WrapNativeTexture( |
| 245 scoped_ptr<gpu::MailboxHolder> mailbox_holder, | 241 scoped_ptr<gpu::MailboxHolder> mailbox_holder, |
| 246 const ReleaseMailboxCB& mailbox_holder_release_cb, | 242 const ReleaseMailboxCB& mailbox_holder_release_cb, |
| 247 const gfx::Size& coded_size, | 243 const gfx::Size& coded_size, |
| 248 const gfx::Rect& visible_rect, | 244 const gfx::Rect& visible_rect, |
| 249 const gfx::Size& natural_size, | 245 const gfx::Size& natural_size, |
| 250 base::TimeDelta timestamp, | 246 base::TimeDelta timestamp) { |
| 251 const ReadPixelsCB& read_pixels_cb) { | |
| 252 scoped_refptr<VideoFrame> frame(new VideoFrame(NATIVE_TEXTURE, | 247 scoped_refptr<VideoFrame> frame(new VideoFrame(NATIVE_TEXTURE, |
| 253 coded_size, | 248 coded_size, |
| 254 visible_rect, | 249 visible_rect, |
| 255 natural_size, | 250 natural_size, |
| 256 mailbox_holder.Pass(), | 251 mailbox_holder.Pass(), |
| 257 timestamp, | 252 timestamp, |
| 258 false)); | 253 false)); |
| 259 frame->mailbox_holder_release_cb_ = mailbox_holder_release_cb; | 254 frame->mailbox_holder_release_cb_ = mailbox_holder_release_cb; |
| 260 frame->read_pixels_cb_ = read_pixels_cb; | |
| 261 | 255 |
| 262 return frame; | 256 return frame; |
| 263 } | 257 } |
| 264 | 258 |
| 265 #if !defined(MEDIA_FOR_CAST_IOS) | |
| 266 void VideoFrame::ReadPixelsFromNativeTexture(const SkBitmap& pixels) { | |
| 267 DCHECK_EQ(format_, NATIVE_TEXTURE); | |
| 268 if (!read_pixels_cb_.is_null()) | |
| 269 read_pixels_cb_.Run(pixels); | |
| 270 } | |
| 271 #endif | |
| 272 | |
| 273 // static | 259 // static |
| 274 scoped_refptr<VideoFrame> VideoFrame::WrapExternalPackedMemory( | 260 scoped_refptr<VideoFrame> VideoFrame::WrapExternalPackedMemory( |
| 275 Format format, | 261 Format format, |
| 276 const gfx::Size& coded_size, | 262 const gfx::Size& coded_size, |
| 277 const gfx::Rect& visible_rect, | 263 const gfx::Rect& visible_rect, |
| 278 const gfx::Size& natural_size, | 264 const gfx::Size& natural_size, |
| 279 uint8* data, | 265 uint8* data, |
| 280 size_t data_size, | 266 size_t data_size, |
| 281 base::SharedMemoryHandle handle, | 267 base::SharedMemoryHandle handle, |
| 282 base::TimeDelta timestamp, | 268 base::TimeDelta timestamp, |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 for (size_t plane = 0; plane < NumPlanes(format_); ++plane) { | 794 for (size_t plane = 0; plane < NumPlanes(format_); ++plane) { |
| 809 for (int row = 0; row < rows(plane); ++row) { | 795 for (int row = 0; row < rows(plane); ++row) { |
| 810 base::MD5Update(context, base::StringPiece( | 796 base::MD5Update(context, base::StringPiece( |
| 811 reinterpret_cast<char*>(data(plane) + stride(plane) * row), | 797 reinterpret_cast<char*>(data(plane) + stride(plane) * row), |
| 812 row_bytes(plane))); | 798 row_bytes(plane))); |
| 813 } | 799 } |
| 814 } | 800 } |
| 815 } | 801 } |
| 816 | 802 |
| 817 } // namespace media | 803 } // namespace media |
| OLD | NEW |