OLD | NEW |
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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 } | 77 } |
78 | 78 |
79 } // namespace | 79 } // namespace |
80 | 80 |
81 TEST(TestVideoFrame, InitialValues) { | 81 TEST(TestVideoFrame, InitialValues) { |
82 VideoFrame frame; | 82 VideoFrame frame; |
83 EXPECT_TRUE(frame.IsZeroSize()); | 83 EXPECT_TRUE(frame.IsZeroSize()); |
84 EXPECT_EQ(kVideoRotation_0, frame.rotation()); | 84 EXPECT_EQ(kVideoRotation_0, frame.rotation()); |
85 } | 85 } |
86 | 86 |
| 87 TEST(TestVideoFrame, CopiesInitialFrameWithoutCrashing) { |
| 88 VideoFrame frame; |
| 89 VideoFrame frame2; |
| 90 frame2.CopyFrame(frame); |
| 91 } |
| 92 |
87 TEST(TestVideoFrame, WidthHeightValues) { | 93 TEST(TestVideoFrame, WidthHeightValues) { |
88 VideoFrame frame(I420Buffer::Create(10, 10, 10, 14, 90), | 94 VideoFrame frame(I420Buffer::Create(10, 10, 10, 14, 90), |
89 webrtc::kVideoRotation_0, | 95 webrtc::kVideoRotation_0, |
90 789 * rtc::kNumMicrosecsPerMillisec); | 96 789 * rtc::kNumMicrosecsPerMillisec); |
91 const int valid_value = 10; | 97 const int valid_value = 10; |
92 EXPECT_EQ(valid_value, frame.width()); | 98 EXPECT_EQ(valid_value, frame.width()); |
93 EXPECT_EQ(valid_value, frame.height()); | 99 EXPECT_EQ(valid_value, frame.height()); |
94 frame.set_timestamp(123u); | 100 frame.set_timestamp(123u); |
95 EXPECT_EQ(123u, frame.timestamp()); | 101 EXPECT_EQ(123u, frame.timestamp()); |
96 frame.set_ntp_time_ms(456); | 102 frame.set_ntp_time_ms(456); |
97 EXPECT_EQ(456, frame.ntp_time_ms()); | 103 EXPECT_EQ(456, frame.ntp_time_ms()); |
98 EXPECT_EQ(789, frame.render_time_ms()); | 104 EXPECT_EQ(789, frame.render_time_ms()); |
99 } | 105 } |
100 | 106 |
| 107 TEST(TestVideoFrame, CopyFrame) { |
| 108 int stride_y = 15; |
| 109 int stride_u = 10; |
| 110 int stride_v = 10; |
| 111 int width = 15; |
| 112 int height = 15; |
| 113 // Copy frame. |
| 114 VideoFrame small_frame; |
| 115 const int kSizeY = 400; |
| 116 const int kSizeU = 100; |
| 117 const int kSizeV = 100; |
| 118 const VideoRotation kRotation = kVideoRotation_270; |
| 119 uint8_t buffer_y[kSizeY]; |
| 120 uint8_t buffer_u[kSizeU]; |
| 121 uint8_t buffer_v[kSizeV]; |
| 122 memset(buffer_y, 16, kSizeY); |
| 123 memset(buffer_u, 8, kSizeU); |
| 124 memset(buffer_v, 4, kSizeV); |
| 125 VideoFrame big_frame; |
| 126 big_frame.CreateFrame(buffer_y, buffer_u, buffer_v, |
| 127 width + 5, height + 5, stride_y + 5, |
| 128 stride_u, stride_v, kRotation); |
| 129 // Frame of smaller dimensions. |
| 130 small_frame.CopyFrame(big_frame); |
| 131 EXPECT_TRUE(test::FramesEqual(small_frame, big_frame)); |
| 132 EXPECT_EQ(kRotation, small_frame.rotation()); |
| 133 |
| 134 // Frame of larger dimensions. |
| 135 rtc::scoped_refptr<I420Buffer> buffer = |
| 136 I420Buffer::Create(width, height, stride_y, stride_u, stride_v); |
| 137 memset(buffer->MutableDataY(), 1, width * height); |
| 138 memset(buffer->MutableDataU(), 2, ((height + 1) / 2) * stride_u); |
| 139 memset(buffer->MutableDataV(), 3, ((height + 1) / 2) * stride_u); |
| 140 VideoFrame other_frame(buffer, 0, 0, webrtc::kVideoRotation_0); |
| 141 big_frame.CopyFrame(other_frame); |
| 142 EXPECT_TRUE(test::FramesEqual(other_frame, big_frame)); |
| 143 } |
| 144 |
101 TEST(TestVideoFrame, ShallowCopy) { | 145 TEST(TestVideoFrame, ShallowCopy) { |
102 uint32_t timestamp = 1; | 146 uint32_t timestamp = 1; |
103 int64_t ntp_time_ms = 2; | 147 int64_t ntp_time_ms = 2; |
104 int64_t render_time_ms = 3; | 148 int64_t render_time_ms = 3; |
105 int stride_y = 15; | 149 int stride_y = 15; |
106 int stride_u = 10; | 150 int stride_u = 10; |
107 int stride_v = 10; | 151 int stride_v = 10; |
108 int width = 15; | 152 int width = 15; |
109 int height = 15; | 153 int height = 15; |
110 | 154 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 | 312 |
269 // Center crop to 640 x 360 (16/9 aspect), then scale down by 2. | 313 // Center crop to 640 x 360 (16/9 aspect), then scale down by 2. |
270 rtc::scoped_refptr<I420Buffer> scaled_buffer( | 314 rtc::scoped_refptr<I420Buffer> scaled_buffer( |
271 I420Buffer::Create(320, 180)); | 315 I420Buffer::Create(320, 180)); |
272 | 316 |
273 scaled_buffer->CropAndScaleFrom(buf); | 317 scaled_buffer->CropAndScaleFrom(buf); |
274 CheckCrop(scaled_buffer, 0.0, 0.125, 1.0, 0.75); | 318 CheckCrop(scaled_buffer, 0.0, 0.125, 1.0, 0.75); |
275 } | 319 } |
276 | 320 |
277 } // namespace webrtc | 321 } // namespace webrtc |
OLD | NEW |