| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 visible_rect.right() <= coded_size.width() && | 56 visible_rect.right() <= coded_size.width() && |
| 57 visible_rect.bottom() <= coded_size.height() && | 57 visible_rect.bottom() <= coded_size.height() && |
| 58 !natural_size.IsEmpty() && | 58 !natural_size.IsEmpty() && |
| 59 natural_size.GetArea() <= limits::kMaxCanvas && | 59 natural_size.GetArea() <= limits::kMaxCanvas && |
| 60 natural_size.width() <= limits::kMaxDimension && | 60 natural_size.width() <= limits::kMaxDimension && |
| 61 natural_size.height() <= limits::kMaxDimension); | 61 natural_size.height() <= limits::kMaxDimension); |
| 62 } | 62 } |
| 63 | 63 |
| 64 // static | 64 // static |
| 65 scoped_refptr<VideoFrame> VideoFrame::WrapNativeTexture( | 65 scoped_refptr<VideoFrame> VideoFrame::WrapNativeTexture( |
| 66 uint32 texture_id, | 66 const gpu::Mailbox& texture_mailbox, |
| 67 uint32 texture_target, | 67 uint32 texture_target, |
| 68 const gfx::Size& coded_size, | 68 const gfx::Size& coded_size, |
| 69 const gfx::Rect& visible_rect, | 69 const gfx::Rect& visible_rect, |
| 70 const gfx::Size& natural_size, | 70 const gfx::Size& natural_size, |
| 71 base::TimeDelta timestamp, | 71 base::TimeDelta timestamp, |
| 72 const ReadPixelsCB& read_pixels_cb, | 72 const ReadPixelsCB& read_pixels_cb, |
| 73 const base::Closure& no_longer_needed_cb) { | 73 const base::Closure& no_longer_needed_cb) { |
| 74 scoped_refptr<VideoFrame> frame(new VideoFrame( | 74 scoped_refptr<VideoFrame> frame(new VideoFrame( |
| 75 NATIVE_TEXTURE, coded_size, visible_rect, natural_size, timestamp)); | 75 NATIVE_TEXTURE, coded_size, visible_rect, natural_size, timestamp)); |
| 76 frame->texture_id_ = texture_id; | 76 frame->texture_mailbox_ = texture_mailbox; |
| 77 frame->texture_target_ = texture_target; | 77 frame->texture_target_ = texture_target; |
| 78 frame->read_pixels_cb_ = read_pixels_cb; | 78 frame->read_pixels_cb_ = read_pixels_cb; |
| 79 frame->no_longer_needed_cb_ = no_longer_needed_cb; | 79 frame->no_longer_needed_cb_ = no_longer_needed_cb; |
| 80 return frame; | 80 return frame; |
| 81 } | 81 } |
| 82 | 82 |
| 83 void VideoFrame::ReadPixelsFromNativeTexture(const SkBitmap& pixels) { | 83 void VideoFrame::ReadPixelsFromNativeTexture(const SkBitmap& pixels) { |
| 84 DCHECK_EQ(format_, NATIVE_TEXTURE); | 84 DCHECK_EQ(format_, NATIVE_TEXTURE); |
| 85 if (!read_pixels_cb_.is_null()) | 85 if (!read_pixels_cb_.is_null()) |
| 86 read_pixels_cb_.Run(pixels); | 86 read_pixels_cb_.Run(pixels); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 | 246 |
| 247 VideoFrame::VideoFrame(VideoFrame::Format format, | 247 VideoFrame::VideoFrame(VideoFrame::Format format, |
| 248 const gfx::Size& coded_size, | 248 const gfx::Size& coded_size, |
| 249 const gfx::Rect& visible_rect, | 249 const gfx::Rect& visible_rect, |
| 250 const gfx::Size& natural_size, | 250 const gfx::Size& natural_size, |
| 251 base::TimeDelta timestamp) | 251 base::TimeDelta timestamp) |
| 252 : format_(format), | 252 : format_(format), |
| 253 coded_size_(coded_size), | 253 coded_size_(coded_size), |
| 254 visible_rect_(visible_rect), | 254 visible_rect_(visible_rect), |
| 255 natural_size_(natural_size), | 255 natural_size_(natural_size), |
| 256 texture_id_(0), | |
| 257 texture_target_(0), | 256 texture_target_(0), |
| 258 timestamp_(timestamp) { | 257 timestamp_(timestamp) { |
| 259 memset(&strides_, 0, sizeof(strides_)); | 258 memset(&strides_, 0, sizeof(strides_)); |
| 260 memset(&data_, 0, sizeof(data_)); | 259 memset(&data_, 0, sizeof(data_)); |
| 261 } | 260 } |
| 262 | 261 |
| 263 VideoFrame::~VideoFrame() { | 262 VideoFrame::~VideoFrame() { |
| 264 if (!no_longer_needed_cb_.is_null()) | 263 if (!no_longer_needed_cb_.is_null()) |
| 265 base::ResetAndReturn(&no_longer_needed_cb_).Run(); | 264 base::ResetAndReturn(&no_longer_needed_cb_).Run(); |
| 266 } | 265 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 // Intentionally leave out non-production formats. | 317 // Intentionally leave out non-production formats. |
| 319 NOTREACHED() << "Unsupported video frame format: " << format_; | 318 NOTREACHED() << "Unsupported video frame format: " << format_; |
| 320 return 0; | 319 return 0; |
| 321 } | 320 } |
| 322 | 321 |
| 323 uint8* VideoFrame::data(size_t plane) const { | 322 uint8* VideoFrame::data(size_t plane) const { |
| 324 DCHECK(IsValidPlane(plane)); | 323 DCHECK(IsValidPlane(plane)); |
| 325 return data_[plane]; | 324 return data_[plane]; |
| 326 } | 325 } |
| 327 | 326 |
| 328 uint32 VideoFrame::texture_id() const { | 327 const gpu::Mailbox& VideoFrame::texture_mailbox() const { |
| 329 DCHECK_EQ(format_, NATIVE_TEXTURE); | 328 DCHECK_EQ(format_, NATIVE_TEXTURE); |
| 330 return texture_id_; | 329 return texture_mailbox_; |
| 331 } | 330 } |
| 332 | 331 |
| 333 uint32 VideoFrame::texture_target() const { | 332 uint32 VideoFrame::texture_target() const { |
| 334 DCHECK_EQ(format_, NATIVE_TEXTURE); | 333 DCHECK_EQ(format_, NATIVE_TEXTURE); |
| 335 return texture_target_; | 334 return texture_target_; |
| 336 } | 335 } |
| 337 | 336 |
| 338 bool VideoFrame::IsEndOfStream() const { | 337 bool VideoFrame::IsEndOfStream() const { |
| 339 return format_ == VideoFrame::EMPTY; | 338 return format_ == VideoFrame::EMPTY; |
| 340 } | 339 } |
| 341 | 340 |
| 342 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { | 341 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { |
| 343 for (int plane = 0; plane < kMaxPlanes; ++plane) { | 342 for (int plane = 0; plane < kMaxPlanes; ++plane) { |
| 344 if (!IsValidPlane(plane)) | 343 if (!IsValidPlane(plane)) |
| 345 break; | 344 break; |
| 346 for (int row = 0; row < rows(plane); ++row) { | 345 for (int row = 0; row < rows(plane); ++row) { |
| 347 base::MD5Update(context, base::StringPiece( | 346 base::MD5Update(context, base::StringPiece( |
| 348 reinterpret_cast<char*>(data(plane) + stride(plane) * row), | 347 reinterpret_cast<char*>(data(plane) + stride(plane) * row), |
| 349 row_bytes(plane))); | 348 row_bytes(plane))); |
| 350 } | 349 } |
| 351 } | 350 } |
| 352 } | 351 } |
| 353 | 352 |
| 354 } // namespace media | 353 } // namespace media |
| OLD | NEW |