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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 return frame; | 110 return frame; |
111 } | 111 } |
112 | 112 |
113 void VideoFrame::ReadPixelsFromNativeTexture(const SkBitmap& pixels) { | 113 void VideoFrame::ReadPixelsFromNativeTexture(const SkBitmap& pixels) { |
114 DCHECK_EQ(format_, NATIVE_TEXTURE); | 114 DCHECK_EQ(format_, NATIVE_TEXTURE); |
115 if (!read_pixels_cb_.is_null()) | 115 if (!read_pixels_cb_.is_null()) |
116 read_pixels_cb_.Run(pixels); | 116 read_pixels_cb_.Run(pixels); |
117 } | 117 } |
118 | 118 |
119 // static | 119 // static |
120 scoped_refptr<VideoFrame> VideoFrame::WrapExternalSharedMemory( | 120 scoped_refptr<VideoFrame> VideoFrame::WrapExternalPackedMemory( |
121 Format format, | 121 Format format, |
122 const gfx::Size& coded_size, | 122 const gfx::Size& coded_size, |
123 const gfx::Rect& visible_rect, | 123 const gfx::Rect& visible_rect, |
124 const gfx::Size& natural_size, | 124 const gfx::Size& natural_size, |
125 uint8* data, | 125 uint8* data, |
126 size_t data_size, | 126 size_t data_size, |
127 base::SharedMemoryHandle handle, | 127 base::SharedMemoryHandle handle, |
128 base::TimeDelta timestamp, | 128 base::TimeDelta timestamp, |
129 const base::Closure& no_longer_needed_cb) { | 129 const base::Closure& no_longer_needed_cb) { |
130 if (data_size < AllocationSize(format, coded_size)) | 130 if (data_size < AllocationSize(format, coded_size)) |
(...skipping 117 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) { |
| 268 const size_t area = |
| 269 RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2); |
258 switch (format) { | 270 switch (format) { |
259 case VideoFrame::YV12: | 271 case VideoFrame::YV12: |
260 case VideoFrame::I420: { | 272 case VideoFrame::I420: { |
261 const size_t rounded_size = | 273 switch (plane) { |
262 RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2); | 274 case VideoFrame::kYPlane: |
263 return rounded_size * 3 / 2; | 275 return area; |
| 276 case VideoFrame::kUPlane: |
| 277 case VideoFrame::kVPlane: |
| 278 return area / 4; |
| 279 default: |
| 280 break; |
| 281 } |
264 } | 282 } |
265 case VideoFrame::YV12A: { | 283 case VideoFrame::YV12A: { |
266 const size_t rounded_size = | 284 switch (plane) { |
267 RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2); | 285 case VideoFrame::kYPlane: |
268 return rounded_size * 5 / 2; | 286 case VideoFrame::kAPlane: |
| 287 return area; |
| 288 case VideoFrame::kUPlane: |
| 289 case VideoFrame::kVPlane: |
| 290 return area / 4; |
| 291 default: |
| 292 break; |
| 293 } |
269 } | 294 } |
270 case VideoFrame::YV16: { | 295 case VideoFrame::YV16: { |
271 const size_t rounded_size = | 296 switch (plane) { |
272 RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2); | 297 case VideoFrame::kYPlane: |
273 return rounded_size * 2; | 298 return area; |
| 299 case VideoFrame::kUPlane: |
| 300 case VideoFrame::kVPlane: |
| 301 return area / 2; |
| 302 default: |
| 303 break; |
| 304 } |
274 } | 305 } |
275 case VideoFrame::UNKNOWN: | 306 case VideoFrame::UNKNOWN: |
276 case VideoFrame::NATIVE_TEXTURE: | 307 case VideoFrame::NATIVE_TEXTURE: |
277 case VideoFrame::HISTOGRAM_MAX: | 308 case VideoFrame::HISTOGRAM_MAX: |
278 #if defined(GOOGLE_TV) | 309 #if defined(GOOGLE_TV) |
279 case VideoFrame::HOLE: | 310 case VideoFrame::HOLE: |
280 #endif | 311 #endif |
281 break; | 312 break; |
282 } | 313 } |
283 NOTREACHED() << "Unsupported video frame format: " << format; | 314 NOTREACHED() << "Unsupported video frame format/plane: " |
| 315 << format << "/" << plane; |
284 return 0; | 316 return 0; |
285 } | 317 } |
286 | 318 |
287 // Release data allocated by AllocateYUV(). | 319 // Release data allocated by AllocateYUV(). |
288 static void ReleaseData(uint8* data) { | 320 static void ReleaseData(uint8* data) { |
289 DCHECK(data); | 321 DCHECK(data); |
290 base::AlignedFree(data); | 322 base::AlignedFree(data); |
291 } | 323 } |
292 | 324 |
293 void VideoFrame::AllocateYUV() { | 325 void VideoFrame::AllocateYUV() { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 : mailbox_(mailbox), | 497 : mailbox_(mailbox), |
466 sync_point_(sync_point), | 498 sync_point_(sync_point), |
467 release_callback_(release_callback) {} | 499 release_callback_(release_callback) {} |
468 | 500 |
469 VideoFrame::MailboxHolder::~MailboxHolder() { | 501 VideoFrame::MailboxHolder::~MailboxHolder() { |
470 if (!release_callback_.is_null()) | 502 if (!release_callback_.is_null()) |
471 release_callback_.Run(sync_point_); | 503 release_callback_.Run(sync_point_); |
472 } | 504 } |
473 | 505 |
474 } // namespace media | 506 } // namespace media |
OLD | NEW |