Chromium Code Reviews| 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)) | |
|
Cris Neckar
2013/08/23 22:25:44
Allocation size will overflow for large values whi
sheu
2013/08/26 21:07:07
I did the check at a higher level now. Do we need
Ami GONE FROM CHROMIUM
2013/08/26 22:00:23
Are you referring to IsValidConfig()? Because tha
sheu
2013/08/27 22:05:56
I'm doing the DCHECKS when values for this are bei
Ami GONE FROM CHROMIUM
2013/08/27 23:57:08
I think the point is that the danger from maliciou
sheu
2013/08/28 00:03:59
Whoops, I meant to say that it's being checked at
| |
| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 size_t VideoFrame::NumPlanes(Format format) { | 227 size_t VideoFrame::NumPlanes(Format format) { |
| 224 switch (format) { | 228 switch (format) { |
| 225 case VideoFrame::NATIVE_TEXTURE: | 229 case VideoFrame::NATIVE_TEXTURE: |
| 226 #if defined(GOOGLE_TV) | 230 #if defined(GOOGLE_TV) |
| 227 case VideoFrame::HOLE: | 231 case VideoFrame::HOLE: |
| 228 #endif | 232 #endif |
| 229 return 0; | 233 return 0; |
| 230 case VideoFrame::RGB32: | 234 case VideoFrame::RGB32: |
| 231 return 1; | 235 return 1; |
| 232 case VideoFrame::YV12: | 236 case VideoFrame::YV12: |
| 237 case VideoFrame::I420: | |
|
Ami GONE FROM CHROMIUM
2013/08/26 22:00:23
Why this reorder, which puts separates two similar
sheu
2013/08/27 22:05:56
I did this to match the order in AllocationSize()
| |
| 233 case VideoFrame::YV16: | 238 case VideoFrame::YV16: |
| 234 case VideoFrame::I420: | |
| 235 return 3; | 239 return 3; |
| 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) { | |
| 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::YV12A: | |
| 259 return coded_size.GetArea() * 5 / 2; | |
|
Ami GONE FROM CHROMIUM
2013/08/26 22:00:23
For this and l.257 above, is it necessary to check
sheu
2013/08/27 22:05:56
Done.
| |
| 260 case VideoFrame::YV16: | |
| 261 return coded_size.GetArea() * 2; | |
| 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 |