diff options
author | Torne (Richard Coles) <torne@google.com> | 2013-11-28 11:55:43 +0000 |
---|---|---|
committer | Torne (Richard Coles) <torne@google.com> | 2013-11-28 11:55:43 +0000 |
commit | f2477e01787aa58f445919b809d89e252beef54f (patch) | |
tree | 2db962b4af39f0db3a5f83b314373d0530c484b8 /media/base/video_frame.cc | |
parent | 7daea1dd5ff7e419322de831b642d81af3247912 (diff) | |
download | chromium_org-f2477e01787aa58f445919b809d89e252beef54f.tar.gz |
Merge from Chromium at DEPS revision 237746
This commit was generated by merge_to_master.py.
Change-Id: I8997af4cddfeb09a7c26f7e8e672c712cab461ea
Diffstat (limited to 'media/base/video_frame.cc')
-rw-r--r-- | media/base/video_frame.cc | 130 |
1 files changed, 69 insertions, 61 deletions
diff --git a/media/base/video_frame.cc b/media/base/video_frame.cc index 9c07251e59..3541e6efa4 100644 --- a/media/base/video_frame.cc +++ b/media/base/video_frame.cc @@ -26,11 +26,8 @@ scoped_refptr<VideoFrame> VideoFrame::CreateFrame( base::TimeDelta timestamp) { DCHECK(IsValidConfig(format, coded_size, visible_rect, natural_size)); scoped_refptr<VideoFrame> frame(new VideoFrame( - format, coded_size, visible_rect, natural_size, timestamp)); + format, coded_size, visible_rect, natural_size, timestamp, false)); switch (format) { - case VideoFrame::RGB32: - frame->AllocateRGB(4u); - break; case VideoFrame::YV12: case VideoFrame::YV12A: case VideoFrame::YV16: @@ -48,14 +45,10 @@ std::string VideoFrame::FormatToString(VideoFrame::Format format) { switch (format) { case VideoFrame::UNKNOWN: return "UNKNOWN"; - case VideoFrame::RGB32: - return "RGB32"; case VideoFrame::YV12: return "YV12"; case VideoFrame::YV16: return "YV16"; - case VideoFrame::EMPTY: - return "EMPTY"; case VideoFrame::I420: return "I420"; case VideoFrame::NATIVE_TEXTURE: @@ -66,6 +59,8 @@ std::string VideoFrame::FormatToString(VideoFrame::Format format) { #endif case VideoFrame::YV12A: return "YV12A"; + case VideoFrame::HISTOGRAM_MAX: + return "HISTOGRAM_MAX"; } NOTREACHED() << "Invalid videoframe format provided: " << format; return ""; @@ -101,8 +96,12 @@ scoped_refptr<VideoFrame> VideoFrame::WrapNativeTexture( base::TimeDelta timestamp, const ReadPixelsCB& read_pixels_cb, const base::Closure& no_longer_needed_cb) { - scoped_refptr<VideoFrame> frame(new VideoFrame( - NATIVE_TEXTURE, coded_size, visible_rect, natural_size, timestamp)); + scoped_refptr<VideoFrame> frame(new VideoFrame(NATIVE_TEXTURE, + coded_size, + visible_rect, + natural_size, + timestamp, + false)); frame->texture_mailbox_holder_ = mailbox_holder; frame->texture_target_ = texture_target; frame->read_pixels_cb_ = read_pixels_cb; @@ -118,7 +117,7 @@ void VideoFrame::ReadPixelsFromNativeTexture(const SkBitmap& pixels) { } // static -scoped_refptr<VideoFrame> VideoFrame::WrapExternalSharedMemory( +scoped_refptr<VideoFrame> VideoFrame::WrapExternalPackedMemory( Format format, const gfx::Size& coded_size, const gfx::Rect& visible_rect, @@ -134,7 +133,7 @@ scoped_refptr<VideoFrame> VideoFrame::WrapExternalSharedMemory( switch (format) { case I420: { scoped_refptr<VideoFrame> frame(new VideoFrame( - format, coded_size, visible_rect, natural_size, timestamp)); + format, coded_size, visible_rect, natural_size, timestamp, false)); frame->shared_memory_handle_ = handle; frame->strides_[kYPlane] = coded_size.width(); frame->strides_[kUPlane] = coded_size.width() / 2; @@ -167,7 +166,7 @@ scoped_refptr<VideoFrame> VideoFrame::WrapExternalYuvData( const base::Closure& no_longer_needed_cb) { DCHECK(format == YV12 || format == YV16 || format == I420) << format; scoped_refptr<VideoFrame> frame(new VideoFrame( - format, coded_size, visible_rect, natural_size, timestamp)); + format, coded_size, visible_rect, natural_size, timestamp, false)); frame->strides_[kYPlane] = y_stride; frame->strides_[kUPlane] = u_stride; frame->strides_[kVPlane] = v_stride; @@ -179,10 +178,13 @@ scoped_refptr<VideoFrame> VideoFrame::WrapExternalYuvData( } // static -scoped_refptr<VideoFrame> VideoFrame::CreateEmptyFrame() { - return new VideoFrame( - VideoFrame::EMPTY, gfx::Size(), gfx::Rect(), gfx::Size(), - base::TimeDelta()); +scoped_refptr<VideoFrame> VideoFrame::CreateEOSFrame() { + return new VideoFrame(VideoFrame::UNKNOWN, + gfx::Size(), + gfx::Rect(), + gfx::Size(), + kNoTimestamp(), + true); } // static @@ -218,7 +220,7 @@ scoped_refptr<VideoFrame> VideoFrame::CreateHoleFrame( const gfx::Size& size) { DCHECK(IsValidConfig(VideoFrame::HOLE, size, gfx::Rect(size), size)); scoped_refptr<VideoFrame> frame(new VideoFrame( - VideoFrame::HOLE, size, gfx::Rect(size), size, base::TimeDelta())); + VideoFrame::HOLE, size, gfx::Rect(size), size, base::TimeDelta(), false)); return frame; } #endif @@ -231,16 +233,14 @@ size_t VideoFrame::NumPlanes(Format format) { case VideoFrame::HOLE: #endif return 0; - case VideoFrame::RGB32: - return 1; case VideoFrame::YV12: case VideoFrame::YV16: case VideoFrame::I420: return 3; case VideoFrame::YV12A: return 4; - case VideoFrame::EMPTY: case VideoFrame::UNKNOWN: + case VideoFrame::HISTOGRAM_MAX: break; } NOTREACHED() << "Unsupported video frame format: " << format; @@ -255,58 +255,73 @@ static inline size_t RoundUp(size_t value, size_t alignment) { // static size_t VideoFrame::AllocationSize(Format format, const gfx::Size& coded_size) { + size_t total = 0; + for (size_t i = 0; i < NumPlanes(format); ++i) + total += PlaneAllocationSize(format, i, coded_size); + return total; +} + +// static +size_t VideoFrame::PlaneAllocationSize(Format format, + size_t plane, + const gfx::Size& coded_size) { + const size_t area = + RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2); switch (format) { - case VideoFrame::RGB32: - return coded_size.GetArea() * 4; case VideoFrame::YV12: case VideoFrame::I420: { - const size_t rounded_size = - RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2); - return rounded_size * 3 / 2; + switch (plane) { + case VideoFrame::kYPlane: + return area; + case VideoFrame::kUPlane: + case VideoFrame::kVPlane: + return area / 4; + default: + break; + } } case VideoFrame::YV12A: { - const size_t rounded_size = - RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2); - return rounded_size * 5 / 2; + switch (plane) { + case VideoFrame::kYPlane: + case VideoFrame::kAPlane: + return area; + case VideoFrame::kUPlane: + case VideoFrame::kVPlane: + return area / 4; + default: + break; + } } case VideoFrame::YV16: { - const size_t rounded_size = - RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2); - return rounded_size * 2; + switch (plane) { + case VideoFrame::kYPlane: + return area; + case VideoFrame::kUPlane: + case VideoFrame::kVPlane: + return area / 2; + default: + break; + } } case VideoFrame::UNKNOWN: - case VideoFrame::EMPTY: case VideoFrame::NATIVE_TEXTURE: + case VideoFrame::HISTOGRAM_MAX: #if defined(GOOGLE_TV) case VideoFrame::HOLE: #endif break; } - NOTREACHED() << "Unsupported video frame format: " << format; + NOTREACHED() << "Unsupported video frame format/plane: " + << format << "/" << plane; return 0; } -// Release data allocated by AllocateRGB() or AllocateYUV(). +// Release data allocated by AllocateYUV(). static void ReleaseData(uint8* data) { DCHECK(data); base::AlignedFree(data); } -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(coded_size_.width(), - kFrameSizeAlignment) * bytes_per_pixel; - size_t aligned_height = RoundUp(coded_size_.height(), kFrameSizeAlignment); - strides_[VideoFrame::kRGBPlane] = bytes_per_row; - data_[VideoFrame::kRGBPlane] = reinterpret_cast<uint8*>( - base::AlignedAlloc(bytes_per_row * aligned_height + kFrameSizePadding, - kFrameAddressAlignment)); - no_longer_needed_cb_ = base::Bind(&ReleaseData, data_[VideoFrame::kRGBPlane]); - DCHECK(!(reinterpret_cast<intptr_t>(data_[VideoFrame::kRGBPlane]) & 7)); - COMPILE_ASSERT(0 == VideoFrame::kRGBPlane, RGB_data_must_be_index_0); -} - void VideoFrame::AllocateYUV() { DCHECK(format_ == VideoFrame::YV12 || format_ == VideoFrame::YV16 || format_ == VideoFrame::YV12A || format_ == VideoFrame::I420); @@ -364,14 +379,16 @@ VideoFrame::VideoFrame(VideoFrame::Format format, const gfx::Size& coded_size, const gfx::Rect& visible_rect, const gfx::Size& natural_size, - base::TimeDelta timestamp) + base::TimeDelta timestamp, + bool end_of_stream) : format_(format), coded_size_(coded_size), visible_rect_(visible_rect), natural_size_(natural_size), texture_target_(0), shared_memory_handle_(base::SharedMemory::NULLHandle()), - timestamp_(timestamp) { + timestamp_(timestamp), + end_of_stream_(end_of_stream) { memset(&strides_, 0, sizeof(strides_)); memset(&data_, 0, sizeof(data_)); } @@ -394,10 +411,6 @@ int VideoFrame::row_bytes(size_t plane) const { DCHECK(IsValidPlane(plane)); int width = coded_size_.width(); switch (format_) { - // 32bpp. - case RGB32: - return width * 4; - // Planar, 8bpp. case YV12A: if (plane == kAPlane) @@ -423,7 +436,6 @@ int VideoFrame::rows(size_t plane) const { DCHECK(IsValidPlane(plane)); int height = coded_size_.height(); switch (format_) { - case RGB32: case YV16: return height; @@ -466,10 +478,6 @@ base::SharedMemoryHandle VideoFrame::shared_memory_handle() const { return shared_memory_handle_; } -bool VideoFrame::IsEndOfStream() const { - return format_ == VideoFrame::EMPTY; -} - void VideoFrame::HashFrameForTesting(base::MD5Context* context) { for (int plane = 0; plane < kMaxPlanes; ++plane) { if (!IsValidPlane(plane)) |