diff options
author | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-20 02:21:38 +0000 |
---|---|---|
committer | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-20 02:21:38 +0000 |
commit | ad5d305c448bf079c32270005f6fef095f8b05b4 (patch) | |
tree | 8b8ff5eecc8ab4dcc3a805cda8182da3fa07522c /media/base | |
parent | da29bbd928e83d96b2bfd5f1955f410b962a3fd9 (diff) | |
download | chromium_src-ad5d305c448bf079c32270005f6fef095f8b05b4.zip chromium_src-ad5d305c448bf079c32270005f6fef095f8b05b4.tar.gz chromium_src-ad5d305c448bf079c32270005f6fef095f8b05b4.tar.bz2 |
Revert 143115 - Provide a Chrome-owned buffer to FFmpeg for video decoding, instead of
letting it allocate a buffer internally and then copy it to our own
buffers after decoding finishes. This saves one memcpy() per decoded
video frame.
+++ REVERT NOTICE +++
Broke all pyauto tests:
http://build.chromium.org/p/chromium.pyauto/builders/Linux%20%28deb%29/builds/34569
+++ +++
Review URL: https://chromiumcodereview.appspot.com/10451051
TBR=rbultje@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10592012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@143125 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base')
-rw-r--r-- | media/base/video_frame.cc | 70 | ||||
-rw-r--r-- | media/base/video_frame.h | 1 |
2 files changed, 21 insertions, 50 deletions
diff --git a/media/base/video_frame.cc b/media/base/video_frame.cc index 565290b..f8cdcf9 100644 --- a/media/base/video_frame.cc +++ b/media/base/video_frame.cc @@ -8,11 +8,6 @@ #include "base/string_piece.h" #include "media/base/limits.h" #include "media/base/video_util.h" -#if !defined(OS_ANDROID) -#include "media/ffmpeg/ffmpeg_common.h" -#endif - -#include <algorithm> namespace media { @@ -98,54 +93,37 @@ static inline size_t RoundUp(size_t value, size_t alignment) { return ((value + (alignment - 1)) & ~(alignment-1)); } -static const int kFrameSizeAlignment = 16; - 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(width_, kFrameSizeAlignment) * bytes_per_pixel; - size_t aligned_height = RoundUp(height_, kFrameSizeAlignment); + // Round up to align at a 64-bit (8 byte) boundary for each row. This + // is sufficient for MMX reads (movq). + size_t bytes_per_row = RoundUp(width_ * bytes_per_pixel, 8); strides_[VideoFrame::kRGBPlane] = bytes_per_row; -#if !defined(OS_ANDROID) - // TODO(dalecurtis): use DataAligned or so, so this #ifdef hackery - // doesn't need to be repeated in every single user of aligned data. - data_[VideoFrame::kRGBPlane] = reinterpret_cast<uint8*>( - av_malloc(bytes_per_row * aligned_height)); -#else - data_[VideoFrame::kRGBPlane] = new uint8_t[bytes_per_row * aligned_height]; -#endif + data_[VideoFrame::kRGBPlane] = new uint8[bytes_per_row * height_]; DCHECK(!(reinterpret_cast<intptr_t>(data_[VideoFrame::kRGBPlane]) & 7)); COMPILE_ASSERT(0 == VideoFrame::kRGBPlane, RGB_data_must_be_index_0); } +static const int kFramePadBytes = 15; // Allows faster SIMD YUV convert. + void VideoFrame::AllocateYUV() { DCHECK(format_ == VideoFrame::YV12 || format_ == VideoFrame::YV16); - // Align Y rows at least at 16 byte boundaries. The stride for both - // YV12 and YV16 is 1/2 of the stride of Y. For YV12, every row of bytes for - // U and V applies to two rows of Y (one byte of UV for 4 bytes of Y), so in - // the case of YV12 the strides are identical for the same width surface, but - // the number of bytes allocated for YV12 is 1/2 the amount for U & V as - // YV16. We also round the height of the surface allocated to be an even - // number to avoid any potential of faulting by code that attempts to access - // the Y values of the final row, but assumes that the last row of U & V - // applies to a full two rows of Y. - size_t y_stride = RoundUp(row_bytes(VideoFrame::kYPlane), - kFrameSizeAlignment); - size_t uv_stride = RoundUp(row_bytes(VideoFrame::kUPlane), - kFrameSizeAlignment); - size_t y_height = RoundUp(height_, kFrameSizeAlignment); - size_t uv_height = format_ == VideoFrame::YV12 ? y_height / 2 : y_height; + // Align Y rows at 32-bit (4 byte) boundaries. The stride for both YV12 and + // YV16 is 1/2 of the stride of Y. For YV12, every row of bytes for U and V + // applies to two rows of Y (one byte of UV for 4 bytes of Y), so in the + // case of YV12 the strides are identical for the same width surface, but the + // number of bytes allocated for YV12 is 1/2 the amount for U & V as YV16. + // We also round the height of the surface allocated to be an even number + // to avoid any potential of faulting by code that attempts to access the Y + // values of the final row, but assumes that the last row of U & V applies to + // a full two rows of Y. + size_t y_height = rows(VideoFrame::kYPlane); + size_t y_stride = RoundUp(row_bytes(VideoFrame::kYPlane), 4); + size_t uv_stride = RoundUp(row_bytes(VideoFrame::kUPlane), 4); + size_t uv_height = rows(VideoFrame::kUPlane); size_t y_bytes = y_height * y_stride; size_t uv_bytes = uv_height * uv_stride; -#if !defined(OS_ANDROID) - // TODO(dalecurtis): use DataAligned or so, so this #ifdef hackery - // doesn't need to be repeated in every single user of aligned data. - uint8* data = reinterpret_cast<uint8*>( - av_malloc(y_bytes + (uv_bytes * 2))); -#else - uint8* data = new uint8_t[y_bytes + (uv_bytes * 2)]; -#endif + uint8* data = new uint8[y_bytes + (uv_bytes * 2) + kFramePadBytes]; COMPILE_ASSERT(0 == VideoFrame::kYPlane, y_plane_data_must_be_index_0); data_[VideoFrame::kYPlane] = data; data_[VideoFrame::kUPlane] = data + y_bytes; @@ -180,13 +158,7 @@ VideoFrame::~VideoFrame() { // In multi-plane allocations, only a single block of memory is allocated // on the heap, and other |data| pointers point inside the same, single block // so just delete index 0. - if (data_[0]) { -#if !defined(OS_ANDROID) - av_free(data_[0]); -#else - delete[] data_[0]; -#endif - } + delete[] data_[0]; } bool VideoFrame::IsValidPlane(size_t plane) const { diff --git a/media/base/video_frame.h b/media/base/video_frame.h index 55d4cd5..42b627a 100644 --- a/media/base/video_frame.h +++ b/media/base/video_frame.h @@ -48,7 +48,6 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { // Call prior to CreateFrame to ensure validity of frame configuration. Called // automatically by VideoDecoderConfig::IsValidConfig(). - // TODO(scherkus): VideoDecoderConfig shouldn't call this method static bool IsValidConfig( Format format, size_t width, |