Make requested_resolution throw on invalid dimensions.
As mandated by the scaleResolutionDownTo spec.
Bug: chromium:363544347
Change-Id: Ic78cad708a271bbd6a1980c08430dbb8ae07663a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/362980
Auto-Submit: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43058}
diff --git a/media/base/media_engine.cc b/media/base/media_engine.cc
index dff4de0..c4b4f81 100644
--- a/media/base/media_engine.cc
+++ b/media/base/media_engine.cc
@@ -186,6 +186,11 @@
if (rtp_parameters.encodings[i].requested_resolution.has_value()) {
has_requested_resolution = true;
+ if (rtp_parameters.encodings[i].requested_resolution->width <= 0 ||
+ rtp_parameters.encodings[i].requested_resolution->height <= 0) {
+ LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_MODIFICATION,
+ "The resolution dimensions must be positive.");
+ }
}
if (!field_trials.IsEnabled("WebRTC-MixedCodecSimulcast")) {
diff --git a/pc/peer_connection_encodings_integrationtest.cc b/pc/peer_connection_encodings_integrationtest.cc
index ed08789..208f33f 100644
--- a/pc/peer_connection_encodings_integrationtest.cc
+++ b/pc/peer_connection_encodings_integrationtest.cc
@@ -2134,6 +2134,15 @@
EXPECT_EQ(transceiver_or_error.error().type(),
RTCErrorType::UNSUPPORTED_OPERATION);
+ // AddTransceiver: Width and height must not be zero.
+ init.send_encodings[0].requested_resolution = {.width = 1280, .height = 0};
+ init.send_encodings[1].requested_resolution = {.width = 0, .height = 720};
+ transceiver_or_error =
+ pc_wrapper->pc()->AddTransceiver(cricket::MEDIA_TYPE_VIDEO, init);
+ EXPECT_FALSE(transceiver_or_error.ok());
+ EXPECT_EQ(transceiver_or_error.error().type(),
+ RTCErrorType::UNSUPPORTED_OPERATION);
+
// AddTransceiver: Specifying both `requested_resolution` and
// `scale_resolution_down_by` is allowed (the latter is ignored).
init.send_encodings[0].requested_resolution = {.width = 640, .height = 480};
@@ -2154,6 +2163,15 @@
EXPECT_FALSE(error.ok());
EXPECT_EQ(error.type(), RTCErrorType::INVALID_MODIFICATION);
+ // SetParameters: Width and height must not be zero.
+ sender = transceiver_or_error.value()->sender();
+ parameters = sender->GetParameters();
+ parameters.encodings[0].requested_resolution = {.width = 1280, .height = 0};
+ parameters.encodings[1].requested_resolution = {.width = 0, .height = 720};
+ error = sender->SetParameters(parameters);
+ EXPECT_FALSE(error.ok());
+ EXPECT_EQ(error.type(), RTCErrorType::INVALID_MODIFICATION);
+
// SetParameters: Specifying both `requested_resolution` and
// `scale_resolution_down_by` is allowed (the latter is ignored).
parameters = sender->GetParameters();