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

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: Rebase. 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.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 17 matching lines...) Expand all
177 uint8_t buffer_y[kSizeY]; 180 uint8_t buffer_y[kSizeY];
178 uint8_t buffer_u[kSizeUv]; 181 uint8_t buffer_u[kSizeUv];
179 uint8_t buffer_v[kSizeUv]; 182 uint8_t buffer_v[kSizeUv];
180 memset(buffer_y, 16, kSizeY); 183 memset(buffer_y, 16, kSizeY);
181 memset(buffer_u, 8, kSizeUv); 184 memset(buffer_u, 8, kSizeUv);
182 memset(buffer_v, 4, kSizeUv); 185 memset(buffer_v, 4, kSizeUv);
183 frame2.CreateFrame(buffer_y, buffer_u, buffer_v, 186 frame2.CreateFrame(buffer_y, buffer_u, buffer_v,
184 width, height, stride_y, stride_uv, stride_uv, 187 width, height, stride_y, stride_uv, stride_uv,
185 kVideoRotation_0); 188 kVideoRotation_0);
186 // Expect exactly the same pixel data. 189 // Expect exactly the same pixel data.
187 EXPECT_TRUE( 190 EXPECT_TRUE(test::EqualPlane(buffer_y, frame2.video_frame_buffer()->DataY(),
188 test::EqualPlane(buffer_y, frame2.buffer(kYPlane), stride_y, 15, 15)); 191 stride_y, 15, 15));
189 EXPECT_TRUE( 192 EXPECT_TRUE(test::EqualPlane(buffer_u, frame2.video_frame_buffer()->DataU(),
190 test::EqualPlane(buffer_u, frame2.buffer(kUPlane), stride_uv, 8, 8)); 193 stride_uv, 8, 8));
191 EXPECT_TRUE( 194 EXPECT_TRUE(test::EqualPlane(buffer_v, frame2.video_frame_buffer()->DataV(),
192 test::EqualPlane(buffer_v, frame2.buffer(kVPlane), stride_uv, 8, 8)); 195 stride_uv, 8, 8));
193 196
194 // Compare size. 197 // Compare size.
195 EXPECT_LE(kSizeY, frame2.allocated_size(kYPlane)); 198 EXPECT_LE(kSizeY, frame2.allocated_size(kYPlane));
196 EXPECT_LE(kSizeUv, frame2.allocated_size(kUPlane)); 199 EXPECT_LE(kSizeUv, frame2.allocated_size(kUPlane));
197 EXPECT_LE(kSizeUv, frame2.allocated_size(kVPlane)); 200 EXPECT_LE(kSizeUv, frame2.allocated_size(kVPlane));
198 } 201 }
199 202
200 TEST(TestVideoFrame, ReuseAllocation) { 203 TEST(TestVideoFrame, ReuseAllocation) {
201 VideoFrame frame; 204 VideoFrame frame;
202 frame.CreateEmptyFrame(640, 320, 640, 320, 320); 205 frame.CreateEmptyFrame(640, 320, 640, 320, 320);
203 const uint8_t* y = frame.buffer(kYPlane); 206 const uint8_t* y = frame.video_frame_buffer()->DataY();
204 const uint8_t* u = frame.buffer(kUPlane); 207 const uint8_t* u = frame.video_frame_buffer()->DataU();
205 const uint8_t* v = frame.buffer(kVPlane); 208 const uint8_t* v = frame.video_frame_buffer()->DataV();
206 frame.CreateEmptyFrame(640, 320, 640, 320, 320); 209 frame.CreateEmptyFrame(640, 320, 640, 320, 320);
207 EXPECT_EQ(y, frame.buffer(kYPlane)); 210 EXPECT_EQ(y, frame.video_frame_buffer()->DataY());
208 EXPECT_EQ(u, frame.buffer(kUPlane)); 211 EXPECT_EQ(u, frame.video_frame_buffer()->DataU());
209 EXPECT_EQ(v, frame.buffer(kVPlane)); 212 EXPECT_EQ(v, frame.video_frame_buffer()->DataV());
210 } 213 }
211 214
212 TEST(TestVideoFrame, FailToReuseAllocation) { 215 TEST(TestVideoFrame, FailToReuseAllocation) {
213 VideoFrame frame1; 216 VideoFrame frame1;
214 frame1.CreateEmptyFrame(640, 320, 640, 320, 320); 217 frame1.CreateEmptyFrame(640, 320, 640, 320, 320);
215 const uint8_t* y = frame1.buffer(kYPlane); 218 const uint8_t* y = frame1.video_frame_buffer()->DataY();
216 const uint8_t* u = frame1.buffer(kUPlane); 219 const uint8_t* u = frame1.video_frame_buffer()->DataU();
217 const uint8_t* v = frame1.buffer(kVPlane); 220 const uint8_t* v = frame1.video_frame_buffer()->DataV();
218 // Make a shallow copy of |frame1|. 221 // Make a shallow copy of |frame1|.
219 VideoFrame frame2(frame1.video_frame_buffer(), 0, 0, kVideoRotation_0); 222 VideoFrame frame2(frame1.video_frame_buffer(), 0, 0, kVideoRotation_0);
220 frame1.CreateEmptyFrame(640, 320, 640, 320, 320); 223 frame1.CreateEmptyFrame(640, 320, 640, 320, 320);
221 EXPECT_NE(y, frame1.buffer(kYPlane)); 224 EXPECT_NE(y, frame1.video_frame_buffer()->DataY());
222 EXPECT_NE(u, frame1.buffer(kUPlane)); 225 EXPECT_NE(u, frame1.video_frame_buffer()->DataU());
223 EXPECT_NE(v, frame1.buffer(kVPlane)); 226 EXPECT_NE(v, frame1.video_frame_buffer()->DataV());
224 } 227 }
225 228
226 TEST(TestVideoFrame, TextureInitialValues) { 229 TEST(TestVideoFrame, TextureInitialValues) {
227 test::FakeNativeHandle* handle = new test::FakeNativeHandle(); 230 test::FakeNativeHandle* handle = new test::FakeNativeHandle();
228 VideoFrame frame = test::FakeNativeHandle::CreateFrame( 231 VideoFrame frame = test::FakeNativeHandle::CreateFrame(
229 handle, 640, 480, 100, 10, webrtc::kVideoRotation_0); 232 handle, 640, 480, 100, 10, webrtc::kVideoRotation_0);
230 EXPECT_EQ(640, frame.width()); 233 EXPECT_EQ(640, frame.width());
231 EXPECT_EQ(480, frame.height()); 234 EXPECT_EQ(480, frame.height());
232 EXPECT_EQ(100u, frame.timestamp()); 235 EXPECT_EQ(100u, frame.timestamp());
233 EXPECT_EQ(10, frame.render_time_ms()); 236 EXPECT_EQ(10, frame.render_time_ms());
(...skipping 10 matching lines...) Expand all
244 rtc::scoped_refptr<I420Buffer> buf1( 247 rtc::scoped_refptr<I420Buffer> buf1(
245 new rtc::RefCountedObject<I420Buffer>(20, 10)); 248 new rtc::RefCountedObject<I420Buffer>(20, 10));
246 memset(buf1->MutableDataY(), 1, 200); 249 memset(buf1->MutableDataY(), 1, 200);
247 memset(buf1->MutableDataU(), 2, 50); 250 memset(buf1->MutableDataU(), 2, 50);
248 memset(buf1->MutableDataV(), 3, 50); 251 memset(buf1->MutableDataV(), 3, 50);
249 rtc::scoped_refptr<I420Buffer> buf2 = I420Buffer::Copy(buf1); 252 rtc::scoped_refptr<I420Buffer> buf2 = I420Buffer::Copy(buf1);
250 EXPECT_TRUE(test::FrameBufsEqual(buf1, buf2)); 253 EXPECT_TRUE(test::FrameBufsEqual(buf1, buf2));
251 } 254 }
252 255
253 } // namespace webrtc 256 } // 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