OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/logging.h" | |
8 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
9 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
10 #include "media/base/buffers.h" | 11 #include "media/base/buffers.h" |
11 #include "media/base/mock_filters.h" | 12 #include "media/base/mock_filters.h" |
12 #include "media/base/yuv_convert.h" | 13 #include "media/base/yuv_convert.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 namespace media { | 16 namespace media { |
16 | 17 |
17 // Helper function that initializes a YV12 frame with white and black scan | 18 // Helper function that initializes a YV12 frame with white and black scan |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 SCOPED_TRACE(""); | 117 SCOPED_TRACE(""); |
117 InitializeYV12Frame(frame, 1.0f); | 118 InitializeYV12Frame(frame, 1.0f); |
118 ExpectFrameColor(frame, 0xFFFFFFFF); | 119 ExpectFrameColor(frame, 0xFFFFFFFF); |
119 } | 120 } |
120 | 121 |
121 // Test an empty frame. | 122 // Test an empty frame. |
122 frame = VideoFrame::CreateEmptyFrame(); | 123 frame = VideoFrame::CreateEmptyFrame(); |
123 EXPECT_TRUE(frame->IsEndOfStream()); | 124 EXPECT_TRUE(frame->IsEndOfStream()); |
124 } | 125 } |
125 | 126 |
127 static inline size_t RoundUp(size_t value, size_t alignment) { | |
Ami GONE FROM CHROMIUM
2012/03/21 04:33:44
If inline was extraneous this could easily become
DaleCurtis
2012/03/22 01:24:43
Aside from the DCHECK it's just a simple return me
Ami GONE FROM CHROMIUM
2012/03/22 10:53:25
Yes.
| |
128 // Check that |alignment| is a power of 2. | |
129 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1))); | |
Ami GONE FROM CHROMIUM
2012/03/21 04:33:44
s/DCHECK/ASSERT_TRUE/
(this is something I'm guil
| |
130 return ((value + (alignment - 1)) & ~(alignment-1)); | |
131 } | |
132 | |
126 TEST(VideoFrame, CreateBlackFrame) { | 133 TEST(VideoFrame, CreateBlackFrame) { |
127 const size_t kWidth = 2; | 134 const size_t kWidth = 2; |
128 const size_t kHeight = 2; | 135 const size_t kHeight = 2; |
129 const uint8 kExpectedYRow[] = { 0, 0 }; | 136 const uint8 kExpectedYRow[] = { 0, 0 }; |
130 const uint8 kExpectedUVRow[] = { 128 }; | 137 const uint8 kExpectedUVRow[] = { 128 }; |
131 | 138 |
132 scoped_refptr<media::VideoFrame> frame = | 139 scoped_refptr<media::VideoFrame> frame = |
133 VideoFrame::CreateBlackFrame(kWidth, kHeight); | 140 VideoFrame::CreateBlackFrame(kWidth, kHeight); |
134 ASSERT_TRUE(frame); | 141 ASSERT_TRUE(frame); |
135 | 142 |
(...skipping 17 matching lines...) Expand all Loading... | |
153 uint8* u_plane = frame->data(VideoFrame::kUPlane); | 160 uint8* u_plane = frame->data(VideoFrame::kUPlane); |
154 uint8* v_plane = frame->data(VideoFrame::kVPlane); | 161 uint8* v_plane = frame->data(VideoFrame::kVPlane); |
155 for (size_t y = 0; y < frame->height() / 2; ++y) { | 162 for (size_t y = 0; y < frame->height() / 2; ++y) { |
156 EXPECT_EQ(0, memcmp(kExpectedUVRow, u_plane, arraysize(kExpectedUVRow))); | 163 EXPECT_EQ(0, memcmp(kExpectedUVRow, u_plane, arraysize(kExpectedUVRow))); |
157 EXPECT_EQ(0, memcmp(kExpectedUVRow, v_plane, arraysize(kExpectedUVRow))); | 164 EXPECT_EQ(0, memcmp(kExpectedUVRow, v_plane, arraysize(kExpectedUVRow))); |
158 u_plane += frame->stride(VideoFrame::kUPlane); | 165 u_plane += frame->stride(VideoFrame::kUPlane); |
159 v_plane += frame->stride(VideoFrame::kVPlane); | 166 v_plane += frame->stride(VideoFrame::kVPlane); |
160 } | 167 } |
161 } | 168 } |
162 | 169 |
170 TEST(VideoFrame, CheckRowSizes) { | |
DaleCurtis
2012/03/20 22:54:06
A bit lengthy, but the generic version proved just
| |
171 const size_t kWidth = 61; | |
172 const size_t kHeight = 31; | |
173 const base::TimeDelta kTimestampA = base::TimeDelta::FromMicroseconds(1337); | |
174 const base::TimeDelta kDurationA = base::TimeDelta::FromMicroseconds(1667); | |
175 | |
176 // Ensure each frame format yields the correct number of rows and row_bytes. | |
Ami GONE FROM CHROMIUM
2012/03/21 04:33:44
This comment belongs at the top of the TEST().
But
DaleCurtis
2012/03/22 01:24:43
I think it sounds great and was similar to what I
| |
177 scoped_refptr<VideoFrame> frame = VideoFrame::CreateFrame( | |
178 VideoFrame::RGB555, kWidth, kHeight, kTimestampA, kDurationA); | |
179 EXPECT_EQ(frame->rows(VideoFrame::kRGBPlane), kHeight); | |
180 EXPECT_EQ(frame->row_bytes(VideoFrame::kRGBPlane), kWidth * 2); | |
181 EXPECT_EQ(frame->stride(VideoFrame::kRGBPlane), RoundUp(kWidth * 2, 8)); | |
182 | |
183 frame = VideoFrame::CreateFrame( | |
184 VideoFrame::RGB565, kWidth, kHeight, kTimestampA, kDurationA); | |
185 EXPECT_EQ(frame->rows(VideoFrame::kRGBPlane), kHeight); | |
186 EXPECT_EQ(frame->row_bytes(VideoFrame::kRGBPlane), kWidth * 2); | |
187 EXPECT_EQ(frame->stride(VideoFrame::kRGBPlane), RoundUp(kWidth * 2, 8)); | |
188 | |
189 frame = VideoFrame::CreateFrame( | |
190 VideoFrame::RGB24, kWidth, kHeight, kTimestampA, kDurationA); | |
191 EXPECT_EQ(frame->rows(VideoFrame::kRGBPlane), kHeight); | |
192 EXPECT_EQ(frame->row_bytes(VideoFrame::kRGBPlane), kWidth * 3); | |
193 EXPECT_EQ(frame->stride(VideoFrame::kRGBPlane), RoundUp(kWidth * 3, 8)); | |
194 | |
195 frame = VideoFrame::CreateFrame( | |
196 VideoFrame::RGB32, kWidth, kHeight, kTimestampA, kDurationA); | |
197 EXPECT_EQ(frame->rows(VideoFrame::kRGBPlane), kHeight); | |
198 EXPECT_EQ(frame->row_bytes(VideoFrame::kRGBPlane), kWidth * 4); | |
199 EXPECT_EQ(frame->stride(VideoFrame::kRGBPlane), RoundUp(kWidth * 4, 8)); | |
200 | |
201 frame = VideoFrame::CreateFrame( | |
202 VideoFrame::RGBA, kWidth, kHeight, kTimestampA, kDurationA); | |
203 EXPECT_EQ(frame->rows(VideoFrame::kRGBPlane), kHeight); | |
204 EXPECT_EQ(frame->row_bytes(VideoFrame::kRGBPlane), kWidth * 4); | |
205 EXPECT_EQ(frame->stride(VideoFrame::kRGBPlane), RoundUp(kWidth * 4, 8)); | |
206 | |
207 frame = VideoFrame::CreateFrame( | |
208 VideoFrame::YV12, kWidth, kHeight, kTimestampA, kDurationA); | |
209 EXPECT_EQ(frame->rows(VideoFrame::kYPlane), kHeight); | |
210 EXPECT_EQ(frame->rows(VideoFrame::kUPlane), RoundUp(kHeight, 2) / 2); | |
211 EXPECT_EQ(frame->rows(VideoFrame::kVPlane), RoundUp(kHeight, 2) / 2); | |
212 EXPECT_EQ(frame->row_bytes(VideoFrame::kYPlane), kWidth); | |
213 EXPECT_EQ(frame->row_bytes(VideoFrame::kUPlane), RoundUp(kWidth, 2) / 2); | |
214 EXPECT_EQ(frame->row_bytes(VideoFrame::kVPlane), RoundUp(kWidth, 2) / 2); | |
215 EXPECT_EQ(frame->stride(VideoFrame::kYPlane), RoundUp(frame->row_bytes( | |
216 VideoFrame::kYPlane), 4)); | |
217 EXPECT_EQ(frame->stride(VideoFrame::kUPlane), RoundUp(frame->row_bytes( | |
218 VideoFrame::kUPlane), 4)); | |
219 EXPECT_EQ(frame->stride(VideoFrame::kVPlane), RoundUp(frame->row_bytes( | |
220 VideoFrame::kVPlane), 4)); | |
221 | |
222 frame = VideoFrame::CreateFrame( | |
223 VideoFrame::YV16, kWidth, kHeight, kTimestampA, kDurationA); | |
224 EXPECT_EQ(frame->rows(VideoFrame::kYPlane), kHeight); | |
225 EXPECT_EQ(frame->rows(VideoFrame::kUPlane), kHeight); | |
226 EXPECT_EQ(frame->rows(VideoFrame::kVPlane), kHeight); | |
227 EXPECT_EQ(frame->row_bytes(VideoFrame::kYPlane), kWidth); | |
228 EXPECT_EQ(frame->row_bytes(VideoFrame::kUPlane), RoundUp(kWidth, 2) / 2); | |
229 EXPECT_EQ(frame->row_bytes(VideoFrame::kVPlane), RoundUp(kWidth, 2) / 2); | |
230 EXPECT_EQ(frame->stride(VideoFrame::kYPlane), RoundUp(frame->row_bytes( | |
231 VideoFrame::kYPlane), 4)); | |
232 EXPECT_EQ(frame->stride(VideoFrame::kUPlane), RoundUp(frame->row_bytes( | |
233 VideoFrame::kUPlane), 4)); | |
234 EXPECT_EQ(frame->stride(VideoFrame::kVPlane), RoundUp(frame->row_bytes( | |
235 VideoFrame::kVPlane), 4)); | |
236 } | |
237 | |
163 } // namespace media | 238 } // namespace media |
OLD | NEW |