OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 |
155 // This test does not apply with spec-compliant constraints. | |
137 TEST_F(MediaStreamVideoCapturerSourceTest, TabCaptureFixedResolutionByDefault) { | 156 TEST_F(MediaStreamVideoCapturerSourceTest, TabCaptureFixedResolutionByDefault) { |
157 base::test::ScopedFeatureList scoped_feature_list; | |
158 scoped_feature_list.InitAndEnableFeature( | |
159 features::kMediaStreamOldVideoConstraints); | |
138 StreamDeviceInfo device_info; | 160 StreamDeviceInfo device_info; |
139 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; | 161 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; |
140 InitWithDeviceInfo(device_info); | 162 InitWithDeviceInfo(device_info); |
141 | 163 |
142 // No constraints are being provided to the implementation, so expect only | 164 // No constraints are being provided to the implementation, so expect only |
143 // default values. | 165 // default values. |
144 media::VideoCaptureParams expected_params; | 166 media::VideoCaptureParams expected_params; |
145 expected_params.requested_format.frame_size.SetSize( | 167 expected_params.requested_format.frame_size.SetSize( |
146 MediaStreamVideoSource::kDefaultWidth, | 168 MediaStreamVideoSource::kDefaultWidth, |
147 MediaStreamVideoSource::kDefaultHeight); | 169 MediaStreamVideoSource::kDefaultHeight); |
148 expected_params.requested_format.frame_rate = | 170 expected_params.requested_format.frame_rate = |
149 MediaStreamVideoSource::kDefaultFrameRate; | 171 MediaStreamVideoSource::kDefaultFrameRate; |
150 expected_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; | 172 expected_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
151 expected_params.resolution_change_policy = | 173 expected_params.resolution_change_policy = |
152 media::RESOLUTION_POLICY_FIXED_RESOLUTION; | 174 media::RESOLUTION_POLICY_FIXED_RESOLUTION; |
153 | 175 |
154 InSequence s; | 176 InSequence s; |
155 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); | 177 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); |
156 EXPECT_CALL(mock_delegate(), StartCapture(expected_params, _, _)); | 178 EXPECT_CALL(mock_delegate(), StartCapture(expected_params, _, _)); |
157 blink::WebMediaStreamTrack track = StartSource(); | 179 blink::WebMediaStreamTrack track = StartSource(); |
158 // When the track goes out of scope, the source will be stopped. | 180 // When the track goes out of scope, the source will be stopped. |
159 EXPECT_CALL(mock_delegate(), StopCapture()); | 181 EXPECT_CALL(mock_delegate(), StopCapture()); |
160 } | 182 } |
161 | 183 |
184 // This test does not apply with spec-compliant constraints. | |
hbos_chromium
2017/04/05 12:37:28
For all of these add a TODO to remove when the old
Guido Urdaneta
2017/04/05 16:17:16
Done.
| |
162 TEST_F(MediaStreamVideoCapturerSourceTest, | 185 TEST_F(MediaStreamVideoCapturerSourceTest, |
163 DesktopCaptureAllowAnyResolutionChangeByDefault) { | 186 DesktopCaptureAllowAnyResolutionChangeByDefault) { |
187 base::test::ScopedFeatureList scoped_feature_list; | |
188 scoped_feature_list.InitAndEnableFeature( | |
189 features::kMediaStreamOldVideoConstraints); | |
164 StreamDeviceInfo device_info; | 190 StreamDeviceInfo device_info; |
165 device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE; | 191 device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE; |
166 InitWithDeviceInfo(device_info); | 192 InitWithDeviceInfo(device_info); |
167 | 193 |
168 // No constraints are being provided to the implementation, so expect only | 194 // No constraints are being provided to the implementation, so expect only |
169 // default values. | 195 // default values. |
170 media::VideoCaptureParams expected_params; | 196 media::VideoCaptureParams expected_params; |
171 expected_params.requested_format.frame_size.SetSize( | 197 expected_params.requested_format.frame_size.SetSize( |
172 MediaStreamVideoSource::kDefaultWidth, | 198 MediaStreamVideoSource::kDefaultWidth, |
173 MediaStreamVideoSource::kDefaultHeight); | 199 MediaStreamVideoSource::kDefaultHeight); |
174 expected_params.requested_format.frame_rate = | 200 expected_params.requested_format.frame_rate = |
175 MediaStreamVideoSource::kDefaultFrameRate; | 201 MediaStreamVideoSource::kDefaultFrameRate; |
176 expected_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; | 202 expected_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
177 expected_params.resolution_change_policy = | 203 expected_params.resolution_change_policy = |
178 media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT; | 204 media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT; |
179 | 205 |
180 InSequence s; | 206 InSequence s; |
181 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); | 207 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); |
182 EXPECT_CALL(mock_delegate(), StartCapture(expected_params, _, _)); | 208 EXPECT_CALL(mock_delegate(), StartCapture(expected_params, _, _)); |
183 blink::WebMediaStreamTrack track = StartSource(); | 209 blink::WebMediaStreamTrack track = StartSource(); |
184 // When the track goes out of scope, the source will be stopped. | 210 // When the track goes out of scope, the source will be stopped. |
185 EXPECT_CALL(mock_delegate(), StopCapture()); | 211 EXPECT_CALL(mock_delegate(), StopCapture()); |
186 } | 212 } |
187 | 213 |
214 // This test does not apply with spec-compliant constraints. | |
188 TEST_F(MediaStreamVideoCapturerSourceTest, | 215 TEST_F(MediaStreamVideoCapturerSourceTest, |
189 TabCaptureConstraintsImplyFixedAspectRatio) { | 216 TabCaptureConstraintsImplyFixedAspectRatio) { |
217 base::test::ScopedFeatureList scoped_feature_list; | |
218 scoped_feature_list.InitAndEnableFeature( | |
219 features::kMediaStreamOldVideoConstraints); | |
190 StreamDeviceInfo device_info; | 220 StreamDeviceInfo device_info; |
191 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; | 221 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; |
192 InitWithDeviceInfo(device_info); | 222 InitWithDeviceInfo(device_info); |
193 | 223 |
194 // Specify max and min size constraints that have the same ~16:9 aspect ratio. | 224 // Specify max and min size constraints that have the same ~16:9 aspect ratio. |
195 constraint_factory()->basic().width.setMax(1920); | 225 constraint_factory()->basic().width.setMax(1920); |
196 constraint_factory()->basic().height.setMax(1080); | 226 constraint_factory()->basic().height.setMax(1080); |
197 constraint_factory()->basic().width.setMin(854); | 227 constraint_factory()->basic().width.setMin(854); |
198 constraint_factory()->basic().height.setMin(480); | 228 constraint_factory()->basic().height.setMin(480); |
199 constraint_factory()->basic().frameRate.setMax(60.0); | 229 constraint_factory()->basic().frameRate.setMax(60.0); |
(...skipping 11 matching lines...) Expand all Loading... | |
211 mock_delegate(), | 241 mock_delegate(), |
212 StartCapture( | 242 StartCapture( |
213 testing::Field(&media::VideoCaptureParams::resolution_change_policy, | 243 testing::Field(&media::VideoCaptureParams::resolution_change_policy, |
214 media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO), | 244 media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO), |
215 _, _)); | 245 _, _)); |
216 blink::WebMediaStreamTrack track = StartSource(); | 246 blink::WebMediaStreamTrack track = StartSource(); |
217 // When the track goes out of scope, the source will be stopped. | 247 // When the track goes out of scope, the source will be stopped. |
218 EXPECT_CALL(mock_delegate(), StopCapture()); | 248 EXPECT_CALL(mock_delegate(), StopCapture()); |
219 } | 249 } |
220 | 250 |
251 // This test does not apply with spec-compliant constraints. | |
221 TEST_F(MediaStreamVideoCapturerSourceTest, | 252 TEST_F(MediaStreamVideoCapturerSourceTest, |
222 TabCaptureConstraintsImplyAllowingAnyResolutionChange) { | 253 TabCaptureConstraintsImplyAllowingAnyResolutionChange) { |
254 base::test::ScopedFeatureList scoped_feature_list; | |
255 scoped_feature_list.InitAndEnableFeature( | |
256 features::kMediaStreamOldVideoConstraints); | |
223 StreamDeviceInfo device_info; | 257 StreamDeviceInfo device_info; |
224 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; | 258 device_info.device.type = MEDIA_TAB_VIDEO_CAPTURE; |
225 InitWithDeviceInfo(device_info); | 259 InitWithDeviceInfo(device_info); |
226 | 260 |
227 // Specify max and min size constraints with different aspect ratios. | 261 // Specify max and min size constraints with different aspect ratios. |
228 constraint_factory()->basic().width.setMax(1920); | 262 constraint_factory()->basic().width.setMax(1920); |
229 constraint_factory()->basic().height.setMax(1080); | 263 constraint_factory()->basic().height.setMax(1080); |
230 constraint_factory()->basic().width.setMin(0); | 264 constraint_factory()->basic().width.setMin(0); |
231 constraint_factory()->basic().height.setMin(0); | 265 constraint_factory()->basic().height.setMin(0); |
232 constraint_factory()->basic().frameRate.setMax(60.0); | 266 constraint_factory()->basic().frameRate.setMax(60.0); |
(...skipping 11 matching lines...) Expand all Loading... | |
244 mock_delegate(), | 278 mock_delegate(), |
245 StartCapture( | 279 StartCapture( |
246 testing::Field(&media::VideoCaptureParams::resolution_change_policy, | 280 testing::Field(&media::VideoCaptureParams::resolution_change_policy, |
247 media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT), | 281 media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT), |
248 _, _)); | 282 _, _)); |
249 blink::WebMediaStreamTrack track = StartSource(); | 283 blink::WebMediaStreamTrack track = StartSource(); |
250 // When the track goes out of scope, the source will be stopped. | 284 // When the track goes out of scope, the source will be stopped. |
251 EXPECT_CALL(mock_delegate(), StopCapture()); | 285 EXPECT_CALL(mock_delegate(), StopCapture()); |
252 } | 286 } |
253 | 287 |
288 // This test does not apply with spec-compliant constraints. | |
254 TEST_F(MediaStreamVideoCapturerSourceTest, | 289 TEST_F(MediaStreamVideoCapturerSourceTest, |
255 DeviceCaptureConstraintsSupportPowerLineFrequency) { | 290 DeviceCaptureConstraintsSupportPowerLineFrequency) { |
291 base::test::ScopedFeatureList scoped_feature_list; | |
292 scoped_feature_list.InitAndEnableFeature( | |
293 features::kMediaStreamOldVideoConstraints); | |
256 for (int frequency = -100; frequency < 100; ++frequency) { | 294 for (int frequency = -100; frequency < 100; ++frequency) { |
257 StreamDeviceInfo device_info; | 295 StreamDeviceInfo device_info; |
258 device_info.device.type = MEDIA_DEVICE_VIDEO_CAPTURE; | 296 device_info.device.type = MEDIA_DEVICE_VIDEO_CAPTURE; |
259 InitWithDeviceInfo(device_info); | 297 InitWithDeviceInfo(device_info); |
260 constraint_factory_.Reset(); | 298 constraint_factory_.Reset(); |
261 | 299 |
262 constraint_factory()->AddAdvanced().googPowerLineFrequency.setExact( | 300 constraint_factory()->AddAdvanced().googPowerLineFrequency.setExact( |
263 frequency); | 301 frequency); |
264 | 302 |
265 media::VideoCaptureParams expected_params; | 303 media::VideoCaptureParams expected_params; |
(...skipping 18 matching lines...) Expand all Loading... | |
284 | 322 |
285 InSequence s; | 323 InSequence s; |
286 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); | 324 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); |
287 EXPECT_CALL(mock_delegate(), StartCapture(expected_params, _, _)); | 325 EXPECT_CALL(mock_delegate(), StartCapture(expected_params, _, _)); |
288 blink::WebMediaStreamTrack track = StartSource(); | 326 blink::WebMediaStreamTrack track = StartSource(); |
289 // When the track goes out of scope, the source will be stopped. | 327 // When the track goes out of scope, the source will be stopped. |
290 EXPECT_CALL(mock_delegate(), StopCapture()); | 328 EXPECT_CALL(mock_delegate(), StopCapture()); |
291 } | 329 } |
292 } | 330 } |
293 | 331 |
294 TEST_F(MediaStreamVideoCapturerSourceTest, Ended) { | 332 TEST_F(MediaStreamVideoCapturerSourceTest, Ended) { |
hbos_chromium
2017/04/05 12:37:28
nit: Add here too
// This test does not apply with
Guido Urdaneta
2017/04/05 16:17:16
Done. Actually this test does apply (hence the New
| |
333 base::test::ScopedFeatureList scoped_feature_list; | |
334 scoped_feature_list.InitAndEnableFeature( | |
335 features::kMediaStreamOldVideoConstraints); | |
295 std::unique_ptr<MockVideoCapturerSource> delegate( | 336 std::unique_ptr<MockVideoCapturerSource> delegate( |
296 new MockVideoCapturerSource()); | 337 new MockVideoCapturerSource()); |
297 delegate_ = delegate.get(); | 338 delegate_ = delegate.get(); |
298 source_ = new MediaStreamVideoCapturerSource( | 339 source_ = new MediaStreamVideoCapturerSource( |
299 base::Bind(&MediaStreamVideoCapturerSourceTest::OnSourceStopped, | 340 base::Bind(&MediaStreamVideoCapturerSourceTest::OnSourceStopped, |
300 base::Unretained(this)), | 341 base::Unretained(this)), |
301 std::move(delegate)); | 342 std::move(delegate)); |
302 webkit_source_.initialize(blink::WebString::fromASCII("dummy_source_id"), | 343 webkit_source_.initialize(blink::WebString::fromASCII("dummy_source_id"), |
303 blink::WebMediaStreamSource::TypeVideo, | 344 blink::WebMediaStreamSource::TypeVideo, |
304 blink::WebString::fromASCII("dummy_source_name"), | 345 blink::WebString::fromASCII("dummy_source_name"), |
(...skipping 16 matching lines...) Expand all Loading... | |
321 | 362 |
322 EXPECT_CALL(mock_delegate(), StopCapture()); | 363 EXPECT_CALL(mock_delegate(), StopCapture()); |
323 OnStarted(false); | 364 OnStarted(false); |
324 base::RunLoop().RunUntilIdle(); | 365 base::RunLoop().RunUntilIdle(); |
325 EXPECT_EQ(blink::WebMediaStreamSource::ReadyStateEnded, | 366 EXPECT_EQ(blink::WebMediaStreamSource::ReadyStateEnded, |
326 webkit_source_.getReadyState()); | 367 webkit_source_.getReadyState()); |
327 // Verify that MediaStreamSource::SourceStoppedCallback has been triggered. | 368 // Verify that MediaStreamSource::SourceStoppedCallback has been triggered. |
328 EXPECT_TRUE(source_stopped_); | 369 EXPECT_TRUE(source_stopped_); |
329 } | 370 } |
330 | 371 |
372 TEST_F(MediaStreamVideoCapturerSourceTest, EndedNew) { | |
hbos_chromium
2017/04/05 12:37:28
Since this covers all of interest (with constraint
Guido Urdaneta
2017/04/05 16:17:16
Renamed to StartAndStop.
No suffix implies new con
hbos_chromium
2017/04/05 16:56:31
Acknowledged.
| |
373 base::test::ScopedFeatureList scoped_feature_list; | |
374 scoped_feature_list.InitAndDisableFeature( | |
375 features::kMediaStreamOldVideoConstraints); | |
376 std::unique_ptr<MockVideoCapturerSource> delegate( | |
377 new MockVideoCapturerSource()); | |
378 delegate_ = delegate.get(); | |
379 EXPECT_CALL(*delegate_, GetPreferredFormats()); | |
380 source_ = new MediaStreamVideoCapturerSource( | |
381 base::Bind(&MediaStreamVideoCapturerSourceTest::OnSourceStopped, | |
382 base::Unretained(this)), | |
383 std::move(delegate)); | |
384 webkit_source_.initialize(blink::WebString::fromASCII("dummy_source_id"), | |
385 blink::WebMediaStreamSource::TypeVideo, | |
386 blink::WebString::fromASCII("dummy_source_name"), | |
387 false /* remote */); | |
388 webkit_source_.setExtraData(source_); | |
389 webkit_source_id_ = webkit_source_.id(); | |
390 | |
391 InSequence s; | |
392 EXPECT_CALL(mock_delegate(), StartCapture(_, _, _)); | |
393 blink::WebMediaStreamTrack track = StartSource( | |
394 VideoTrackAdapterSettings(), base::Optional<bool>(), false, 0.0); | |
395 base::RunLoop().RunUntilIdle(); | |
396 | |
397 OnStarted(true); | |
398 base::RunLoop().RunUntilIdle(); | |
399 EXPECT_EQ(blink::WebMediaStreamSource::ReadyStateLive, | |
400 webkit_source_.getReadyState()); | |
401 | |
402 EXPECT_FALSE(source_stopped_); | |
403 | |
404 EXPECT_CALL(mock_delegate(), StopCapture()); | |
405 OnStarted(false); | |
406 base::RunLoop().RunUntilIdle(); | |
407 EXPECT_EQ(blink::WebMediaStreamSource::ReadyStateEnded, | |
408 webkit_source_.getReadyState()); | |
409 // Verify that MediaStreamSource::SourceStoppedCallback has been triggered. | |
410 EXPECT_TRUE(source_stopped_); | |
411 } | |
412 | |
331 class FakeMediaStreamVideoSink : public MediaStreamVideoSink { | 413 class FakeMediaStreamVideoSink : public MediaStreamVideoSink { |
332 public: | 414 public: |
333 FakeMediaStreamVideoSink(base::TimeTicks* capture_time, | 415 FakeMediaStreamVideoSink(base::TimeTicks* capture_time, |
334 media::VideoFrameMetadata* metadata, | 416 media::VideoFrameMetadata* metadata, |
335 base::Closure got_frame_cb) | 417 base::Closure got_frame_cb) |
336 : capture_time_(capture_time), | 418 : capture_time_(capture_time), |
337 metadata_(metadata), | 419 metadata_(metadata), |
338 got_frame_cb_(got_frame_cb) {} | 420 got_frame_cb_(got_frame_cb) {} |
339 | 421 |
340 void ConnectToTrack(const blink::WebMediaStreamTrack& track) { | 422 void ConnectToTrack(const blink::WebMediaStreamTrack& track) { |
(...skipping 15 matching lines...) Expand all Loading... | |
356 base::ResetAndReturn(&got_frame_cb_).Run(); | 438 base::ResetAndReturn(&got_frame_cb_).Run(); |
357 } | 439 } |
358 | 440 |
359 private: | 441 private: |
360 base::TimeTicks* const capture_time_; | 442 base::TimeTicks* const capture_time_; |
361 media::VideoFrameMetadata* const metadata_; | 443 media::VideoFrameMetadata* const metadata_; |
362 base::Closure got_frame_cb_; | 444 base::Closure got_frame_cb_; |
363 }; | 445 }; |
364 | 446 |
365 TEST_F(MediaStreamVideoCapturerSourceTest, CaptureTimeAndMetadataPlumbing) { | 447 TEST_F(MediaStreamVideoCapturerSourceTest, CaptureTimeAndMetadataPlumbing) { |
448 base::test::ScopedFeatureList scoped_feature_list; | |
449 scoped_feature_list.InitAndEnableFeature( | |
450 features::kMediaStreamOldVideoConstraints); | |
366 StreamDeviceInfo device_info; | 451 StreamDeviceInfo device_info; |
367 device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE; | 452 device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE; |
368 InitWithDeviceInfo(device_info); | 453 InitWithDeviceInfo(device_info); |
369 | 454 |
370 VideoCaptureDeliverFrameCB deliver_frame_cb; | 455 VideoCaptureDeliverFrameCB deliver_frame_cb; |
371 media::VideoCapturerSource::RunningCallback running_cb; | 456 media::VideoCapturerSource::RunningCallback running_cb; |
372 | 457 |
373 InSequence s; | 458 InSequence s; |
374 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); | 459 EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); |
375 EXPECT_CALL(mock_delegate(), StartCapture(_, _, _)) | 460 EXPECT_CALL(mock_delegate(), StartCapture(_, _, _)) |
(...skipping 20 matching lines...) Expand all Loading... | |
396 FROM_HERE, base::Bind(deliver_frame_cb, frame, reference_capture_time)); | 481 FROM_HERE, base::Bind(deliver_frame_cb, frame, reference_capture_time)); |
397 run_loop.Run(); | 482 run_loop.Run(); |
398 fake_sink.DisconnectFromTrack(); | 483 fake_sink.DisconnectFromTrack(); |
399 EXPECT_EQ(reference_capture_time, capture_time); | 484 EXPECT_EQ(reference_capture_time, capture_time); |
400 double metadata_value; | 485 double metadata_value; |
401 EXPECT_TRUE(metadata.GetDouble(media::VideoFrameMetadata::FRAME_RATE, | 486 EXPECT_TRUE(metadata.GetDouble(media::VideoFrameMetadata::FRAME_RATE, |
402 &metadata_value)); | 487 &metadata_value)); |
403 EXPECT_EQ(30.0, metadata_value); | 488 EXPECT_EQ(30.0, metadata_value); |
404 } | 489 } |
405 | 490 |
491 TEST_F(MediaStreamVideoCapturerSourceTest, CaptureTimeAndMetadataPlumbingNew) { | |
hbos_chromium
2017/04/05 12:37:28
...WithOldConstraints
and
...WithNewConstraints
?
Guido Urdaneta
2017/04/05 16:17:16
Using OldConstraints for tests that use the old al
hbos_chromium
2017/04/05 16:56:31
Acknowledged.
| |
492 base::test::ScopedFeatureList scoped_feature_list; | |
493 scoped_feature_list.InitAndDisableFeature( | |
494 features::kMediaStreamOldVideoConstraints); | |
495 std::unique_ptr<MockVideoCapturerSource> delegate( | |
496 new MockVideoCapturerSource()); | |
497 delegate_ = delegate.get(); | |
498 EXPECT_CALL(*delegate_, GetPreferredFormats()); | |
499 source_ = new MediaStreamVideoCapturerSource( | |
500 base::Bind(&MediaStreamVideoCapturerSourceTest::OnSourceStopped, | |
501 base::Unretained(this)), | |
502 std::move(delegate)); | |
503 webkit_source_.initialize(blink::WebString::fromASCII("dummy_source_id"), | |
504 blink::WebMediaStreamSource::TypeVideo, | |
505 blink::WebString::fromASCII("dummy_source_name"), | |
506 false /* remote */); | |
507 webkit_source_.setExtraData(source_); | |
508 webkit_source_id_ = webkit_source_.id(); | |
509 | |
510 VideoCaptureDeliverFrameCB deliver_frame_cb; | |
511 media::VideoCapturerSource::RunningCallback running_cb; | |
512 | |
513 InSequence s; | |
514 // EXPECT_CALL(mock_delegate(), GetCurrentSupportedFormats(_, _, _, _)); | |
515 EXPECT_CALL(mock_delegate(), StartCapture(_, _, _)) | |
516 .WillOnce(testing::DoAll(testing::SaveArg<1>(&deliver_frame_cb), | |
517 testing::SaveArg<2>(&running_cb))); | |
518 EXPECT_CALL(mock_delegate(), RequestRefreshFrame()); | |
519 EXPECT_CALL(mock_delegate(), StopCapture()); | |
520 blink::WebMediaStreamTrack track = StartSource( | |
521 VideoTrackAdapterSettings(), base::Optional<bool>(), false, 0.0); | |
522 running_cb.Run(true); | |
523 | |
524 base::RunLoop run_loop; | |
525 base::TimeTicks reference_capture_time = | |
526 base::TimeTicks::FromInternalValue(60013); | |
527 base::TimeTicks capture_time; | |
528 media::VideoFrameMetadata metadata; | |
529 FakeMediaStreamVideoSink fake_sink( | |
530 &capture_time, &metadata, | |
531 media::BindToCurrentLoop(run_loop.QuitClosure())); | |
532 fake_sink.ConnectToTrack(track); | |
533 const scoped_refptr<media::VideoFrame> frame = | |
534 media::VideoFrame::CreateBlackFrame(gfx::Size(2, 2)); | |
535 frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, 30.0); | |
536 child_process_->io_task_runner()->PostTask( | |
537 FROM_HERE, base::Bind(deliver_frame_cb, frame, reference_capture_time)); | |
538 run_loop.Run(); | |
539 fake_sink.DisconnectFromTrack(); | |
540 EXPECT_EQ(reference_capture_time, capture_time); | |
541 double metadata_value; | |
542 EXPECT_TRUE(metadata.GetDouble(media::VideoFrameMetadata::FRAME_RATE, | |
543 &metadata_value)); | |
544 EXPECT_EQ(30.0, metadata_value); | |
545 } | |
546 | |
406 } // namespace content | 547 } // namespace content |
OLD | NEW |