webrtc_m130/pc/peer_connection_histogram_unittest.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

788 lines
33 KiB
C++
Raw Normal View History

/*
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <memory>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "absl/types/optional.h"
#include "api/async_resolver_factory.h"
#include "api/call/call_factory_interface.h"
#include "api/jsep.h"
#include "api/jsep_session_description.h"
#include "api/peer_connection_interface.h"
#include "api/rtc_error.h"
#include "api/scoped_refptr.h"
#include "api/task_queue/default_task_queue_factory.h"
#include "api/task_queue/task_queue_factory.h"
#include "media/base/fake_media_engine.h"
#include "media/base/media_engine.h"
#include "p2p/base/mock_async_resolver.h"
#include "p2p/base/port_allocator.h"
#include "p2p/client/basic_port_allocator.h"
#include "pc/peer_connection.h"
#include "pc/peer_connection_factory.h"
#include "pc/peer_connection_proxy.h"
#include "pc/peer_connection_wrapper.h"
#include "pc/sdp_utils.h"
#include "pc/test/mock_peer_connection_observers.h"
#include "pc/usage_pattern.h"
#include "pc/webrtc_sdp.h"
#include "rtc_base/arraysize.h"
#include "rtc_base/checks.h"
#include "rtc_base/fake_mdns_responder.h"
#include "rtc_base/fake_network.h"
#include "rtc_base/gunit.h"
#include "rtc_base/mdns_responder_interface.h"
#include "rtc_base/ref_counted_object.h"
#include "rtc_base/socket_address.h"
#include "rtc_base/thread.h"
#include "rtc_base/virtual_socket_server.h"
#include "system_wrappers/include/metrics.h"
#include "test/gmock.h"
#include "test/gtest.h"
namespace webrtc {
using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
using ::testing::NiceMock;
using ::testing::Values;
static const char kUsagePatternMetric[] = "WebRTC.PeerConnection.UsagePattern";
static constexpr int kDefaultTimeout = 10000;
static const rtc::SocketAddress kLocalAddrs[2] = {
rtc::SocketAddress("1.1.1.1", 0), rtc::SocketAddress("2.2.2.2", 0)};
static const rtc::SocketAddress kPrivateLocalAddress("10.1.1.1", 0);
static const rtc::SocketAddress kPrivateIpv6LocalAddress("fd12:3456:789a:1::1",
0);
int MakeUsageFingerprint(std::set<UsageEvent> events) {
int signature = 0;
for (const auto it : events) {
signature |= static_cast<int>(it);
}
return signature;
}
class PeerConnectionFactoryForUsageHistogramTest
: public PeerConnectionFactory {
public:
PeerConnectionFactoryForUsageHistogramTest()
: PeerConnectionFactory([] {
PeerConnectionFactoryDependencies dependencies;
dependencies.network_thread = rtc::Thread::Current();
dependencies.worker_thread = rtc::Thread::Current();
dependencies.signaling_thread = rtc::Thread::Current();
dependencies.task_queue_factory = CreateDefaultTaskQueueFactory();
dependencies.media_engine =
Use std::make_unique instead of absl::make_unique. WebRTC is now using C++14 so there is no need to use the Abseil version of std::make_unique. This CL has been created with the following steps: git grep -l absl::make_unique | sort | uniq > /tmp/make_unique.txt git grep -l absl::WrapUnique | sort | uniq > /tmp/wrap_unique.txt git grep -l "#include <memory>" | sort | uniq > /tmp/memory.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/make_unique.txt /tmp/wrap_unique.txt | sort | \ uniq > /tmp/only_make_unique.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/only_make_unique.txt /tmp/memory.txt | \ xargs grep -l "absl/memory" > /tmp/add-memory.txt git grep -l "\babsl::make_unique\b" | \ xargs sed -i "s/\babsl::make_unique\b/std::make_unique/g" git checkout PRESUBMIT.py abseil-in-webrtc.md cat /tmp/add-memory.txt | \ xargs sed -i \ 's/#include "absl\/memory\/memory.h"/#include <memory>/g' git cl format # Manual fix order of the new inserted #include <memory> cat /tmp/only_make_unique | xargs grep -l "#include <memory>" | \ xargs sed -i '/#include "absl\/memory\/memory.h"/d' git ls-files | grep BUILD.gn | \ xargs sed -i '/\/\/third_party\/abseil-cpp\/absl\/memory/d' python tools_webrtc/gn_check_autofix.py \ -m tryserver.webrtc -b linux_rel # Repead the gn_check_autofix step for other platforms git ls-files | grep BUILD.gn | \ xargs sed -i 's/absl\/memory:memory/absl\/memory/g' git cl format Bug: webrtc:10945 Change-Id: I3fe28ea80f4dd3ba3cf28effd151d5e1f19aff89 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/153221 Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#29209}
2019-09-17 17:06:18 +02:00
std::make_unique<cricket::FakeMediaEngine>();
dependencies.call_factory = CreateCallFactory();
return dependencies;
}()) {}
};
class PeerConnectionWrapperForUsageHistogramTest;
typedef PeerConnectionWrapperForUsageHistogramTest* RawWrapperPtr;
class ObserverForUsageHistogramTest : public MockPeerConnectionObserver {
public:
void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override;
void OnInterestingUsage(int usage_pattern) override {
interesting_usage_detected_ = usage_pattern;
}
void PrepareToExchangeCandidates(RawWrapperPtr other) {
candidate_target_ = other;
}
bool HaveDataChannel() { return last_datachannel_ != nullptr; }
absl::optional<int> interesting_usage_detected() {
return interesting_usage_detected_;
}
void ClearInterestingUsageDetector() {
interesting_usage_detected_ = absl::optional<int>();
}
bool candidate_gathered() const { return candidate_gathered_; }
private:
absl::optional<int> interesting_usage_detected_;
bool candidate_gathered_ = false;
RawWrapperPtr candidate_target_; // Note: Not thread-safe against deletions.
};
class PeerConnectionWrapperForUsageHistogramTest
: public PeerConnectionWrapper {
public:
using PeerConnectionWrapper::PeerConnectionWrapper;
PeerConnection* GetInternalPeerConnection() {
auto* pci =
static_cast<PeerConnectionProxyWithInternal<PeerConnectionInterface>*>(
pc());
return static_cast<PeerConnection*>(pci->internal());
}
// Override with different return type
ObserverForUsageHistogramTest* observer() {
return static_cast<ObserverForUsageHistogramTest*>(
PeerConnectionWrapper::observer());
}
void PrepareToExchangeCandidates(
PeerConnectionWrapperForUsageHistogramTest* other) {
observer()->PrepareToExchangeCandidates(other);
other->observer()->PrepareToExchangeCandidates(this);
}
bool IsConnected() {
return pc()->ice_connection_state() ==
PeerConnectionInterface::kIceConnectionConnected ||
pc()->ice_connection_state() ==
PeerConnectionInterface::kIceConnectionCompleted;
}
bool HaveDataChannel() {
return static_cast<ObserverForUsageHistogramTest*>(observer())
->HaveDataChannel();
}
void BufferIceCandidate(const webrtc::IceCandidateInterface* candidate) {
std::string sdp;
EXPECT_TRUE(candidate->ToString(&sdp));
std::unique_ptr<webrtc::IceCandidateInterface> candidate_copy(
CreateIceCandidate(candidate->sdp_mid(), candidate->sdp_mline_index(),
sdp, nullptr));
buffered_candidates_.push_back(std::move(candidate_copy));
}
void AddBufferedIceCandidates() {
for (const auto& candidate : buffered_candidates_) {
EXPECT_TRUE(pc()->AddIceCandidate(candidate.get()));
}
buffered_candidates_.clear();
}
// This method performs the following actions in sequence:
// 1. Exchange Offer and Answer.
// 2. Exchange ICE candidates after both caller and callee complete
// gathering.
// 3. Wait for ICE to connect.
//
// This guarantees a deterministic sequence of events and also rules out the
// occurrence of prflx candidates if the offer/answer signaling and the
// candidate trickling race in order. In case prflx candidates need to be
// simulated, see the approach used by tests below for that.
bool ConnectTo(PeerConnectionWrapperForUsageHistogramTest* callee) {
PrepareToExchangeCandidates(callee);
if (!ExchangeOfferAnswerWith(callee)) {
return false;
}
// Wait until the gathering completes before we signal the candidate.
WAIT(observer()->ice_gathering_complete_, kDefaultTimeout);
WAIT(callee->observer()->ice_gathering_complete_, kDefaultTimeout);
AddBufferedIceCandidates();
callee->AddBufferedIceCandidates();
WAIT(IsConnected(), kDefaultTimeout);
WAIT(callee->IsConnected(), kDefaultTimeout);
return IsConnected() && callee->IsConnected();
}
bool GenerateOfferAndCollectCandidates() {
auto offer = CreateOffer(RTCOfferAnswerOptions());
if (!offer) {
return false;
}
bool set_local_offer =
SetLocalDescription(CloneSessionDescription(offer.get()));
EXPECT_TRUE(set_local_offer);
if (!set_local_offer) {
return false;
}
EXPECT_TRUE_WAIT(observer()->ice_gathering_complete_, kDefaultTimeout);
return true;
}
webrtc::PeerConnectionInterface::IceGatheringState ice_gathering_state() {
return pc()->ice_gathering_state();
}
private:
// Candidates that have been sent but not yet configured
std::vector<std::unique_ptr<webrtc::IceCandidateInterface>>
buffered_candidates_;
};
// Buffers candidates until we add them via AddBufferedIceCandidates.
void ObserverForUsageHistogramTest::OnIceCandidate(
const webrtc::IceCandidateInterface* candidate) {
// If target is not set, ignore. This happens in one-ended unit tests.
if (candidate_target_) {
this->candidate_target_->BufferIceCandidate(candidate);
}
candidate_gathered_ = true;
}
class PeerConnectionUsageHistogramTest : public ::testing::Test {
protected:
typedef std::unique_ptr<PeerConnectionWrapperForUsageHistogramTest>
WrapperPtr;
PeerConnectionUsageHistogramTest()
: vss_(new rtc::VirtualSocketServer()), main_(vss_.get()) {
Reland "Reland "Replace the usage of MetricsObserverInterface by RTC_HISTOGRAM_*."" This is a reland of 1a2cc0acba6a66f89249455d8e5775849b56f755 Original change's description: > Reland "Replace the usage of MetricsObserverInterface by RTC_HISTOGRAM_*." > > This is a reland of 870bca1f418a1abf445169a638a61f9a649d557f > > Original change's description: > > Replace the usage of MetricsObserverInterface by RTC_HISTOGRAM_*. > > > > We now use RTC_HISTOGRAM_* macros in system_wrappers/include/metrics.h > > to report the metrics in pc/ and p2p/ that are currently been reported > > using MetricsObserverInterface. > > > > TBR=tommi@webrtc.org > > > > Bug: webrtc:9409 > > Change-Id: I47c9975402293c72250203fa1ec19eb1668766f6 > > Reviewed-on: https://webrtc-review.googlesource.com/83782 > > Commit-Queue: Qingsi Wang <qingsi@google.com> > > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > > Reviewed-by: Taylor (left Google) <deadbeef@webrtc.org> > > Reviewed-by: Steve Anton <steveanton@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#23914} > > TBR=steveanton@webrtc.org,hta@webrtc.org,tommi@webrtc.org > > Bug: webrtc:9409 > Change-Id: I37fc95ced60dea25aa9b4f5ad44bdf7174c8bd5c > Reviewed-on: https://webrtc-review.googlesource.com/88060 > Reviewed-by: Qingsi Wang <qingsi@webrtc.org> > Commit-Queue: Qingsi Wang <qingsi@google.com> > Cr-Commit-Position: refs/heads/master@{#23919} TBR=steveanton@webrtc.org,tommi@webrtc.org Bug: webrtc:9409 Change-Id: Ib55f0b6c9bcb9d9585924a4dfac5cf643ff4d76b Reviewed-on: https://webrtc-review.googlesource.com/88343 Commit-Queue: Qingsi Wang <qingsi@google.com> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/master@{#23957}
2018-07-12 12:54:53 -07:00
webrtc::metrics::Reset();
}
WrapperPtr CreatePeerConnection() {
RTCConfiguration config;
config.sdp_semantics = webrtc::SdpSemantics::kUnifiedPlan;
return CreatePeerConnection(
config, PeerConnectionFactoryInterface::Options(), nullptr);
}
WrapperPtr CreatePeerConnection(const RTCConfiguration& config) {
return CreatePeerConnection(
config, PeerConnectionFactoryInterface::Options(), nullptr);
}
WrapperPtr CreatePeerConnectionWithMdns(const RTCConfiguration& config) {
auto resolver_factory =
Use std::make_unique instead of absl::make_unique. WebRTC is now using C++14 so there is no need to use the Abseil version of std::make_unique. This CL has been created with the following steps: git grep -l absl::make_unique | sort | uniq > /tmp/make_unique.txt git grep -l absl::WrapUnique | sort | uniq > /tmp/wrap_unique.txt git grep -l "#include <memory>" | sort | uniq > /tmp/memory.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/make_unique.txt /tmp/wrap_unique.txt | sort | \ uniq > /tmp/only_make_unique.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/only_make_unique.txt /tmp/memory.txt | \ xargs grep -l "absl/memory" > /tmp/add-memory.txt git grep -l "\babsl::make_unique\b" | \ xargs sed -i "s/\babsl::make_unique\b/std::make_unique/g" git checkout PRESUBMIT.py abseil-in-webrtc.md cat /tmp/add-memory.txt | \ xargs sed -i \ 's/#include "absl\/memory\/memory.h"/#include <memory>/g' git cl format # Manual fix order of the new inserted #include <memory> cat /tmp/only_make_unique | xargs grep -l "#include <memory>" | \ xargs sed -i '/#include "absl\/memory\/memory.h"/d' git ls-files | grep BUILD.gn | \ xargs sed -i '/\/\/third_party\/abseil-cpp\/absl\/memory/d' python tools_webrtc/gn_check_autofix.py \ -m tryserver.webrtc -b linux_rel # Repead the gn_check_autofix step for other platforms git ls-files | grep BUILD.gn | \ xargs sed -i 's/absl\/memory:memory/absl\/memory/g' git cl format Bug: webrtc:10945 Change-Id: I3fe28ea80f4dd3ba3cf28effd151d5e1f19aff89 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/153221 Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#29209}
2019-09-17 17:06:18 +02:00
std::make_unique<NiceMock<webrtc::MockAsyncResolverFactory>>();
webrtc::PeerConnectionDependencies deps(nullptr /* observer_in */);
auto fake_network = NewFakeNetwork();
fake_network->set_mdns_responder(
Use std::make_unique instead of absl::make_unique. WebRTC is now using C++14 so there is no need to use the Abseil version of std::make_unique. This CL has been created with the following steps: git grep -l absl::make_unique | sort | uniq > /tmp/make_unique.txt git grep -l absl::WrapUnique | sort | uniq > /tmp/wrap_unique.txt git grep -l "#include <memory>" | sort | uniq > /tmp/memory.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/make_unique.txt /tmp/wrap_unique.txt | sort | \ uniq > /tmp/only_make_unique.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/only_make_unique.txt /tmp/memory.txt | \ xargs grep -l "absl/memory" > /tmp/add-memory.txt git grep -l "\babsl::make_unique\b" | \ xargs sed -i "s/\babsl::make_unique\b/std::make_unique/g" git checkout PRESUBMIT.py abseil-in-webrtc.md cat /tmp/add-memory.txt | \ xargs sed -i \ 's/#include "absl\/memory\/memory.h"/#include <memory>/g' git cl format # Manual fix order of the new inserted #include <memory> cat /tmp/only_make_unique | xargs grep -l "#include <memory>" | \ xargs sed -i '/#include "absl\/memory\/memory.h"/d' git ls-files | grep BUILD.gn | \ xargs sed -i '/\/\/third_party\/abseil-cpp\/absl\/memory/d' python tools_webrtc/gn_check_autofix.py \ -m tryserver.webrtc -b linux_rel # Repead the gn_check_autofix step for other platforms git ls-files | grep BUILD.gn | \ xargs sed -i 's/absl\/memory:memory/absl\/memory/g' git cl format Bug: webrtc:10945 Change-Id: I3fe28ea80f4dd3ba3cf28effd151d5e1f19aff89 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/153221 Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#29209}
2019-09-17 17:06:18 +02:00
std::make_unique<webrtc::FakeMdnsResponder>(rtc::Thread::Current()));
fake_network->AddInterface(NextLocalAddress());
std::unique_ptr<cricket::BasicPortAllocator> port_allocator(
Revert "Reland "Don't create PacketSocketFactory inside BasicPortAllocatorSession"" This reverts commit a8be79ce27f10a698bdb46e490c2bbcbb2300e52. Reason for revert: Downstream projects were not fixed and I was to eager to reland this, sorry about this. Original change's description: > Reland "Don't create PacketSocketFactory inside BasicPortAllocatorSession" > > This is a reland of commit 7d4634cef76a1ac244d4b83faaf4c617bf236b71 > > Original change's description: > > Don't create PacketSocketFactory inside BasicPortAllocatorSession > > > > This extends AlwaysValidPointer to avoid creating a unique_ptr inside it. > > > > Bug: webrtc:13145 > > Change-Id: I73a4f18d0a7037b57f575b04b134e4f7eadceb79 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/263240 > > Reviewed-by: Jonas Oreland <jonaso@webrtc.org> > > Commit-Queue: Daniel.L (Byoungchan) Lee <daniel.l@hpcnt.com> > > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#37048} > > Bug: webrtc:13145 > Change-Id: I7d64c25b2942b392a1c35ff2fe1edc83d7b03746 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/264503 > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > Reviewed-by: Christoffer Jansson <jansson@webrtc.org> > Commit-Queue: Christoffer Jansson <jansson@webrtc.org> > Reviewed-by: Daniel.L (Byoungchan) Lee <daniel.l@hpcnt.com> > Cr-Commit-Position: refs/heads/main@{#37088} Bug: webrtc:13145 Change-Id: Ie7990bae9a7c864ffaa4eb5b637618caad509633 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/264823 Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> Commit-Queue: Christoffer Jansson <jansson@webrtc.org> Owners-Override: Christoffer Jansson <jansson@webrtc.org> Cr-Commit-Position: refs/heads/main@{#37089}
2022-06-02 09:44:03 +00:00
new cricket::BasicPortAllocator(fake_network));
deps.async_resolver_factory = std::move(resolver_factory);
deps.allocator = std::move(port_allocator);
return CreatePeerConnection(
config, PeerConnectionFactoryInterface::Options(), std::move(deps));
}
WrapperPtr CreatePeerConnectionWithImmediateReport() {
RTCConfiguration configuration;
configuration.sdp_semantics = webrtc::SdpSemantics::kUnifiedPlan;
configuration.report_usage_pattern_delay_ms = 0;
return CreatePeerConnection(
configuration, PeerConnectionFactoryInterface::Options(), nullptr);
}
WrapperPtr CreatePeerConnectionWithPrivateLocalAddresses() {
auto* fake_network = NewFakeNetwork();
fake_network->AddInterface(NextLocalAddress());
fake_network->AddInterface(kPrivateLocalAddress);
Revert "Reland "Don't create PacketSocketFactory inside BasicPortAllocatorSession"" This reverts commit a8be79ce27f10a698bdb46e490c2bbcbb2300e52. Reason for revert: Downstream projects were not fixed and I was to eager to reland this, sorry about this. Original change's description: > Reland "Don't create PacketSocketFactory inside BasicPortAllocatorSession" > > This is a reland of commit 7d4634cef76a1ac244d4b83faaf4c617bf236b71 > > Original change's description: > > Don't create PacketSocketFactory inside BasicPortAllocatorSession > > > > This extends AlwaysValidPointer to avoid creating a unique_ptr inside it. > > > > Bug: webrtc:13145 > > Change-Id: I73a4f18d0a7037b57f575b04b134e4f7eadceb79 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/263240 > > Reviewed-by: Jonas Oreland <jonaso@webrtc.org> > > Commit-Queue: Daniel.L (Byoungchan) Lee <daniel.l@hpcnt.com> > > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#37048} > > Bug: webrtc:13145 > Change-Id: I7d64c25b2942b392a1c35ff2fe1edc83d7b03746 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/264503 > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > Reviewed-by: Christoffer Jansson <jansson@webrtc.org> > Commit-Queue: Christoffer Jansson <jansson@webrtc.org> > Reviewed-by: Daniel.L (Byoungchan) Lee <daniel.l@hpcnt.com> > Cr-Commit-Position: refs/heads/main@{#37088} Bug: webrtc:13145 Change-Id: Ie7990bae9a7c864ffaa4eb5b637618caad509633 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/264823 Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> Commit-Queue: Christoffer Jansson <jansson@webrtc.org> Owners-Override: Christoffer Jansson <jansson@webrtc.org> Cr-Commit-Position: refs/heads/main@{#37089}
2022-06-02 09:44:03 +00:00
auto port_allocator =
std::make_unique<cricket::BasicPortAllocator>(fake_network);
RTCConfiguration config;
config.sdp_semantics = SdpSemantics::kUnifiedPlan;
return CreatePeerConnection(config,
PeerConnectionFactoryInterface::Options(),
std::move(port_allocator));
}
WrapperPtr CreatePeerConnectionWithPrivateIpv6LocalAddresses() {
auto* fake_network = NewFakeNetwork();
fake_network->AddInterface(NextLocalAddress());
fake_network->AddInterface(kPrivateIpv6LocalAddress);
Revert "Reland "Don't create PacketSocketFactory inside BasicPortAllocatorSession"" This reverts commit a8be79ce27f10a698bdb46e490c2bbcbb2300e52. Reason for revert: Downstream projects were not fixed and I was to eager to reland this, sorry about this. Original change's description: > Reland "Don't create PacketSocketFactory inside BasicPortAllocatorSession" > > This is a reland of commit 7d4634cef76a1ac244d4b83faaf4c617bf236b71 > > Original change's description: > > Don't create PacketSocketFactory inside BasicPortAllocatorSession > > > > This extends AlwaysValidPointer to avoid creating a unique_ptr inside it. > > > > Bug: webrtc:13145 > > Change-Id: I73a4f18d0a7037b57f575b04b134e4f7eadceb79 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/263240 > > Reviewed-by: Jonas Oreland <jonaso@webrtc.org> > > Commit-Queue: Daniel.L (Byoungchan) Lee <daniel.l@hpcnt.com> > > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#37048} > > Bug: webrtc:13145 > Change-Id: I7d64c25b2942b392a1c35ff2fe1edc83d7b03746 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/264503 > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > Reviewed-by: Christoffer Jansson <jansson@webrtc.org> > Commit-Queue: Christoffer Jansson <jansson@webrtc.org> > Reviewed-by: Daniel.L (Byoungchan) Lee <daniel.l@hpcnt.com> > Cr-Commit-Position: refs/heads/main@{#37088} Bug: webrtc:13145 Change-Id: Ie7990bae9a7c864ffaa4eb5b637618caad509633 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/264823 Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> Commit-Queue: Christoffer Jansson <jansson@webrtc.org> Owners-Override: Christoffer Jansson <jansson@webrtc.org> Cr-Commit-Position: refs/heads/main@{#37089}
2022-06-02 09:44:03 +00:00
auto port_allocator =
std::make_unique<cricket::BasicPortAllocator>(fake_network);
RTCConfiguration config;
config.sdp_semantics = SdpSemantics::kUnifiedPlan;
return CreatePeerConnection(config,
PeerConnectionFactoryInterface::Options(),
std::move(port_allocator));
}
WrapperPtr CreatePeerConnection(
const RTCConfiguration& config,
const PeerConnectionFactoryInterface::Options factory_options,
std::unique_ptr<cricket::PortAllocator> allocator) {
PeerConnectionDependencies deps(nullptr);
deps.allocator = std::move(allocator);
return CreatePeerConnection(config, factory_options, std::move(deps));
}
WrapperPtr CreatePeerConnection(
const RTCConfiguration& config,
const PeerConnectionFactoryInterface::Options factory_options,
PeerConnectionDependencies deps) {
auto pc_factory =
rtc::make_ref_counted<PeerConnectionFactoryForUsageHistogramTest>();
pc_factory->SetOptions(factory_options);
// If no allocator is provided, one will be created using a network manager
// that uses the host network. This doesn't work on all trybots.
if (!deps.allocator) {
auto fake_network = NewFakeNetwork();
fake_network->AddInterface(NextLocalAddress());
Revert "Reland "Don't create PacketSocketFactory inside BasicPortAllocatorSession"" This reverts commit a8be79ce27f10a698bdb46e490c2bbcbb2300e52. Reason for revert: Downstream projects were not fixed and I was to eager to reland this, sorry about this. Original change's description: > Reland "Don't create PacketSocketFactory inside BasicPortAllocatorSession" > > This is a reland of commit 7d4634cef76a1ac244d4b83faaf4c617bf236b71 > > Original change's description: > > Don't create PacketSocketFactory inside BasicPortAllocatorSession > > > > This extends AlwaysValidPointer to avoid creating a unique_ptr inside it. > > > > Bug: webrtc:13145 > > Change-Id: I73a4f18d0a7037b57f575b04b134e4f7eadceb79 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/263240 > > Reviewed-by: Jonas Oreland <jonaso@webrtc.org> > > Commit-Queue: Daniel.L (Byoungchan) Lee <daniel.l@hpcnt.com> > > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#37048} > > Bug: webrtc:13145 > Change-Id: I7d64c25b2942b392a1c35ff2fe1edc83d7b03746 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/264503 > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > Reviewed-by: Christoffer Jansson <jansson@webrtc.org> > Commit-Queue: Christoffer Jansson <jansson@webrtc.org> > Reviewed-by: Daniel.L (Byoungchan) Lee <daniel.l@hpcnt.com> > Cr-Commit-Position: refs/heads/main@{#37088} Bug: webrtc:13145 Change-Id: Ie7990bae9a7c864ffaa4eb5b637618caad509633 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/264823 Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> Commit-Queue: Christoffer Jansson <jansson@webrtc.org> Owners-Override: Christoffer Jansson <jansson@webrtc.org> Cr-Commit-Position: refs/heads/main@{#37089}
2022-06-02 09:44:03 +00:00
deps.allocator =
std::make_unique<cricket::BasicPortAllocator>(fake_network);
}
Use std::make_unique instead of absl::make_unique. WebRTC is now using C++14 so there is no need to use the Abseil version of std::make_unique. This CL has been created with the following steps: git grep -l absl::make_unique | sort | uniq > /tmp/make_unique.txt git grep -l absl::WrapUnique | sort | uniq > /tmp/wrap_unique.txt git grep -l "#include <memory>" | sort | uniq > /tmp/memory.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/make_unique.txt /tmp/wrap_unique.txt | sort | \ uniq > /tmp/only_make_unique.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/only_make_unique.txt /tmp/memory.txt | \ xargs grep -l "absl/memory" > /tmp/add-memory.txt git grep -l "\babsl::make_unique\b" | \ xargs sed -i "s/\babsl::make_unique\b/std::make_unique/g" git checkout PRESUBMIT.py abseil-in-webrtc.md cat /tmp/add-memory.txt | \ xargs sed -i \ 's/#include "absl\/memory\/memory.h"/#include <memory>/g' git cl format # Manual fix order of the new inserted #include <memory> cat /tmp/only_make_unique | xargs grep -l "#include <memory>" | \ xargs sed -i '/#include "absl\/memory\/memory.h"/d' git ls-files | grep BUILD.gn | \ xargs sed -i '/\/\/third_party\/abseil-cpp\/absl\/memory/d' python tools_webrtc/gn_check_autofix.py \ -m tryserver.webrtc -b linux_rel # Repead the gn_check_autofix step for other platforms git ls-files | grep BUILD.gn | \ xargs sed -i 's/absl\/memory:memory/absl\/memory/g' git cl format Bug: webrtc:10945 Change-Id: I3fe28ea80f4dd3ba3cf28effd151d5e1f19aff89 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/153221 Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#29209}
2019-09-17 17:06:18 +02:00
auto observer = std::make_unique<ObserverForUsageHistogramTest>();
deps.observer = observer.get();
auto result =
pc_factory->CreatePeerConnectionOrError(config, std::move(deps));
if (!result.ok()) {
return nullptr;
}
observer->SetPeerConnectionInterface(result.value().get());
Use std::make_unique instead of absl::make_unique. WebRTC is now using C++14 so there is no need to use the Abseil version of std::make_unique. This CL has been created with the following steps: git grep -l absl::make_unique | sort | uniq > /tmp/make_unique.txt git grep -l absl::WrapUnique | sort | uniq > /tmp/wrap_unique.txt git grep -l "#include <memory>" | sort | uniq > /tmp/memory.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/make_unique.txt /tmp/wrap_unique.txt | sort | \ uniq > /tmp/only_make_unique.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/only_make_unique.txt /tmp/memory.txt | \ xargs grep -l "absl/memory" > /tmp/add-memory.txt git grep -l "\babsl::make_unique\b" | \ xargs sed -i "s/\babsl::make_unique\b/std::make_unique/g" git checkout PRESUBMIT.py abseil-in-webrtc.md cat /tmp/add-memory.txt | \ xargs sed -i \ 's/#include "absl\/memory\/memory.h"/#include <memory>/g' git cl format # Manual fix order of the new inserted #include <memory> cat /tmp/only_make_unique | xargs grep -l "#include <memory>" | \ xargs sed -i '/#include "absl\/memory\/memory.h"/d' git ls-files | grep BUILD.gn | \ xargs sed -i '/\/\/third_party\/abseil-cpp\/absl\/memory/d' python tools_webrtc/gn_check_autofix.py \ -m tryserver.webrtc -b linux_rel # Repead the gn_check_autofix step for other platforms git ls-files | grep BUILD.gn | \ xargs sed -i 's/absl\/memory:memory/absl\/memory/g' git cl format Bug: webrtc:10945 Change-Id: I3fe28ea80f4dd3ba3cf28effd151d5e1f19aff89 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/153221 Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#29209}
2019-09-17 17:06:18 +02:00
auto wrapper = std::make_unique<PeerConnectionWrapperForUsageHistogramTest>(
pc_factory, result.MoveValue(), std::move(observer));
return wrapper;
}
int ObservedFingerprint() {
// This works correctly only if there is only one sample value
// that has been counted.
// Returns -1 for "not found".
return webrtc::metrics::MinSample(kUsagePatternMetric);
}
// The PeerConnection's port allocator is tied to the PeerConnection's
// lifetime and expects the underlying NetworkManager to outlive it. That
// prevents us from having the PeerConnectionWrapper own the fake network.
// Therefore, the test fixture will own all the fake networks even though
// tests should access the fake network through the PeerConnectionWrapper.
rtc::FakeNetworkManager* NewFakeNetwork() {
Use std::make_unique instead of absl::make_unique. WebRTC is now using C++14 so there is no need to use the Abseil version of std::make_unique. This CL has been created with the following steps: git grep -l absl::make_unique | sort | uniq > /tmp/make_unique.txt git grep -l absl::WrapUnique | sort | uniq > /tmp/wrap_unique.txt git grep -l "#include <memory>" | sort | uniq > /tmp/memory.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/make_unique.txt /tmp/wrap_unique.txt | sort | \ uniq > /tmp/only_make_unique.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/only_make_unique.txt /tmp/memory.txt | \ xargs grep -l "absl/memory" > /tmp/add-memory.txt git grep -l "\babsl::make_unique\b" | \ xargs sed -i "s/\babsl::make_unique\b/std::make_unique/g" git checkout PRESUBMIT.py abseil-in-webrtc.md cat /tmp/add-memory.txt | \ xargs sed -i \ 's/#include "absl\/memory\/memory.h"/#include <memory>/g' git cl format # Manual fix order of the new inserted #include <memory> cat /tmp/only_make_unique | xargs grep -l "#include <memory>" | \ xargs sed -i '/#include "absl\/memory\/memory.h"/d' git ls-files | grep BUILD.gn | \ xargs sed -i '/\/\/third_party\/abseil-cpp\/absl\/memory/d' python tools_webrtc/gn_check_autofix.py \ -m tryserver.webrtc -b linux_rel # Repead the gn_check_autofix step for other platforms git ls-files | grep BUILD.gn | \ xargs sed -i 's/absl\/memory:memory/absl\/memory/g' git cl format Bug: webrtc:10945 Change-Id: I3fe28ea80f4dd3ba3cf28effd151d5e1f19aff89 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/153221 Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#29209}
2019-09-17 17:06:18 +02:00
fake_networks_.emplace_back(std::make_unique<rtc::FakeNetworkManager>());
return fake_networks_.back().get();
}
rtc::SocketAddress NextLocalAddress() {
RTC_DCHECK(next_local_address_ < (int)arraysize(kLocalAddrs));
return kLocalAddrs[next_local_address_++];
}
std::vector<std::unique_ptr<rtc::FakeNetworkManager>> fake_networks_;
int next_local_address_ = 0;
std::unique_ptr<rtc::VirtualSocketServer> vss_;
rtc::AutoSocketServerThread main_;
};
TEST_F(PeerConnectionUsageHistogramTest, UsageFingerprintHistogramFromTimeout) {
auto pc = CreatePeerConnectionWithImmediateReport();
int expected_fingerprint = MakeUsageFingerprint({});
EXPECT_METRIC_EQ_WAIT(1, webrtc::metrics::NumSamples(kUsagePatternMetric),
kDefaultTimeout);
EXPECT_METRIC_EQ(
1, webrtc::metrics::NumEvents(kUsagePatternMetric, expected_fingerprint));
}
#ifndef WEBRTC_ANDROID
// These tests do not work on Android. Why is unclear.
// https://bugs.webrtc.org/9461
// Test getting the usage fingerprint for an audio/video connection.
TEST_F(PeerConnectionUsageHistogramTest, FingerprintAudioVideo) {
auto caller = CreatePeerConnection();
auto callee = CreatePeerConnection();
caller->AddAudioTrack("audio");
caller->AddVideoTrack("video");
ASSERT_TRUE(caller->ConnectTo(callee.get()));
caller->pc()->Close();
callee->pc()->Close();
int expected_fingerprint = MakeUsageFingerprint(
{UsageEvent::AUDIO_ADDED, UsageEvent::VIDEO_ADDED,
UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED,
UsageEvent::SET_REMOTE_DESCRIPTION_SUCCEEDED,
UsageEvent::CANDIDATE_COLLECTED, UsageEvent::ADD_ICE_CANDIDATE_SUCCEEDED,
UsageEvent::ICE_STATE_CONNECTED, UsageEvent::REMOTE_CANDIDATE_ADDED,
UsageEvent::DIRECT_CONNECTION_SELECTED, UsageEvent::CLOSE_CALLED});
// In this case, we may or may not have PRIVATE_CANDIDATE_COLLECTED,
// depending on the machine configuration.
EXPECT_METRIC_EQ(2, webrtc::metrics::NumSamples(kUsagePatternMetric));
EXPECT_METRIC_TRUE(
webrtc::metrics::NumEvents(kUsagePatternMetric, expected_fingerprint) ==
2 ||
webrtc::metrics::NumEvents(
kUsagePatternMetric,
expected_fingerprint |
static_cast<int>(UsageEvent::PRIVATE_CANDIDATE_COLLECTED)) == 2);
}
// Test getting the usage fingerprint when the caller collects an mDNS
// candidate.
TEST_F(PeerConnectionUsageHistogramTest, FingerprintWithMdnsCaller) {
RTCConfiguration config;
config.sdp_semantics = SdpSemantics::kUnifiedPlan;
// Enable hostname candidates with mDNS names.
auto caller = CreatePeerConnectionWithMdns(config);
auto callee = CreatePeerConnection(config);
caller->AddAudioTrack("audio");
caller->AddVideoTrack("video");
ASSERT_TRUE(caller->ConnectTo(callee.get()));
caller->pc()->Close();
callee->pc()->Close();
int expected_fingerprint_caller = MakeUsageFingerprint(
{UsageEvent::AUDIO_ADDED, UsageEvent::VIDEO_ADDED,
UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED,
UsageEvent::SET_REMOTE_DESCRIPTION_SUCCEEDED,
UsageEvent::CANDIDATE_COLLECTED, UsageEvent::MDNS_CANDIDATE_COLLECTED,
UsageEvent::ADD_ICE_CANDIDATE_SUCCEEDED, UsageEvent::ICE_STATE_CONNECTED,
UsageEvent::REMOTE_CANDIDATE_ADDED,
UsageEvent::DIRECT_CONNECTION_SELECTED, UsageEvent::CLOSE_CALLED});
// Without a resolver, the callee cannot resolve the received mDNS candidate
// but can still connect with the caller via a prflx candidate. As a result,
// the bit for the direct connection should not be logged.
int expected_fingerprint_callee = MakeUsageFingerprint(
{UsageEvent::AUDIO_ADDED, UsageEvent::VIDEO_ADDED,
UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED,
UsageEvent::SET_REMOTE_DESCRIPTION_SUCCEEDED,
UsageEvent::CANDIDATE_COLLECTED, UsageEvent::ADD_ICE_CANDIDATE_SUCCEEDED,
UsageEvent::REMOTE_MDNS_CANDIDATE_ADDED, UsageEvent::ICE_STATE_CONNECTED,
UsageEvent::REMOTE_CANDIDATE_ADDED, UsageEvent::CLOSE_CALLED});
EXPECT_METRIC_EQ(2, webrtc::metrics::NumSamples(kUsagePatternMetric));
EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents(kUsagePatternMetric,
expected_fingerprint_caller));
EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents(kUsagePatternMetric,
expected_fingerprint_callee));
}
// Test getting the usage fingerprint when the callee collects an mDNS
// candidate.
TEST_F(PeerConnectionUsageHistogramTest, FingerprintWithMdnsCallee) {
RTCConfiguration config;
config.sdp_semantics = SdpSemantics::kUnifiedPlan;
// Enable hostname candidates with mDNS names.
auto caller = CreatePeerConnection(config);
auto callee = CreatePeerConnectionWithMdns(config);
caller->AddAudioTrack("audio");
caller->AddVideoTrack("video");
ASSERT_TRUE(caller->ConnectTo(callee.get()));
caller->pc()->Close();
callee->pc()->Close();
// Similar to the test above, the caller connects with the callee via a prflx
// candidate.
int expected_fingerprint_caller = MakeUsageFingerprint(
{UsageEvent::AUDIO_ADDED, UsageEvent::VIDEO_ADDED,
UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED,
UsageEvent::SET_REMOTE_DESCRIPTION_SUCCEEDED,
UsageEvent::CANDIDATE_COLLECTED, UsageEvent::ADD_ICE_CANDIDATE_SUCCEEDED,
UsageEvent::REMOTE_MDNS_CANDIDATE_ADDED, UsageEvent::ICE_STATE_CONNECTED,
UsageEvent::REMOTE_CANDIDATE_ADDED, UsageEvent::CLOSE_CALLED});
int expected_fingerprint_callee = MakeUsageFingerprint(
{UsageEvent::AUDIO_ADDED, UsageEvent::VIDEO_ADDED,
UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED,
UsageEvent::SET_REMOTE_DESCRIPTION_SUCCEEDED,
UsageEvent::CANDIDATE_COLLECTED, UsageEvent::MDNS_CANDIDATE_COLLECTED,
UsageEvent::ADD_ICE_CANDIDATE_SUCCEEDED, UsageEvent::ICE_STATE_CONNECTED,
UsageEvent::REMOTE_CANDIDATE_ADDED,
UsageEvent::DIRECT_CONNECTION_SELECTED, UsageEvent::CLOSE_CALLED});
EXPECT_METRIC_EQ(2, webrtc::metrics::NumSamples(kUsagePatternMetric));
EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents(kUsagePatternMetric,
expected_fingerprint_caller));
EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents(kUsagePatternMetric,
expected_fingerprint_callee));
}
#ifdef WEBRTC_HAVE_SCTP
TEST_F(PeerConnectionUsageHistogramTest, FingerprintDataOnly) {
auto caller = CreatePeerConnection();
auto callee = CreatePeerConnection();
caller->CreateDataChannel("foodata");
ASSERT_TRUE(caller->ConnectTo(callee.get()));
ASSERT_TRUE_WAIT(callee->HaveDataChannel(), kDefaultTimeout);
caller->pc()->Close();
callee->pc()->Close();
int expected_fingerprint = MakeUsageFingerprint(
{UsageEvent::DATA_ADDED, UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED,
UsageEvent::SET_REMOTE_DESCRIPTION_SUCCEEDED,
UsageEvent::CANDIDATE_COLLECTED, UsageEvent::ADD_ICE_CANDIDATE_SUCCEEDED,
UsageEvent::ICE_STATE_CONNECTED, UsageEvent::REMOTE_CANDIDATE_ADDED,
UsageEvent::DIRECT_CONNECTION_SELECTED, UsageEvent::CLOSE_CALLED});
EXPECT_METRIC_EQ(2, webrtc::metrics::NumSamples(kUsagePatternMetric));
EXPECT_METRIC_TRUE(
webrtc::metrics::NumEvents(kUsagePatternMetric, expected_fingerprint) ==
2 ||
webrtc::metrics::NumEvents(
kUsagePatternMetric,
expected_fingerprint |
static_cast<int>(UsageEvent::PRIVATE_CANDIDATE_COLLECTED)) == 2);
}
#endif // WEBRTC_HAVE_SCTP
#endif // WEBRTC_ANDROID
TEST_F(PeerConnectionUsageHistogramTest, FingerprintStunTurn) {
RTCConfiguration configuration;
configuration.sdp_semantics = SdpSemantics::kUnifiedPlan;
PeerConnection::IceServer server;
server.urls = {"stun:dummy.stun.server"};
configuration.servers.push_back(server);
server.urls = {"turn:dummy.turn.server"};
server.username = "username";
server.password = "password";
configuration.servers.push_back(server);
auto caller = CreatePeerConnection(configuration);
ASSERT_TRUE(caller);
caller->pc()->Close();
int expected_fingerprint = MakeUsageFingerprint(
{UsageEvent::STUN_SERVER_ADDED, UsageEvent::TURN_SERVER_ADDED,
UsageEvent::CLOSE_CALLED});
EXPECT_METRIC_EQ(1, webrtc::metrics::NumSamples(kUsagePatternMetric));
EXPECT_METRIC_EQ(
1, webrtc::metrics::NumEvents(kUsagePatternMetric, expected_fingerprint));
}
TEST_F(PeerConnectionUsageHistogramTest, FingerprintStunTurnInReconfiguration) {
RTCConfiguration configuration;
configuration.sdp_semantics = SdpSemantics::kUnifiedPlan;
PeerConnection::IceServer server;
server.urls = {"stun:dummy.stun.server"};
configuration.servers.push_back(server);
server.urls = {"turn:dummy.turn.server"};
server.username = "username";
server.password = "password";
configuration.servers.push_back(server);
auto caller = CreatePeerConnection();
ASSERT_TRUE(caller);
ASSERT_TRUE(caller->pc()->SetConfiguration(configuration).ok());
caller->pc()->Close();
int expected_fingerprint = MakeUsageFingerprint(
{UsageEvent::STUN_SERVER_ADDED, UsageEvent::TURN_SERVER_ADDED,
UsageEvent::CLOSE_CALLED});
EXPECT_METRIC_EQ(1, webrtc::metrics::NumSamples(kUsagePatternMetric));
EXPECT_METRIC_EQ(
1, webrtc::metrics::NumEvents(kUsagePatternMetric, expected_fingerprint));
}
TEST_F(PeerConnectionUsageHistogramTest, FingerprintWithPrivateIPCaller) {
auto caller = CreatePeerConnectionWithPrivateLocalAddresses();
auto callee = CreatePeerConnection();
caller->AddAudioTrack("audio");
ASSERT_TRUE(caller->ConnectTo(callee.get()));
caller->pc()->Close();
callee->pc()->Close();
int expected_fingerprint_caller = MakeUsageFingerprint(
{UsageEvent::AUDIO_ADDED, UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED,
UsageEvent::SET_REMOTE_DESCRIPTION_SUCCEEDED,
UsageEvent::CANDIDATE_COLLECTED, UsageEvent::PRIVATE_CANDIDATE_COLLECTED,
UsageEvent::ADD_ICE_CANDIDATE_SUCCEEDED, UsageEvent::ICE_STATE_CONNECTED,
UsageEvent::REMOTE_CANDIDATE_ADDED,
UsageEvent::DIRECT_CONNECTION_SELECTED, UsageEvent::CLOSE_CALLED});
int expected_fingerprint_callee = MakeUsageFingerprint(
{UsageEvent::AUDIO_ADDED, UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED,
UsageEvent::SET_REMOTE_DESCRIPTION_SUCCEEDED,
UsageEvent::CANDIDATE_COLLECTED, UsageEvent::ADD_ICE_CANDIDATE_SUCCEEDED,
UsageEvent::REMOTE_PRIVATE_CANDIDATE_ADDED,
UsageEvent::ICE_STATE_CONNECTED, UsageEvent::REMOTE_CANDIDATE_ADDED,
UsageEvent::DIRECT_CONNECTION_SELECTED, UsageEvent::CLOSE_CALLED});
EXPECT_METRIC_EQ(2, webrtc::metrics::NumSamples(kUsagePatternMetric));
EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents(kUsagePatternMetric,
expected_fingerprint_caller));
EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents(kUsagePatternMetric,
expected_fingerprint_callee));
}
TEST_F(PeerConnectionUsageHistogramTest, FingerprintWithPrivateIpv6Callee) {
auto caller = CreatePeerConnection();
auto callee = CreatePeerConnectionWithPrivateIpv6LocalAddresses();
caller->AddAudioTrack("audio");
ASSERT_TRUE(caller->ConnectTo(callee.get()));
caller->pc()->Close();
callee->pc()->Close();
int expected_fingerprint_caller = MakeUsageFingerprint(
{UsageEvent::AUDIO_ADDED, UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED,
UsageEvent::SET_REMOTE_DESCRIPTION_SUCCEEDED,
UsageEvent::CANDIDATE_COLLECTED, UsageEvent::ADD_ICE_CANDIDATE_SUCCEEDED,
UsageEvent::REMOTE_PRIVATE_CANDIDATE_ADDED,
UsageEvent::ICE_STATE_CONNECTED, UsageEvent::REMOTE_CANDIDATE_ADDED,
UsageEvent::REMOTE_IPV6_CANDIDATE_ADDED,
UsageEvent::DIRECT_CONNECTION_SELECTED, UsageEvent::CLOSE_CALLED});
int expected_fingerprint_callee = MakeUsageFingerprint(
{UsageEvent::AUDIO_ADDED, UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED,
UsageEvent::SET_REMOTE_DESCRIPTION_SUCCEEDED,
UsageEvent::CANDIDATE_COLLECTED, UsageEvent::PRIVATE_CANDIDATE_COLLECTED,
UsageEvent::IPV6_CANDIDATE_COLLECTED,
UsageEvent::ADD_ICE_CANDIDATE_SUCCEEDED,
UsageEvent::REMOTE_CANDIDATE_ADDED, UsageEvent::ICE_STATE_CONNECTED,
UsageEvent::DIRECT_CONNECTION_SELECTED, UsageEvent::CLOSE_CALLED});
EXPECT_METRIC_EQ(2, webrtc::metrics::NumSamples(kUsagePatternMetric));
EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents(kUsagePatternMetric,
expected_fingerprint_caller));
EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents(kUsagePatternMetric,
expected_fingerprint_callee));
}
#ifndef WEBRTC_ANDROID
#ifdef WEBRTC_HAVE_SCTP
// Test that the usage pattern bits for adding remote (private IPv6) candidates
// are set when the remote candidates are retrieved from the Offer SDP instead
// of trickled ICE messages.
TEST_F(PeerConnectionUsageHistogramTest,
AddRemoteCandidatesFromRemoteDescription) {
// We construct the following data-channel-only scenario. The caller collects
// IPv6 private local candidates and appends them in the Offer as in
// non-trickled sessions. The callee collects mDNS candidates that are not
// contained in the Answer as in Trickle ICE. Only the Offer and Answer are
// signaled and we expect a connection with prflx remote candidates at the
// caller side.
auto caller = CreatePeerConnectionWithPrivateIpv6LocalAddresses();
RTCConfiguration config;
config.sdp_semantics = SdpSemantics::kUnifiedPlan;
auto callee = CreatePeerConnectionWithMdns(config);
caller->CreateDataChannel("test_channel");
ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer()));
// Wait until the gathering completes so that the session description would
// have contained ICE candidates.
EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete,
caller->ice_gathering_state(), kDefaultTimeout);
EXPECT_TRUE(caller->observer()->candidate_gathered());
// Get the current offer that contains candidates and pass it to the callee.
//
Reland "Use backticks not vertical bars to denote variables in comments for /pc" Original change's description: > Revert "Use backticks not vertical bars to denote variables in comments for /pc" > > This reverts commit 37ee0f5e594dd772ec6d620b5e5ea8a751b684f0. > > Reason for revert: Revert in order to be able to revert https://webrtc-review.googlesource.com/c/src/+/225642 > > Original change's description: > > Use backticks not vertical bars to denote variables in comments for /pc > > > > Bug: webrtc:12338 > > Change-Id: I88cf10afa5fc810b95d2a585ab2e895dcc163b63 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/226953 > > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > > Commit-Queue: Artem Titov <titovartem@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#34575} > > TBR=hta@webrtc.org,titovartem@webrtc.org,webrtc-scoped@luci-project-accounts.iam.gserviceaccount.com > > Change-Id: I5eddd3a14e1f664bf831e5c294fbc4de5f6a88af > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:12338 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/227082 > Reviewed-by: Björn Terelius <terelius@webrtc.org> > Commit-Queue: Björn Terelius <terelius@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#34577} Bug: webrtc:12338 Change-Id: I96bd229b73613c162d11d75fa4f5934e1b4295c7 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/227087 Commit-Queue: Artem Titov <titovartem@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/master@{#34611}
2021-07-30 22:30:23 +02:00
// Note that we cannot use CloneSessionDescription on `cur_offer` to obtain an
// SDP with candidates. The method above does not strictly copy everything, in
// particular, not copying the ICE candidates.
// TODO(qingsi): Technically, this is a bug. Fix it.
auto cur_offer = caller->pc()->local_description();
ASSERT_TRUE(cur_offer);
std::string sdp_with_candidates_str;
cur_offer->ToString(&sdp_with_candidates_str);
Use std::make_unique instead of absl::make_unique. WebRTC is now using C++14 so there is no need to use the Abseil version of std::make_unique. This CL has been created with the following steps: git grep -l absl::make_unique | sort | uniq > /tmp/make_unique.txt git grep -l absl::WrapUnique | sort | uniq > /tmp/wrap_unique.txt git grep -l "#include <memory>" | sort | uniq > /tmp/memory.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/make_unique.txt /tmp/wrap_unique.txt | sort | \ uniq > /tmp/only_make_unique.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/only_make_unique.txt /tmp/memory.txt | \ xargs grep -l "absl/memory" > /tmp/add-memory.txt git grep -l "\babsl::make_unique\b" | \ xargs sed -i "s/\babsl::make_unique\b/std::make_unique/g" git checkout PRESUBMIT.py abseil-in-webrtc.md cat /tmp/add-memory.txt | \ xargs sed -i \ 's/#include "absl\/memory\/memory.h"/#include <memory>/g' git cl format # Manual fix order of the new inserted #include <memory> cat /tmp/only_make_unique | xargs grep -l "#include <memory>" | \ xargs sed -i '/#include "absl\/memory\/memory.h"/d' git ls-files | grep BUILD.gn | \ xargs sed -i '/\/\/third_party\/abseil-cpp\/absl\/memory/d' python tools_webrtc/gn_check_autofix.py \ -m tryserver.webrtc -b linux_rel # Repead the gn_check_autofix step for other platforms git ls-files | grep BUILD.gn | \ xargs sed -i 's/absl\/memory:memory/absl\/memory/g' git cl format Bug: webrtc:10945 Change-Id: I3fe28ea80f4dd3ba3cf28effd151d5e1f19aff89 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/153221 Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#29209}
2019-09-17 17:06:18 +02:00
auto offer = std::make_unique<JsepSessionDescription>(SdpType::kOffer);
ASSERT_TRUE(SdpDeserialize(sdp_with_candidates_str, offer.get(),
nullptr /* error */));
ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer)));
// By default, the Answer created does not contain ICE candidates.
auto answer = callee->CreateAnswer();
callee->SetLocalDescription(CloneSessionDescription(answer.get()));
caller->SetRemoteDescription(std::move(answer));
EXPECT_TRUE_WAIT(caller->IsConnected(), kDefaultTimeout);
EXPECT_TRUE_WAIT(callee->IsConnected(), kDefaultTimeout);
// The callee needs to process the open message to have the data channel open.
EXPECT_TRUE_WAIT(callee->observer()->last_datachannel_ != nullptr,
kDefaultTimeout);
caller->pc()->Close();
callee->pc()->Close();
// The caller should not have added any remote candidate either via
// AddIceCandidate or from the remote description. Also, the caller connects
// with the callee via a prflx candidate and hence no direct connection bit
// should be set.
int expected_fingerprint_caller = MakeUsageFingerprint(
{UsageEvent::DATA_ADDED, UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED,
UsageEvent::SET_REMOTE_DESCRIPTION_SUCCEEDED,
UsageEvent::CANDIDATE_COLLECTED, UsageEvent::PRIVATE_CANDIDATE_COLLECTED,
UsageEvent::IPV6_CANDIDATE_COLLECTED, UsageEvent::ICE_STATE_CONNECTED,
UsageEvent::CLOSE_CALLED});
int expected_fingerprint_callee = MakeUsageFingerprint(
{UsageEvent::DATA_ADDED, UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED,
UsageEvent::SET_REMOTE_DESCRIPTION_SUCCEEDED,
UsageEvent::CANDIDATE_COLLECTED, UsageEvent::MDNS_CANDIDATE_COLLECTED,
UsageEvent::REMOTE_CANDIDATE_ADDED,
UsageEvent::REMOTE_PRIVATE_CANDIDATE_ADDED,
UsageEvent::REMOTE_IPV6_CANDIDATE_ADDED, UsageEvent::ICE_STATE_CONNECTED,
UsageEvent::DIRECT_CONNECTION_SELECTED, UsageEvent::CLOSE_CALLED});
EXPECT_METRIC_EQ(2, webrtc::metrics::NumSamples(kUsagePatternMetric));
EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents(kUsagePatternMetric,
expected_fingerprint_caller));
EXPECT_METRIC_EQ(1, webrtc::metrics::NumEvents(kUsagePatternMetric,
expected_fingerprint_callee));
}
TEST_F(PeerConnectionUsageHistogramTest, NotableUsageNoted) {
auto caller = CreatePeerConnection();
caller->CreateDataChannel("foo");
caller->GenerateOfferAndCollectCandidates();
caller->pc()->Close();
int expected_fingerprint = MakeUsageFingerprint(
{UsageEvent::DATA_ADDED, UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED,
UsageEvent::CANDIDATE_COLLECTED, UsageEvent::CLOSE_CALLED});
EXPECT_METRIC_EQ(1, webrtc::metrics::NumSamples(kUsagePatternMetric));
EXPECT_METRIC_TRUE(
expected_fingerprint == ObservedFingerprint() ||
(expected_fingerprint |
static_cast<int>(UsageEvent::PRIVATE_CANDIDATE_COLLECTED)) ==
ObservedFingerprint());
EXPECT_METRIC_EQ(absl::make_optional(ObservedFingerprint()),
caller->observer()->interesting_usage_detected());
}
TEST_F(PeerConnectionUsageHistogramTest, NotableUsageOnEventFiring) {
auto caller = CreatePeerConnection();
caller->CreateDataChannel("foo");
caller->GenerateOfferAndCollectCandidates();
int expected_fingerprint = MakeUsageFingerprint(
{UsageEvent::DATA_ADDED, UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED,
UsageEvent::CANDIDATE_COLLECTED});
EXPECT_METRIC_EQ(0, webrtc::metrics::NumSamples(kUsagePatternMetric));
caller->GetInternalPeerConnection()->RequestUsagePatternReportForTesting();
EXPECT_METRIC_EQ_WAIT(1, webrtc::metrics::NumSamples(kUsagePatternMetric),
kDefaultTimeout);
EXPECT_METRIC_TRUE(
expected_fingerprint == ObservedFingerprint() ||
(expected_fingerprint |
static_cast<int>(UsageEvent::PRIVATE_CANDIDATE_COLLECTED)) ==
ObservedFingerprint());
EXPECT_METRIC_EQ(absl::make_optional(ObservedFingerprint()),
caller->observer()->interesting_usage_detected());
}
TEST_F(PeerConnectionUsageHistogramTest,
NoNotableUsageOnEventFiringAfterClose) {
auto caller = CreatePeerConnection();
caller->CreateDataChannel("foo");
caller->GenerateOfferAndCollectCandidates();
int expected_fingerprint = MakeUsageFingerprint(
{UsageEvent::DATA_ADDED, UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED,
UsageEvent::CANDIDATE_COLLECTED, UsageEvent::CLOSE_CALLED});
EXPECT_METRIC_EQ(0, webrtc::metrics::NumSamples(kUsagePatternMetric));
caller->pc()->Close();
EXPECT_METRIC_EQ(1, webrtc::metrics::NumSamples(kUsagePatternMetric));
caller->GetInternalPeerConnection()->RequestUsagePatternReportForTesting();
caller->observer()->ClearInterestingUsageDetector();
EXPECT_METRIC_EQ_WAIT(2, webrtc::metrics::NumSamples(kUsagePatternMetric),
kDefaultTimeout);
EXPECT_METRIC_TRUE(
expected_fingerprint == ObservedFingerprint() ||
(expected_fingerprint |
static_cast<int>(UsageEvent::PRIVATE_CANDIDATE_COLLECTED)) ==
ObservedFingerprint());
// After close, the usage-detection callback should NOT have been called.
EXPECT_METRIC_FALSE(caller->observer()->interesting_usage_detected());
}
#endif
#endif
} // namespace webrtc