--- a/media/mtransport/test/ice_unittest.cpp
+++ b/media/mtransport/test/ice_unittest.cpp
@@ -380,17 +380,16 @@ class IceTestPeer : public sigslot::has_
// Bug 1193437.
IceTestPeer(const std::string& name, MtransportTestUtils* utils,
bool offerer,
bool allow_loopback = false, bool enable_tcp = true,
bool allow_link_local = false, bool hide_non_default = false) :
name_(name),
ice_ctx_(NrIceCtx::Create(name, offerer, allow_loopback,
enable_tcp, allow_link_local, hide_non_default)),
- streams_(),
candidates_(),
gathering_complete_(false),
ready_ct_(0),
ice_complete_(false),
ice_reached_checking_(false),
received_(0),
sent_(0),
fake_resolver_(),
@@ -425,39 +424,37 @@ class IceTestPeer : public sigslot::has_
// Give the ICE destruction callback time to fire before
// we destroy the resolver.
PR_Sleep(1000);
}
void AddStream_s(int components) {
char name[100];
snprintf(name, sizeof(name), "%s:stream%d", name_.c_str(),
- (int)streams_.size());
+ (int)ice_ctx_->GetStreamCount());
RefPtr<NrIceMediaStream> stream =
ice_ctx_->CreateStream(static_cast<char *>(name), components);
- ice_ctx_->SetStream(streams_.size(), stream);
+ ice_ctx_->SetStream(ice_ctx_->GetStreamCount(), stream);
ASSERT_TRUE(stream);
- streams_.push_back(stream);
stream->SignalCandidate.connect(this, &IceTestPeer::CandidateInitialized);
stream->SignalReady.connect(this, &IceTestPeer::StreamReady);
stream->SignalFailed.connect(this, &IceTestPeer::StreamFailed);
stream->SignalPacketReceived.connect(this, &IceTestPeer::PacketReceived);
}
void AddStream(int components)
{
test_utils_->sts_target()->Dispatch(
WrapRunnable(this, &IceTestPeer::AddStream_s, components),
NS_DISPATCH_SYNC);
}
void RemoveStream_s(size_t index) {
- streams_[index] = nullptr;
ice_ctx_->SetStream(index, nullptr);
}
void RemoveStream(size_t index) {
test_utils_->sts_target()->Dispatch(
WrapRunnable(this, &IceTestPeer::RemoveStream_s, index),
NS_DISPATCH_SYNC);
}
@@ -582,23 +579,23 @@ class IceTestPeer : public sigslot::has_
return candidate_filter_(candidate);
}
return candidate;
}
std::vector<std::string> GetCandidates_s(size_t stream) {
std::vector<std::string> candidates;
- if (stream >= streams_.size() || !streams_[stream]) {
+ if (stream >= ice_ctx_->GetStreamCount() || !ice_ctx_->GetStream(stream)) {
EXPECT_TRUE(false) << "No such stream " << stream;
return candidates;
}
std::vector<std::string> candidates_in =
- streams_[stream]->GetCandidates();
+ ice_ctx_->GetStream(stream)->GetCandidates();
for (size_t i=0; i < candidates_in.size(); i++) {
std::string candidate(FilterCandidate(candidates_in[i]));
if (!candidate.empty()) {
std::cerr << "Returning candidate: " << candidate << std::endl;
candidates.push_back(candidate);
}
@@ -643,21 +640,21 @@ class IceTestPeer : public sigslot::has_
}
}
return host_net;
}
bool gathering_complete() { return gathering_complete_; }
int ready_ct() { return ready_ct_; }
bool is_ready_s(size_t stream) {
- if (!streams_[stream]) {
+ if (!ice_ctx_->GetStream(stream)) {
EXPECT_TRUE(false) << "No such stream " << stream;
return false;
}
- return streams_[stream]->state() == NrIceMediaStream::ICE_OPEN;
+ return ice_ctx_->GetStream(stream)->state() == NrIceMediaStream::ICE_OPEN;
}
bool is_ready(size_t stream)
{
bool result;
test_utils_->sts_target()->Dispatch(
WrapRunnableRet(&result, this, &IceTestPeer::is_ready_s, stream),
NS_DISPATCH_SYNC);
return result;
@@ -676,38 +673,40 @@ class IceTestPeer : public sigslot::has_
trickle_mode_ = trickle_mode;
ice_complete_ = false;
res = ice_ctx_->ParseGlobalAttributes(remote->GetGlobalAttributes());
ASSERT_TRUE(NS_SUCCEEDED(res));
if (trickle_mode == TRICKLE_NONE ||
trickle_mode == TRICKLE_REAL) {
- for (size_t i=0; i<streams_.size(); ++i) {
- if (!streams_[i] || streams_[i]->HasParsedAttributes()) {
+ for (size_t i=0; i<ice_ctx_->GetStreamCount(); ++i) {
+ RefPtr<NrIceMediaStream> aStream = ice_ctx_->GetStream(i);
+ if (!aStream || aStream->HasParsedAttributes()) {
continue;
}
std::vector<std::string> candidates =
remote->GetCandidates(i);
for (size_t j=0; j<candidates.size(); ++j) {
std::cerr << "Candidate: " + candidates[j] << std::endl;
}
- res = streams_[i]->ParseAttributes(candidates);
+ res = aStream->ParseAttributes(candidates);
ASSERT_TRUE(NS_SUCCEEDED(res));
}
} else {
// Parse empty attributes and then trickle them out later
- for (size_t i=0; i<streams_.size(); ++i) {
- if (!streams_[i] || streams_[i]->HasParsedAttributes()) {
+ for (size_t i=0; i<ice_ctx_->GetStreamCount(); ++i) {
+ RefPtr<NrIceMediaStream> aStream = ice_ctx_->GetStream(i);
+ if (!aStream || aStream->HasParsedAttributes()) {
continue;
}
std::vector<std::string> empty_attrs;
std::cout << "Calling ParseAttributes on stream " << i << std::endl;
- res = streams_[i]->ParseAttributes(empty_attrs);
+ res = aStream->ParseAttributes(empty_attrs);
ASSERT_TRUE(NS_SUCCEEDED(res));
}
}
if (start) {
// Now start checks
res = ice_ctx_->StartChecks();
ASSERT_TRUE(NS_SUCCEEDED(res));
@@ -722,20 +721,20 @@ class IceTestPeer : public sigslot::has_
NS_DISPATCH_SYNC);
}
void SimulateTrickle(size_t stream) {
std::cerr << "Doing trickle for stream " << stream << std::endl;
// If we are in trickle deferred mode, now trickle in the candidates
// for |stream|
- // The size of streams_ is not going to change out from under us, so should
+ // The size of streams is not going to change out from under us, so should
// be safe here.
- ASSERT_GT(remote_->streams_.size(), stream);
- ASSERT_TRUE(remote_->streams_[stream]);
+ ASSERT_GT(remote_->ice_ctx_->GetStreamCount(), stream);
+ ASSERT_TRUE(remote_->ice_ctx_->GetStream(stream).get());
std::vector<SchedulableTrickleCandidate*>& candidates =
ControlTrickle(stream);
for (auto i = candidates.begin(); i != candidates.end(); ++i) {
(*i)->Schedule(0);
}
}
@@ -754,21 +753,21 @@ class IceTestPeer : public sigslot::has_
new SchedulableTrickleCandidate(
this, stream, candidates[j], test_utils_));
}
return controlled_trickle_candidates_[stream];
}
nsresult TrickleCandidate_s(const std::string &candidate, size_t stream) {
- if (!streams_[stream]) {
+ if (!ice_ctx_->GetStream(stream)) {
// stream might have gone away before the trickle timer popped
return NS_OK;
}
- return streams_[stream]->ParseTrickleCandidate(candidate);
+ return ice_ctx_->GetStream(stream)->ParseTrickleCandidate(candidate);
}
void DumpCandidate(std::string which, const NrIceCandidate& cand) {
std::string type;
std::string tcp_type;
std::string addr;
int port;
@@ -830,28 +829,28 @@ class IceTestPeer : public sigslot::has_
<< tcp_type
<< " codeword="
<< cand.codeword
<< std::endl;
}
void DumpAndCheckActiveCandidates_s() {
std::cerr << "Active candidates:" << std::endl;
- for (size_t i=0; i < streams_.size(); ++i) {
- if (!streams_[i]) {
+ for (size_t i=0; i < ice_ctx_->GetStreamCount(); ++i) {
+ if (!ice_ctx_->GetStream(i)) {
continue;
}
- for (size_t j=0; j < streams_[i]->components(); ++j) {
+ for (size_t j=0; j < ice_ctx_->GetStream(i)->components(); ++j) {
std::cerr << "Stream " << i << " component " << j+1 << std::endl;
UniquePtr<NrIceCandidate> local;
UniquePtr<NrIceCandidate> remote;
- nsresult res = streams_[i]->GetActivePair(j+1, &local, &remote);
+ nsresult res = ice_ctx_->GetStream(i)->GetActivePair(j+1, &local, &remote);
if (res == NS_ERROR_NOT_AVAILABLE) {
std::cerr << "Component unpaired or disabled." << std::endl;
} else {
ASSERT_TRUE(NS_SUCCEEDED(res));
DumpCandidate("Local ", *local);
/* Depending on timing, and the whims of the network
* stack/configuration we're running on top of, prflx is always a
* possibility. */
@@ -931,26 +930,26 @@ class IceTestPeer : public sigslot::has_
if (state != NrIceCtx::ICE_CTX_GATHER_COMPLETE) {
return;
}
std::cerr << "Gathering complete for " << name_ << std::endl;
gathering_complete_ = true;
std::cerr << "CANDIDATES:" << std::endl;
- for (size_t i=0; i<streams_.size(); ++i) {
+ for (size_t i=0; i<ice_ctx_->GetStreamCount(); ++i) {
std::cerr << "Stream " << name_ << std::endl;
- if (!streams_[i]) {
+ if (!ice_ctx_->GetStream(i)) {
std::cerr << "DISABLED" << std::endl;
continue;
}
std::vector<std::string> candidates =
- streams_[i]->GetCandidates();
+ ice_ctx_->GetStream(i)->GetCandidates();
for(size_t j=0; j<candidates.size(); ++j) {
std::cerr << candidates[j] << std::endl;
}
}
std::cerr << std::endl;
}
@@ -959,43 +958,48 @@ class IceTestPeer : public sigslot::has_
std::string candidate(FilterCandidate(raw_candidate));
if (candidate.empty()) {
return;
}
std::cerr << "Candidate for stream " << stream->name() << " initialized: "
<< candidate << std::endl;
candidates_[stream->name()].push_back(candidate);
- // If we are connected, then try to trickle to the
- // other side.
+ // If we are connected, then try to trickle to the other side.
if (remote_ && remote_->remote_ && (trickle_mode_ != TRICKLE_SIMULATE)) {
- std::vector<RefPtr<NrIceMediaStream> >::iterator it =
- std::find(streams_.begin(), streams_.end(), stream);
- ASSERT_NE(streams_.end(), it);
- size_t index = it - streams_.begin();
-
- ASSERT_GT(remote_->streams_.size(), index);
- nsresult res = remote_->streams_[index]->ParseTrickleCandidate(
+ // first, find the index of the stream we've been given so
+ // we can get the corresponding stream on the remote side
+ size_t index = -1;
+ for (size_t i=0; i<ice_ctx_->GetStreamCount(); ++i) {
+ if (ice_ctx_->GetStream(i) == stream) {
+ index = i;
+ break;
+ }
+ }
+ ASSERT_NE(index, -1);
+
+ ASSERT_GT(remote_->ice_ctx_->GetStreamCount(), index);
+ nsresult res = remote_->ice_ctx_->GetStream(index)->ParseTrickleCandidate(
candidate);
ASSERT_TRUE(NS_SUCCEEDED(res));
++trickled_;
}
}
nsresult GetCandidatePairs_s(size_t stream_index,
std::vector<NrIceCandidatePair>* pairs)
{
MOZ_ASSERT(pairs);
- if (stream_index >= streams_.size() || !streams_[stream_index]) {
+ if (stream_index >= ice_ctx_->GetStreamCount() || !ice_ctx_->GetStream(stream_index)) {
// Is there a better error for "no such index"?
ADD_FAILURE() << "No such media stream index: " << stream_index;
return NS_ERROR_INVALID_ARG;
}
- return streams_[stream_index]->GetCandidatePairs(pairs);
+ return ice_ctx_->GetStream(stream_index)->GetCandidatePairs(pairs);
}
nsresult GetCandidatePairs(size_t stream_index,
std::vector<NrIceCandidatePair>* pairs) {
nsresult v;
test_utils_->sts_target()->Dispatch(
WrapRunnableRet(&v, this,
&IceTestPeer::GetCandidatePairs_s,
@@ -1027,21 +1031,21 @@ class IceTestPeer : public sigslot::has_
p != pairs.end(); ++p) {
DumpCandidatePair(*p);
}
std::cerr << "]" << std::endl;
}
void DumpCandidatePairs_s() {
std::cerr << "Dumping candidate pairs for all streams [" << std::endl;
- for (size_t s = 0; s < streams_.size(); ++s) {
- if (!streams_[s]) {
+ for (size_t s = 0; s < ice_ctx_->GetStreamCount(); ++s) {
+ if (!ice_ctx_->GetStream(s)) {
continue;
}
- DumpCandidatePairs_s(streams_[s]);
+ DumpCandidatePairs_s(ice_ctx_->GetStream(s).get());
}
std::cerr << "]" << std::endl;
}
bool CandidatePairsPriorityDescending(const std::vector<NrIceCandidatePair>&
pairs) {
// Verify that priority is descending
uint64_t priority = std::numeric_limits<uint64_t>::max();
@@ -1150,54 +1154,54 @@ class IceTestPeer : public sigslot::has_
void PacketReceived(NrIceMediaStream *stream, int component, const unsigned char *data,
int len) {
std::cerr << "Received " << len << " bytes" << std::endl;
++received_;
}
void SendPacket(int stream, int component, const unsigned char *data,
int len) {
- if (!streams_[stream]) {
+ if (!ice_ctx_->GetStream(stream)) {
ADD_FAILURE() << "No such stream " << stream;
return;
}
- ASSERT_TRUE(NS_SUCCEEDED(streams_[stream]->SendPacket(component, data, len)));
+ ASSERT_TRUE(NS_SUCCEEDED(ice_ctx_->GetStream(stream)->SendPacket(component, data, len)));
++sent_;
std::cerr << "Sent " << len << " bytes" << std::endl;
}
void SetCandidateFilter(CandidateFilter filter) {
candidate_filter_ = filter;
}
void ParseCandidate_s(size_t i, const std::string& candidate) {
- ASSERT_TRUE(streams_[i]) << "No such stream " << i;
+ ASSERT_TRUE(ice_ctx_->GetStream(i).get()) << "No such stream " << i;
std::vector<std::string> attributes;
attributes.push_back(candidate);
- streams_[i]->ParseAttributes(attributes);
+ ice_ctx_->GetStream(i)->ParseAttributes(attributes);
}
void ParseCandidate(size_t i, const std::string& candidate)
{
test_utils_->sts_target()->Dispatch(
WrapRunnable(this,
&IceTestPeer::ParseCandidate_s,
i,
candidate),
NS_DISPATCH_SYNC);
}
void DisableComponent_s(size_t stream, int component_id) {
- ASSERT_LT(stream, streams_.size());
- ASSERT_TRUE(streams_[stream]) << "No such stream " << stream;
- nsresult res = streams_[stream]->DisableComponent(component_id);
+ ASSERT_LT(stream, ice_ctx_->GetStreamCount());
+ ASSERT_TRUE(ice_ctx_->GetStream(stream).get()) << "No such stream " << stream;
+ nsresult res = ice_ctx_->GetStream(stream)->DisableComponent(component_id);
ASSERT_TRUE(NS_SUCCEEDED(res));
}
void DisableComponent(size_t stream, int component_id)
{
test_utils_->sts_target()->Dispatch(
WrapRunnable(this,
&IceTestPeer::DisableComponent_s,
@@ -1243,23 +1247,22 @@ class IceTestPeer : public sigslot::has_
&IceTestPeer::GetDefaultCandidate_s,
stream, cand),
NS_DISPATCH_SYNC);
return rv;
}
nsresult GetDefaultCandidate_s(unsigned int stream, NrIceCandidate* cand) {
- return streams_[stream]->GetDefaultCandidate(1, cand);
+ return ice_ctx_->GetStream(stream)->GetDefaultCandidate(1, cand);
}
private:
std::string name_;
RefPtr<NrIceCtx> ice_ctx_;
- std::vector<RefPtr<NrIceMediaStream> > streams_;
std::map<std::string, std::vector<std::string> > candidates_;
// Maps from stream id to list of remote trickle candidates
std::map<size_t, std::vector<SchedulableTrickleCandidate*> >
controlled_trickle_candidates_;
bool gathering_complete_;
int ready_ct_;
bool ice_complete_;
bool ice_reached_checking_;