Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Unified Diff: webrtc/media/engine/webrtcvideoengine2.cc

Issue 1813763005: Updated structures and functions for setting the max bitrate limit to take rtc::Optional<int> Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Code review feedback Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/media/engine/webrtcvideoengine2.h ('k') | webrtc/media/engine/webrtcvideoengine2_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/media/engine/webrtcvideoengine2.cc
diff --git a/webrtc/media/engine/webrtcvideoengine2.cc b/webrtc/media/engine/webrtcvideoengine2.cc
index cd05f8e6ff5bbe48c820639f10477c8e88dc3306..2917ec3cf2eb8ca897a12e885112dc50395d95f9 100644
--- a/webrtc/media/engine/webrtcvideoengine2.cc
+++ b/webrtc/media/engine/webrtcvideoengine2.cc
@@ -78,9 +78,9 @@ webrtc::Call::Config::BitrateConfig GetBitrateConfigForCodec(
}
if (codec.GetParam(kCodecParamMaxBitrate, &bitrate_kbps) &&
bitrate_kbps > 0) {
- config.max_bitrate_bps = bitrate_kbps * 1000;
+ config.max_bitrate_bps = rtc::Optional<int>(bitrate_kbps * 1000);
} else {
- config.max_bitrate_bps = -1;
+ config.max_bitrate_bps = rtc::Optional<int>();
}
return config;
}
@@ -400,11 +400,13 @@ std::vector<webrtc::VideoStream>
WebRtcVideoChannel2::WebRtcVideoSendStream::CreateSimulcastVideoStreams(
const VideoCodec& codec,
const VideoOptions& options,
- int max_bitrate_bps,
+ rtc::Optional<int> max_bitrate_bps,
size_t num_streams) {
int max_qp = kDefaultQpMax;
codec.GetParam(kCodecParamMaxQuantization, &max_qp);
+ // TODO(skvlad): Consider replacing special case constants with
+ // rtc::Optional<int>
return GetSimulcastConfig(
num_streams, codec.width, codec.height, max_bitrate_bps, max_qp,
codec.framerate != 0 ? codec.framerate : kDefaultVideoMaxFramerate);
@@ -414,11 +416,11 @@ std::vector<webrtc::VideoStream>
WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoStreams(
const VideoCodec& codec,
const VideoOptions& options,
- int max_bitrate_bps,
+ rtc::Optional<int> max_bitrate_bps,
size_t num_streams) {
int codec_max_bitrate_kbps;
if (codec.GetParam(kCodecParamMaxBitrate, &codec_max_bitrate_kbps)) {
- max_bitrate_bps = codec_max_bitrate_kbps * 1000;
+ max_bitrate_bps = rtc::Optional<int>(codec_max_bitrate_kbps * 1000);
}
if (num_streams != 1) {
return CreateSimulcastVideoStreams(codec, options, max_bitrate_bps,
@@ -426,9 +428,9 @@ WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoStreams(
}
// For unset max bitrates set default bitrate for non-simulcast.
- if (max_bitrate_bps <= 0) {
- max_bitrate_bps =
- GetMaxDefaultVideoBitrateKbps(codec.width, codec.height) * 1000;
+ if (!max_bitrate_bps) {
+ max_bitrate_bps = rtc::Optional<int>(
+ GetMaxDefaultVideoBitrateKbps(codec.width, codec.height) * 1000);
}
webrtc::VideoStream stream;
@@ -438,7 +440,7 @@ WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoStreams(
codec.framerate != 0 ? codec.framerate : kDefaultVideoMaxFramerate;
stream.min_bitrate_bps = kMinVideoBitrate * 1000;
- stream.target_bitrate_bps = stream.max_bitrate_bps = max_bitrate_bps;
+ stream.target_bitrate_bps = stream.max_bitrate_bps = *max_bitrate_bps;
int max_qp = kDefaultQpMax;
codec.GetParam(kCodecParamMaxQuantization, &max_qp);
@@ -771,11 +773,9 @@ bool WebRtcVideoChannel2::GetChangedSendParameters(
}
// Handle max bitrate.
- if (params.max_bandwidth_bps != bitrate_config_.max_bitrate_bps &&
- params.max_bandwidth_bps >= 0) {
- // 0 uncaps max bitrate (-1).
- changed_params->max_bandwidth_bps = rtc::Optional<int>(
- params.max_bandwidth_bps == 0 ? -1 : params.max_bandwidth_bps);
+ if (params.max_bitrate_bps != bitrate_config_.max_bitrate_bps) {
+ changed_params->max_bandwidth_bps =
+ rtc::Optional<rtc::Optional<int>>(params.max_bitrate_bps);
}
// Handle conference mode.
@@ -828,12 +828,11 @@ bool WebRtcVideoChannel2::SetSendParameters(const VideoSendParameters& params) {
// WebRtcVideoChannel2 (in which case we're good), or per sender (SSRC), in
// which case this should not set a Call::BitrateConfig but rather
// reconfigure all senders.
- int max_bitrate_bps = *changed_params.max_bandwidth_bps;
bitrate_config_.start_bitrate_bps = -1;
- bitrate_config_.max_bitrate_bps = max_bitrate_bps;
- if (max_bitrate_bps > 0 &&
- bitrate_config_.min_bitrate_bps > max_bitrate_bps) {
- bitrate_config_.min_bitrate_bps = max_bitrate_bps;
+ bitrate_config_.max_bitrate_bps = *changed_params.max_bandwidth_bps;
+ if (bitrate_config_.max_bitrate_bps &&
+ (bitrate_config_.min_bitrate_bps > *bitrate_config_.max_bitrate_bps)) {
+ bitrate_config_.min_bitrate_bps = *bitrate_config_.max_bitrate_bps;
}
bitrate_config_changed = true;
}
@@ -1479,7 +1478,7 @@ WebRtcVideoChannel2::WebRtcVideoSendStream::VideoSendStreamParameters::
VideoSendStreamParameters(
const webrtc::VideoSendStream::Config& config,
const VideoOptions& options,
- int max_bitrate_bps,
+ rtc::Optional<int> max_bitrate_bps,
const rtc::Optional<VideoCodecSettings>& codec_settings)
: config(config),
options(options),
@@ -1508,7 +1507,7 @@ WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream(
const VideoOptions& options,
WebRtcVideoEncoderFactory* external_encoder_factory,
bool enable_cpu_overuse_detection,
- int max_bitrate_bps,
+ rtc::Optional<int> max_bitrate_bps,
const rtc::Optional<VideoCodecSettings>& codec_settings,
const std::vector<webrtc::RtpExtension>& rtp_extensions,
// TODO(deadbeef): Don't duplicate information between send_params,
@@ -1875,6 +1874,11 @@ bool WebRtcVideoChannel2::WebRtcVideoSendStream::ValidateRtpParameters(
<< "Attempted to set RtpParameters without exactly one encoding";
return false;
}
+ if (rtp_parameters.encodings[0].max_bitrate_bps &&
+ (*rtp_parameters.encodings[0].max_bitrate_bps <= 0)) {
+ LOG(LS_ERROR) << "Attempted to set a negative bitrate limit";
+ return false;
+ }
return true;
}
@@ -1930,8 +1934,8 @@ WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig(
stream_count = 1;
}
- int stream_max_bitrate =
- MinPositive(rtp_parameters_.encodings[0].max_bitrate_bps,
+ rtc::Optional<int> stream_max_bitrate =
+ OptionalMin(rtp_parameters_.encodings[0].max_bitrate_bps,
parameters_.max_bitrate_bps);
encoder_config.streams = CreateVideoStreams(
clamped_codec, parameters_.options, stream_max_bitrate, stream_count);
« no previous file with comments | « webrtc/media/engine/webrtcvideoengine2.h ('k') | webrtc/media/engine/webrtcvideoengine2_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698