summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/video/video_send_stream_impl.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:43:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:43:14 +0000
commit8dd16259287f58f9273002717ec4d27e97127719 (patch)
tree3863e62a53829a84037444beab3abd4ed9dfc7d0 /third_party/libwebrtc/video/video_send_stream_impl.cc
parentReleasing progress-linux version 126.0.1-1~progress7.99u1. (diff)
downloadfirefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz
firefox-8dd16259287f58f9273002717ec4d27e97127719.zip
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/video/video_send_stream_impl.cc')
-rw-r--r--third_party/libwebrtc/video/video_send_stream_impl.cc70
1 files changed, 38 insertions, 32 deletions
diff --git a/third_party/libwebrtc/video/video_send_stream_impl.cc b/third_party/libwebrtc/video/video_send_stream_impl.cc
index 23dbb7177f..ec63b51816 100644
--- a/third_party/libwebrtc/video/video_send_stream_impl.cc
+++ b/third_party/libwebrtc/video/video_send_stream_impl.cc
@@ -362,6 +362,15 @@ std::unique_ptr<VideoStreamEncoderInterface> CreateVideoStreamEncoder(
encoder_selector);
}
+bool HasActiveEncodings(const VideoEncoderConfig& config) {
+ for (const VideoStream& stream : config.simulcast_layers) {
+ if (stream.active) {
+ return true;
+ }
+ }
+ return false;
+}
+
} // namespace
PacingConfig::PacingConfig(const FieldTrialsView& field_trials)
@@ -438,6 +447,7 @@ VideoSendStreamImpl::VideoSendStreamImpl(
timed_out_(false),
bitrate_allocator_(bitrate_allocator),
+ has_active_encodings_(HasActiveEncodings(encoder_config)),
disable_padding_(true),
max_padding_bitrate_(0),
encoder_min_bitrate_bps_(0),
@@ -512,6 +522,7 @@ VideoSendStreamImpl::~VideoSendStreamImpl() {
RTC_DCHECK_RUN_ON(&thread_checker_);
RTC_LOG(LS_INFO) << "~VideoSendStreamImpl: " << config_.ToString();
RTC_DCHECK(!started());
+ RTC_DCHECK(!IsRunning());
transport_->DestroyRtpVideoSender(rtp_video_sender_);
}
@@ -545,6 +556,13 @@ void VideoSendStreamImpl::ReconfigureVideoEncoder(
RTC_DCHECK_EQ(content_type_, config.content_type);
RTC_LOG(LS_VERBOSE) << "Encoder config: " << config.ToString()
<< " VideoSendStream config: " << config_.ToString();
+
+ has_active_encodings_ = HasActiveEncodings(config);
+ if (has_active_encodings_ && rtp_video_sender_->IsActive() && !IsRunning()) {
+ StartupVideoSendStream();
+ } else if (!has_active_encodings_ && IsRunning()) {
+ StopVideoSendStream();
+ }
video_stream_encoder_->ConfigureEncoder(
std::move(config),
config_.rtp.max_packet_size - CalculateMaxHeaderSize(config_.rtp),
@@ -609,40 +627,24 @@ bool VideoSendStreamImpl::started() {
}
void VideoSendStreamImpl::Start() {
- const std::vector<bool> active_layers(config_.rtp.ssrcs.size(), true);
- StartPerRtpStream(active_layers);
-}
-
-void VideoSendStreamImpl::StartPerRtpStream(
- const std::vector<bool> active_layers) {
RTC_DCHECK_RUN_ON(&thread_checker_);
-
- rtc::StringBuilder active_layers_string;
- active_layers_string << "{";
- for (size_t i = 0; i < active_layers.size(); ++i) {
- if (active_layers[i]) {
- active_layers_string << "1";
- } else {
- active_layers_string << "0";
- }
- if (i < active_layers.size() - 1) {
- active_layers_string << ", ";
- }
- }
- active_layers_string << "}";
- RTC_LOG(LS_INFO) << "StartPerRtpStream: " << active_layers_string.str();
-
- bool previously_active = rtp_video_sender_->IsActive();
- rtp_video_sender_->SetActiveModules(active_layers);
- if (!rtp_video_sender_->IsActive() && previously_active) {
- StopVideoSendStream();
- } else if (rtp_video_sender_->IsActive() && !previously_active) {
+ // This sender is allowed to send RTP packets. Start monitoring and allocating
+ // a rate if there is also active encodings. (has_active_encodings_).
+ rtp_video_sender_->SetSending(true);
+ if (!IsRunning() && has_active_encodings_) {
StartupVideoSendStream();
}
}
+bool VideoSendStreamImpl::IsRunning() const {
+ RTC_DCHECK_RUN_ON(&thread_checker_);
+ return check_encoder_activity_task_.Running();
+}
+
void VideoSendStreamImpl::StartupVideoSendStream() {
RTC_DCHECK_RUN_ON(&thread_checker_);
+ RTC_DCHECK(rtp_video_sender_->IsActive());
+ RTC_DCHECK(has_active_encodings_);
bitrate_allocator_->AddObserver(this, GetAllocationConfig());
// Start monitoring encoder activity.
@@ -679,8 +681,10 @@ void VideoSendStreamImpl::Stop() {
return;
TRACE_EVENT_INSTANT0("webrtc", "VideoSendStream::Stop");
- rtp_video_sender_->Stop();
- StopVideoSendStream();
+ rtp_video_sender_->SetSending(false);
+ if (IsRunning()) {
+ StopVideoSendStream();
+ }
}
void VideoSendStreamImpl::StopVideoSendStream() {
@@ -761,7 +765,7 @@ void VideoSendStreamImpl::OnVideoLayersAllocationUpdated(
void VideoSendStreamImpl::SignalEncoderActive() {
RTC_DCHECK_RUN_ON(&thread_checker_);
- if (rtp_video_sender_->IsActive()) {
+ if (IsRunning()) {
RTC_LOG(LS_INFO) << "SignalEncoderActive, Encoder is active.";
bitrate_allocator_->AddObserver(this, GetAllocationConfig());
}
@@ -805,7 +809,9 @@ void VideoSendStreamImpl::OnEncoderConfigurationChanged(
double stream_bitrate_priority_sum = 0;
for (const auto& stream : streams) {
// We don't want to allocate more bitrate than needed to inactive streams.
- encoder_max_bitrate_bps_ += stream.active ? stream.max_bitrate_bps : 0;
+ if (stream.active) {
+ encoder_max_bitrate_bps_ += stream.max_bitrate_bps;
+ }
if (stream.bitrate_priority) {
RTC_DCHECK_GT(*stream.bitrate_priority, 0);
stream_bitrate_priority_sum += *stream.bitrate_priority;
@@ -833,7 +839,7 @@ void VideoSendStreamImpl::OnEncoderConfigurationChanged(
rtp_video_sender_->SetEncodingData(streams[0].width, streams[0].height,
num_temporal_layers);
- if (rtp_video_sender_->IsActive()) {
+ if (IsRunning()) {
// The send stream is started already. Update the allocator with new
// bitrate limits.
bitrate_allocator_->AddObserver(this, GetAllocationConfig());