0

Allow client to provide a target video FPS via SessionOptions

This CL will allow us to pass a target frame rate from the client to
use as the target framerate for capture and encode when WebRTC is
used. This is to be used for testing and performance tuning, once we
are done tuning, we can look into whether to update the framerate
constant or whether we need to provide a framerate per codec in the
SDP.

Bug: b:217468304
Change-Id: I2ed310f1ccafa69ff05540e4f510d350316adf8a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3700825
Reviewed-by: Lambros Lambrou <lambroslambrou@chromium.org>
Commit-Queue: Joe Downing <joedow@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1013695}
This commit is contained in:
Joe Downing
2022-06-13 22:42:43 +00:00
committed by Chromium LUCI CQ
parent 9dd6f695e7
commit c157f2bcd5
4 changed files with 22 additions and 6 deletions

@ -356,9 +356,11 @@ void WebrtcVideoEncoderGpu::Core::BeginInitialization() {
#endif
VideoPixelFormat input_format = VideoPixelFormat::PIXEL_FORMAT_NV12;
// TODO(zijiehe): implement some logical way to set an initial bitrate.
// TODO(zijiehe): Implement some logical way to set an initial bitrate.
// Currently we set the bitrate to 8M bits / 1M bytes per frame, and 30 frames
// per second.
// TODO(joedow): Use the framerate from SessionOptions instead of the constant
// framerate value if we decide to make H.264 generally available.
media::Bitrate initial_bitrate = media::Bitrate::ConstantBitrate(
static_cast<uint32_t>(kTargetFrameRate * 1024 * 1024 * 8));

@ -118,7 +118,7 @@ void WebrtcFrameSchedulerConstantRate::ScheduleNextFrame() {
if (!last_capture_started_time_.is_null()) {
base::TimeTicks target_capture_time =
std::max(last_capture_started_time_ + capture_interval, now);
delay = target_capture_time - now;
delay = std::max(target_capture_time - now, base::Milliseconds(1));
}
capture_timer_.Start(FROM_HERE, delay, this,

@ -13,6 +13,7 @@
#include "base/base64.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/cxx17_backports.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_number_conversions.h"
@ -144,7 +145,8 @@ TransportRoute::RouteType CandidateTypeToTransportRouteType(
// Initializes default parameters for a sender that may be different from
// WebRTC's defaults.
void SetDefaultSenderParameters(
rtc::scoped_refptr<webrtc::RtpSenderInterface> sender) {
rtc::scoped_refptr<webrtc::RtpSenderInterface> sender,
int video_frame_rate) {
if (sender->media_type() == cricket::MEDIA_TYPE_VIDEO) {
webrtc::RtpParameters parameters = sender->GetParameters();
if (parameters.encodings.empty()) {
@ -153,7 +155,7 @@ void SetDefaultSenderParameters(
}
for (auto& encoding : parameters.encodings) {
encoding.max_framerate = kTargetFrameRate;
encoding.max_framerate = video_frame_rate;
}
webrtc::RTCError result = sender->SetParameters(parameters);
@ -745,6 +747,16 @@ void WebrtcTransport::ApplySessionOptions(const SessionOptions& options) {
if (video_codec) {
preferred_video_codec_ = *video_codec;
}
absl::optional<std::string> video_frame_rate =
session_options().Get("Video-Frame-Rate");
if (video_frame_rate) {
int frame_rate;
if (base::StringToInt(*video_frame_rate, &frame_rate)) {
// Clamp the range to prevent a bad experience in case of a client bug.
frame_rate = base::clamp<int>(frame_rate, kTargetFrameRate, 1000);
desired_video_frame_rate_ = frame_rate;
}
}
}
void WebrtcTransport::OnAudioTransceiverCreated(
@ -757,7 +769,7 @@ void WebrtcTransport::OnVideoTransceiverCreated(
auto sender = transceiver->sender();
auto [min_bitrate_bps, max_bitrate_bps] = BitratesForConnection();
SetSenderBitrates(sender, min_bitrate_bps, max_bitrate_bps);
SetDefaultSenderParameters(sender);
SetDefaultSenderParameters(sender, desired_video_frame_rate_);
}
void WebrtcTransport::OnLocalSessionDescriptionCreated(
@ -845,7 +857,7 @@ void WebrtcTransport::OnLocalDescriptionSet(bool success,
// maximum framerate.
auto senders = peer_connection()->GetSenders();
for (const auto& sender : senders) {
SetDefaultSenderParameters(sender);
SetDefaultSenderParameters(sender, desired_video_frame_rate_);
}
}

@ -17,6 +17,7 @@
#include "base/threading/thread_checker.h"
#include "base/timer/timer.h"
#include "crypto/hmac.h"
#include "remoting/base/constants.h"
#include "remoting/base/session_options.h"
#include "remoting/protocol/peer_connection_controls.h"
#include "remoting/protocol/session_options_provider.h"
@ -253,6 +254,7 @@ class WebrtcTransport : public Transport,
pending_incoming_candidates_;
std::string preferred_video_codec_;
int desired_video_frame_rate_ = kTargetFrameRate;
SessionOptions session_options_;