Let EmulatedNetworkManagerInterface own and expose a PacketSocketFactory
So that applications don't need to construct it from the exposed network_thread. The EmulatedNetworkManagerInterface::network_thread() accessor is currently used as a way to get to emulation's SocketServer, and should be deleted when applications of the emulation framework have migrated away from that usage. Bug: webrtc:13145 Change-Id: I3efa55d117cad8ac601c48a9d2d2aa62a121f9c9 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/231649 Reviewed-by: Artem Titov <titovartem@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/main@{#34964}
This commit is contained in:

committed by
WebRTC LUCI CQ

parent
824eebab8b
commit
5e7a3aedf1
@ -623,6 +623,7 @@ rtc_source_set("network_emulation_manager_api") {
|
|||||||
]
|
]
|
||||||
deps = [
|
deps = [
|
||||||
":array_view",
|
":array_view",
|
||||||
|
":packet_socket_factory",
|
||||||
":simulated_network_api",
|
":simulated_network_api",
|
||||||
":time_controller",
|
":time_controller",
|
||||||
"../call:simulated_network",
|
"../call:simulated_network",
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "api/array_view.h"
|
#include "api/array_view.h"
|
||||||
|
#include "api/packet_socket_factory.h"
|
||||||
#include "api/test/network_emulation/cross_traffic.h"
|
#include "api/test/network_emulation/cross_traffic.h"
|
||||||
#include "api/test/network_emulation/network_emulation_interfaces.h"
|
#include "api/test/network_emulation/network_emulation_interfaces.h"
|
||||||
#include "api/test/simulated_network.h"
|
#include "api/test/simulated_network.h"
|
||||||
@ -125,6 +126,10 @@ class EmulatedNetworkManagerInterface {
|
|||||||
// WebRTC to properly setup network emulation. Returned manager is owned by
|
// WebRTC to properly setup network emulation. Returned manager is owned by
|
||||||
// EmulatedNetworkManagerInterface implementation.
|
// EmulatedNetworkManagerInterface implementation.
|
||||||
virtual rtc::NetworkManager* network_manager() = 0;
|
virtual rtc::NetworkManager* network_manager() = 0;
|
||||||
|
// Returns non-null pointer to packet socket factory that have to be injected
|
||||||
|
// into WebRTC to properly setup network emulation. Returned factory is owned
|
||||||
|
// by EmulatedNetworkManagerInterface implementation.
|
||||||
|
virtual rtc::PacketSocketFactory* packet_socket_factory() = 0;
|
||||||
// Returns list of endpoints that are associated with this instance. Pointers
|
// Returns list of endpoints that are associated with this instance. Pointers
|
||||||
// are guaranteed to be non-null and are owned by NetworkEmulationManager.
|
// are guaranteed to be non-null and are owned by NetworkEmulationManager.
|
||||||
virtual std::vector<EmulatedEndpoint*> endpoints() const = 0;
|
virtual std::vector<EmulatedEndpoint*> endpoints() const = 0;
|
||||||
|
@ -18,6 +18,7 @@ include_rules = [
|
|||||||
"+modules/utility",
|
"+modules/utility",
|
||||||
"+modules/video_capture",
|
"+modules/video_capture",
|
||||||
"+modules/video_coding",
|
"+modules/video_coding",
|
||||||
|
"+p2p/base/basic_packet_socket_factory.h",
|
||||||
"+sdk",
|
"+sdk",
|
||||||
"+system_wrappers",
|
"+system_wrappers",
|
||||||
"+third_party/libyuv",
|
"+third_party/libyuv",
|
||||||
|
@ -54,6 +54,7 @@ rtc_library("emulated_network") {
|
|||||||
"../../api/units:timestamp",
|
"../../api/units:timestamp",
|
||||||
"../../call:simulated_network",
|
"../../call:simulated_network",
|
||||||
"../../p2p:p2p_server_utils",
|
"../../p2p:p2p_server_utils",
|
||||||
|
"../../p2p:rtc_p2p",
|
||||||
"../../rtc_base",
|
"../../rtc_base",
|
||||||
"../../rtc_base:ip_address",
|
"../../rtc_base:ip_address",
|
||||||
"../../rtc_base:network_constants",
|
"../../rtc_base:network_constants",
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "absl/memory/memory.h"
|
#include "absl/memory/memory.h"
|
||||||
|
#include "p2p/base/basic_packet_socket_factory.h"
|
||||||
#include "test/network/fake_network_socket_server.h"
|
#include "test/network/fake_network_socket_server.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
@ -25,11 +26,17 @@ EmulatedNetworkManager::EmulatedNetworkManager(
|
|||||||
EndpointsContainer* endpoints_container)
|
EndpointsContainer* endpoints_container)
|
||||||
: task_queue_(task_queue),
|
: task_queue_(task_queue),
|
||||||
endpoints_container_(endpoints_container),
|
endpoints_container_(endpoints_container),
|
||||||
network_thread_(time_controller->CreateThread(
|
|
||||||
"net_thread",
|
|
||||||
std::make_unique<FakeNetworkSocketServer>(endpoints_container))),
|
|
||||||
sent_first_update_(false),
|
sent_first_update_(false),
|
||||||
start_count_(0) {}
|
start_count_(0) {
|
||||||
|
auto socket_server =
|
||||||
|
std::make_unique<FakeNetworkSocketServer>(endpoints_container);
|
||||||
|
packet_socket_factory_ =
|
||||||
|
std::make_unique<rtc::BasicPacketSocketFactory>(socket_server.get());
|
||||||
|
// Since we pass ownership of the socket server to `network_thread_`, we must
|
||||||
|
// arrange that it outlives `packet_socket_factory_` which refers to it.
|
||||||
|
network_thread_ =
|
||||||
|
time_controller->CreateThread("net_thread", std::move(socket_server));
|
||||||
|
}
|
||||||
|
|
||||||
void EmulatedNetworkManager::EnableEndpoint(EmulatedEndpointImpl* endpoint) {
|
void EmulatedNetworkManager::EnableEndpoint(EmulatedEndpointImpl* endpoint) {
|
||||||
RTC_CHECK(endpoints_container_->HasEndpoint(endpoint))
|
RTC_CHECK(endpoints_container_->HasEndpoint(endpoint))
|
||||||
|
@ -50,6 +50,9 @@ class EmulatedNetworkManager : public rtc::NetworkManagerBase,
|
|||||||
// EmulatedNetworkManagerInterface API
|
// EmulatedNetworkManagerInterface API
|
||||||
rtc::Thread* network_thread() override { return network_thread_.get(); }
|
rtc::Thread* network_thread() override { return network_thread_.get(); }
|
||||||
rtc::NetworkManager* network_manager() override { return this; }
|
rtc::NetworkManager* network_manager() override { return this; }
|
||||||
|
rtc::PacketSocketFactory* packet_socket_factory() override {
|
||||||
|
return packet_socket_factory_.get();
|
||||||
|
}
|
||||||
std::vector<EmulatedEndpoint*> endpoints() const override {
|
std::vector<EmulatedEndpoint*> endpoints() const override {
|
||||||
return endpoints_container_->GetEndpoints();
|
return endpoints_container_->GetEndpoints();
|
||||||
}
|
}
|
||||||
@ -62,8 +65,12 @@ class EmulatedNetworkManager : public rtc::NetworkManagerBase,
|
|||||||
|
|
||||||
TaskQueueForTest* const task_queue_;
|
TaskQueueForTest* const task_queue_;
|
||||||
const EndpointsContainer* const endpoints_container_;
|
const EndpointsContainer* const endpoints_container_;
|
||||||
|
// The `network_thread_` must outlive `packet_socket_factory_`, because they
|
||||||
|
// both refer to a socket server that is owned by `network_thread_`. Both
|
||||||
|
// pointers are assigned only in the constructor, but the way they are
|
||||||
|
// initialized unfortunately doesn't work with const std::unique_ptr<...>.
|
||||||
std::unique_ptr<rtc::Thread> network_thread_;
|
std::unique_ptr<rtc::Thread> network_thread_;
|
||||||
|
std::unique_ptr<rtc::PacketSocketFactory> packet_socket_factory_;
|
||||||
bool sent_first_update_ RTC_GUARDED_BY(network_thread_);
|
bool sent_first_update_ RTC_GUARDED_BY(network_thread_);
|
||||||
int start_count_ RTC_GUARDED_BY(network_thread_);
|
int start_count_ RTC_GUARDED_BY(network_thread_);
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user