Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(288)

Side by Side Diff: media/base/video_frame_unittest.cc

Issue 56713002: Remove RGB32 from VideoFrame::Format. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@vframe_invalid
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/base/video_frame.cc ('k') | media/filters/video_renderer_base_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
21 static inline size_t RoundUp(size_t value, size_t alignment) {
rileya (GONE FROM CHROMIUM) 2013/11/04 19:25:53 This was copied from video_frame.cc... in the inte
scherkus (not reviewing) 2013/11/04 22:54:34 either: 1) dump this in media/base/video_util.h
rileya (GONE FROM CHROMIUM) 2013/11/04 23:51:41 Alright, I did 2).
22 // Check that |alignment| is a power of 2.
23 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1)));
24 return ((value + (alignment - 1)) & ~(alignment-1));
25 }
26
20 // Helper function that initializes a YV12 frame with white and black scan 27 // Helper function that initializes a YV12 frame with white and black scan
21 // lines based on the |white_to_black| parameter. If 0, then the entire 28 // lines based on the |white_to_black| parameter. If 0, then the entire
22 // frame will be black, if 1 then the entire frame will be white. 29 // frame will be black, if 1 then the entire frame will be white.
23 void InitializeYV12Frame(VideoFrame* frame, double white_to_black) { 30 void InitializeYV12Frame(VideoFrame* frame, double white_to_black) {
24 EXPECT_EQ(VideoFrame::YV12, frame->format()); 31 EXPECT_EQ(VideoFrame::YV12, frame->format());
25 int first_black_row = static_cast<int>(frame->coded_size().height() * 32 int first_black_row = static_cast<int>(frame->coded_size().height() *
26 white_to_black); 33 white_to_black);
27 uint8* y_plane = frame->data(VideoFrame::kYPlane); 34 uint8* y_plane = frame->data(VideoFrame::kYPlane);
28 for (int row = 0; row < frame->coded_size().height(); ++row) { 35 for (int row = 0; row < frame->coded_size().height(); ++row) {
29 int color = (row < first_black_row) ? 0xFF : 0x00; 36 int color = (row < first_black_row) ? 0xFF : 0x00;
(...skipping 10 matching lines...) Expand all
40 } 47 }
41 } 48 }
42 49
43 // Given a |yv12_frame| this method converts the YV12 frame to RGBA and 50 // 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|. 51 // 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) { 52 void ExpectFrameColor(media::VideoFrame* yv12_frame, uint32 expect_rgb_color) {
46 ASSERT_EQ(VideoFrame::YV12, yv12_frame->format()); 53 ASSERT_EQ(VideoFrame::YV12, yv12_frame->format());
47 ASSERT_EQ(yv12_frame->stride(VideoFrame::kUPlane), 54 ASSERT_EQ(yv12_frame->stride(VideoFrame::kUPlane),
48 yv12_frame->stride(VideoFrame::kVPlane)); 55 yv12_frame->stride(VideoFrame::kVPlane));
49 56
50 scoped_refptr<media::VideoFrame> rgb_frame; 57 size_t bytes_per_row = RoundUp(yv12_frame->coded_size().width(),
51 rgb_frame = media::VideoFrame::CreateFrame(VideoFrame::RGB32, 58 VideoFrame::kFrameSizeAlignment) * 4u;
52 yv12_frame->coded_size(), 59 size_t aligned_height = RoundUp(yv12_frame->coded_size().height(),
53 yv12_frame->visible_rect(), 60 VideoFrame::kFrameSizeAlignment);
54 yv12_frame->natural_size(), 61 uint8* data = reinterpret_cast<uint8*>(base::AlignedAlloc(
scherkus (not reviewing) 2013/11/04 22:54:34 s/data/rgb_data/
rileya (GONE FROM CHROMIUM) 2013/11/04 23:51:41 Done.
55 yv12_frame->GetTimestamp()); 62 bytes_per_row * aligned_height + VideoFrame::kFrameSizePadding,
56 63 VideoFrame::kFrameAddressAlignment));
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 64
62 media::ConvertYUVToRGB32(yv12_frame->data(VideoFrame::kYPlane), 65 media::ConvertYUVToRGB32(yv12_frame->data(VideoFrame::kYPlane),
63 yv12_frame->data(VideoFrame::kUPlane), 66 yv12_frame->data(VideoFrame::kUPlane),
64 yv12_frame->data(VideoFrame::kVPlane), 67 yv12_frame->data(VideoFrame::kVPlane),
65 rgb_frame->data(VideoFrame::kRGBPlane), 68 data,
66 rgb_frame->coded_size().width(), 69 yv12_frame->coded_size().width(),
67 rgb_frame->coded_size().height(), 70 yv12_frame->coded_size().height(),
68 yv12_frame->stride(VideoFrame::kYPlane), 71 yv12_frame->stride(VideoFrame::kYPlane),
69 yv12_frame->stride(VideoFrame::kUPlane), 72 yv12_frame->stride(VideoFrame::kUPlane),
70 rgb_frame->stride(VideoFrame::kRGBPlane), 73 bytes_per_row,
71 media::YV12); 74 media::YV12);
72 75
73 for (int row = 0; row < rgb_frame->coded_size().height(); ++row) { 76 for (int row = 0; row < yv12_frame->coded_size().height(); ++row) {
74 uint32* rgb_row_data = reinterpret_cast<uint32*>( 77 uint32* rgb_row_data = reinterpret_cast<uint32*>(
75 rgb_frame->data(VideoFrame::kRGBPlane) + 78 data + (bytes_per_row * row));
76 (rgb_frame->stride(VideoFrame::kRGBPlane) * row)); 79 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( 80 SCOPED_TRACE(
79 base::StringPrintf("Checking (%d, %d)", row, col)); 81 base::StringPrintf("Checking (%d, %d)", row, col));
80 EXPECT_EQ(expect_rgb_color, rgb_row_data[col]); 82 EXPECT_EQ(expect_rgb_color, rgb_row_data[col]);
81 } 83 }
82 } 84 }
85
86 base::AlignedFree(data);
83 } 87 }
84 88
85 // Fill each plane to its reported extents and verify accessors report non 89 // Fill each plane to its reported extents and verify accessors report non
86 // zero values. Additionally, for the first plane verify the rows and 90 // zero values. Additionally, for the first plane verify the rows and
87 // row_bytes values are correct. 91 // row_bytes values are correct.
88 void ExpectFrameExtents(VideoFrame::Format format, int planes, 92 void ExpectFrameExtents(VideoFrame::Format format, int planes,
89 int bytes_per_pixel, const char* expected_hash) { 93 int bytes_per_pixel, const char* expected_hash) {
90 const unsigned char kFillByte = 0x80; 94 const unsigned char kFillByte = 0x80;
91 const int kWidth = 61; 95 const int kWidth = 61;
92 const int kHeight = 31; 96 const int kHeight = 31;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 201 }
198 } 202 }
199 203
200 // Ensure each frame is properly sized and allocated. Will trigger OOB reads 204 // Ensure each frame is properly sized and allocated. Will trigger OOB reads
201 // and writes as well as incorrect frame hashes otherwise. 205 // and writes as well as incorrect frame hashes otherwise.
202 TEST(VideoFrame, CheckFrameExtents) { 206 TEST(VideoFrame, CheckFrameExtents) {
203 // Each call consists of a VideoFrame::Format, # of planes, bytes per pixel, 207 // 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 208 // and the expected hash of all planes if filled with kFillByte (defined in
205 // ExpectFrameExtents). 209 // ExpectFrameExtents).
206 ExpectFrameExtents( 210 ExpectFrameExtents(
207 VideoFrame::RGB32, 1, 4, "de6d3d567e282f6a38d478f04fc81fb0");
208 ExpectFrameExtents(
209 VideoFrame::YV12, 3, 1, "71113bdfd4c0de6cf62f48fb74f7a0b1"); 211 VideoFrame::YV12, 3, 1, "71113bdfd4c0de6cf62f48fb74f7a0b1");
210 ExpectFrameExtents( 212 ExpectFrameExtents(
211 VideoFrame::YV16, 3, 1, "9bb99ac3ff350644ebff4d28dc01b461"); 213 VideoFrame::YV16, 3, 1, "9bb99ac3ff350644ebff4d28dc01b461");
212 } 214 }
213 215
214 static void TextureCallback(uint32* called_sync_point, uint32 sync_point) { 216 static void TextureCallback(uint32* called_sync_point, uint32 sync_point) {
215 *called_sync_point = sync_point; 217 *called_sync_point = sync_point;
216 } 218 }
217 219
218 // Verify the TextureNoLongerNeededCallback is called when VideoFrame is 220 // Verify the TextureNoLongerNeededCallback is called when VideoFrame is
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 418
417 EXPECT_EQ(0u, called_sync_point); 419 EXPECT_EQ(0u, called_sync_point);
418 420
419 // Don't use the mailbox at all and drop our ref on it. 421 // Don't use the mailbox at all and drop our ref on it.
420 } 422 }
421 // The VideoFrame is destroyed, it should call the callback. 423 // The VideoFrame is destroyed, it should call the callback.
422 EXPECT_EQ(sync_point, called_sync_point); 424 EXPECT_EQ(sync_point, called_sync_point);
423 } 425 }
424 426
425 } // namespace media 427 } // namespace media
OLDNEW
« no previous file with comments | « media/base/video_frame.cc ('k') | media/filters/video_renderer_base_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698