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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/memory/aligned_memory.h" |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
12 #include "media/base/buffers.h" | 13 #include "media/base/buffers.h" |
13 #include "media/base/yuv_convert.h" | 14 #include "media/base/yuv_convert.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace media { | 17 namespace media { |
17 | 18 |
18 using base::MD5DigestToBase16; | 19 using base::MD5DigestToBase16; |
19 | 20 |
(...skipping 19 matching lines...) Expand all Loading... |
39 v_plane += frame->stride(VideoFrame::kVPlane); | 40 v_plane += frame->stride(VideoFrame::kVPlane); |
40 } | 41 } |
41 } | 42 } |
42 | 43 |
43 // Given a |yv12_frame| this method converts the YV12 frame to RGBA and | 44 // Given a |yv12_frame| this method converts the YV12 frame to RGBA and |
44 // makes sure that all the pixels of the RBG frame equal |expect_rgb_color|. | 45 // makes sure that all the pixels of the RBG frame equal |expect_rgb_color|. |
45 void ExpectFrameColor(media::VideoFrame* yv12_frame, uint32 expect_rgb_color) { | 46 void ExpectFrameColor(media::VideoFrame* yv12_frame, uint32 expect_rgb_color) { |
46 ASSERT_EQ(VideoFrame::YV12, yv12_frame->format()); | 47 ASSERT_EQ(VideoFrame::YV12, yv12_frame->format()); |
47 ASSERT_EQ(yv12_frame->stride(VideoFrame::kUPlane), | 48 ASSERT_EQ(yv12_frame->stride(VideoFrame::kUPlane), |
48 yv12_frame->stride(VideoFrame::kVPlane)); | 49 yv12_frame->stride(VideoFrame::kVPlane)); |
| 50 ASSERT_EQ( |
| 51 yv12_frame->coded_size().width() & (VideoFrame::kFrameSizeAlignment - 1), |
| 52 0); |
| 53 ASSERT_EQ( |
| 54 yv12_frame->coded_size().height() & (VideoFrame::kFrameSizeAlignment - 1), |
| 55 0); |
49 | 56 |
50 scoped_refptr<media::VideoFrame> rgb_frame; | 57 size_t bytes_per_row = yv12_frame->coded_size().width() * 4u; |
51 rgb_frame = media::VideoFrame::CreateFrame(VideoFrame::RGB32, | 58 uint8* rgb_data = reinterpret_cast<uint8*>( |
52 yv12_frame->coded_size(), | 59 base::AlignedAlloc(bytes_per_row * yv12_frame->coded_size().height() + |
53 yv12_frame->visible_rect(), | 60 VideoFrame::kFrameSizePadding, |
54 yv12_frame->natural_size(), | 61 VideoFrame::kFrameAddressAlignment)); |
55 yv12_frame->GetTimestamp()); | |
56 | |
57 ASSERT_EQ(yv12_frame->coded_size().width(), | |
58 rgb_frame->coded_size().width()); | |
59 ASSERT_EQ(yv12_frame->coded_size().height(), | |
60 rgb_frame->coded_size().height()); | |
61 | 62 |
62 media::ConvertYUVToRGB32(yv12_frame->data(VideoFrame::kYPlane), | 63 media::ConvertYUVToRGB32(yv12_frame->data(VideoFrame::kYPlane), |
63 yv12_frame->data(VideoFrame::kUPlane), | 64 yv12_frame->data(VideoFrame::kUPlane), |
64 yv12_frame->data(VideoFrame::kVPlane), | 65 yv12_frame->data(VideoFrame::kVPlane), |
65 rgb_frame->data(VideoFrame::kRGBPlane), | 66 rgb_data, |
66 rgb_frame->coded_size().width(), | 67 yv12_frame->coded_size().width(), |
67 rgb_frame->coded_size().height(), | 68 yv12_frame->coded_size().height(), |
68 yv12_frame->stride(VideoFrame::kYPlane), | 69 yv12_frame->stride(VideoFrame::kYPlane), |
69 yv12_frame->stride(VideoFrame::kUPlane), | 70 yv12_frame->stride(VideoFrame::kUPlane), |
70 rgb_frame->stride(VideoFrame::kRGBPlane), | 71 bytes_per_row, |
71 media::YV12); | 72 media::YV12); |
72 | 73 |
73 for (int row = 0; row < rgb_frame->coded_size().height(); ++row) { | 74 for (int row = 0; row < yv12_frame->coded_size().height(); ++row) { |
74 uint32* rgb_row_data = reinterpret_cast<uint32*>( | 75 uint32* rgb_row_data = reinterpret_cast<uint32*>( |
75 rgb_frame->data(VideoFrame::kRGBPlane) + | 76 rgb_data + (bytes_per_row * row)); |
76 (rgb_frame->stride(VideoFrame::kRGBPlane) * row)); | 77 for (int col = 0; col < yv12_frame->coded_size().width(); ++col) { |
77 for (int col = 0; col < rgb_frame->coded_size().width(); ++col) { | |
78 SCOPED_TRACE( | 78 SCOPED_TRACE( |
79 base::StringPrintf("Checking (%d, %d)", row, col)); | 79 base::StringPrintf("Checking (%d, %d)", row, col)); |
80 EXPECT_EQ(expect_rgb_color, rgb_row_data[col]); | 80 EXPECT_EQ(expect_rgb_color, rgb_row_data[col]); |
81 } | 81 } |
82 } | 82 } |
| 83 |
| 84 base::AlignedFree(rgb_data); |
83 } | 85 } |
84 | 86 |
85 // Fill each plane to its reported extents and verify accessors report non | 87 // Fill each plane to its reported extents and verify accessors report non |
86 // zero values. Additionally, for the first plane verify the rows and | 88 // zero values. Additionally, for the first plane verify the rows and |
87 // row_bytes values are correct. | 89 // row_bytes values are correct. |
88 void ExpectFrameExtents(VideoFrame::Format format, int planes, | 90 void ExpectFrameExtents(VideoFrame::Format format, int planes, |
89 int bytes_per_pixel, const char* expected_hash) { | 91 int bytes_per_pixel, const char* expected_hash) { |
90 const unsigned char kFillByte = 0x80; | 92 const unsigned char kFillByte = 0x80; |
91 const int kWidth = 61; | 93 const int kWidth = 61; |
92 const int kHeight = 31; | 94 const int kHeight = 31; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 } | 199 } |
198 } | 200 } |
199 | 201 |
200 // Ensure each frame is properly sized and allocated. Will trigger OOB reads | 202 // Ensure each frame is properly sized and allocated. Will trigger OOB reads |
201 // and writes as well as incorrect frame hashes otherwise. | 203 // and writes as well as incorrect frame hashes otherwise. |
202 TEST(VideoFrame, CheckFrameExtents) { | 204 TEST(VideoFrame, CheckFrameExtents) { |
203 // Each call consists of a VideoFrame::Format, # of planes, bytes per pixel, | 205 // Each call consists of a VideoFrame::Format, # of planes, bytes per pixel, |
204 // and the expected hash of all planes if filled with kFillByte (defined in | 206 // and the expected hash of all planes if filled with kFillByte (defined in |
205 // ExpectFrameExtents). | 207 // ExpectFrameExtents). |
206 ExpectFrameExtents( | 208 ExpectFrameExtents( |
207 VideoFrame::RGB32, 1, 4, "de6d3d567e282f6a38d478f04fc81fb0"); | |
208 ExpectFrameExtents( | |
209 VideoFrame::YV12, 3, 1, "71113bdfd4c0de6cf62f48fb74f7a0b1"); | 209 VideoFrame::YV12, 3, 1, "71113bdfd4c0de6cf62f48fb74f7a0b1"); |
210 ExpectFrameExtents( | 210 ExpectFrameExtents( |
211 VideoFrame::YV16, 3, 1, "9bb99ac3ff350644ebff4d28dc01b461"); | 211 VideoFrame::YV16, 3, 1, "9bb99ac3ff350644ebff4d28dc01b461"); |
212 } | 212 } |
213 | 213 |
214 static void TextureCallback(uint32* called_sync_point, uint32 sync_point) { | 214 static void TextureCallback(uint32* called_sync_point, uint32 sync_point) { |
215 *called_sync_point = sync_point; | 215 *called_sync_point = sync_point; |
216 } | 216 } |
217 | 217 |
218 // Verify the TextureNoLongerNeededCallback is called when VideoFrame is | 218 // Verify the TextureNoLongerNeededCallback is called when VideoFrame is |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 | 416 |
417 EXPECT_EQ(0u, called_sync_point); | 417 EXPECT_EQ(0u, called_sync_point); |
418 | 418 |
419 // Don't use the mailbox at all and drop our ref on it. | 419 // Don't use the mailbox at all and drop our ref on it. |
420 } | 420 } |
421 // The VideoFrame is destroyed, it should call the callback. | 421 // The VideoFrame is destroyed, it should call the callback. |
422 EXPECT_EQ(sync_point, called_sync_point); | 422 EXPECT_EQ(sync_point, called_sync_point); |
423 } | 423 } |
424 | 424 |
425 } // namespace media | 425 } // namespace media |
OLD | NEW |