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

Side by Side Diff: talk/media/base/capturemanager_unittest.cc

Issue 1594973006: New rtc::VideoSinkInterface. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Use rtc::VideoSinkInterface on the call chain VideoSource --> CaptureRenderAdapter Created 4 years, 11 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 * libjingle 2 * libjingle
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 84
85 cricket::CaptureState capture_state_; 85 cricket::CaptureState capture_state_;
86 int callback_count_; 86 int callback_count_;
87 cricket::VideoFormat format_vga_; 87 cricket::VideoFormat format_vga_;
88 cricket::VideoFormat format_qvga_; 88 cricket::VideoFormat format_qvga_;
89 }; 89 };
90 90
91 // Incorrect use cases. 91 // Incorrect use cases.
92 TEST_F(CaptureManagerTest, InvalidCallOrder) { 92 TEST_F(CaptureManagerTest, InvalidCallOrder) {
93 // Capturer must be registered before any of these calls. 93 // Capturer must be registered before any of these calls.
94 EXPECT_FALSE(capture_manager_.AddVideoRenderer(&video_capturer_, 94 EXPECT_FALSE(capture_manager_.AddVideoSink(&video_capturer_,
95 &video_renderer_)); 95 &video_renderer_));
96 } 96 }
97 97
98 TEST_F(CaptureManagerTest, InvalidAddingRemoving) { 98 TEST_F(CaptureManagerTest, InvalidAddingRemoving) {
99 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_, 99 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_,
100 cricket::VideoFormat())); 100 cricket::VideoFormat()));
101 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, 101 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_,
102 format_vga_)); 102 format_vga_));
103 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); 103 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait);
104 EXPECT_EQ(1, callback_count()); 104 EXPECT_EQ(1, callback_count());
105 EXPECT_FALSE(capture_manager_.AddVideoRenderer(&video_capturer_, NULL)); 105 EXPECT_FALSE(capture_manager_.AddVideoSink(&video_capturer_, NULL));
106 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, format_vga_)); 106 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, format_vga_));
107 } 107 }
108 108
109 // Valid use cases 109 // Valid use cases
110 TEST_F(CaptureManagerTest, KeepFirstResolutionHigh) { 110 TEST_F(CaptureManagerTest, KeepFirstResolutionHigh) {
111 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, 111 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_,
112 format_vga_)); 112 format_vga_));
113 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); 113 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait);
114 EXPECT_EQ(1, callback_count()); 114 EXPECT_EQ(1, callback_count());
115 EXPECT_TRUE(capture_manager_.AddVideoRenderer(&video_capturer_, 115 EXPECT_TRUE(capture_manager_.AddVideoSink(&video_capturer_,
116 &video_renderer_)); 116 &video_renderer_));
117 EXPECT_TRUE(video_capturer_.CaptureFrame()); 117 EXPECT_TRUE(video_capturer_.CaptureFrame());
118 EXPECT_EQ(1, NumFramesRendered()); 118 EXPECT_EQ(1, NumFramesRendered());
119 // Renderer should be fed frames with the resolution of format_vga_. 119 // Renderer should be fed frames with the resolution of format_vga_.
120 EXPECT_TRUE(WasRenderedResolution(format_vga_)); 120 EXPECT_TRUE(WasRenderedResolution(format_vga_));
121 121
122 // Start again with one more format. 122 // Start again with one more format.
123 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, 123 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_,
124 format_qvga_)); 124 format_qvga_));
125 // Existing renderers should be fed frames with the resolution of format_vga_. 125 // Existing renderers should be fed frames with the resolution of format_vga_.
126 EXPECT_TRUE(video_capturer_.CaptureFrame()); 126 EXPECT_TRUE(video_capturer_.CaptureFrame());
127 EXPECT_TRUE(WasRenderedResolution(format_vga_)); 127 EXPECT_TRUE(WasRenderedResolution(format_vga_));
128 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, format_vga_)); 128 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, format_vga_));
129 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, 129 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_,
130 format_qvga_)); 130 format_qvga_));
131 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_, 131 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_,
132 format_vga_)); 132 format_vga_));
133 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_, 133 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_,
134 format_qvga_)); 134 format_qvga_));
135 } 135 }
136 136
137 // Should pick the lowest resolution as the highest resolution is not chosen 137 // Should pick the lowest resolution as the highest resolution is not chosen
138 // until after capturing has started. This ensures that no particular resolution 138 // until after capturing has started. This ensures that no particular resolution
139 // is favored over others. 139 // is favored over others.
140 TEST_F(CaptureManagerTest, KeepFirstResolutionLow) { 140 TEST_F(CaptureManagerTest, KeepFirstResolutionLow) {
141 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, 141 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_,
142 format_qvga_)); 142 format_qvga_));
143 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, 143 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_,
144 format_vga_)); 144 format_vga_));
145 EXPECT_TRUE(capture_manager_.AddVideoRenderer(&video_capturer_, 145 EXPECT_TRUE(capture_manager_.AddVideoSink(&video_capturer_,
146 &video_renderer_)); 146 &video_renderer_));
147 EXPECT_EQ_WAIT(1, callback_count(), kMsCallbackWait); 147 EXPECT_EQ_WAIT(1, callback_count(), kMsCallbackWait);
148 EXPECT_TRUE(video_capturer_.CaptureFrame()); 148 EXPECT_TRUE(video_capturer_.CaptureFrame());
149 EXPECT_EQ(1, NumFramesRendered()); 149 EXPECT_EQ(1, NumFramesRendered());
150 EXPECT_TRUE(WasRenderedResolution(format_qvga_)); 150 EXPECT_TRUE(WasRenderedResolution(format_qvga_));
151 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, 151 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_,
152 format_qvga_)); 152 format_qvga_));
153 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, 153 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_,
154 format_vga_)); 154 format_vga_));
155 } 155 }
156 156
157 // Ensure that the reference counting is working when multiple start and 157 // Ensure that the reference counting is working when multiple start and
158 // multiple stop calls are made. 158 // multiple stop calls are made.
159 TEST_F(CaptureManagerTest, MultipleStartStops) { 159 TEST_F(CaptureManagerTest, MultipleStartStops) {
160 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, 160 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_,
161 format_vga_)); 161 format_vga_));
162 // Add video capturer but with different format. 162 // Add video capturer but with different format.
163 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, 163 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_,
164 format_qvga_)); 164 format_qvga_));
165 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); 165 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait);
166 EXPECT_EQ(1, callback_count()); 166 EXPECT_EQ(1, callback_count());
167 EXPECT_TRUE(capture_manager_.AddVideoRenderer(&video_capturer_, 167 EXPECT_TRUE(capture_manager_.AddVideoSink(&video_capturer_,
168 &video_renderer_)); 168 &video_renderer_));
169 // Ensure that a frame can be captured when two start calls have been made. 169 // Ensure that a frame can be captured when two start calls have been made.
170 EXPECT_TRUE(video_capturer_.CaptureFrame()); 170 EXPECT_TRUE(video_capturer_.CaptureFrame());
171 EXPECT_EQ(1, NumFramesRendered()); 171 EXPECT_EQ(1, NumFramesRendered());
172 172
173 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, format_vga_)); 173 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, format_vga_));
174 // Video should still render since there has been two start calls but only 174 // Video should still render since there has been two start calls but only
175 // one stop call. 175 // one stop call.
176 EXPECT_TRUE(video_capturer_.CaptureFrame()); 176 EXPECT_TRUE(video_capturer_.CaptureFrame());
177 EXPECT_EQ(2, NumFramesRendered()); 177 EXPECT_EQ(2, NumFramesRendered());
178 178
179 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, 179 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_,
180 format_qvga_)); 180 format_qvga_));
181 EXPECT_EQ_WAIT(cricket::CS_STOPPED, capture_state(), kMsCallbackWait); 181 EXPECT_EQ_WAIT(cricket::CS_STOPPED, capture_state(), kMsCallbackWait);
182 EXPECT_EQ(2, callback_count()); 182 EXPECT_EQ(2, callback_count());
183 // Last stop call should fail as it is one more than the number of start 183 // Last stop call should fail as it is one more than the number of start
184 // calls. 184 // calls.
185 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_, 185 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_,
186 format_vga_)); 186 format_vga_));
187 } 187 }
188 188
189 TEST_F(CaptureManagerTest, TestForceRestart) { 189 TEST_F(CaptureManagerTest, TestForceRestart) {
190 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, 190 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_,
191 format_qvga_)); 191 format_qvga_));
192 EXPECT_TRUE(capture_manager_.AddVideoRenderer(&video_capturer_, 192 EXPECT_TRUE(capture_manager_.AddVideoSink(&video_capturer_,
193 &video_renderer_)); 193 &video_renderer_));
194 EXPECT_EQ_WAIT(1, callback_count(), kMsCallbackWait); 194 EXPECT_EQ_WAIT(1, callback_count(), kMsCallbackWait);
195 EXPECT_TRUE(video_capturer_.CaptureFrame()); 195 EXPECT_TRUE(video_capturer_.CaptureFrame());
196 EXPECT_EQ(1, NumFramesRendered()); 196 EXPECT_EQ(1, NumFramesRendered());
197 EXPECT_TRUE(WasRenderedResolution(format_qvga_)); 197 EXPECT_TRUE(WasRenderedResolution(format_qvga_));
198 // Now restart with vga. 198 // Now restart with vga.
199 EXPECT_TRUE(capture_manager_.RestartVideoCapture( 199 EXPECT_TRUE(capture_manager_.RestartVideoCapture(
200 &video_capturer_, format_qvga_, format_vga_, 200 &video_capturer_, format_qvga_, format_vga_,
201 cricket::CaptureManager::kForceRestart)); 201 cricket::CaptureManager::kForceRestart));
202 EXPECT_TRUE(video_capturer_.CaptureFrame()); 202 EXPECT_TRUE(video_capturer_.CaptureFrame());
203 EXPECT_EQ(2, NumFramesRendered()); 203 EXPECT_EQ(2, NumFramesRendered());
204 EXPECT_TRUE(WasRenderedResolution(format_vga_)); 204 EXPECT_TRUE(WasRenderedResolution(format_vga_));
205 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, 205 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_,
206 format_vga_)); 206 format_vga_));
207 } 207 }
208 208
209 TEST_F(CaptureManagerTest, TestRequestRestart) { 209 TEST_F(CaptureManagerTest, TestRequestRestart) {
210 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, 210 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_,
211 format_vga_)); 211 format_vga_));
212 EXPECT_TRUE(capture_manager_.AddVideoRenderer(&video_capturer_, 212 EXPECT_TRUE(capture_manager_.AddVideoSink(&video_capturer_,
213 &video_renderer_)); 213 &video_renderer_));
pthatcher1 2016/01/27 01:11:03 You can just remove all the expects on the return
nisse-webrtc 2016/01/27 09:08:51 Done. I have no choice with a void return value...
214 EXPECT_EQ_WAIT(1, callback_count(), kMsCallbackWait); 214 EXPECT_EQ_WAIT(1, callback_count(), kMsCallbackWait);
215 EXPECT_TRUE(video_capturer_.CaptureFrame()); 215 EXPECT_TRUE(video_capturer_.CaptureFrame());
216 EXPECT_EQ(1, NumFramesRendered()); 216 EXPECT_EQ(1, NumFramesRendered());
217 EXPECT_TRUE(WasRenderedResolution(format_vga_)); 217 EXPECT_TRUE(WasRenderedResolution(format_vga_));
218 // Now request restart with qvga. 218 // Now request restart with qvga.
219 EXPECT_TRUE(capture_manager_.RestartVideoCapture( 219 EXPECT_TRUE(capture_manager_.RestartVideoCapture(
220 &video_capturer_, format_vga_, format_qvga_, 220 &video_capturer_, format_vga_, format_qvga_,
221 cricket::CaptureManager::kRequestRestart)); 221 cricket::CaptureManager::kRequestRestart));
222 EXPECT_TRUE(video_capturer_.CaptureFrame()); 222 EXPECT_TRUE(video_capturer_.CaptureFrame());
223 EXPECT_EQ(2, NumFramesRendered()); 223 EXPECT_EQ(2, NumFramesRendered());
224 EXPECT_TRUE(WasRenderedResolution(format_vga_)); 224 EXPECT_TRUE(WasRenderedResolution(format_vga_));
225 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, 225 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_,
226 format_qvga_)); 226 format_qvga_));
227 } 227 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698