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

Side by Side Diff: webrtc/common_video/i420_video_frame_unittest.cc

Issue 1983583002: Revert of Delete webrtc::VideoFrame methods buffer and stride. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 7 months 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 frame.set_ntp_time_ms(456); 44 frame.set_ntp_time_ms(456);
45 EXPECT_EQ(456, frame.ntp_time_ms()); 45 EXPECT_EQ(456, frame.ntp_time_ms());
46 frame.set_render_time_ms(789); 46 frame.set_render_time_ms(789);
47 EXPECT_EQ(789, frame.render_time_ms()); 47 EXPECT_EQ(789, frame.render_time_ms());
48 } 48 }
49 49
50 TEST(TestVideoFrame, SizeAllocation) { 50 TEST(TestVideoFrame, SizeAllocation) {
51 VideoFrame frame; 51 VideoFrame frame;
52 frame. CreateEmptyFrame(10, 10, 12, 14, 220); 52 frame. CreateEmptyFrame(10, 10, 12, 14, 220);
53 int height = frame.height(); 53 int height = frame.height();
54 int stride_y = frame.video_frame_buffer()->StrideY(); 54 int stride_y = frame.stride(kYPlane);
55 int stride_u = frame.video_frame_buffer()->StrideU(); 55 int stride_u = frame.stride(kUPlane);
56 int stride_v = frame.video_frame_buffer()->StrideV(); 56 int stride_v = frame.stride(kVPlane);
57 // Verify that allocated size was computed correctly. 57 // Verify that allocated size was computed correctly.
58 EXPECT_EQ(ExpectedSize(stride_y, height, kYPlane), 58 EXPECT_EQ(ExpectedSize(stride_y, height, kYPlane),
59 frame.allocated_size(kYPlane)); 59 frame.allocated_size(kYPlane));
60 EXPECT_EQ(ExpectedSize(stride_u, height, kUPlane), 60 EXPECT_EQ(ExpectedSize(stride_u, height, kUPlane),
61 frame.allocated_size(kUPlane)); 61 frame.allocated_size(kUPlane));
62 EXPECT_EQ(ExpectedSize(stride_v, height, kVPlane), 62 EXPECT_EQ(ExpectedSize(stride_v, height, kVPlane),
63 frame.allocated_size(kVPlane)); 63 frame.allocated_size(kVPlane));
64 } 64 }
65 65
66 TEST(TestVideoFrame, CopyFrame) { 66 TEST(TestVideoFrame, CopyFrame) {
(...skipping 27 matching lines...) Expand all
94 width + 5, height + 5, stride_y + 5, 94 width + 5, height + 5, stride_y + 5,
95 stride_u, stride_v, kRotation); 95 stride_u, stride_v, kRotation);
96 // Frame of smaller dimensions. 96 // Frame of smaller dimensions.
97 small_frame.CopyFrame(big_frame); 97 small_frame.CopyFrame(big_frame);
98 EXPECT_TRUE(test::FramesEqual(small_frame, big_frame)); 98 EXPECT_TRUE(test::FramesEqual(small_frame, big_frame));
99 EXPECT_EQ(kRotation, small_frame.rotation()); 99 EXPECT_EQ(kRotation, small_frame.rotation());
100 100
101 // Frame of larger dimensions. 101 // Frame of larger dimensions.
102 small_frame.CreateEmptyFrame(width, height, 102 small_frame.CreateEmptyFrame(width, height,
103 stride_y, stride_u, stride_v); 103 stride_y, stride_u, stride_v);
104 memset(small_frame.video_frame_buffer()->MutableDataY(), 1, 104 memset(small_frame.buffer(kYPlane), 1, small_frame.allocated_size(kYPlane));
105 small_frame.allocated_size(kYPlane)); 105 memset(small_frame.buffer(kUPlane), 2, small_frame.allocated_size(kUPlane));
106 memset(small_frame.video_frame_buffer()->MutableDataU(), 2, 106 memset(small_frame.buffer(kVPlane), 3, small_frame.allocated_size(kVPlane));
107 small_frame.allocated_size(kUPlane));
108 memset(small_frame.video_frame_buffer()->MutableDataV(), 3,
109 small_frame.allocated_size(kVPlane));
110 big_frame.CopyFrame(small_frame); 107 big_frame.CopyFrame(small_frame);
111 EXPECT_TRUE(test::FramesEqual(small_frame, big_frame)); 108 EXPECT_TRUE(test::FramesEqual(small_frame, big_frame));
112 } 109 }
113 110
114 TEST(TestVideoFrame, ShallowCopy) { 111 TEST(TestVideoFrame, ShallowCopy) {
115 uint32_t timestamp = 1; 112 uint32_t timestamp = 1;
116 int64_t ntp_time_ms = 2; 113 int64_t ntp_time_ms = 2;
117 int64_t render_time_ms = 3; 114 int64_t render_time_ms = 3;
118 int stride_y = 15; 115 int stride_y = 15;
119 int stride_u = 10; 116 int stride_u = 10;
(...skipping 17 matching lines...) Expand all
137 frame1.set_timestamp(timestamp); 134 frame1.set_timestamp(timestamp);
138 frame1.set_ntp_time_ms(ntp_time_ms); 135 frame1.set_ntp_time_ms(ntp_time_ms);
139 frame1.set_render_time_ms(render_time_ms); 136 frame1.set_render_time_ms(render_time_ms);
140 VideoFrame frame2; 137 VideoFrame frame2;
141 frame2.ShallowCopy(frame1); 138 frame2.ShallowCopy(frame1);
142 139
143 // To be able to access the buffers, we need const pointers to the frames. 140 // To be able to access the buffers, we need const pointers to the frames.
144 const VideoFrame* const_frame1_ptr = &frame1; 141 const VideoFrame* const_frame1_ptr = &frame1;
145 const VideoFrame* const_frame2_ptr = &frame2; 142 const VideoFrame* const_frame2_ptr = &frame2;
146 143
147 EXPECT_TRUE(const_frame1_ptr->video_frame_buffer()->DataY() == 144 EXPECT_TRUE(const_frame1_ptr->buffer(kYPlane) ==
148 const_frame2_ptr->video_frame_buffer()->DataY()); 145 const_frame2_ptr->buffer(kYPlane));
149 EXPECT_TRUE(const_frame1_ptr->video_frame_buffer()->DataU() == 146 EXPECT_TRUE(const_frame1_ptr->buffer(kUPlane) ==
150 const_frame2_ptr->video_frame_buffer()->DataU()); 147 const_frame2_ptr->buffer(kUPlane));
151 EXPECT_TRUE(const_frame1_ptr->video_frame_buffer()->DataV() == 148 EXPECT_TRUE(const_frame1_ptr->buffer(kVPlane) ==
152 const_frame2_ptr->video_frame_buffer()->DataV()); 149 const_frame2_ptr->buffer(kVPlane));
153 150
154 EXPECT_EQ(frame2.timestamp(), frame1.timestamp()); 151 EXPECT_EQ(frame2.timestamp(), frame1.timestamp());
155 EXPECT_EQ(frame2.ntp_time_ms(), frame1.ntp_time_ms()); 152 EXPECT_EQ(frame2.ntp_time_ms(), frame1.ntp_time_ms());
156 EXPECT_EQ(frame2.render_time_ms(), frame1.render_time_ms()); 153 EXPECT_EQ(frame2.render_time_ms(), frame1.render_time_ms());
157 EXPECT_EQ(frame2.rotation(), frame1.rotation()); 154 EXPECT_EQ(frame2.rotation(), frame1.rotation());
158 155
159 frame2.set_timestamp(timestamp + 1); 156 frame2.set_timestamp(timestamp + 1);
160 frame2.set_ntp_time_ms(ntp_time_ms + 1); 157 frame2.set_ntp_time_ms(ntp_time_ms + 1);
161 frame2.set_render_time_ms(render_time_ms + 1); 158 frame2.set_render_time_ms(render_time_ms + 1);
162 frame2.set_rotation(kVideoRotation_90); 159 frame2.set_rotation(kVideoRotation_90);
(...skipping 17 matching lines...) Expand all
180 uint8_t buffer_y[kSizeY]; 177 uint8_t buffer_y[kSizeY];
181 uint8_t buffer_u[kSizeUv]; 178 uint8_t buffer_u[kSizeUv];
182 uint8_t buffer_v[kSizeUv]; 179 uint8_t buffer_v[kSizeUv];
183 memset(buffer_y, 16, kSizeY); 180 memset(buffer_y, 16, kSizeY);
184 memset(buffer_u, 8, kSizeUv); 181 memset(buffer_u, 8, kSizeUv);
185 memset(buffer_v, 4, kSizeUv); 182 memset(buffer_v, 4, kSizeUv);
186 frame2.CreateFrame(buffer_y, buffer_u, buffer_v, 183 frame2.CreateFrame(buffer_y, buffer_u, buffer_v,
187 width, height, stride_y, stride_uv, stride_uv, 184 width, height, stride_y, stride_uv, stride_uv,
188 kVideoRotation_0); 185 kVideoRotation_0);
189 // Expect exactly the same pixel data. 186 // Expect exactly the same pixel data.
190 EXPECT_TRUE(test::EqualPlane(buffer_y, frame2.video_frame_buffer()->DataY(), 187 EXPECT_TRUE(
191 stride_y, 15, 15)); 188 test::EqualPlane(buffer_y, frame2.buffer(kYPlane), stride_y, 15, 15));
192 EXPECT_TRUE(test::EqualPlane(buffer_u, frame2.video_frame_buffer()->DataU(), 189 EXPECT_TRUE(
193 stride_uv, 8, 8)); 190 test::EqualPlane(buffer_u, frame2.buffer(kUPlane), stride_uv, 8, 8));
194 EXPECT_TRUE(test::EqualPlane(buffer_v, frame2.video_frame_buffer()->DataV(), 191 EXPECT_TRUE(
195 stride_uv, 8, 8)); 192 test::EqualPlane(buffer_v, frame2.buffer(kVPlane), stride_uv, 8, 8));
196 193
197 // Compare size. 194 // Compare size.
198 EXPECT_LE(kSizeY, frame2.allocated_size(kYPlane)); 195 EXPECT_LE(kSizeY, frame2.allocated_size(kYPlane));
199 EXPECT_LE(kSizeUv, frame2.allocated_size(kUPlane)); 196 EXPECT_LE(kSizeUv, frame2.allocated_size(kUPlane));
200 EXPECT_LE(kSizeUv, frame2.allocated_size(kVPlane)); 197 EXPECT_LE(kSizeUv, frame2.allocated_size(kVPlane));
201 } 198 }
202 199
203 TEST(TestVideoFrame, ReuseAllocation) { 200 TEST(TestVideoFrame, ReuseAllocation) {
204 VideoFrame frame; 201 VideoFrame frame;
205 frame.CreateEmptyFrame(640, 320, 640, 320, 320); 202 frame.CreateEmptyFrame(640, 320, 640, 320, 320);
206 const uint8_t* y = frame.video_frame_buffer()->DataY(); 203 const uint8_t* y = frame.buffer(kYPlane);
207 const uint8_t* u = frame.video_frame_buffer()->DataU(); 204 const uint8_t* u = frame.buffer(kUPlane);
208 const uint8_t* v = frame.video_frame_buffer()->DataV(); 205 const uint8_t* v = frame.buffer(kVPlane);
209 frame.CreateEmptyFrame(640, 320, 640, 320, 320); 206 frame.CreateEmptyFrame(640, 320, 640, 320, 320);
210 EXPECT_EQ(y, frame.video_frame_buffer()->DataY()); 207 EXPECT_EQ(y, frame.buffer(kYPlane));
211 EXPECT_EQ(u, frame.video_frame_buffer()->DataU()); 208 EXPECT_EQ(u, frame.buffer(kUPlane));
212 EXPECT_EQ(v, frame.video_frame_buffer()->DataV()); 209 EXPECT_EQ(v, frame.buffer(kVPlane));
213 } 210 }
214 211
215 TEST(TestVideoFrame, FailToReuseAllocation) { 212 TEST(TestVideoFrame, FailToReuseAllocation) {
216 VideoFrame frame1; 213 VideoFrame frame1;
217 frame1.CreateEmptyFrame(640, 320, 640, 320, 320); 214 frame1.CreateEmptyFrame(640, 320, 640, 320, 320);
218 const uint8_t* y = frame1.video_frame_buffer()->DataY(); 215 const uint8_t* y = frame1.buffer(kYPlane);
219 const uint8_t* u = frame1.video_frame_buffer()->DataU(); 216 const uint8_t* u = frame1.buffer(kUPlane);
220 const uint8_t* v = frame1.video_frame_buffer()->DataV(); 217 const uint8_t* v = frame1.buffer(kVPlane);
221 // Make a shallow copy of |frame1|. 218 // Make a shallow copy of |frame1|.
222 VideoFrame frame2(frame1.video_frame_buffer(), 0, 0, kVideoRotation_0); 219 VideoFrame frame2(frame1.video_frame_buffer(), 0, 0, kVideoRotation_0);
223 frame1.CreateEmptyFrame(640, 320, 640, 320, 320); 220 frame1.CreateEmptyFrame(640, 320, 640, 320, 320);
224 EXPECT_NE(y, frame1.video_frame_buffer()->DataY()); 221 EXPECT_NE(y, frame1.buffer(kYPlane));
225 EXPECT_NE(u, frame1.video_frame_buffer()->DataU()); 222 EXPECT_NE(u, frame1.buffer(kUPlane));
226 EXPECT_NE(v, frame1.video_frame_buffer()->DataV()); 223 EXPECT_NE(v, frame1.buffer(kVPlane));
227 } 224 }
228 225
229 TEST(TestVideoFrame, TextureInitialValues) { 226 TEST(TestVideoFrame, TextureInitialValues) {
230 test::FakeNativeHandle* handle = new test::FakeNativeHandle(); 227 test::FakeNativeHandle* handle = new test::FakeNativeHandle();
231 VideoFrame frame = test::FakeNativeHandle::CreateFrame( 228 VideoFrame frame = test::FakeNativeHandle::CreateFrame(
232 handle, 640, 480, 100, 10, webrtc::kVideoRotation_0); 229 handle, 640, 480, 100, 10, webrtc::kVideoRotation_0);
233 EXPECT_EQ(640, frame.width()); 230 EXPECT_EQ(640, frame.width());
234 EXPECT_EQ(480, frame.height()); 231 EXPECT_EQ(480, frame.height());
235 EXPECT_EQ(100u, frame.timestamp()); 232 EXPECT_EQ(100u, frame.timestamp());
236 EXPECT_EQ(10, frame.render_time_ms()); 233 EXPECT_EQ(10, frame.render_time_ms());
(...skipping 10 matching lines...) Expand all
247 rtc::scoped_refptr<I420Buffer> buf1( 244 rtc::scoped_refptr<I420Buffer> buf1(
248 new rtc::RefCountedObject<I420Buffer>(20, 10)); 245 new rtc::RefCountedObject<I420Buffer>(20, 10));
249 memset(buf1->MutableDataY(), 1, 200); 246 memset(buf1->MutableDataY(), 1, 200);
250 memset(buf1->MutableDataU(), 2, 50); 247 memset(buf1->MutableDataU(), 2, 50);
251 memset(buf1->MutableDataV(), 3, 50); 248 memset(buf1->MutableDataV(), 3, 50);
252 rtc::scoped_refptr<I420Buffer> buf2 = I420Buffer::Copy(buf1); 249 rtc::scoped_refptr<I420Buffer> buf2 = I420Buffer::Copy(buf1);
253 EXPECT_TRUE(test::FrameBufsEqual(buf1, buf2)); 250 EXPECT_TRUE(test::FrameBufsEqual(buf1, buf2));
254 } 251 }
255 252
256 } // namespace webrtc 253 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/api/java/jni/androidmediaencoder_jni.cc ('k') | webrtc/common_video/libyuv/libyuv_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698