Index: content/renderer/media/media_stream_constraints_util_unittest.cc |
diff --git a/content/renderer/media/media_stream_constraints_util_unittest.cc b/content/renderer/media/media_stream_constraints_util_unittest.cc |
index 786f681db4f2465c66b3cbc5e5a8e659bfedc697..857e27e1e374cd12e2f6f585b10a98d654eb9749 100644 |
--- a/content/renderer/media/media_stream_constraints_util_unittest.cc |
+++ b/content/renderer/media/media_stream_constraints_util_unittest.cc |
@@ -6,13 +6,30 @@ |
#include "content/renderer/media/media_stream_audio_processor_options.h" |
#include "content/renderer/media/media_stream_constraints_util.h" |
-#include "content/renderer/media/media_stream_video_source.h" |
+#include "content/renderer/media/media_stream_constraints_util_sets.h" |
#include "content/renderer/media/mock_constraint_factory.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+namespace { |
+ |
+const int kSourceHeight = 1000; |
+const int kSourceWidth = 1500; |
+constexpr double kSourceAspectRatio = |
+ static_cast<double>(kSourceWidth) / static_cast<double>(kSourceHeight); |
+const double kSourceFrameRate = 100.0; |
+ |
+media::VideoCaptureFormat SourceFormat() { |
+ return media::VideoCaptureFormat(gfx::Size(kSourceWidth, kSourceHeight), |
+ kSourceFrameRate, media::PIXEL_FORMAT_I420); |
+} |
+ |
+} // namespace |
+ |
namespace content { |
class MediaStreamConstraintsUtilTest : public testing::Test { |
+ protected: |
+ using DoubleRangeSet = NumericRangeSet<double>; |
}; |
TEST_F(MediaStreamConstraintsUtilTest, BooleanConstraints) { |
@@ -63,7 +80,7 @@ TEST_F(MediaStreamConstraintsUtilTest, BooleanConstraints) { |
TEST_F(MediaStreamConstraintsUtilTest, DoubleConstraints) { |
MockConstraintFactory constraint_factory; |
- const double test_value= 0.01f; |
+ const double test_value = 0.01f; |
constraint_factory.basic().aspectRatio.setExact(test_value); |
blink::WebMediaConstraints constraints = |
@@ -99,4 +116,387 @@ TEST_F(MediaStreamConstraintsUtilTest, IntConstraints) { |
EXPECT_EQ(test_value, value); |
} |
+TEST_F(MediaStreamConstraintsUtilTest, VideoTrackAdapterSettingsUnconstrained) { |
+ ResolutionSet resolution_set; |
+ DoubleRangeSet frame_rate_set; |
+ |
+ // No ideal values. |
+ { |
+ MockConstraintFactory constraint_factory; |
+ auto result = SelectVideoTrackAdapterSettings( |
+ constraint_factory.CreateWebMediaConstraints().basic(), resolution_set, |
+ frame_rate_set, SourceFormat()); |
+ EXPECT_EQ(kSourceHeight, result.max_height); |
+ EXPECT_EQ(kSourceWidth, result.max_width); |
+ EXPECT_EQ(0.0, result.min_aspect_ratio); |
+ EXPECT_EQ(HUGE_VAL, result.max_aspect_ratio); |
+ EXPECT_EQ(0.0, result.max_frame_rate); |
+ } |
+ |
+ // Ideal height. |
+ { |
+ int kIdealHeight = 400; |
hbos_chromium
2017/03/28 12:52:53
If you use this naming convention make it const in
Guido Urdaneta
2017/03/28 18:35:43
Done. That's what I originally intended :)
|
+ MockConstraintFactory constraint_factory; |
+ constraint_factory.basic().height.setIdeal(kIdealHeight); |
+ auto result = SelectVideoTrackAdapterSettings( |
+ constraint_factory.CreateWebMediaConstraints().basic(), resolution_set, |
+ frame_rate_set, SourceFormat()); |
+ EXPECT_EQ(kIdealHeight, result.max_height); |
+ EXPECT_EQ(std::round(kIdealHeight * kSourceAspectRatio), result.max_width); |
+ EXPECT_EQ(0.0, result.min_aspect_ratio); |
+ EXPECT_EQ(HUGE_VAL, result.max_aspect_ratio); |
+ EXPECT_EQ(0.0, result.max_frame_rate); |
+ } |
+ |
+ // Ideal width. |
+ { |
+ int kIdealWidth = 400; |
+ MockConstraintFactory constraint_factory; |
+ constraint_factory.basic().width.setIdeal(kIdealWidth); |
+ auto result = SelectVideoTrackAdapterSettings( |
+ constraint_factory.CreateWebMediaConstraints().basic(), resolution_set, |
+ frame_rate_set, SourceFormat()); |
+ EXPECT_EQ(std::round(kIdealWidth / kSourceAspectRatio), result.max_height); |
+ EXPECT_EQ(kIdealWidth, result.max_width); |
+ EXPECT_EQ(0.0, result.min_aspect_ratio); |
+ EXPECT_EQ(HUGE_VAL, result.max_aspect_ratio); |
+ EXPECT_EQ(0.0, result.max_frame_rate); |
+ } |
+ |
+ // Ideal aspect ratio. |
+ { |
+ double kIdealAspectRatio = 2.0; |
+ MockConstraintFactory constraint_factory; |
+ constraint_factory.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
+ auto result = SelectVideoTrackAdapterSettings( |
+ constraint_factory.CreateWebMediaConstraints().basic(), resolution_set, |
+ frame_rate_set, SourceFormat()); |
+ EXPECT_EQ(kSourceHeight, result.max_height); |
+ EXPECT_EQ(std::round(kSourceHeight * kIdealAspectRatio), result.max_width); |
+ EXPECT_EQ(0.0, result.min_aspect_ratio); |
+ EXPECT_EQ(HUGE_VAL, result.max_aspect_ratio); |
+ EXPECT_EQ(0.0, result.max_frame_rate); |
+ } |
+ |
+ // Ideal frame rate. |
+ { |
+ double kIdealFrameRate = 33; |
+ MockConstraintFactory constraint_factory; |
+ constraint_factory.basic().frameRate.setIdeal(kIdealFrameRate); |
+ auto result = SelectVideoTrackAdapterSettings( |
+ constraint_factory.CreateWebMediaConstraints().basic(), resolution_set, |
+ frame_rate_set, SourceFormat()); |
+ EXPECT_EQ(kSourceHeight, result.max_height); |
+ EXPECT_EQ(kSourceWidth, result.max_width); |
+ EXPECT_EQ(0.0, result.min_aspect_ratio); |
+ EXPECT_EQ(HUGE_VAL, result.max_aspect_ratio); |
+ EXPECT_EQ(kIdealFrameRate, result.max_frame_rate); |
+ } |
+ |
+ // All ideals supplied. |
+ { |
+ int kIdealHeight = 400; |
+ int kIdealWidth = 600; |
+ int kIdealAspectRatio = 2.0; |
+ double kIdealFrameRate = 33; |
+ MockConstraintFactory constraint_factory; |
+ constraint_factory.basic().height.setIdeal(kIdealHeight); |
+ constraint_factory.basic().width.setIdeal(kIdealWidth); |
+ // Ideal aspect ratio is ignored if ideal width and height are supplied. |
+ constraint_factory.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
+ constraint_factory.basic().frameRate.setIdeal(kIdealFrameRate); |
+ auto result = SelectVideoTrackAdapterSettings( |
+ constraint_factory.CreateWebMediaConstraints().basic(), resolution_set, |
+ frame_rate_set, SourceFormat()); |
+ EXPECT_EQ(kIdealHeight, result.max_height); |
+ EXPECT_EQ(kIdealWidth, result.max_width); |
+ EXPECT_EQ(0.0, result.min_aspect_ratio); |
+ EXPECT_EQ(HUGE_VAL, result.max_aspect_ratio); |
+ EXPECT_EQ(kIdealFrameRate, result.max_frame_rate); |
+ } |
+} |
+ |
+TEST_F(MediaStreamConstraintsUtilTest, VideoTrackAdapterSettingsConstrained) { |
+ const int kMinHeight = 500; |
+ const int kMaxHeight = 1200; |
+ const int kMinWidth = 1000; |
+ const int kMaxWidth = 2000; |
+ const double kMinAspectRatio = 1.0; |
+ const double kMaxAspectRatio = 2.0; |
+ const double kMinFrameRate = 20.0; |
+ const double kMaxFrameRate = 44.0; |
+ ResolutionSet resolution_set(kMinHeight, kMaxHeight, kMinWidth, kMaxWidth, |
+ kMinAspectRatio, kMaxAspectRatio); |
+ DoubleRangeSet frame_rate_set(kMinFrameRate, kMaxFrameRate); |
+ |
+ // No ideal values. |
+ { |
+ MockConstraintFactory constraint_factory; |
+ auto result = SelectVideoTrackAdapterSettings( |
+ constraint_factory.CreateWebMediaConstraints().basic(), resolution_set, |
+ frame_rate_set, SourceFormat()); |
+ EXPECT_EQ(kSourceHeight, result.max_height); |
+ EXPECT_EQ(kSourceWidth, result.max_width); |
+ EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio); |
+ EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio); |
+ EXPECT_EQ(kMaxFrameRate, result.max_frame_rate); |
+ } |
+ |
+ // Ideal height < min. |
hbos_chromium
2017/03/28 12:52:53
You could static_assert these type of things.
Guido Urdaneta
2017/03/28 18:35:43
Done.
|
+ { |
+ int kIdealHeight = 400; |
+ MockConstraintFactory constraint_factory; |
+ constraint_factory.basic().height.setIdeal(kIdealHeight); |
+ auto result = SelectVideoTrackAdapterSettings( |
+ constraint_factory.CreateWebMediaConstraints().basic(), resolution_set, |
+ frame_rate_set, SourceFormat()); |
+ EXPECT_EQ(kMinHeight, result.max_height); |
+ // kMinWidth > kMinHeight * kNativeAspectRatio |
+ EXPECT_EQ(kMinWidth, result.max_width); |
+ EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio); |
+ EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio); |
+ EXPECT_EQ(kMaxFrameRate, result.max_frame_rate); |
+ } |
+ |
+ // min < Ideal height < max. |
+ { |
+ int kIdealHeight = 1100; |
+ MockConstraintFactory constraint_factory; |
+ constraint_factory.basic().height.setIdeal(kIdealHeight); |
+ auto result = SelectVideoTrackAdapterSettings( |
+ constraint_factory.CreateWebMediaConstraints().basic(), resolution_set, |
+ frame_rate_set, SourceFormat()); |
+ EXPECT_EQ(kIdealHeight, result.max_height); |
+ EXPECT_EQ(std::round(kIdealHeight * kSourceAspectRatio), result.max_width); |
+ EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio); |
+ EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio); |
+ EXPECT_EQ(kMaxFrameRate, result.max_frame_rate); |
+ } |
+ |
+ // Ideal height > max. |
+ { |
+ int kIdealHeight = 2000; |
+ MockConstraintFactory constraint_factory; |
+ constraint_factory.basic().height.setIdeal(kIdealHeight); |
+ auto result = SelectVideoTrackAdapterSettings( |
+ constraint_factory.CreateWebMediaConstraints().basic(), resolution_set, |
+ frame_rate_set, SourceFormat()); |
+ EXPECT_EQ(kMaxHeight, result.max_height); |
+ EXPECT_EQ(std::round(kMaxHeight * kSourceAspectRatio), result.max_width); |
+ EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio); |
+ EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio); |
+ EXPECT_EQ(kMaxFrameRate, result.max_frame_rate); |
+ } |
+ |
+ // Ideal width < min. |
+ { |
+ int kIdealWidth = 800; |
+ MockConstraintFactory constraint_factory; |
+ constraint_factory.basic().width.setIdeal(kIdealWidth); |
+ auto result = SelectVideoTrackAdapterSettings( |
+ constraint_factory.CreateWebMediaConstraints().basic(), resolution_set, |
+ frame_rate_set, SourceFormat()); |
+ EXPECT_EQ(std::round(kMinWidth / kSourceAspectRatio), result.max_height); |
+ EXPECT_EQ(kMinWidth, result.max_width); |
+ EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio); |
+ EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio); |
+ EXPECT_EQ(kMaxFrameRate, result.max_frame_rate); |
+ } |
+ |
+ // min < Ideal width < max. |
+ { |
+ int kIdealWidth = 1800; |
+ MockConstraintFactory constraint_factory; |
+ constraint_factory.basic().width.setIdeal(kIdealWidth); |
+ auto result = SelectVideoTrackAdapterSettings( |
+ constraint_factory.CreateWebMediaConstraints().basic(), resolution_set, |
+ frame_rate_set, SourceFormat()); |
+ EXPECT_EQ(std::round(kIdealWidth / kSourceAspectRatio), result.max_height); |
+ EXPECT_EQ(kIdealWidth, result.max_width); |
+ EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio); |
+ EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio); |
+ EXPECT_EQ(kMaxFrameRate, result.max_frame_rate); |
+ } |
+ |
+ // Ideal width > max. |
+ { |
+ int kIdealWidth = 3000; |
+ MockConstraintFactory constraint_factory; |
+ constraint_factory.basic().width.setIdeal(kIdealWidth); |
+ auto result = SelectVideoTrackAdapterSettings( |
+ constraint_factory.CreateWebMediaConstraints().basic(), resolution_set, |
+ frame_rate_set, SourceFormat()); |
+ // kMaxHeight < kMaxWidth / kNativeAspectRatio |
+ EXPECT_EQ(kMaxHeight, result.max_height); |
+ EXPECT_EQ(kMaxWidth, result.max_width); |
+ EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio); |
+ EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio); |
+ EXPECT_EQ(kMaxFrameRate, result.max_frame_rate); |
+ } |
+ |
+ // Ideal aspect ratio < min. |
+ { |
+ double kIdealAspectRatio = 0.5; |
+ MockConstraintFactory constraint_factory; |
+ constraint_factory.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
+ auto result = SelectVideoTrackAdapterSettings( |
+ constraint_factory.CreateWebMediaConstraints().basic(), resolution_set, |
+ frame_rate_set, SourceFormat()); |
+ // Desired point is (kNativeWidth/kMinAspectRatio, kNativeWidth), but it |
+ // is outside the size constraints. Closest to that while maintaining the |
+ // same aspect ratio is (kMaxHeight, kMaxHeight * kMinAspectRatio). |
+ EXPECT_EQ(kMaxHeight, result.max_height); |
+ EXPECT_EQ(std::round(kMaxHeight * kMinAspectRatio), result.max_width); |
+ EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio); |
+ EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio); |
+ EXPECT_EQ(kMaxFrameRate, result.max_frame_rate); |
+ } |
+ |
+ // min < Ideal aspect ratio < max. |
+ { |
+ double kIdealAspectRatio = 1.25; |
+ MockConstraintFactory constraint_factory; |
+ constraint_factory.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
+ auto result = SelectVideoTrackAdapterSettings( |
+ constraint_factory.CreateWebMediaConstraints().basic(), resolution_set, |
+ frame_rate_set, SourceFormat()); |
+ EXPECT_EQ(std::round(kSourceWidth / kIdealAspectRatio), result.max_height); |
+ EXPECT_EQ(kSourceWidth, result.max_width); |
+ EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio); |
+ EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio); |
+ EXPECT_EQ(kMaxFrameRate, result.max_frame_rate); |
+ } |
+ |
+ // Ideal aspect ratio > max. |
+ { |
+ double kIdealAspectRatio = 3.0; |
+ MockConstraintFactory constraint_factory; |
+ constraint_factory.basic().aspectRatio.setIdeal(kIdealAspectRatio); |
+ auto result = SelectVideoTrackAdapterSettings( |
+ constraint_factory.CreateWebMediaConstraints().basic(), resolution_set, |
+ frame_rate_set, SourceFormat()); |
+ EXPECT_EQ(kSourceHeight, result.max_height); |
+ EXPECT_EQ(std::round(kSourceHeight * kMaxAspectRatio), result.max_width); |
+ EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio); |
+ EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio); |
+ EXPECT_EQ(kMaxFrameRate, result.max_frame_rate); |
+ } |
+ |
+ // Ideal frame rate < min. |
+ { |
+ double kIdealFrameRate = 3.0; |
+ MockConstraintFactory constraint_factory; |
+ constraint_factory.basic().frameRate.setIdeal(kIdealFrameRate); |
+ auto result = SelectVideoTrackAdapterSettings( |
+ constraint_factory.CreateWebMediaConstraints().basic(), resolution_set, |
+ frame_rate_set, SourceFormat()); |
+ EXPECT_EQ(kSourceHeight, result.max_height); |
+ EXPECT_EQ(kSourceWidth, result.max_width); |
+ EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio); |
+ EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio); |
+ EXPECT_EQ(kMinFrameRate, result.max_frame_rate); |
+ } |
+ |
+ // min < Ideal frame rate < max. |
+ { |
+ double kIdealFrameRate = 31.0; |
+ MockConstraintFactory constraint_factory; |
+ constraint_factory.basic().frameRate.setIdeal(kIdealFrameRate); |
+ auto result = SelectVideoTrackAdapterSettings( |
+ constraint_factory.CreateWebMediaConstraints().basic(), resolution_set, |
+ frame_rate_set, SourceFormat()); |
+ EXPECT_EQ(kSourceHeight, result.max_height); |
+ EXPECT_EQ(kSourceWidth, result.max_width); |
+ EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio); |
+ EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio); |
+ EXPECT_EQ(kIdealFrameRate, result.max_frame_rate); |
+ } |
+ |
+ // Ideal frame rate > max. |
+ { |
+ double kIdealFrameRate = 1000.0; |
+ MockConstraintFactory constraint_factory; |
+ constraint_factory.basic().frameRate.setIdeal(kIdealFrameRate); |
+ auto result = SelectVideoTrackAdapterSettings( |
+ constraint_factory.CreateWebMediaConstraints().basic(), resolution_set, |
+ frame_rate_set, SourceFormat()); |
+ EXPECT_EQ(kSourceHeight, result.max_height); |
+ EXPECT_EQ(kSourceWidth, result.max_width); |
+ EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio); |
+ EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio); |
+ EXPECT_EQ(kMaxFrameRate, result.max_frame_rate); |
+ } |
+ |
+ // Ideal values inside constraints. |
+ { |
+ int kIdealHeight = 900; |
+ int kIdealWidth = 1600; |
+ double kIdealFrameRate = 35.0; |
+ MockConstraintFactory constraint_factory; |
+ constraint_factory.basic().height.setIdeal(kIdealHeight); |
+ constraint_factory.basic().width.setIdeal(kIdealWidth); |
+ constraint_factory.basic().frameRate.setIdeal(kIdealFrameRate); |
+ auto result = SelectVideoTrackAdapterSettings( |
+ constraint_factory.CreateWebMediaConstraints().basic(), resolution_set, |
+ frame_rate_set, SourceFormat()); |
+ EXPECT_EQ(kIdealHeight, result.max_height); |
+ EXPECT_EQ(kIdealWidth, result.max_width); |
+ EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio); |
+ EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio); |
+ EXPECT_EQ(kIdealFrameRate, result.max_frame_rate); |
+ } |
+ |
+ // Ideal values outside constraints. |
+ { |
+ int kIdealHeight = 2900; |
+ int kIdealWidth = 3600; |
+ double kIdealFrameRate = 350.0; |
+ MockConstraintFactory constraint_factory; |
+ constraint_factory.basic().height.setIdeal(kIdealHeight); |
+ constraint_factory.basic().width.setIdeal(kIdealWidth); |
+ constraint_factory.basic().frameRate.setIdeal(kIdealFrameRate); |
+ auto result = SelectVideoTrackAdapterSettings( |
+ constraint_factory.CreateWebMediaConstraints().basic(), resolution_set, |
+ frame_rate_set, SourceFormat()); |
+ EXPECT_EQ(kMaxHeight, result.max_height); |
+ EXPECT_EQ(kMaxWidth, result.max_width); |
+ EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio); |
+ EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio); |
+ EXPECT_EQ(kMaxFrameRate, result.max_frame_rate); |
+ } |
+ |
+ // Source frame rate. |
+ { |
+ DoubleRangeSet frame_rate_set(kMinFrameRate, kSourceFrameRate); |
+ MockConstraintFactory constraint_factory; |
+ auto result = SelectVideoTrackAdapterSettings( |
+ constraint_factory.CreateWebMediaConstraints().basic(), resolution_set, |
+ frame_rate_set, SourceFormat()); |
+ EXPECT_EQ(kSourceHeight, result.max_height); |
+ EXPECT_EQ(kSourceWidth, result.max_width); |
+ EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio); |
+ EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio); |
+ // No frame-rate adjustment because the track will use the same frame rate |
+ // as the source. |
hbos_chromium
2017/03/28 12:52:53
In the larger context of sources and settings: ...
Guido Urdaneta
2017/03/28 18:35:43
0.0 is a special value that VideoTrackAdapter inte
hbos_chromium
2017/03/29 14:54:53
Acknowledged.
|
+ EXPECT_EQ(0.0, result.max_frame_rate); |
+ } |
+ |
+ // High frame rate. |
+ { |
+ const double kHighFrameRate = 400.0; // Greater than source. |
+ DoubleRangeSet frame_rate_set(kMinFrameRate, kHighFrameRate); |
+ MockConstraintFactory constraint_factory; |
+ auto result = SelectVideoTrackAdapterSettings( |
+ constraint_factory.CreateWebMediaConstraints().basic(), resolution_set, |
+ frame_rate_set, SourceFormat()); |
+ EXPECT_EQ(kSourceHeight, result.max_height); |
+ EXPECT_EQ(kSourceWidth, result.max_width); |
+ EXPECT_EQ(kMinAspectRatio, result.min_aspect_ratio); |
+ EXPECT_EQ(kMaxAspectRatio, result.max_aspect_ratio); |
+ // No frame-rate adjustment because the track will use a frame rate that is |
+ // greater than the source's. |
+ EXPECT_EQ(0.0, result.max_frame_rate); |
+ } |
+} |
+ |
} // namespace content |