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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/test/scoped_feature_list.h" | 13 #include "base/test/scoped_feature_list.h" |
| 14 #include "build/build_config.h" |
14 #include "content/child/child_process.h" | 15 #include "content/child/child_process.h" |
15 #include "content/public/common/content_features.h" | 16 #include "content/public/common/content_features.h" |
16 #include "content/renderer/media/media_stream_video_source.h" | 17 #include "content/renderer/media/media_stream_video_source.h" |
17 #include "content/renderer/media/media_stream_video_track.h" | 18 #include "content/renderer/media/media_stream_video_track.h" |
18 #include "content/renderer/media/mock_constraint_factory.h" | 19 #include "content/renderer/media/mock_constraint_factory.h" |
19 #include "content/renderer/media/mock_media_stream_video_sink.h" | 20 #include "content/renderer/media/mock_media_stream_video_sink.h" |
20 #include "content/renderer/media/mock_media_stream_video_source.h" | 21 #include "content/renderer/media/mock_media_stream_video_source.h" |
21 #include "content/renderer/media/video_track_adapter.h" | 22 #include "content/renderer/media/video_track_adapter.h" |
22 #include "media/base/limits.h" | 23 #include "media/base/limits.h" |
23 #include "media/base/video_frame.h" | 24 #include "media/base/video_frame.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 double min_frame_rate) { | 91 double min_frame_rate) { |
91 bool enabled = true; | 92 bool enabled = true; |
92 return MediaStreamVideoTrack::CreateVideoTrack( | 93 return MediaStreamVideoTrack::CreateVideoTrack( |
93 mock_source_, adapter_settings, noise_reduction, is_screencast, | 94 mock_source_, adapter_settings, noise_reduction, is_screencast, |
94 min_frame_rate, | 95 min_frame_rate, |
95 base::Bind(&MediaStreamVideoSourceTest::OnConstraintsApplied, | 96 base::Bind(&MediaStreamVideoSourceTest::OnConstraintsApplied, |
96 base::Unretained(this)), | 97 base::Unretained(this)), |
97 enabled); | 98 enabled); |
98 } | 99 } |
99 | 100 |
100 blink::WebMediaStreamTrack CreateTrackAndStartSource(int width, | 101 blink::WebMediaStreamTrack CreateTrackAndStartSource( |
101 int height, | 102 int width, |
102 double frame_rate) { | 103 int height, |
| 104 double frame_rate, |
| 105 bool detect_rotation = false) { |
103 DCHECK(!IsOldVideoConstraints()); | 106 DCHECK(!IsOldVideoConstraints()); |
104 blink::WebMediaStreamTrack track = CreateTrack( | 107 blink::WebMediaStreamTrack track = |
105 "123", | 108 CreateTrack("123", |
106 VideoTrackAdapterSettings(width, height, 0.0, HUGE_VAL, frame_rate), | 109 VideoTrackAdapterSettings( |
107 base::Optional<bool>(), false, 0.0); | 110 width, height, 0.0, HUGE_VAL, frame_rate, |
| 111 detect_rotation ? gfx::Size(width, height) |
| 112 : base::Optional<gfx::Size>()), |
| 113 base::Optional<bool>(), false, 0.0); |
108 | 114 |
109 EXPECT_EQ(0, NumberOfSuccessConstraintsCallbacks()); | 115 EXPECT_EQ(0, NumberOfSuccessConstraintsCallbacks()); |
110 mock_source_->StartMockedSource(); | 116 mock_source_->StartMockedSource(); |
111 // Once the source has started successfully we expect that the | 117 // Once the source has started successfully we expect that the |
112 // ConstraintsCallback in MediaStreamSource::AddTrack completes. | 118 // ConstraintsCallback in MediaStreamSource::AddTrack completes. |
113 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); | 119 EXPECT_EQ(1, NumberOfSuccessConstraintsCallbacks()); |
114 return track; | 120 return track; |
115 } | 121 } |
116 | 122 |
117 int NumberOfSuccessConstraintsCallbacks() const { | 123 int NumberOfSuccessConstraintsCallbacks() const { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 MockMediaStreamVideoSink* sink) { | 161 MockMediaStreamVideoSink* sink) { |
156 base::RunLoop run_loop; | 162 base::RunLoop run_loop; |
157 base::Closure quit_closure = run_loop.QuitClosure(); | 163 base::Closure quit_closure = run_loop.QuitClosure(); |
158 EXPECT_CALL(*sink, OnVideoFrame()).WillOnce(RunClosure(quit_closure)); | 164 EXPECT_CALL(*sink, OnVideoFrame()).WillOnce(RunClosure(quit_closure)); |
159 scoped_refptr<media::VideoFrame> frame = | 165 scoped_refptr<media::VideoFrame> frame = |
160 media::VideoFrame::CreateBlackFrame(gfx::Size(width, height)); | 166 media::VideoFrame::CreateBlackFrame(gfx::Size(width, height)); |
161 mock_source()->DeliverVideoFrame(frame); | 167 mock_source()->DeliverVideoFrame(frame); |
162 run_loop.Run(); | 168 run_loop.Run(); |
163 } | 169 } |
164 | 170 |
| 171 void DeliverRotatedVideoFrameAndWaitForRenderer( |
| 172 int width, |
| 173 int height, |
| 174 MockMediaStreamVideoSink* sink) { |
| 175 DeliverVideoFrameAndWaitForRenderer(height, width, sink); |
| 176 } |
| 177 |
165 void DeliverVideoFrameAndWaitForTwoRenderers( | 178 void DeliverVideoFrameAndWaitForTwoRenderers( |
166 int width, | 179 int width, |
167 int height, | 180 int height, |
168 MockMediaStreamVideoSink* sink1, | 181 MockMediaStreamVideoSink* sink1, |
169 MockMediaStreamVideoSink* sink2) { | 182 MockMediaStreamVideoSink* sink2) { |
170 base::RunLoop run_loop; | 183 base::RunLoop run_loop; |
171 base::Closure quit_closure = run_loop.QuitClosure(); | 184 base::Closure quit_closure = run_loop.QuitClosure(); |
172 EXPECT_CALL(*sink1, OnVideoFrame()); | 185 EXPECT_CALL(*sink1, OnVideoFrame()); |
173 EXPECT_CALL(*sink2, OnVideoFrame()).WillOnce(RunClosure(quit_closure)); | 186 EXPECT_CALL(*sink2, OnVideoFrame()).WillOnce(RunClosure(quit_closure)); |
174 scoped_refptr<media::VideoFrame> frame = | 187 scoped_refptr<media::VideoFrame> frame = |
175 media::VideoFrame::CreateBlackFrame(gfx::Size(width, height)); | 188 media::VideoFrame::CreateBlackFrame(gfx::Size(width, height)); |
176 mock_source()->DeliverVideoFrame(frame); | 189 mock_source()->DeliverVideoFrame(frame); |
177 run_loop.Run(); | 190 run_loop.Run(); |
178 } | 191 } |
179 | 192 |
180 void TestTwoTracksWithDifferentSettings(int capture_width, | 193 void TestTwoTracksWithDifferentSettings(int capture_width, |
181 int capture_height, | 194 int capture_height, |
182 int expected_width1, | 195 int expected_width1, |
183 int expected_height1, | 196 int expected_height1, |
184 int expected_width2, | 197 int expected_width2, |
185 int expected_height2) { | 198 int expected_height2) { |
186 blink::WebMediaStreamTrack track1 = | 199 blink::WebMediaStreamTrack track1 = |
187 CreateTrackAndStartSource(expected_width1, expected_height1, | 200 CreateTrackAndStartSource(expected_width1, expected_height1, |
188 MediaStreamVideoSource::kDefaultFrameRate); | 201 MediaStreamVideoSource::kDefaultFrameRate); |
189 | 202 |
190 blink::WebMediaStreamTrack track2 = | 203 blink::WebMediaStreamTrack track2 = |
191 CreateTrack("dummy", | 204 CreateTrack("dummy", |
192 VideoTrackAdapterSettings( | 205 VideoTrackAdapterSettings( |
193 expected_width2, expected_height2, 0.0, HUGE_VAL, | 206 expected_width2, expected_height2, 0.0, HUGE_VAL, |
194 MediaStreamVideoSource::kDefaultFrameRate), | 207 MediaStreamVideoSource::kDefaultFrameRate, |
| 208 base::Optional<gfx::Size>()), |
195 base::Optional<bool>(), false, 0.0); | 209 base::Optional<bool>(), false, 0.0); |
196 | 210 |
197 MockMediaStreamVideoSink sink1; | 211 MockMediaStreamVideoSink sink1; |
198 sink1.ConnectToTrack(track1); | 212 sink1.ConnectToTrack(track1); |
199 EXPECT_EQ(0, sink1.number_of_frames()); | 213 EXPECT_EQ(0, sink1.number_of_frames()); |
200 | 214 |
201 MockMediaStreamVideoSink sink2; | 215 MockMediaStreamVideoSink sink2; |
202 sink2.ConnectToTrack(track2); | 216 sink2.ConnectToTrack(track2); |
203 EXPECT_EQ(0, sink2.number_of_frames()); | 217 EXPECT_EQ(0, sink2.number_of_frames()); |
204 | 218 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 | 310 |
297 TEST_F(MediaStreamVideoSourceTest, TwoTracksWithVGAAndWVGA) { | 311 TEST_F(MediaStreamVideoSourceTest, TwoTracksWithVGAAndWVGA) { |
298 TestTwoTracksWithDifferentSettings(640, 480, 640, 480, 640, 360); | 312 TestTwoTracksWithDifferentSettings(640, 480, 640, 480, 640, 360); |
299 } | 313 } |
300 | 314 |
301 TEST_F(MediaStreamVideoSourceTest, TwoTracksWith720AndWVGA) { | 315 TEST_F(MediaStreamVideoSourceTest, TwoTracksWith720AndWVGA) { |
302 TestTwoTracksWithDifferentSettings(1280, 720, 1280, 720, 640, 360); | 316 TestTwoTracksWithDifferentSettings(1280, 720, 1280, 720, 640, 360); |
303 } | 317 } |
304 | 318 |
305 TEST_F(MediaStreamVideoSourceTest, SourceChangeFrameSize) { | 319 TEST_F(MediaStreamVideoSourceTest, SourceChangeFrameSize) { |
306 MockConstraintFactory factory; | |
307 factory.AddAdvanced().width.SetMax(800); | |
308 factory.AddAdvanced().height.SetMax(700); | |
309 | |
310 // Expect the source to start capture with the supported resolution. | 320 // Expect the source to start capture with the supported resolution. |
311 // Disable frame-rate adjustment in spec-compliant mode to ensure no frames | 321 // Disable frame-rate adjustment in spec-compliant mode to ensure no frames |
312 // are dropped. | 322 // are dropped. |
313 blink::WebMediaStreamTrack track = CreateTrackAndStartSource(800, 700, 0.0); | 323 blink::WebMediaStreamTrack track = CreateTrackAndStartSource(800, 700, 0.0); |
314 | 324 |
315 MockMediaStreamVideoSink sink; | 325 MockMediaStreamVideoSink sink; |
316 sink.ConnectToTrack(track); | 326 sink.ConnectToTrack(track); |
317 EXPECT_EQ(0, sink.number_of_frames()); | 327 EXPECT_EQ(0, sink.number_of_frames()); |
318 DeliverVideoFrameAndWaitForRenderer(320, 240, &sink); | 328 DeliverVideoFrameAndWaitForRenderer(320, 240, &sink); |
319 EXPECT_EQ(1, sink.number_of_frames()); | 329 EXPECT_EQ(1, sink.number_of_frames()); |
(...skipping 11 matching lines...) Expand all Loading... |
331 | 341 |
332 DeliverVideoFrameAndWaitForRenderer(1280, 720, &sink); | 342 DeliverVideoFrameAndWaitForRenderer(1280, 720, &sink); |
333 EXPECT_EQ(3, sink.number_of_frames()); | 343 EXPECT_EQ(3, sink.number_of_frames()); |
334 // Expect a frame to be cropped since its larger than max requested. | 344 // Expect a frame to be cropped since its larger than max requested. |
335 EXPECT_EQ(800, sink.frame_size().width()); | 345 EXPECT_EQ(800, sink.frame_size().width()); |
336 EXPECT_EQ(700, sink.frame_size().height()); | 346 EXPECT_EQ(700, sink.frame_size().height()); |
337 | 347 |
338 sink.DisconnectFromTrack(); | 348 sink.DisconnectFromTrack(); |
339 } | 349 } |
340 | 350 |
| 351 #if defined(OS_ANDROID) |
| 352 TEST_F(MediaStreamVideoSourceTest, RotatedSource) { |
| 353 // Expect the source to start capture with the supported resolution. |
| 354 // Disable frame-rate adjustment in spec-compliant mode to ensure no frames |
| 355 // are dropped. |
| 356 blink::WebMediaStreamTrack track = |
| 357 CreateTrackAndStartSource(640, 480, 0.0, true); |
| 358 |
| 359 MockMediaStreamVideoSink sink; |
| 360 sink.ConnectToTrack(track); |
| 361 EXPECT_EQ(0, sink.number_of_frames()); |
| 362 DeliverVideoFrameAndWaitForRenderer(640, 480, &sink); |
| 363 EXPECT_EQ(1, sink.number_of_frames()); |
| 364 // Expect the delivered frame to be passed unchanged since its smaller than |
| 365 // max requested. |
| 366 EXPECT_EQ(640, sink.frame_size().width()); |
| 367 EXPECT_EQ(480, sink.frame_size().height()); |
| 368 |
| 369 DeliverRotatedVideoFrameAndWaitForRenderer(640, 480, &sink); |
| 370 EXPECT_EQ(2, sink.number_of_frames()); |
| 371 // Expect the delivered frame to be passed unchanged since its detected as |
| 372 // a valid frame on a rotated device. |
| 373 EXPECT_EQ(480, sink.frame_size().width()); |
| 374 EXPECT_EQ(640, sink.frame_size().height()); |
| 375 |
| 376 sink.DisconnectFromTrack(); |
| 377 } |
| 378 #endif |
| 379 |
341 // Test that a source producing no frames change the source ReadyState to muted. | 380 // Test that a source producing no frames change the source ReadyState to muted. |
342 // that in a reasonable time frame the muted state turns to false. | 381 // that in a reasonable time frame the muted state turns to false. |
343 TEST_F(MediaStreamVideoSourceTest, MutedSource) { | 382 TEST_F(MediaStreamVideoSourceTest, MutedSource) { |
344 // Setup the source for support a frame rate of 999 fps in order to test | 383 // Setup the source for support a frame rate of 999 fps in order to test |
345 // the muted event faster. This is since the frame monitoring uses | 384 // the muted event faster. This is since the frame monitoring uses |
346 // PostDelayedTask that is dependent on the source frame rate. | 385 // PostDelayedTask that is dependent on the source frame rate. |
347 // Note that media::limits::kMaxFramesPerSecond is 1000. | 386 // Note that media::limits::kMaxFramesPerSecond is 1000. |
348 blink::WebMediaStreamTrack track = CreateTrackAndStartSource( | 387 blink::WebMediaStreamTrack track = CreateTrackAndStartSource( |
349 640, 480, media::limits::kMaxFramesPerSecond - 2); | 388 640, 480, media::limits::kMaxFramesPerSecond - 2); |
350 MockMediaStreamVideoSink sink; | 389 MockMediaStreamVideoSink sink; |
(...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1215 InvalidMandatoryAspectRatioFails) { | 1254 InvalidMandatoryAspectRatioFails) { |
1216 MockConstraintFactory factory; | 1255 MockConstraintFactory factory; |
1217 factory.basic().aspect_ratio.SetMax(0.0); | 1256 factory.basic().aspect_ratio.SetMax(0.0); |
1218 blink::WebMediaStreamTrack track = | 1257 blink::WebMediaStreamTrack track = |
1219 CreateTrack("123", factory.CreateWebMediaConstraints()); | 1258 CreateTrack("123", factory.CreateWebMediaConstraints()); |
1220 mock_source()->CompleteGetSupportedFormats(); | 1259 mock_source()->CompleteGetSupportedFormats(); |
1221 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); | 1260 EXPECT_EQ(1, NumberOfFailedConstraintsCallbacks()); |
1222 } | 1261 } |
1223 | 1262 |
1224 } // namespace content | 1263 } // namespace content |
OLD | NEW |