Skip to content

Commit 2678a53

Browse files
youennfphiln
authored andcommitted
Resync libwebrtc to M115.0.5790.95
https://bugs.webkit.org/show_bug.cgi?id=259183 rdar://problem/112187110 Reviewed by Eric Carlson. Cherry-pick webrtc patches that got merged in M115 branch: ad3838a9b5 ba943f71e6 f0d954f659 f5ffd45855 6603550a42 43670de877 * Source/ThirdParty/libwebrtc/Source/webrtc/api/video_codecs/video_codec.h: * Source/ThirdParty/libwebrtc/Source/webrtc/call/rtp_payload_params.cc: * Source/ThirdParty/libwebrtc/Source/webrtc/call/rtp_payload_params_unittest.cc: * Source/ThirdParty/libwebrtc/Source/webrtc/modules/desktop_capture/linux/wayland/shared_screencast_stream.cc: * Source/ThirdParty/libwebrtc/Source/webrtc/pc/BUILD.gn: * Source/ThirdParty/libwebrtc/Source/webrtc/pc/data_channel_controller.cc: * Source/ThirdParty/libwebrtc/Source/webrtc/pc/peer_connection.cc: * Source/ThirdParty/libwebrtc/Source/webrtc/pc/peer_connection.h: * Source/ThirdParty/libwebrtc/Source/webrtc/pc/peer_connection_encodings_integrationtest.cc: * Source/ThirdParty/libwebrtc/Source/webrtc/pc/peer_connection_integrationtest.cc: * Source/ThirdParty/libwebrtc/Source/webrtc/pc/webrtc_sdp.cc: * Source/ThirdParty/libwebrtc/Source/webrtc/pc/webrtc_sdp_unittest.cc: * Source/ThirdParty/libwebrtc/Source/webrtc/video/adaptation/bitrate_constraint.cc: * Source/ThirdParty/libwebrtc/Source/webrtc/video/adaptation/bitrate_constraint_unittest.cc: * Source/ThirdParty/libwebrtc/Source/webrtc/video/adaptation/video_stream_encoder_resource_manager.cc: * Source/ThirdParty/libwebrtc/Source/webrtc/video/adaptation/video_stream_encoder_resource_manager.h: * Source/ThirdParty/libwebrtc/Source/webrtc/video/config/video_encoder_config.h: * Source/ThirdParty/libwebrtc/Source/webrtc/video/video_stream_encoder.cc: Canonical link: https://commits.webkit.org/266045@main
1 parent 9e5f1e4 commit 2678a53

18 files changed

Lines changed: 293 additions & 75 deletions

Source/ThirdParty/libwebrtc/Source/webrtc/api/video_codecs/video_codec.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,15 @@ class RTC_EXPORT VideoCodec {
148148
bool active;
149149

150150
unsigned int qpMax;
151+
// The actual number of simulcast streams. This is <= 1 in singlecast (it can
152+
// be 0 in old code paths), but it is also 1 in the {active,inactive,inactive}
153+
// "single RTP simulcast" use case and the legacy kSVC use case. In all other
154+
// cases this is the same as the number of encodings (which may include
155+
// inactive encodings). In other words:
156+
// - `numberOfSimulcastStreams <= 1` in singlecast and singlecast-like setups
157+
// including legacy kSVC (encodings interpreted as spatial layers) or
158+
// standard kSVC (1 active encoding).
159+
// - `numberOfSimulcastStreams > 1` in simulcast of 2+ active encodings.
151160
unsigned char numberOfSimulcastStreams;
152161
SimulcastStream simulcastStream[kMaxSimulcastStreams];
153162
SpatialLayer spatialLayers[kMaxSpatialLayers];

Source/ThirdParty/libwebrtc/Source/webrtc/call/rtp_payload_params.cc

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -621,23 +621,42 @@ void RtpPayloadParams::Vp9ToGeneric(const CodecSpecificInfoVP9& vp9_info,
621621
// Create the array only if it is ever used.
622622
last_vp9_frame_id_.resize(kPictureDiffLimit);
623623
}
624-
if (vp9_header.inter_layer_predicted && spatial_index > 0) {
625-
result.dependencies.push_back(
626-
last_vp9_frame_id_[vp9_header.picture_id % kPictureDiffLimit]
627-
[spatial_index - 1]);
628-
}
629-
if (vp9_header.inter_pic_predicted) {
630-
for (size_t i = 0; i < vp9_header.num_ref_pics; ++i) {
631-
// picture_id is 15 bit number that wraps around. Though undeflow may
632-
// produce picture that exceeds 2^15, it is ok because in this
633-
// code block only last 7 bits of the picture_id are used.
634-
uint16_t depend_on = vp9_header.picture_id - vp9_header.pid_diff[i];
624+
625+
if (vp9_header.flexible_mode) {
626+
if (vp9_header.inter_layer_predicted && spatial_index > 0) {
635627
result.dependencies.push_back(
636-
last_vp9_frame_id_[depend_on % kPictureDiffLimit][spatial_index]);
628+
last_vp9_frame_id_[vp9_header.picture_id % kPictureDiffLimit]
629+
[spatial_index - 1]);
630+
}
631+
if (vp9_header.inter_pic_predicted) {
632+
for (size_t i = 0; i < vp9_header.num_ref_pics; ++i) {
633+
// picture_id is 15 bit number that wraps around. Though undeflow may
634+
// produce picture that exceeds 2^15, it is ok because in this
635+
// code block only last 7 bits of the picture_id are used.
636+
uint16_t depend_on = vp9_header.picture_id - vp9_header.pid_diff[i];
637+
result.dependencies.push_back(
638+
last_vp9_frame_id_[depend_on % kPictureDiffLimit][spatial_index]);
639+
}
640+
}
641+
last_vp9_frame_id_[vp9_header.picture_id % kPictureDiffLimit]
642+
[spatial_index] = shared_frame_id;
643+
} else {
644+
// Implementing general conversion logic for non-flexible mode requires some
645+
// work and we will almost certainly never need it, so for now support only
646+
// non-layerd streams.
647+
if (spatial_index > 0 || temporal_index > 0) {
648+
// Prefer to generate no generic layering than an inconsistent one.
649+
rtp_video_header.generic.reset();
650+
return;
651+
}
652+
653+
if (vp9_header.inter_pic_predicted) {
654+
// Since we only support non-scalable streams we only need to save the
655+
// last frame id.
656+
result.dependencies.push_back(last_vp9_frame_id_[0][0]);
637657
}
658+
last_vp9_frame_id_[0][0] = shared_frame_id;
638659
}
639-
last_vp9_frame_id_[vp9_header.picture_id % kPictureDiffLimit][spatial_index] =
640-
shared_frame_id;
641660

642661
result.active_decode_targets =
643662
((uint32_t{1} << num_temporal_layers * num_active_spatial_layers) - 1);

Source/ThirdParty/libwebrtc/Source/webrtc/call/rtp_payload_params_unittest.cc

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ TEST(RtpPayloadParamsVp9ToGenericTest, NoScalability) {
567567
EncodedImage encoded_image;
568568
CodecSpecificInfo codec_info;
569569
codec_info.codecType = kVideoCodecVP9;
570+
codec_info.codecSpecific.VP9.flexible_mode = true;
570571
codec_info.codecSpecific.VP9.num_spatial_layers = 1;
571572
codec_info.codecSpecific.VP9.temporal_idx = kNoTemporalIdx;
572573
codec_info.codecSpecific.VP9.first_frame_in_picture = true;
@@ -611,6 +612,55 @@ TEST(RtpPayloadParamsVp9ToGenericTest, NoScalability) {
611612
EXPECT_EQ(header.generic->chain_diffs[0], 3 - 1);
612613
}
613614

615+
TEST(RtpPayloadParamsVp9ToGenericTest, NoScalabilityNonFlexibleMode) {
616+
RtpPayloadState state;
617+
RtpPayloadParams params(/*ssrc=*/123, &state, FieldTrialBasedConfig());
618+
619+
EncodedImage encoded_image;
620+
CodecSpecificInfo codec_info;
621+
codec_info.codecType = kVideoCodecVP9;
622+
codec_info.codecSpecific.VP9.flexible_mode = false;
623+
codec_info.codecSpecific.VP9.num_spatial_layers = 1;
624+
codec_info.codecSpecific.VP9.temporal_idx = kNoTemporalIdx;
625+
codec_info.codecSpecific.VP9.first_frame_in_picture = true;
626+
codec_info.end_of_picture = true;
627+
628+
// Key frame.
629+
encoded_image._frameType = VideoFrameType::kVideoFrameKey;
630+
codec_info.codecSpecific.VP9.inter_pic_predicted = false;
631+
RTPVideoHeader key_header =
632+
params.GetRtpVideoHeader(encoded_image, &codec_info,
633+
/*shared_frame_id=*/1);
634+
635+
ASSERT_TRUE(key_header.generic);
636+
EXPECT_EQ(key_header.generic->spatial_index, 0);
637+
EXPECT_EQ(key_header.generic->temporal_index, 0);
638+
EXPECT_EQ(key_header.generic->frame_id, 1);
639+
ASSERT_THAT(key_header.generic->decode_target_indications, Not(IsEmpty()));
640+
EXPECT_EQ(key_header.generic->decode_target_indications[0],
641+
DecodeTargetIndication::kSwitch);
642+
EXPECT_THAT(key_header.generic->dependencies, IsEmpty());
643+
ASSERT_THAT(key_header.generic->chain_diffs, Not(IsEmpty()));
644+
EXPECT_EQ(key_header.generic->chain_diffs[0], 0);
645+
646+
encoded_image._frameType = VideoFrameType::kVideoFrameDelta;
647+
codec_info.codecSpecific.VP9.inter_pic_predicted = true;
648+
RTPVideoHeader delta_header =
649+
params.GetRtpVideoHeader(encoded_image, &codec_info,
650+
/*shared_frame_id=*/3);
651+
652+
ASSERT_TRUE(delta_header.generic);
653+
EXPECT_EQ(delta_header.generic->spatial_index, 0);
654+
EXPECT_EQ(delta_header.generic->temporal_index, 0);
655+
EXPECT_EQ(delta_header.generic->frame_id, 3);
656+
ASSERT_THAT(delta_header.generic->decode_target_indications, Not(IsEmpty()));
657+
EXPECT_EQ(delta_header.generic->decode_target_indications[0],
658+
DecodeTargetIndication::kSwitch);
659+
EXPECT_THAT(delta_header.generic->dependencies, ElementsAre(1));
660+
ASSERT_THAT(delta_header.generic->chain_diffs, Not(IsEmpty()));
661+
EXPECT_EQ(delta_header.generic->chain_diffs[0], 3 - 1);
662+
}
663+
614664
TEST(RtpPayloadParamsVp9ToGenericTest, TemporalScalabilityWith2Layers) {
615665
// Test with 2 temporal layers structure that is not used by webrtc:
616666
// 1---3 5
@@ -622,6 +672,7 @@ TEST(RtpPayloadParamsVp9ToGenericTest, TemporalScalabilityWith2Layers) {
622672
EncodedImage image;
623673
CodecSpecificInfo info;
624674
info.codecType = kVideoCodecVP9;
675+
info.codecSpecific.VP9.flexible_mode = true;
625676
info.codecSpecific.VP9.num_spatial_layers = 1;
626677
info.codecSpecific.VP9.first_frame_in_picture = true;
627678
info.end_of_picture = true;
@@ -732,6 +783,7 @@ TEST(RtpPayloadParamsVp9ToGenericTest, TemporalScalabilityWith3Layers) {
732783
EncodedImage image;
733784
CodecSpecificInfo info;
734785
info.codecType = kVideoCodecVP9;
786+
info.codecSpecific.VP9.flexible_mode = true;
735787
info.codecSpecific.VP9.num_spatial_layers = 1;
736788
info.codecSpecific.VP9.first_frame_in_picture = true;
737789
info.end_of_picture = true;
@@ -885,6 +937,7 @@ TEST(RtpPayloadParamsVp9ToGenericTest, SpatialScalabilityKSvc) {
885937
EncodedImage image;
886938
CodecSpecificInfo info;
887939
info.codecType = kVideoCodecVP9;
940+
info.codecSpecific.VP9.flexible_mode = true;
888941
info.codecSpecific.VP9.num_spatial_layers = 2;
889942
info.codecSpecific.VP9.first_frame_in_picture = true;
890943

@@ -993,6 +1046,7 @@ TEST(RtpPayloadParamsVp9ToGenericTest,
9931046
EncodedImage image;
9941047
CodecSpecificInfo info;
9951048
info.codecType = kVideoCodecVP9;
1049+
info.codecSpecific.VP9.flexible_mode = true;
9961050
info.codecSpecific.VP9.num_spatial_layers = 1;
9971051
info.codecSpecific.VP9.first_frame_in_picture = true;
9981052

Source/ThirdParty/libwebrtc/Source/webrtc/modules/desktop_capture/linux/wayland/shared_screencast_stream.cc

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ class SharedScreenCastStreamPrivate {
144144
uint32_t frame_rate_ = 60;
145145

146146
bool use_damage_region_ = true;
147-
DesktopRegion last_damage_region_;
148147

149148
// Specifies whether the pipewire stream has been initialized with a request
150149
// to embed cursor into the captured frames.
@@ -159,9 +158,7 @@ class SharedScreenCastStreamPrivate {
159158
void ProcessBuffer(pw_buffer* buffer);
160159
bool ProcessMemFDBuffer(pw_buffer* buffer,
161160
DesktopFrame& frame,
162-
const DesktopFrame* previous_frame,
163-
const DesktopVector& offset,
164-
bool effectively_new_frame);
161+
const DesktopVector& offset);
165162
bool ProcessDMABuffer(pw_buffer* buffer,
166163
DesktopFrame& frame,
167164
const DesktopVector& offset);
@@ -828,22 +825,17 @@ void SharedScreenCastStreamPrivate::ProcessBuffer(pw_buffer* buffer) {
828825
}
829826
}
830827

831-
bool effectively_new_frame = false;
832828
if (!queue_.current_frame() ||
833829
!queue_.current_frame()->size().equals(frame_size_)) {
834830
std::unique_ptr<DesktopFrame> frame(new BasicDesktopFrame(
835831
DesktopSize(frame_size_.width(), frame_size_.height())));
836832
queue_.ReplaceCurrentFrame(SharedDesktopFrame::Wrap(std::move(frame)));
837-
effectively_new_frame = true;
838833
}
839834

840-
UpdateFrameUpdatedRegions(spa_buffer, *queue_.current_frame());
841-
842835
bool bufferProcessed = false;
843836
if (spa_buffer->datas[0].type == SPA_DATA_MemFd) {
844-
bufferProcessed = ProcessMemFDBuffer(buffer, *queue_.current_frame(),
845-
queue_.previous_frame(), offset,
846-
effectively_new_frame);
837+
bufferProcessed =
838+
ProcessMemFDBuffer(buffer, *queue_.current_frame(), offset);
847839
} else if (spa_buffer->datas[0].type == SPA_DATA_DmaBuf) {
848840
bufferProcessed = ProcessDMABuffer(buffer, *queue_.current_frame(), offset);
849841
}
@@ -870,6 +862,7 @@ void SharedScreenCastStreamPrivate::ProcessBuffer(pw_buffer* buffer) {
870862
observer_->OnDesktopFrameChanged();
871863
}
872864

865+
UpdateFrameUpdatedRegions(spa_buffer, *queue_.current_frame());
873866
queue_.current_frame()->set_may_contain_cursor(is_cursor_embedded_);
874867

875868
if (callback_) {
@@ -885,9 +878,7 @@ RTC_NO_SANITIZE("cfi-icall")
885878
bool SharedScreenCastStreamPrivate::ProcessMemFDBuffer(
886879
pw_buffer* buffer,
887880
DesktopFrame& frame,
888-
const DesktopFrame* previous_frame,
889-
const DesktopVector& offset,
890-
bool effectively_new_frame) {
881+
const DesktopVector& offset) {
891882
spa_buffer* spa_buffer = buffer->buffer;
892883
ScopedBuf map;
893884
uint8_t* src = nullptr;
@@ -913,31 +904,9 @@ bool SharedScreenCastStreamPrivate::ProcessMemFDBuffer(
913904
uint8_t* updated_src =
914905
src + (src_stride * offset.y()) + (kBytesPerPixel * offset.x());
915906

916-
const int stride = src_stride - (kBytesPerPixel * offset.x());
917-
918-
if (effectively_new_frame || !previous_frame || !use_damage_region_ ||
919-
damage_region_.is_empty()) {
920-
frame.CopyPixelsFrom(
921-
updated_src, stride,
922-
DesktopRect::MakeWH(frame.size().width(), frame.size().height()));
923-
} else {
924-
for (DesktopRegion::Iterator it(last_damage_region_); !it.IsAtEnd();
925-
it.Advance()) {
926-
const DesktopRect& r = it.rect();
927-
frame.CopyPixelsFrom(*previous_frame, r.top_left(), r);
928-
}
929-
930-
for (DesktopRegion::Iterator it(damage_region_); !it.IsAtEnd();
931-
it.Advance()) {
932-
const auto& rect = it.rect();
933-
frame.CopyPixelsFrom(src + rect.top() * stride +
934-
rect.left() * DesktopFrame::kBytesPerPixel,
935-
stride,
936-
DesktopRect::MakeXYWH(rect.left(), rect.top(),
937-
rect.width(), rect.height()));
938-
}
939-
}
940-
last_damage_region_ = damage_region_;
907+
frame.CopyPixelsFrom(
908+
updated_src, (src_stride - (kBytesPerPixel * offset.x())),
909+
DesktopRect::MakeWH(frame.size().width(), frame.size().height()));
941910

942911
return true;
943912
}

Source/ThirdParty/libwebrtc/Source/webrtc/pc/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2430,6 +2430,7 @@ if (rtc_include_tests && !build_with_chromium) {
24302430
"../api/transport:field_trial_based_config",
24312431
"../api/transport:sctp_transport_factory_interface",
24322432
"../api/transport/rtp:rtp_source",
2433+
"../api/units:data_rate",
24332434
"../api/units:time_delta",
24342435
"../api/units:timestamp",
24352436
"../api/video:builtin_video_bitrate_allocator_factory",

Source/ThirdParty/libwebrtc/Source/webrtc/pc/data_channel_controller.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,19 @@ void DataChannelController::OnChannelStateChanged(
7070
SctpDataChannel* channel,
7171
DataChannelInterface::DataState state) {
7272
RTC_DCHECK_RUN_ON(network_thread());
73+
74+
// Stash away the internal id here in case `OnSctpDataChannelClosed` ends up
75+
// releasing the last reference to the channel.
76+
const int channel_id = channel->internal_id();
77+
7378
if (state == DataChannelInterface::DataState::kClosed)
7479
OnSctpDataChannelClosed(channel);
7580

7681
DataChannelUsage channel_usage = sctp_data_channels_n_.empty()
7782
? DataChannelUsage::kHaveBeenUsed
7883
: DataChannelUsage::kInUse;
7984
signaling_thread()->PostTask(SafeTask(
80-
signaling_safety_.flag(), [this, channel_id = channel->internal_id(),
81-
state = state, channel_usage] {
85+
signaling_safety_.flag(), [this, channel_id, state, channel_usage] {
8286
RTC_DCHECK_RUN_ON(signaling_thread());
8387
channel_usage_ = channel_usage;
8488
pc_->OnSctpDataChannelStateChanged(channel_id, state);

Source/ThirdParty/libwebrtc/Source/webrtc/pc/peer_connection.cc

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -739,9 +739,6 @@ JsepTransportController* PeerConnection::InitializeTransportController_n(
739739
transport_controller_->SubscribeIceConnectionState(
740740
[this](cricket::IceConnectionState s) {
741741
RTC_DCHECK_RUN_ON(network_thread());
742-
if (s == cricket::kIceConnectionConnected) {
743-
ReportTransportStats();
744-
}
745742
signaling_thread()->PostTask(
746743
SafeTask(signaling_thread_safety_.flag(), [this, s]() {
747744
RTC_DCHECK_RUN_ON(signaling_thread());
@@ -2405,6 +2402,20 @@ void PeerConnection::OnTransportControllerConnectionState(
24052402
case cricket::kIceConnectionConnected:
24062403
RTC_LOG(LS_INFO) << "Changing to ICE connected state because "
24072404
"all transports are writable.";
2405+
{
2406+
std::vector<RtpTransceiverProxyRefPtr> transceivers;
2407+
if (ConfiguredForMedia()) {
2408+
transceivers = rtp_manager()->transceivers()->List();
2409+
}
2410+
2411+
network_thread()->PostTask(
2412+
SafeTask(network_thread_safety_,
2413+
[this, transceivers = std::move(transceivers)] {
2414+
RTC_DCHECK_RUN_ON(network_thread());
2415+
ReportTransportStats(std::move(transceivers));
2416+
}));
2417+
}
2418+
24082419
SetIceConnectionState(PeerConnectionInterface::kIceConnectionConnected);
24092420
NoteUsageEvent(UsageEvent::ICE_STATE_CONNECTED);
24102421
break;
@@ -2748,20 +2759,18 @@ void PeerConnection::OnTransportControllerGatheringState(
27482759
}
27492760

27502761
// Runs on network_thread().
2751-
void PeerConnection::ReportTransportStats() {
2762+
void PeerConnection::ReportTransportStats(
2763+
std::vector<RtpTransceiverProxyRefPtr> transceivers) {
27522764
TRACE_EVENT0("webrtc", "PeerConnection::ReportTransportStats");
27532765
rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls;
27542766
std::map<std::string, std::set<cricket::MediaType>>
27552767
media_types_by_transport_name;
2756-
if (ConfiguredForMedia()) {
2757-
for (const auto& transceiver :
2758-
rtp_manager()->transceivers()->UnsafeList()) {
2759-
if (transceiver->internal()->channel()) {
2760-
std::string transport_name(
2761-
transceiver->internal()->channel()->transport_name());
2762-
media_types_by_transport_name[transport_name].insert(
2763-
transceiver->media_type());
2764-
}
2768+
for (const auto& transceiver : transceivers) {
2769+
if (transceiver->internal()->channel()) {
2770+
std::string transport_name(
2771+
transceiver->internal()->channel()->transport_name());
2772+
media_types_by_transport_name[transport_name].insert(
2773+
transceiver->media_type());
27652774
}
27662775
}
27672776

Source/ThirdParty/libwebrtc/Source/webrtc/pc/peer_connection.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,8 @@ class PeerConnection : public PeerConnectionInternal,
567567

568568
// Invoked when TransportController connection completion is signaled.
569569
// Reports stats for all transports in use.
570-
void ReportTransportStats() RTC_RUN_ON(network_thread());
570+
void ReportTransportStats(std::vector<RtpTransceiverProxyRefPtr> transceivers)
571+
RTC_RUN_ON(network_thread());
571572

572573
// Gather the usage of IPv4/IPv6 as best connection.
573574
static void ReportBestConnectionState(const cricket::TransportStats& stats);

0 commit comments

Comments
 (0)