webrtc_m130/video/config/encoder_stream_factory_unittest.cc
Jonas Oreland 43f0f29d30 RtpEncodingParameters::request_resolution patch 4
This patch

1) modifies VideoAdapter to use requested_resolution
instead on OnOutputFormatRequest, iff there are no active encoders
that is not using requested_resolution (i.e all "old" encoder(s) are
not active).

2) modifies VideoBroadcaster to not broadcast wants from
encoders that are not active (iff there is an active encoder
using requested_resolution).

3) fixes a bug in encoder_stream_factor in that the
requested_resolution was not propagated to return value
(must have been lost in merge?).

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

84 lines
2.9 KiB
C++

/*
* Copyright (c) 2022 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 "video/config/encoder_stream_factory.h"
#include "call/adaptation/video_source_restrictions.h"
#include "test/gtest.h"
namespace webrtc {
using cricket::EncoderStreamFactory;
constexpr int kMaxQp = 48;
namespace {
std::vector<Resolution> GetStreamResolutions(
const std::vector<VideoStream>& streams) {
std::vector<Resolution> res;
for (const auto& s : streams) {
if (s.active) {
res.push_back(
{rtc::checked_cast<int>(s.width), rtc::checked_cast<int>(s.height)});
}
}
return res;
}
VideoStream LayerWithRequestedResolution(Resolution res) {
VideoStream s;
s.requested_resolution = res;
return s;
}
} // namespace
TEST(EncoderStreamFactory, SinglecastRequestedResolution) {
VideoEncoder::EncoderInfo encoder_info;
auto factory = rtc::make_ref_counted<EncoderStreamFactory>(
"VP8", kMaxQp,
/* is_screenshare= */ false,
/* conference_mode= */ false, encoder_info);
VideoEncoderConfig encoder_config;
encoder_config.number_of_streams = 1;
encoder_config.simulcast_layers.push_back(
LayerWithRequestedResolution({.width = 640, .height = 360}));
auto streams = factory->CreateEncoderStreams(1280, 720, encoder_config);
EXPECT_EQ(streams[0].requested_resolution,
(Resolution{.width = 640, .height = 360}));
EXPECT_EQ(GetStreamResolutions(streams), (std::vector<Resolution>{
{.width = 640, .height = 360},
}));
}
TEST(EncoderStreamFactory, SinglecastRequestedResolutionWithAdaptation) {
VideoSourceRestrictions restrictions(
/* max_pixels_per_frame= */ (320 * 320),
/* target_pixels_per_frame= */ absl::nullopt,
/* max_frame_rate= */ absl::nullopt);
VideoEncoder::EncoderInfo encoder_info;
auto factory = rtc::make_ref_counted<EncoderStreamFactory>(
"VP8", kMaxQp,
/* is_screenshare= */ false,
/* conference_mode= */ false, encoder_info, restrictions);
VideoEncoderConfig encoder_config;
encoder_config.number_of_streams = 1;
encoder_config.simulcast_layers.push_back(
LayerWithRequestedResolution({.width = 640, .height = 360}));
auto streams = factory->CreateEncoderStreams(1280, 720, encoder_config);
EXPECT_EQ(streams[0].requested_resolution,
(Resolution{.width = 640, .height = 360}));
EXPECT_EQ(GetStreamResolutions(streams), (std::vector<Resolution>{
{.width = 320, .height = 180},
}));
}
} // namespace webrtc