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

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

Issue 2790823002: Spec compliant video constraints for getUserMedia behind flag. (Closed)
Patch Set: rebase Created 3 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
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 "content/renderer/media/media_stream_video_capturer_source.h" 5 #include "content/renderer/media/media_stream_video_capturer_source.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/test/scoped_feature_list.h"
15 #include "content/child/child_process.h" 16 #include "content/child/child_process.h"
17 #include "content/public/common/content_features.h"
16 #include "content/public/renderer/media_stream_video_sink.h" 18 #include "content/public/renderer/media_stream_video_sink.h"
17 #include "content/renderer/media/media_stream_video_track.h" 19 #include "content/renderer/media/media_stream_video_track.h"
18 #include "content/renderer/media/mock_constraint_factory.h" 20 #include "content/renderer/media/mock_constraint_factory.h"
21 #include "content/renderer/media/video_track_adapter.h"
19 #include "media/base/bind_to_current_loop.h" 22 #include "media/base/bind_to_current_loop.h"
20 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
22 #include "third_party/WebKit/public/web/WebHeap.h" 25 #include "third_party/WebKit/public/web/WebHeap.h"
23 26
24 using ::testing::_; 27 using ::testing::_;
25 using ::testing::InSequence; 28 using ::testing::InSequence;
26 using ::testing::Invoke; 29 using ::testing::Invoke;
27 using ::testing::WithArgs; 30 using ::testing::WithArgs;
28 31
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 blink::WebMediaStreamTrack StartSource() { 100 blink::WebMediaStreamTrack StartSource() {
98 bool enabled = true; 101 bool enabled = true;
99 // CreateVideoTrack will trigger OnConstraintsApplied. 102 // CreateVideoTrack will trigger OnConstraintsApplied.
100 return MediaStreamVideoTrack::CreateVideoTrack( 103 return MediaStreamVideoTrack::CreateVideoTrack(
101 source_, constraint_factory_.CreateWebMediaConstraints(), 104 source_, constraint_factory_.CreateWebMediaConstraints(),
102 base::Bind(&MediaStreamVideoCapturerSourceTest::OnConstraintsApplied, 105 base::Bind(&MediaStreamVideoCapturerSourceTest::OnConstraintsApplied,
103 base::Unretained(this)), 106 base::Unretained(this)),
104 enabled); 107 enabled);
105 } 108 }
106 109
110 blink::WebMediaStreamTrack StartSource(
111 const VideoTrackAdapterSettings& adapter_settings,
112 const base::Optional<bool>& noise_reduction,
113 bool is_screencast,
114 double min_frame_rate) {
115 bool enabled = true;
116 // CreateVideoTrack will trigger OnConstraintsApplied.
117 return MediaStreamVideoTrack::CreateVideoTrack(
118 source_, adapter_settings, noise_reduction, is_screencast,
119 min_frame_rate,
120 base::Bind(&MediaStreamVideoCapturerSourceTest::OnConstraintsApplied,
121 base::Unretained(this)),
122 enabled);
123 }
124
107 MockVideoCapturerSource& mock_delegate() { return *delegate_; } 125 MockVideoCapturerSource& mock_delegate() { return *delegate_; }
108 126
109 const char* GetPowerLineFrequencyForTesting() const { 127 const char* GetPowerLineFrequencyForTesting() const {
110 return source_->GetPowerLineFrequencyForTesting(); 128 return source_->GetPowerLineFrequencyForTesting();
111 } 129 }
112 130
113 void OnSourceStopped(const blink::WebMediaStreamSource& source) { 131 void OnSourceStopped(const blink::WebMediaStreamSource& source) {
114 source_stopped_ = true; 132 source_stopped_ = true;
115 EXPECT_EQ(source.id(), webkit_source_id_); 133 EXPECT_EQ(source.id(), webkit_source_id_);
116 } 134 }
(...skipping 10 matching lines...) Expand all
127 std::unique_ptr<ChildProcess> child_process_; 145 std::unique_ptr<ChildProcess> child_process_;
128 146
129 blink::WebMediaStreamSource webkit_source_; 147 blink::WebMediaStreamSource webkit_source_;
130 MediaStreamVideoCapturerSource* source_; // owned by |webkit_source_|. 148 MediaStreamVideoCapturerSource* source_; // owned by |webkit_source_|.
131 MockVideoCapturerSource* delegate_; // owned by |source|. 149 MockVideoCapturerSource* delegate_; // owned by |source|.
132 blink::WebString webkit_source_id_; 150 blink::WebString webkit_source_id_;
133 bool source_stopped_; 151 bool source_stopped_;
134 MockConstraintFactory constraint_factory_; 152 MockConstraintFactory constraint_factory_;
135 }; 153 };
136 154
137 TEST_F(MediaStreamVideoCapturerSourceTest, TabCaptureFixedResolutionByDefault) { 155 // This test does not apply with spec-compliant constraints.
156 // TODO(guidou): Remove this test. http://crbug.com/706408
157 TEST_F(MediaStreamVideoCapturerSourceTest,
158 TabCaptureFixedResolutionByDefaultOldConstraints) {
159 base::test::ScopedFeatureList scoped_feature_list;
160 scoped_feature_list.InitAndEnableFeature(
161 features::kMediaStreamOldVideoConstraints);
138 StreamDeviceInfo device_info; 162 StreamDeviceInfo device_info;
139 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; 163 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE;
140 InitWithDeviceInfo(device_info); 164 InitWithDeviceInfo(device_info);
141 165
142 // No constraints are being provided to the implementation, so expect only 166 // No constraints are being provided to the implementation, so expect only
143 // default values. 167 // default values.
144 media::VideoCaptureParams expected_params; 168 media::VideoCaptureParams expected_params;
145 expected_params.requested_format.frame_size.SetSize( 169 expected_params.requested_format.frame_size.SetSize(
146 MediaStreamVideoSource::kDefaultWidth, 170 MediaStreamVideoSource::kDefaultWidth,
147 MediaStreamVideoSource::kDefaultHeight); 171 MediaStreamVideoSource::kDefaultHeight);
148 expected_params.requested_format.frame_rate = 172 expected_params.requested_format.frame_rate =
149 MediaStreamVideoSource::kDefaultFrameRate; 173 MediaStreamVideoSource::kDefaultFrameRate;
150 expected_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 174 expected_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
151 expected_params.resolution_change_policy = 175 expected_params.resolution_change_policy =
152 media::RESOLUTION_POLICY_FIXED_RESOLUTION; 176 media::RESOLUTION_POLICY_FIXED_RESOLUTION;
153 177
154 InSequence s; 178 InSequence s;
155 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); 179 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _));
156 EXPECT_CALL(mock_delegate(), StartCapture(expected_params, _, _)); 180 EXPECT_CALL(mock_delegate(), StartCapture(expected_params, _, _));
157 blink::WebMediaStreamTrack track = StartSource(); 181 blink::WebMediaStreamTrack track = StartSource();
158 // When the track goes out of scope, the source will be stopped. 182 // When the track goes out of scope, the source will be stopped.
159 EXPECT_CALL(mock_delegate(), StopCapture()); 183 EXPECT_CALL(mock_delegate(), StopCapture());
160 } 184 }
161 185
186 // This test does not apply with spec-compliant constraints.
187 // TODO(guidou): Remove this test. http://crbug.com/706408
162 TEST_F(MediaStreamVideoCapturerSourceTest, 188 TEST_F(MediaStreamVideoCapturerSourceTest,
163 DesktopCaptureAllowAnyResolutionChangeByDefault) { 189 DesktopCaptureAllowAnyResolutionChangeByDefaultOldConstraints) {
190 base::test::ScopedFeatureList scoped_feature_list;
191 scoped_feature_list.InitAndEnableFeature(
192 features::kMediaStreamOldVideoConstraints);
164 StreamDeviceInfo device_info; 193 StreamDeviceInfo device_info;
165 device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE; 194 device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE;
166 InitWithDeviceInfo(device_info); 195 InitWithDeviceInfo(device_info);
167 196
168 // No constraints are being provided to the implementation, so expect only 197 // No constraints are being provided to the implementation, so expect only
169 // default values. 198 // default values.
170 media::VideoCaptureParams expected_params; 199 media::VideoCaptureParams expected_params;
171 expected_params.requested_format.frame_size.SetSize( 200 expected_params.requested_format.frame_size.SetSize(
172 MediaStreamVideoSource::kDefaultWidth, 201 MediaStreamVideoSource::kDefaultWidth,
173 MediaStreamVideoSource::kDefaultHeight); 202 MediaStreamVideoSource::kDefaultHeight);
174 expected_params.requested_format.frame_rate = 203 expected_params.requested_format.frame_rate =
175 MediaStreamVideoSource::kDefaultFrameRate; 204 MediaStreamVideoSource::kDefaultFrameRate;
176 expected_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 205 expected_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
177 expected_params.resolution_change_policy = 206 expected_params.resolution_change_policy =
178 media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT; 207 media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT;
179 208
180 InSequence s; 209 InSequence s;
181 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); 210 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _));
182 EXPECT_CALL(mock_delegate(), StartCapture(expected_params, _, _)); 211 EXPECT_CALL(mock_delegate(), StartCapture(expected_params, _, _));
183 blink::WebMediaStreamTrack track = StartSource(); 212 blink::WebMediaStreamTrack track = StartSource();
184 // When the track goes out of scope, the source will be stopped. 213 // When the track goes out of scope, the source will be stopped.
185 EXPECT_CALL(mock_delegate(), StopCapture()); 214 EXPECT_CALL(mock_delegate(), StopCapture());
186 } 215 }
187 216
217 // This test does not apply with spec-compliant constraints.
218 // TODO(guidou): Remove this test. http://crbug.com/706408
188 TEST_F(MediaStreamVideoCapturerSourceTest, 219 TEST_F(MediaStreamVideoCapturerSourceTest,
189 TabCaptureConstraintsImplyFixedAspectRatio) { 220 TabCaptureConstraintsImplyFixedAspectRatioOldConstraints) {
221 base::test::ScopedFeatureList scoped_feature_list;
222 scoped_feature_list.InitAndEnableFeature(
223 features::kMediaStreamOldVideoConstraints);
190 StreamDeviceInfo device_info; 224 StreamDeviceInfo device_info;
191 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; 225 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE;
192 InitWithDeviceInfo(device_info); 226 InitWithDeviceInfo(device_info);
193 227
194 // Specify max and min size constraints that have the same ~16:9 aspect ratio. 228 // Specify max and min size constraints that have the same ~16:9 aspect ratio.
195 constraint_factory()->basic().width.setMax(1920); 229 constraint_factory()->basic().width.setMax(1920);
196 constraint_factory()->basic().height.setMax(1080); 230 constraint_factory()->basic().height.setMax(1080);
197 constraint_factory()->basic().width.setMin(854); 231 constraint_factory()->basic().width.setMin(854);
198 constraint_factory()->basic().height.setMin(480); 232 constraint_factory()->basic().height.setMin(480);
199 constraint_factory()->basic().frameRate.setMax(60.0); 233 constraint_factory()->basic().frameRate.setMax(60.0);
(...skipping 11 matching lines...) Expand all
211 mock_delegate(), 245 mock_delegate(),
212 StartCapture( 246 StartCapture(
213 testing::Field(&media::VideoCaptureParams::resolution_change_policy, 247 testing::Field(&media::VideoCaptureParams::resolution_change_policy,
214 media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO), 248 media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO),
215 _, _)); 249 _, _));
216 blink::WebMediaStreamTrack track = StartSource(); 250 blink::WebMediaStreamTrack track = StartSource();
217 // When the track goes out of scope, the source will be stopped. 251 // When the track goes out of scope, the source will be stopped.
218 EXPECT_CALL(mock_delegate(), StopCapture()); 252 EXPECT_CALL(mock_delegate(), StopCapture());
219 } 253 }
220 254
255 // This test does not apply with spec-compliant constraints.
256 // TODO(guidou): Remove this test. http://crbug.com/706408
221 TEST_F(MediaStreamVideoCapturerSourceTest, 257 TEST_F(MediaStreamVideoCapturerSourceTest,
222 TabCaptureConstraintsImplyAllowingAnyResolutionChange) { 258 TabCaptureConstraintsImplyAllowingAnyResolutionChangeOldConstraints) {
259 base::test::ScopedFeatureList scoped_feature_list;
260 scoped_feature_list.InitAndEnableFeature(
261 features::kMediaStreamOldVideoConstraints);
223 StreamDeviceInfo device_info; 262 StreamDeviceInfo device_info;
224 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; 263 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE;
225 InitWithDeviceInfo(device_info); 264 InitWithDeviceInfo(device_info);
226 265
227 // Specify max and min size constraints with different aspect ratios. 266 // Specify max and min size constraints with different aspect ratios.
228 constraint_factory()->basic().width.setMax(1920); 267 constraint_factory()->basic().width.setMax(1920);
229 constraint_factory()->basic().height.setMax(1080); 268 constraint_factory()->basic().height.setMax(1080);
230 constraint_factory()->basic().width.setMin(0); 269 constraint_factory()->basic().width.setMin(0);
231 constraint_factory()->basic().height.setMin(0); 270 constraint_factory()->basic().height.setMin(0);
232 constraint_factory()->basic().frameRate.setMax(60.0); 271 constraint_factory()->basic().frameRate.setMax(60.0);
(...skipping 11 matching lines...) Expand all
244 mock_delegate(), 283 mock_delegate(),
245 StartCapture( 284 StartCapture(
246 testing::Field(&media::VideoCaptureParams::resolution_change_policy, 285 testing::Field(&media::VideoCaptureParams::resolution_change_policy,
247 media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT), 286 media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT),
248 _, _)); 287 _, _));
249 blink::WebMediaStreamTrack track = StartSource(); 288 blink::WebMediaStreamTrack track = StartSource();
250 // When the track goes out of scope, the source will be stopped. 289 // When the track goes out of scope, the source will be stopped.
251 EXPECT_CALL(mock_delegate(), StopCapture()); 290 EXPECT_CALL(mock_delegate(), StopCapture());
252 } 291 }
253 292
293 // This test does not apply with spec-compliant constraints.
294 // TODO(guidou): Remove this test. http://crbug.com/706408
254 TEST_F(MediaStreamVideoCapturerSourceTest, 295 TEST_F(MediaStreamVideoCapturerSourceTest,
255 DeviceCaptureConstraintsSupportPowerLineFrequency) { 296 DeviceCaptureConstraintsSupportPowerLineFrequencyOldConstraints) {
297 base::test::ScopedFeatureList scoped_feature_list;
298 scoped_feature_list.InitAndEnableFeature(
299 features::kMediaStreamOldVideoConstraints);
256 for (int frequency = -100; frequency < 100; ++frequency) { 300 for (int frequency = -100; frequency < 100; ++frequency) {
257 StreamDeviceInfo device_info; 301 StreamDeviceInfo device_info;
258 device_info.device.type = MEDIA_DEVICE_VIDEO_CAPTURE; 302 device_info.device.type = MEDIA_DEVICE_VIDEO_CAPTURE;
259 InitWithDeviceInfo(device_info); 303 InitWithDeviceInfo(device_info);
260 constraint_factory_.Reset(); 304 constraint_factory_.Reset();
261 305
262 constraint_factory()->AddAdvanced().googPowerLineFrequency.setExact( 306 constraint_factory()->AddAdvanced().googPowerLineFrequency.setExact(
263 frequency); 307 frequency);
264 308
265 media::VideoCaptureParams expected_params; 309 media::VideoCaptureParams expected_params;
(...skipping 18 matching lines...) Expand all
284 328
285 InSequence s; 329 InSequence s;
286 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); 330 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _));
287 EXPECT_CALL(mock_delegate(), StartCapture(expected_params, _, _)); 331 EXPECT_CALL(mock_delegate(), StartCapture(expected_params, _, _));
288 blink::WebMediaStreamTrack track = StartSource(); 332 blink::WebMediaStreamTrack track = StartSource();
289 // When the track goes out of scope, the source will be stopped. 333 // When the track goes out of scope, the source will be stopped.
290 EXPECT_CALL(mock_delegate(), StopCapture()); 334 EXPECT_CALL(mock_delegate(), StopCapture());
291 } 335 }
292 } 336 }
293 337
294 TEST_F(MediaStreamVideoCapturerSourceTest, Ended) { 338 // TODO(guidou): Remove this test. http://crbug.com/706408
339 TEST_F(MediaStreamVideoCapturerSourceTest, EndedOldConstraints) {
340 base::test::ScopedFeatureList scoped_feature_list;
341 scoped_feature_list.InitAndEnableFeature(
342 features::kMediaStreamOldVideoConstraints);
295 std::unique_ptr<MockVideoCapturerSource> delegate( 343 std::unique_ptr<MockVideoCapturerSource> delegate(
296 new MockVideoCapturerSource()); 344 new MockVideoCapturerSource());
297 delegate_ = delegate.get(); 345 delegate_ = delegate.get();
298 source_ = new MediaStreamVideoCapturerSource( 346 source_ = new MediaStreamVideoCapturerSource(
299 base::Bind(&MediaStreamVideoCapturerSourceTest::OnSourceStopped, 347 base::Bind(&MediaStreamVideoCapturerSourceTest::OnSourceStopped,
300 base::Unretained(this)), 348 base::Unretained(this)),
301 std::move(delegate)); 349 std::move(delegate));
302 webkit_source_.initialize(blink::WebString::fromASCII("dummy_source_id"), 350 webkit_source_.initialize(blink::WebString::fromASCII("dummy_source_id"),
303 blink::WebMediaStreamSource::TypeVideo, 351 blink::WebMediaStreamSource::TypeVideo,
304 blink::WebString::fromASCII("dummy_source_name"), 352 blink::WebString::fromASCII("dummy_source_name"),
(...skipping 16 matching lines...) Expand all
321 369
322 EXPECT_CALL(mock_delegate(), StopCapture()); 370 EXPECT_CALL(mock_delegate(), StopCapture());
323 OnStarted(false); 371 OnStarted(false);
324 base::RunLoop().RunUntilIdle(); 372 base::RunLoop().RunUntilIdle();
325 EXPECT_EQ(blink::WebMediaStreamSource::ReadyStateEnded, 373 EXPECT_EQ(blink::WebMediaStreamSource::ReadyStateEnded,
326 webkit_source_.getReadyState()); 374 webkit_source_.getReadyState());
327 // Verify that MediaStreamSource::SourceStoppedCallback has been triggered. 375 // Verify that MediaStreamSource::SourceStoppedCallback has been triggered.
328 EXPECT_TRUE(source_stopped_); 376 EXPECT_TRUE(source_stopped_);
329 } 377 }
330 378
379 TEST_F(MediaStreamVideoCapturerSourceTest, StartAndStop) {
380 base::test::ScopedFeatureList scoped_feature_list;
381 scoped_feature_list.InitAndDisableFeature(
382 features::kMediaStreamOldVideoConstraints);
383 std::unique_ptr<MockVideoCapturerSource> delegate(
384 new MockVideoCapturerSource());
385 delegate_ = delegate.get();
386 EXPECT_CALL(*delegate_, GetPreferredFormats());
387 source_ = new MediaStreamVideoCapturerSource(
388 base::Bind(&MediaStreamVideoCapturerSourceTest::OnSourceStopped,
389 base::Unretained(this)),
390 std::move(delegate));
391 webkit_source_.initialize(blink::WebString::fromASCII("dummy_source_id"),
392 blink::WebMediaStreamSource::TypeVideo,
393 blink::WebString::fromASCII("dummy_source_name"),
394 false /* remote */);
395 webkit_source_.setExtraData(source_);
396 webkit_source_id_ = webkit_source_.id();
397
398 InSequence s;
399 EXPECT_CALL(mock_delegate(), StartCapture(_, _, _));
400 blink::WebMediaStreamTrack track = StartSource(
401 VideoTrackAdapterSettings(), base::Optional<bool>(), false, 0.0);
402 base::RunLoop().RunUntilIdle();
403
404 OnStarted(true);
405 base::RunLoop().RunUntilIdle();
406 EXPECT_EQ(blink::WebMediaStreamSource::ReadyStateLive,
407 webkit_source_.getReadyState());
408
409 EXPECT_FALSE(source_stopped_);
410
411 EXPECT_CALL(mock_delegate(), StopCapture());
412 OnStarted(false);
413 base::RunLoop().RunUntilIdle();
414 EXPECT_EQ(blink::WebMediaStreamSource::ReadyStateEnded,
415 webkit_source_.getReadyState());
416 // Verify that MediaStreamSource::SourceStoppedCallback has been triggered.
417 EXPECT_TRUE(source_stopped_);
418 }
419
331 class FakeMediaStreamVideoSink : public MediaStreamVideoSink { 420 class FakeMediaStreamVideoSink : public MediaStreamVideoSink {
332 public: 421 public:
333 FakeMediaStreamVideoSink(base::TimeTicks* capture_time, 422 FakeMediaStreamVideoSink(base::TimeTicks* capture_time,
334 media::VideoFrameMetadata* metadata, 423 media::VideoFrameMetadata* metadata,
335 base::Closure got_frame_cb) 424 base::Closure got_frame_cb)
336 : capture_time_(capture_time), 425 : capture_time_(capture_time),
337 metadata_(metadata), 426 metadata_(metadata),
338 got_frame_cb_(got_frame_cb) {} 427 got_frame_cb_(got_frame_cb) {}
339 428
340 void ConnectToTrack(const blink::WebMediaStreamTrack& track) { 429 void ConnectToTrack(const blink::WebMediaStreamTrack& track) {
(...skipping 14 matching lines...) Expand all
355 metadata_->MergeMetadataFrom(frame->metadata()); 444 metadata_->MergeMetadataFrom(frame->metadata());
356 base::ResetAndReturn(&got_frame_cb_).Run(); 445 base::ResetAndReturn(&got_frame_cb_).Run();
357 } 446 }
358 447
359 private: 448 private:
360 base::TimeTicks* const capture_time_; 449 base::TimeTicks* const capture_time_;
361 media::VideoFrameMetadata* const metadata_; 450 media::VideoFrameMetadata* const metadata_;
362 base::Closure got_frame_cb_; 451 base::Closure got_frame_cb_;
363 }; 452 };
364 453
365 TEST_F(MediaStreamVideoCapturerSourceTest, CaptureTimeAndMetadataPlumbing) { 454 TEST_F(MediaStreamVideoCapturerSourceTest,
455 CaptureTimeAndMetadataPlumbingOldConstraints) {
456 base::test::ScopedFeatureList scoped_feature_list;
457 scoped_feature_list.InitAndEnableFeature(
458 features::kMediaStreamOldVideoConstraints);
366 StreamDeviceInfo device_info; 459 StreamDeviceInfo device_info;
367 device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE; 460 device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE;
368 InitWithDeviceInfo(device_info); 461 InitWithDeviceInfo(device_info);
369 462
370 VideoCaptureDeliverFrameCB deliver_frame_cb; 463 VideoCaptureDeliverFrameCB deliver_frame_cb;
371 media::VideoCapturerSource::RunningCallback running_cb; 464 media::VideoCapturerSource::RunningCallback running_cb;
372 465
373 InSequence s; 466 InSequence s;
374 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); 467 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _));
375 EXPECT_CALL(mock_delegate(), StartCapture(_, _, _)) 468 EXPECT_CALL(mock_delegate(), StartCapture(_, _, _))
(...skipping 20 matching lines...) Expand all
396 FROM_HERE, base::Bind(deliver_frame_cb, frame, reference_capture_time)); 489 FROM_HERE, base::Bind(deliver_frame_cb, frame, reference_capture_time));
397 run_loop.Run(); 490 run_loop.Run();
398 fake_sink.DisconnectFromTrack(); 491 fake_sink.DisconnectFromTrack();
399 EXPECT_EQ(reference_capture_time, capture_time); 492 EXPECT_EQ(reference_capture_time, capture_time);
400 double metadata_value; 493 double metadata_value;
401 EXPECT_TRUE(metadata.GetDouble(media::VideoFrameMetadata::FRAME_RATE, 494 EXPECT_TRUE(metadata.GetDouble(media::VideoFrameMetadata::FRAME_RATE,
402 &metadata_value)); 495 &metadata_value));
403 EXPECT_EQ(30.0, metadata_value); 496 EXPECT_EQ(30.0, metadata_value);
404 } 497 }
405 498
499 TEST_F(MediaStreamVideoCapturerSourceTest, CaptureTimeAndMetadataPlumbing) {
500 base::test::ScopedFeatureList scoped_feature_list;
501 scoped_feature_list.InitAndDisableFeature(
502 features::kMediaStreamOldVideoConstraints);
503 std::unique_ptr<MockVideoCapturerSource> delegate(
504 new MockVideoCapturerSource());
505 delegate_ = delegate.get();
506 EXPECT_CALL(*delegate_, GetPreferredFormats());
507 source_ = new MediaStreamVideoCapturerSource(
508 base::Bind(&MediaStreamVideoCapturerSourceTest::OnSourceStopped,
509 base::Unretained(this)),
510 std::move(delegate));
511 webkit_source_.initialize(blink::WebString::fromASCII("dummy_source_id"),
512 blink::WebMediaStreamSource::TypeVideo,
513 blink::WebString::fromASCII("dummy_source_name"),
514 false /* remote */);
515 webkit_source_.setExtraData(source_);
516 webkit_source_id_ = webkit_source_.id();
517
518 VideoCaptureDeliverFrameCB deliver_frame_cb;
519 media::VideoCapturerSource::RunningCallback running_cb;
520
521 InSequence s;
522 // EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _));
523 EXPECT_CALL(mock_delegate(), StartCapture(_, _, _))
524 .WillOnce(testing::DoAll(testing::SaveArg<1>(&deliver_frame_cb),
525 testing::SaveArg<2>(&running_cb)));
526 EXPECT_CALL(mock_delegate(), RequestRefreshFrame());
527 EXPECT_CALL(mock_delegate(), StopCapture());
528 blink::WebMediaStreamTrack track = StartSource(
529 VideoTrackAdapterSettings(), base::Optional<bool>(), false, 0.0);
530 running_cb.Run(true);
531
532 base::RunLoop run_loop;
533 base::TimeTicks reference_capture_time =
534 base::TimeTicks::FromInternalValue(60013);
535 base::TimeTicks capture_time;
536 media::VideoFrameMetadata metadata;
537 FakeMediaStreamVideoSink fake_sink(
538 &capture_time, &metadata,
539 media::BindToCurrentLoop(run_loop.QuitClosure()));
540 fake_sink.ConnectToTrack(track);
541 const scoped_refptr<media::VideoFrame> frame =
542 media::VideoFrame::CreateBlackFrame(gfx::Size(2, 2));
543 frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, 30.0);
544 child_process_->io_task_runner()->PostTask(
545 FROM_HERE, base::Bind(deliver_frame_cb, frame, reference_capture_time));
546 run_loop.Run();
547 fake_sink.DisconnectFromTrack();
548 EXPECT_EQ(reference_capture_time, capture_time);
549 double metadata_value;
550 EXPECT_TRUE(metadata.GetDouble(media::VideoFrameMetadata::FRAME_RATE,
551 &metadata_value));
552 EXPECT_EQ(30.0, metadata_value);
553 }
554
406 } // namespace content 555 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698