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

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

Issue 1646463002: Revert of New rtc::VideoSinkInterface. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: 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
« no previous file with comments | « talk/media/base/capturemanager.cc ('k') | talk/media/base/capturerenderadapter.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 * 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 82
83 cricket::CaptureManager capture_manager_; 83 cricket::CaptureManager capture_manager_;
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) {
93 // Capturer must be registered before any of these calls.
94 EXPECT_FALSE(capture_manager_.AddVideoRenderer(&video_capturer_,
95 &video_renderer_));
96 }
97
92 TEST_F(CaptureManagerTest, InvalidAddingRemoving) { 98 TEST_F(CaptureManagerTest, InvalidAddingRemoving) {
93 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_, 99 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_,
94 cricket::VideoFormat())); 100 cricket::VideoFormat()));
95 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, 101 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_,
96 format_vga_)); 102 format_vga_));
97 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); 103 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait);
98 EXPECT_EQ(1, callback_count()); 104 EXPECT_EQ(1, callback_count());
99 // NULL argument currently allowed, and does nothing. 105 EXPECT_FALSE(capture_manager_.AddVideoRenderer(&video_capturer_, NULL));
100 capture_manager_.AddVideoSink(&video_capturer_, NULL);
101 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, format_vga_)); 106 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, format_vga_));
102 } 107 }
103 108
104 // Valid use cases 109 // Valid use cases
105 TEST_F(CaptureManagerTest, KeepFirstResolutionHigh) { 110 TEST_F(CaptureManagerTest, KeepFirstResolutionHigh) {
106 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, 111 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_,
107 format_vga_)); 112 format_vga_));
108 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); 113 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait);
109 EXPECT_EQ(1, callback_count()); 114 EXPECT_EQ(1, callback_count());
110 capture_manager_.AddVideoSink(&video_capturer_, &video_renderer_); 115 EXPECT_TRUE(capture_manager_.AddVideoRenderer(&video_capturer_,
116 &video_renderer_));
111 EXPECT_TRUE(video_capturer_.CaptureFrame()); 117 EXPECT_TRUE(video_capturer_.CaptureFrame());
112 EXPECT_EQ(1, NumFramesRendered()); 118 EXPECT_EQ(1, NumFramesRendered());
113 // Renderer should be fed frames with the resolution of format_vga_. 119 // Renderer should be fed frames with the resolution of format_vga_.
114 EXPECT_TRUE(WasRenderedResolution(format_vga_)); 120 EXPECT_TRUE(WasRenderedResolution(format_vga_));
115 121
116 // Start again with one more format. 122 // Start again with one more format.
117 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, 123 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_,
118 format_qvga_)); 124 format_qvga_));
119 // 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_.
120 EXPECT_TRUE(video_capturer_.CaptureFrame()); 126 EXPECT_TRUE(video_capturer_.CaptureFrame());
121 EXPECT_TRUE(WasRenderedResolution(format_vga_)); 127 EXPECT_TRUE(WasRenderedResolution(format_vga_));
122 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, format_vga_)); 128 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, format_vga_));
123 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, 129 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_,
124 format_qvga_)); 130 format_qvga_));
125 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_, 131 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_,
126 format_vga_)); 132 format_vga_));
127 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_, 133 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_,
128 format_qvga_)); 134 format_qvga_));
129 } 135 }
130 136
131 // 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
132 // until after capturing has started. This ensures that no particular resolution 138 // until after capturing has started. This ensures that no particular resolution
133 // is favored over others. 139 // is favored over others.
134 TEST_F(CaptureManagerTest, KeepFirstResolutionLow) { 140 TEST_F(CaptureManagerTest, KeepFirstResolutionLow) {
135 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, 141 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_,
136 format_qvga_)); 142 format_qvga_));
137 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, 143 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_,
138 format_vga_)); 144 format_vga_));
139 capture_manager_.AddVideoSink(&video_capturer_, &video_renderer_); 145 EXPECT_TRUE(capture_manager_.AddVideoRenderer(&video_capturer_,
146 &video_renderer_));
140 EXPECT_EQ_WAIT(1, callback_count(), kMsCallbackWait); 147 EXPECT_EQ_WAIT(1, callback_count(), kMsCallbackWait);
141 EXPECT_TRUE(video_capturer_.CaptureFrame()); 148 EXPECT_TRUE(video_capturer_.CaptureFrame());
142 EXPECT_EQ(1, NumFramesRendered()); 149 EXPECT_EQ(1, NumFramesRendered());
143 EXPECT_TRUE(WasRenderedResolution(format_qvga_)); 150 EXPECT_TRUE(WasRenderedResolution(format_qvga_));
144 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, 151 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_,
145 format_qvga_)); 152 format_qvga_));
146 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, 153 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_,
147 format_vga_)); 154 format_vga_));
148 } 155 }
149 156
150 // Ensure that the reference counting is working when multiple start and 157 // Ensure that the reference counting is working when multiple start and
151 // multiple stop calls are made. 158 // multiple stop calls are made.
152 TEST_F(CaptureManagerTest, MultipleStartStops) { 159 TEST_F(CaptureManagerTest, MultipleStartStops) {
153 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, 160 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_,
154 format_vga_)); 161 format_vga_));
155 // Add video capturer but with different format. 162 // Add video capturer but with different format.
156 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, 163 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_,
157 format_qvga_)); 164 format_qvga_));
158 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); 165 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait);
159 EXPECT_EQ(1, callback_count()); 166 EXPECT_EQ(1, callback_count());
160 capture_manager_.AddVideoSink(&video_capturer_, &video_renderer_); 167 EXPECT_TRUE(capture_manager_.AddVideoRenderer(&video_capturer_,
168 &video_renderer_));
161 // 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.
162 EXPECT_TRUE(video_capturer_.CaptureFrame()); 170 EXPECT_TRUE(video_capturer_.CaptureFrame());
163 EXPECT_EQ(1, NumFramesRendered()); 171 EXPECT_EQ(1, NumFramesRendered());
164 172
165 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, format_vga_)); 173 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, format_vga_));
166 // 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
167 // one stop call. 175 // one stop call.
168 EXPECT_TRUE(video_capturer_.CaptureFrame()); 176 EXPECT_TRUE(video_capturer_.CaptureFrame());
169 EXPECT_EQ(2, NumFramesRendered()); 177 EXPECT_EQ(2, NumFramesRendered());
170 178
171 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, 179 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_,
172 format_qvga_)); 180 format_qvga_));
173 EXPECT_EQ_WAIT(cricket::CS_STOPPED, capture_state(), kMsCallbackWait); 181 EXPECT_EQ_WAIT(cricket::CS_STOPPED, capture_state(), kMsCallbackWait);
174 EXPECT_EQ(2, callback_count()); 182 EXPECT_EQ(2, callback_count());
175 // 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
176 // calls. 184 // calls.
177 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_, 185 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_,
178 format_vga_)); 186 format_vga_));
179 } 187 }
180 188
181 TEST_F(CaptureManagerTest, TestForceRestart) { 189 TEST_F(CaptureManagerTest, TestForceRestart) {
182 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, 190 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_,
183 format_qvga_)); 191 format_qvga_));
184 capture_manager_.AddVideoSink(&video_capturer_, &video_renderer_); 192 EXPECT_TRUE(capture_manager_.AddVideoRenderer(&video_capturer_,
193 &video_renderer_));
185 EXPECT_EQ_WAIT(1, callback_count(), kMsCallbackWait); 194 EXPECT_EQ_WAIT(1, callback_count(), kMsCallbackWait);
186 EXPECT_TRUE(video_capturer_.CaptureFrame()); 195 EXPECT_TRUE(video_capturer_.CaptureFrame());
187 EXPECT_EQ(1, NumFramesRendered()); 196 EXPECT_EQ(1, NumFramesRendered());
188 EXPECT_TRUE(WasRenderedResolution(format_qvga_)); 197 EXPECT_TRUE(WasRenderedResolution(format_qvga_));
189 // Now restart with vga. 198 // Now restart with vga.
190 EXPECT_TRUE(capture_manager_.RestartVideoCapture( 199 EXPECT_TRUE(capture_manager_.RestartVideoCapture(
191 &video_capturer_, format_qvga_, format_vga_, 200 &video_capturer_, format_qvga_, format_vga_,
192 cricket::CaptureManager::kForceRestart)); 201 cricket::CaptureManager::kForceRestart));
193 EXPECT_TRUE(video_capturer_.CaptureFrame()); 202 EXPECT_TRUE(video_capturer_.CaptureFrame());
194 EXPECT_EQ(2, NumFramesRendered()); 203 EXPECT_EQ(2, NumFramesRendered());
195 EXPECT_TRUE(WasRenderedResolution(format_vga_)); 204 EXPECT_TRUE(WasRenderedResolution(format_vga_));
196 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, 205 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_,
197 format_vga_)); 206 format_vga_));
198 } 207 }
199 208
200 TEST_F(CaptureManagerTest, TestRequestRestart) { 209 TEST_F(CaptureManagerTest, TestRequestRestart) {
201 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_, 210 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_,
202 format_vga_)); 211 format_vga_));
203 capture_manager_.AddVideoSink(&video_capturer_, &video_renderer_); 212 EXPECT_TRUE(capture_manager_.AddVideoRenderer(&video_capturer_,
213 &video_renderer_));
204 EXPECT_EQ_WAIT(1, callback_count(), kMsCallbackWait); 214 EXPECT_EQ_WAIT(1, callback_count(), kMsCallbackWait);
205 EXPECT_TRUE(video_capturer_.CaptureFrame()); 215 EXPECT_TRUE(video_capturer_.CaptureFrame());
206 EXPECT_EQ(1, NumFramesRendered()); 216 EXPECT_EQ(1, NumFramesRendered());
207 EXPECT_TRUE(WasRenderedResolution(format_vga_)); 217 EXPECT_TRUE(WasRenderedResolution(format_vga_));
208 // Now request restart with qvga. 218 // Now request restart with qvga.
209 EXPECT_TRUE(capture_manager_.RestartVideoCapture( 219 EXPECT_TRUE(capture_manager_.RestartVideoCapture(
210 &video_capturer_, format_vga_, format_qvga_, 220 &video_capturer_, format_vga_, format_qvga_,
211 cricket::CaptureManager::kRequestRestart)); 221 cricket::CaptureManager::kRequestRestart));
212 EXPECT_TRUE(video_capturer_.CaptureFrame()); 222 EXPECT_TRUE(video_capturer_.CaptureFrame());
213 EXPECT_EQ(2, NumFramesRendered()); 223 EXPECT_EQ(2, NumFramesRendered());
214 EXPECT_TRUE(WasRenderedResolution(format_vga_)); 224 EXPECT_TRUE(WasRenderedResolution(format_vga_));
215 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, 225 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_,
216 format_qvga_)); 226 format_qvga_));
217 } 227 }
OLDNEW
« no previous file with comments | « talk/media/base/capturemanager.cc ('k') | talk/media/base/capturerenderadapter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698