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

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: Addressed comments. 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 // Test that the source crops to the requested max width and 94 // Test that the source crops to the requested max width and
95 // height even though the camera delivers a larger frame. 95 // height even though the camera delivers a larger frame.
96 // TODO(perkj): Frame resolution should be verified in MediaStreamVideoTrack 96 // TODO(perkj): Frame resolution should be verified in MediaStreamVideoTrack
97 // and not in the adapter. 97 // and not in the adapter.
98 void TestSourceCropFrame(int capture_width, 98 void TestSourceCropFrame(int capture_width,
99 int capture_height, 99 int capture_height,
100 const blink::WebMediaConstraints& constraints, 100 const blink::WebMediaConstraints& constraints,
101 int expected_height, 101 int expected_height,
102 int expected_width) { 102 int expected_width) {
103 // Expect the source to start capture with the supported resolution. 103 // Expect the source to start capture with the supported resolution.
104 CreateTrackAndStartSource(constraints, capture_width, capture_height , 30); 104 blink::WebMediaStreamTrack track = CreateTrackAndStartSource(
105 constraints, capture_width, capture_height , 30);
105 106
106 ASSERT_TRUE(mock_source()->GetAdapter()); 107 ASSERT_TRUE(mock_source()->GetAdapter());
107 MockVideoSource* adapter = static_cast<MockVideoSource*>( 108 MockVideoSource* adapter = static_cast<MockVideoSource*>(
108 mock_source()->GetAdapter()); 109 mock_source()->GetAdapter());
109 EXPECT_EQ(0, adapter->GetFrameNum()); 110 EXPECT_EQ(0, adapter->GetFrameNum());
110 111
111 scoped_refptr<media::VideoFrame> frame = 112 scoped_refptr<media::VideoFrame> frame =
112 media::VideoFrame::CreateBlackFrame(gfx::Size(capture_width, 113 media::VideoFrame::CreateBlackFrame(gfx::Size(capture_width,
113 capture_height)); 114 capture_height));
114 mock_source()->DeliverVideoFrame(frame); 115 mock_source()->DeliverVideoFrame(frame);
(...skipping 18 matching lines...) Expand all
133 int number_of_failed_constraints_applied_; 134 int number_of_failed_constraints_applied_;
134 MockMediaStreamDependencyFactory factory_; 135 MockMediaStreamDependencyFactory factory_;
135 blink::WebMediaStreamSource webkit_source_; 136 blink::WebMediaStreamSource webkit_source_;
136 // |mock_source_| is owned by |webkit_source_|. 137 // |mock_source_| is owned by |webkit_source_|.
137 MockMediaStreamVideoSource* mock_source_; 138 MockMediaStreamVideoSource* mock_source_;
138 }; 139 };
139 140
140 TEST_F(MediaStreamVideoSourceTest, AddTrackAndStartSource) { 141 TEST_F(MediaStreamVideoSourceTest, AddTrackAndStartSource) {
141 blink::WebMediaConstraints constraints; 142 blink::WebMediaConstraints constraints;
142 constraints.initialize(); 143 constraints.initialize();
143 CreateTrack("123", constraints); 144 blink::WebMediaStreamTrack track = CreateTrack("123", constraints);
144 mock_source()->CompleteGetSupportedFormats(); 145 mock_source()->CompleteGetSupportedFormats();
145 mock_source()->StartMockedSource(); 146 mock_source()->StartMockedSource();
146 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); 147 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks());
147 } 148 }
148 149
149 TEST_F(MediaStreamVideoSourceTest, AddTwoTracksBeforeSourceStarts) { 150 TEST_F(MediaStreamVideoSourceTest, AddTwoTracksBeforeSourceStarts) {
150 blink::WebMediaConstraints constraints; 151 blink::WebMediaConstraints constraints;
151 constraints.initialize(); 152 constraints.initialize();
152 blink::WebMediaStreamTrack track1 = CreateTrack("123", constraints); 153 blink::WebMediaStreamTrack track1 = CreateTrack("123", constraints);
153 mock_source()->CompleteGetSupportedFormats(); 154 mock_source()->CompleteGetSupportedFormats();
154 blink::WebMediaStreamTrack track2 = CreateTrack("123", constraints); 155 blink::WebMediaStreamTrack track2 = CreateTrack("123", constraints);
155 EXPECT_EQ(0, NumberOfSuccessConstraintsCallbacks()); 156 EXPECT_EQ(0, NumberOfSuccessConstraintsCallbacks());
156 mock_source()->StartMockedSource(); 157 mock_source()->StartMockedSource();
157 EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks()); 158 EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks());
158 } 159 }
159 160
160 TEST_F(MediaStreamVideoSourceTest, AddTrackAfterSourceStarts) { 161 TEST_F(MediaStreamVideoSourceTest, AddTrackAfterSourceStarts) {
161 blink::WebMediaConstraints constraints; 162 blink::WebMediaConstraints constraints;
162 constraints.initialize(); 163 constraints.initialize();
163 CreateTrack("123", constraints); 164 blink::WebMediaStreamTrack track1 = CreateTrack("123", constraints);
164 mock_source()->CompleteGetSupportedFormats(); 165 mock_source()->CompleteGetSupportedFormats();
165 mock_source()->StartMockedSource(); 166 mock_source()->StartMockedSource();
166 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); 167 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks());
167 CreateTrack("123", constraints); 168 blink::WebMediaStreamTrack track2 = CreateTrack("123", constraints);
168 EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks()); 169 EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks());
169 } 170 }
170 171
171 TEST_F(MediaStreamVideoSourceTest, AddTrackAndFailToStartSource) { 172 TEST_F(MediaStreamVideoSourceTest, AddTrackAndFailToStartSource) {
172 blink::WebMediaConstraints constraints; 173 blink::WebMediaConstraints constraints;
173 constraints.initialize(); 174 constraints.initialize();
174 CreateTrack("123", constraints); 175 blink::WebMediaStreamTrack track = CreateTrack("123", constraints);
175 mock_source()->CompleteGetSupportedFormats(); 176 mock_source()->CompleteGetSupportedFormats();
176 mock_source()->FailToStartMockedSource(); 177 mock_source()->FailToStartMockedSource();
177 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); 178 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks());
178 } 179 }
179 180
180 TEST_F(MediaStreamVideoSourceTest, AddTwoTracksBeforeGetSupportedFormats) { 181 TEST_F(MediaStreamVideoSourceTest, AddTwoTracksBeforeGetSupportedFormats) {
181 blink::WebMediaConstraints constraints; 182 blink::WebMediaConstraints constraints;
182 constraints.initialize(); 183 constraints.initialize();
183 CreateTrack("123", constraints); 184 blink::WebMediaStreamTrack track1 = CreateTrack("123", constraints);
184 CreateTrack("123", constraints); 185 blink::WebMediaStreamTrack track2 = CreateTrack("123", constraints);
185 mock_source()->CompleteGetSupportedFormats(); 186 mock_source()->CompleteGetSupportedFormats();
186 mock_source()->StartMockedSource(); 187 mock_source()->StartMockedSource();
187 EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks()); 188 EXPECT_EQ(2, NumberOfSuccessConstraintsCallbacks());
188 } 189 }
189 190
190 // Test that the capture output is CIF if we set max constraints to CIF. 191 // Test that the capture output is CIF if we set max constraints to CIF.
191 // and the capture device support CIF. 192 // and the capture device support CIF.
192 TEST_F(MediaStreamVideoSourceTest, MandatoryConstraintCif5Fps) { 193 TEST_F(MediaStreamVideoSourceTest, MandatoryConstraintCif5Fps) {
193 MockMediaConstraintFactory factory; 194 MockMediaConstraintFactory factory;
194 factory.AddMandatory(MediaStreamVideoSource::kMaxWidth, 352); 195 factory.AddMandatory(MediaStreamVideoSource::kMaxWidth, 352);
(...skipping 28 matching lines...) Expand all
223 factory.AddOptional(MediaStreamVideoSource::kMinWidth, 1280); 224 factory.AddOptional(MediaStreamVideoSource::kMinWidth, 1280);
224 225
225 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 640, 480, 30); 226 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 640, 480, 30);
226 } 227 }
227 228
228 // Test that AddTrack fail if the mandatory aspect ratio 229 // Test that AddTrack fail if the mandatory aspect ratio
229 // is set higher than supported. 230 // is set higher than supported.
230 TEST_F(MediaStreamVideoSourceTest, MandatoryAspectRatioTooHigh) { 231 TEST_F(MediaStreamVideoSourceTest, MandatoryAspectRatioTooHigh) {
231 MockMediaConstraintFactory factory; 232 MockMediaConstraintFactory factory;
232 factory.AddMandatory(MediaStreamVideoSource::kMinAspectRatio, 2); 233 factory.AddMandatory(MediaStreamVideoSource::kMinAspectRatio, 2);
233 CreateTrack("123", factory.CreateWebMediaConstraints()); 234 blink::WebMediaStreamTrack track = CreateTrack(
235 "123", factory.CreateWebMediaConstraints());
234 mock_source()->CompleteGetSupportedFormats(); 236 mock_source()->CompleteGetSupportedFormats();
235 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); 237 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks());
236 } 238 }
237 239
238 // Test that the source ignores an optional aspect ratio that is higher than 240 // Test that the source ignores an optional aspect ratio that is higher than
239 // supported. 241 // supported.
240 TEST_F(MediaStreamVideoSourceTest, OptionalAspectRatioTooHigh) { 242 TEST_F(MediaStreamVideoSourceTest, OptionalAspectRatioTooHigh) {
241 MockMediaConstraintFactory factory; 243 MockMediaConstraintFactory factory;
242 factory.AddOptional(MediaStreamVideoSource::kMinAspectRatio, 2); 244 factory.AddOptional(MediaStreamVideoSource::kMinAspectRatio, 2);
243 CreateTrack("123", factory.CreateWebMediaConstraints()); 245 blink::WebMediaStreamTrack track = CreateTrack(
246 "123", factory.CreateWebMediaConstraints());
244 mock_source()->CompleteGetSupportedFormats(); 247 mock_source()->CompleteGetSupportedFormats();
245 248
246 const media::VideoCaptureParams& params = mock_source()->start_params(); 249 const media::VideoCaptureParams& params = mock_source()->start_params();
247 double aspect_ratio = 250 double aspect_ratio =
248 static_cast<double>(params.requested_format.frame_size.width()) / 251 static_cast<double>(params.requested_format.frame_size.width()) /
249 params.requested_format.frame_size.height(); 252 params.requested_format.frame_size.height();
250 EXPECT_LT(aspect_ratio, 2); 253 EXPECT_LT(aspect_ratio, 2);
251 } 254 }
252 255
253 // Test that the source starts video with the default resolution if the 256 // Test that the source starts video with the default resolution if the
(...skipping 11 matching lines...) Expand all
265 constraints.initialize(); 268 constraints.initialize();
266 CreateTrackAndStartSource(constraints, 269 CreateTrackAndStartSource(constraints,
267 MediaStreamVideoSource::kDefaultWidth, 270 MediaStreamVideoSource::kDefaultWidth,
268 MediaStreamVideoSource::kDefaultHeight, 271 MediaStreamVideoSource::kDefaultHeight,
269 30); 272 30);
270 } 273 }
271 274
272 TEST_F(MediaStreamVideoSourceTest, InvalidMandatoryConstraint) { 275 TEST_F(MediaStreamVideoSourceTest, InvalidMandatoryConstraint) {
273 MockMediaConstraintFactory factory; 276 MockMediaConstraintFactory factory;
274 factory.AddMandatory("weird key", 640); 277 factory.AddMandatory("weird key", 640);
275 CreateTrack("123", factory.CreateWebMediaConstraints()); 278 blink::WebMediaStreamTrack track = CreateTrack(
279 "123", factory.CreateWebMediaConstraints());
276 mock_source()->CompleteGetSupportedFormats(); 280 mock_source()->CompleteGetSupportedFormats();
277 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); 281 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks());
278 } 282 }
279 283
280 // Test that the source ignores an unknown optional constraint. 284 // Test that the source ignores an unknown optional constraint.
281 TEST_F(MediaStreamVideoSourceTest, InvalidOptionalConstraint) { 285 TEST_F(MediaStreamVideoSourceTest, InvalidOptionalConstraint) {
282 MockMediaConstraintFactory factory; 286 MockMediaConstraintFactory factory;
283 factory.AddOptional("weird key", 640); 287 factory.AddOptional("weird key", 640);
284 288
285 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 289 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(),
286 MediaStreamVideoSource::kDefaultWidth, 290 MediaStreamVideoSource::kDefaultWidth,
287 MediaStreamVideoSource::kDefaultHeight, 291 MediaStreamVideoSource::kDefaultHeight,
288 30); 292 30);
289 } 293 }
290 294
291 // Tests that the source starts video with the max width and height set by 295 // Tests that the source starts video with the max width and height set by
292 // constraints for screencast. 296 // constraints for screencast.
293 TEST_F(MediaStreamVideoSourceTest, ScreencastResolutionWithConstraint) { 297 TEST_F(MediaStreamVideoSourceTest, ScreencastResolutionWithConstraint) {
294 media::VideoCaptureFormats formats; 298 media::VideoCaptureFormats formats;
295 formats.push_back(media::VideoCaptureFormat( 299 formats.push_back(media::VideoCaptureFormat(
296 gfx::Size(480, 270), 30, media::PIXEL_FORMAT_I420)); 300 gfx::Size(480, 270), 30, media::PIXEL_FORMAT_I420));
297 mock_source()->SetSupportedFormats(formats); 301 mock_source()->SetSupportedFormats(formats);
298 MockMediaConstraintFactory factory; 302 MockMediaConstraintFactory factory;
299 factory.AddMandatory(MediaStreamVideoSource::kMaxWidth, 480); 303 factory.AddMandatory(MediaStreamVideoSource::kMaxWidth, 480);
300 factory.AddMandatory(MediaStreamVideoSource::kMaxHeight, 270); 304 factory.AddMandatory(MediaStreamVideoSource::kMaxHeight, 270);
301 305
302 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 480, 270, 30); 306 blink::WebMediaStreamTrack track = CreateTrackAndStartSource(
307 factory.CreateWebMediaConstraints(), 480, 270, 30);
303 EXPECT_EQ(480, mock_source()->max_requested_height()); 308 EXPECT_EQ(480, mock_source()->max_requested_height());
304 EXPECT_EQ(270, mock_source()->max_requested_width()); 309 EXPECT_EQ(270, mock_source()->max_requested_width());
305 } 310 }
306 311
307 // Test that optional constraints are applied in order. 312 // Test that optional constraints are applied in order.
308 TEST_F(MediaStreamVideoSourceTest, OptionalConstraints) { 313 TEST_F(MediaStreamVideoSourceTest, OptionalConstraints) {
309 MockMediaConstraintFactory factory; 314 MockMediaConstraintFactory factory;
310 // Min width of 2056 pixels can not be fulfilled. 315 // Min width of 2056 pixels can not be fulfilled.
311 factory.AddOptional(MediaStreamVideoSource::kMinWidth, 2056); 316 factory.AddOptional(MediaStreamVideoSource::kMinWidth, 2056);
312 factory.AddOptional(MediaStreamVideoSource::kMinWidth, 641); 317 factory.AddOptional(MediaStreamVideoSource::kMinWidth, 641);
313 // Since min width is set to 641 pixels, max width 640 can not be fulfilled. 318 // Since min width is set to 641 pixels, max width 640 can not be fulfilled.
314 factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 640); 319 factory.AddOptional(MediaStreamVideoSource::kMaxWidth, 640);
315 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 1280, 720, 30); 320 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 1280, 720, 30);
316 } 321 }
317 322
318 // Test that the webrtc video adapter can be created and that it received 323 // Test that the webrtc video adapter can be created and that it received
319 // video frames if the source deliver video frames. 324 // video frames if the source deliver video frames.
320 TEST_F(MediaStreamVideoSourceTest, AdapterReceiveVideoFrame) { 325 TEST_F(MediaStreamVideoSourceTest, AdapterReceiveVideoFrame) {
321 MockMediaConstraintFactory factory; 326 MockMediaConstraintFactory factory;
322 CreateTrackAndStartSource(factory.CreateWebMediaConstraints(), 327 blink::WebMediaStreamTrack track = CreateTrackAndStartSource(
323 MediaStreamVideoSource::kDefaultWidth, 328 factory.CreateWebMediaConstraints(),
324 MediaStreamVideoSource::kDefaultHeight, 329 MediaStreamVideoSource::kDefaultWidth,
325 MediaStreamVideoSource::kDefaultFrameRate); 330 MediaStreamVideoSource::kDefaultHeight,
331 MediaStreamVideoSource::kDefaultFrameRate);
326 ASSERT_TRUE(mock_source()->GetAdapter()); 332 ASSERT_TRUE(mock_source()->GetAdapter());
327 MockVideoSource* adapter = static_cast<MockVideoSource*>( 333 MockVideoSource* adapter = static_cast<MockVideoSource*>(
328 mock_source()->GetAdapter()); 334 mock_source()->GetAdapter());
329 EXPECT_EQ(0, adapter->GetFrameNum()); 335 EXPECT_EQ(0, adapter->GetFrameNum());
330 336
331 scoped_refptr<media::VideoFrame> frame = 337 scoped_refptr<media::VideoFrame> frame =
332 media::VideoFrame::CreateBlackFrame( 338 media::VideoFrame::CreateBlackFrame(
333 gfx::Size(MediaStreamVideoSource::kDefaultWidth, 339 gfx::Size(MediaStreamVideoSource::kDefaultWidth,
334 MediaStreamVideoSource::kDefaultHeight)); 340 MediaStreamVideoSource::kDefaultHeight));
335 mock_source()->DeliverVideoFrame(frame); 341 mock_source()->DeliverVideoFrame(frame);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported( 454 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported(
449 MediaStreamVideoSource::kMaxHeight)); 455 MediaStreamVideoSource::kMaxHeight));
450 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported( 456 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported(
451 MediaStreamVideoSource::kMinHeight)); 457 MediaStreamVideoSource::kMinHeight));
452 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported( 458 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported(
453 MediaStreamVideoSource::kMaxAspectRatio)); 459 MediaStreamVideoSource::kMaxAspectRatio));
454 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported( 460 EXPECT_TRUE(MediaStreamVideoSource::IsConstraintSupported(
455 MediaStreamVideoSource::kMinAspectRatio)); 461 MediaStreamVideoSource::kMinAspectRatio));
456 462
457 EXPECT_FALSE(MediaStreamVideoSource::IsConstraintSupported( 463 EXPECT_FALSE(MediaStreamVideoSource::IsConstraintSupported(
458 "googCpuAdaptation")); 464 "something unsupported"));
459 } 465 }
460 466
461 } // namespace content 467 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_video_source.cc ('k') | content/renderer/media/media_stream_video_track.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698