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

Side by Side Diff: webrtc/media/engine/webrtcvideoframe_unittest.cc

Issue 2370993003: Reland of Delete VideoFrameFactory, CapturedFrame, and related code. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Resolve conflict in webrtc/media/BUILD.gn. Created 4 years, 2 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
« no previous file with comments | « webrtc/media/engine/webrtcvideoframe.cc ('k') | webrtc/media/engine/webrtcvideoframefactory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2011 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 #include <string.h> 11 #include <string.h>
12 12
13 #include <memory> 13 #include <memory>
14 14
15 #include "webrtc/media/base/videoframe_unittest.h" 15 #include "webrtc/media/base/videoframe_unittest.h"
16 #include "webrtc/media/engine/webrtcvideoframe.h" 16 #include "webrtc/media/engine/webrtcvideoframe.h"
17 #include "webrtc/test/fake_texture_frame.h" 17 #include "webrtc/test/fake_texture_frame.h"
18 18
19 namespace cricket { 19 namespace cricket {
20 20
21 class WebRtcVideoFrameTest : public VideoFrameTest<WebRtcVideoFrame> { 21 class WebRtcVideoFrameTest : public VideoFrameTest<WebRtcVideoFrame> {
22 public: 22 public:
23 WebRtcVideoFrameTest() {} 23 WebRtcVideoFrameTest() {}
24 24
25 void TestInit(int cropped_width, int cropped_height,
26 webrtc::VideoRotation frame_rotation,
27 bool apply_rotation) {
28 const int frame_width = 1920;
29 const int frame_height = 1080;
30
31 // Build the CapturedFrame.
32 CapturedFrame captured_frame;
33 captured_frame.fourcc = FOURCC_I420;
34 captured_frame.time_stamp = rtc::TimeNanos();
35 captured_frame.rotation = frame_rotation;
36 captured_frame.width = frame_width;
37 captured_frame.height = frame_height;
38 captured_frame.data_size = (frame_width * frame_height) +
39 ((frame_width + 1) / 2) * ((frame_height + 1) / 2) * 2;
40 std::unique_ptr<uint8_t[]> captured_frame_buffer(
41 new uint8_t[captured_frame.data_size]);
42 // Initialize memory to satisfy DrMemory tests.
43 memset(captured_frame_buffer.get(), 0, captured_frame.data_size);
44 captured_frame.data = captured_frame_buffer.get();
45
46 // Create the new frame from the CapturedFrame.
47 WebRtcVideoFrame frame;
48 EXPECT_TRUE(
49 frame.Init(&captured_frame, cropped_width, cropped_height,
50 apply_rotation));
51
52 // Verify the new frame.
53 EXPECT_EQ(captured_frame.time_stamp / rtc::kNumNanosecsPerMicrosec,
54 frame.timestamp_us());
55 if (apply_rotation)
56 EXPECT_EQ(webrtc::kVideoRotation_0, frame.rotation());
57 else
58 EXPECT_EQ(frame_rotation, frame.rotation());
59 // If |apply_rotation| and the frame rotation is 90 or 270, width and
60 // height are flipped.
61 if (apply_rotation && (frame_rotation == webrtc::kVideoRotation_90
62 || frame_rotation == webrtc::kVideoRotation_270)) {
63 EXPECT_EQ(cropped_width, frame.height());
64 EXPECT_EQ(cropped_height, frame.width());
65 } else {
66 EXPECT_EQ(cropped_width, frame.width());
67 EXPECT_EQ(cropped_height, frame.height());
68 }
69 }
70
71 void SetFrameRotation(WebRtcVideoFrame* frame, 25 void SetFrameRotation(WebRtcVideoFrame* frame,
72 webrtc::VideoRotation rotation) { 26 webrtc::VideoRotation rotation) {
73 frame->rotation_ = rotation; 27 frame->rotation_ = rotation;
74 } 28 }
75 }; 29 };
76 30
77 #define TEST_WEBRTCVIDEOFRAME(X) \ 31 #define TEST_WEBRTCVIDEOFRAME(X) \
78 TEST_F(WebRtcVideoFrameTest, X) { VideoFrameTest<WebRtcVideoFrame>::X(); } 32 TEST_F(WebRtcVideoFrameTest, X) { VideoFrameTest<WebRtcVideoFrame>::X(); }
79 33
80 TEST_WEBRTCVIDEOFRAME(ConstructI420) 34 TEST_WEBRTCVIDEOFRAME(ConstructI420)
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 // TEST_WEBRTCVIDEOFRAME(ValidateMjpgI420InvalidSize) 101 // TEST_WEBRTCVIDEOFRAME(ValidateMjpgI420InvalidSize)
148 // TEST_WEBRTCVIDEOFRAME(ValidateI420InvalidSize) 102 // TEST_WEBRTCVIDEOFRAME(ValidateI420InvalidSize)
149 103
150 // TODO(fbarchard): WebRtcVideoFrame does not support odd sizes. 104 // TODO(fbarchard): WebRtcVideoFrame does not support odd sizes.
151 // Re-evaluate once WebRTC switches to libyuv 105 // Re-evaluate once WebRTC switches to libyuv
152 // TEST_WEBRTCVIDEOFRAME(ConstructYuy2AllSizes) 106 // TEST_WEBRTCVIDEOFRAME(ConstructYuy2AllSizes)
153 // TEST_WEBRTCVIDEOFRAME(ConstructARGBAllSizes) 107 // TEST_WEBRTCVIDEOFRAME(ConstructARGBAllSizes)
154 // TEST_WEBRTCVIDEOFRAME(ConvertToI422Buffer) 108 // TEST_WEBRTCVIDEOFRAME(ConvertToI422Buffer)
155 // TEST_WEBRTCVIDEOFRAME(ConstructARGBBlackWhitePixel) 109 // TEST_WEBRTCVIDEOFRAME(ConstructARGBBlackWhitePixel)
156 110
157 // These functions test implementation-specific details.
158 // Tests the Init function with different cropped size.
159 TEST_F(WebRtcVideoFrameTest, InitEvenSize) {
160 TestInit(640, 360, webrtc::kVideoRotation_0, true);
161 }
162
163 TEST_F(WebRtcVideoFrameTest, InitOddWidth) {
164 TestInit(601, 480, webrtc::kVideoRotation_0, true);
165 }
166
167 TEST_F(WebRtcVideoFrameTest, InitOddHeight) {
168 TestInit(360, 765, webrtc::kVideoRotation_0, true);
169 }
170
171 TEST_F(WebRtcVideoFrameTest, InitOddWidthHeight) {
172 TestInit(355, 1021, webrtc::kVideoRotation_0, true);
173 }
174
175 TEST_F(WebRtcVideoFrameTest, InitRotated90ApplyRotation) {
176 TestInit(640, 360, webrtc::kVideoRotation_90, true);
177 }
178
179 TEST_F(WebRtcVideoFrameTest, InitRotated90DontApplyRotation) {
180 TestInit(640, 360, webrtc::kVideoRotation_90, false);
181 }
182
183 TEST_F(WebRtcVideoFrameTest, TextureInitialValues) { 111 TEST_F(WebRtcVideoFrameTest, TextureInitialValues) {
184 webrtc::test::FakeNativeHandle* dummy_handle = 112 webrtc::test::FakeNativeHandle* dummy_handle =
185 new webrtc::test::FakeNativeHandle(); 113 new webrtc::test::FakeNativeHandle();
186 webrtc::NativeHandleBuffer* buffer = 114 webrtc::NativeHandleBuffer* buffer =
187 new rtc::RefCountedObject<webrtc::test::FakeNativeHandleBuffer>( 115 new rtc::RefCountedObject<webrtc::test::FakeNativeHandleBuffer>(
188 dummy_handle, 640, 480); 116 dummy_handle, 640, 480);
189 117
190 WebRtcVideoFrame frame(buffer, webrtc::kVideoRotation_0, 20); 118 WebRtcVideoFrame frame(buffer, webrtc::kVideoRotation_0, 20);
191 EXPECT_EQ(dummy_handle, frame.video_frame_buffer()->native_handle()); 119 EXPECT_EQ(dummy_handle, frame.video_frame_buffer()->native_handle());
192 EXPECT_EQ(640, frame.width()); 120 EXPECT_EQ(640, frame.width());
(...skipping 27 matching lines...) Expand all
220 SetFrameRotation(&applied90, webrtc::kVideoRotation_270); 148 SetFrameRotation(&applied90, webrtc::kVideoRotation_270);
221 WebRtcVideoFrame applied360( 149 WebRtcVideoFrame applied360(
222 webrtc::I420Buffer::Rotate(applied90.video_frame_buffer(), 150 webrtc::I420Buffer::Rotate(applied90.video_frame_buffer(),
223 applied90.rotation()), 151 applied90.rotation()),
224 webrtc::kVideoRotation_0, applied90.timestamp_us()); 152 webrtc::kVideoRotation_0, applied90.timestamp_us());
225 EXPECT_EQ(applied360.rotation(), webrtc::kVideoRotation_0); 153 EXPECT_EQ(applied360.rotation(), webrtc::kVideoRotation_0);
226 EXPECT_TRUE(IsEqual(applied0, applied360, 0)); 154 EXPECT_TRUE(IsEqual(applied0, applied360, 0));
227 } 155 }
228 156
229 } // namespace cricket 157 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/media/engine/webrtcvideoframe.cc ('k') | webrtc/media/engine/webrtcvideoframefactory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698