| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 case VideoFrame::kVPlane: | 50 case VideoFrame::kVPlane: |
| 51 switch (format) { | 51 switch (format) { |
| 52 case VideoFrame::YV24: | 52 case VideoFrame::YV24: |
| 53 return gfx::Size(1, 1); | 53 return gfx::Size(1, 1); |
| 54 | 54 |
| 55 case VideoFrame::YV16: | 55 case VideoFrame::YV16: |
| 56 return gfx::Size(2, 1); | 56 return gfx::Size(2, 1); |
| 57 | 57 |
| 58 case VideoFrame::YV12: | 58 case VideoFrame::YV12: |
| 59 case VideoFrame::YV12J: | 59 case VideoFrame::YV12J: |
| 60 case VideoFrame::YV12HD: |
| 60 case VideoFrame::I420: | 61 case VideoFrame::I420: |
| 61 case VideoFrame::YV12A: | 62 case VideoFrame::YV12A: |
| 62 case VideoFrame::NV12: | 63 case VideoFrame::NV12: |
| 63 return gfx::Size(2, 2); | 64 return gfx::Size(2, 2); |
| 64 | 65 |
| 65 case VideoFrame::UNKNOWN: | 66 case VideoFrame::UNKNOWN: |
| 66 #if defined(VIDEO_HOLE) | 67 #if defined(VIDEO_HOLE) |
| 67 case VideoFrame::HOLE: | 68 case VideoFrame::HOLE: |
| 68 #endif // defined(VIDEO_HOLE) | 69 #endif // defined(VIDEO_HOLE) |
| 69 case VideoFrame::NATIVE_TEXTURE: | 70 case VideoFrame::NATIVE_TEXTURE: |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 return "HOLE"; | 153 return "HOLE"; |
| 153 #endif // defined(VIDEO_HOLE) | 154 #endif // defined(VIDEO_HOLE) |
| 154 case VideoFrame::YV12A: | 155 case VideoFrame::YV12A: |
| 155 return "YV12A"; | 156 return "YV12A"; |
| 156 case VideoFrame::YV12J: | 157 case VideoFrame::YV12J: |
| 157 return "YV12J"; | 158 return "YV12J"; |
| 158 case VideoFrame::NV12: | 159 case VideoFrame::NV12: |
| 159 return "NV12"; | 160 return "NV12"; |
| 160 case VideoFrame::YV24: | 161 case VideoFrame::YV24: |
| 161 return "YV24"; | 162 return "YV24"; |
| 163 case VideoFrame::YV12HD: |
| 164 return "YV12HD"; |
| 162 } | 165 } |
| 163 NOTREACHED() << "Invalid videoframe format provided: " << format; | 166 NOTREACHED() << "Invalid videoframe format provided: " << format; |
| 164 return ""; | 167 return ""; |
| 165 } | 168 } |
| 166 | 169 |
| 167 // static | 170 // static |
| 168 bool VideoFrame::IsValidConfig(VideoFrame::Format format, | 171 bool VideoFrame::IsValidConfig(VideoFrame::Format format, |
| 169 const gfx::Size& coded_size, | 172 const gfx::Size& coded_size, |
| 170 const gfx::Rect& visible_rect, | 173 const gfx::Rect& visible_rect, |
| 171 const gfx::Size& natural_size) { | 174 const gfx::Size& natural_size) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 194 case VideoFrame::HOLE: | 197 case VideoFrame::HOLE: |
| 195 #endif // defined(VIDEO_HOLE) | 198 #endif // defined(VIDEO_HOLE) |
| 196 return true; | 199 return true; |
| 197 | 200 |
| 198 case VideoFrame::YV24: | 201 case VideoFrame::YV24: |
| 199 case VideoFrame::YV12: | 202 case VideoFrame::YV12: |
| 200 case VideoFrame::YV12J: | 203 case VideoFrame::YV12J: |
| 201 case VideoFrame::I420: | 204 case VideoFrame::I420: |
| 202 case VideoFrame::YV12A: | 205 case VideoFrame::YV12A: |
| 203 case VideoFrame::NV12: | 206 case VideoFrame::NV12: |
| 207 case VideoFrame::YV12HD: |
| 204 case VideoFrame::YV16: | 208 case VideoFrame::YV16: |
| 205 // Check that software-allocated buffer formats are aligned correctly and | 209 // Check that software-allocated buffer formats are aligned correctly and |
| 206 // not empty. | 210 // not empty. |
| 207 const gfx::Size alignment = CommonAlignment(format); | 211 const gfx::Size alignment = CommonAlignment(format); |
| 208 return RoundUp(visible_rect.right(), alignment.width()) <= | 212 return RoundUp(visible_rect.right(), alignment.width()) <= |
| 209 static_cast<size_t>(coded_size.width()) && | 213 static_cast<size_t>(coded_size.width()) && |
| 210 RoundUp(visible_rect.bottom(), alignment.height()) <= | 214 RoundUp(visible_rect.bottom(), alignment.height()) <= |
| 211 static_cast<size_t>(coded_size.height()) && | 215 static_cast<size_t>(coded_size.height()) && |
| 212 !coded_size.IsEmpty() && !visible_rect.IsEmpty() && | 216 !coded_size.IsEmpty() && !visible_rect.IsEmpty() && |
| 213 !natural_size.IsEmpty(); | 217 !natural_size.IsEmpty(); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 #if defined(VIDEO_HOLE) | 525 #if defined(VIDEO_HOLE) |
| 522 case VideoFrame::HOLE: | 526 case VideoFrame::HOLE: |
| 523 #endif // defined(VIDEO_HOLE) | 527 #endif // defined(VIDEO_HOLE) |
| 524 return 0; | 528 return 0; |
| 525 case VideoFrame::NV12: | 529 case VideoFrame::NV12: |
| 526 return 2; | 530 return 2; |
| 527 case VideoFrame::YV12: | 531 case VideoFrame::YV12: |
| 528 case VideoFrame::YV16: | 532 case VideoFrame::YV16: |
| 529 case VideoFrame::I420: | 533 case VideoFrame::I420: |
| 530 case VideoFrame::YV12J: | 534 case VideoFrame::YV12J: |
| 535 case VideoFrame::YV12HD: |
| 531 case VideoFrame::YV24: | 536 case VideoFrame::YV24: |
| 532 return 3; | 537 return 3; |
| 533 case VideoFrame::YV12A: | 538 case VideoFrame::YV12A: |
| 534 return 4; | 539 return 4; |
| 535 case VideoFrame::UNKNOWN: | 540 case VideoFrame::UNKNOWN: |
| 536 break; | 541 break; |
| 537 } | 542 } |
| 538 NOTREACHED() << "Unsupported video frame format: " << format; | 543 NOTREACHED() << "Unsupported video frame format: " << format; |
| 539 return 0; | 544 return 0; |
| 540 } | 545 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 } | 589 } |
| 585 | 590 |
| 586 // Release data allocated by AllocateYUV(). | 591 // Release data allocated by AllocateYUV(). |
| 587 static void ReleaseData(uint8* data) { | 592 static void ReleaseData(uint8* data) { |
| 588 DCHECK(data); | 593 DCHECK(data); |
| 589 base::AlignedFree(data); | 594 base::AlignedFree(data); |
| 590 } | 595 } |
| 591 | 596 |
| 592 void VideoFrame::AllocateYUV() { | 597 void VideoFrame::AllocateYUV() { |
| 593 DCHECK(format_ == YV12 || format_ == YV16 || format_ == YV12A || | 598 DCHECK(format_ == YV12 || format_ == YV16 || format_ == YV12A || |
| 594 format_ == I420 || format_ == YV12J || format_ == YV24); | 599 format_ == I420 || format_ == YV12J || format_ == YV24 || |
| 600 format_ == YV12HD); |
| 595 static_assert(0 == kYPlane, "y plane data must be index 0"); | 601 static_assert(0 == kYPlane, "y plane data must be index 0"); |
| 596 | 602 |
| 597 size_t data_size = 0; | 603 size_t data_size = 0; |
| 598 size_t offset[kMaxPlanes]; | 604 size_t offset[kMaxPlanes]; |
| 599 for (size_t plane = 0; plane < VideoFrame::NumPlanes(format_); ++plane) { | 605 for (size_t plane = 0; plane < VideoFrame::NumPlanes(format_); ++plane) { |
| 600 // The *2 in alignment for height is because some formats (e.g. h264) allow | 606 // The *2 in alignment for height is because some formats (e.g. h264) allow |
| 601 // interlaced coding, and then the size needs to be a multiple of two | 607 // interlaced coding, and then the size needs to be a multiple of two |
| 602 // macroblocks (vertically). See | 608 // macroblocks (vertically). See |
| 603 // libavcodec/utils.c:avcodec_align_dimensions2(). | 609 // libavcodec/utils.c:avcodec_align_dimensions2(). |
| 604 const size_t height = RoundUp(rows(plane), kFrameSizeAlignment * 2); | 610 const size_t height = RoundUp(rows(plane), kFrameSizeAlignment * 2); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 for (size_t plane = 0; plane < NumPlanes(format_); ++plane) { | 777 for (size_t plane = 0; plane < NumPlanes(format_); ++plane) { |
| 772 for (int row = 0; row < rows(plane); ++row) { | 778 for (int row = 0; row < rows(plane); ++row) { |
| 773 base::MD5Update(context, base::StringPiece( | 779 base::MD5Update(context, base::StringPiece( |
| 774 reinterpret_cast<char*>(data(plane) + stride(plane) * row), | 780 reinterpret_cast<char*>(data(plane) + stride(plane) * row), |
| 775 row_bytes(plane))); | 781 row_bytes(plane))); |
| 776 } | 782 } |
| 777 } | 783 } |
| 778 } | 784 } |
| 779 | 785 |
| 780 } // namespace media | 786 } // namespace media |
| OLD | NEW |