Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Unified Diff: media/base/video_frame.cc

Issue 10451051: Provide a Chrome-owned buffer to FFmpeg for video decoding, instead of (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/base/video_frame.cc
===================================================================
--- media/base/video_frame.cc (revision 140753)
+++ media/base/video_frame.cc (working copy)
@@ -8,6 +8,9 @@
#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
namespace media {
@@ -16,18 +19,19 @@
VideoFrame::Format format,
size_t width,
size_t height,
+ size_t alignment,
base::TimeDelta timestamp,
base::TimeDelta duration) {
- DCHECK(IsValidConfig(format, width, height));
+ DCHECK(IsValidConfig(format, width, height, alignment));
scoped_refptr<VideoFrame> frame(new VideoFrame(
format, width, height, timestamp, duration));
switch (format) {
case VideoFrame::RGB32:
- frame->AllocateRGB(4u);
+ frame->AllocateRGB(4u, alignment);
scherkus (not reviewing) 2012/06/14 02:21:33 fix indent here
break;
case VideoFrame::YV12:
case VideoFrame::YV16:
- frame->AllocateYUV();
+ frame->AllocateYUV(alignment);
scherkus (not reviewing) 2012/06/14 02:21:33 fix indent here
break;
default:
LOG(FATAL) << "Unsupported frame format: " << format;
@@ -39,12 +43,13 @@
bool VideoFrame::IsValidConfig(
VideoFrame::Format format,
size_t width,
- size_t height) {
+ size_t height,
+ size_t alignment) {
return (format != VideoFrame::INVALID &&
width > 0 && height > 0 &&
width <= limits::kMaxDimension && height <= limits::kMaxDimension &&
- width * height <= limits::kMaxCanvas);
+ width * height <= limits::kMaxCanvas && alignment > 0);
scherkus (not reviewing) 2012/06/14 02:21:33 shouldn't alignment be checked for power of 2? ch
}
// static
@@ -78,7 +83,8 @@
// Create our frame.
const base::TimeDelta kZero;
scoped_refptr<VideoFrame> frame =
- VideoFrame::CreateFrame(VideoFrame::YV12, width, height, kZero, kZero);
+ VideoFrame::CreateFrame(VideoFrame::YV12, width, height,
scherkus (not reviewing) 2012/06/14 02:21:33 revert change here
+ kZero, kZero);
// Now set the data to YUV(0,128,128).
const uint8 kBlackY = 0x00;
@@ -93,19 +99,31 @@
return ((value + (alignment - 1)) & ~(alignment-1));
}
-void VideoFrame::AllocateRGB(size_t bytes_per_pixel) {
+static inline size_t Max(size_t a, size_t b) {
scherkus (not reviewing) 2012/06/14 02:21:33 use std::max() instead?
+ return a > b ? a : b;
+}
+
+void VideoFrame::AllocateRGB(size_t bytes_per_pixel, size_t alignment) {
// 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);
+ size_t bytes_per_row = RoundUp(width_ * bytes_per_pixel, Max(alignment, 8u));
+ size_t aligned_height = RoundUp(height_, alignment);
strides_[VideoFrame::kRGBPlane] = bytes_per_row;
- data_[VideoFrame::kRGBPlane] = new uint8[bytes_per_row * height_];
+#if !defined(OS_ANDROID)
+ // TODO use DataAligned or so, so this #ifdef hackery doesn't need to be
scherkus (not reviewing) 2012/06/14 02:21:33 s/TODO/TODO(dalecurtis):/
+ // repeated in every single user of aligned data.
+ data_[VideoFrame::kRGBPlane] = reinterpret_cast<uint8 *>(
scherkus (not reviewing) 2012/06/14 02:21:33 pointers go w/ types good: uint8* var bad: uint8
+ av_malloc(bytes_per_row * aligned_height));
scherkus (not reviewing) 2012/06/14 02:21:33 4-space indent
+#else
+ data_[VideoFrame::kRGBPlane] = new uint8_t[bytes_per_row * aligned_height];
+#endif
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() {
+void VideoFrame::AllocateYUV(size_t alignment) {
DCHECK(format_ == VideoFrame::YV12 || format_ == VideoFrame::YV16);
// 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
@@ -116,14 +134,23 @@
// 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.
scherkus (not reviewing) 2012/06/14 02:21:33 comment needs updating to say this does a minimum
- 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_stride = RoundUp(row_bytes(VideoFrame::kYPlane),
+ Max(alignment, 4u));
+ size_t uv_stride = RoundUp(row_bytes(VideoFrame::kUPlane),
+ Max(alignment, 4u));
+ size_t y_height = RoundUp(height_, Max(alignment, 2u));
+ 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;
- uint8* data = new uint8[y_bytes + (uv_bytes * 2) + kFramePadBytes];
+#if !defined(OS_ANDROID)
+ // TODO use DataAligned or so, so this #ifdef hackery doesn't need to be
scherkus (not reviewing) 2012/06/14 02:21:33 ditto
+ // repeated in every single user of aligned data.
+ uint8* data = reinterpret_cast<uint8 *>(
scherkus (not reviewing) 2012/06/14 02:21:33 ditto for pointers
+ av_malloc(y_bytes + (uv_bytes * 2) + kFramePadBytes));
+#else
+ uint8* data = new uint8_t[y_bytes + (uv_bytes * 2) + kFramePadBytes];
+#endif
COMPILE_ASSERT(0 == VideoFrame::kYPlane, y_plane_data_must_be_index_0);
data_[VideoFrame::kYPlane] = data;
data_[VideoFrame::kUPlane] = data + y_bytes;
@@ -158,7 +185,13 @@
// 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.
- delete[] data_[0];
+ if (data_[0]) {
+#if !defined(OS_ANDROID)
+ av_free(data_[0]);
+#else
+ delete[] data_[0];
+#endif
+ }
}
bool VideoFrame::IsValidPlane(size_t plane) const {

Powered by Google App Engine
This is Rietveld 408576698