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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/base/video_frame.h" 5 #include "media/base/video_frame.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string_piece.h" 8 #include "base/string_piece.h"
9 #include "media/base/limits.h" 9 #include "media/base/limits.h"
10 #include "media/base/video_util.h" 10 #include "media/base/video_util.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 uint8* data = new uint8[y_bytes + (uv_bytes * 2) + kFramePadBytes]; 126 uint8* data = new uint8[y_bytes + (uv_bytes * 2) + kFramePadBytes];
127 COMPILE_ASSERT(0 == VideoFrame::kYPlane, y_plane_data_must_be_index_0); 127 COMPILE_ASSERT(0 == VideoFrame::kYPlane, y_plane_data_must_be_index_0);
128 data_[VideoFrame::kYPlane] = data; 128 data_[VideoFrame::kYPlane] = data;
129 data_[VideoFrame::kUPlane] = data + y_bytes; 129 data_[VideoFrame::kUPlane] = data + y_bytes;
130 data_[VideoFrame::kVPlane] = data + y_bytes + uv_bytes; 130 data_[VideoFrame::kVPlane] = data + y_bytes + uv_bytes;
131 strides_[VideoFrame::kYPlane] = y_stride; 131 strides_[VideoFrame::kYPlane] = y_stride;
132 strides_[VideoFrame::kUPlane] = uv_stride; 132 strides_[VideoFrame::kUPlane] = uv_stride;
133 strides_[VideoFrame::kVPlane] = uv_stride; 133 strides_[VideoFrame::kVPlane] = uv_stride;
134 } 134 }
135 135
136 extern "C" {
Ami GONE FROM CHROMIUM 2012/05/26 22:52:34 this should not be necessary
137 #include <stdlib.h>
Ami GONE FROM CHROMIUM 2012/05/26 22:52:34 this belongs at the top of the file
138 }
139
140 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!
141 {
142 if (format_ == RGB32) {
143 strides_[VideoFrame::kRGBPlane] = strides[0];
144 uint8_t *data;
Ami GONE FROM CHROMIUM 2012/05/26 22:52:34 unnecessary; just use data_[VideoFrame::kRGBPlane]
145 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
146 return -1;
147 }
148 data_[VideoFrame::kRGBPlane] = data;
149 } 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
150 size_t y_height = aligned_h;
151 DCHECK(aligned_h >= rows(VideoFrame::kYPlane));
152 size_t uv_height = format_ == YV12 ? y_height >> 1 : y_height;
153 size_t y_bytes = y_height * strides[0];
154 size_t uv_bytes = uv_height * strides[1];
155 uint8_t *data;
156
157 if (posix_memalign((void **) &data, 32, y_bytes + (uv_bytes * 2) + kFramePad Bytes)) {
Ami GONE FROM CHROMIUM 2012/05/26 22:52:34 80-col limit, here and elsewhere
158 return -1;
159 }
160
161 data_[VideoFrame::kYPlane] = data;
162 data_[VideoFrame::kUPlane] = data + y_bytes;
163 data_[VideoFrame::kVPlane] = data + y_bytes + uv_bytes;
164 strides_[VideoFrame::kYPlane] = strides[0];
165 strides_[VideoFrame::kUPlane] = strides[1];
166 strides_[VideoFrame::kVPlane] = strides[1];
167 } else {
168 return -1;
169 }
170 is_aligned_alloc_ = 1;
171 return 0;
172 }
173
136 VideoFrame::VideoFrame(VideoFrame::Format format, 174 VideoFrame::VideoFrame(VideoFrame::Format format,
137 size_t width, 175 size_t width,
138 size_t height, 176 size_t height,
139 base::TimeDelta timestamp, 177 base::TimeDelta timestamp,
140 base::TimeDelta duration) 178 base::TimeDelta duration)
141 : format_(format), 179 : format_(format),
142 width_(width), 180 width_(width),
143 height_(height), 181 height_(height),
182 is_aligned_alloc_(0),
144 texture_id_(0), 183 texture_id_(0),
145 texture_target_(0), 184 texture_target_(0),
146 timestamp_(timestamp), 185 timestamp_(timestamp),
147 duration_(duration) { 186 duration_(duration) {
148 memset(&strides_, 0, sizeof(strides_)); 187 memset(&strides_, 0, sizeof(strides_));
149 memset(&data_, 0, sizeof(data_)); 188 memset(&data_, 0, sizeof(data_));
150 } 189 }
151 190
152 VideoFrame::~VideoFrame() { 191 VideoFrame::~VideoFrame() {
153 if (format_ == NATIVE_TEXTURE && !texture_no_longer_needed_.is_null()) { 192 if (format_ == NATIVE_TEXTURE && !texture_no_longer_needed_.is_null()) {
154 texture_no_longer_needed_.Run(); 193 texture_no_longer_needed_.Run();
155 texture_no_longer_needed_.Reset(); 194 texture_no_longer_needed_.Reset();
156 } 195 }
157 196
158 // In multi-plane allocations, only a single block of memory is allocated 197 // In multi-plane allocations, only a single block of memory is allocated
159 // on the heap, and other |data| pointers point inside the same, single block 198 // on the heap, and other |data| pointers point inside the same, single block
160 // so just delete index 0. 199 // so just delete index 0.
161 delete[] data_[0]; 200 if (data_[0]) {
201 if (is_aligned_alloc_) {
202 free(data_[0]);
203 } else {
204 delete[] data_[0];
205 }
206 }
162 } 207 }
163 208
164 bool VideoFrame::IsValidPlane(size_t plane) const { 209 bool VideoFrame::IsValidPlane(size_t plane) const {
165 switch (format_) { 210 switch (format_) {
166 case RGB32: 211 case RGB32:
167 return plane == kRGBPlane; 212 return plane == kRGBPlane;
168 213
169 case YV12: 214 case YV12:
170 case YV16: 215 case YV16:
171 return plane == kYPlane || plane == kUPlane || plane == kVPlane; 216 return plane == kYPlane || plane == kUPlane || plane == kVPlane;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 break; 302 break;
258 for(int row = 0; row < rows(plane); row++) { 303 for(int row = 0; row < rows(plane); row++) {
259 base::MD5Update(context, base::StringPiece( 304 base::MD5Update(context, base::StringPiece(
260 reinterpret_cast<char*>(data(plane) + stride(plane) * row), 305 reinterpret_cast<char*>(data(plane) + stride(plane) * row),
261 row_bytes(plane))); 306 row_bytes(plane)));
262 } 307 }
263 } 308 }
264 } 309 }
265 310
266 } // namespace media 311 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698