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

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

Issue 1900673002: Delete webrtc::VideoFrame methods buffer and stride. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Update ios video_render. Created 4 years, 8 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.stride(kYPlane); 54 int stride_y = frame.video_frame_buffer()->StrideY();
55 int stride_u = frame.stride(kUPlane); 55 int stride_u = frame.video_frame_buffer()->StrideU();
56 int stride_v = frame.stride(kVPlane); 56 int stride_v = frame.video_frame_buffer()->StrideV();
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.buffer(kYPlane), 1, small_frame.allocated_size(kYPlane)); 104 memset(small_frame.video_frame_buffer()->MutableDataY(), 1,
105 memset(small_frame.buffer(kUPlane), 2, small_frame.allocated_size(kUPlane)); 105 small_frame.allocated_size(kYPlane));
106 memset(small_frame.buffer(kVPlane), 3, small_frame.allocated_size(kVPlane)); 106 memset(small_frame.video_frame_buffer()->MutableDataU(), 2,
107 small_frame.allocated_size(kUPlane));
108 memset(small_frame.video_frame_buffer()->MutableDataV(), 3,
109 small_frame.allocated_size(kVPlane));
107 big_frame.CopyFrame(small_frame); 110 big_frame.CopyFrame(small_frame);
108 EXPECT_TRUE(test::FramesEqual(small_frame, big_frame)); 111 EXPECT_TRUE(test::FramesEqual(small_frame, big_frame));
109 } 112 }
110 113
111 TEST(TestVideoFrame, ShallowCopy) { 114 TEST(TestVideoFrame, ShallowCopy) {
112 uint32_t timestamp = 1; 115 uint32_t timestamp = 1;
113 int64_t ntp_time_ms = 2; 116 int64_t ntp_time_ms = 2;
114 int64_t render_time_ms = 3; 117 int64_t render_time_ms = 3;
115 int stride_y = 15; 118 int stride_y = 15;
116 int stride_u = 10; 119 int stride_u = 10;
(...skipping 17 matching lines...) Expand all
134 frame1.set_timestamp(timestamp); 137 frame1.set_timestamp(timestamp);
135 frame1.set_ntp_time_ms(ntp_time_ms); 138 frame1.set_ntp_time_ms(ntp_time_ms);
136 frame1.set_render_time_ms(render_time_ms); 139 frame1.set_render_time_ms(render_time_ms);
137 VideoFrame frame2; 140 VideoFrame frame2;
138 frame2.ShallowCopy(frame1); 141 frame2.ShallowCopy(frame1);
139 142
140 // To be able to access the buffers, we need const pointers to the frames. 143 // To be able to access the buffers, we need const pointers to the frames.
141 const VideoFrame* const_frame1_ptr = &frame1; 144 const VideoFrame* const_frame1_ptr = &frame1;
142 const VideoFrame* const_frame2_ptr = &frame2; 145 const VideoFrame* const_frame2_ptr = &frame2;
143 146
144 EXPECT_TRUE(const_frame1_ptr->buffer(kYPlane) == 147 EXPECT_TRUE(const_frame1_ptr->video_frame_buffer()->DataY() ==
145 const_frame2_ptr->buffer(kYPlane)); 148 const_frame2_ptr->video_frame_buffer()->DataY());
146 EXPECT_TRUE(const_frame1_ptr->buffer(kUPlane) == 149 EXPECT_TRUE(const_frame1_ptr->video_frame_buffer()->DataU() ==
147 const_frame2_ptr->buffer(kUPlane)); 150 const_frame2_ptr->video_frame_buffer()->DataU());
148 EXPECT_TRUE(const_frame1_ptr->buffer(kVPlane) == 151 EXPECT_TRUE(const_frame1_ptr->video_frame_buffer()->DataV() ==
149 const_frame2_ptr->buffer(kVPlane)); 152 const_frame2_ptr->video_frame_buffer()->DataV());
150 153
151 EXPECT_EQ(frame2.timestamp(), frame1.timestamp()); 154 EXPECT_EQ(frame2.timestamp(), frame1.timestamp());
152 EXPECT_EQ(frame2.ntp_time_ms(), frame1.ntp_time_ms()); 155 EXPECT_EQ(frame2.ntp_time_ms(), frame1.ntp_time_ms());
153 EXPECT_EQ(frame2.render_time_ms(), frame1.render_time_ms()); 156 EXPECT_EQ(frame2.render_time_ms(), frame1.render_time_ms());
154 EXPECT_EQ(frame2.rotation(), frame1.rotation()); 157 EXPECT_EQ(frame2.rotation(), frame1.rotation());
155 158
156 frame2.set_timestamp(timestamp + 1); 159 frame2.set_timestamp(timestamp + 1);
157 frame2.set_ntp_time_ms(ntp_time_ms + 1); 160 frame2.set_ntp_time_ms(ntp_time_ms + 1);
158 frame2.set_render_time_ms(render_time_ms + 1); 161 frame2.set_render_time_ms(render_time_ms + 1);
159 frame2.set_rotation(kVideoRotation_90); 162 frame2.set_rotation(kVideoRotation_90);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 uint8_t buffer_y[kSizeY]; 195 uint8_t buffer_y[kSizeY];
193 uint8_t buffer_u[kSizeUv]; 196 uint8_t buffer_u[kSizeUv];
194 uint8_t buffer_v[kSizeUv]; 197 uint8_t buffer_v[kSizeUv];
195 memset(buffer_y, 16, kSizeY); 198 memset(buffer_y, 16, kSizeY);
196 memset(buffer_u, 8, kSizeUv); 199 memset(buffer_u, 8, kSizeUv);
197 memset(buffer_v, 4, kSizeUv); 200 memset(buffer_v, 4, kSizeUv);
198 frame2.CreateFrame(buffer_y, buffer_u, buffer_v, 201 frame2.CreateFrame(buffer_y, buffer_u, buffer_v,
199 width, height, stride_y, stride_uv, stride_uv, 202 width, height, stride_y, stride_uv, stride_uv,
200 kVideoRotation_0); 203 kVideoRotation_0);
201 // Expect exactly the same pixel data. 204 // Expect exactly the same pixel data.
202 EXPECT_TRUE( 205 EXPECT_TRUE(test::EqualPlane(buffer_y, frame2.video_frame_buffer()->DataY(),
203 test::EqualPlane(buffer_y, frame2.buffer(kYPlane), stride_y, 15, 15)); 206 stride_y, 15, 15));
204 EXPECT_TRUE( 207 EXPECT_TRUE(test::EqualPlane(buffer_u, frame2.video_frame_buffer()->DataU(),
205 test::EqualPlane(buffer_u, frame2.buffer(kUPlane), stride_uv, 8, 8)); 208 stride_uv, 8, 8));
206 EXPECT_TRUE( 209 EXPECT_TRUE(test::EqualPlane(buffer_v, frame2.video_frame_buffer()->DataV(),
207 test::EqualPlane(buffer_v, frame2.buffer(kVPlane), stride_uv, 8, 8)); 210 stride_uv, 8, 8));
208 211
209 // Compare size. 212 // Compare size.
210 EXPECT_LE(kSizeY, frame2.allocated_size(kYPlane)); 213 EXPECT_LE(kSizeY, frame2.allocated_size(kYPlane));
211 EXPECT_LE(kSizeUv, frame2.allocated_size(kUPlane)); 214 EXPECT_LE(kSizeUv, frame2.allocated_size(kUPlane));
212 EXPECT_LE(kSizeUv, frame2.allocated_size(kVPlane)); 215 EXPECT_LE(kSizeUv, frame2.allocated_size(kVPlane));
213 } 216 }
214 217
215 TEST(TestVideoFrame, ReuseAllocation) { 218 TEST(TestVideoFrame, ReuseAllocation) {
216 VideoFrame frame; 219 VideoFrame frame;
217 frame.CreateEmptyFrame(640, 320, 640, 320, 320); 220 frame.CreateEmptyFrame(640, 320, 640, 320, 320);
218 const uint8_t* y = frame.buffer(kYPlane); 221 const uint8_t* y = frame.video_frame_buffer()->DataY();
219 const uint8_t* u = frame.buffer(kUPlane); 222 const uint8_t* u = frame.video_frame_buffer()->DataU();
220 const uint8_t* v = frame.buffer(kVPlane); 223 const uint8_t* v = frame.video_frame_buffer()->DataV();
221 frame.CreateEmptyFrame(640, 320, 640, 320, 320); 224 frame.CreateEmptyFrame(640, 320, 640, 320, 320);
222 EXPECT_EQ(y, frame.buffer(kYPlane)); 225 EXPECT_EQ(y, frame.video_frame_buffer()->DataY());
223 EXPECT_EQ(u, frame.buffer(kUPlane)); 226 EXPECT_EQ(u, frame.video_frame_buffer()->DataU());
224 EXPECT_EQ(v, frame.buffer(kVPlane)); 227 EXPECT_EQ(v, frame.video_frame_buffer()->DataV());
225 } 228 }
226 229
227 TEST(TestVideoFrame, FailToReuseAllocation) { 230 TEST(TestVideoFrame, FailToReuseAllocation) {
228 VideoFrame frame1; 231 VideoFrame frame1;
229 frame1.CreateEmptyFrame(640, 320, 640, 320, 320); 232 frame1.CreateEmptyFrame(640, 320, 640, 320, 320);
230 const uint8_t* y = frame1.buffer(kYPlane); 233 const uint8_t* y = frame1.video_frame_buffer()->DataY();
231 const uint8_t* u = frame1.buffer(kUPlane); 234 const uint8_t* u = frame1.video_frame_buffer()->DataU();
232 const uint8_t* v = frame1.buffer(kVPlane); 235 const uint8_t* v = frame1.video_frame_buffer()->DataV();
233 // Make a shallow copy of |frame1|. 236 // Make a shallow copy of |frame1|.
234 VideoFrame frame2(frame1.video_frame_buffer(), 0, 0, kVideoRotation_0); 237 VideoFrame frame2(frame1.video_frame_buffer(), 0, 0, kVideoRotation_0);
235 frame1.CreateEmptyFrame(640, 320, 640, 320, 320); 238 frame1.CreateEmptyFrame(640, 320, 640, 320, 320);
236 EXPECT_NE(y, frame1.buffer(kYPlane)); 239 EXPECT_NE(y, frame1.video_frame_buffer()->DataY());
237 EXPECT_NE(u, frame1.buffer(kUPlane)); 240 EXPECT_NE(u, frame1.video_frame_buffer()->DataU());
238 EXPECT_NE(v, frame1.buffer(kVPlane)); 241 EXPECT_NE(v, frame1.video_frame_buffer()->DataV());
239 } 242 }
240 243
241 TEST(TestVideoFrame, TextureInitialValues) { 244 TEST(TestVideoFrame, TextureInitialValues) {
242 test::FakeNativeHandle* handle = new test::FakeNativeHandle(); 245 test::FakeNativeHandle* handle = new test::FakeNativeHandle();
243 VideoFrame frame = test::FakeNativeHandle::CreateFrame( 246 VideoFrame frame = test::FakeNativeHandle::CreateFrame(
244 handle, 640, 480, 100, 10, webrtc::kVideoRotation_0); 247 handle, 640, 480, 100, 10, webrtc::kVideoRotation_0);
245 EXPECT_EQ(640, frame.width()); 248 EXPECT_EQ(640, frame.width());
246 EXPECT_EQ(480, frame.height()); 249 EXPECT_EQ(480, frame.height());
247 EXPECT_EQ(100u, frame.timestamp()); 250 EXPECT_EQ(100u, frame.timestamp());
248 EXPECT_EQ(10, frame.render_time_ms()); 251 EXPECT_EQ(10, frame.render_time_ms());
(...skipping 10 matching lines...) Expand all
259 rtc::scoped_refptr<I420Buffer> buf1( 262 rtc::scoped_refptr<I420Buffer> buf1(
260 new rtc::RefCountedObject<I420Buffer>(20, 10)); 263 new rtc::RefCountedObject<I420Buffer>(20, 10));
261 memset(buf1->MutableDataY(), 1, 200); 264 memset(buf1->MutableDataY(), 1, 200);
262 memset(buf1->MutableDataU(), 2, 50); 265 memset(buf1->MutableDataU(), 2, 50);
263 memset(buf1->MutableDataV(), 3, 50); 266 memset(buf1->MutableDataV(), 3, 50);
264 rtc::scoped_refptr<I420Buffer> buf2 = I420Buffer::Copy(buf1); 267 rtc::scoped_refptr<I420Buffer> buf2 = I420Buffer::Copy(buf1);
265 EXPECT_TRUE(test::FrameBufsEqual(buf1, buf2)); 268 EXPECT_TRUE(test::FrameBufsEqual(buf1, buf2));
266 } 269 }
267 270
268 } // namespace webrtc 271 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698