Update WebRTC IceCandidate type usage.

Replaces `webrtc::IceCandidateInterface` with `webrtc::IceCandidate` due to a change in the WebRTC API.

PiperOrigin-RevId: 798263016
This commit is contained in:
hai007
2025-08-22 10:39:19 -07:00
committed by Copybara-Service
parent 9d06831a9c
commit 5f27145da5
10 changed files with 46 additions and 52 deletions
+3 -4
View File
@@ -612,8 +612,7 @@ void WebRtc::ReceiveAnswer(const WebrtcPeerId& remote_peer_id,
void WebRtc::ReceiveIceCandidates(
const WebrtcPeerId& remote_peer_id,
std::vector<std::unique_ptr<webrtc::IceCandidateInterface>>
ice_candidates) {
std::vector<std::unique_ptr<webrtc::IceCandidate>> ice_candidates) {
const auto& entry = connection_flows_.find(remote_peer_id.GetId());
if (entry == connection_flows_.end()) {
LOG(INFO) << "Unable to receive ice candidates. Failed to create a "
@@ -704,8 +703,8 @@ std::unique_ptr<ConnectionFlow> WebRtc::CreateConnectionFlow(
return ConnectionFlow::Create(
{.local_ice_candidate_found_cb =
{[this, service_id, remote_peer_id](
const webrtc::IceCandidateInterface* ice_candidate) {
{[this, service_id,
remote_peer_id](const webrtc::IceCandidate* ice_candidate) {
// Note: We need to encode the ice candidate here, before we jump
// off the thread. Otherwise, it gets destroyed and we can't read
// it later.
+2 -2
View File
@@ -195,8 +195,8 @@ class WebRtc {
// Runs on |single_thread_executor_|.
void ReceiveIceCandidates(
const WebrtcPeerId& remote_peer_id,
std::vector<std::unique_ptr<webrtc::IceCandidateInterface>>
ice_candidates) ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
std::vector<std::unique_ptr<webrtc::IceCandidate>> ice_candidates)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Runs on |single_thread_executor_|.
std::unique_ptr<ConnectionFlow> CreateConnectionFlow(
@@ -302,8 +302,7 @@ bool ConnectionFlow::OnAnswerReceived(SessionDescriptionWrapper answer) {
}
bool ConnectionFlow::OnRemoteIceCandidatesReceived(
std::vector<std::unique_ptr<webrtc::IceCandidateInterface>>
ice_candidates) {
std::vector<std::unique_ptr<webrtc::IceCandidate>> ice_candidates) {
CHECK(!IsRunningOnSignalingThread());
// We can't call RunOnSignalingThread because C++ wants to copy ice_candidates
// if we try. unique_ptr is not CopyConstructible and compilation fails.
@@ -325,8 +324,7 @@ bool ConnectionFlow::OnRemoteIceCandidatesReceived(
}
void ConnectionFlow::AddIceCandidatesOnSignalingThread(
std::vector<std::unique_ptr<webrtc::IceCandidateInterface>>
ice_candidates) {
std::vector<std::unique_ptr<webrtc::IceCandidate>> ice_candidates) {
CHECK(IsRunningOnSignalingThread());
if (state_ == State::kEnded) {
LOG(WARNING) << "You cannot add ice candidates to a disconnected session.";
@@ -436,8 +434,7 @@ void ConnectionFlow::CreateSocketFromDataChannel(
socket_wrapper_ = WebRtcSocketWrapper(std::move(socket));
}
void ConnectionFlow::OnIceCandidate(
const webrtc::IceCandidateInterface* candidate) {
void ConnectionFlow::OnIceCandidate(const webrtc::IceCandidate* candidate) {
CHECK(IsRunningOnSignalingThread());
local_ice_candidate_listener_.local_ice_candidate_found_cb(candidate);
}
@@ -128,15 +128,15 @@ class ConnectionFlow : public webrtc::PeerConnectionObserver {
// ice candidate to the peer connection if ready or cache it otherwise.
// Can be called on any thread but never called on signaling thread.
bool OnRemoteIceCandidatesReceived(
std::vector<std::unique_ptr<webrtc::IceCandidateInterface>>
ice_candidates) ABSL_LOCKS_EXCLUDED(mutex_);
std::vector<std::unique_ptr<webrtc::IceCandidate>> ice_candidates)
ABSL_LOCKS_EXCLUDED(mutex_);
// Close the peer connection and data channel if not connected.
// Can be called on any thread but never called on signaling thread.
bool CloseIfNotConnected() ABSL_LOCKS_EXCLUDED(mutex_);
// webrtc::PeerConnectionObserver:
// All methods called only on signaling thread.
void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override;
void OnIceCandidate(const webrtc::IceCandidate* candidate) override;
void OnSignalingChange(
webrtc::PeerConnectionInterface::SignalingState new_state) override;
void OnDataChannel(webrtc::scoped_refptr<webrtc::DataChannelInterface>
@@ -165,8 +165,7 @@ class ConnectionFlow : public webrtc::PeerConnectionObserver {
void CreateAnswerOnSignalingThread(
Future<SessionDescriptionWrapper> success_future);
void AddIceCandidatesOnSignalingThread(
std::vector<std::unique_ptr<webrtc::IceCandidateInterface>>
ice_candidates);
std::vector<std::unique_ptr<webrtc::IceCandidate>> ice_candidates);
// Invoked when the peer connection indicates that signaling is stable.
void OnSignalingStable() ABSL_LOCKS_EXCLUDED(mutex_);
@@ -225,7 +224,7 @@ class ConnectionFlow : public webrtc::PeerConnectionObserver {
// connecting.
WebRtcSocketWrapper socket_wrapper_;
std::vector<std::unique_ptr<webrtc::IceCandidateInterface>>
std::vector<std::unique_ptr<webrtc::IceCandidate>>
cached_remote_ice_candidates_;
// This pointer is only for DCHECK() assertions.
// It allows us to check if we are running on signaling thread even
@@ -47,8 +47,8 @@ class ConnectionFlowTest : public ::testing::Test {
~ConnectionFlowTest() override { MediumEnvironment::Instance().Stop(); }
};
std::unique_ptr<webrtc::IceCandidateInterface> CopyCandidate(
const webrtc::IceCandidateInterface* candidate) {
std::unique_ptr<webrtc::IceCandidate> CopyCandidate(
const webrtc::IceCandidate* candidate) {
return webrtc::CreateIceCandidate(candidate->sdp_mid(),
candidate->sdp_mline_index(),
candidate->candidate());
@@ -68,8 +68,8 @@ TEST_F(ConnectionFlowTest, SuccessfulOfferAnswerFlow) {
// Send Ice Candidates immediately when you retrieve them
offerer = ConnectionFlow::Create(
{.local_ice_candidate_found_cb =
[&answerer](const webrtc::IceCandidateInterface* candidate) {
std::vector<std::unique_ptr<webrtc::IceCandidateInterface>> vec;
[&answerer](const webrtc::IceCandidate* candidate) {
std::vector<std::unique_ptr<webrtc::IceCandidate>> vec;
vec.push_back(CopyCandidate(candidate));
// The callback might be alive while the objects in test are
// destroyed.
@@ -88,8 +88,8 @@ TEST_F(ConnectionFlowTest, SuccessfulOfferAnswerFlow) {
ASSERT_NE(offerer, nullptr);
answerer = ConnectionFlow::Create(
{.local_ice_candidate_found_cb =
[&offerer](const webrtc::IceCandidateInterface* candidate) {
std::vector<std::unique_ptr<webrtc::IceCandidateInterface>> vec;
[&offerer](const webrtc::IceCandidate* candidate) {
std::vector<std::unique_ptr<webrtc::IceCandidate>> vec;
vec.push_back(CopyCandidate(candidate));
// The callback might be alive while the objects in test are
// destroyed.
@@ -267,8 +267,8 @@ TEST_F(ConnectionFlowTest, TerminateAnswerer) {
// Send Ice Candidates immediately when you retrieve them
offerer = ConnectionFlow::Create(
{.local_ice_candidate_found_cb =
[&answerer](const webrtc::IceCandidateInterface* candidate) {
std::vector<std::unique_ptr<webrtc::IceCandidateInterface>> vec;
[&answerer](const webrtc::IceCandidate* candidate) {
std::vector<std::unique_ptr<webrtc::IceCandidate>> vec;
vec.push_back(CopyCandidate(candidate));
// The callback might be alive while the objects in test are
// destroyed.
@@ -287,8 +287,8 @@ TEST_F(ConnectionFlowTest, TerminateAnswerer) {
ASSERT_NE(offerer, nullptr);
answerer = ConnectionFlow::Create(
{.local_ice_candidate_found_cb =
[&offerer](const webrtc::IceCandidateInterface* candidate) {
std::vector<std::unique_ptr<webrtc::IceCandidateInterface>> vec;
[&offerer](const webrtc::IceCandidate* candidate) {
std::vector<std::unique_ptr<webrtc::IceCandidate>> vec;
vec.push_back(CopyCandidate(candidate));
// The callback might be alive while the objects in test are
// destroyed.
@@ -357,8 +357,8 @@ TEST_F(ConnectionFlowTest, TerminateOfferer) {
// Send Ice Candidates immediately when you retrieve them
offerer = ConnectionFlow::Create(
{.local_ice_candidate_found_cb =
[&answerer](const webrtc::IceCandidateInterface* candidate) {
std::vector<std::unique_ptr<webrtc::IceCandidateInterface>> vec;
[&answerer](const webrtc::IceCandidate* candidate) {
std::vector<std::unique_ptr<webrtc::IceCandidate>> vec;
vec.push_back(CopyCandidate(candidate));
// The callback might be alive while the objects in test are
// destroyed.
@@ -378,8 +378,8 @@ TEST_F(ConnectionFlowTest, TerminateOfferer) {
ASSERT_NE(offerer, nullptr);
answerer = ConnectionFlow::Create(
{.local_ice_candidate_found_cb =
[&offerer](const webrtc::IceCandidateInterface* candidate) {
std::vector<std::unique_ptr<webrtc::IceCandidateInterface>> vec;
[&offerer](const webrtc::IceCandidate* candidate) {
std::vector<std::unique_ptr<webrtc::IceCandidate>> vec;
vec.push_back(CopyCandidate(candidate));
// The callback might be alive while the objects in test are
// destroyed.
@@ -18,6 +18,7 @@
#ifndef NO_WEBRTC
#include "connections/listeners.h"
#include "webrtc/api/jsep.h"
#include "webrtc/api/peer_connection_interface.h"
namespace nearby {
@@ -27,9 +28,9 @@ namespace mediums {
// Callbacks from local ice candidate collection.
struct LocalIceCandidateListener {
// Called when a new local ice candidate has been found.
absl::AnyInvocable<void(const webrtc::IceCandidateInterface*)>
absl::AnyInvocable<void(const webrtc::IceCandidate*)>
local_ice_candidate_found_cb =
nearby::DefaultCallback<const webrtc::IceCandidateInterface*>();
nearby::DefaultCallback<const webrtc::IceCandidate*>();
};
} // namespace mediums
@@ -34,13 +34,12 @@ void SetSenderId(const WebrtcPeerId& sender_id, WebRtcSignalingFrame& frame) {
frame.mutable_sender_id()->set_id(sender_id.GetId());
}
std::unique_ptr<webrtc::IceCandidateInterface> DecodeIceCandidate(
std::unique_ptr<webrtc::IceCandidate> DecodeIceCandidate(
location::nearby::mediums::IceCandidate ice_candidate_proto) {
webrtc::SdpParseError error;
return std::unique_ptr<webrtc::IceCandidateInterface>(
webrtc::CreateIceCandidate(ice_candidate_proto.sdp_mid(),
ice_candidate_proto.sdp_m_line_index(),
ice_candidate_proto.sdp(), &error));
return std::unique_ptr<webrtc::IceCandidate>(webrtc::CreateIceCandidate(
ice_candidate_proto.sdp_mid(), ice_candidate_proto.sdp_m_line_index(),
ice_candidate_proto.sdp(), &error));
}
} // namespace
@@ -108,9 +107,9 @@ std::unique_ptr<webrtc::SessionDescriptionInterface> DecodeAnswer(
frame.answer().session_description().description());
}
std::vector<std::unique_ptr<webrtc::IceCandidateInterface>> DecodeIceCandidates(
std::vector<std::unique_ptr<webrtc::IceCandidate>> DecodeIceCandidates(
const WebRtcSignalingFrame& frame) {
std::vector<std::unique_ptr<webrtc::IceCandidateInterface>> ice_candidates;
std::vector<std::unique_ptr<webrtc::IceCandidate>> ice_candidates;
for (const auto& candidate : frame.ice_candidates().ice_candidates()) {
ice_candidates.push_back(DecodeIceCandidate(candidate));
}
@@ -118,7 +117,7 @@ std::vector<std::unique_ptr<webrtc::IceCandidateInterface>> DecodeIceCandidates(
}
location::nearby::mediums::IceCandidate EncodeIceCandidate(
const webrtc::IceCandidateInterface& ice_candidate) {
const webrtc::IceCandidate& ice_candidate) {
std::string sdp;
ice_candidate.ToString(&sdp);
location::nearby::mediums::IceCandidate ice_candidate_proto;
@@ -40,14 +40,14 @@ ByteArray EncodeIceCandidates(
const WebrtcPeerId& sender_id,
const std::vector<location::nearby::mediums::IceCandidate>& ice_candidates);
location::nearby::mediums::IceCandidate EncodeIceCandidate(
const webrtc::IceCandidateInterface& ice_candidate);
const webrtc::IceCandidate& ice_candidate);
std::unique_ptr<webrtc::SessionDescriptionInterface> DecodeOffer(
const location::nearby::mediums::WebRtcSignalingFrame& frame);
std::unique_ptr<webrtc::SessionDescriptionInterface> DecodeAnswer(
const location::nearby::mediums::WebRtcSignalingFrame& frame);
std::vector<std::unique_ptr<webrtc::IceCandidateInterface>> DecodeIceCandidates(
std::vector<std::unique_ptr<webrtc::IceCandidate>> DecodeIceCandidates(
const location::nearby::mediums::WebRtcSignalingFrame& frame);
} // namespace webrtc_frames
@@ -21,6 +21,7 @@
#include "gtest/gtest.h"
#include "connections/implementation/mediums/webrtc_peer_id.h"
#include "google/protobuf/text_format.h"
#include "webrtc/api/jsep.h"
namespace nearby {
namespace connections {
@@ -149,7 +150,7 @@ TEST(SignalingFramesTest, EncodeValidIceCandidates) {
WebrtcPeerId sender_id("abc");
webrtc::SdpParseError error;
std::vector<std::unique_ptr<webrtc::IceCandidateInterface>> ice_candidates;
std::vector<std::unique_ptr<webrtc::IceCandidate>> ice_candidates;
ice_candidates.emplace_back(webrtc::CreateIceCandidate(
kIceSdpMid, kIceSdpMLineIndex, kIceCandidateSdp1, &error));
ice_candidates.emplace_back(webrtc::CreateIceCandidate(
@@ -170,7 +171,7 @@ TEST(SignalingFramesTest, EncodeValidIceCandidates) {
TEST(SignalingFramesTest, DecodeValidIceCandidates) {
webrtc::SdpParseError error;
std::vector<std::unique_ptr<webrtc::IceCandidateInterface>> ice_candidates;
std::vector<std::unique_ptr<webrtc::IceCandidate>> ice_candidates;
ice_candidates.emplace_back(webrtc::CreateIceCandidate(
kIceSdpMid, kIceSdpMLineIndex, kIceCandidateSdp1, &error));
ice_candidates.emplace_back(webrtc::CreateIceCandidate(
@@ -178,8 +179,8 @@ TEST(SignalingFramesTest, DecodeValidIceCandidates) {
WebRtcSignalingFrame frame;
proto2::TextFormat::ParseFromString(kIceCandidatesProto, &frame);
std::vector<std::unique_ptr<webrtc::IceCandidateInterface>>
decoded_candidates = DecodeIceCandidates(frame);
std::vector<std::unique_ptr<webrtc::IceCandidate>> decoded_candidates =
DecodeIceCandidates(frame);
ASSERT_EQ(2u, decoded_candidates.size());
for (int i = 0; i < static_cast<int>(decoded_candidates.size()); i++) {
@@ -19,10 +19,9 @@
#include <string>
#include "gtest/gtest.h"
#include "internal/platform/implementation/webrtc.h"
#include "webrtc/api/jsep.h"
#include "webrtc/api/data_channel_interface.h"
#include "webrtc/api/jsep.h"
#include "webrtc/api/peer_connection_interface.h"
#include "webrtc/api/scoped_refptr.h"
@@ -40,8 +39,7 @@ class MockPeerConnectionObserver : public webrtc::PeerConnectionObserver {
void OnIceGatheringChange(
webrtc::PeerConnectionInterface::IceGatheringState new_state) override {}
void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
}
void OnIceCandidate(const webrtc::IceCandidate* candidate) override {}
};
location::nearby::connections::LocationHint GetCountryCodeLocationHint(