Create separate WebRtc Platform.

PiperOrigin-RevId: 919283950
This commit is contained in:
Francis Tsui
2026-05-21 15:26:28 -07:00
committed by Copybara-Service
parent 765bd555e4
commit 5df1af7c61
14 changed files with 69 additions and 65 deletions
@@ -93,8 +93,7 @@ cc_library(
hdrs = ["webrtc.h"],
deps = [
"//internal/platform:base",
"//internal/platform/implementation:comm",
"//internal/platform/implementation:platform",
"//internal/platform/implementation:webrtc_platform",
# "//third_party/webrtc/files/stable/webrtc/api:libjingle_peerconnection_api",
"//third_party/webrtc/files/stable/webrtc/rtc_base:network_constants",
"@com_google_absl//absl/strings:string_view",
@@ -23,8 +23,8 @@
#include "absl/strings/string_view.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/feature_flags.h"
#include "internal/platform/implementation/platform.h"
#include "internal/platform/implementation/webrtc.h"
#include "internal/platform/implementation/webrtc_platform.h"
#include "webrtc/api/peer_connection_interface.h"
#include "webrtc/rtc_base/network_constants.h"
@@ -66,7 +66,8 @@ class WebRtcSignalingMessenger {
class WebRtcMedium {
public:
WebRtcMedium() : impl_(api::ImplementationPlatform::CreateWebRtcMedium()) {}
WebRtcMedium()
: impl_(api::WebRtcImplementationPlatform::CreateWebRtcMedium()) {}
virtual ~WebRtcMedium() = default;
WebRtcMedium(WebRtcMedium&&) = default;
WebRtcMedium& operator=(WebRtcMedium&&) = delete;
@@ -75,9 +76,7 @@ class WebRtcMedium {
// For example, en_US locale resolves to "US".
std::string GetDefaultCountryCode() { return impl_->GetDefaultCountryCode(); }
void SetNonCellular(bool non_cellular) {
non_cellular_ = non_cellular;
}
void SetNonCellular(bool non_cellular) { non_cellular_ = non_cellular; }
// Creates and returns a new webrtc::PeerConnectionInterface object via
// |callback|.
@@ -86,7 +85,8 @@ class WebRtcMedium {
api::WebRtcMedium::PeerConnectionCallback callback) {
if (FeatureFlags::GetInstance()
.GetFlags()
.support_web_rtc_non_cellular_medium && non_cellular_) {
.support_web_rtc_non_cellular_medium &&
non_cellular_) {
std::optional<webrtc::PeerConnectionFactoryInterface::Options> options;
options->network_ignore_mask |= webrtc::ADAPTER_TYPE_CELLULAR;
impl_->CreatePeerConnection(options, observer, std::move(callback));
+2 -1
View File
@@ -299,7 +299,7 @@ cc_library(
":logging",
":types",
"//internal/account",
"//internal/platform/implementation:comm",
"//internal/platform/implementation:webrtc_platform",
"//internal/proto:messaging_cc_grpc_proto",
"//internal/proto:tachyon_cc_proto",
"//internal/rpc:utils",
@@ -411,6 +411,7 @@ cc_library(
":uuid",
"//internal/base",
"//internal/platform/implementation:comm",
"//internal/platform/implementation:webrtc_platform",
"//internal/platform/implementation:wifi_utils",
"//internal/test",
"@com_google_absl//absl/base:core_headers",
+1 -5
View File
@@ -90,6 +90,7 @@ cc_library(
cc_library(
name = "webrtc_platform",
hdrs = [
"webrtc.h",
"webrtc_platform.h",
],
compatible_with = ["//buildenv/target:non_prod"],
@@ -97,7 +98,6 @@ cc_library(
"//:__subpackages__",
],
deps = [
":comm",
"//connections/implementation/proto:offline_wire_formats_cc_proto",
"//internal/platform:base",
# "//third_party/webrtc/files/stable/webrtc/api:libjingle_peerconnection_api",
@@ -120,7 +120,6 @@ cc_library(
"http_loader.h",
"psk_info.h",
"upgrade_address_info.h",
"webrtc.h",
"wifi.h",
"wifi_direct.h",
"wifi_hotspot.h",
@@ -136,15 +135,12 @@ cc_library(
"//third_party/nearby/presence/implementation:__subpackages__",
],
deps = [
"//connections/implementation/proto:offline_wire_formats_cc_proto",
"//internal/platform:base",
"//internal/platform:cancellation_flag",
"//internal/platform:mac_address",
"//internal/platform:uuid",
"//internal/proto:credential_cc_proto",
"//internal/proto:local_credential_cc_proto",
# "//third_party/webrtc/files/stable/webrtc/api:create_peerconnection_factory", # buildcleaner: keep
# "//third_party/webrtc/files/stable/webrtc/api:peer_connection_interface",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/functional:any_invocable",
+14 -7
View File
@@ -54,11 +54,24 @@ objc_library(
objc_library(
name = "apple_webrtc",
srcs = [
"webrtc.mm",
"webrtc_platform.mm",
],
hdrs = [
"webrtc.h",
],
deps = [
":apple",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings",
"//third_party/apple_frameworks:Foundation",
"//internal/platform:logging",
"//internal/platform:tachyon_express_signaling_messenger",
"//internal/platform:types",
"//internal/platform/implementation:webrtc_platform",
"//internal/proto:tachyon_cc_proto",
# "//third_party/webrtc/files/stable/webrtc/api:create_modular_peer_connection_factory",
# "//third_party/webrtc/files/stable/webrtc/api:peer_connection_interface",
"//third_party/webrtc/files/stable/webrtc/api/task_queue:default_task_queue_factory",
],
)
@@ -72,7 +85,6 @@ objc_library(
"preferences_manager.mm",
"scheduled_executor.mm",
"timer.mm",
"webrtc.mm",
"wifi_hotspot.mm",
"wifi_lan.mm",
],
@@ -81,7 +93,6 @@ objc_library(
"device_info.h",
"preferences_manager.h",
"timer.h",
"webrtc.h",
"wifi.h",
"wifi_hotspot.h",
"wifi_lan.h",
@@ -122,10 +133,6 @@ objc_library(
"//internal/platform:tachyon_express_signaling_messenger",
"//internal/platform:types",
"//internal/proto:tachyon_cc_proto",
"//third_party/webrtc/files/stable/webrtc/api/task_queue:default_task_queue_factory",
# "//third_party/webrtc/files/stable/webrtc/api:create_modular_peer_connection_factory",
# "//third_party/webrtc/files/stable/webrtc/api:peer_connection_interface",
"//third_party/webrtc/files/stable/webrtc/rtc_base:checks",
"//internal/platform:base",
"//internal/platform/implementation:comm",
"//internal/platform/implementation:platform",
+5 -1
View File
@@ -112,6 +112,7 @@ cc_library(
"//internal/platform:types",
"//internal/platform:uuid",
"//internal/platform/implementation:comm",
"//internal/platform/implementation:webrtc_platform",
"//internal/platform/implementation:wifi_utils",
"//internal/proto:credential_cc_proto",
# "//third_party/webrtc/files/stable/webrtc/api:create_modular_peer_connection_factory",
@@ -177,6 +178,7 @@ cc_library(
testonly = True,
srcs = [
"platform.cc",
"webrtc_platform.cc",
],
defines = ["NO_WEBRTC"],
visibility = [
@@ -208,14 +210,16 @@ cc_library(
"//internal/platform/implementation:comm",
"//internal/platform/implementation:platform",
"//internal/platform/implementation:types",
"//internal/platform/implementation:webrtc_platform",
"//internal/platform/implementation/shared:count_down_latch",
"//internal/platform/implementation/shared:file",
"//third_party/gloop/thread",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_nisaba//nisaba/port:thread_pool",
],
alwayslink = 1,
)
cc_library(
@@ -14,7 +14,6 @@
#include "internal/platform/implementation/platform.h"
#include <cstddef>
#include <cstdint>
#include <functional>
#include <memory>
@@ -25,6 +24,7 @@
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "third_party/gloop/thread/thread.h"
#include "internal/base/file_path.h"
#include "internal/base/files.h"
#include "internal/platform/implementation/app_lifecycle_monitor.h"
@@ -55,11 +55,6 @@
#include "internal/platform/logging.h"
#include "internal/platform/os_name.h"
#include "internal/platform/payload_id.h"
#include "thread/thread.h"
#ifndef NO_WEBRTC
#include "internal/platform/implementation/g3/webrtc.h"
#include "internal/platform/implementation/webrtc.h"
#endif
#include "internal/platform/implementation/g3/atomic_boolean.h"
#include "internal/platform/implementation/g3/atomic_reference.h"
#include "internal/platform/implementation/g3/ble.h"
@@ -80,7 +75,6 @@
#include "internal/platform/implementation/g3/wifi_lan.h"
#include "internal/platform/implementation/shared/file.h"
#include "internal/platform/implementation/wifi.h"
#include "internal/platform/medium_environment.h"
namespace nearby {
namespace api {
@@ -219,16 +213,6 @@ ImplementationPlatform::CreateWifiDirectMedium() {
return std::make_unique<g3::WifiDirectMedium>();
}
#ifndef NO_WEBRTC
std::unique_ptr<WebRtcMedium> ImplementationPlatform::CreateWebRtcMedium() {
if (MediumEnvironment::Instance().GetEnvironmentConfig().webrtc_enabled) {
return std::make_unique<g3::WebRtcMedium>();
} else {
return nullptr;
}
}
#endif
std::unique_ptr<AppLifecycleMonitor>
ImplementationPlatform::CreateAppLifecycleMonitor(
std::function<void(AppLifecycleMonitor::AppLifecycleState)>
@@ -0,0 +1,34 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "internal/platform/implementation/webrtc_platform.h"
#include <memory>
#include "internal/platform/implementation/g3/webrtc.h"
#include "internal/platform/implementation/webrtc.h"
#include "internal/platform/medium_environment.h"
namespace nearby::api {
std::unique_ptr<WebRtcMedium>
WebRtcImplementationPlatform::CreateWebRtcMedium() {
if (MediumEnvironment::Instance().GetEnvironmentConfig().webrtc_enabled) {
return std::make_unique<g3::WebRtcMedium>();
} else {
return nullptr;
}
}
} // namespace nearby::api
@@ -43,9 +43,6 @@
#include "internal/platform/implementation/scheduled_executor.h"
#include "internal/platform/implementation/submittable_executor.h"
#include "internal/platform/implementation/timer.h"
#ifndef NO_WEBRTC
#include "internal/platform/implementation/webrtc.h"
#endif
#include "internal/platform/implementation/wifi.h"
#include "internal/platform/implementation/wifi_direct.h"
#include "internal/platform/implementation/wifi_hotspot.h"
@@ -134,9 +131,6 @@ class ImplementationPlatform {
static std::unique_ptr<WifiHotspotMedium> CreateWifiHotspotMedium();
static std::unique_ptr<WifiDirectMedium> CreateWifiDirectMedium();
static std::unique_ptr<Timer> CreateTimer();
#ifndef NO_WEBRTC
static std::unique_ptr<WebRtcMedium> CreateWebRtcMedium();
#endif
#if defined(NEARBY_CHROMIUM)
static std::unique_ptr<AppLifecycleMonitor> CreateAppLifecycleMonitor(
+1 -4
View File
@@ -15,8 +15,6 @@
#ifndef PLATFORM_API_WEBRTC_H_
#define PLATFORM_API_WEBRTC_H_
#ifndef NO_WEBRTC
#include <memory>
#include <optional>
#include <string>
@@ -26,6 +24,7 @@
#include "connections/implementation/proto/offline_wire_formats.pb.h"
#include "internal/platform/byte_array.h"
#include "webrtc/api/peer_connection_interface.h"
#include "webrtc/api/scoped_refptr.h"
namespace nearby {
namespace api {
@@ -78,6 +77,4 @@ class WebRtcMedium {
} // namespace api
} // namespace nearby
#endif
#endif // PLATFORM_API_WEBRTC_H_
@@ -321,6 +321,9 @@ cc_library(
"-DNO_INTEL_PIE",
"-D_WIN32_WINNT=_WIN32_WINNT_WIN10 -DWINVER=_WIN32_WINNT_WIN10",
],
linkopts = [
"iphlpapi.lib",
],
tags = ["windows"],
visibility = [
"//chrome/chromeos/assistant/data_migration/lib:__pkg__",
@@ -259,10 +259,6 @@ ImplementationPlatform::CreateWifiDirectMedium() {
return std::make_unique<windows::WifiDirectMedium>();
}
std::unique_ptr<WebRtcMedium> ImplementationPlatform::CreateWebRtcMedium() {
return nullptr;
}
std::unique_ptr<AppLifecycleMonitor>
ImplementationPlatform::CreateAppLifecycleMonitor(
std::function<void(AppLifecycleMonitor::AppLifecycleState)>
+1 -4
View File
@@ -103,10 +103,8 @@ void MediumEnvironment::Reset() {
bluetooth_adapters_.clear();
bluetooth_mediums_.clear();
ble_mediums_.clear();
#ifndef NO_WEBRTC
webrtc_signaling_message_callback_.clear();
webrtc_signaling_complete_callback_.clear();
#endif
wifi_lan_mediums_.clear();
awdl_mediums_.clear();
{
@@ -675,7 +673,6 @@ MediumEnvironment::GetBleMediumStatus(const api::ble::BleMedium& medium) {
return result;
}
#ifndef NO_WEBRTC
void MediumEnvironment::RegisterWebRtcSignalingMessenger(
absl::string_view self_id, OnSignalingMessageCallback message_callback,
OnSignalingCompleteCallback complete_callback) {
@@ -733,7 +730,7 @@ void MediumEnvironment::SendWebRtcSignalingComplete(absl::string_view peer_id,
item->second(success);
});
}
#endif
void MediumEnvironment::SetUseValidPeerConnection(
bool use_valid_peer_connection) {
use_valid_peer_connection_ = use_valid_peer_connection;
-8
View File
@@ -37,9 +37,7 @@
#include "internal/platform/runnable.h"
#include "internal/platform/uuid.h"
#include "internal/test/fake_clock.h"
#ifndef NO_WEBRTC
#include "internal/platform/implementation/webrtc.h"
#endif
#include "internal/platform/byte_array.h"
#include "internal/platform/feature_flags.h"
#include "internal/platform/implementation/wifi_direct.h"
@@ -80,12 +78,10 @@ class MediumEnvironment {
using BluetoothDiscoveryCallback =
api::BluetoothClassicMedium::DiscoveryCallback;
using BleScanCallback = api::ble::BleMedium::ScanningCallback;
#ifndef NO_WEBRTC
using OnSignalingMessageCallback =
api::WebRtcSignalingMessenger::OnSignalingMessageCallback;
using OnSignalingCompleteCallback =
api::WebRtcSignalingMessenger::OnSignalingCompleteCallback;
#endif
using WifiLanDiscoveredServiceCallback =
api::WifiLanMedium::DiscoveredServiceCallback;
using AwdlDiscoveredServiceCallback =
@@ -164,7 +160,6 @@ class MediumEnvironment {
api::BluetoothDevice* FindBluetoothDevice(MacAddress mac_address);
EnvironmentConfig GetEnvironmentConfig();
#ifndef NO_WEBRTC
// Registers |message_callback| to receive messages sent to device with id
// |self_id|, and |complete_callback| to notify when signaling is complete.
void RegisterWebRtcSignalingMessenger(
@@ -181,7 +176,6 @@ class MediumEnvironment {
// Simulates sending an "signaling complete" signal to the WebRTC medium.
void SendWebRtcSignalingComplete(absl::string_view peer_id, bool success);
#endif
// Used to set if WebRtcMedium should use a valid peer connection or nullptr
// in tests.
void SetUseValidPeerConnection(bool use_valid_peer_connection);
@@ -497,7 +491,6 @@ class MediumEnvironment {
absl::flat_hash_map<api::ble::BleMedium*, BleMediumContext> ble_mediums_;
absl::flat_hash_map<api::BluetoothDevice*, BluetoothPairingContext>
devices_pairing_contexts_;
#ifndef NO_WEBRTC
// Maps peer id to callback for receiving signaling messages.
absl::flat_hash_map<std::string, OnSignalingMessageCallback>
webrtc_signaling_message_callback_;
@@ -505,7 +498,6 @@ class MediumEnvironment {
// Maps peer id to callback for signaling complete events.
absl::flat_hash_map<std::string, OnSignalingCompleteCallback>
webrtc_signaling_complete_callback_;
#endif
absl::flat_hash_map<api::WifiLanMedium*, WifiLanMediumContext>
wifi_lan_mediums_;