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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 return frame; | 111 return frame; |
112 } | 112 } |
113 | 113 |
114 void VideoFrame::ReadPixelsFromNativeTexture(const SkBitmap& pixels) { | 114 void VideoFrame::ReadPixelsFromNativeTexture(const SkBitmap& pixels) { |
115 DCHECK_EQ(format_, NATIVE_TEXTURE); | 115 DCHECK_EQ(format_, NATIVE_TEXTURE); |
116 if (!read_pixels_cb_.is_null()) | 116 if (!read_pixels_cb_.is_null()) |
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::WrapExternalPackedMemory( |
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 size_t data_size, |
128 base::SharedMemoryHandle handle, | 128 base::SharedMemoryHandle handle, |
129 base::TimeDelta timestamp, | 129 base::TimeDelta timestamp, |
130 const base::Closure& no_longer_needed_cb) { | 130 const base::Closure& no_longer_needed_cb) { |
131 if (data_size < AllocationSize(format, coded_size)) | 131 if (data_size < AllocationSize(format, coded_size)) |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 } | 248 } |
249 | 249 |
250 static inline size_t RoundUp(size_t value, size_t alignment) { | 250 static inline size_t RoundUp(size_t value, size_t alignment) { |
251 // Check that |alignment| is a power of 2. | 251 // Check that |alignment| is a power of 2. |
252 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1))); | 252 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1))); |
253 return ((value + (alignment - 1)) & ~(alignment-1)); | 253 return ((value + (alignment - 1)) & ~(alignment-1)); |
254 } | 254 } |
255 | 255 |
256 // static | 256 // static |
257 size_t VideoFrame::AllocationSize(Format format, const gfx::Size& coded_size) { | 257 size_t VideoFrame::AllocationSize(Format format, const gfx::Size& coded_size) { |
| 258 size_t total = 0; |
| 259 for (size_t i = 0; i < NumPlanes(format); ++i) |
| 260 total += PlaneAllocationSize(format, i, coded_size); |
| 261 return total; |
| 262 } |
| 263 |
| 264 // static |
| 265 size_t VideoFrame::PlaneAllocationSize(Format format, |
| 266 size_t plane, |
| 267 const gfx::Size& coded_size) { |
258 switch (format) { | 268 switch (format) { |
259 case VideoFrame::RGB32: | 269 case VideoFrame::RGB32: |
260 return coded_size.GetArea() * 4; | 270 switch (plane) { |
| 271 case VideoFrame::kRGBPlane: |
| 272 return coded_size.GetArea() * 4; |
| 273 default: |
| 274 break; |
| 275 } |
261 case VideoFrame::YV12: | 276 case VideoFrame::YV12: |
262 case VideoFrame::I420: { | 277 case VideoFrame::I420: { |
263 const size_t rounded_size = | 278 const size_t area = |
264 RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2); | 279 RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2); |
265 return rounded_size * 3 / 2; | 280 switch (plane) { |
| 281 case VideoFrame::kYPlane: |
| 282 return area; |
| 283 case VideoFrame::kUPlane: |
| 284 case VideoFrame::kVPlane: |
| 285 return area / 4; |
| 286 default: |
| 287 break; |
| 288 } |
266 } | 289 } |
267 case VideoFrame::YV12A: { | 290 case VideoFrame::YV12A: { |
268 const size_t rounded_size = | 291 const size_t area = |
269 RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2); | 292 RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2); |
270 return rounded_size * 5 / 2; | 293 switch (plane) { |
| 294 case VideoFrame::kYPlane: |
| 295 case VideoFrame::kAPlane: |
| 296 return area; |
| 297 case VideoFrame::kUPlane: |
| 298 case VideoFrame::kVPlane: |
| 299 return area / 4; |
| 300 default: |
| 301 break; |
| 302 } |
271 } | 303 } |
272 case VideoFrame::YV16: { | 304 case VideoFrame::YV16: { |
273 const size_t rounded_size = | 305 const size_t area = |
274 RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2); | 306 RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2); |
275 return rounded_size * 2; | 307 switch (plane) { |
| 308 case VideoFrame::kYPlane: |
| 309 return area; |
| 310 case VideoFrame::kUPlane: |
| 311 case VideoFrame::kVPlane: |
| 312 return area / 2; |
| 313 default: |
| 314 break; |
| 315 } |
276 } | 316 } |
277 case VideoFrame::INVALID: | 317 case VideoFrame::INVALID: |
278 case VideoFrame::EMPTY: | 318 case VideoFrame::EMPTY: |
279 case VideoFrame::NATIVE_TEXTURE: | 319 case VideoFrame::NATIVE_TEXTURE: |
280 #if defined(GOOGLE_TV) | 320 #if defined(GOOGLE_TV) |
281 case VideoFrame::HOLE: | 321 case VideoFrame::HOLE: |
282 #endif | 322 #endif |
283 break; | 323 break; |
284 } | 324 } |
285 NOTREACHED() << "Unsupported video frame format: " << format; | 325 NOTREACHED() << "Unsupported video frame format/plane: " |
| 326 << format << "/" << plane; |
286 return 0; | 327 return 0; |
287 } | 328 } |
288 | 329 |
289 // Release data allocated by AllocateRGB() or AllocateYUV(). | 330 // Release data allocated by AllocateRGB() or AllocateYUV(). |
290 static void ReleaseData(uint8* data) { | 331 static void ReleaseData(uint8* data) { |
291 DCHECK(data); | 332 DCHECK(data); |
292 base::AlignedFree(data); | 333 base::AlignedFree(data); |
293 } | 334 } |
294 | 335 |
295 void VideoFrame::AllocateRGB(size_t bytes_per_pixel) { | 336 void VideoFrame::AllocateRGB(size_t bytes_per_pixel) { |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 : mailbox_(mailbox), | 530 : mailbox_(mailbox), |
490 sync_point_(sync_point), | 531 sync_point_(sync_point), |
491 release_callback_(release_callback) {} | 532 release_callback_(release_callback) {} |
492 | 533 |
493 VideoFrame::MailboxHolder::~MailboxHolder() { | 534 VideoFrame::MailboxHolder::~MailboxHolder() { |
494 if (!release_callback_.is_null()) | 535 if (!release_callback_.is_null()) |
495 release_callback_.Run(sync_point_); | 536 release_callback_.Run(sync_point_); |
496 } | 537 } |
497 | 538 |
498 } // namespace media | 539 } // namespace media |
OLD | NEW |