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

Side by Side Diff: media/base/video_frame.cc

Issue 22875047: EVEA cleanup: use video utility functions in media::* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@git-svn
Patch Set: b2b1b2ee Last comments. Created 7 years, 3 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
« no previous file with comments | « media/base/video_frame.h ('k') | media/video/capture/fake_video_capture_device.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 read_pixels_cb_.Run(pixels); 117 read_pixels_cb_.Run(pixels);
118 } 118 }
119 119
120 // static 120 // static
121 scoped_refptr<VideoFrame> VideoFrame::WrapExternalSharedMemory( 121 scoped_refptr<VideoFrame> VideoFrame::WrapExternalSharedMemory(
122 Format format, 122 Format format,
123 const gfx::Size& coded_size, 123 const gfx::Size& coded_size,
124 const gfx::Rect& visible_rect, 124 const gfx::Rect& visible_rect,
125 const gfx::Size& natural_size, 125 const gfx::Size& natural_size,
126 uint8* data, 126 uint8* data,
127 size_t data_size,
127 base::SharedMemoryHandle handle, 128 base::SharedMemoryHandle handle,
128 base::TimeDelta timestamp, 129 base::TimeDelta timestamp,
129 const base::Closure& no_longer_needed_cb) { 130 const base::Closure& no_longer_needed_cb) {
131 if (data_size < AllocationSize(format, coded_size))
132 return NULL;
133
130 switch (format) { 134 switch (format) {
131 case I420: { 135 case I420: {
132 scoped_refptr<VideoFrame> frame(new VideoFrame( 136 scoped_refptr<VideoFrame> frame(new VideoFrame(
133 format, coded_size, visible_rect, natural_size, timestamp)); 137 format, coded_size, visible_rect, natural_size, timestamp));
134 frame->shared_memory_handle_ = handle; 138 frame->shared_memory_handle_ = handle;
135 frame->strides_[kYPlane] = coded_size.width(); 139 frame->strides_[kYPlane] = coded_size.width();
136 frame->strides_[kUPlane] = coded_size.width() / 2; 140 frame->strides_[kUPlane] = coded_size.width() / 2;
137 frame->strides_[kVPlane] = coded_size.width() / 2; 141 frame->strides_[kVPlane] = coded_size.width() / 2;
138 frame->data_[kYPlane] = data; 142 frame->data_[kYPlane] = data;
139 frame->data_[kUPlane] = data + coded_size.GetArea(); 143 frame->data_[kUPlane] = data + coded_size.GetArea();
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 NOTREACHED() << "Unsupported video frame format: " << format; 246 NOTREACHED() << "Unsupported video frame format: " << format;
243 return 0; 247 return 0;
244 } 248 }
245 249
246 static inline size_t RoundUp(size_t value, size_t alignment) { 250 static inline size_t RoundUp(size_t value, size_t alignment) {
247 // Check that |alignment| is a power of 2. 251 // Check that |alignment| is a power of 2.
248 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1))); 252 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1)));
249 return ((value + (alignment - 1)) & ~(alignment-1)); 253 return ((value + (alignment - 1)) & ~(alignment-1));
250 } 254 }
251 255
256 // static
257 size_t VideoFrame::AllocationSize(Format format, const gfx::Size& coded_size) {
258 switch (format) {
259 case VideoFrame::RGB32:
260 return coded_size.GetArea() * 4;
261 case VideoFrame::YV12:
262 case VideoFrame::I420: {
263 const size_t rounded_size =
264 RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2);
265 return rounded_size * 3 / 2;
266 }
267 case VideoFrame::YV12A: {
268 const size_t rounded_size =
269 RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2);
270 return rounded_size * 5 / 2;
271 }
272 case VideoFrame::YV16: {
273 const size_t rounded_size =
274 RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2);
275 return rounded_size * 2;
276 }
277 case VideoFrame::INVALID:
278 case VideoFrame::EMPTY:
279 case VideoFrame::NATIVE_TEXTURE:
280 #if defined(GOOGLE_TV)
281 case VideoFrame::HOLE:
282 #endif
283 break;
284 }
285 NOTREACHED() << "Unsupported video frame format: " << format;
286 return 0;
287 }
288
252 // Release data allocated by AllocateRGB() or AllocateYUV(). 289 // Release data allocated by AllocateRGB() or AllocateYUV().
253 static void ReleaseData(uint8* data) { 290 static void ReleaseData(uint8* data) {
254 DCHECK(data); 291 DCHECK(data);
255 base::AlignedFree(data); 292 base::AlignedFree(data);
256 } 293 }
257 294
258 void VideoFrame::AllocateRGB(size_t bytes_per_pixel) { 295 void VideoFrame::AllocateRGB(size_t bytes_per_pixel) {
259 // Round up to align at least at a 16-byte boundary for each row. 296 // Round up to align at least at a 16-byte boundary for each row.
260 // This is sufficient for MMX and SSE2 reads (movq/movdqa). 297 // This is sufficient for MMX and SSE2 reads (movq/movdqa).
261 size_t bytes_per_row = RoundUp(coded_size_.width(), 298 size_t bytes_per_row = RoundUp(coded_size_.width(),
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 : mailbox_(mailbox), 489 : mailbox_(mailbox),
453 sync_point_(sync_point), 490 sync_point_(sync_point),
454 release_callback_(release_callback) {} 491 release_callback_(release_callback) {}
455 492
456 VideoFrame::MailboxHolder::~MailboxHolder() { 493 VideoFrame::MailboxHolder::~MailboxHolder() {
457 if (!release_callback_.is_null()) 494 if (!release_callback_.is_null())
458 release_callback_.Run(sync_point_); 495 release_callback_.Run(sync_point_);
459 } 496 }
460 497
461 } // namespace media 498 } // namespace media
OLDNEW
« no previous file with comments | « media/base/video_frame.h ('k') | media/video/capture/fake_video_capture_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698