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

Side by Side Diff: content/renderer/media/media_stream_video_source_unittest.cc

Issue 218763007: Update MediaStreamTrack::Stop to latest draft. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "content/renderer/media/media_stream_video_source.h" 10 #include "content/renderer/media/media_stream_video_source.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 // Test that the source crops to the requested max width and 93 // Test that the source crops to the requested max width and
94 // height even though the camera delivers a larger frame. 94 // height even though the camera delivers a larger frame.
95 // TODO(perkj): Frame resolution should be verified in MediaStreamVideoTrack 95 // TODO(perkj): Frame resolution should be verified in MediaStreamVideoTrack
96 // and not in the adapter. 96 // and not in the adapter.
97 void TestSourceCropFrame(int capture_width, 97 void TestSourceCropFrame(int capture_width,
98 int capture_height, 98 int capture_height,
99 const blink::WebMediaConstraints& constraints, 99 const blink::WebMediaConstraints& constraints,
100 int expected_height, 100 int expected_height,
101 int expected_width) { 101 int expected_width) {
102 // Expect the source to start capture with the supported resolution. 102 // Expect the source to start capture with the supported resolution.
103 CreateTrackAndStartSource(constraints, capture_width, capture_height , 30); 103 blink::WebMediaStreamTrack track = CreateTrackAndStartSource(
104 constraints, capture_width, capture_height , 30);
104 105
105 ASSERT_TRUE(mock_source()->GetAdapter()); 106 ASSERT_TRUE(mock_source()->GetAdapter());
106 MockVideoSource* adapter = static_cast<MockVideoSource*>( 107 MockVideoSource* adapter = static_cast<MockVideoSource*>(
107 mock_source()->GetAdapter()); 108 mock_source()->GetAdapter());
108 EXPECT_EQ(0, adapter->GetFrameNum()); 109 EXPECT_EQ(0, adapter->GetFrameNum());
109 110
110 scoped_refptr<media::VideoFrame> frame = 111 scoped_refptr<media::VideoFrame> frame =
111 media::VideoFrame::CreateBlackFrame(gfx::Size(capture_width, 112 media::VideoFrame::CreateBlackFrame(gfx::Size(capture_width,
112 capture_height)); 113 capture_height));
113 mock_source()->DeliverVideoFrame(frame); 114 mock_source()->DeliverVideoFrame(frame);
(...skipping 18 matching lines...) Expand all
132 int number_of_failed_constraints_applied_; 133 int number_of_failed_constraints_applied_;
133 MockMediaStreamDependencyFactory factory_; 134 MockMediaStreamDependencyFactory factory_;
134 blink::WebMediaStreamSource webkit_source_; 135 blink::WebMediaStreamSource webkit_source_;
135 // |mock_source_| is owned by |webkit_source_|. 136 // |mock_source_| is owned by |webkit_source_|.
136 MockMediaStreamVideoSource* mock_source_; 137 MockMediaStreamVideoSource* mock_source_;
137 }; 138 };
138 139
139 TEST_F(MediaStreamVideoSourceTest, AddTrackAndStartSource) { 140 TEST_F(MediaStreamVideoSourceTest, AddTrackAndStartSource) {
140 blink::WebMediaConstraints constraints; 141 blink::WebMediaConstraints constraints;
141 constraints.initialize(); 142 constraints.initialize();
142 CreateTrack("123", constraints); 143 blink::WebMediaStreamTrack track = CreateTrack("123", constraints);
143 mock_source()->CompleteGetSupportedFormats(); 144 mock_source()->CompleteGetSupportedFormats();
144 mock_source()->StartMockedSource(); 145 mock_source()->StartMockedSource();
145 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); 146 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks());
146 } 147 }
147 148
148 TEST_F(MediaStreamVideoSourceTest, AddTwoTracksBeforeSourceStarts) { 149 TEST_F(MediaStreamVideoSourceTest, AddTwoTracksBeforeSourceStarts) {
149 blink::WebMediaConstraints constraints; 150 blink::WebMediaConstraints constraints;
150 constraints.initialize(); 151 constraints.initialize();
151 blink::WebMediaStreamTrack track1 = CreateTrack("123", constraints); 152 blink::WebMediaStreamTrack track1 = CreateTrack("123", constraints);
152 mock_source()->CompleteGetSupportedFormats(); 153 mock_source()->CompleteGetSupportedFormats();
153 blink::WebMediaStreamTrack track2 = CreateTrack("123", constraints); 154 blink::WebMediaStreamTrack track2 = CreateTrack("123", constraints);
154 EXPECT_EQ(0, NumberOfSuccessConstraintsCallbacks()); 155 EXPECT_EQ(0, NumberOfSuccessConstraintsCallbacks());
155 mock_source()->StartMockedSource(); 156 mock_source()->StartMockedSource();
156 EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks()); 157 EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks());
157 } 158 }
158 159
159 TEST_F(MediaStreamVideoSourceTest, AddTrackAfterSourceStarts) { 160 TEST_F(MediaStreamVideoSourceTest, AddTrackAfterSourceStarts) {
160 blink::WebMediaConstraints constraints; 161 blink::WebMediaConstraints constraints;
161 constraints.initialize(); 162 constraints.initialize();
162 CreateTrack("123", constraints); 163 blink::WebMediaStreamTrack track1 = CreateTrack("123", constraints);
163 mock_source()->CompleteGetSupportedFormats(); 164 mock_source()->CompleteGetSupportedFormats();
164 mock_source()->StartMockedSource(); 165 mock_source()->StartMockedSource();
165 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); 166 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks());
166 CreateTrack("123", constraints); 167 blink::WebMediaStreamTrack track2 = CreateTrack("123", constraints);
167 EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks()); 168 EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks());
168 } 169 }
169 170
170 TEST_F(MediaStreamVideoSourceTest, AddTrackAndFailToStartSource) { 171 TEST_F(MediaStreamVideoSourceTest, AddTrackAndFailToStartSource) {
171 blink::WebMediaConstraints constraints; 172 blink::WebMediaConstraints constraints;
172 constraints.initialize(); 173 constraints.initialize();
173 CreateTrack("123", constraints); 174 blink::WebMediaStreamTrack track = CreateTrack("123", constraints);
174 mock_source()->CompleteGetSupportedFormats(); 175 mock_source()->CompleteGetSupportedFormats();
175 mock_source()->FailToStartMockedSource(); 176 mock_source()->FailToStartMockedSource();
176 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); 177 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks());
177 } 178 }
178 179
179 TEST_F(MediaStreamVideoSourceTest, AddTwoTracksBeforeGetSupportedFormats) { 180 TEST_F(MediaStreamVideoSourceTest, AddTwoTracksBeforeGetSupportedFormats) {
180 blink::WebMediaConstraints constraints; 181 blink::WebMediaConstraints constraints;
181 constraints.initialize(); 182 constraints.initialize();
182 CreateTrack("123", constraints); 183 blink::WebMediaStreamTrack track1 = CreateTrack("123", constraints);
183 CreateTrack("123", constraints); 184 blink::WebMediaStreamTrack track2 = CreateTrack("123", constraints);
184 mock_source()->CompleteGetSupportedFormats(); 185 mock_source()->CompleteGetSupportedFormats();
185 mock_source()->StartMockedSource(); 186 mock_source()->StartMockedSource();
186 EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks()); 187 EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks());
187 } 188 }
188 189
189 // Test that the capture output is CIF if we set max constraints to CIF. 190 // Test that the capture output is CIF if we set max constraints to CIF.
190 // and the capture device support CIF. 191 // and the capture device support CIF.
191 TEST_F(MediaStreamVideoSourceTest, MandatoryConstraintCif5Fps) { 192 TEST_F(MediaStreamVideoSourceTest, MandatoryConstraintCif5Fps) {
192 MockMediaConstraintFactory factory; 193 MockMediaConstraintFactory factory;
193 factory.AddMandatory(MediaStreamVideoSource::kMaxWidth, 352); 194 factory.AddMandatory(MediaStreamVideoSource::kMaxWidth, 352);
(...skipping 28 matching lines...) Expand all
222 factory.AddOptional(MediaStreamVideoSource::kMinWidth, 1280); 223 factory.AddOptional(MediaStreamVideoSource::kMinWidth, 1280);
223 224
224 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 640, 480, 30); 225 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 640, 480, 30);
225 } 226 }
226 227
227 // Test that AddTrack fail if the mandatory aspect ratio 228 // Test that AddTrack fail if the mandatory aspect ratio
228 // is set higher than supported. 229 // is set higher than supported.
229 TEST_F(MediaStreamVideoSourceTest, MandatoryAspectRatioTooHigh) { 230 TEST_F(MediaStreamVideoSourceTest, MandatoryAspectRatioTooHigh) {
230 MockMediaConstraintFactory factory; 231 MockMediaConstraintFactory factory;
231 factory.AddMandatory(MediaStreamVideoSource::kMinAspectRatio, 2); 232 factory.AddMandatory(MediaStreamVideoSource::kMinAspectRatio, 2);
232 CreateTrack("123", factory.CreateWebMediaConstraints()); 233 blink::WebMediaStreamTrack track = CreateTrack(
234 "123", factory.CreateWebMediaConstraints());
233 mock_source()->CompleteGetSupportedFormats(); 235 mock_source()->CompleteGetSupportedFormats();
234 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); 236 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks());
235 } 237 }
236 238
237 // Test that the source ignores an optional aspect ratio that is higher than 239 // Test that the source ignores an optional aspect ratio that is higher than
238 // supported. 240 // supported.
239 TEST_F(MediaStreamVideoSourceTest, OptionalAspectRatioTooHigh) { 241 TEST_F(MediaStreamVideoSourceTest, OptionalAspectRatioTooHigh) {
240 MockMediaConstraintFactory factory; 242 MockMediaConstraintFactory factory;
241 factory.AddOptional(MediaStreamVideoSource::kMinAspectRatio, 2); 243 factory.AddOptional(MediaStreamVideoSource::kMinAspectRatio, 2);
242 CreateTrack("123", factory.CreateWebMediaConstraints()); 244 blink::WebMediaStreamTrack track = CreateTrack(
245 "123", factory.CreateWebMediaConstraints());
243 mock_source()->CompleteGetSupportedFormats(); 246 mock_source()->CompleteGetSupportedFormats();
244 247
245 const media::VideoCaptureParams& params = mock_source()->start_params(); 248 const media::VideoCaptureParams& params = mock_source()->start_params();
246 double aspect_ratio = 249 double aspect_ratio =
247 static_cast<double>(params.requested_format.frame_size.width()) / 250 static_cast<double>(params.requested_format.frame_size.width()) /
248 params.requested_format.frame_size.height(); 251 params.requested_format.frame_size.height();
249 EXPECT_LT(aspect_ratio, 2); 252 EXPECT_LT(aspect_ratio, 2);
250 } 253 }
251 254
252 // Test that the source starts video with the default resolution if the 255 // Test that the source starts video with the default resolution if the
(...skipping 11 matching lines...) Expand all
264 constraints.initialize(); 267 constraints.initialize();
265 CreateTrackAndStartSource(constraints, 268 CreateTrackAndStartSource(constraints,
266 MediaStreamVideoSource::kDefaultWidth, 269 MediaStreamVideoSource::kDefaultWidth,
267 MediaStreamVideoSource::kDefaultHeight, 270 MediaStreamVideoSource::kDefaultHeight,
268 30); 271 30);
269 } 272 }
270 273
271 TEST_F(MediaStreamVideoSourceTest, InvalidMandatoryConstraint) { 274 TEST_F(MediaStreamVideoSourceTest, InvalidMandatoryConstraint) {
272 MockMediaConstraintFactory factory; 275 MockMediaConstraintFactory factory;
273 factory.AddMandatory("weird key", 640); 276 factory.AddMandatory("weird key", 640);
274 CreateTrack("123", factory.CreateWebMediaConstraints()); 277 blink::WebMediaStreamTrack track = CreateTrack(
278 "123", factory.CreateWebMediaConstraints());
275 mock_source()->CompleteGetSupportedFormats(); 279 mock_source()->CompleteGetSupportedFormats();
276 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); 280 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks());
277 } 281 }
278 282
279 // Test that the source ignores an unknown optional constraint. 283 // Test that the source ignores an unknown optional constraint.
280 TEST_F(MediaStreamVideoSourceTest, InvalidOptionalConstraint) { 284 TEST_F(MediaStreamVideoSourceTest, InvalidOptionalConstraint) {
281 MockMediaConstraintFactory factory; 285 MockMediaConstraintFactory factory;
282 factory.AddOptional("weird key", 640); 286 factory.AddOptional("weird key", 640);
283 287
284 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 288 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(),
285 MediaStreamVideoSource::kDefaultWidth, 289 MediaStreamVideoSource::kDefaultWidth,
286 MediaStreamVideoSource::kDefaultHeight, 290 MediaStreamVideoSource::kDefaultHeight,
287 30); 291 30);
288 } 292 }
289 293
290 // Tests that the source starts video with the max width and height set by 294 // Tests that the source starts video with the max width and height set by
291 // constraints for screencast. 295 // constraints for screencast.
292 TEST_F(MediaStreamVideoSourceTest, ScreencastResolutionWithConstraint) { 296 TEST_F(MediaStreamVideoSourceTest, ScreencastResolutionWithConstraint) {
293 media::VideoCaptureFormats formats; 297 media::VideoCaptureFormats formats;
294 formats.push_back(media::VideoCaptureFormat( 298 formats.push_back(media::VideoCaptureFormat(
295 gfx::Size(480, 270), 30, media::PIXEL_FORMAT_I420)); 299 gfx::Size(480, 270), 30, media::PIXEL_FORMAT_I420));
296 mock_source()->SetSupportedFormats(formats); 300 mock_source()->SetSupportedFormats(formats);
297 MockMediaConstraintFactory factory; 301 MockMediaConstraintFactory factory;
298 factory.AddMandatory(MediaStreamVideoSource::kMaxWidth, 480); 302 factory.AddMandatory(MediaStreamVideoSource::kMaxWidth, 480);
299 factory.AddMandatory(MediaStreamVideoSource::kMaxHeight, 270); 303 factory.AddMandatory(MediaStreamVideoSource::kMaxHeight, 270);
300 304
301 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 480, 270, 30); 305 blink::WebMediaStreamTrack track = CreateTrackAndStartSource(
306 factory.CreateWebMediaConstraints(), 480, 270, 30);
302 EXPECT_EQ(480, mock_source()->max_requested_height()); 307 EXPECT_EQ(480, mock_source()->max_requested_height());
303 EXPECT_EQ(270, mock_source()->max_requested_width()); 308 EXPECT_EQ(270, mock_source()->max_requested_width());
304 } 309 }
305 310
306 // Test that optional constraints are applied in order. 311 // Test that optional constraints are applied in order.
307 TEST_F(MediaStreamVideoSourceTest, OptionalConstraints) { 312 TEST_F(MediaStreamVideoSourceTest, OptionalConstraints) {
308 MockMediaConstraintFactory factory; 313 MockMediaConstraintFactory factory;
309 // Min width of 2056 pixels can not be fulfilled. 314 // Min width of 2056 pixels can not be fulfilled.
310 factory.AddOptional(MediaStreamVideoSource::kMinWidth, 2056); 315 factory.AddOptional(MediaStreamVideoSource::kMinWidth, 2056);
311 factory.AddOptional(MediaStreamVideoSource::kMinWidth, 641); 316 factory.AddOptional(MediaStreamVideoSource::kMinWidth, 641);
312 // Since min width is set to 641 pixels, max width 640 can not be fulfilled. 317 // Since min width is set to 641 pixels, max width 640 can not be fulfilled.
313 factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 640); 318 factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 640);
314 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 1280, 720, 30); 319 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 1280, 720, 30);
315 } 320 }
316 321
317 // Test that the webrtc video adapter can be created and that it received 322 // Test that the webrtc video adapter can be created and that it received
318 // video frames if the source deliver video frames. 323 // video frames if the source deliver video frames.
319 TEST_F(MediaStreamVideoSourceTest, AdapterReceiveVideoFrame) { 324 TEST_F(MediaStreamVideoSourceTest, AdapterReceiveVideoFrame) {
320 MockMediaConstraintFactory factory; 325 MockMediaConstraintFactory factory;
321 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 326 blink::WebMediaStreamTrack track = CreateTrackAndStartSource(
322 MediaStreamVideoSource::kDefaultWidth, 327 factory.CreateWebMediaConstraints(),
323 MediaStreamVideoSource::kDefaultHeight, 328 MediaStreamVideoSource::kDefaultWidth,
324 MediaStreamVideoSource::kDefaultFrameRate); 329 MediaStreamVideoSource::kDefaultHeight,
330 MediaStreamVideoSource::kDefaultFrameRate);
325 ASSERT_TRUE(mock_source()->GetAdapter()); 331 ASSERT_TRUE(mock_source()->GetAdapter());
326 MockVideoSource* adapter = static_cast<MockVideoSource*>( 332 MockVideoSource* adapter = static_cast<MockVideoSource*>(
327 mock_source()->GetAdapter()); 333 mock_source()->GetAdapter());
328 EXPECT_EQ(0, adapter->GetFrameNum()); 334 EXPECT_EQ(0, adapter->GetFrameNum());
329 335
330 scoped_refptr<media::VideoFrame> frame = 336 scoped_refptr<media::VideoFrame> frame =
331 media::VideoFrame::CreateBlackFrame( 337 media::VideoFrame::CreateBlackFrame(
332 gfx::Size(MediaStreamVideoSource::kDefaultWidth, 338 gfx::Size(MediaStreamVideoSource::kDefaultWidth,
333 MediaStreamVideoSource::kDefaultHeight)); 339 MediaStreamVideoSource::kDefaultHeight));
334 mock_source()->DeliverVideoFrame(frame); 340 mock_source()->DeliverVideoFrame(frame);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported( 401 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported(
396 MediaStreamVideoSource::kMaxHeight)); 402 MediaStreamVideoSource::kMaxHeight));
397 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported( 403 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported(
398 MediaStreamVideoSource::kMinHeight)); 404 MediaStreamVideoSource::kMinHeight));
399 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported( 405 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported(
400 MediaStreamVideoSource::kMaxAspectRatio)); 406 MediaStreamVideoSource::kMaxAspectRatio));
401 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported( 407 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported(
402 MediaStreamVideoSource::kMinAspectRatio)); 408 MediaStreamVideoSource::kMinAspectRatio));
403 409
404 EXPECT_FALSE(MediaStreamVideoSource::IsConstraintSupported( 410 EXPECT_FALSE(MediaStreamVideoSource::IsConstraintSupported(
405 "googCpuAdaptation")); 411 "googCpuAdaptation"));
tommi (sloooow) - chröme 2014/04/07 10:05:44 is this constant nowhere specified? if no, can you
perkj_chrome 2014/04/07 15:33:52 this is not related to this cl but I changed this
406 } 412 }
407 413
408 } // namespace content 414 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698