Skip to content

Commit fdcbe38

Browse files
authored
Updates webrtc to m138 HEAD. (#11492)
Updates webrtc from e4445e46a910eb407571ec0b0b8b7043562678cf to 7ad61a0a06fac695468b843e17b81a6ab19d0feb. Bug: 537464074
1 parent 5b592f4 commit fdcbe38

9 files changed

Lines changed: 15927 additions & 15812 deletions

File tree

third_party/webrtc/docs/monorail-bug-tracker-migration/monorail-issue-tracker-map.csv

Lines changed: 15789 additions & 15789 deletions
Large diffs are not rendered by default.

third_party/webrtc/media/engine/webrtc_voice_engine.cc

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2598,9 +2598,14 @@ bool WebRtcVoiceReceiveChannel::MaybeCreateDefaultReceiveStream(
25982598
// it up to the *latest* unsignaled stream we've seen, in order to support
25992599
// the case where the SSRC of one unsignaled stream changes.
26002600
if (default_sink_) {
2601-
for (uint32_t drop_ssrc : unsignaled_recv_ssrcs_) {
2602-
auto it = recv_streams_.find(drop_ssrc);
2603-
it->second->SetRawAudioSink(nullptr);
2601+
// The new ssrc has already been appended to `unsignaled_recv_ssrcs_`.
2602+
// If there are 2 or more streams, the stream at `size - 2` is the previous
2603+
// latest stream which currently possesses the default sink.
2604+
if (unsignaled_recv_ssrcs_.size() >= 2) {
2605+
// Detach the default sink from the previous latest stream.
2606+
uint32_t prev_ssrc =
2607+
unsignaled_recv_ssrcs_[unsignaled_recv_ssrcs_.size() - 2];
2608+
SetRawAudioSink(prev_ssrc, nullptr);
26042609
}
26052610
std::unique_ptr<AudioSinkInterface> proxy_sink(
26062611
new ProxySink(default_sink_.get()));
@@ -2799,7 +2804,22 @@ bool WebRtcVoiceReceiveChannel::MaybeDeregisterUnsignaledRecvStream(
27992804
RTC_DCHECK_RUN_ON(worker_thread_);
28002805
auto it = absl::c_find(unsignaled_recv_ssrcs_, ssrc);
28012806
if (it != unsignaled_recv_ssrcs_.end()) {
2807+
bool is_latest_unsignaled = (it == unsignaled_recv_ssrcs_.end() - 1);
28022808
unsignaled_recv_ssrcs_.erase(it);
2809+
if (default_sink_) {
2810+
// Detach the default sink from the deregistered stream. This is needed
2811+
// to prevent the ProxySink from holding a dangling pointer to the
2812+
// default_sink_.
2813+
SetRawAudioSink(ssrc, nullptr);
2814+
if (is_latest_unsignaled && !unsignaled_recv_ssrcs_.empty()) {
2815+
// The deregistered stream was the latest unsignaled stream, so it held
2816+
// the default sink. Since it was removed, we must pass the default sink
2817+
// to the *new* latest unsignaled stream via a new ProxySink.
2818+
std::unique_ptr<AudioSinkInterface> proxy_sink(
2819+
new ProxySink(default_sink_.get()));
2820+
SetRawAudioSink(unsignaled_recv_ssrcs_.back(), std::move(proxy_sink));
2821+
}
2822+
}
28032823
return true;
28042824
}
28052825
return false;

third_party/webrtc/modules/audio_coding/BUILD.gn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ rtc_library("audio_coding") {
4747
"../../api/neteq:default_neteq_factory",
4848
"../../api/neteq:neteq_api",
4949
"../../api/units:timestamp",
50+
"../../audio/utility:audio_frame_operations",
5051
"../../common_audio",
5152
"../../common_audio:common_audio_c",
5253
"../../rtc_base:buffer",
@@ -819,7 +820,6 @@ if (rtc_include_tests) {
819820
":acm_send_test",
820821
":audio_codec_speed_tests",
821822
":audio_decoder_unittests",
822-
":audio_decoder_unittests",
823823
":g711_test",
824824
":g722_test",
825825
":neteq_opus_quality_test",
@@ -1063,7 +1063,7 @@ if (rtc_include_tests) {
10631063
"../../api:scoped_refptr",
10641064
"../../api/audio_codecs:audio_codecs_api",
10651065
"../../api/audio_codecs:builtin_audio_decoder_factory",
1066-
"../../api/environment:environment",
1066+
"../../api/environment",
10671067
"../../api/neteq:neteq_api",
10681068
"../../logging:rtc_event_log_parser",
10691069
"../../rtc_base:checks",

third_party/webrtc/modules/audio_coding/DEPS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
include_rules = [
2+
"+audio/utility",
23
"+call",
34
"+common_audio",
45
"+logging/rtc_event_log",

third_party/webrtc/modules/audio_coding/acm2/acm_resampler.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111
#include "modules/audio_coding/acm2/acm_resampler.h"
1212

1313
#include <array>
14+
#include <cstddef>
1415
#include <cstdint>
1516

1617
#include "api/audio/audio_frame.h"
1718
#include "api/audio/audio_view.h"
19+
#include "audio/utility/audio_frame_operations.h"
1820
#include "rtc_base/checks.h"
21+
#include "rtc_base/logging.h"
1922

2023
namespace webrtc {
2124
namespace acm2 {
@@ -37,6 +40,18 @@ bool ResamplerHelper::MaybeResample(int desired_sample_rate_hz,
3740
(desired_sample_rate_hz != -1) &&
3841
(current_sample_rate_hz != desired_sample_rate_hz);
3942

43+
if (need_resampling) {
44+
const size_t target_size =
45+
audio_frame->num_channels_ *
46+
SampleRateToDefaultChannelSize(desired_sample_rate_hz);
47+
if (target_size > AudioFrame::kMaxDataSizeSamples) {
48+
RTC_LOG(LS_ERROR) << "AudioFrame cannot hold resampled data.";
49+
AudioFrameOperations::Mute(audio_frame);
50+
audio_frame->SetSampleRateAndChannelSize(desired_sample_rate_hz);
51+
return false;
52+
}
53+
}
54+
4055
if (need_resampling && !resampled_last_output_frame_) {
4156
// Prime the resampler with the last frame.
4257
InterleavedView<const int16_t> src(last_audio_buffer_.data(),

third_party/webrtc/modules/video_coding/codecs/av1/dav1d_decoder.cc

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@ class ScopedDav1dPicture : public RefCountedNonVirtual<ScopedDav1dPicture> {
8181

8282
constexpr char kDav1dName[] = "dav1d";
8383

84-
// Calling `dav1d_data_wrap` requires a `free_callback` to be registered.
85-
void NullFreeCallback(const uint8_t* /* buffer */, void* /* opaque */) {}
86-
8784
Dav1dDecoder::Dav1dDecoder() = default;
8885

8986
Dav1dDecoder::Dav1dDecoder(const Environment& env)
@@ -141,9 +138,25 @@ int32_t Dav1dDecoder::Decode(const EncodedImage& encoded_image,
141138

142139
ScopedDav1dData scoped_dav1d_data;
143140
Dav1dData& dav1d_data = scoped_dav1d_data.Data();
144-
dav1d_data_wrap(&dav1d_data, encoded_image.data(), encoded_image.size(),
145-
/*free_callback=*/&NullFreeCallback,
146-
/*user_data=*/nullptr);
141+
142+
// Calling GetEncodedData will create a new `scoped_refptr` and increment the
143+
// ref count. By simply releasing we are now responsible for decrementing
144+
// the ref count when appropriate, which is when dav1d calls the
145+
// `free_callback` to indicate that the buffer is no longer needed.
146+
EncodedImageBufferInterface* bitstream_buffer =
147+
encoded_image.GetEncodedData().release();
148+
149+
// Note that the `bitstream_buffer` can have a higher capacity than what is
150+
// actually being used, so `encoded_image.size()` should be used to get the
151+
// actual size of the bitstream.
152+
dav1d_data_wrap(
153+
&dav1d_data, encoded_image.data(), encoded_image.size(),
154+
/*free_callback=*/
155+
[](const uint8_t* /* buffer */, void* user_data) {
156+
auto* bb = static_cast<EncodedImageBufferInterface*>(user_data);
157+
bb->Release();
158+
},
159+
/*user_data=*/bitstream_buffer);
147160

148161
if (int decode_res = dav1d_send_data(context_, &dav1d_data)) {
149162
RTC_LOG(LS_WARNING)

third_party/webrtc/modules/video_coding/codecs/av1/dav1d_decoder_unittest.cc

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,9 @@ class TestAv1Decoder : public DecodedImageCallback {
6161
TestAv1Decoder(const TestAv1Decoder&) = delete;
6262
TestAv1Decoder& operator=(const TestAv1Decoder&) = delete;
6363

64-
void Decode(const EncodedImage& image) {
65-
ASSERT_THAT(decoder_, NotNull());
64+
int32_t Decode(const EncodedImage& image) {
6665
decoded_frame_ = std::nullopt;
67-
int32_t error =
68-
decoder_->Decode(image, /*render_time_ms=*/image.capture_time_ms_);
69-
ASSERT_EQ(error, WEBRTC_VIDEO_CODEC_OK);
70-
ASSERT_THAT(decoded_frame_, Not(Eq(std::nullopt)));
66+
return decoder_->Decode(image, /*render_time_ms=*/image.capture_time_ms_);
7167
}
7268

7369
VideoFrame& decoded_frame() { return *decoded_frame_; }
@@ -89,8 +85,9 @@ class TestAv1Decoder : public DecodedImageCallback {
8985

9086
TEST(Dav1dDecoderTest, KeepsDecodedResolutionByDefault) {
9187
TestAv1Decoder decoder(CreateEnvironment());
92-
decoder.Decode(
93-
CreateEncodedImage(kAv1FrameWith36x20EncodededAnd32x16RenderResolution));
88+
EXPECT_EQ(decoder.Decode(CreateEncodedImage(
89+
kAv1FrameWith36x20EncodededAnd32x16RenderResolution)),
90+
WEBRTC_VIDEO_CODEC_OK);
9491
EXPECT_EQ(decoder.decoded_frame().width(), 36);
9592
EXPECT_EQ(decoder.decoded_frame().height(), 20);
9693
}
@@ -99,8 +96,9 @@ TEST(Dav1dDecoderTest, CropsToRenderResolutionWhenCropIsEnabled) {
9996
TestAv1Decoder decoder(
10097
CreateEnvironment(std::make_unique<ExplicitKeyValueConfig>(
10198
"WebRTC-Dav1dDecoder-CropToRenderResolution/Enabled/")));
102-
decoder.Decode(
103-
CreateEncodedImage(kAv1FrameWith36x20EncodededAnd32x16RenderResolution));
99+
EXPECT_EQ(decoder.Decode(CreateEncodedImage(
100+
kAv1FrameWith36x20EncodededAnd32x16RenderResolution)),
101+
WEBRTC_VIDEO_CODEC_OK);
104102
EXPECT_EQ(decoder.decoded_frame().width(), 32);
105103
EXPECT_EQ(decoder.decoded_frame().height(), 16);
106104
}
@@ -109,12 +107,44 @@ TEST(Dav1dDecoderTest, DoesNotCropToRenderResolutionWhenCropIsDisabled) {
109107
TestAv1Decoder decoder(
110108
CreateEnvironment(std::make_unique<ExplicitKeyValueConfig>(
111109
"WebRTC-Dav1dDecoder-CropToRenderResolution/Disabled/")));
112-
decoder.Decode(
113-
CreateEncodedImage(kAv1FrameWith36x20EncodededAnd32x16RenderResolution));
110+
EXPECT_EQ(decoder.Decode(CreateEncodedImage(
111+
kAv1FrameWith36x20EncodededAnd32x16RenderResolution)),
112+
WEBRTC_VIDEO_CODEC_OK);
114113
EXPECT_EQ(decoder.decoded_frame().width(), 36);
115114
EXPECT_EQ(decoder.decoded_frame().height(), 20);
116115
}
117116

117+
TEST(Dav1dDecoderTest, FailDecoderOnTiles) {
118+
// This test tests buffer management, any failures would be detected
119+
// by running this test under ASAN.
120+
static constexpr uint8_t kTile0[] = {
121+
0x0a, 0x0a, 0x00, 0x00, 0x00, 0x04, 0x3c, 0xff, 0xbc, 0x01, 0xa0, 0x08,
122+
0x32, 0xbd, 0x01, 0x10, 0x60, 0xb0, 0x01, 0xa6, 0x9a, 0x68, 0x50, 0x91,
123+
0xb0, 0x80, 0xb0, 0xd9, 0x8a, 0x40, 0xe4, 0x3e, 0xfb, 0x06, 0x1f, 0x0e,
124+
0xcc, 0xdc, 0xcb, 0x8c, 0x2d, 0x5c, 0xb0, 0x52, 0xe0, 0xb3, 0x89, 0x2b,
125+
0x6b, 0x8b, 0x56, 0xd3, 0x0a, 0x70, 0xad, 0x26, 0xf0, 0xca, 0xfa, 0xad,
126+
0x27, 0xcc, 0x5b, 0x8c, 0x0c, 0x72, 0x76, 0xa7, 0x42, 0x69, 0x4c, 0x47,
127+
0xf4, 0x2b, 0xa9, 0x5e, 0x13, 0x81, 0x69, 0x47, 0x40, 0x13, 0x3e, 0xac,
128+
0xef, 0x0f, 0x74, 0x02, 0x79, 0xa7, 0x50, 0xf4, 0x50, 0x82, 0x4d, 0x4f,
129+
0x70, 0x02, 0x9c, 0x0f, 0x61, 0xbc, 0x1c, 0x22, 0xc2, 0xac, 0x9f, 0x88,
130+
0xbd, 0x2a, 0xdc, 0xdb, 0xf0, 0xbe, 0x95, 0x54, 0x6e, 0xda, 0x08, 0x76,
131+
0x2c, 0x86, 0xd2, 0x0f, 0x86, 0xc1, 0x86, 0xcb, 0x98, 0x35, 0xfc, 0x2c,
132+
0xe7, 0x51, 0x44, 0x62, 0xfe, 0xf1, 0x97, 0x1f, 0xb0, 0x7f, 0x14, 0xc4,
133+
0xef, 0xb0, 0x01, 0x7c, 0x07, 0x22, 0x3e, 0xda, 0x2b, 0xef, 0x59, 0xcc,
134+
0x57, 0x65, 0xc5, 0x22, 0xe9, 0x61, 0x99, 0x0c, 0xd6, 0x07, 0x68, 0x1a,
135+
0x26, 0xad, 0x9b, 0x1e, 0x91, 0x2c, 0xee, 0xe2, 0xe4, 0x7c, 0x4d, 0x07,
136+
0x51, 0x72, 0x89, 0x51, 0xbf, 0x17, 0x67, 0xc0, 0x6d, 0x02, 0x69, 0x92,
137+
0x20, 0x7b, 0xeb, 0x11, 0xea, 0xc1, 0x43, 0x59, 0x4f, 0x75, 0xbb, 0x20};
138+
static constexpr uint8_t kTile1[] = {
139+
0x22, 0x1e, 0xe0, 0xc1, 0xb6, 0x2f, 0x07, 0xd0, 0x0b, 0xaf, 0x14,
140+
0xbf, 0x51, 0xa3, 0x0d, 0xf4, 0xb6, 0x45, 0xd8, 0x16, 0xda, 0x8c,
141+
0xb0, 0xbf, 0x29, 0x39, 0xdf, 0x9a, 0x9e, 0x9c, 0x69, 0x80};
142+
143+
TestAv1Decoder decoder(CreateEnvironment());
144+
decoder.Decode(CreateEncodedImage(kTile0));
145+
decoder.Decode(CreateEncodedImage(kTile1));
146+
}
147+
118148
} // namespace
119149
} // namespace test
120150
} // namespace webrtc

third_party/webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,11 @@ int32_t H264EncoderImpl::Encode(
429429
<< " image to I420. Can't encode frame.";
430430
return WEBRTC_VIDEO_CODEC_ENCODER_FAILURE;
431431
}
432+
if (frame_buffer->StrideU() != frame_buffer->StrideV()) {
433+
// TODO: crbug.com/chromium:491655161 - Remove once the root cause is fixed.
434+
RTC_LOG(LS_ERROR) << "OpenH264 requires the U and V strides to be equal.";
435+
return WEBRTC_VIDEO_CODEC_ENCODER_FAILURE;
436+
}
432437
RTC_CHECK(frame_buffer->type() == VideoFrameBuffer::Type::kI420 ||
433438
frame_buffer->type() == VideoFrameBuffer::Type::kI420A);
434439

third_party/webrtc/modules/video_coding/codecs/h264/h264_encoder_impl_unittest.cc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@
1212
#include "modules/video_coding/codecs/h264/h264_encoder_impl.h"
1313

1414
#include "api/environment/environment_factory.h"
15+
#include "api/test/mock_video_encoder.h"
16+
#include "api/video/i420_buffer.h"
17+
#include "api/video/video_codec_type.h"
18+
#include "api/video/video_frame.h"
19+
#include "api/video_codecs/video_codec.h"
1520
#include "api/video_codecs/video_encoder.h"
21+
#include "modules/video_coding/codecs/h264/include/h264_globals.h"
1622
#include "modules/video_coding/include/video_error_codes.h"
1723
#include "test/gtest.h"
1824

@@ -74,6 +80,31 @@ TEST(H264EncoderImplTest, CanInitializeWithSingleNalUnitModeExplicitly) {
7480
encoder.PacketizationModeForTesting());
7581
}
7682

83+
TEST(H264EncoderImplTest, RejectsFramesWithUnequalChromaStrides) {
84+
H264EncoderImpl encoder(CreateEnvironment(), {});
85+
VideoCodec codec_settings;
86+
SetDefaultSettings(&codec_settings);
87+
MockEncodedImageCallback callback;
88+
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
89+
encoder.InitEncode(&codec_settings, kSettings));
90+
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
91+
encoder.RegisterEncodeCompleteCallback(&callback));
92+
// Create a VideoFrame where the U and V strides are different.
93+
auto buffer = I420Buffer::Create(
94+
/*width=*/codec_settings.width,
95+
/*height=*/codec_settings.height,
96+
/*stride_y=*/codec_settings.width,
97+
/*stride_u=*/(codec_settings.width + 1) / 2,
98+
/*stride_v=*/(codec_settings.width + 1) / 2 + 1);
99+
100+
VideoFrame frame = VideoFrame::Builder()
101+
.set_video_frame_buffer(buffer)
102+
.set_rtp_timestamp(0)
103+
.build();
104+
105+
EXPECT_EQ(WEBRTC_VIDEO_CODEC_ENCODER_FAILURE, encoder.Encode(frame, nullptr));
106+
}
107+
77108
} // anonymous namespace
78109

79110
} // namespace webrtc

0 commit comments

Comments
 (0)