| 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 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 // Rounds up |coded_size| if necessary for |format|. | 30 // Rounds up |coded_size| if necessary for |format|. |
| 31 static gfx::Size AdjustCodedSize(VideoFrame::Format format, | 31 static gfx::Size AdjustCodedSize(VideoFrame::Format format, |
| 32 const gfx::Size& coded_size) { | 32 const gfx::Size& coded_size) { |
| 33 gfx::Size new_coded_size(coded_size); | 33 gfx::Size new_coded_size(coded_size); |
| 34 switch (format) { | 34 switch (format) { |
| 35 case VideoFrame::YV12: | 35 case VideoFrame::YV12: |
| 36 case VideoFrame::YV12A: | 36 case VideoFrame::YV12A: |
| 37 case VideoFrame::I420: | 37 case VideoFrame::I420: |
| 38 case VideoFrame::YV12J: | 38 case VideoFrame::YV12J: |
| 39 case VideoFrame::YV12HD: |
| 39 new_coded_size.set_height(RoundUp(new_coded_size.height(), 2)); | 40 new_coded_size.set_height(RoundUp(new_coded_size.height(), 2)); |
| 40 // Fallthrough. | 41 // Fallthrough. |
| 41 case VideoFrame::YV16: | 42 case VideoFrame::YV16: |
| 42 new_coded_size.set_width(RoundUp(new_coded_size.width(), 2)); | 43 new_coded_size.set_width(RoundUp(new_coded_size.width(), 2)); |
| 43 break; | 44 break; |
| 44 default: | 45 default: |
| 45 break; | 46 break; |
| 46 } | 47 } |
| 47 return new_coded_size; | 48 return new_coded_size; |
| 48 } | 49 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 return "HOLE"; | 98 return "HOLE"; |
| 98 #endif // defined(VIDEO_HOLE) | 99 #endif // defined(VIDEO_HOLE) |
| 99 case VideoFrame::YV12A: | 100 case VideoFrame::YV12A: |
| 100 return "YV12A"; | 101 return "YV12A"; |
| 101 case VideoFrame::YV12J: | 102 case VideoFrame::YV12J: |
| 102 return "YV12J"; | 103 return "YV12J"; |
| 103 case VideoFrame::NV12: | 104 case VideoFrame::NV12: |
| 104 return "NV12"; | 105 return "NV12"; |
| 105 case VideoFrame::YV24: | 106 case VideoFrame::YV24: |
| 106 return "YV24"; | 107 return "YV24"; |
| 108 case VideoFrame::YV12HD: |
| 109 return "YV12HD"; |
| 107 } | 110 } |
| 108 NOTREACHED() << "Invalid videoframe format provided: " << format; | 111 NOTREACHED() << "Invalid videoframe format provided: " << format; |
| 109 return ""; | 112 return ""; |
| 110 } | 113 } |
| 111 | 114 |
| 112 // static | 115 // static |
| 113 bool VideoFrame::IsValidConfig(VideoFrame::Format format, | 116 bool VideoFrame::IsValidConfig(VideoFrame::Format format, |
| 114 const gfx::Size& coded_size, | 117 const gfx::Size& coded_size, |
| 115 const gfx::Rect& visible_rect, | 118 const gfx::Rect& visible_rect, |
| 116 const gfx::Size& natural_size) { | 119 const gfx::Size& natural_size) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 131 case VideoFrame::UNKNOWN: | 134 case VideoFrame::UNKNOWN: |
| 132 return (coded_size.IsEmpty() && visible_rect.IsEmpty() && | 135 return (coded_size.IsEmpty() && visible_rect.IsEmpty() && |
| 133 natural_size.IsEmpty()); | 136 natural_size.IsEmpty()); |
| 134 case VideoFrame::YV24: | 137 case VideoFrame::YV24: |
| 135 break; | 138 break; |
| 136 case VideoFrame::YV12: | 139 case VideoFrame::YV12: |
| 137 case VideoFrame::YV12J: | 140 case VideoFrame::YV12J: |
| 138 case VideoFrame::I420: | 141 case VideoFrame::I420: |
| 139 case VideoFrame::YV12A: | 142 case VideoFrame::YV12A: |
| 140 case VideoFrame::NV12: | 143 case VideoFrame::NV12: |
| 144 case VideoFrame::YV12HD: |
| 141 // Subsampled YUV formats have width/height requirements. | 145 // Subsampled YUV formats have width/height requirements. |
| 142 if (static_cast<size_t>(coded_size.height()) < | 146 if (static_cast<size_t>(coded_size.height()) < |
| 143 RoundUp(visible_rect.bottom(), 2)) | 147 RoundUp(visible_rect.bottom(), 2)) |
| 144 return false; | 148 return false; |
| 145 // Fallthrough. | 149 // Fallthrough. |
| 146 case VideoFrame::YV16: | 150 case VideoFrame::YV16: |
| 147 if (static_cast<size_t>(coded_size.width()) < | 151 if (static_cast<size_t>(coded_size.width()) < |
| 148 RoundUp(visible_rect.right(), 2)) | 152 RoundUp(visible_rect.right(), 2)) |
| 149 return false; | 153 return false; |
| 150 break; | 154 break; |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 #if defined(VIDEO_HOLE) | 470 #if defined(VIDEO_HOLE) |
| 467 case VideoFrame::HOLE: | 471 case VideoFrame::HOLE: |
| 468 #endif // defined(VIDEO_HOLE) | 472 #endif // defined(VIDEO_HOLE) |
| 469 return 0; | 473 return 0; |
| 470 case VideoFrame::NV12: | 474 case VideoFrame::NV12: |
| 471 return 2; | 475 return 2; |
| 472 case VideoFrame::YV12: | 476 case VideoFrame::YV12: |
| 473 case VideoFrame::YV16: | 477 case VideoFrame::YV16: |
| 474 case VideoFrame::I420: | 478 case VideoFrame::I420: |
| 475 case VideoFrame::YV12J: | 479 case VideoFrame::YV12J: |
| 480 case VideoFrame::YV12HD: |
| 476 case VideoFrame::YV24: | 481 case VideoFrame::YV24: |
| 477 return 3; | 482 return 3; |
| 478 case VideoFrame::YV12A: | 483 case VideoFrame::YV12A: |
| 479 return 4; | 484 return 4; |
| 480 case VideoFrame::UNKNOWN: | 485 case VideoFrame::UNKNOWN: |
| 481 break; | 486 break; |
| 482 } | 487 } |
| 483 NOTREACHED() << "Unsupported video frame format: " << format; | 488 NOTREACHED() << "Unsupported video frame format: " << format; |
| 484 return 0; | 489 return 0; |
| 485 } | 490 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 508 case VideoFrame::kYPlane: | 513 case VideoFrame::kYPlane: |
| 509 case VideoFrame::kUPlane: | 514 case VideoFrame::kUPlane: |
| 510 case VideoFrame::kVPlane: | 515 case VideoFrame::kVPlane: |
| 511 return gfx::Size(width, height); | 516 return gfx::Size(width, height); |
| 512 default: | 517 default: |
| 513 break; | 518 break; |
| 514 } | 519 } |
| 515 break; | 520 break; |
| 516 case VideoFrame::YV12: | 521 case VideoFrame::YV12: |
| 517 case VideoFrame::YV12J: | 522 case VideoFrame::YV12J: |
| 523 case VideoFrame::YV12HD: |
| 518 case VideoFrame::I420: | 524 case VideoFrame::I420: |
| 519 switch (plane) { | 525 switch (plane) { |
| 520 case VideoFrame::kYPlane: | 526 case VideoFrame::kYPlane: |
| 521 return gfx::Size(width, height); | 527 return gfx::Size(width, height); |
| 522 case VideoFrame::kUPlane: | 528 case VideoFrame::kUPlane: |
| 523 case VideoFrame::kVPlane: | 529 case VideoFrame::kVPlane: |
| 524 return gfx::Size(width / 2, height / 2); | 530 return gfx::Size(width / 2, height / 2); |
| 525 default: | 531 default: |
| 526 break; | 532 break; |
| 527 } | 533 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 case kVPlane: | 594 case kVPlane: |
| 589 return 8; | 595 return 8; |
| 590 default: | 596 default: |
| 591 break; | 597 break; |
| 592 } | 598 } |
| 593 break; | 599 break; |
| 594 case VideoFrame::YV12: | 600 case VideoFrame::YV12: |
| 595 case VideoFrame::YV16: | 601 case VideoFrame::YV16: |
| 596 case VideoFrame::I420: | 602 case VideoFrame::I420: |
| 597 case VideoFrame::YV12J: | 603 case VideoFrame::YV12J: |
| 604 case VideoFrame::YV12HD: |
| 598 switch (plane) { | 605 switch (plane) { |
| 599 case kYPlane: | 606 case kYPlane: |
| 600 return 8; | 607 return 8; |
| 601 case kUPlane: | 608 case kUPlane: |
| 602 case kVPlane: | 609 case kVPlane: |
| 603 return 2; | 610 return 2; |
| 604 default: | 611 default: |
| 605 break; | 612 break; |
| 606 } | 613 } |
| 607 break; | 614 break; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 | 648 |
| 642 // Release data allocated by AllocateYUV(). | 649 // Release data allocated by AllocateYUV(). |
| 643 static void ReleaseData(uint8* data) { | 650 static void ReleaseData(uint8* data) { |
| 644 DCHECK(data); | 651 DCHECK(data); |
| 645 base::AlignedFree(data); | 652 base::AlignedFree(data); |
| 646 } | 653 } |
| 647 | 654 |
| 648 void VideoFrame::AllocateYUV() { | 655 void VideoFrame::AllocateYUV() { |
| 649 DCHECK(format_ == VideoFrame::YV12 || format_ == VideoFrame::YV16 || | 656 DCHECK(format_ == VideoFrame::YV12 || format_ == VideoFrame::YV16 || |
| 650 format_ == VideoFrame::YV12A || format_ == VideoFrame::I420 || | 657 format_ == VideoFrame::YV12A || format_ == VideoFrame::I420 || |
| 651 format_ == VideoFrame::YV12J || format_ == VideoFrame::YV24); | 658 format_ == VideoFrame::YV12J || format_ == VideoFrame::YV24 || |
| 659 format_ == VideoFrame::YV12HD); |
| 652 // Align Y rows at least at 16 byte boundaries. The stride for both | 660 // Align Y rows at least at 16 byte boundaries. The stride for both |
| 653 // YV12 and YV16 is 1/2 of the stride of Y. For YV12, every row of bytes for | 661 // YV12 and YV16 is 1/2 of the stride of Y. For YV12, every row of bytes for |
| 654 // U and V applies to two rows of Y (one byte of UV for 4 bytes of Y), so in | 662 // U and V applies to two rows of Y (one byte of UV for 4 bytes of Y), so in |
| 655 // the case of YV12 the strides are identical for the same width surface, but | 663 // the case of YV12 the strides are identical for the same width surface, but |
| 656 // the number of bytes allocated for YV12 is 1/2 the amount for U & V as | 664 // the number of bytes allocated for YV12 is 1/2 the amount for U & V as |
| 657 // YV16. We also round the height of the surface allocated to be an even | 665 // YV16. We also round the height of the surface allocated to be an even |
| 658 // number to avoid any potential of faulting by code that attempts to access | 666 // number to avoid any potential of faulting by code that attempts to access |
| 659 // the Y values of the final row, but assumes that the last row of U & V | 667 // the Y values of the final row, but assumes that the last row of U & V |
| 660 // applies to a full two rows of Y. YV12A is the same as YV12, but with an | 668 // applies to a full two rows of Y. YV12A is the same as YV12, but with an |
| 661 // additional alpha plane that has the same size and alignment as the Y plane. | 669 // additional alpha plane that has the same size and alignment as the Y plane. |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 case kVPlane: | 769 case kVPlane: |
| 762 return width; | 770 return width; |
| 763 default: | 771 default: |
| 764 break; | 772 break; |
| 765 } | 773 } |
| 766 break; | 774 break; |
| 767 case VideoFrame::YV12: | 775 case VideoFrame::YV12: |
| 768 case VideoFrame::YV16: | 776 case VideoFrame::YV16: |
| 769 case VideoFrame::I420: | 777 case VideoFrame::I420: |
| 770 case VideoFrame::YV12J: | 778 case VideoFrame::YV12J: |
| 779 case VideoFrame::YV12HD: |
| 771 switch (plane) { | 780 switch (plane) { |
| 772 case kYPlane: | 781 case kYPlane: |
| 773 return width; | 782 return width; |
| 774 case kUPlane: | 783 case kUPlane: |
| 775 case kVPlane: | 784 case kVPlane: |
| 776 return RoundUp(width, 2) / 2; | 785 return RoundUp(width, 2) / 2; |
| 777 default: | 786 default: |
| 778 break; | 787 break; |
| 779 } | 788 } |
| 780 break; | 789 break; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 case kYPlane: | 834 case kYPlane: |
| 826 case kUPlane: | 835 case kUPlane: |
| 827 case kVPlane: | 836 case kVPlane: |
| 828 return height; | 837 return height; |
| 829 default: | 838 default: |
| 830 break; | 839 break; |
| 831 } | 840 } |
| 832 break; | 841 break; |
| 833 case VideoFrame::YV12: | 842 case VideoFrame::YV12: |
| 834 case VideoFrame::YV12J: | 843 case VideoFrame::YV12J: |
| 844 case VideoFrame::YV12HD: |
| 835 case VideoFrame::I420: | 845 case VideoFrame::I420: |
| 836 switch (plane) { | 846 switch (plane) { |
| 837 case kYPlane: | 847 case kYPlane: |
| 838 return height; | 848 return height; |
| 839 case kUPlane: | 849 case kUPlane: |
| 840 case kVPlane: | 850 case kVPlane: |
| 841 return RoundUp(height, 2) / 2; | 851 return RoundUp(height, 2) / 2; |
| 842 default: | 852 default: |
| 843 break; | 853 break; |
| 844 } | 854 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 924 break; | 934 break; |
| 925 for (int row = 0; row < rows(plane); ++row) { | 935 for (int row = 0; row < rows(plane); ++row) { |
| 926 base::MD5Update(context, base::StringPiece( | 936 base::MD5Update(context, base::StringPiece( |
| 927 reinterpret_cast<char*>(data(plane) + stride(plane) * row), | 937 reinterpret_cast<char*>(data(plane) + stride(plane) * row), |
| 928 row_bytes(plane))); | 938 row_bytes(plane))); |
| 929 } | 939 } |
| 930 } | 940 } |
| 931 } | 941 } |
| 932 | 942 |
| 933 } // namespace media | 943 } // namespace media |
| OLD | NEW |