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 14 matching lines...) Expand all Loading... |
25 const gfx::Size& natural_size, | 25 const gfx::Size& natural_size, |
26 base::TimeDelta timestamp) { | 26 base::TimeDelta timestamp) { |
27 DCHECK(IsValidConfig(format, coded_size, visible_rect, natural_size)); | 27 DCHECK(IsValidConfig(format, coded_size, visible_rect, natural_size)); |
28 scoped_refptr<VideoFrame> frame(new VideoFrame( | 28 scoped_refptr<VideoFrame> frame(new VideoFrame( |
29 format, coded_size, visible_rect, natural_size, timestamp, false)); | 29 format, coded_size, visible_rect, natural_size, timestamp, false)); |
30 switch (format) { | 30 switch (format) { |
31 case VideoFrame::YV12: | 31 case VideoFrame::YV12: |
32 case VideoFrame::YV12A: | 32 case VideoFrame::YV12A: |
33 case VideoFrame::YV16: | 33 case VideoFrame::YV16: |
34 case VideoFrame::I420: | 34 case VideoFrame::I420: |
| 35 case VideoFrame::YV12J: |
35 frame->AllocateYUV(); | 36 frame->AllocateYUV(); |
36 break; | 37 break; |
37 default: | 38 default: |
38 LOG(FATAL) << "Unsupported frame format: " << format; | 39 LOG(FATAL) << "Unsupported frame format: " << format; |
39 } | 40 } |
40 return frame; | 41 return frame; |
41 } | 42 } |
42 | 43 |
43 // static | 44 // static |
44 std::string VideoFrame::FormatToString(VideoFrame::Format format) { | 45 std::string VideoFrame::FormatToString(VideoFrame::Format format) { |
45 switch (format) { | 46 switch (format) { |
46 case VideoFrame::UNKNOWN: | 47 case VideoFrame::UNKNOWN: |
47 return "UNKNOWN"; | 48 return "UNKNOWN"; |
48 case VideoFrame::YV12: | 49 case VideoFrame::YV12: |
49 return "YV12"; | 50 return "YV12"; |
50 case VideoFrame::YV16: | 51 case VideoFrame::YV16: |
51 return "YV16"; | 52 return "YV16"; |
52 case VideoFrame::I420: | 53 case VideoFrame::I420: |
53 return "I420"; | 54 return "I420"; |
54 case VideoFrame::NATIVE_TEXTURE: | 55 case VideoFrame::NATIVE_TEXTURE: |
55 return "NATIVE_TEXTURE"; | 56 return "NATIVE_TEXTURE"; |
56 #if defined(GOOGLE_TV) | 57 #if defined(GOOGLE_TV) |
57 case VideoFrame::HOLE: | 58 case VideoFrame::HOLE: |
58 return "HOLE"; | 59 return "HOLE"; |
59 #endif | 60 #endif |
60 case VideoFrame::YV12A: | 61 case VideoFrame::YV12A: |
61 return "YV12A"; | 62 return "YV12A"; |
| 63 case VideoFrame::YV12J: |
| 64 return "YV12J"; |
62 case VideoFrame::HISTOGRAM_MAX: | 65 case VideoFrame::HISTOGRAM_MAX: |
63 return "HISTOGRAM_MAX"; | 66 return "HISTOGRAM_MAX"; |
64 } | 67 } |
65 NOTREACHED() << "Invalid videoframe format provided: " << format; | 68 NOTREACHED() << "Invalid videoframe format provided: " << format; |
66 return ""; | 69 return ""; |
67 } | 70 } |
68 | 71 |
69 // static | 72 // static |
70 bool VideoFrame::IsValidConfig(VideoFrame::Format format, | 73 bool VideoFrame::IsValidConfig(VideoFrame::Format format, |
71 const gfx::Size& coded_size, | 74 const gfx::Size& coded_size, |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 size_t VideoFrame::NumPlanes(Format format) { | 232 size_t VideoFrame::NumPlanes(Format format) { |
230 switch (format) { | 233 switch (format) { |
231 case VideoFrame::NATIVE_TEXTURE: | 234 case VideoFrame::NATIVE_TEXTURE: |
232 #if defined(GOOGLE_TV) | 235 #if defined(GOOGLE_TV) |
233 case VideoFrame::HOLE: | 236 case VideoFrame::HOLE: |
234 #endif | 237 #endif |
235 return 0; | 238 return 0; |
236 case VideoFrame::YV12: | 239 case VideoFrame::YV12: |
237 case VideoFrame::YV16: | 240 case VideoFrame::YV16: |
238 case VideoFrame::I420: | 241 case VideoFrame::I420: |
| 242 case VideoFrame::YV12J: |
239 return 3; | 243 return 3; |
240 case VideoFrame::YV12A: | 244 case VideoFrame::YV12A: |
241 return 4; | 245 return 4; |
242 case VideoFrame::UNKNOWN: | 246 case VideoFrame::UNKNOWN: |
243 case VideoFrame::HISTOGRAM_MAX: | 247 case VideoFrame::HISTOGRAM_MAX: |
244 break; | 248 break; |
245 } | 249 } |
246 NOTREACHED() << "Unsupported video frame format: " << format; | 250 NOTREACHED() << "Unsupported video frame format: " << format; |
247 return 0; | 251 return 0; |
248 } | 252 } |
(...skipping 13 matching lines...) Expand all Loading... |
262 } | 266 } |
263 | 267 |
264 // static | 268 // static |
265 size_t VideoFrame::PlaneAllocationSize(Format format, | 269 size_t VideoFrame::PlaneAllocationSize(Format format, |
266 size_t plane, | 270 size_t plane, |
267 const gfx::Size& coded_size) { | 271 const gfx::Size& coded_size) { |
268 const size_t area = | 272 const size_t area = |
269 RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2); | 273 RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2); |
270 switch (format) { | 274 switch (format) { |
271 case VideoFrame::YV12: | 275 case VideoFrame::YV12: |
| 276 case VideoFrame::YV12J: |
272 case VideoFrame::I420: { | 277 case VideoFrame::I420: { |
273 switch (plane) { | 278 switch (plane) { |
274 case VideoFrame::kYPlane: | 279 case VideoFrame::kYPlane: |
275 return area; | 280 return area; |
276 case VideoFrame::kUPlane: | 281 case VideoFrame::kUPlane: |
277 case VideoFrame::kVPlane: | 282 case VideoFrame::kVPlane: |
278 return area / 4; | 283 return area / 4; |
279 default: | 284 default: |
280 break; | 285 break; |
281 } | 286 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 } | 322 } |
318 | 323 |
319 // Release data allocated by AllocateYUV(). | 324 // Release data allocated by AllocateYUV(). |
320 static void ReleaseData(uint8* data) { | 325 static void ReleaseData(uint8* data) { |
321 DCHECK(data); | 326 DCHECK(data); |
322 base::AlignedFree(data); | 327 base::AlignedFree(data); |
323 } | 328 } |
324 | 329 |
325 void VideoFrame::AllocateYUV() { | 330 void VideoFrame::AllocateYUV() { |
326 DCHECK(format_ == VideoFrame::YV12 || format_ == VideoFrame::YV16 || | 331 DCHECK(format_ == VideoFrame::YV12 || format_ == VideoFrame::YV16 || |
327 format_ == VideoFrame::YV12A || format_ == VideoFrame::I420); | 332 format_ == VideoFrame::YV12A || format_ == VideoFrame::I420 || |
| 333 format_ == VideoFrame::YV12J); |
328 // Align Y rows at least at 16 byte boundaries. The stride for both | 334 // Align Y rows at least at 16 byte boundaries. The stride for both |
329 // YV12 and YV16 is 1/2 of the stride of Y. For YV12, every row of bytes for | 335 // YV12 and YV16 is 1/2 of the stride of Y. For YV12, every row of bytes for |
330 // U and V applies to two rows of Y (one byte of UV for 4 bytes of Y), so in | 336 // U and V applies to two rows of Y (one byte of UV for 4 bytes of Y), so in |
331 // the case of YV12 the strides are identical for the same width surface, but | 337 // the case of YV12 the strides are identical for the same width surface, but |
332 // the number of bytes allocated for YV12 is 1/2 the amount for U & V as | 338 // the number of bytes allocated for YV12 is 1/2 the amount for U & V as |
333 // YV16. We also round the height of the surface allocated to be an even | 339 // YV16. We also round the height of the surface allocated to be an even |
334 // number to avoid any potential of faulting by code that attempts to access | 340 // number to avoid any potential of faulting by code that attempts to access |
335 // the Y values of the final row, but assumes that the last row of U & V | 341 // the Y values of the final row, but assumes that the last row of U & V |
336 // applies to a full two rows of Y. YV12A is the same as YV12, but with an | 342 // applies to a full two rows of Y. YV12A is the same as YV12, but with an |
337 // additional alpha plane that has the same size and alignment as the Y plane. | 343 // additional alpha plane that has the same size and alignment as the Y plane. |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 int width = coded_size_.width(); | 418 int width = coded_size_.width(); |
413 switch (format_) { | 419 switch (format_) { |
414 // Planar, 8bpp. | 420 // Planar, 8bpp. |
415 case YV12A: | 421 case YV12A: |
416 if (plane == kAPlane) | 422 if (plane == kAPlane) |
417 return width; | 423 return width; |
418 // Fallthrough. | 424 // Fallthrough. |
419 case YV12: | 425 case YV12: |
420 case YV16: | 426 case YV16: |
421 case I420: | 427 case I420: |
| 428 case YV12J: |
422 if (plane == kYPlane) | 429 if (plane == kYPlane) |
423 return width; | 430 return width; |
424 return RoundUp(width, 2) / 2; | 431 return RoundUp(width, 2) / 2; |
425 | 432 |
426 default: | 433 default: |
427 break; | 434 break; |
428 } | 435 } |
429 | 436 |
430 // Intentionally leave out non-production formats. | 437 // Intentionally leave out non-production formats. |
431 NOTREACHED() << "Unsupported video frame format: " << format_; | 438 NOTREACHED() << "Unsupported video frame format: " << format_; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 : mailbox_(mailbox), | 504 : mailbox_(mailbox), |
498 sync_point_(sync_point), | 505 sync_point_(sync_point), |
499 release_callback_(release_callback) {} | 506 release_callback_(release_callback) {} |
500 | 507 |
501 VideoFrame::MailboxHolder::~MailboxHolder() { | 508 VideoFrame::MailboxHolder::~MailboxHolder() { |
502 if (!release_callback_.is_null()) | 509 if (!release_callback_.is_null()) |
503 release_callback_.Run(sync_point_); | 510 release_callback_.Run(sync_point_); |
504 } | 511 } |
505 | 512 |
506 } // namespace media | 513 } // namespace media |
OLD | NEW |