OLD | NEW |
---|---|
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 Loading... | |
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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 case VideoFrame::YV12A: | 240 case VideoFrame::YV12A: |
237 return 4; | 241 return 4; |
238 case VideoFrame::EMPTY: | 242 case VideoFrame::EMPTY: |
239 case VideoFrame::INVALID: | 243 case VideoFrame::INVALID: |
240 break; | 244 break; |
241 } | 245 } |
242 NOTREACHED() << "Unsupported video frame format: " << format; | 246 NOTREACHED() << "Unsupported video frame format: " << format; |
243 return 0; | 247 return 0; |
244 } | 248 } |
245 | 249 |
250 // static | |
251 size_t VideoFrame::AllocationSize(Format format, const gfx::Size& coded_size) { | |
ncarter (slow)
2013/08/15 20:46:59
The behavior of this function does not match the p
sheu
2013/08/15 21:30:48
The problem is that I'm doing a lot of "if format
| |
252 switch (format) { | |
253 case VideoFrame::RGB32: | |
254 return coded_size.GetArea() * 4; | |
255 case VideoFrame::YV12: | |
256 case VideoFrame::I420: | |
257 return coded_size.GetArea() * 3 / 2; | |
258 case VideoFrame::YV16: | |
259 return coded_size.GetArea() * 2; | |
260 case VideoFrame::YV12A: | |
261 return coded_size.GetArea() * 5 / 4; | |
262 case VideoFrame::INVALID: | |
263 case VideoFrame::EMPTY: | |
264 case VideoFrame::NATIVE_TEXTURE: | |
265 #if defined(GOOGLE_TV) | |
266 case VideoFrame::HOLE: | |
267 #endif | |
268 break; | |
269 } | |
270 NOTREACHED() << "Unsupported video frame format: " << format; | |
271 return 0; | |
272 } | |
273 | |
246 static inline size_t RoundUp(size_t value, size_t alignment) { | 274 static inline size_t RoundUp(size_t value, size_t alignment) { |
247 // Check that |alignment| is a power of 2. | 275 // Check that |alignment| is a power of 2. |
248 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1))); | 276 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1))); |
249 return ((value + (alignment - 1)) & ~(alignment-1)); | 277 return ((value + (alignment - 1)) & ~(alignment-1)); |
250 } | 278 } |
251 | 279 |
252 // Release data allocated by AllocateRGB() or AllocateYUV(). | 280 // Release data allocated by AllocateRGB() or AllocateYUV(). |
253 static void ReleaseData(uint8* data) { | 281 static void ReleaseData(uint8* data) { |
254 DCHECK(data); | 282 DCHECK(data); |
255 base::AlignedFree(data); | 283 base::AlignedFree(data); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
452 : mailbox_(mailbox), | 480 : mailbox_(mailbox), |
453 sync_point_(sync_point), | 481 sync_point_(sync_point), |
454 release_callback_(release_callback) {} | 482 release_callback_(release_callback) {} |
455 | 483 |
456 VideoFrame::MailboxHolder::~MailboxHolder() { | 484 VideoFrame::MailboxHolder::~MailboxHolder() { |
457 if (!release_callback_.is_null()) | 485 if (!release_callback_.is_null()) |
458 release_callback_.Run(sync_point_); | 486 release_callback_.Run(sync_point_); |
459 } | 487 } |
460 | 488 |
461 } // namespace media | 489 } // namespace media |
OLD | NEW |