Add comparison methods for VideoSourceRestrictions
Bug: None Change-Id: Ia67f39e9b17e37294462823dd6f6ca365c7fd46b Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/174700 Commit-Queue: Evan Shrubsole <eshr@google.com> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/master@{#31182}
This commit is contained in:
parent
0dcb470cfe
commit
3b6afeeed0
@ -65,6 +65,32 @@ void VideoSourceRestrictions::set_max_frame_rate(
|
||||
max_frame_rate_ = std::move(max_frame_rate);
|
||||
}
|
||||
|
||||
bool DidRestrictionsIncrease(VideoSourceRestrictions before,
|
||||
VideoSourceRestrictions after) {
|
||||
bool decreased_resolution = DidDecreaseResolution(before, after);
|
||||
bool decreased_framerate = DidDecreaseFrameRate(before, after);
|
||||
bool same_resolution =
|
||||
before.max_pixels_per_frame() == after.max_pixels_per_frame();
|
||||
bool same_framerate = before.max_frame_rate() == after.max_frame_rate();
|
||||
|
||||
return (decreased_resolution && decreased_framerate) ||
|
||||
(decreased_resolution && same_framerate) ||
|
||||
(same_resolution && decreased_framerate);
|
||||
}
|
||||
|
||||
bool DidRestrictionsDecrease(VideoSourceRestrictions before,
|
||||
VideoSourceRestrictions after) {
|
||||
bool increased_resolution = DidIncreaseResolution(before, after);
|
||||
bool increased_framerate = DidIncreaseFrameRate(before, after);
|
||||
bool same_resolution =
|
||||
before.max_pixels_per_frame() == after.max_pixels_per_frame();
|
||||
bool same_framerate = before.max_frame_rate() == after.max_frame_rate();
|
||||
|
||||
return (increased_resolution && increased_framerate) ||
|
||||
(increased_resolution && same_framerate) ||
|
||||
(same_resolution && increased_framerate);
|
||||
}
|
||||
|
||||
bool DidIncreaseResolution(VideoSourceRestrictions restrictions_before,
|
||||
VideoSourceRestrictions restrictions_after) {
|
||||
if (!restrictions_before.max_pixels_per_frame().has_value())
|
||||
@ -75,6 +101,26 @@ bool DidIncreaseResolution(VideoSourceRestrictions restrictions_before,
|
||||
restrictions_before.max_pixels_per_frame().value();
|
||||
}
|
||||
|
||||
bool DidDecreaseResolution(VideoSourceRestrictions restrictions_before,
|
||||
VideoSourceRestrictions restrictions_after) {
|
||||
if (!restrictions_after.max_pixels_per_frame().has_value())
|
||||
return false;
|
||||
if (!restrictions_before.max_pixels_per_frame().has_value())
|
||||
return true;
|
||||
return restrictions_after.max_pixels_per_frame().value() <
|
||||
restrictions_before.max_pixels_per_frame().value();
|
||||
}
|
||||
|
||||
bool DidIncreaseFrameRate(VideoSourceRestrictions restrictions_before,
|
||||
VideoSourceRestrictions restrictions_after) {
|
||||
if (!restrictions_before.max_frame_rate().has_value())
|
||||
return false;
|
||||
if (!restrictions_after.max_frame_rate().has_value())
|
||||
return true;
|
||||
return restrictions_after.max_frame_rate().value() >
|
||||
restrictions_before.max_frame_rate().value();
|
||||
}
|
||||
|
||||
bool DidDecreaseFrameRate(VideoSourceRestrictions restrictions_before,
|
||||
VideoSourceRestrictions restrictions_after) {
|
||||
if (!restrictions_after.max_frame_rate().has_value())
|
||||
|
||||
@ -65,9 +65,16 @@ class VideoSourceRestrictions {
|
||||
absl::optional<double> max_frame_rate_;
|
||||
};
|
||||
|
||||
bool DidRestrictionsIncrease(VideoSourceRestrictions before,
|
||||
VideoSourceRestrictions after);
|
||||
bool DidRestrictionsDecrease(VideoSourceRestrictions before,
|
||||
VideoSourceRestrictions after);
|
||||
bool DidIncreaseResolution(VideoSourceRestrictions restrictions_before,
|
||||
VideoSourceRestrictions restrictions_after);
|
||||
|
||||
bool DidDecreaseResolution(VideoSourceRestrictions restrictions_before,
|
||||
VideoSourceRestrictions restrictions_after);
|
||||
bool DidIncreaseFrameRate(VideoSourceRestrictions restrictions_before,
|
||||
VideoSourceRestrictions restrictions_after);
|
||||
bool DidDecreaseFrameRate(VideoSourceRestrictions restrictions_before,
|
||||
VideoSourceRestrictions restrictions_after);
|
||||
|
||||
|
||||
@ -16,6 +16,14 @@ namespace webrtc {
|
||||
|
||||
namespace {
|
||||
|
||||
const size_t kHdPixels = 1280 * 720;
|
||||
|
||||
const VideoSourceRestrictions kUnlimited;
|
||||
const VideoSourceRestrictions k15fps(absl::nullopt, absl::nullopt, 15.0);
|
||||
const VideoSourceRestrictions kHd(kHdPixels, kHdPixels, absl::nullopt);
|
||||
const VideoSourceRestrictions kHd15fps(kHdPixels, kHdPixels, 15.0);
|
||||
const VideoSourceRestrictions kVga7fps(kHdPixels / 2, kHdPixels / 2, 7.0);
|
||||
|
||||
VideoSourceRestrictions RestrictionsFromMaxPixelsPerFrame(
|
||||
size_t max_pixels_per_frame) {
|
||||
return VideoSourceRestrictions(max_pixels_per_frame, absl::nullopt,
|
||||
@ -70,4 +78,52 @@ TEST(VideoSourceRestrictionsTest, DidDecreaseFrameRate) {
|
||||
RestrictionsFromMaxFrameRate(9)));
|
||||
}
|
||||
|
||||
TEST(VideoSourceRestrictionsTest, DidRestrictionsChangeFalseForSame) {
|
||||
EXPECT_FALSE(DidRestrictionsDecrease(kUnlimited, kUnlimited));
|
||||
EXPECT_FALSE(DidRestrictionsIncrease(kUnlimited, kUnlimited));
|
||||
|
||||
// Both resolution and fps restricted.
|
||||
EXPECT_FALSE(DidRestrictionsDecrease(kHd15fps, kHd15fps));
|
||||
EXPECT_FALSE(DidRestrictionsIncrease(kHd15fps, kHd15fps));
|
||||
}
|
||||
|
||||
TEST(VideoSourceRestrictions,
|
||||
DidRestrictionsIncreaseTrueWhenPixelsOrFrameRateDecreased) {
|
||||
// Unlimited > Limited resolution.
|
||||
EXPECT_TRUE(DidRestrictionsIncrease(kUnlimited, kHd));
|
||||
// Unlimited > limited fps.
|
||||
EXPECT_TRUE(DidRestrictionsIncrease(kUnlimited, k15fps));
|
||||
// Unlimited > limited resolution + limited fps.
|
||||
EXPECT_TRUE(DidRestrictionsIncrease(kUnlimited, kHd15fps));
|
||||
// Limited resolution > limited resolution + limited fps.
|
||||
EXPECT_TRUE(DidRestrictionsIncrease(kHd, kHd15fps));
|
||||
// Limited fps > limited resolution + limited fps.
|
||||
EXPECT_TRUE(DidRestrictionsIncrease(k15fps, kHd15fps));
|
||||
// Limited resolution + fps > More limited resolution + more limited fps
|
||||
EXPECT_TRUE(DidRestrictionsIncrease(kHd15fps, kVga7fps));
|
||||
}
|
||||
|
||||
TEST(VideoSourceRestrictions,
|
||||
DidRestrictionsDecreaseTrueWhenPixelsOrFrameRateIncreased) {
|
||||
// Limited resolution < Unlimited.
|
||||
EXPECT_TRUE(DidRestrictionsDecrease(kHd, kUnlimited));
|
||||
// Limited fps < Unlimited.
|
||||
EXPECT_TRUE(DidRestrictionsDecrease(k15fps, kUnlimited));
|
||||
// Limited resolution + limited fps < unlimited.
|
||||
EXPECT_TRUE(DidRestrictionsDecrease(kHd15fps, kUnlimited));
|
||||
// Limited resolution + limited fps < limited resolution.
|
||||
EXPECT_TRUE(DidRestrictionsDecrease(kHd15fps, kHd));
|
||||
// Limited resolution + limited fps < limited fps.
|
||||
EXPECT_TRUE(DidRestrictionsDecrease(kHd15fps, k15fps));
|
||||
// More limited resolution + more limited fps < limited resolution + fps
|
||||
EXPECT_TRUE(DidRestrictionsDecrease(kVga7fps, kHd15fps));
|
||||
}
|
||||
|
||||
TEST(VideoSourceRestrictions,
|
||||
DidRestrictionsChangeFalseWhenFrameRateAndPixelsChangeDifferently) {
|
||||
// One changed framerate, the other resolution; not an increase or decrease.
|
||||
EXPECT_FALSE(DidRestrictionsIncrease(kHd, k15fps));
|
||||
EXPECT_FALSE(DidRestrictionsDecrease(kHd, k15fps));
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user