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

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, 7 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 139175)
+++ media/base/video_frame.cc (working copy)
@@ -133,6 +133,44 @@
strides_[VideoFrame::kVPlane] = uv_stride;
}
+extern "C" {
Ami GONE FROM CHROMIUM 2012/05/26 22:52:34 this should not be necessary
+#include <stdlib.h>
Ami GONE FROM CHROMIUM 2012/05/26 22:52:34 this belongs at the top of the file
+}
+
+int VideoFrame::AllocateAlignedWithStrides(int strides[], int aligned_h)
Ami GONE FROM CHROMIUM 2012/05/26 22:52:34 Welcome to C++! We've got bools!
+{
+ if (format_ == RGB32) {
+ strides_[VideoFrame::kRGBPlane] = strides[0];
+ uint8_t *data;
Ami GONE FROM CHROMIUM 2012/05/26 22:52:34 unnecessary; just use data_[VideoFrame::kRGBPlane]
+ if (posix_memalign((void **) &data, 32, strides[0] * aligned_h)) {
Ami GONE FROM CHROMIUM 2012/05/26 22:52:34 32 is magic here and elsewhere. Name-constant (en
Ami GONE FROM CHROMIUM 2012/05/26 22:52:34 Does this even compile on windows?
DaleCurtis 2012/05/29 17:33:19 I don't think this works on other platforms; for r
+ return -1;
+ }
+ data_[VideoFrame::kRGBPlane] = data;
+ } else if (format_ == VideoFrame::YV12 || format_ == VideoFrame::YV16) {
Ami GONE FROM CHROMIUM 2012/05/26 22:52:34 Other than the memalign's this function is a dup o
+ size_t y_height = aligned_h;
+ DCHECK(aligned_h >= rows(VideoFrame::kYPlane));
+ size_t uv_height = format_ == YV12 ? y_height >> 1 : y_height;
+ size_t y_bytes = y_height * strides[0];
+ size_t uv_bytes = uv_height * strides[1];
+ uint8_t *data;
+
+ if (posix_memalign((void **) &data, 32, y_bytes + (uv_bytes * 2) + kFramePadBytes)) {
Ami GONE FROM CHROMIUM 2012/05/26 22:52:34 80-col limit, here and elsewhere
+ return -1;
+ }
+
+ data_[VideoFrame::kYPlane] = data;
+ data_[VideoFrame::kUPlane] = data + y_bytes;
+ data_[VideoFrame::kVPlane] = data + y_bytes + uv_bytes;
+ strides_[VideoFrame::kYPlane] = strides[0];
+ strides_[VideoFrame::kUPlane] = strides[1];
+ strides_[VideoFrame::kVPlane] = strides[1];
+ } else {
+ return -1;
+ }
+ is_aligned_alloc_ = 1;
+ return 0;
+}
+
VideoFrame::VideoFrame(VideoFrame::Format format,
size_t width,
size_t height,
@@ -141,6 +179,7 @@
: format_(format),
width_(width),
height_(height),
+ is_aligned_alloc_(0),
texture_id_(0),
texture_target_(0),
timestamp_(timestamp),
@@ -158,7 +197,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 (is_aligned_alloc_) {
+ free(data_[0]);
+ } else {
+ delete[] data_[0];
+ }
+ }
}
bool VideoFrame::IsValidPlane(size_t plane) const {

Powered by Google App Engine
This is Rietveld 408576698