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

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

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

Powered by Google App Engine
This is Rietveld 408576698