Index: media/base/video_frame.cc |
diff --git a/media/base/video_frame.cc b/media/base/video_frame.cc |
index 6303f09baf4dafcf12ed57e99aa93920c9820fef..3d764103f1965397fd1fff8c26d24f63df827609 100644 |
--- a/media/base/video_frame.cc |
+++ b/media/base/video_frame.cc |
@@ -19,12 +19,13 @@ namespace media { |
// static |
scoped_refptr<VideoFrame> VideoFrame::CreateFrame( |
VideoFrame::Format format, |
- const gfx::Size& data_size, |
+ const gfx::Size& coded_size, |
+ const gfx::Rect& visible_rect, |
const gfx::Size& natural_size, |
base::TimeDelta timestamp) { |
- DCHECK(IsValidConfig(format, data_size, natural_size)); |
+ DCHECK(IsValidConfig(format, coded_size, visible_rect, natural_size)); |
scoped_refptr<VideoFrame> frame(new VideoFrame( |
- format, data_size, natural_size, timestamp)); |
+ format, coded_size, visible_rect, natural_size, timestamp)); |
switch (format) { |
case VideoFrame::RGB32: |
frame->AllocateRGB(4u); |
@@ -41,30 +42,37 @@ scoped_refptr<VideoFrame> VideoFrame::CreateFrame( |
// static |
bool VideoFrame::IsValidConfig(VideoFrame::Format format, |
- const gfx::Size& data_size, |
+ const gfx::Size& coded_size, |
+ const gfx::Rect& visible_rect, |
const gfx::Size& natural_size) { |
return (format != VideoFrame::INVALID && |
- data_size.width() > 0 && data_size.height() > 0 && |
- data_size.width() <= limits::kMaxDimension && |
- data_size.height() <= limits::kMaxDimension && |
- data_size.width() * data_size.height() <= limits::kMaxCanvas && |
- natural_size.width() > 0 && natural_size.height() > 0 && |
+ !coded_size.IsEmpty() && |
+ coded_size.GetArea() <= limits::kMaxCanvas && |
+ coded_size.width() <= limits::kMaxDimension && |
+ coded_size.height() <= limits::kMaxDimension && |
+ !visible_rect.IsEmpty() && |
+ visible_rect.x() >= 0 && visible_rect.y() >= 0 && |
+ visible_rect.right() <= coded_size.width() && |
+ visible_rect.bottom() <= coded_size.height() && |
+ !natural_size.IsEmpty() && |
+ natural_size.GetArea() <= limits::kMaxCanvas && |
natural_size.width() <= limits::kMaxDimension && |
- natural_size.height() <= limits::kMaxDimension && |
- natural_size.width() * natural_size.height() <= limits::kMaxCanvas); |
+ natural_size.height() <= limits::kMaxDimension); |
} |
// static |
scoped_refptr<VideoFrame> VideoFrame::WrapNativeTexture( |
uint32 texture_id, |
uint32 texture_target, |
- const gfx::Size& data_size, |
+ const gfx::Size& coded_size, |
+ const gfx::Rect& visible_rect, |
const gfx::Size& natural_size, |
base::TimeDelta timestamp, |
const ReadPixelsCB& read_pixels_cb, |
const base::Closure& no_longer_needed) { |
scoped_refptr<VideoFrame> frame( |
- new VideoFrame(NATIVE_TEXTURE, data_size, natural_size, timestamp)); |
+ new VideoFrame(NATIVE_TEXTURE, coded_size, visible_rect, natural_size, |
+ timestamp)); |
frame->texture_id_ = texture_id; |
frame->texture_target_ = texture_target; |
frame->read_pixels_cb_ = read_pixels_cb; |
@@ -81,7 +89,8 @@ void VideoFrame::ReadPixelsFromNativeTexture(void* pixels) { |
// static |
scoped_refptr<VideoFrame> VideoFrame::CreateEmptyFrame() { |
return new VideoFrame( |
- VideoFrame::EMPTY, gfx::Size(), gfx::Size(), base::TimeDelta()); |
+ VideoFrame::EMPTY, gfx::Size(), gfx::Rect(), gfx::Size(), |
+ base::TimeDelta()); |
} |
// static |
@@ -89,9 +98,9 @@ scoped_refptr<VideoFrame> VideoFrame::CreateColorFrame( |
const gfx::Size& size, |
uint8 y, uint8 u, uint8 v, |
base::TimeDelta timestamp) { |
- DCHECK(IsValidConfig(VideoFrame::YV12, size, size)); |
+ DCHECK(IsValidConfig(VideoFrame::YV12, size, gfx::Rect(size), size)); |
scoped_refptr<VideoFrame> frame = VideoFrame::CreateFrame( |
- VideoFrame::YV12, size, size, timestamp); |
+ VideoFrame::YV12, size, gfx::Rect(size), size, timestamp); |
FillYUV(frame, y, u, v); |
return frame; |
} |
@@ -117,9 +126,9 @@ static const int kFramePadBytes = 15; |
void VideoFrame::AllocateRGB(size_t bytes_per_pixel) { |
// Round up to align at least at a 16-byte boundary for each row. |
// This is sufficient for MMX and SSE2 reads (movq/movdqa). |
- size_t bytes_per_row = RoundUp(data_size_.width(), |
+ size_t bytes_per_row = RoundUp(coded_size_.width(), |
kFrameSizeAlignment) * bytes_per_pixel; |
- size_t aligned_height = RoundUp(data_size_.height(), kFrameSizeAlignment); |
+ size_t aligned_height = RoundUp(coded_size_.height(), kFrameSizeAlignment); |
strides_[VideoFrame::kRGBPlane] = bytes_per_row; |
#if !defined(OS_ANDROID) |
// TODO(dalecurtis): use DataAligned or so, so this #ifdef hackery |
@@ -151,7 +160,7 @@ void VideoFrame::AllocateYUV() { |
// The *2 here is because some formats (e.g. h264) allow interlaced coding, |
// and then the size needs to be a multiple of two macroblocks (vertically). |
// See libavcodec/utils.c:avcodec_align_dimensions2(). |
- size_t y_height = RoundUp(data_size_.height(), kFrameSizeAlignment * 2); |
+ size_t y_height = RoundUp(coded_size_.height(), kFrameSizeAlignment * 2); |
size_t uv_height = format_ == VideoFrame::YV12 ? y_height / 2 : y_height; |
size_t y_bytes = y_height * y_stride; |
size_t uv_bytes = uv_height * uv_stride; |
@@ -178,11 +187,13 @@ void VideoFrame::AllocateYUV() { |
} |
VideoFrame::VideoFrame(VideoFrame::Format format, |
- const gfx::Size& data_size, |
+ const gfx::Size& coded_size, |
+ const gfx::Rect& visible_rect, |
const gfx::Size& natural_size, |
base::TimeDelta timestamp) |
: format_(format), |
- data_size_(data_size), |
+ coded_size_(coded_size), |
+ visible_rect_(visible_rect), |
natural_size_(natural_size), |
texture_id_(0), |
texture_target_(0), |
@@ -238,7 +249,7 @@ int VideoFrame::stride(size_t plane) const { |
int VideoFrame::row_bytes(size_t plane) const { |
DCHECK(IsValidPlane(plane)); |
- int width = data_size_.width(); |
+ int width = coded_size_.width(); |
switch (format_) { |
// 32bpp. |
case RGB32: |
@@ -262,7 +273,7 @@ int VideoFrame::row_bytes(size_t plane) const { |
int VideoFrame::rows(size_t plane) const { |
DCHECK(IsValidPlane(plane)); |
- int height = data_size_.height(); |
+ int height = coded_size_.height(); |
switch (format_) { |
case RGB32: |
case YV16: |