OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2004 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 |
11 #ifndef WEBRTC_MEDIA_BASE_VIDEOFRAME_UNITTEST_H_ | 11 #ifndef WEBRTC_MEDIA_BASE_VIDEOFRAME_UNITTEST_H_ |
12 #define WEBRTC_MEDIA_BASE_VIDEOFRAME_UNITTEST_H_ | 12 #define WEBRTC_MEDIA_BASE_VIDEOFRAME_UNITTEST_H_ |
13 | 13 |
14 #include <algorithm> | 14 #include <algorithm> |
| 15 #include <memory> |
15 #include <string> | 16 #include <string> |
16 | 17 |
17 #include "libyuv/convert.h" | 18 #include "libyuv/convert.h" |
18 #include "libyuv/convert_from.h" | 19 #include "libyuv/convert_from.h" |
19 #include "libyuv/planar_functions.h" | 20 #include "libyuv/planar_functions.h" |
20 #include "libyuv/rotate.h" | 21 #include "libyuv/rotate.h" |
21 #include "webrtc/base/gunit.h" | 22 #include "webrtc/base/gunit.h" |
22 #include "webrtc/base/pathutils.h" | 23 #include "webrtc/base/pathutils.h" |
23 #include "webrtc/base/stream.h" | 24 #include "webrtc/base/stream.h" |
24 #include "webrtc/base/stringutils.h" | 25 #include "webrtc/base/stringutils.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 webrtc::kVideoRotation_0, frame); | 75 webrtc::kVideoRotation_0, frame); |
75 } | 76 } |
76 bool LoadFrame(const std::string& filename, | 77 bool LoadFrame(const std::string& filename, |
77 uint32_t format, | 78 uint32_t format, |
78 int32_t width, | 79 int32_t width, |
79 int32_t height, | 80 int32_t height, |
80 int dw, | 81 int dw, |
81 int dh, | 82 int dh, |
82 webrtc::VideoRotation rotation, | 83 webrtc::VideoRotation rotation, |
83 T* frame) { | 84 T* frame) { |
84 rtc::scoped_ptr<rtc::MemoryStream> ms(LoadSample(filename)); | 85 std::unique_ptr<rtc::MemoryStream> ms(LoadSample(filename)); |
85 return LoadFrame(ms.get(), format, width, height, dw, dh, rotation, frame); | 86 return LoadFrame(ms.get(), format, width, height, dw, dh, rotation, frame); |
86 } | 87 } |
87 // Load a video frame from a memory stream. | 88 // Load a video frame from a memory stream. |
88 bool LoadFrame(rtc::MemoryStream* ms, | 89 bool LoadFrame(rtc::MemoryStream* ms, |
89 uint32_t format, | 90 uint32_t format, |
90 int32_t width, | 91 int32_t width, |
91 int32_t height, | 92 int32_t height, |
92 T* frame) { | 93 T* frame) { |
93 return LoadFrame(ms, format, width, height, width, abs(height), | 94 return LoadFrame(ms, format, width, height, width, abs(height), |
94 webrtc::kVideoRotation_0, frame); | 95 webrtc::kVideoRotation_0, frame); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 bool ret = false; | 136 bool ret = false; |
136 for (int i = 0; i < repeat_; ++i) { | 137 for (int i = 0; i < repeat_; ++i) { |
137 ret = frame->Init(format, width, height, dw, dh, | 138 ret = frame->Init(format, width, height, dw, dh, |
138 sample, sample_size, 0, rotation); | 139 sample, sample_size, 0, rotation); |
139 } | 140 } |
140 return ret; | 141 return ret; |
141 } | 142 } |
142 | 143 |
143 rtc::MemoryStream* LoadSample(const std::string& filename) { | 144 rtc::MemoryStream* LoadSample(const std::string& filename) { |
144 rtc::Pathname path(cricket::GetTestFilePath(filename)); | 145 rtc::Pathname path(cricket::GetTestFilePath(filename)); |
145 rtc::scoped_ptr<rtc::FileStream> fs( | 146 std::unique_ptr<rtc::FileStream> fs( |
146 rtc::Filesystem::OpenFile(path, "rb")); | 147 rtc::Filesystem::OpenFile(path, "rb")); |
147 if (!fs.get()) { | 148 if (!fs.get()) { |
148 LOG(LS_ERROR) << "Could not open test file path: " << path.pathname() | 149 LOG(LS_ERROR) << "Could not open test file path: " << path.pathname() |
149 << " from current dir " | 150 << " from current dir " |
150 << rtc::Filesystem::GetCurrentDirectory().pathname(); | 151 << rtc::Filesystem::GetCurrentDirectory().pathname(); |
151 return NULL; | 152 return NULL; |
152 } | 153 } |
153 | 154 |
154 char buf[4096]; | 155 char buf[4096]; |
155 rtc::scoped_ptr<rtc::MemoryStream> ms( | 156 std::unique_ptr<rtc::MemoryStream> ms( |
156 new rtc::MemoryStream()); | 157 new rtc::MemoryStream()); |
157 rtc::StreamResult res = Flow(fs.get(), buf, sizeof(buf), ms.get()); | 158 rtc::StreamResult res = Flow(fs.get(), buf, sizeof(buf), ms.get()); |
158 if (res != rtc::SR_SUCCESS) { | 159 if (res != rtc::SR_SUCCESS) { |
159 LOG(LS_ERROR) << "Could not load test file path: " << path.pathname(); | 160 LOG(LS_ERROR) << "Could not load test file path: " << path.pathname(); |
160 return NULL; | 161 return NULL; |
161 } | 162 } |
162 | 163 |
163 return ms.release(); | 164 return ms.release(); |
164 } | 165 } |
165 | 166 |
166 bool DumpSample(const std::string& filename, const void* buffer, int size) { | 167 bool DumpSample(const std::string& filename, const void* buffer, int size) { |
167 rtc::Pathname path(filename); | 168 rtc::Pathname path(filename); |
168 rtc::scoped_ptr<rtc::FileStream> fs( | 169 std::unique_ptr<rtc::FileStream> fs( |
169 rtc::Filesystem::OpenFile(path, "wb")); | 170 rtc::Filesystem::OpenFile(path, "wb")); |
170 if (!fs.get()) { | 171 if (!fs.get()) { |
171 return false; | 172 return false; |
172 } | 173 } |
173 | 174 |
174 return (fs->Write(buffer, size, NULL, NULL) == rtc::SR_SUCCESS); | 175 return (fs->Write(buffer, size, NULL, NULL) == rtc::SR_SUCCESS); |
175 } | 176 } |
176 | 177 |
177 // Create a test image in the desired color space. | 178 // Create a test image in the desired color space. |
178 // The image is a checkerboard pattern with 63x63 squares, which allows | 179 // The image is a checkerboard pattern with 63x63 squares, which allows |
179 // I420 chroma artifacts to easily be seen on the square boundaries. | 180 // I420 chroma artifacts to easily be seen on the square boundaries. |
180 // The pattern is { { green, orange }, { blue, purple } } | 181 // The pattern is { { green, orange }, { blue, purple } } |
181 // There is also a gradient within each square to ensure that the luma | 182 // There is also a gradient within each square to ensure that the luma |
182 // values are handled properly. | 183 // values are handled properly. |
183 rtc::MemoryStream* CreateYuv422Sample(uint32_t fourcc, | 184 rtc::MemoryStream* CreateYuv422Sample(uint32_t fourcc, |
184 uint32_t width, | 185 uint32_t width, |
185 uint32_t height) { | 186 uint32_t height) { |
186 int y1_pos, y2_pos, u_pos, v_pos; | 187 int y1_pos, y2_pos, u_pos, v_pos; |
187 if (!GetYuv422Packing(fourcc, &y1_pos, &y2_pos, &u_pos, &v_pos)) { | 188 if (!GetYuv422Packing(fourcc, &y1_pos, &y2_pos, &u_pos, &v_pos)) { |
188 return NULL; | 189 return NULL; |
189 } | 190 } |
190 | 191 |
191 rtc::scoped_ptr<rtc::MemoryStream> ms( | 192 std::unique_ptr<rtc::MemoryStream> ms( |
192 new rtc::MemoryStream); | 193 new rtc::MemoryStream); |
193 int awidth = (width + 1) & ~1; | 194 int awidth = (width + 1) & ~1; |
194 int size = awidth * 2 * height; | 195 int size = awidth * 2 * height; |
195 if (!ms->ReserveSize(size)) { | 196 if (!ms->ReserveSize(size)) { |
196 return NULL; | 197 return NULL; |
197 } | 198 } |
198 for (uint32_t y = 0; y < height; ++y) { | 199 for (uint32_t y = 0; y < height; ++y) { |
199 for (int x = 0; x < awidth; x += 2) { | 200 for (int x = 0; x < awidth; x += 2) { |
200 uint8_t quad[4]; | 201 uint8_t quad[4]; |
201 quad[y1_pos] = (x % 63 + y % 63) + 64; | 202 quad[y1_pos] = (x % 63 + y % 63) + 64; |
202 quad[y2_pos] = ((x + 1) % 63 + y % 63) + 64; | 203 quad[y2_pos] = ((x + 1) % 63 + y % 63) + 64; |
203 quad[u_pos] = ((x / 63) & 1) ? 192 : 64; | 204 quad[u_pos] = ((x / 63) & 1) ? 192 : 64; |
204 quad[v_pos] = ((y / 63) & 1) ? 192 : 64; | 205 quad[v_pos] = ((y / 63) & 1) ? 192 : 64; |
205 ms->Write(quad, sizeof(quad), NULL, NULL); | 206 ms->Write(quad, sizeof(quad), NULL, NULL); |
206 } | 207 } |
207 } | 208 } |
208 return ms.release(); | 209 return ms.release(); |
209 } | 210 } |
210 | 211 |
211 // Create a test image for YUV 420 formats with 12 bits per pixel. | 212 // Create a test image for YUV 420 formats with 12 bits per pixel. |
212 rtc::MemoryStream* CreateYuvSample(uint32_t width, | 213 rtc::MemoryStream* CreateYuvSample(uint32_t width, |
213 uint32_t height, | 214 uint32_t height, |
214 uint32_t bpp) { | 215 uint32_t bpp) { |
215 rtc::scoped_ptr<rtc::MemoryStream> ms( | 216 std::unique_ptr<rtc::MemoryStream> ms( |
216 new rtc::MemoryStream); | 217 new rtc::MemoryStream); |
217 if (!ms->ReserveSize(width * height * bpp / 8)) { | 218 if (!ms->ReserveSize(width * height * bpp / 8)) { |
218 return NULL; | 219 return NULL; |
219 } | 220 } |
220 | 221 |
221 for (uint32_t i = 0; i < width * height * bpp / 8; ++i) { | 222 for (uint32_t i = 0; i < width * height * bpp / 8; ++i) { |
222 uint8_t value = ((i / 63) & 1) ? 192 : 64; | 223 uint8_t value = ((i / 63) & 1) ? 192 : 64; |
223 ms->Write(&value, sizeof(value), NULL, NULL); | 224 ms->Write(&value, sizeof(value), NULL, NULL); |
224 } | 225 } |
225 return ms.release(); | 226 return ms.release(); |
226 } | 227 } |
227 | 228 |
228 rtc::MemoryStream* CreateRgbSample(uint32_t fourcc, | 229 rtc::MemoryStream* CreateRgbSample(uint32_t fourcc, |
229 uint32_t width, | 230 uint32_t width, |
230 uint32_t height) { | 231 uint32_t height) { |
231 int r_pos, g_pos, b_pos, bytes; | 232 int r_pos, g_pos, b_pos, bytes; |
232 if (!GetRgbPacking(fourcc, &r_pos, &g_pos, &b_pos, &bytes)) { | 233 if (!GetRgbPacking(fourcc, &r_pos, &g_pos, &b_pos, &bytes)) { |
233 return NULL; | 234 return NULL; |
234 } | 235 } |
235 | 236 |
236 rtc::scoped_ptr<rtc::MemoryStream> ms( | 237 std::unique_ptr<rtc::MemoryStream> ms( |
237 new rtc::MemoryStream); | 238 new rtc::MemoryStream); |
238 if (!ms->ReserveSize(width * height * bytes)) { | 239 if (!ms->ReserveSize(width * height * bytes)) { |
239 return NULL; | 240 return NULL; |
240 } | 241 } |
241 | 242 |
242 for (uint32_t y = 0; y < height; ++y) { | 243 for (uint32_t y = 0; y < height; ++y) { |
243 for (uint32_t x = 0; x < width; ++x) { | 244 for (uint32_t x = 0; x < width; ++x) { |
244 uint8_t rgb[4] = {255, 255, 255, 255}; | 245 uint8_t rgb[4] = {255, 255, 255, 255}; |
245 rgb[r_pos] = ((x / 63) & 1) ? 224 : 32; | 246 rgb[r_pos] = ((x / 63) & 1) ? 224 : 32; |
246 rgb[g_pos] = (x % 63 + y % 63) + 96; | 247 rgb[g_pos] = (x % 63 + y % 63) + 96; |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 } | 499 } |
499 | 500 |
500 //////////////////////// | 501 //////////////////////// |
501 // Construction tests // | 502 // Construction tests // |
502 //////////////////////// | 503 //////////////////////// |
503 | 504 |
504 // Test constructing an image from a I420 buffer. | 505 // Test constructing an image from a I420 buffer. |
505 void ConstructI420() { | 506 void ConstructI420() { |
506 T frame; | 507 T frame; |
507 EXPECT_TRUE(IsNull(frame)); | 508 EXPECT_TRUE(IsNull(frame)); |
508 rtc::scoped_ptr<rtc::MemoryStream> ms( | 509 std::unique_ptr<rtc::MemoryStream> ms( |
509 CreateYuvSample(kWidth, kHeight, 12)); | 510 CreateYuvSample(kWidth, kHeight, 12)); |
510 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_I420, | 511 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_I420, |
511 kWidth, kHeight, &frame)); | 512 kWidth, kHeight, &frame)); |
512 | 513 |
513 const uint8_t* y = reinterpret_cast<uint8_t*>(ms.get()->GetBuffer()); | 514 const uint8_t* y = reinterpret_cast<uint8_t*>(ms.get()->GetBuffer()); |
514 const uint8_t* u = y + kWidth * kHeight; | 515 const uint8_t* u = y + kWidth * kHeight; |
515 const uint8_t* v = u + kWidth * kHeight / 4; | 516 const uint8_t* v = u + kWidth * kHeight / 4; |
516 EXPECT_TRUE(IsEqual(frame, kWidth, kHeight, 0, y, kWidth, u, | 517 EXPECT_TRUE(IsEqual(frame, kWidth, kHeight, 0, y, kWidth, u, |
517 kWidth / 2, v, kWidth / 2, 0)); | 518 kWidth / 2, v, kWidth / 2, 0)); |
518 } | 519 } |
519 | 520 |
520 // Test constructing an image from a YV12 buffer. | 521 // Test constructing an image from a YV12 buffer. |
521 void ConstructYV12() { | 522 void ConstructYV12() { |
522 T frame; | 523 T frame; |
523 rtc::scoped_ptr<rtc::MemoryStream> ms( | 524 std::unique_ptr<rtc::MemoryStream> ms( |
524 CreateYuvSample(kWidth, kHeight, 12)); | 525 CreateYuvSample(kWidth, kHeight, 12)); |
525 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YV12, | 526 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YV12, |
526 kWidth, kHeight, &frame)); | 527 kWidth, kHeight, &frame)); |
527 | 528 |
528 const uint8_t* y = reinterpret_cast<uint8_t*>(ms.get()->GetBuffer()); | 529 const uint8_t* y = reinterpret_cast<uint8_t*>(ms.get()->GetBuffer()); |
529 const uint8_t* v = y + kWidth * kHeight; | 530 const uint8_t* v = y + kWidth * kHeight; |
530 const uint8_t* u = v + kWidth * kHeight / 4; | 531 const uint8_t* u = v + kWidth * kHeight / 4; |
531 EXPECT_TRUE(IsEqual(frame, kWidth, kHeight, 0, y, kWidth, u, | 532 EXPECT_TRUE(IsEqual(frame, kWidth, kHeight, 0, y, kWidth, u, |
532 kWidth / 2, v, kWidth / 2, 0)); | 533 kWidth / 2, v, kWidth / 2, 0)); |
533 } | 534 } |
534 | 535 |
535 // Test constructing an image from a I422 buffer. | 536 // Test constructing an image from a I422 buffer. |
536 void ConstructI422() { | 537 void ConstructI422() { |
537 T frame1, frame2; | 538 T frame1, frame2; |
538 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); | 539 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); |
539 size_t buf_size = kWidth * kHeight * 2; | 540 size_t buf_size = kWidth * kHeight * 2; |
540 rtc::scoped_ptr<uint8_t[]> buf(new uint8_t[buf_size + kAlignment]); | 541 std::unique_ptr<uint8_t[]> buf(new uint8_t[buf_size + kAlignment]); |
541 uint8_t* y = ALIGNP(buf.get(), kAlignment); | 542 uint8_t* y = ALIGNP(buf.get(), kAlignment); |
542 uint8_t* u = y + kWidth * kHeight; | 543 uint8_t* u = y + kWidth * kHeight; |
543 uint8_t* v = u + (kWidth / 2) * kHeight; | 544 uint8_t* v = u + (kWidth / 2) * kHeight; |
544 EXPECT_EQ(0, libyuv::I420ToI422(frame1.GetYPlane(), frame1.GetYPitch(), | 545 EXPECT_EQ(0, libyuv::I420ToI422(frame1.GetYPlane(), frame1.GetYPitch(), |
545 frame1.GetUPlane(), frame1.GetUPitch(), | 546 frame1.GetUPlane(), frame1.GetUPitch(), |
546 frame1.GetVPlane(), frame1.GetVPitch(), | 547 frame1.GetVPlane(), frame1.GetVPitch(), |
547 y, kWidth, | 548 y, kWidth, |
548 u, kWidth / 2, | 549 u, kWidth / 2, |
549 v, kWidth / 2, | 550 v, kWidth / 2, |
550 kWidth, kHeight)); | 551 kWidth, kHeight)); |
551 EXPECT_TRUE(LoadFrame(y, buf_size, cricket::FOURCC_I422, | 552 EXPECT_TRUE(LoadFrame(y, buf_size, cricket::FOURCC_I422, |
552 kWidth, kHeight, &frame2)); | 553 kWidth, kHeight, &frame2)); |
553 EXPECT_TRUE(IsEqual(frame1, frame2, 1)); | 554 EXPECT_TRUE(IsEqual(frame1, frame2, 1)); |
554 } | 555 } |
555 | 556 |
556 // Test constructing an image from a YUY2 buffer. | 557 // Test constructing an image from a YUY2 buffer. |
557 void ConstructYuy2() { | 558 void ConstructYuy2() { |
558 T frame1, frame2; | 559 T frame1, frame2; |
559 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); | 560 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); |
560 size_t buf_size = kWidth * kHeight * 2; | 561 size_t buf_size = kWidth * kHeight * 2; |
561 rtc::scoped_ptr<uint8_t[]> buf(new uint8_t[buf_size + kAlignment]); | 562 std::unique_ptr<uint8_t[]> buf(new uint8_t[buf_size + kAlignment]); |
562 uint8_t* yuy2 = ALIGNP(buf.get(), kAlignment); | 563 uint8_t* yuy2 = ALIGNP(buf.get(), kAlignment); |
563 EXPECT_EQ(0, libyuv::I420ToYUY2(frame1.GetYPlane(), frame1.GetYPitch(), | 564 EXPECT_EQ(0, libyuv::I420ToYUY2(frame1.GetYPlane(), frame1.GetYPitch(), |
564 frame1.GetUPlane(), frame1.GetUPitch(), | 565 frame1.GetUPlane(), frame1.GetUPitch(), |
565 frame1.GetVPlane(), frame1.GetVPitch(), | 566 frame1.GetVPlane(), frame1.GetVPitch(), |
566 yuy2, kWidth * 2, | 567 yuy2, kWidth * 2, |
567 kWidth, kHeight)); | 568 kWidth, kHeight)); |
568 EXPECT_TRUE(LoadFrame(yuy2, buf_size, cricket::FOURCC_YUY2, | 569 EXPECT_TRUE(LoadFrame(yuy2, buf_size, cricket::FOURCC_YUY2, |
569 kWidth, kHeight, &frame2)); | 570 kWidth, kHeight, &frame2)); |
570 EXPECT_TRUE(IsEqual(frame1, frame2, 0)); | 571 EXPECT_TRUE(IsEqual(frame1, frame2, 0)); |
571 } | 572 } |
572 | 573 |
573 // Test constructing an image from a YUY2 buffer with buffer unaligned. | 574 // Test constructing an image from a YUY2 buffer with buffer unaligned. |
574 void ConstructYuy2Unaligned() { | 575 void ConstructYuy2Unaligned() { |
575 T frame1, frame2; | 576 T frame1, frame2; |
576 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); | 577 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); |
577 size_t buf_size = kWidth * kHeight * 2; | 578 size_t buf_size = kWidth * kHeight * 2; |
578 rtc::scoped_ptr<uint8_t[]> buf(new uint8_t[buf_size + kAlignment + 1]); | 579 std::unique_ptr<uint8_t[]> buf(new uint8_t[buf_size + kAlignment + 1]); |
579 uint8_t* yuy2 = ALIGNP(buf.get(), kAlignment) + 1; | 580 uint8_t* yuy2 = ALIGNP(buf.get(), kAlignment) + 1; |
580 EXPECT_EQ(0, libyuv::I420ToYUY2(frame1.GetYPlane(), frame1.GetYPitch(), | 581 EXPECT_EQ(0, libyuv::I420ToYUY2(frame1.GetYPlane(), frame1.GetYPitch(), |
581 frame1.GetUPlane(), frame1.GetUPitch(), | 582 frame1.GetUPlane(), frame1.GetUPitch(), |
582 frame1.GetVPlane(), frame1.GetVPitch(), | 583 frame1.GetVPlane(), frame1.GetVPitch(), |
583 yuy2, kWidth * 2, | 584 yuy2, kWidth * 2, |
584 kWidth, kHeight)); | 585 kWidth, kHeight)); |
585 EXPECT_TRUE(LoadFrame(yuy2, buf_size, cricket::FOURCC_YUY2, | 586 EXPECT_TRUE(LoadFrame(yuy2, buf_size, cricket::FOURCC_YUY2, |
586 kWidth, kHeight, &frame2)); | 587 kWidth, kHeight, &frame2)); |
587 EXPECT_TRUE(IsEqual(frame1, frame2, 0)); | 588 EXPECT_TRUE(IsEqual(frame1, frame2, 0)); |
588 } | 589 } |
589 | 590 |
590 // Test constructing an image from a wide YUY2 buffer. | 591 // Test constructing an image from a wide YUY2 buffer. |
591 // Normal is 1280x720. Wide is 12800x72 | 592 // Normal is 1280x720. Wide is 12800x72 |
592 void ConstructYuy2Wide() { | 593 void ConstructYuy2Wide() { |
593 T frame1, frame2; | 594 T frame1, frame2; |
594 rtc::scoped_ptr<rtc::MemoryStream> ms( | 595 std::unique_ptr<rtc::MemoryStream> ms( |
595 CreateYuv422Sample(cricket::FOURCC_YUY2, kWidth * 10, kHeight / 10)); | 596 CreateYuv422Sample(cricket::FOURCC_YUY2, kWidth * 10, kHeight / 10)); |
596 ASSERT_TRUE(ms.get() != NULL); | 597 ASSERT_TRUE(ms.get() != NULL); |
597 EXPECT_TRUE(ConvertYuv422(ms.get(), cricket::FOURCC_YUY2, | 598 EXPECT_TRUE(ConvertYuv422(ms.get(), cricket::FOURCC_YUY2, |
598 kWidth * 10, kHeight / 10, | 599 kWidth * 10, kHeight / 10, |
599 &frame1)); | 600 &frame1)); |
600 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YUY2, | 601 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YUY2, |
601 kWidth * 10, kHeight / 10, &frame2)); | 602 kWidth * 10, kHeight / 10, &frame2)); |
602 EXPECT_TRUE(IsEqual(frame1, frame2, 0)); | 603 EXPECT_TRUE(IsEqual(frame1, frame2, 0)); |
603 } | 604 } |
604 | 605 |
605 // Test constructing an image from a UYVY buffer. | 606 // Test constructing an image from a UYVY buffer. |
606 void ConstructUyvy() { | 607 void ConstructUyvy() { |
607 T frame1, frame2; | 608 T frame1, frame2; |
608 rtc::scoped_ptr<rtc::MemoryStream> ms( | 609 std::unique_ptr<rtc::MemoryStream> ms( |
609 CreateYuv422Sample(cricket::FOURCC_UYVY, kWidth, kHeight)); | 610 CreateYuv422Sample(cricket::FOURCC_UYVY, kWidth, kHeight)); |
610 ASSERT_TRUE(ms.get() != NULL); | 611 ASSERT_TRUE(ms.get() != NULL); |
611 EXPECT_TRUE(ConvertYuv422(ms.get(), cricket::FOURCC_UYVY, kWidth, kHeight, | 612 EXPECT_TRUE(ConvertYuv422(ms.get(), cricket::FOURCC_UYVY, kWidth, kHeight, |
612 &frame1)); | 613 &frame1)); |
613 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_UYVY, | 614 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_UYVY, |
614 kWidth, kHeight, &frame2)); | 615 kWidth, kHeight, &frame2)); |
615 EXPECT_TRUE(IsEqual(frame1, frame2, 0)); | 616 EXPECT_TRUE(IsEqual(frame1, frame2, 0)); |
616 } | 617 } |
617 | 618 |
618 // Test constructing an image from a random buffer. | 619 // Test constructing an image from a random buffer. |
619 // We are merely verifying that the code succeeds and is free of crashes. | 620 // We are merely verifying that the code succeeds and is free of crashes. |
620 void ConstructM420() { | 621 void ConstructM420() { |
621 T frame; | 622 T frame; |
622 rtc::scoped_ptr<rtc::MemoryStream> ms( | 623 std::unique_ptr<rtc::MemoryStream> ms( |
623 CreateYuvSample(kWidth, kHeight, 12)); | 624 CreateYuvSample(kWidth, kHeight, 12)); |
624 ASSERT_TRUE(ms.get() != NULL); | 625 ASSERT_TRUE(ms.get() != NULL); |
625 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_M420, | 626 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_M420, |
626 kWidth, kHeight, &frame)); | 627 kWidth, kHeight, &frame)); |
627 } | 628 } |
628 | 629 |
629 void ConstructNV21() { | 630 void ConstructNV21() { |
630 T frame; | 631 T frame; |
631 rtc::scoped_ptr<rtc::MemoryStream> ms( | 632 std::unique_ptr<rtc::MemoryStream> ms( |
632 CreateYuvSample(kWidth, kHeight, 12)); | 633 CreateYuvSample(kWidth, kHeight, 12)); |
633 ASSERT_TRUE(ms.get() != NULL); | 634 ASSERT_TRUE(ms.get() != NULL); |
634 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_NV21, | 635 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_NV21, |
635 kWidth, kHeight, &frame)); | 636 kWidth, kHeight, &frame)); |
636 } | 637 } |
637 | 638 |
638 void ConstructNV12() { | 639 void ConstructNV12() { |
639 T frame; | 640 T frame; |
640 rtc::scoped_ptr<rtc::MemoryStream> ms( | 641 std::unique_ptr<rtc::MemoryStream> ms( |
641 CreateYuvSample(kWidth, kHeight, 12)); | 642 CreateYuvSample(kWidth, kHeight, 12)); |
642 ASSERT_TRUE(ms.get() != NULL); | 643 ASSERT_TRUE(ms.get() != NULL); |
643 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_NV12, | 644 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_NV12, |
644 kWidth, kHeight, &frame)); | 645 kWidth, kHeight, &frame)); |
645 } | 646 } |
646 | 647 |
647 // Test constructing an image from a ABGR buffer | 648 // Test constructing an image from a ABGR buffer |
648 // Due to rounding, some pixels may differ slightly from the VideoFrame impl. | 649 // Due to rounding, some pixels may differ slightly from the VideoFrame impl. |
649 void ConstructABGR() { | 650 void ConstructABGR() { |
650 T frame1, frame2; | 651 T frame1, frame2; |
651 rtc::scoped_ptr<rtc::MemoryStream> ms( | 652 std::unique_ptr<rtc::MemoryStream> ms( |
652 CreateRgbSample(cricket::FOURCC_ABGR, kWidth, kHeight)); | 653 CreateRgbSample(cricket::FOURCC_ABGR, kWidth, kHeight)); |
653 ASSERT_TRUE(ms.get() != NULL); | 654 ASSERT_TRUE(ms.get() != NULL); |
654 EXPECT_TRUE(ConvertRgb(ms.get(), cricket::FOURCC_ABGR, kWidth, kHeight, | 655 EXPECT_TRUE(ConvertRgb(ms.get(), cricket::FOURCC_ABGR, kWidth, kHeight, |
655 &frame1)); | 656 &frame1)); |
656 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_ABGR, | 657 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_ABGR, |
657 kWidth, kHeight, &frame2)); | 658 kWidth, kHeight, &frame2)); |
658 EXPECT_TRUE(IsEqual(frame1, frame2, 2)); | 659 EXPECT_TRUE(IsEqual(frame1, frame2, 2)); |
659 } | 660 } |
660 | 661 |
661 // Test constructing an image from a ARGB buffer | 662 // Test constructing an image from a ARGB buffer |
662 // Due to rounding, some pixels may differ slightly from the VideoFrame impl. | 663 // Due to rounding, some pixels may differ slightly from the VideoFrame impl. |
663 void ConstructARGB() { | 664 void ConstructARGB() { |
664 T frame1, frame2; | 665 T frame1, frame2; |
665 rtc::scoped_ptr<rtc::MemoryStream> ms( | 666 std::unique_ptr<rtc::MemoryStream> ms( |
666 CreateRgbSample(cricket::FOURCC_ARGB, kWidth, kHeight)); | 667 CreateRgbSample(cricket::FOURCC_ARGB, kWidth, kHeight)); |
667 ASSERT_TRUE(ms.get() != NULL); | 668 ASSERT_TRUE(ms.get() != NULL); |
668 EXPECT_TRUE(ConvertRgb(ms.get(), cricket::FOURCC_ARGB, kWidth, kHeight, | 669 EXPECT_TRUE(ConvertRgb(ms.get(), cricket::FOURCC_ARGB, kWidth, kHeight, |
669 &frame1)); | 670 &frame1)); |
670 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_ARGB, | 671 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_ARGB, |
671 kWidth, kHeight, &frame2)); | 672 kWidth, kHeight, &frame2)); |
672 EXPECT_TRUE(IsEqual(frame1, frame2, 2)); | 673 EXPECT_TRUE(IsEqual(frame1, frame2, 2)); |
673 } | 674 } |
674 | 675 |
675 // Test constructing an image from a wide ARGB buffer | 676 // Test constructing an image from a wide ARGB buffer |
676 // Normal is 1280x720. Wide is 12800x72 | 677 // Normal is 1280x720. Wide is 12800x72 |
677 void ConstructARGBWide() { | 678 void ConstructARGBWide() { |
678 T frame1, frame2; | 679 T frame1, frame2; |
679 rtc::scoped_ptr<rtc::MemoryStream> ms( | 680 std::unique_ptr<rtc::MemoryStream> ms( |
680 CreateRgbSample(cricket::FOURCC_ARGB, kWidth * 10, kHeight / 10)); | 681 CreateRgbSample(cricket::FOURCC_ARGB, kWidth * 10, kHeight / 10)); |
681 ASSERT_TRUE(ms.get() != NULL); | 682 ASSERT_TRUE(ms.get() != NULL); |
682 EXPECT_TRUE(ConvertRgb(ms.get(), cricket::FOURCC_ARGB, | 683 EXPECT_TRUE(ConvertRgb(ms.get(), cricket::FOURCC_ARGB, |
683 kWidth * 10, kHeight / 10, &frame1)); | 684 kWidth * 10, kHeight / 10, &frame1)); |
684 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_ARGB, | 685 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_ARGB, |
685 kWidth * 10, kHeight / 10, &frame2)); | 686 kWidth * 10, kHeight / 10, &frame2)); |
686 EXPECT_TRUE(IsEqual(frame1, frame2, 2)); | 687 EXPECT_TRUE(IsEqual(frame1, frame2, 2)); |
687 } | 688 } |
688 | 689 |
689 // Test constructing an image from an BGRA buffer. | 690 // Test constructing an image from an BGRA buffer. |
690 // Due to rounding, some pixels may differ slightly from the VideoFrame impl. | 691 // Due to rounding, some pixels may differ slightly from the VideoFrame impl. |
691 void ConstructBGRA() { | 692 void ConstructBGRA() { |
692 T frame1, frame2; | 693 T frame1, frame2; |
693 rtc::scoped_ptr<rtc::MemoryStream> ms( | 694 std::unique_ptr<rtc::MemoryStream> ms( |
694 CreateRgbSample(cricket::FOURCC_BGRA, kWidth, kHeight)); | 695 CreateRgbSample(cricket::FOURCC_BGRA, kWidth, kHeight)); |
695 ASSERT_TRUE(ms.get() != NULL); | 696 ASSERT_TRUE(ms.get() != NULL); |
696 EXPECT_TRUE(ConvertRgb(ms.get(), cricket::FOURCC_BGRA, kWidth, kHeight, | 697 EXPECT_TRUE(ConvertRgb(ms.get(), cricket::FOURCC_BGRA, kWidth, kHeight, |
697 &frame1)); | 698 &frame1)); |
698 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_BGRA, | 699 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_BGRA, |
699 kWidth, kHeight, &frame2)); | 700 kWidth, kHeight, &frame2)); |
700 EXPECT_TRUE(IsEqual(frame1, frame2, 2)); | 701 EXPECT_TRUE(IsEqual(frame1, frame2, 2)); |
701 } | 702 } |
702 | 703 |
703 // Test constructing an image from a 24BG buffer. | 704 // Test constructing an image from a 24BG buffer. |
704 // Due to rounding, some pixels may differ slightly from the VideoFrame impl. | 705 // Due to rounding, some pixels may differ slightly from the VideoFrame impl. |
705 void Construct24BG() { | 706 void Construct24BG() { |
706 T frame1, frame2; | 707 T frame1, frame2; |
707 rtc::scoped_ptr<rtc::MemoryStream> ms( | 708 std::unique_ptr<rtc::MemoryStream> ms( |
708 CreateRgbSample(cricket::FOURCC_24BG, kWidth, kHeight)); | 709 CreateRgbSample(cricket::FOURCC_24BG, kWidth, kHeight)); |
709 ASSERT_TRUE(ms.get() != NULL); | 710 ASSERT_TRUE(ms.get() != NULL); |
710 EXPECT_TRUE(ConvertRgb(ms.get(), cricket::FOURCC_24BG, kWidth, kHeight, | 711 EXPECT_TRUE(ConvertRgb(ms.get(), cricket::FOURCC_24BG, kWidth, kHeight, |
711 &frame1)); | 712 &frame1)); |
712 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_24BG, | 713 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_24BG, |
713 kWidth, kHeight, &frame2)); | 714 kWidth, kHeight, &frame2)); |
714 EXPECT_TRUE(IsEqual(frame1, frame2, 2)); | 715 EXPECT_TRUE(IsEqual(frame1, frame2, 2)); |
715 } | 716 } |
716 | 717 |
717 // Test constructing an image from a raw RGB buffer. | 718 // Test constructing an image from a raw RGB buffer. |
718 // Due to rounding, some pixels may differ slightly from the VideoFrame impl. | 719 // Due to rounding, some pixels may differ slightly from the VideoFrame impl. |
719 void ConstructRaw() { | 720 void ConstructRaw() { |
720 T frame1, frame2; | 721 T frame1, frame2; |
721 rtc::scoped_ptr<rtc::MemoryStream> ms( | 722 std::unique_ptr<rtc::MemoryStream> ms( |
722 CreateRgbSample(cricket::FOURCC_RAW, kWidth, kHeight)); | 723 CreateRgbSample(cricket::FOURCC_RAW, kWidth, kHeight)); |
723 ASSERT_TRUE(ms.get() != NULL); | 724 ASSERT_TRUE(ms.get() != NULL); |
724 EXPECT_TRUE(ConvertRgb(ms.get(), cricket::FOURCC_RAW, kWidth, kHeight, | 725 EXPECT_TRUE(ConvertRgb(ms.get(), cricket::FOURCC_RAW, kWidth, kHeight, |
725 &frame1)); | 726 &frame1)); |
726 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_RAW, | 727 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_RAW, |
727 kWidth, kHeight, &frame2)); | 728 kWidth, kHeight, &frame2)); |
728 EXPECT_TRUE(IsEqual(frame1, frame2, 2)); | 729 EXPECT_TRUE(IsEqual(frame1, frame2, 2)); |
729 } | 730 } |
730 | 731 |
731 // Test constructing an image from a RGB565 buffer | 732 // Test constructing an image from a RGB565 buffer |
732 void ConstructRGB565() { | 733 void ConstructRGB565() { |
733 T frame1, frame2; | 734 T frame1, frame2; |
734 size_t out_size = kWidth * kHeight * 2; | 735 size_t out_size = kWidth * kHeight * 2; |
735 rtc::scoped_ptr<uint8_t[]> outbuf(new uint8_t[out_size + kAlignment]); | 736 std::unique_ptr<uint8_t[]> outbuf(new uint8_t[out_size + kAlignment]); |
736 uint8_t* out = ALIGNP(outbuf.get(), kAlignment); | 737 uint8_t* out = ALIGNP(outbuf.get(), kAlignment); |
737 T frame; | 738 T frame; |
738 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); | 739 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); |
739 EXPECT_EQ(out_size, frame1.ConvertToRgbBuffer(cricket::FOURCC_RGBP, | 740 EXPECT_EQ(out_size, frame1.ConvertToRgbBuffer(cricket::FOURCC_RGBP, |
740 out, | 741 out, |
741 out_size, kWidth * 2)); | 742 out_size, kWidth * 2)); |
742 EXPECT_TRUE(LoadFrame(out, out_size, cricket::FOURCC_RGBP, | 743 EXPECT_TRUE(LoadFrame(out, out_size, cricket::FOURCC_RGBP, |
743 kWidth, kHeight, &frame2)); | 744 kWidth, kHeight, &frame2)); |
744 EXPECT_TRUE(IsEqual(frame1, frame2, 20)); | 745 EXPECT_TRUE(IsEqual(frame1, frame2, 20)); |
745 } | 746 } |
746 | 747 |
747 // Test constructing an image from a ARGB1555 buffer | 748 // Test constructing an image from a ARGB1555 buffer |
748 void ConstructARGB1555() { | 749 void ConstructARGB1555() { |
749 T frame1, frame2; | 750 T frame1, frame2; |
750 size_t out_size = kWidth * kHeight * 2; | 751 size_t out_size = kWidth * kHeight * 2; |
751 rtc::scoped_ptr<uint8_t[]> outbuf(new uint8_t[out_size + kAlignment]); | 752 std::unique_ptr<uint8_t[]> outbuf(new uint8_t[out_size + kAlignment]); |
752 uint8_t* out = ALIGNP(outbuf.get(), kAlignment); | 753 uint8_t* out = ALIGNP(outbuf.get(), kAlignment); |
753 T frame; | 754 T frame; |
754 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); | 755 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); |
755 EXPECT_EQ(out_size, frame1.ConvertToRgbBuffer(cricket::FOURCC_RGBO, | 756 EXPECT_EQ(out_size, frame1.ConvertToRgbBuffer(cricket::FOURCC_RGBO, |
756 out, | 757 out, |
757 out_size, kWidth * 2)); | 758 out_size, kWidth * 2)); |
758 EXPECT_TRUE(LoadFrame(out, out_size, cricket::FOURCC_RGBO, | 759 EXPECT_TRUE(LoadFrame(out, out_size, cricket::FOURCC_RGBO, |
759 kWidth, kHeight, &frame2)); | 760 kWidth, kHeight, &frame2)); |
760 EXPECT_TRUE(IsEqual(frame1, frame2, 20)); | 761 EXPECT_TRUE(IsEqual(frame1, frame2, 20)); |
761 } | 762 } |
762 | 763 |
763 // Test constructing an image from a ARGB4444 buffer | 764 // Test constructing an image from a ARGB4444 buffer |
764 void ConstructARGB4444() { | 765 void ConstructARGB4444() { |
765 T frame1, frame2; | 766 T frame1, frame2; |
766 size_t out_size = kWidth * kHeight * 2; | 767 size_t out_size = kWidth * kHeight * 2; |
767 rtc::scoped_ptr<uint8_t[]> outbuf(new uint8_t[out_size + kAlignment]); | 768 std::unique_ptr<uint8_t[]> outbuf(new uint8_t[out_size + kAlignment]); |
768 uint8_t* out = ALIGNP(outbuf.get(), kAlignment); | 769 uint8_t* out = ALIGNP(outbuf.get(), kAlignment); |
769 T frame; | 770 T frame; |
770 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); | 771 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); |
771 EXPECT_EQ(out_size, frame1.ConvertToRgbBuffer(cricket::FOURCC_R444, | 772 EXPECT_EQ(out_size, frame1.ConvertToRgbBuffer(cricket::FOURCC_R444, |
772 out, | 773 out, |
773 out_size, kWidth * 2)); | 774 out_size, kWidth * 2)); |
774 EXPECT_TRUE(LoadFrame(out, out_size, cricket::FOURCC_R444, | 775 EXPECT_TRUE(LoadFrame(out, out_size, cricket::FOURCC_R444, |
775 kWidth, kHeight, &frame2)); | 776 kWidth, kHeight, &frame2)); |
776 EXPECT_TRUE(IsEqual(frame1, frame2, 20)); | 777 EXPECT_TRUE(IsEqual(frame1, frame2, 20)); |
777 } | 778 } |
778 | 779 |
779 // Macro to help test different rotations | 780 // Macro to help test different rotations |
780 #define TEST_MIRROR(FOURCC, BPP) \ | 781 #define TEST_MIRROR(FOURCC, BPP) \ |
781 void Construct##FOURCC##Mirror() { \ | 782 void Construct##FOURCC##Mirror() { \ |
782 T frame1, frame2, frame3; \ | 783 T frame1, frame2, frame3; \ |
783 rtc::scoped_ptr<rtc::MemoryStream> ms( \ | 784 std::unique_ptr<rtc::MemoryStream> ms( \ |
784 CreateYuvSample(kWidth, kHeight, BPP)); \ | 785 CreateYuvSample(kWidth, kHeight, BPP)); \ |
785 ASSERT_TRUE(ms.get() != NULL); \ | 786 ASSERT_TRUE(ms.get() != NULL); \ |
786 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_##FOURCC, kWidth, \ | 787 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_##FOURCC, kWidth, \ |
787 -kHeight, kWidth, kHeight, \ | 788 -kHeight, kWidth, kHeight, \ |
788 webrtc::kVideoRotation_180, &frame1)); \ | 789 webrtc::kVideoRotation_180, &frame1)); \ |
789 size_t data_size; \ | 790 size_t data_size; \ |
790 bool ret = ms->GetSize(&data_size); \ | 791 bool ret = ms->GetSize(&data_size); \ |
791 EXPECT_TRUE(ret); \ | 792 EXPECT_TRUE(ret); \ |
792 EXPECT_TRUE(frame2.Init(cricket::FOURCC_##FOURCC, kWidth, kHeight, kWidth, \ | 793 EXPECT_TRUE(frame2.Init(cricket::FOURCC_##FOURCC, kWidth, kHeight, kWidth, \ |
793 kHeight, \ | 794 kHeight, \ |
(...skipping 10 matching lines...) Expand all Loading... |
804 kHeight); \ | 805 kHeight); \ |
805 EXPECT_TRUE(IsEqual(frame1, frame3, 0)); \ | 806 EXPECT_TRUE(IsEqual(frame1, frame3, 0)); \ |
806 } | 807 } |
807 | 808 |
808 TEST_MIRROR(I420, 420) | 809 TEST_MIRROR(I420, 420) |
809 | 810 |
810 // Macro to help test different rotations | 811 // Macro to help test different rotations |
811 #define TEST_ROTATE(FOURCC, BPP, ROTATE) \ | 812 #define TEST_ROTATE(FOURCC, BPP, ROTATE) \ |
812 void Construct##FOURCC##Rotate##ROTATE() { \ | 813 void Construct##FOURCC##Rotate##ROTATE() { \ |
813 T frame1, frame2, frame3; \ | 814 T frame1, frame2, frame3; \ |
814 rtc::scoped_ptr<rtc::MemoryStream> ms( \ | 815 std::unique_ptr<rtc::MemoryStream> ms( \ |
815 CreateYuvSample(kWidth, kHeight, BPP)); \ | 816 CreateYuvSample(kWidth, kHeight, BPP)); \ |
816 ASSERT_TRUE(ms.get() != NULL); \ | 817 ASSERT_TRUE(ms.get() != NULL); \ |
817 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_##FOURCC, kWidth, kHeight, \ | 818 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_##FOURCC, kWidth, kHeight, \ |
818 kWidth, kHeight, webrtc::kVideoRotation_##ROTATE, \ | 819 kWidth, kHeight, webrtc::kVideoRotation_##ROTATE, \ |
819 &frame1)); \ | 820 &frame1)); \ |
820 size_t data_size; \ | 821 size_t data_size; \ |
821 bool ret = ms->GetSize(&data_size); \ | 822 bool ret = ms->GetSize(&data_size); \ |
822 EXPECT_TRUE(ret); \ | 823 EXPECT_TRUE(ret); \ |
823 EXPECT_TRUE(frame2.Init(cricket::FOURCC_##FOURCC, kWidth, kHeight, kWidth, \ | 824 EXPECT_TRUE(frame2.Init(cricket::FOURCC_##FOURCC, kWidth, kHeight, kWidth, \ |
824 kHeight, \ | 825 kHeight, \ |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 TEST_ROTATE(UYVY, 16, 180) | 859 TEST_ROTATE(UYVY, 16, 180) |
859 TEST_ROTATE(UYVY, 16, 270) | 860 TEST_ROTATE(UYVY, 16, 270) |
860 TEST_ROTATE(YUY2, 16, 0) | 861 TEST_ROTATE(YUY2, 16, 0) |
861 TEST_ROTATE(YUY2, 16, 90) | 862 TEST_ROTATE(YUY2, 16, 90) |
862 TEST_ROTATE(YUY2, 16, 180) | 863 TEST_ROTATE(YUY2, 16, 180) |
863 TEST_ROTATE(YUY2, 16, 270) | 864 TEST_ROTATE(YUY2, 16, 270) |
864 | 865 |
865 // Test constructing an image from a UYVY buffer rotated 90 degrees. | 866 // Test constructing an image from a UYVY buffer rotated 90 degrees. |
866 void ConstructUyvyRotate90() { | 867 void ConstructUyvyRotate90() { |
867 T frame2; | 868 T frame2; |
868 rtc::scoped_ptr<rtc::MemoryStream> ms( | 869 std::unique_ptr<rtc::MemoryStream> ms( |
869 CreateYuv422Sample(cricket::FOURCC_UYVY, kWidth, kHeight)); | 870 CreateYuv422Sample(cricket::FOURCC_UYVY, kWidth, kHeight)); |
870 ASSERT_TRUE(ms.get() != NULL); | 871 ASSERT_TRUE(ms.get() != NULL); |
871 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_UYVY, kWidth, kHeight, | 872 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_UYVY, kWidth, kHeight, |
872 kWidth, kHeight, webrtc::kVideoRotation_90, &frame2)); | 873 kWidth, kHeight, webrtc::kVideoRotation_90, &frame2)); |
873 } | 874 } |
874 | 875 |
875 // Test constructing an image from a UYVY buffer rotated 180 degrees. | 876 // Test constructing an image from a UYVY buffer rotated 180 degrees. |
876 void ConstructUyvyRotate180() { | 877 void ConstructUyvyRotate180() { |
877 T frame2; | 878 T frame2; |
878 rtc::scoped_ptr<rtc::MemoryStream> ms( | 879 std::unique_ptr<rtc::MemoryStream> ms( |
879 CreateYuv422Sample(cricket::FOURCC_UYVY, kWidth, kHeight)); | 880 CreateYuv422Sample(cricket::FOURCC_UYVY, kWidth, kHeight)); |
880 ASSERT_TRUE(ms.get() != NULL); | 881 ASSERT_TRUE(ms.get() != NULL); |
881 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_UYVY, kWidth, kHeight, | 882 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_UYVY, kWidth, kHeight, |
882 kWidth, kHeight, webrtc::kVideoRotation_180, | 883 kWidth, kHeight, webrtc::kVideoRotation_180, |
883 &frame2)); | 884 &frame2)); |
884 } | 885 } |
885 | 886 |
886 // Test constructing an image from a UYVY buffer rotated 270 degrees. | 887 // Test constructing an image from a UYVY buffer rotated 270 degrees. |
887 void ConstructUyvyRotate270() { | 888 void ConstructUyvyRotate270() { |
888 T frame2; | 889 T frame2; |
889 rtc::scoped_ptr<rtc::MemoryStream> ms( | 890 std::unique_ptr<rtc::MemoryStream> ms( |
890 CreateYuv422Sample(cricket::FOURCC_UYVY, kWidth, kHeight)); | 891 CreateYuv422Sample(cricket::FOURCC_UYVY, kWidth, kHeight)); |
891 ASSERT_TRUE(ms.get() != NULL); | 892 ASSERT_TRUE(ms.get() != NULL); |
892 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_UYVY, kWidth, kHeight, | 893 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_UYVY, kWidth, kHeight, |
893 kWidth, kHeight, webrtc::kVideoRotation_270, | 894 kWidth, kHeight, webrtc::kVideoRotation_270, |
894 &frame2)); | 895 &frame2)); |
895 } | 896 } |
896 | 897 |
897 // Test constructing an image from a YUY2 buffer rotated 90 degrees. | 898 // Test constructing an image from a YUY2 buffer rotated 90 degrees. |
898 void ConstructYuy2Rotate90() { | 899 void ConstructYuy2Rotate90() { |
899 T frame2; | 900 T frame2; |
900 rtc::scoped_ptr<rtc::MemoryStream> ms( | 901 std::unique_ptr<rtc::MemoryStream> ms( |
901 CreateYuv422Sample(cricket::FOURCC_YUY2, kWidth, kHeight)); | 902 CreateYuv422Sample(cricket::FOURCC_YUY2, kWidth, kHeight)); |
902 ASSERT_TRUE(ms.get() != NULL); | 903 ASSERT_TRUE(ms.get() != NULL); |
903 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YUY2, kWidth, kHeight, | 904 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YUY2, kWidth, kHeight, |
904 kWidth, kHeight, webrtc::kVideoRotation_90, &frame2)); | 905 kWidth, kHeight, webrtc::kVideoRotation_90, &frame2)); |
905 } | 906 } |
906 | 907 |
907 // Test constructing an image from a YUY2 buffer rotated 180 degrees. | 908 // Test constructing an image from a YUY2 buffer rotated 180 degrees. |
908 void ConstructYuy2Rotate180() { | 909 void ConstructYuy2Rotate180() { |
909 T frame2; | 910 T frame2; |
910 rtc::scoped_ptr<rtc::MemoryStream> ms( | 911 std::unique_ptr<rtc::MemoryStream> ms( |
911 CreateYuv422Sample(cricket::FOURCC_YUY2, kWidth, kHeight)); | 912 CreateYuv422Sample(cricket::FOURCC_YUY2, kWidth, kHeight)); |
912 ASSERT_TRUE(ms.get() != NULL); | 913 ASSERT_TRUE(ms.get() != NULL); |
913 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YUY2, kWidth, kHeight, | 914 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YUY2, kWidth, kHeight, |
914 kWidth, kHeight, webrtc::kVideoRotation_180, | 915 kWidth, kHeight, webrtc::kVideoRotation_180, |
915 &frame2)); | 916 &frame2)); |
916 } | 917 } |
917 | 918 |
918 // Test constructing an image from a YUY2 buffer rotated 270 degrees. | 919 // Test constructing an image from a YUY2 buffer rotated 270 degrees. |
919 void ConstructYuy2Rotate270() { | 920 void ConstructYuy2Rotate270() { |
920 T frame2; | 921 T frame2; |
921 rtc::scoped_ptr<rtc::MemoryStream> ms( | 922 std::unique_ptr<rtc::MemoryStream> ms( |
922 CreateYuv422Sample(cricket::FOURCC_YUY2, kWidth, kHeight)); | 923 CreateYuv422Sample(cricket::FOURCC_YUY2, kWidth, kHeight)); |
923 ASSERT_TRUE(ms.get() != NULL); | 924 ASSERT_TRUE(ms.get() != NULL); |
924 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YUY2, kWidth, kHeight, | 925 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YUY2, kWidth, kHeight, |
925 kWidth, kHeight, webrtc::kVideoRotation_270, | 926 kWidth, kHeight, webrtc::kVideoRotation_270, |
926 &frame2)); | 927 &frame2)); |
927 } | 928 } |
928 | 929 |
929 // Test 1 pixel edge case image I420 buffer. | 930 // Test 1 pixel edge case image I420 buffer. |
930 void ConstructI4201Pixel() { | 931 void ConstructI4201Pixel() { |
931 T frame; | 932 T frame; |
(...skipping 29 matching lines...) Expand all Loading... |
961 void ConstructARGB1Pixel() { | 962 void ConstructARGB1Pixel() { |
962 T frame; | 963 T frame; |
963 uint8_t pixel[4] = {64, 128, 192, 255}; | 964 uint8_t pixel[4] = {64, 128, 192, 255}; |
964 for (int i = 0; i < repeat_; ++i) { | 965 for (int i = 0; i < repeat_; ++i) { |
965 EXPECT_TRUE(frame.Init(cricket::FOURCC_ARGB, 1, 1, 1, 1, pixel, | 966 EXPECT_TRUE(frame.Init(cricket::FOURCC_ARGB, 1, 1, 1, 1, pixel, |
966 sizeof(pixel), 0, | 967 sizeof(pixel), 0, |
967 webrtc::kVideoRotation_0)); | 968 webrtc::kVideoRotation_0)); |
968 } | 969 } |
969 // Convert back to ARGB. | 970 // Convert back to ARGB. |
970 size_t out_size = 4; | 971 size_t out_size = 4; |
971 rtc::scoped_ptr<uint8_t[]> outbuf(new uint8_t[out_size + kAlignment]); | 972 std::unique_ptr<uint8_t[]> outbuf(new uint8_t[out_size + kAlignment]); |
972 uint8_t* out = ALIGNP(outbuf.get(), kAlignment); | 973 uint8_t* out = ALIGNP(outbuf.get(), kAlignment); |
973 | 974 |
974 EXPECT_EQ(out_size, frame.ConvertToRgbBuffer(cricket::FOURCC_ARGB, | 975 EXPECT_EQ(out_size, frame.ConvertToRgbBuffer(cricket::FOURCC_ARGB, |
975 out, | 976 out, |
976 out_size, // buffer size | 977 out_size, // buffer size |
977 out_size)); // stride | 978 out_size)); // stride |
978 #ifdef USE_LMI_CONVERT | 979 #ifdef USE_LMI_CONVERT |
979 // TODO(fbarchard): Expected to fail, but not crash. | 980 // TODO(fbarchard): Expected to fail, but not crash. |
980 EXPECT_FALSE(IsPlaneEqual("argb", pixel, 4, out, 4, 3, 1, 2)); | 981 EXPECT_FALSE(IsPlaneEqual("argb", pixel, 4, out, 4, 3, 1, 2)); |
981 #else | 982 #else |
(...skipping 16 matching lines...) Expand all Loading... |
998 255, 255, 255, 255, // White. | 999 255, 255, 255, 255, // White. |
999 255, 255, 255, 255}; // White. | 1000 255, 255, 255, 255}; // White. |
1000 | 1001 |
1001 for (int i = 0; i < repeat_; ++i) { | 1002 for (int i = 0; i < repeat_; ++i) { |
1002 EXPECT_TRUE(frame.Init(cricket::FOURCC_ARGB, 10, 1, 10, 1, pixel, | 1003 EXPECT_TRUE(frame.Init(cricket::FOURCC_ARGB, 10, 1, 10, 1, pixel, |
1003 sizeof(pixel), 1, 1, 0, | 1004 sizeof(pixel), 1, 1, 0, |
1004 webrtc::kVideoRotation_0)); | 1005 webrtc::kVideoRotation_0)); |
1005 } | 1006 } |
1006 // Convert back to ARGB | 1007 // Convert back to ARGB |
1007 size_t out_size = 10 * 4; | 1008 size_t out_size = 10 * 4; |
1008 rtc::scoped_ptr<uint8_t[]> outbuf(new uint8_t[out_size + kAlignment]); | 1009 std::unique_ptr<uint8_t[]> outbuf(new uint8_t[out_size + kAlignment]); |
1009 uint8_t* out = ALIGNP(outbuf.get(), kAlignment); | 1010 uint8_t* out = ALIGNP(outbuf.get(), kAlignment); |
1010 | 1011 |
1011 EXPECT_EQ(out_size, frame.ConvertToRgbBuffer(cricket::FOURCC_ARGB, | 1012 EXPECT_EQ(out_size, frame.ConvertToRgbBuffer(cricket::FOURCC_ARGB, |
1012 out, | 1013 out, |
1013 out_size, // buffer size. | 1014 out_size, // buffer size. |
1014 out_size)); // stride. | 1015 out_size)); // stride. |
1015 EXPECT_TRUE(IsPlaneEqual("argb", pixel, out_size, | 1016 EXPECT_TRUE(IsPlaneEqual("argb", pixel, out_size, |
1016 out, out_size, | 1017 out, out_size, |
1017 out_size, 1, 2)); | 1018 out_size, 1, 2)); |
1018 } | 1019 } |
1019 | 1020 |
1020 // Test constructing an image from an I420 buffer with horizontal cropping. | 1021 // Test constructing an image from an I420 buffer with horizontal cropping. |
1021 void ConstructI420CropHorizontal() { | 1022 void ConstructI420CropHorizontal() { |
1022 T frame1, frame2; | 1023 T frame1, frame2; |
1023 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); | 1024 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); |
1024 ASSERT_TRUE(LoadFrame(kImageFilename, cricket::FOURCC_I420, kWidth, kHeight, | 1025 ASSERT_TRUE(LoadFrame(kImageFilename, cricket::FOURCC_I420, kWidth, kHeight, |
1025 kWidth * 3 / 4, kHeight, webrtc::kVideoRotation_0, | 1026 kWidth * 3 / 4, kHeight, webrtc::kVideoRotation_0, |
1026 &frame2)); | 1027 &frame2)); |
1027 EXPECT_TRUE(IsEqualWithCrop(frame2, frame1, kWidth / 8, 0, 0)); | 1028 EXPECT_TRUE(IsEqualWithCrop(frame2, frame1, kWidth / 8, 0, 0)); |
1028 } | 1029 } |
1029 | 1030 |
1030 // Test constructing an image from a YUY2 buffer with horizontal cropping. | 1031 // Test constructing an image from a YUY2 buffer with horizontal cropping. |
1031 void ConstructYuy2CropHorizontal() { | 1032 void ConstructYuy2CropHorizontal() { |
1032 T frame1, frame2; | 1033 T frame1, frame2; |
1033 rtc::scoped_ptr<rtc::MemoryStream> ms( | 1034 std::unique_ptr<rtc::MemoryStream> ms( |
1034 CreateYuv422Sample(cricket::FOURCC_YUY2, kWidth, kHeight)); | 1035 CreateYuv422Sample(cricket::FOURCC_YUY2, kWidth, kHeight)); |
1035 ASSERT_TRUE(ms.get() != NULL); | 1036 ASSERT_TRUE(ms.get() != NULL); |
1036 EXPECT_TRUE(ConvertYuv422(ms.get(), cricket::FOURCC_YUY2, kWidth, kHeight, | 1037 EXPECT_TRUE(ConvertYuv422(ms.get(), cricket::FOURCC_YUY2, kWidth, kHeight, |
1037 &frame1)); | 1038 &frame1)); |
1038 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YUY2, kWidth, kHeight, | 1039 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YUY2, kWidth, kHeight, |
1039 kWidth * 3 / 4, kHeight, webrtc::kVideoRotation_0, | 1040 kWidth * 3 / 4, kHeight, webrtc::kVideoRotation_0, |
1040 &frame2)); | 1041 &frame2)); |
1041 EXPECT_TRUE(IsEqualWithCrop(frame2, frame1, kWidth / 8, 0, 0)); | 1042 EXPECT_TRUE(IsEqualWithCrop(frame2, frame1, kWidth / 8, 0, 0)); |
1042 } | 1043 } |
1043 | 1044 |
1044 // Test constructing an image from an ARGB buffer with horizontal cropping. | 1045 // Test constructing an image from an ARGB buffer with horizontal cropping. |
1045 void ConstructARGBCropHorizontal() { | 1046 void ConstructARGBCropHorizontal() { |
1046 T frame1, frame2; | 1047 T frame1, frame2; |
1047 rtc::scoped_ptr<rtc::MemoryStream> ms( | 1048 std::unique_ptr<rtc::MemoryStream> ms( |
1048 CreateRgbSample(cricket::FOURCC_ARGB, kWidth, kHeight)); | 1049 CreateRgbSample(cricket::FOURCC_ARGB, kWidth, kHeight)); |
1049 ASSERT_TRUE(ms.get() != NULL); | 1050 ASSERT_TRUE(ms.get() != NULL); |
1050 EXPECT_TRUE(ConvertRgb(ms.get(), cricket::FOURCC_ARGB, kWidth, kHeight, | 1051 EXPECT_TRUE(ConvertRgb(ms.get(), cricket::FOURCC_ARGB, kWidth, kHeight, |
1051 &frame1)); | 1052 &frame1)); |
1052 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_ARGB, kWidth, kHeight, | 1053 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_ARGB, kWidth, kHeight, |
1053 kWidth * 3 / 4, kHeight, webrtc::kVideoRotation_0, | 1054 kWidth * 3 / 4, kHeight, webrtc::kVideoRotation_0, |
1054 &frame2)); | 1055 &frame2)); |
1055 EXPECT_TRUE(IsEqualWithCrop(frame2, frame1, kWidth / 8, 0, 2)); | 1056 EXPECT_TRUE(IsEqualWithCrop(frame2, frame1, kWidth / 8, 0, 2)); |
1056 } | 1057 } |
1057 | 1058 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1127 EXPECT_TRUE(IsEqual(frame1, frame2, 128)); | 1128 EXPECT_TRUE(IsEqual(frame1, frame2, 128)); |
1128 } | 1129 } |
1129 | 1130 |
1130 // Test constructing an image from an I420 MJPG buffer. | 1131 // Test constructing an image from an I420 MJPG buffer. |
1131 void ValidateFrame(const char* name, | 1132 void ValidateFrame(const char* name, |
1132 uint32_t fourcc, | 1133 uint32_t fourcc, |
1133 int data_adjust, | 1134 int data_adjust, |
1134 int size_adjust, | 1135 int size_adjust, |
1135 bool expected_result) { | 1136 bool expected_result) { |
1136 T frame; | 1137 T frame; |
1137 rtc::scoped_ptr<rtc::MemoryStream> ms(LoadSample(name)); | 1138 std::unique_ptr<rtc::MemoryStream> ms(LoadSample(name)); |
1138 ASSERT_TRUE(ms.get() != NULL); | 1139 ASSERT_TRUE(ms.get() != NULL); |
1139 const uint8_t* sample = | 1140 const uint8_t* sample = |
1140 reinterpret_cast<const uint8_t*>(ms.get()->GetBuffer()); | 1141 reinterpret_cast<const uint8_t*>(ms.get()->GetBuffer()); |
1141 size_t sample_size; | 1142 size_t sample_size; |
1142 ms->GetSize(&sample_size); | 1143 ms->GetSize(&sample_size); |
1143 // Optional adjust size to test invalid size. | 1144 // Optional adjust size to test invalid size. |
1144 size_t data_size = sample_size + data_adjust; | 1145 size_t data_size = sample_size + data_adjust; |
1145 | 1146 |
1146 // Allocate a buffer with end page aligned. | 1147 // Allocate a buffer with end page aligned. |
1147 const int kPadToHeapSized = 16 * 1024 * 1024; | 1148 const int kPadToHeapSized = 16 * 1024 * 1024; |
1148 rtc::scoped_ptr<uint8_t[]> page_buffer( | 1149 std::unique_ptr<uint8_t[]> page_buffer( |
1149 new uint8_t[((data_size + kPadToHeapSized + 4095) & ~4095)]); | 1150 new uint8_t[((data_size + kPadToHeapSized + 4095) & ~4095)]); |
1150 uint8_t* data_ptr = page_buffer.get(); | 1151 uint8_t* data_ptr = page_buffer.get(); |
1151 if (!data_ptr) { | 1152 if (!data_ptr) { |
1152 LOG(LS_WARNING) << "Failed to allocate memory for ValidateFrame test."; | 1153 LOG(LS_WARNING) << "Failed to allocate memory for ValidateFrame test."; |
1153 EXPECT_FALSE(expected_result); // NULL is okay if failure was expected. | 1154 EXPECT_FALSE(expected_result); // NULL is okay if failure was expected. |
1154 return; | 1155 return; |
1155 } | 1156 } |
1156 data_ptr += kPadToHeapSized + (-(static_cast<int>(data_size)) & 4095); | 1157 data_ptr += kPadToHeapSized + (-(static_cast<int>(data_size)) & 4095); |
1157 memcpy(data_ptr, sample, std::min(data_size, sample_size)); | 1158 memcpy(data_ptr, sample, std::min(data_size, sample_size)); |
1158 for (int i = 0; i < repeat_; ++i) { | 1159 for (int i = 0; i < repeat_; ++i) { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1244 FAIL() << "Validate was expected to cause EXCEPTION_ACCESS_VIOLATION."; | 1245 FAIL() << "Validate was expected to cause EXCEPTION_ACCESS_VIOLATION."; |
1245 } __except(ExceptionFilter(GetExceptionCode(), GetExceptionInformation())) { | 1246 } __except(ExceptionFilter(GetExceptionCode(), GetExceptionInformation())) { |
1246 return; // Successfully crashed in ValidateFrame. | 1247 return; // Successfully crashed in ValidateFrame. |
1247 } | 1248 } |
1248 } | 1249 } |
1249 #endif | 1250 #endif |
1250 | 1251 |
1251 // Test constructing an image from a YUY2 buffer (and synonymous formats). | 1252 // Test constructing an image from a YUY2 buffer (and synonymous formats). |
1252 void ConstructYuy2Aliases() { | 1253 void ConstructYuy2Aliases() { |
1253 T frame1, frame2, frame3, frame4; | 1254 T frame1, frame2, frame3, frame4; |
1254 rtc::scoped_ptr<rtc::MemoryStream> ms( | 1255 std::unique_ptr<rtc::MemoryStream> ms( |
1255 CreateYuv422Sample(cricket::FOURCC_YUY2, kWidth, kHeight)); | 1256 CreateYuv422Sample(cricket::FOURCC_YUY2, kWidth, kHeight)); |
1256 ASSERT_TRUE(ms.get() != NULL); | 1257 ASSERT_TRUE(ms.get() != NULL); |
1257 EXPECT_TRUE(ConvertYuv422(ms.get(), cricket::FOURCC_YUY2, kWidth, kHeight, | 1258 EXPECT_TRUE(ConvertYuv422(ms.get(), cricket::FOURCC_YUY2, kWidth, kHeight, |
1258 &frame1)); | 1259 &frame1)); |
1259 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YUY2, | 1260 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YUY2, |
1260 kWidth, kHeight, &frame2)); | 1261 kWidth, kHeight, &frame2)); |
1261 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YUVS, | 1262 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YUVS, |
1262 kWidth, kHeight, &frame3)); | 1263 kWidth, kHeight, &frame3)); |
1263 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YUYV, | 1264 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YUYV, |
1264 kWidth, kHeight, &frame4)); | 1265 kWidth, kHeight, &frame4)); |
1265 EXPECT_TRUE(IsEqual(frame1, frame2, 0)); | 1266 EXPECT_TRUE(IsEqual(frame1, frame2, 0)); |
1266 EXPECT_TRUE(IsEqual(frame1, frame3, 0)); | 1267 EXPECT_TRUE(IsEqual(frame1, frame3, 0)); |
1267 EXPECT_TRUE(IsEqual(frame1, frame4, 0)); | 1268 EXPECT_TRUE(IsEqual(frame1, frame4, 0)); |
1268 } | 1269 } |
1269 | 1270 |
1270 // Test constructing an image from a UYVY buffer (and synonymous formats). | 1271 // Test constructing an image from a UYVY buffer (and synonymous formats). |
1271 void ConstructUyvyAliases() { | 1272 void ConstructUyvyAliases() { |
1272 T frame1, frame2, frame3, frame4; | 1273 T frame1, frame2, frame3, frame4; |
1273 rtc::scoped_ptr<rtc::MemoryStream> ms( | 1274 std::unique_ptr<rtc::MemoryStream> ms( |
1274 CreateYuv422Sample(cricket::FOURCC_UYVY, kWidth, kHeight)); | 1275 CreateYuv422Sample(cricket::FOURCC_UYVY, kWidth, kHeight)); |
1275 ASSERT_TRUE(ms.get() != NULL); | 1276 ASSERT_TRUE(ms.get() != NULL); |
1276 EXPECT_TRUE(ConvertYuv422(ms.get(), cricket::FOURCC_UYVY, kWidth, kHeight, | 1277 EXPECT_TRUE(ConvertYuv422(ms.get(), cricket::FOURCC_UYVY, kWidth, kHeight, |
1277 &frame1)); | 1278 &frame1)); |
1278 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_UYVY, | 1279 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_UYVY, |
1279 kWidth, kHeight, &frame2)); | 1280 kWidth, kHeight, &frame2)); |
1280 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_2VUY, | 1281 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_2VUY, |
1281 kWidth, kHeight, &frame3)); | 1282 kWidth, kHeight, &frame3)); |
1282 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_HDYC, | 1283 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_HDYC, |
1283 kWidth, kHeight, &frame4)); | 1284 kWidth, kHeight, &frame4)); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1318 EXPECT_TRUE(IsSize(frame, kWidth, kHeight)); | 1319 EXPECT_TRUE(IsSize(frame, kWidth, kHeight)); |
1319 EXPECT_TRUE(IsBlack(frame)); | 1320 EXPECT_TRUE(IsBlack(frame)); |
1320 } | 1321 } |
1321 | 1322 |
1322 // Test constructing an image from a YUY2 buffer with a range of sizes. | 1323 // Test constructing an image from a YUY2 buffer with a range of sizes. |
1323 // Only tests that conversion does not crash or corrupt heap. | 1324 // Only tests that conversion does not crash or corrupt heap. |
1324 void ConstructYuy2AllSizes() { | 1325 void ConstructYuy2AllSizes() { |
1325 T frame1, frame2; | 1326 T frame1, frame2; |
1326 for (int height = kMinHeightAll; height <= kMaxHeightAll; ++height) { | 1327 for (int height = kMinHeightAll; height <= kMaxHeightAll; ++height) { |
1327 for (int width = kMinWidthAll; width <= kMaxWidthAll; ++width) { | 1328 for (int width = kMinWidthAll; width <= kMaxWidthAll; ++width) { |
1328 rtc::scoped_ptr<rtc::MemoryStream> ms( | 1329 std::unique_ptr<rtc::MemoryStream> ms( |
1329 CreateYuv422Sample(cricket::FOURCC_YUY2, width, height)); | 1330 CreateYuv422Sample(cricket::FOURCC_YUY2, width, height)); |
1330 ASSERT_TRUE(ms.get() != NULL); | 1331 ASSERT_TRUE(ms.get() != NULL); |
1331 EXPECT_TRUE(ConvertYuv422(ms.get(), cricket::FOURCC_YUY2, width, height, | 1332 EXPECT_TRUE(ConvertYuv422(ms.get(), cricket::FOURCC_YUY2, width, height, |
1332 &frame1)); | 1333 &frame1)); |
1333 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YUY2, | 1334 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YUY2, |
1334 width, height, &frame2)); | 1335 width, height, &frame2)); |
1335 EXPECT_TRUE(IsEqual(frame1, frame2, 0)); | 1336 EXPECT_TRUE(IsEqual(frame1, frame2, 0)); |
1336 } | 1337 } |
1337 } | 1338 } |
1338 } | 1339 } |
1339 | 1340 |
1340 // Test constructing an image from a ARGB buffer with a range of sizes. | 1341 // Test constructing an image from a ARGB buffer with a range of sizes. |
1341 // Only tests that conversion does not crash or corrupt heap. | 1342 // Only tests that conversion does not crash or corrupt heap. |
1342 void ConstructARGBAllSizes() { | 1343 void ConstructARGBAllSizes() { |
1343 T frame1, frame2; | 1344 T frame1, frame2; |
1344 for (int height = kMinHeightAll; height <= kMaxHeightAll; ++height) { | 1345 for (int height = kMinHeightAll; height <= kMaxHeightAll; ++height) { |
1345 for (int width = kMinWidthAll; width <= kMaxWidthAll; ++width) { | 1346 for (int width = kMinWidthAll; width <= kMaxWidthAll; ++width) { |
1346 rtc::scoped_ptr<rtc::MemoryStream> ms( | 1347 std::unique_ptr<rtc::MemoryStream> ms( |
1347 CreateRgbSample(cricket::FOURCC_ARGB, width, height)); | 1348 CreateRgbSample(cricket::FOURCC_ARGB, width, height)); |
1348 ASSERT_TRUE(ms.get() != NULL); | 1349 ASSERT_TRUE(ms.get() != NULL); |
1349 EXPECT_TRUE(ConvertRgb(ms.get(), cricket::FOURCC_ARGB, width, height, | 1350 EXPECT_TRUE(ConvertRgb(ms.get(), cricket::FOURCC_ARGB, width, height, |
1350 &frame1)); | 1351 &frame1)); |
1351 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_ARGB, | 1352 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_ARGB, |
1352 width, height, &frame2)); | 1353 width, height, &frame2)); |
1353 EXPECT_TRUE(IsEqual(frame1, frame2, 64)); | 1354 EXPECT_TRUE(IsEqual(frame1, frame2, 64)); |
1354 } | 1355 } |
1355 } | 1356 } |
1356 // Test a practical window size for screencasting usecase. | 1357 // Test a practical window size for screencasting usecase. |
1357 const int kOddWidth = 1228; | 1358 const int kOddWidth = 1228; |
1358 const int kOddHeight = 260; | 1359 const int kOddHeight = 260; |
1359 for (int j = 0; j < 2; ++j) { | 1360 for (int j = 0; j < 2; ++j) { |
1360 for (int i = 0; i < 2; ++i) { | 1361 for (int i = 0; i < 2; ++i) { |
1361 rtc::scoped_ptr<rtc::MemoryStream> ms( | 1362 std::unique_ptr<rtc::MemoryStream> ms( |
1362 CreateRgbSample(cricket::FOURCC_ARGB, kOddWidth + i, kOddHeight + j)); | 1363 CreateRgbSample(cricket::FOURCC_ARGB, kOddWidth + i, kOddHeight + j)); |
1363 ASSERT_TRUE(ms.get() != NULL); | 1364 ASSERT_TRUE(ms.get() != NULL); |
1364 EXPECT_TRUE(ConvertRgb(ms.get(), cricket::FOURCC_ARGB, | 1365 EXPECT_TRUE(ConvertRgb(ms.get(), cricket::FOURCC_ARGB, |
1365 kOddWidth + i, kOddHeight + j, | 1366 kOddWidth + i, kOddHeight + j, |
1366 &frame1)); | 1367 &frame1)); |
1367 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_ARGB, | 1368 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_ARGB, |
1368 kOddWidth + i, kOddHeight + j, &frame2)); | 1369 kOddWidth + i, kOddHeight + j, &frame2)); |
1369 EXPECT_TRUE(IsEqual(frame1, frame2, 64)); | 1370 EXPECT_TRUE(IsEqual(frame1, frame2, 64)); |
1370 } | 1371 } |
1371 } | 1372 } |
1372 } | 1373 } |
1373 | 1374 |
1374 // Tests re-initing an existing image. | 1375 // Tests re-initing an existing image. |
1375 void Reset(webrtc::VideoRotation rotation, bool apply_rotation) { | 1376 void Reset(webrtc::VideoRotation rotation, bool apply_rotation) { |
1376 T frame1, frame2; | 1377 T frame1, frame2; |
1377 rtc::scoped_ptr<rtc::MemoryStream> ms( | 1378 std::unique_ptr<rtc::MemoryStream> ms( |
1378 LoadSample(kImageFilename)); | 1379 LoadSample(kImageFilename)); |
1379 ASSERT_TRUE(ms.get() != NULL); | 1380 ASSERT_TRUE(ms.get() != NULL); |
1380 size_t data_size; | 1381 size_t data_size; |
1381 ms->GetSize(&data_size); | 1382 ms->GetSize(&data_size); |
1382 EXPECT_TRUE(frame1.InitToBlack(kWidth, kHeight, 0)); | 1383 EXPECT_TRUE(frame1.InitToBlack(kWidth, kHeight, 0)); |
1383 EXPECT_TRUE(frame2.InitToBlack(kWidth, kHeight, 0)); | 1384 EXPECT_TRUE(frame2.InitToBlack(kWidth, kHeight, 0)); |
1384 EXPECT_TRUE(IsBlack(frame1)); | 1385 EXPECT_TRUE(IsBlack(frame1)); |
1385 EXPECT_TRUE(IsEqual(frame1, frame2, 0)); | 1386 EXPECT_TRUE(IsEqual(frame1, frame2, 0)); |
1386 EXPECT_TRUE(frame1.Reset(cricket::FOURCC_I420, kWidth, kHeight, kWidth, | 1387 EXPECT_TRUE(frame1.Reset(cricket::FOURCC_I420, kWidth, kHeight, kWidth, |
1387 kHeight, | 1388 kHeight, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1435 uint8_t* dst_v, | 1436 uint8_t* dst_v, |
1436 int dst_stride_v, | 1437 int dst_stride_v, |
1437 int width, | 1438 int width, |
1438 int height)) { | 1439 int height)) { |
1439 T frame1, frame2; | 1440 T frame1, frame2; |
1440 int repeat_to = (to_from == TO) ? repeat_ : 1; | 1441 int repeat_to = (to_from == TO) ? repeat_ : 1; |
1441 int repeat_from = (to_from == FROM) ? repeat_ : 1; | 1442 int repeat_from = (to_from == FROM) ? repeat_ : 1; |
1442 | 1443 |
1443 int astride = kWidth * bpp + rowpad; | 1444 int astride = kWidth * bpp + rowpad; |
1444 size_t out_size = astride * kHeight; | 1445 size_t out_size = astride * kHeight; |
1445 rtc::scoped_ptr<uint8_t[]> outbuf(new uint8_t[out_size + kAlignment + 1]); | 1446 std::unique_ptr<uint8_t[]> outbuf(new uint8_t[out_size + kAlignment + 1]); |
1446 memset(outbuf.get(), 0, out_size + kAlignment + 1); | 1447 memset(outbuf.get(), 0, out_size + kAlignment + 1); |
1447 uint8_t* outtop = ALIGNP(outbuf.get(), kAlignment); | 1448 uint8_t* outtop = ALIGNP(outbuf.get(), kAlignment); |
1448 uint8_t* out = outtop; | 1449 uint8_t* out = outtop; |
1449 int stride = astride; | 1450 int stride = astride; |
1450 if (invert) { | 1451 if (invert) { |
1451 out += (kHeight - 1) * stride; // Point to last row. | 1452 out += (kHeight - 1) * stride; // Point to last row. |
1452 stride = -stride; | 1453 stride = -stride; |
1453 } | 1454 } |
1454 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); | 1455 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); |
1455 | 1456 |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1753 } | 1754 } |
1754 void ConvertFromUYVYBufferInverted() { | 1755 void ConvertFromUYVYBufferInverted() { |
1755 ConvertToBuffer(2, 0, true, FROM, kError, | 1756 ConvertToBuffer(2, 0, true, FROM, kError, |
1756 cricket::FOURCC_UYVY, libyuv::UYVYToI420); | 1757 cricket::FOURCC_UYVY, libyuv::UYVYToI420); |
1757 } | 1758 } |
1758 | 1759 |
1759 // Test converting from I420 to I422. | 1760 // Test converting from I420 to I422. |
1760 void ConvertToI422Buffer() { | 1761 void ConvertToI422Buffer() { |
1761 T frame1, frame2; | 1762 T frame1, frame2; |
1762 size_t out_size = kWidth * kHeight * 2; | 1763 size_t out_size = kWidth * kHeight * 2; |
1763 rtc::scoped_ptr<uint8_t[]> buf(new uint8_t[out_size + kAlignment]); | 1764 std::unique_ptr<uint8_t[]> buf(new uint8_t[out_size + kAlignment]); |
1764 uint8_t* y = ALIGNP(buf.get(), kAlignment); | 1765 uint8_t* y = ALIGNP(buf.get(), kAlignment); |
1765 uint8_t* u = y + kWidth * kHeight; | 1766 uint8_t* u = y + kWidth * kHeight; |
1766 uint8_t* v = u + (kWidth / 2) * kHeight; | 1767 uint8_t* v = u + (kWidth / 2) * kHeight; |
1767 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); | 1768 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); |
1768 for (int i = 0; i < repeat_; ++i) { | 1769 for (int i = 0; i < repeat_; ++i) { |
1769 EXPECT_EQ(0, libyuv::I420ToI422(frame1.GetYPlane(), frame1.GetYPitch(), | 1770 EXPECT_EQ(0, libyuv::I420ToI422(frame1.GetYPlane(), frame1.GetYPitch(), |
1770 frame1.GetUPlane(), frame1.GetUPitch(), | 1771 frame1.GetUPlane(), frame1.GetUPitch(), |
1771 frame1.GetVPlane(), frame1.GetVPitch(), | 1772 frame1.GetVPlane(), frame1.GetVPitch(), |
1772 y, kWidth, | 1773 y, kWidth, |
1773 u, kWidth / 2, | 1774 u, kWidth / 2, |
1774 v, kWidth / 2, | 1775 v, kWidth / 2, |
1775 kWidth, kHeight)); | 1776 kWidth, kHeight)); |
1776 } | 1777 } |
1777 EXPECT_TRUE(frame2.Init(cricket::FOURCC_I422, kWidth, kHeight, kWidth, | 1778 EXPECT_TRUE(frame2.Init(cricket::FOURCC_I422, kWidth, kHeight, kWidth, |
1778 kHeight, y, out_size, 1, 1, 0, | 1779 kHeight, y, out_size, 1, 1, 0, |
1779 webrtc::kVideoRotation_0)); | 1780 webrtc::kVideoRotation_0)); |
1780 EXPECT_TRUE(IsEqual(frame1, frame2, 1)); | 1781 EXPECT_TRUE(IsEqual(frame1, frame2, 1)); |
1781 } | 1782 } |
1782 | 1783 |
1783 /////////////////// | 1784 /////////////////// |
1784 // General tests // | 1785 // General tests // |
1785 /////////////////// | 1786 /////////////////// |
1786 | 1787 |
1787 void Copy() { | 1788 void Copy() { |
1788 rtc::scoped_ptr<T> source(new T); | 1789 std::unique_ptr<T> source(new T); |
1789 rtc::scoped_ptr<cricket::VideoFrame> target; | 1790 std::unique_ptr<cricket::VideoFrame> target; |
1790 ASSERT_TRUE(LoadFrameNoRepeat(source.get())); | 1791 ASSERT_TRUE(LoadFrameNoRepeat(source.get())); |
1791 target.reset(source->Copy()); | 1792 target.reset(source->Copy()); |
1792 EXPECT_TRUE(IsEqual(*source, *target, 0)); | 1793 EXPECT_TRUE(IsEqual(*source, *target, 0)); |
1793 source.reset(); | 1794 source.reset(); |
1794 EXPECT_TRUE(target->GetYPlane() != NULL); | 1795 EXPECT_TRUE(target->GetYPlane() != NULL); |
1795 } | 1796 } |
1796 | 1797 |
1797 void CopyIsRef() { | 1798 void CopyIsRef() { |
1798 rtc::scoped_ptr<T> source(new T); | 1799 std::unique_ptr<T> source(new T); |
1799 rtc::scoped_ptr<const cricket::VideoFrame> target; | 1800 std::unique_ptr<const cricket::VideoFrame> target; |
1800 ASSERT_TRUE(LoadFrameNoRepeat(source.get())); | 1801 ASSERT_TRUE(LoadFrameNoRepeat(source.get())); |
1801 target.reset(source->Copy()); | 1802 target.reset(source->Copy()); |
1802 EXPECT_TRUE(IsEqual(*source, *target, 0)); | 1803 EXPECT_TRUE(IsEqual(*source, *target, 0)); |
1803 const T* const_source = source.get(); | 1804 const T* const_source = source.get(); |
1804 EXPECT_EQ(const_source->GetYPlane(), target->GetYPlane()); | 1805 EXPECT_EQ(const_source->GetYPlane(), target->GetYPlane()); |
1805 EXPECT_EQ(const_source->GetUPlane(), target->GetUPlane()); | 1806 EXPECT_EQ(const_source->GetUPlane(), target->GetUPlane()); |
1806 EXPECT_EQ(const_source->GetVPlane(), target->GetVPlane()); | 1807 EXPECT_EQ(const_source->GetVPlane(), target->GetVPlane()); |
1807 } | 1808 } |
1808 | 1809 |
1809 void MakeExclusive() { | 1810 void MakeExclusive() { |
1810 rtc::scoped_ptr<T> source(new T); | 1811 std::unique_ptr<T> source(new T); |
1811 rtc::scoped_ptr<cricket::VideoFrame> target; | 1812 std::unique_ptr<cricket::VideoFrame> target; |
1812 ASSERT_TRUE(LoadFrameNoRepeat(source.get())); | 1813 ASSERT_TRUE(LoadFrameNoRepeat(source.get())); |
1813 target.reset(source->Copy()); | 1814 target.reset(source->Copy()); |
1814 EXPECT_TRUE(target->MakeExclusive()); | 1815 EXPECT_TRUE(target->MakeExclusive()); |
1815 EXPECT_TRUE(IsEqual(*source, *target, 0)); | 1816 EXPECT_TRUE(IsEqual(*source, *target, 0)); |
1816 EXPECT_NE(target->GetYPlane(), source->GetYPlane()); | 1817 EXPECT_NE(target->GetYPlane(), source->GetYPlane()); |
1817 EXPECT_NE(target->GetUPlane(), source->GetUPlane()); | 1818 EXPECT_NE(target->GetUPlane(), source->GetUPlane()); |
1818 EXPECT_NE(target->GetVPlane(), source->GetVPlane()); | 1819 EXPECT_NE(target->GetVPlane(), source->GetVPlane()); |
1819 } | 1820 } |
1820 | 1821 |
1821 void CopyToFrame() { | 1822 void CopyToFrame() { |
1822 T source; | 1823 T source; |
1823 rtc::scoped_ptr<rtc::MemoryStream> ms( | 1824 std::unique_ptr<rtc::MemoryStream> ms( |
1824 LoadSample(kImageFilename)); | 1825 LoadSample(kImageFilename)); |
1825 ASSERT_TRUE(ms.get() != NULL); | 1826 ASSERT_TRUE(ms.get() != NULL); |
1826 ASSERT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_I420, kWidth, kHeight, | 1827 ASSERT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_I420, kWidth, kHeight, |
1827 &source)); | 1828 &source)); |
1828 | 1829 |
1829 // Create the target frame by loading from a file. | 1830 // Create the target frame by loading from a file. |
1830 T target; | 1831 T target; |
1831 ASSERT_TRUE(LoadFrameNoRepeat(&target)); | 1832 ASSERT_TRUE(LoadFrameNoRepeat(&target)); |
1832 EXPECT_FALSE(IsBlack(target)); | 1833 EXPECT_FALSE(IsBlack(target)); |
1833 | 1834 |
(...skipping 23 matching lines...) Expand all Loading... |
1857 ASSERT_TRUE(LoadFrameNoRepeat(&target2)); | 1858 ASSERT_TRUE(LoadFrameNoRepeat(&target2)); |
1858 source.StretchToFrame(&target2, true, true); | 1859 source.StretchToFrame(&target2, true, true); |
1859 EXPECT_TRUE(IsBlack(target2)); | 1860 EXPECT_TRUE(IsBlack(target2)); |
1860 EXPECT_EQ(source.GetTimeStamp(), target2.GetTimeStamp()); | 1861 EXPECT_EQ(source.GetTimeStamp(), target2.GetTimeStamp()); |
1861 } | 1862 } |
1862 | 1863 |
1863 int repeat_; | 1864 int repeat_; |
1864 }; | 1865 }; |
1865 | 1866 |
1866 #endif // WEBRTC_MEDIA_BASE_VIDEOFRAME_UNITTEST_H_ | 1867 #endif // WEBRTC_MEDIA_BASE_VIDEOFRAME_UNITTEST_H_ |
OLD | NEW |