Bug 1903098 - Vendor libwebrtc from 7e41c06d25

Upstream commit: https://webrtc.googlesource.com/src/+/7e41c06d25d8ce5d5adfd11721ff6b04f006be0f
    Deprecate the StreamInterface::SignalEvent sigslot

    In its stead, there's now a SetEventCallback() method.

    Bug: webrtc:11943
    Change-Id: If936d6e1e23e8a584f06feb123ecf2d450ea4145
    Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/319040
    Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
    Reviewed-by: Harald Alvestrand <hta@webrtc.org>
    Cr-Commit-Position: refs/heads/main@{#42187}
This commit is contained in:
Michael Froman 2024-06-18 17:40:40 -05:00
Родитель d8e85e8b63
Коммит 2bad356d16
14 изменённых файлов: 158 добавлений и 95 удалений

3
third_party/libwebrtc/README.moz-ff-commit поставляемый
Просмотреть файл

@ -30330,3 +30330,6 @@ c75ee61a0b
# MOZ_LIBWEBRTC_SRC=/home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc MOZ_LIBWEBRTC_BRANCH=mozpatches bash dom/media/webrtc/third_party_build/fast-forward-libwebrtc.sh # MOZ_LIBWEBRTC_SRC=/home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc MOZ_LIBWEBRTC_BRANCH=mozpatches bash dom/media/webrtc/third_party_build/fast-forward-libwebrtc.sh
# base of lastest vendoring # base of lastest vendoring
e92f4095ad e92f4095ad
# MOZ_LIBWEBRTC_SRC=/home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc MOZ_LIBWEBRTC_BRANCH=mozpatches bash dom/media/webrtc/third_party_build/fast-forward-libwebrtc.sh
# base of lastest vendoring
7e41c06d25

2
third_party/libwebrtc/README.mozilla поставляемый
Просмотреть файл

@ -20244,3 +20244,5 @@ libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc
libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2024-06-18T22:38:51.724001. libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2024-06-18T22:38:51.724001.
# ./mach python dom/media/webrtc/third_party_build/vendor-libwebrtc.py --from-local /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc --commit mozpatches libwebrtc # ./mach python dom/media/webrtc/third_party_build/vendor-libwebrtc.py --from-local /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc --commit mozpatches libwebrtc
libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2024-06-18T22:39:41.468174. libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2024-06-18T22:39:41.468174.
# ./mach python dom/media/webrtc/third_party_build/vendor-libwebrtc.py --from-local /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc --commit mozpatches libwebrtc
libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2024-06-18T22:40:29.716405.

Просмотреть файл

@ -1563,7 +1563,7 @@ index d8c9805b9b..1238f01aae 100644
std::unique_ptr<ScalableVideoController> svc_controller_; std::unique_ptr<ScalableVideoController> svc_controller_;
absl::optional<ScalabilityMode> scalability_mode_; absl::optional<ScalabilityMode> scalability_mode_;
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
index a7a2adadfc..eb089fc8c2 100644 index f761c36400..fd94cff373 100644
--- a/rtc_base/BUILD.gn --- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn
@@ -470,6 +470,12 @@ rtc_library("logging") { @@ -470,6 +470,12 @@ rtc_library("logging") {

Просмотреть файл

@ -1050,7 +1050,7 @@ index b8345841fa..7289dbe0a8 100644
"/config/external/nspr", "/config/external/nspr",
"/nsprpub/lib/ds", "/nsprpub/lib/ds",
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
index eb089fc8c2..5c83ceb4e6 100644 index fd94cff373..45ed15e39a 100644
--- a/rtc_base/BUILD.gn --- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn
@@ -334,6 +334,7 @@ rtc_library("sample_counter") { @@ -334,6 +334,7 @@ rtc_library("sample_counter") {
@ -1181,7 +1181,7 @@ index eb089fc8c2..5c83ceb4e6 100644
rtc_library("crc32") { rtc_library("crc32") {
sources = [ sources = [
@@ -1473,6 +1493,7 @@ rtc_library("stream") { @@ -1475,6 +1495,7 @@ rtc_library("stream") {
} }
rtc_library("rtc_certificate_generator") { rtc_library("rtc_certificate_generator") {
@ -1189,7 +1189,7 @@ index eb089fc8c2..5c83ceb4e6 100644
visibility = [ "*" ] visibility = [ "*" ]
sources = [ sources = [
"rtc_certificate_generator.cc", "rtc_certificate_generator.cc",
@@ -1490,8 +1511,10 @@ rtc_library("rtc_certificate_generator") { @@ -1492,8 +1513,10 @@ rtc_library("rtc_certificate_generator") {
"//third_party/abseil-cpp/absl/types:optional", "//third_party/abseil-cpp/absl/types:optional",
] ]
} }
@ -1200,7 +1200,7 @@ index eb089fc8c2..5c83ceb4e6 100644
visibility = [ "*" ] visibility = [ "*" ]
sources = [ sources = [
"helpers.cc", "helpers.cc",
@@ -1592,6 +1615,7 @@ rtc_library("ssl") { @@ -1594,6 +1617,7 @@ rtc_library("ssl") {
deps += [ ":win32" ] deps += [ ":win32" ]
} }
} }
@ -1208,7 +1208,7 @@ index eb089fc8c2..5c83ceb4e6 100644
rtc_library("crypt_string") { rtc_library("crypt_string") {
sources = [ sources = [
@@ -2158,7 +2182,7 @@ if (rtc_include_tests) { @@ -2161,7 +2185,7 @@ if (rtc_include_tests) {
} }
} }

Просмотреть файл

@ -29,7 +29,7 @@ index 8697f87433..4a320422fb 100644
rtc_library("task_queue_test") { rtc_library("task_queue_test") {
visibility = [ "*" ] visibility = [ "*" ]
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
index 5c83ceb4e6..ae8b129624 100644 index 45ed15e39a..d0abc8d1d8 100644
--- a/rtc_base/BUILD.gn --- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn
@@ -733,10 +733,14 @@ if (is_mac || is_ios) { @@ -733,10 +733,14 @@ if (is_mac || is_ios) {

Просмотреть файл

@ -13,7 +13,7 @@ Mercurial Revision: https://hg.mozilla.org/mozilla-central/rev/4e7b3c485e549e7e3
1 file changed, 6 insertions(+) 1 file changed, 6 insertions(+)
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
index ae8b129624..aea7d619b8 100644 index d0abc8d1d8..12953b6106 100644
--- a/rtc_base/BUILD.gn --- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn
@@ -1033,6 +1033,12 @@ rtc_library("threading") { @@ -1033,6 +1033,12 @@ rtc_library("threading") {

Просмотреть файл

@ -379,7 +379,8 @@ bool DtlsTransport::SetupDtls() {
dtls_->SetMode(rtc::SSL_MODE_DTLS); dtls_->SetMode(rtc::SSL_MODE_DTLS);
dtls_->SetMaxProtocolVersion(ssl_max_version_); dtls_->SetMaxProtocolVersion(ssl_max_version_);
dtls_->SetServerRole(*dtls_role_); dtls_->SetServerRole(*dtls_role_);
dtls_->SignalEvent.connect(this, &DtlsTransport::OnDtlsEvent); dtls_->SetEventCallback(
[this](int events, int err) { OnDtlsEvent(events, err); });
if (remote_fingerprint_value_.size() && if (remote_fingerprint_value_.size() &&
!dtls_->SetPeerCertificateDigest( !dtls_->SetPeerCertificateDigest(
remote_fingerprint_algorithm_, remote_fingerprint_algorithm_,
@ -698,9 +699,8 @@ void DtlsTransport::OnReadyToSend(rtc::PacketTransportInternal* transport) {
} }
} }
void DtlsTransport::OnDtlsEvent(rtc::StreamInterface* dtls, int sig, int err) { void DtlsTransport::OnDtlsEvent(int sig, int err) {
RTC_DCHECK_RUN_ON(&thread_checker_); RTC_DCHECK_RUN_ON(&thread_checker_);
RTC_DCHECK(dtls == dtls_.get());
if (sig & rtc::SE_OPEN) { if (sig & rtc::SE_OPEN) {
// This is the first time. // This is the first time.
RTC_LOG(LS_INFO) << ToString() << ": DTLS handshake complete."; RTC_LOG(LS_INFO) << ToString() << ": DTLS handshake complete.";

Просмотреть файл

@ -221,7 +221,7 @@ class DtlsTransport : public DtlsTransportInternal {
const rtc::SentPacket& sent_packet); const rtc::SentPacket& sent_packet);
void OnReadyToSend(rtc::PacketTransportInternal* transport); void OnReadyToSend(rtc::PacketTransportInternal* transport);
void OnReceivingState(rtc::PacketTransportInternal* transport); void OnReceivingState(rtc::PacketTransportInternal* transport);
void OnDtlsEvent(rtc::StreamInterface* stream_, int sig, int err); void OnDtlsEvent(int sig, int err);
void OnNetworkRouteChanged(absl::optional<rtc::NetworkRoute> network_route); void OnNetworkRouteChanged(absl::optional<rtc::NetworkRoute> network_route);
bool SetupDtls(); bool SetupDtls();
void MaybeStartDtls(); void MaybeStartDtls();

3
third_party/libwebrtc/rtc_base/BUILD.gn поставляемый
Просмотреть файл

@ -1500,6 +1500,8 @@ rtc_library("stream") {
"system:rtc_export", "system:rtc_export",
"third_party/sigslot", "third_party/sigslot",
] ]
absl_deps = [ "//third_party/abseil-cpp/absl/functional:any_invocable" ]
} }
rtc_library("rtc_certificate_generator") { rtc_library("rtc_certificate_generator") {
@ -2171,6 +2173,7 @@ if (rtc_include_tests) {
"ssl_identity_unittest.cc", "ssl_identity_unittest.cc",
"ssl_stream_adapter_unittest.cc", "ssl_stream_adapter_unittest.cc",
] ]
deps += [ ":callback_list" ]
} }
absl_deps = [ absl_deps = [
"//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/algorithm:container",

Просмотреть файл

@ -296,7 +296,8 @@ OpenSSLStreamAdapter::OpenSSLStreamAdapter(
#endif #endif
ssl_mode_(SSL_MODE_TLS), ssl_mode_(SSL_MODE_TLS),
ssl_max_version_(SSL_PROTOCOL_TLS_12) { ssl_max_version_(SSL_PROTOCOL_TLS_12) {
stream_->SignalEvent.connect(this, &OpenSSLStreamAdapter::OnEvent); stream_->SetEventCallback(
[this](int events, int err) { OnEvent(events, err); });
} }
OpenSSLStreamAdapter::~OpenSSLStreamAdapter() { OpenSSLStreamAdapter::~OpenSSLStreamAdapter() {
@ -741,13 +742,10 @@ StreamState OpenSSLStreamAdapter::GetState() const {
// not reached // not reached
} }
void OpenSSLStreamAdapter::OnEvent(StreamInterface* stream, void OpenSSLStreamAdapter::OnEvent(int events, int err) {
int events,
int err) {
RTC_DCHECK_RUN_ON(&callback_sequence_); RTC_DCHECK_RUN_ON(&callback_sequence_);
int events_to_signal = 0; int events_to_signal = 0;
int signal_error = 0; int signal_error = 0;
RTC_DCHECK(stream == stream_.get());
if ((events & SE_OPEN)) { if ((events & SE_OPEN)) {
RTC_DLOG(LS_VERBOSE) << "OpenSSLStreamAdapter::OnEvent SE_OPEN"; RTC_DLOG(LS_VERBOSE) << "OpenSSLStreamAdapter::OnEvent SE_OPEN";

Просмотреть файл

@ -148,7 +148,7 @@ class OpenSSLStreamAdapter final : public SSLStreamAdapter,
SSL_CLOSED // Clean close SSL_CLOSED // Clean close
}; };
void OnEvent(StreamInterface* stream, int events, int err); void OnEvent(int events, int err);
void PostEvent(int events, int err); void PostEvent(int events, int err);
void SetTimeout(int delay_ms); void SetTimeout(int delay_ms);

Просмотреть файл

@ -321,7 +321,7 @@ class SSLAdapterTestDummyServer : public sigslot::has_slots<> {
DoHandshake(server_socket_->Accept(nullptr)); DoHandshake(server_socket_->Accept(nullptr));
} }
void OnSSLStreamAdapterEvent(rtc::StreamInterface* stream, int sig, int err) { void OnSSLStreamAdapterEvent(int sig, int err) {
if (sig & rtc::SE_READ) { if (sig & rtc::SE_READ) {
uint8_t buffer[4096] = ""; uint8_t buffer[4096] = "";
size_t read; size_t read;
@ -329,7 +329,7 @@ class SSLAdapterTestDummyServer : public sigslot::has_slots<> {
// Read data received from the client and store it in our internal // Read data received from the client and store it in our internal
// buffer. // buffer.
rtc::StreamResult r = stream->Read(buffer, read, error); rtc::StreamResult r = ssl_stream_adapter_->Read(buffer, read, error);
if (r == rtc::SR_SUCCESS) { if (r == rtc::SR_SUCCESS) {
buffer[read] = '\0'; buffer[read] = '\0';
// Here we assume that the buffer is interpretable as string. // Here we assume that the buffer is interpretable as string.
@ -365,8 +365,8 @@ class SSLAdapterTestDummyServer : public sigslot::has_slots<> {
ssl_stream_adapter_->StartSSL(); ssl_stream_adapter_->StartSSL();
ssl_stream_adapter_->SignalEvent.connect( ssl_stream_adapter_->SetEventCallback(
this, &SSLAdapterTestDummyServer::OnSSLStreamAdapterEvent); [this](int events, int err) { OnSSLStreamAdapterEvent(events, err); });
} }
const rtc::SSLMode ssl_mode_; const rtc::SSLMode ssl_mode_;

Просмотреть файл

@ -20,6 +20,7 @@
#include "api/array_view.h" #include "api/array_view.h"
#include "api/task_queue/pending_task_safety_flag.h" #include "api/task_queue/pending_task_safety_flag.h"
#include "rtc_base/buffer_queue.h" #include "rtc_base/buffer_queue.h"
#include "rtc_base/callback_list.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/gunit.h" #include "rtc_base/gunit.h"
#include "rtc_base/helpers.h" #include "rtc_base/helpers.h"
@ -149,17 +150,75 @@ static const char kCACert[] =
class SSLStreamAdapterTestBase; class SSLStreamAdapterTestBase;
class SSLDummyStreamBase : public rtc::StreamInterface, // StreamWrapper is a middle layer between `stream`, which supports a single
public sigslot::has_slots<> { // event callback, and test classes in this file that need that event forwarded
// to them. I.e. this class wraps a `stream` object that it delegates all calls
// to, but for the event callback, `StreamWrapper` additionally provides support
// for forwarding event notifications to test classes that call
// `SubscribeStreamEvent()`.
//
// This is needed because in this file, tests connect both client and server
// streams (SSLDummyStream) to the same underlying `stream` objects
// (see CreateClientStream() and CreateServerStream()).
class StreamWrapper : public rtc::StreamInterface {
public: public:
SSLDummyStreamBase(SSLStreamAdapterTestBase* test, explicit StreamWrapper(std::unique_ptr<rtc::StreamInterface> stream)
: stream_(std::move(stream)) {
stream_->SetEventCallback([this](int events, int err) {
RTC_DCHECK_RUN_ON(&callback_sequence_);
callbacks_.Send(events, err);
FireEvent(events, err);
});
}
template <typename F>
void SubscribeStreamEvent(const void* removal_tag, F&& callback) {
callbacks_.AddReceiver(removal_tag, std::forward<F>(callback));
}
void UnsubscribeStreamEvent(const void* removal_tag) {
callbacks_.RemoveReceivers(removal_tag);
}
rtc::StreamState GetState() const override { return stream_->GetState(); }
void Close() override { stream_->Close(); }
rtc::StreamResult Read(rtc::ArrayView<uint8_t> buffer,
size_t& read,
int& error) override {
return stream_->Read(buffer, read, error);
}
rtc::StreamResult Write(rtc::ArrayView<const uint8_t> data,
size_t& written,
int& error) override {
return stream_->Write(data, written, error);
}
private:
const std::unique_ptr<rtc::StreamInterface> stream_;
webrtc::CallbackList<int, int> callbacks_;
};
class SSLDummyStream final : public rtc::StreamInterface {
public:
SSLDummyStream(SSLStreamAdapterTestBase* test,
absl::string_view side, absl::string_view side,
rtc::StreamInterface* in, StreamWrapper* in,
rtc::StreamInterface* out) StreamWrapper* out)
: test_base_(test), side_(side), in_(in), out_(out), first_packet_(true) { : test_base_(test), side_(side), in_(in), out_(out), first_packet_(true) {
RTC_DCHECK_NE(in, out); RTC_CHECK(thread_);
in_->SignalEvent.connect(this, &SSLDummyStreamBase::OnEventIn); RTC_CHECK_NE(in, out);
out_->SignalEvent.connect(this, &SSLDummyStreamBase::OnEventOut); in_->SubscribeStreamEvent(
this, [this](int events, int err) { OnEventIn(events, err); });
out_->SubscribeStreamEvent(
this, [this](int events, int err) { OnEventOut(events, err); });
}
~SSLDummyStream() override {
in_->UnsubscribeStreamEvent(this);
out_->UnsubscribeStreamEvent(this);
} }
rtc::StreamState GetState() const override { return rtc::SS_OPEN; } rtc::StreamState GetState() const override { return rtc::SS_OPEN; }
@ -184,20 +243,20 @@ class SSLDummyStreamBase : public rtc::StreamInterface,
} }
// Catch readability events on in and pass them up. // Catch readability events on in and pass them up.
void OnEventIn(rtc::StreamInterface* stream, int sig, int err) { void OnEventIn(int sig, int err) {
int mask = (rtc::SE_READ | rtc::SE_CLOSE); int mask = (rtc::SE_READ | rtc::SE_CLOSE);
if (sig & mask) { if (sig & mask) {
RTC_LOG(LS_VERBOSE) << "SSLDummyStreamBase::OnEventIn side=" << side_ RTC_LOG(LS_VERBOSE) << "SSLDummyStream::OnEventIn side=" << side_
<< " sig=" << sig << " forwarding upward"; << " sig=" << sig << " forwarding upward";
PostEvent(sig & mask, 0); PostEvent(sig & mask, 0);
} }
} }
// Catch writeability events on out and pass them up. // Catch writeability events on out and pass them up.
void OnEventOut(rtc::StreamInterface* stream, int sig, int err) { void OnEventOut(int sig, int err) {
if (sig & rtc::SE_WRITE) { if (sig & rtc::SE_WRITE) {
RTC_LOG(LS_VERBOSE) << "SSLDummyStreamBase::OnEventOut side=" << side_ RTC_LOG(LS_VERBOSE) << "SSLDummyStream::OnEventOut side=" << side_
<< " sig=" << sig << " forwarding upward"; << " sig=" << sig << " forwarding upward";
PostEvent(sig & rtc::SE_WRITE, 0); PostEvent(sig & rtc::SE_WRITE, 0);
@ -232,20 +291,11 @@ class SSLDummyStreamBase : public rtc::StreamInterface,
rtc::Thread* const thread_ = rtc::Thread::Current(); rtc::Thread* const thread_ = rtc::Thread::Current();
SSLStreamAdapterTestBase* test_base_; SSLStreamAdapterTestBase* test_base_;
const std::string side_; const std::string side_;
rtc::StreamInterface* in_; StreamWrapper* const in_;
rtc::StreamInterface* out_; StreamWrapper* const out_;
bool first_packet_; bool first_packet_;
}; };
class SSLDummyStreamTLS : public SSLDummyStreamBase {
public:
SSLDummyStreamTLS(SSLStreamAdapterTestBase* test,
absl::string_view side,
rtc::FifoBuffer* in,
rtc::FifoBuffer* out)
: SSLDummyStreamBase(test, side, in, out) {}
};
class BufferQueueStream : public rtc::StreamInterface { class BufferQueueStream : public rtc::StreamInterface {
public: public:
BufferQueueStream(size_t capacity, size_t default_size) BufferQueueStream(size_t capacity, size_t default_size)
@ -304,15 +354,6 @@ class BufferQueueStream : public rtc::StreamInterface {
rtc::BufferQueue buffer_; rtc::BufferQueue buffer_;
}; };
class SSLDummyStreamDTLS : public SSLDummyStreamBase {
public:
SSLDummyStreamDTLS(SSLStreamAdapterTestBase* test,
absl::string_view side,
BufferQueueStream* in,
BufferQueueStream* out)
: SSLDummyStreamBase(test, side, in, out) {}
};
static const int kFifoBufferSize = 4096; static const int kFifoBufferSize = 4096;
static const int kBufferCapacity = 1; static const int kBufferCapacity = 1;
static const size_t kDefaultBufferSize = 2048; static const size_t kDefaultBufferSize = 2048;
@ -391,11 +432,10 @@ class SSLStreamAdapterTestBase : public ::testing::Test,
: new ScopedFieldTrials(server_experiment)); : new ScopedFieldTrials(server_experiment));
server_ssl_ = rtc::SSLStreamAdapter::Create(CreateServerStream()); server_ssl_ = rtc::SSLStreamAdapter::Create(CreateServerStream());
} }
client_ssl_->SetEventCallback(
client_ssl_->SignalEvent.connect(this, [this](int events, int err) { OnClientEvent(events, err); });
&SSLStreamAdapterTestBase::OnClientEvent); server_ssl_->SetEventCallback(
server_ssl_->SignalEvent.connect(this, [this](int events, int err) { OnServerEvent(events, err); });
&SSLStreamAdapterTestBase::OnServerEvent);
} }
// Recreate the client/server identities with the specified validity period. // Recreate the client/server identities with the specified validity period.
@ -648,7 +688,7 @@ class SSLStreamAdapterTestBase : public ::testing::Test,
} }
} }
rtc::StreamResult DataWritten(SSLDummyStreamBase* from, rtc::StreamResult DataWritten(SSLDummyStream* from,
const void* data, const void* data,
size_t data_len, size_t data_len,
size_t& written, size_t& written,
@ -756,13 +796,12 @@ class SSLStreamAdapterTestBase : public ::testing::Test,
virtual void TestTransfer(int size) = 0; virtual void TestTransfer(int size) = 0;
private: private:
void OnClientEvent(rtc::StreamInterface* stream, int sig, int err) { void OnClientEvent(int sig, int err) {
RTC_DCHECK_EQ(stream, client_ssl_.get());
RTC_LOG(LS_VERBOSE) << "SSLStreamAdapterTestBase::OnClientEvent sig=" RTC_LOG(LS_VERBOSE) << "SSLStreamAdapterTestBase::OnClientEvent sig="
<< sig; << sig;
if (sig & rtc::SE_READ) { if (sig & rtc::SE_READ) {
ReadData(stream); ReadData(client_ssl_.get());
} }
if (sig & rtc::SE_WRITE) { if (sig & rtc::SE_WRITE) {
@ -770,12 +809,11 @@ class SSLStreamAdapterTestBase : public ::testing::Test,
} }
} }
void OnServerEvent(rtc::StreamInterface* stream, int sig, int err) { void OnServerEvent(int sig, int err) {
RTC_DCHECK_EQ(stream, server_ssl_.get());
RTC_LOG(LS_VERBOSE) << "SSLStreamAdapterTestBase::OnServerEvent sig=" RTC_LOG(LS_VERBOSE) << "SSLStreamAdapterTestBase::OnServerEvent sig="
<< sig; << sig;
if (sig & rtc::SE_READ) { if (sig & rtc::SE_READ) {
ReadData(stream); ReadData(server_ssl_.get());
} }
} }
@ -819,18 +857,16 @@ class SSLStreamAdapterTestTLS
"", "",
false, false,
::testing::get<0>(GetParam()), ::testing::get<0>(GetParam()),
::testing::get<1>(GetParam())), ::testing::get<1>(GetParam())) {}
client_buffer_(kFifoBufferSize),
server_buffer_(kFifoBufferSize) {}
std::unique_ptr<rtc::StreamInterface> CreateClientStream() override final { std::unique_ptr<rtc::StreamInterface> CreateClientStream() override final {
return absl::WrapUnique( return absl::WrapUnique(
new SSLDummyStreamTLS(this, "c2s", &client_buffer_, &server_buffer_)); new SSLDummyStream(this, "c2s", &client_buffer_, &server_buffer_));
} }
std::unique_ptr<rtc::StreamInterface> CreateServerStream() override final { std::unique_ptr<rtc::StreamInterface> CreateServerStream() override final {
return absl::WrapUnique( return absl::WrapUnique(
new SSLDummyStreamTLS(this, "s2c", &server_buffer_, &client_buffer_)); new SSLDummyStream(this, "s2c", &server_buffer_, &client_buffer_));
} }
// Test data transfer for TLS // Test data transfer for TLS
@ -930,8 +966,10 @@ class SSLStreamAdapterTestTLS
} }
private: private:
rtc::FifoBuffer client_buffer_; StreamWrapper client_buffer_{
rtc::FifoBuffer server_buffer_; std::make_unique<rtc::FifoBuffer>(kFifoBufferSize)};
StreamWrapper server_buffer_{
std::make_unique<rtc::FifoBuffer>(kFifoBufferSize)};
rtc::MemoryStream send_stream_; rtc::MemoryStream send_stream_;
rtc::MemoryStream recv_stream_; rtc::MemoryStream recv_stream_;
}; };
@ -940,8 +978,6 @@ class SSLStreamAdapterTestDTLSBase : public SSLStreamAdapterTestBase {
public: public:
SSLStreamAdapterTestDTLSBase(rtc::KeyParams param1, rtc::KeyParams param2) SSLStreamAdapterTestDTLSBase(rtc::KeyParams param1, rtc::KeyParams param2)
: SSLStreamAdapterTestBase("", "", true, param1, param2), : SSLStreamAdapterTestBase("", "", true, param1, param2),
client_buffer_(kBufferCapacity, kDefaultBufferSize),
server_buffer_(kBufferCapacity, kDefaultBufferSize),
packet_size_(1000), packet_size_(1000),
count_(0), count_(0),
sent_(0) {} sent_(0) {}
@ -949,20 +985,18 @@ class SSLStreamAdapterTestDTLSBase : public SSLStreamAdapterTestBase {
SSLStreamAdapterTestDTLSBase(absl::string_view cert_pem, SSLStreamAdapterTestDTLSBase(absl::string_view cert_pem,
absl::string_view private_key_pem) absl::string_view private_key_pem)
: SSLStreamAdapterTestBase(cert_pem, private_key_pem, true), : SSLStreamAdapterTestBase(cert_pem, private_key_pem, true),
client_buffer_(kBufferCapacity, kDefaultBufferSize),
server_buffer_(kBufferCapacity, kDefaultBufferSize),
packet_size_(1000), packet_size_(1000),
count_(0), count_(0),
sent_(0) {} sent_(0) {}
std::unique_ptr<rtc::StreamInterface> CreateClientStream() override final { std::unique_ptr<rtc::StreamInterface> CreateClientStream() override final {
return absl::WrapUnique( return absl::WrapUnique(
new SSLDummyStreamDTLS(this, "c2s", &client_buffer_, &server_buffer_)); new SSLDummyStream(this, "c2s", &client_buffer_, &server_buffer_));
} }
std::unique_ptr<rtc::StreamInterface> CreateServerStream() override final { std::unique_ptr<rtc::StreamInterface> CreateServerStream() override final {
return absl::WrapUnique( return absl::WrapUnique(
new SSLDummyStreamDTLS(this, "s2c", &server_buffer_, &client_buffer_)); new SSLDummyStream(this, "s2c", &server_buffer_, &client_buffer_));
} }
void WriteData() override { void WriteData() override {
@ -1052,8 +1086,10 @@ class SSLStreamAdapterTestDTLSBase : public SSLStreamAdapterTestBase {
} }
protected: protected:
BufferQueueStream client_buffer_; StreamWrapper client_buffer_{
BufferQueueStream server_buffer_; std::make_unique<BufferQueueStream>(kBufferCapacity, kDefaultBufferSize)};
StreamWrapper server_buffer_{
std::make_unique<BufferQueueStream>(kBufferCapacity, kDefaultBufferSize)};
private: private:
size_t packet_size_; size_t packet_size_;
@ -1075,7 +1111,7 @@ class SSLStreamAdapterTestDTLS
: SSLStreamAdapterTestDTLSBase(cert_pem, private_key_pem) {} : SSLStreamAdapterTestDTLSBase(cert_pem, private_key_pem) {}
}; };
rtc::StreamResult SSLDummyStreamBase::Write(rtc::ArrayView<const uint8_t> data, rtc::StreamResult SSLDummyStream::Write(rtc::ArrayView<const uint8_t> data,
size_t& written, size_t& written,
int& error) { int& error) {
RTC_LOG(LS_VERBOSE) << "Writing to loopback " << data.size(); RTC_LOG(LS_VERBOSE) << "Writing to loopback " << data.size();

41
third_party/libwebrtc/rtc_base/stream.h поставляемый
Просмотреть файл

@ -13,9 +13,11 @@
#include <memory> #include <memory>
#include "absl/functional/any_invocable.h"
#include "api/array_view.h" #include "api/array_view.h"
#include "api/sequence_checker.h" #include "api/sequence_checker.h"
#include "rtc_base/buffer.h" #include "rtc_base/buffer.h"
#include "rtc_base/logging.h"
#include "rtc_base/system/no_unique_address.h" #include "rtc_base/system/no_unique_address.h"
#include "rtc_base/system/rtc_export.h" #include "rtc_base/system/rtc_export.h"
#include "rtc_base/third_party/sigslot/sigslot.h" #include "rtc_base/third_party/sigslot/sigslot.h"
@ -83,15 +85,24 @@ class RTC_EXPORT StreamInterface {
// signalled as a result of this call. // signalled as a result of this call.
virtual void Close() = 0; virtual void Close() = 0;
// Streams may signal one or more StreamEvents to indicate state changes. // Streams may issue one or more events to indicate state changes to a
// The first argument identifies the stream on which the state change occured. // provided callback.
// The second argument is a bit-wise combination of StreamEvents. // The first argument is a bit-wise combination of `StreamEvent` flags.
// If SE_CLOSE is signalled, then the third argument is the associated error // If SE_CLOSE is set, then the second argument is the associated error code.
// code. Otherwise, the value is undefined. // Otherwise, the value of the second parameter is undefined and should be
// Note: Not all streams will support asynchronous event signalling. However, // set to 0.
// SS_OPENING and SR_BLOCK returned from stream member functions imply that // Note: Not all streams support callbacks. However, SS_OPENING and
// certain events will be raised in the future. // SR_BLOCK returned from member functions imply that certain callbacks will
sigslot::signal3<StreamInterface*, int, int> SignalEvent; // be made in the future.
void SetEventCallback(absl::AnyInvocable<void(int, int)> callback) {
RTC_DCHECK_RUN_ON(&callback_sequence_);
RTC_DCHECK(!callback_ || !callback);
callback_ = std::move(callback);
}
// TODO(bugs.webrtc.org/11943): Remove after updating downstream code.
sigslot::signal3<StreamInterface*, int, int> SignalEvent
[[deprecated("Use SetEventCallback instead")]];
// Return true if flush is successful. // Return true if flush is successful.
virtual bool Flush(); virtual bool Flush();
@ -126,13 +137,23 @@ class RTC_EXPORT StreamInterface {
// Utility function for derived classes. // Utility function for derived classes.
void FireEvent(int stream_events, int err) RTC_RUN_ON(&callback_sequence_) { void FireEvent(int stream_events, int err) RTC_RUN_ON(&callback_sequence_) {
if (callback_) {
callback_(stream_events, err);
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// TODO(tommi): This is for backwards compatibility only while `SignalEvent` // TODO(tommi): This is for backwards compatibility only while `SignalEvent`
// is being replaced by `SetEventHandler`. // is being replaced by `SetEventCallback`.
SignalEvent(this, stream_events, err); SignalEvent(this, stream_events, err);
#pragma clang diagnostic pop
} }
RTC_NO_UNIQUE_ADDRESS webrtc::SequenceChecker callback_sequence_{ RTC_NO_UNIQUE_ADDRESS webrtc::SequenceChecker callback_sequence_{
webrtc::SequenceChecker::kDetached}; webrtc::SequenceChecker::kDetached};
private:
absl::AnyInvocable<void(int, int)> callback_
RTC_GUARDED_BY(&callback_sequence_) = nullptr;
}; };
} // namespace rtc } // namespace rtc