webrtc/call/adaptation/video_source_restrictions_unittest.cc
Jonas Oreland 37132e10fd RtpEncodingParameters::request_resolution patch 3
This cl/ adds resource adapation to the requested_resolution
feature. The restrictions that are sent to the video source
are also saved inside video_stream_encoder and used when
determining layer resolution.

Anticipated further patches
4) Let VideoSource do adaption if possible

Bug: webrtc:14451
Change-Id: Ia9b990a6b92b76af7ff6665a562f84585f79c35b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/277580
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Jonas Oreland <jonaso@webrtc.org>
Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38306}
2022-10-06 10:29:31 +00:00

146 lines
6.2 KiB
C++

/*
* Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "call/adaptation/video_source_restrictions.h"
#include "test/gtest.h"
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,
absl::nullopt);
}
VideoSourceRestrictions RestrictionsFromMaxFrameRate(double max_frame_rate) {
return VideoSourceRestrictions(absl::nullopt, absl::nullopt, max_frame_rate);
}
} // namespace
TEST(VideoSourceRestrictionsTest, DidIncreaseResolution) {
// smaller restrictions -> larger restrictions
EXPECT_TRUE(DidIncreaseResolution(RestrictionsFromMaxPixelsPerFrame(10),
RestrictionsFromMaxPixelsPerFrame(11)));
// unrestricted -> restricted
EXPECT_FALSE(DidIncreaseResolution(VideoSourceRestrictions(),
RestrictionsFromMaxPixelsPerFrame(10)));
// restricted -> unrestricted
EXPECT_TRUE(DidIncreaseResolution(RestrictionsFromMaxPixelsPerFrame(10),
VideoSourceRestrictions()));
// restricted -> equally restricted
EXPECT_FALSE(DidIncreaseResolution(RestrictionsFromMaxPixelsPerFrame(10),
RestrictionsFromMaxPixelsPerFrame(10)));
// unrestricted -> unrestricted
EXPECT_FALSE(DidIncreaseResolution(VideoSourceRestrictions(),
VideoSourceRestrictions()));
// larger restrictions -> smaller restrictions
EXPECT_FALSE(DidIncreaseResolution(RestrictionsFromMaxPixelsPerFrame(10),
RestrictionsFromMaxPixelsPerFrame(9)));
}
TEST(VideoSourceRestrictionsTest, DidDecreaseFrameRate) {
// samller restrictions -> larger restrictions
EXPECT_FALSE(DidDecreaseFrameRate(RestrictionsFromMaxFrameRate(10),
RestrictionsFromMaxFrameRate(11)));
// unrestricted -> restricted
EXPECT_TRUE(DidDecreaseFrameRate(VideoSourceRestrictions(),
RestrictionsFromMaxFrameRate(10)));
// restricted -> unrestricted
EXPECT_FALSE(DidDecreaseFrameRate(RestrictionsFromMaxFrameRate(10),
VideoSourceRestrictions()));
// restricted -> equally restricted
EXPECT_FALSE(DidDecreaseFrameRate(RestrictionsFromMaxFrameRate(10),
RestrictionsFromMaxFrameRate(10)));
// unrestricted -> unrestricted
EXPECT_FALSE(DidDecreaseFrameRate(VideoSourceRestrictions(),
VideoSourceRestrictions()));
// larger restrictions -> samller restrictions
EXPECT_TRUE(DidDecreaseFrameRate(RestrictionsFromMaxFrameRate(10),
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));
}
TEST(VideoSourceRestrictions, UpdateMin) {
VideoSourceRestrictions one(kHdPixels / 2, kHdPixels, 7.0);
VideoSourceRestrictions two(kHdPixels, kHdPixels / 3, 15.0);
one.UpdateMin(two);
EXPECT_EQ(one.max_pixels_per_frame(), kHdPixels / 2);
EXPECT_EQ(one.target_pixels_per_frame(), kHdPixels / 3);
EXPECT_EQ(one.max_frame_rate(), 7.0);
two.UpdateMin(one);
EXPECT_EQ(two.max_pixels_per_frame(), kHdPixels / 2);
EXPECT_EQ(two.target_pixels_per_frame(), kHdPixels / 3);
EXPECT_EQ(two.max_frame_rate(), 7.0);
}
} // namespace webrtc