mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1251714 - use UniquePtr instead of ScopedDeletePtr in media/; r=jesup
UniquePtr is more standard than ScopedDeletePtr; using standard constructs whenever possible is preferable. This patch merits a couple explanations: - Where it made sense, I tried to convert: T* foo() { UniquePtr<T> x = ...; ... return x.release(); } into: UniquePtr<T> foo() with corresponding changes inside |foo|'s body. - The attentive reader will note that: auto x = MakeUnique<T>(...); is used sometimes and: UniquePtr<T> x(new T(...)); is used sometimes. I would prefer to use the former, but was stymied in several places due to protected constructors. (MakeUnique doesn't have access to those protected constructors, natch.)
This commit is contained in:
parent
d39ba6caa5
commit
b938c57967
@ -58,8 +58,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "prnetdb.h"
|
||||
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/Scoped.h"
|
||||
#include "mozilla/TimeStamp.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsIEventTarget.h"
|
||||
#include "nsITimer.h"
|
||||
@ -99,16 +99,15 @@ class NrIceStunServer {
|
||||
}
|
||||
|
||||
// The main function to use. Will take either an address or a hostname.
|
||||
static NrIceStunServer* Create(const std::string& addr, uint16_t port,
|
||||
static UniquePtr<NrIceStunServer> Create(const std::string& addr, uint16_t port,
|
||||
const char *transport = kNrIceTransportUdp) {
|
||||
ScopedDeletePtr<NrIceStunServer> server(
|
||||
new NrIceStunServer(transport));
|
||||
UniquePtr<NrIceStunServer> server(new NrIceStunServer(transport));
|
||||
|
||||
nsresult rv = server->Init(addr, port);
|
||||
if (NS_FAILED(rv))
|
||||
return nullptr;
|
||||
|
||||
return server.forget();
|
||||
return server;
|
||||
}
|
||||
|
||||
nsresult ToNicerStunStruct(nr_ice_stun_server* server) const;
|
||||
@ -146,18 +145,17 @@ class NrIceStunServer {
|
||||
|
||||
class NrIceTurnServer : public NrIceStunServer {
|
||||
public:
|
||||
static NrIceTurnServer *Create(const std::string& addr, uint16_t port,
|
||||
const std::string& username,
|
||||
const std::vector<unsigned char>& password,
|
||||
const char *transport = kNrIceTransportUdp) {
|
||||
ScopedDeletePtr<NrIceTurnServer> server(
|
||||
new NrIceTurnServer(username, password, transport));
|
||||
static UniquePtr<NrIceTurnServer> Create(const std::string& addr, uint16_t port,
|
||||
const std::string& username,
|
||||
const std::vector<unsigned char>& password,
|
||||
const char *transport = kNrIceTransportUdp) {
|
||||
UniquePtr<NrIceTurnServer> server(new NrIceTurnServer(username, password, transport));
|
||||
|
||||
nsresult rv = server->Init(addr, port);
|
||||
if (NS_FAILED(rv))
|
||||
return nullptr;
|
||||
|
||||
return server.forget();
|
||||
return server;
|
||||
}
|
||||
|
||||
nsresult ToNicerTurnStruct(nr_ice_turn_server *server) const;
|
||||
|
@ -46,7 +46,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "logging.h"
|
||||
#include "nsError.h"
|
||||
#include "mozilla/Scoped.h"
|
||||
|
||||
// nICEr includes
|
||||
extern "C" {
|
||||
@ -169,13 +168,13 @@ static bool ToNrIceCandidate(const nr_ice_candidate& candc,
|
||||
// Make an NrIceCandidate from the candidate |cand|.
|
||||
// This is not a member fxn because we want to hide the
|
||||
// defn of nr_ice_candidate but we pass by reference.
|
||||
static NrIceCandidate* MakeNrIceCandidate(const nr_ice_candidate& candc) {
|
||||
ScopedDeletePtr<NrIceCandidate> out(new NrIceCandidate());
|
||||
static UniquePtr<NrIceCandidate> MakeNrIceCandidate(const nr_ice_candidate& candc) {
|
||||
UniquePtr<NrIceCandidate> out(new NrIceCandidate());
|
||||
|
||||
if (!ToNrIceCandidate(candc, out)) {
|
||||
if (!ToNrIceCandidate(candc, out.get())) {
|
||||
return nullptr;
|
||||
}
|
||||
return out.forget();
|
||||
return out;
|
||||
}
|
||||
|
||||
// NrIceMediaStream
|
||||
@ -259,8 +258,8 @@ nsresult NrIceMediaStream::ParseTrickleCandidate(const std::string& candidate) {
|
||||
|
||||
// Returns NS_ERROR_NOT_AVAILABLE if component is unpaired or disabled.
|
||||
nsresult NrIceMediaStream::GetActivePair(int component,
|
||||
NrIceCandidate **localp,
|
||||
NrIceCandidate **remotep) {
|
||||
UniquePtr<NrIceCandidate>* localp,
|
||||
UniquePtr<NrIceCandidate>* remotep) {
|
||||
int r;
|
||||
nr_ice_candidate *local_int;
|
||||
nr_ice_candidate *remote_int;
|
||||
@ -280,20 +279,20 @@ nsresult NrIceMediaStream::GetActivePair(int component,
|
||||
if (r)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
ScopedDeletePtr<NrIceCandidate> local(
|
||||
UniquePtr<NrIceCandidate> local(
|
||||
MakeNrIceCandidate(*local_int));
|
||||
if (!local)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
ScopedDeletePtr<NrIceCandidate> remote(
|
||||
UniquePtr<NrIceCandidate> remote(
|
||||
MakeNrIceCandidate(*remote_int));
|
||||
if (!remote)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (localp)
|
||||
*localp = local.forget();
|
||||
*localp = Move(local);
|
||||
if (remotep)
|
||||
*remotep = remote.forget();
|
||||
*remotep = Move(remote);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "sigslot.h"
|
||||
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/Scoped.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIEventTarget.h"
|
||||
#include "nsITimer.h"
|
||||
@ -159,7 +159,8 @@ class NrIceMediaStream {
|
||||
// Get the candidate pair currently active. It's the
|
||||
// caller's responsibility to free these.
|
||||
nsresult GetActivePair(int component,
|
||||
NrIceCandidate** local, NrIceCandidate** remote);
|
||||
UniquePtr<NrIceCandidate>* local,
|
||||
UniquePtr<NrIceCandidate>* remote);
|
||||
|
||||
// The number of components
|
||||
size_t components() const { return components_; }
|
||||
|
@ -12,8 +12,6 @@
|
||||
#include "nss.h"
|
||||
#include "ssl.h"
|
||||
|
||||
#include "mozilla/Scoped.h"
|
||||
|
||||
extern "C" {
|
||||
#include "nr_api.h"
|
||||
#include "nr_socket.h"
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include "ssl.h"
|
||||
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/Scoped.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsXPCOM.h"
|
||||
|
||||
@ -471,7 +470,7 @@ class IceTestPeer : public sigslot::has_slots<> {
|
||||
}
|
||||
|
||||
std::vector<NrIceStunServer> stun_servers;
|
||||
ScopedDeletePtr<NrIceStunServer> server(NrIceStunServer::Create(
|
||||
UniquePtr<NrIceStunServer> server(NrIceStunServer::Create(
|
||||
addr, port, transport));
|
||||
stun_servers.push_back(*server);
|
||||
SetStunServers(stun_servers);
|
||||
@ -500,7 +499,7 @@ class IceTestPeer : public sigslot::has_slots<> {
|
||||
const std::vector<unsigned char> password,
|
||||
const char* transport) {
|
||||
std::vector<NrIceTurnServer> turn_servers;
|
||||
ScopedDeletePtr<NrIceTurnServer> server(NrIceTurnServer::Create(
|
||||
UniquePtr<NrIceTurnServer> server(NrIceTurnServer::Create(
|
||||
addr, port, username, password, transport));
|
||||
turn_servers.push_back(*server);
|
||||
ASSERT_TRUE(NS_SUCCEEDED(ice_ctx_->SetTurnServers(turn_servers)));
|
||||
@ -844,8 +843,8 @@ class IceTestPeer : public sigslot::has_slots<> {
|
||||
for (size_t j=0; j < streams_[i]->components(); ++j) {
|
||||
std::cerr << "Stream " << i << " component " << j+1 << std::endl;
|
||||
|
||||
NrIceCandidate *local;
|
||||
NrIceCandidate *remote;
|
||||
UniquePtr<NrIceCandidate> local;
|
||||
UniquePtr<NrIceCandidate> remote;
|
||||
|
||||
nsresult res = streams_[i]->GetActivePair(j+1, &local, &remote);
|
||||
if (res == NS_ERROR_NOT_AVAILABLE) {
|
||||
@ -876,8 +875,6 @@ class IceTestPeer : public sigslot::has_slots<> {
|
||||
if (!expected_remote_addr_.empty()) {
|
||||
ASSERT_EQ(expected_remote_addr_, remote->cand_addr.host);
|
||||
}
|
||||
delete local;
|
||||
delete remote;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1315,12 +1312,12 @@ class IceGatherTest : public StunTest {
|
||||
|
||||
void EnsurePeer(const unsigned int flags = ICE_TEST_PEER_OFFERER) {
|
||||
if (!peer_) {
|
||||
peer_ = new IceTestPeer("P1", test_utils_,
|
||||
flags & ICE_TEST_PEER_OFFERER,
|
||||
flags & ICE_TEST_PEER_ALLOW_LOOPBACK,
|
||||
flags & ICE_TEST_PEER_ENABLED_TCP,
|
||||
flags & ICE_TEST_PEER_ALLOW_LINK_LOCAL,
|
||||
flags & ICE_TEST_PEER_HIDE_NON_DEFAULT);
|
||||
peer_ = MakeUnique<IceTestPeer>("P1", test_utils_,
|
||||
flags & ICE_TEST_PEER_OFFERER,
|
||||
flags & ICE_TEST_PEER_ALLOW_LOOPBACK,
|
||||
flags & ICE_TEST_PEER_ENABLED_TCP,
|
||||
flags & ICE_TEST_PEER_ALLOW_LINK_LOCAL,
|
||||
flags & ICE_TEST_PEER_HIDE_NON_DEFAULT);
|
||||
peer_->AddStream(1);
|
||||
}
|
||||
}
|
||||
@ -1453,7 +1450,7 @@ class IceGatherTest : public StunTest {
|
||||
}
|
||||
|
||||
protected:
|
||||
mozilla::ScopedDeletePtr<IceTestPeer> peer_;
|
||||
mozilla::UniquePtr<IceTestPeer> peer_;
|
||||
};
|
||||
|
||||
class IceConnectTest : public StunTest {
|
||||
@ -1493,10 +1490,10 @@ class IceConnectTest : public StunTest {
|
||||
|
||||
void Init(bool allow_loopback, bool enable_tcp, bool default_only = false) {
|
||||
if (!initted_) {
|
||||
p1_ = new IceTestPeer("P1", test_utils_, true, allow_loopback,
|
||||
enable_tcp, false, default_only);
|
||||
p2_ = new IceTestPeer("P2", test_utils_, false, allow_loopback,
|
||||
enable_tcp, false, default_only);
|
||||
p1_ = MakeUnique<IceTestPeer>("P1", test_utils_, true, allow_loopback,
|
||||
enable_tcp, false, default_only);
|
||||
p2_ = MakeUnique<IceTestPeer>("P2", test_utils_, false, allow_loopback,
|
||||
enable_tcp, false, default_only);
|
||||
}
|
||||
initted_ = true;
|
||||
}
|
||||
@ -1593,8 +1590,8 @@ class IceConnectTest : public StunTest {
|
||||
// to |this|, meaning that p2_->Connect(p1_, ...) simulates p1 sending an
|
||||
// offer to p2. Order matters here because it determines which peer is
|
||||
// controlling.
|
||||
p2_->Connect(p1_, TRICKLE_NONE);
|
||||
p1_->Connect(p2_, TRICKLE_NONE);
|
||||
p2_->Connect(p1_.get(), TRICKLE_NONE);
|
||||
p1_->Connect(p2_.get(), TRICKLE_NONE);
|
||||
|
||||
ASSERT_TRUE_WAIT(p1_->ready_ct() == 1 && p2_->ready_ct() == 1,
|
||||
kDefaultTimeout);
|
||||
@ -1624,11 +1621,11 @@ class IceConnectTest : public StunTest {
|
||||
}
|
||||
|
||||
void ConnectP1(TrickleMode mode = TRICKLE_NONE) {
|
||||
p1_->Connect(p2_, mode);
|
||||
p1_->Connect(p2_.get(), mode);
|
||||
}
|
||||
|
||||
void ConnectP2(TrickleMode mode = TRICKLE_NONE) {
|
||||
p2_->Connect(p1_, mode);
|
||||
p2_->Connect(p1_.get(), mode);
|
||||
}
|
||||
|
||||
void WaitForComplete(int expected_streams = 1) {
|
||||
@ -1649,8 +1646,8 @@ class IceConnectTest : public StunTest {
|
||||
}
|
||||
|
||||
void ConnectTrickle(TrickleMode trickle = TRICKLE_SIMULATE) {
|
||||
p2_->Connect(p1_, trickle);
|
||||
p1_->Connect(p2_, trickle);
|
||||
p2_->Connect(p1_.get(), trickle);
|
||||
p1_->Connect(p2_.get(), trickle);
|
||||
}
|
||||
|
||||
void SimulateTrickle(size_t stream) {
|
||||
@ -1676,8 +1673,8 @@ class IceConnectTest : public StunTest {
|
||||
}
|
||||
|
||||
void ConnectThenDelete() {
|
||||
p2_->Connect(p1_, TRICKLE_NONE, false);
|
||||
p1_->Connect(p2_, TRICKLE_NONE, true);
|
||||
p2_->Connect(p1_.get(), TRICKLE_NONE, false);
|
||||
p1_->Connect(p2_.get(), TRICKLE_NONE, true);
|
||||
test_utils_->sts_target()->Dispatch(WrapRunnable(this,
|
||||
&IceConnectTest::CloseP1),
|
||||
NS_DISPATCH_SYNC);
|
||||
@ -1701,8 +1698,8 @@ class IceConnectTest : public StunTest {
|
||||
protected:
|
||||
bool initted_;
|
||||
nsCOMPtr<nsIEventTarget> target_;
|
||||
mozilla::ScopedDeletePtr<IceTestPeer> p1_;
|
||||
mozilla::ScopedDeletePtr<IceTestPeer> p2_;
|
||||
mozilla::UniquePtr<IceTestPeer> p1_;
|
||||
mozilla::UniquePtr<IceTestPeer> p2_;
|
||||
bool use_nat_;
|
||||
TestNat::NatBehavior filtering_type_;
|
||||
TestNat::NatBehavior mapping_type_;
|
||||
@ -1860,7 +1857,7 @@ TEST_F(IceGatherTest, TestGatherStunServerIpAddressDefaultRouteOnly) {
|
||||
return;
|
||||
}
|
||||
|
||||
peer_ = new IceTestPeer("P1", test_utils_, true, false, false, false, true);
|
||||
peer_ = MakeUnique<IceTestPeer>("P1", test_utils_, true, false, false, false, true);
|
||||
peer_->AddStream(1);
|
||||
peer_->SetStunServer(stun_server_address_, kDefaultStunServerPort);
|
||||
peer_->SetFakeResolver(stun_server_address_, stun_server_hostname_);
|
||||
@ -2049,7 +2046,7 @@ TEST_F(IceGatherTest, TestGatherVerifyNoLoopback) {
|
||||
|
||||
TEST_F(IceGatherTest, TestGatherAllowLoopback) {
|
||||
// Set up peer with loopback allowed.
|
||||
peer_ = new IceTestPeer("P1", test_utils_, true, true);
|
||||
peer_ = MakeUnique<IceTestPeer>("P1", test_utils_, true, true);
|
||||
peer_->AddStream(1);
|
||||
Gather();
|
||||
ASSERT_TRUE(StreamHasMatchingCandidate(0, "127.0.0.1"));
|
||||
@ -2057,7 +2054,7 @@ TEST_F(IceGatherTest, TestGatherAllowLoopback) {
|
||||
|
||||
TEST_F(IceGatherTest, TestGatherTcpDisabled) {
|
||||
// Set up peer with tcp disabled.
|
||||
peer_ = new IceTestPeer("P1", test_utils_, true, false, false);
|
||||
peer_ = MakeUnique<IceTestPeer>("P1", test_utils_, true, false, false);
|
||||
peer_->AddStream(1);
|
||||
Gather();
|
||||
ASSERT_FALSE(StreamHasMatchingCandidate(0, " TCP "));
|
||||
@ -2160,7 +2157,7 @@ TEST_F(IceGatherTest, TestStunServerTrickle) {
|
||||
// Test default route only with our fake STUN server and
|
||||
// apparently NATted.
|
||||
TEST_F(IceGatherTest, TestFakeStunServerNatedDefaultRouteOnly) {
|
||||
peer_ = new IceTestPeer("P1", test_utils_, true, false, false, false, true);
|
||||
peer_ = MakeUnique<IceTestPeer>("P1", test_utils_, true, false, false, false, true);
|
||||
peer_->AddStream(1);
|
||||
UseFakeStunUdpServerWithResponse("192.0.2.1", 3333);
|
||||
Gather(0);
|
||||
@ -2178,7 +2175,7 @@ TEST_F(IceGatherTest, TestFakeStunServerNatedDefaultRouteOnly) {
|
||||
// Test default route only with our fake STUN server and
|
||||
// apparently non-NATted.
|
||||
TEST_F(IceGatherTest, TestFakeStunServerNoNatDefaultRouteOnly) {
|
||||
peer_ = new IceTestPeer("P1", test_utils_, true, false, false, false, true);
|
||||
peer_ = MakeUnique<IceTestPeer>("P1", test_utils_, true, false, false, false, true);
|
||||
peer_->AddStream(1);
|
||||
UseTestStunServer();
|
||||
Gather(0);
|
||||
@ -3057,10 +3054,8 @@ TEST_F(IceConnectTest, TestHostCandPairingFilter) {
|
||||
}
|
||||
|
||||
ConnectTrickle();
|
||||
AddNonPairableCandidates(p1_->ControlTrickle(0), p1_, 0, host_net,
|
||||
test_utils_);
|
||||
AddNonPairableCandidates(p2_->ControlTrickle(0), p2_, 0, host_net,
|
||||
test_utils_);
|
||||
AddNonPairableCandidates(p1_->ControlTrickle(0), p1_.get(), 0, host_net, test_utils_);
|
||||
AddNonPairableCandidates(p2_->ControlTrickle(0), p2_.get(), 0, host_net, test_utils_);
|
||||
|
||||
std::vector<NrIceCandidatePair> pairs;
|
||||
p1_->GetCandidatePairs(0, &pairs);
|
||||
@ -3121,8 +3116,8 @@ TEST_F(IceConnectTest, TestPollCandPairsDuringConnect) {
|
||||
AddStream("first", 1);
|
||||
ASSERT_TRUE(Gather());
|
||||
|
||||
p2_->Connect(p1_, TRICKLE_NONE, false);
|
||||
p1_->Connect(p2_, TRICKLE_NONE, false);
|
||||
p2_->Connect(p1_.get(), TRICKLE_NONE, false);
|
||||
p1_->Connect(p2_.get(), TRICKLE_NONE, false);
|
||||
|
||||
std::vector<NrIceCandidatePair> pairs1;
|
||||
std::vector<NrIceCandidatePair> pairs2;
|
||||
@ -3146,8 +3141,8 @@ TEST_F(IceConnectTest, TestRLogRingBuffer) {
|
||||
AddStream("first", 1);
|
||||
ASSERT_TRUE(Gather());
|
||||
|
||||
p2_->Connect(p1_, TRICKLE_NONE, false);
|
||||
p1_->Connect(p2_, TRICKLE_NONE, false);
|
||||
p2_->Connect(p1_.get(), TRICKLE_NONE, false);
|
||||
p1_->Connect(p2_.get(), TRICKLE_NONE, false);
|
||||
|
||||
std::vector<NrIceCandidatePair> pairs1;
|
||||
std::vector<NrIceCandidatePair> pairs2;
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "mozilla/Scoped.h"
|
||||
#include "mozilla/Atomics.h"
|
||||
#include "runnable_utils.h"
|
||||
#include "nss.h"
|
||||
@ -106,7 +105,7 @@ class MultiTcpSocketTest : public MtransportTest {
|
||||
|
||||
if (!stun_server_addr.empty()) {
|
||||
std::vector<NrIceStunServer> stun_servers;
|
||||
ScopedDeletePtr<NrIceStunServer> server(NrIceStunServer::Create(
|
||||
UniquePtr<NrIceStunServer> server(NrIceStunServer::Create(
|
||||
stun_server_addr, stun_server_port, kNrIceTransportTcp));
|
||||
stun_servers.push_back(*server);
|
||||
|
||||
|
@ -12,8 +12,6 @@
|
||||
#include "nss.h"
|
||||
#include "ssl.h"
|
||||
|
||||
#include "mozilla/Scoped.h"
|
||||
|
||||
extern "C" {
|
||||
#include "nr_api.h"
|
||||
#include "nr_socket.h"
|
||||
|
@ -78,7 +78,8 @@ nrappkit copyright:
|
||||
ekr@rtfm.com Thu Dec 20 20:14:49 2001
|
||||
*/
|
||||
#include "logging.h"
|
||||
#include "mozilla/Scoped.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "mozilla/unused.h"
|
||||
#include "databuffer.h"
|
||||
|
||||
extern "C" {
|
||||
@ -174,7 +175,7 @@ static nr_socket_vtbl nr_socket_wrapped_vtbl = {
|
||||
};
|
||||
|
||||
int nr_socket_wrapped_create(nr_socket *inner, nr_socket **outp) {
|
||||
ScopedDeletePtr<nr_socket_wrapped> wrapped(new nr_socket_wrapped());
|
||||
auto wrapped = MakeUnique<nr_socket_wrapped>();
|
||||
|
||||
wrapped->sock_ = inner;
|
||||
|
||||
@ -182,7 +183,7 @@ int nr_socket_wrapped_create(nr_socket *inner, nr_socket **outp) {
|
||||
if (r)
|
||||
return r;
|
||||
|
||||
wrapped.forget();
|
||||
Unused << wrapped.release();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -323,10 +324,10 @@ int TestStunServer::Initialize(int address_family) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
TestStunServer* TestStunServer::Create(int address_family) {
|
||||
UniquePtr<TestStunServer> TestStunServer::Create(int address_family) {
|
||||
NR_reg_init(NR_REG_MODE_LOCAL);
|
||||
|
||||
ScopedDeletePtr<TestStunServer> server(new TestStunServer());
|
||||
UniquePtr<TestStunServer> server(new TestStunServer());
|
||||
|
||||
if (server->Initialize(address_family))
|
||||
return nullptr;
|
||||
@ -340,7 +341,7 @@ TestStunServer* TestStunServer::Create(int address_family) {
|
||||
|
||||
NR_ASYNC_WAIT(fd, NR_ASYNC_WAIT_READ, &TestStunServer::readable_cb, server.get());
|
||||
|
||||
return server.forget();
|
||||
return server;
|
||||
}
|
||||
|
||||
void TestStunServer::ConfigurePort(uint16_t port) {
|
||||
@ -351,13 +352,13 @@ TestStunServer* TestStunServer::GetInstance(int address_family) {
|
||||
switch (address_family) {
|
||||
case AF_INET:
|
||||
if (!instance)
|
||||
instance = Create(address_family);
|
||||
instance = Create(address_family).release();
|
||||
|
||||
MOZ_ASSERT(instance);
|
||||
return instance;
|
||||
case AF_INET6:
|
||||
if (!instance6)
|
||||
instance6 = Create(address_family);
|
||||
instance6 = Create(address_family).release();
|
||||
|
||||
return instance6;
|
||||
default:
|
||||
@ -535,13 +536,13 @@ TestStunTcpServer* TestStunTcpServer::GetInstance(int address_family) {
|
||||
switch (address_family) {
|
||||
case AF_INET:
|
||||
if (!instance)
|
||||
instance = Create(address_family);
|
||||
instance = Create(address_family).release();
|
||||
|
||||
MOZ_ASSERT(instance);
|
||||
return instance;
|
||||
case AF_INET6:
|
||||
if (!instance6)
|
||||
instance6 = Create(address_family);
|
||||
instance6 = Create(address_family).release();
|
||||
|
||||
return instance6;
|
||||
default:
|
||||
@ -632,10 +633,10 @@ void TestStunTcpServer::accept_cb(NR_SOCKET s, int how, void *cb_arg) {
|
||||
NR_ASYNC_WAIT(fd, NR_ASYNC_WAIT_READ, &TestStunServer::readable_cb, server);
|
||||
}
|
||||
|
||||
TestStunTcpServer* TestStunTcpServer::Create(int address_family) {
|
||||
UniquePtr<TestStunTcpServer> TestStunTcpServer::Create(int address_family) {
|
||||
NR_reg_init(NR_REG_MODE_LOCAL);
|
||||
|
||||
ScopedDeletePtr<TestStunTcpServer> server(new TestStunTcpServer());
|
||||
UniquePtr<TestStunTcpServer> server(new TestStunTcpServer());
|
||||
|
||||
if (server->Initialize(address_family)) {
|
||||
return nullptr;
|
||||
@ -649,7 +650,7 @@ TestStunTcpServer* TestStunTcpServer::Create(int address_family) {
|
||||
|
||||
NR_ASYNC_WAIT(fd, NR_ASYNC_WAIT_READ, &TestStunTcpServer::accept_cb, server.get());
|
||||
|
||||
return server.forget();
|
||||
return server;
|
||||
}
|
||||
|
||||
TestStunTcpServer::~TestStunTcpServer() {
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <string>
|
||||
#include "prio.h"
|
||||
#include "nsError.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
|
||||
typedef struct nr_stun_server_ctx_ nr_stun_server_ctx;
|
||||
typedef struct nr_socket_ nr_socket;
|
||||
@ -31,7 +32,7 @@ class TestStunServer {
|
||||
// to |GetInstance| (possibly following a |ShutdownInstance| call)
|
||||
static void ConfigurePort(uint16_t port);
|
||||
// AF_INET, AF_INET6
|
||||
static TestStunServer *Create(int address_family);
|
||||
static UniquePtr<TestStunServer> Create(int address_family);
|
||||
|
||||
virtual ~TestStunServer();
|
||||
|
||||
@ -110,7 +111,7 @@ class TestStunTcpServer: public TestStunServer {
|
||||
|
||||
private:
|
||||
virtual int TryOpenListenSocket(nr_local_addr *addr, uint16_t port);
|
||||
static TestStunTcpServer *Create(int address_family);
|
||||
static UniquePtr<TestStunTcpServer> Create(int address_family);
|
||||
|
||||
static TestStunTcpServer *instance;
|
||||
static TestStunTcpServer *instance6;
|
||||
|
@ -49,7 +49,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "nss.h"
|
||||
#include "ssl.h"
|
||||
|
||||
#include "mozilla/Scoped.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsXPCOM.h"
|
||||
|
||||
|
@ -35,14 +35,14 @@ TransportFlow::~TransportFlow() {
|
||||
// destroy it simultaneously. The conversion to an nsAutoPtr
|
||||
// ensures automatic destruction of the queue at exit of
|
||||
// DestroyFinal.
|
||||
nsAutoPtr<std::deque<TransportLayer*> > layers_tmp(layers_.forget());
|
||||
nsAutoPtr<std::deque<TransportLayer*>> layers_tmp(layers_.release());
|
||||
RUN_ON_THREAD(target_,
|
||||
WrapRunnableNM(&TransportFlow::DestroyFinal, layers_tmp),
|
||||
NS_DISPATCH_NORMAL);
|
||||
}
|
||||
|
||||
void TransportFlow::DestroyFinal(nsAutoPtr<std::deque<TransportLayer *> > layers) {
|
||||
ClearLayers(layers);
|
||||
ClearLayers(layers.get());
|
||||
}
|
||||
|
||||
void TransportFlow::ClearLayers(std::queue<TransportLayer *>* layers) {
|
||||
@ -61,7 +61,7 @@ void TransportFlow::ClearLayers(std::deque<TransportLayer *>* layers) {
|
||||
|
||||
nsresult TransportFlow::PushLayer(TransportLayer *layer) {
|
||||
CheckThread();
|
||||
ScopedDeletePtr<TransportLayer> layer_tmp(layer); // Destroy on failure.
|
||||
UniquePtr<TransportLayer> layer_tmp(layer); // Destroy on failure.
|
||||
|
||||
// Don't allow pushes once we are in error state.
|
||||
if (state_ == TransportLayer::TS_ERROR) {
|
||||
@ -90,7 +90,7 @@ nsresult TransportFlow::PushLayer(TransportLayer *layer) {
|
||||
old_layer->SignalStateChange.disconnect(this);
|
||||
old_layer->SignalPacketReceived.disconnect(this);
|
||||
}
|
||||
layers_->push_front(layer_tmp.forget());
|
||||
layers_->push_front(layer_tmp.release());
|
||||
layer->Inserted(this, old_layer);
|
||||
|
||||
layer->SignalStateChange.connect(this, &TransportFlow::StateChange);
|
||||
@ -146,11 +146,11 @@ nsresult TransportFlow::PushLayers(nsAutoPtr<std::queue<TransportLayer *> > laye
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
// Destroy any layers we could not push.
|
||||
ClearLayers(layers);
|
||||
ClearLayers(layers.get());
|
||||
|
||||
// Now destroy the rest of the flow, because it's no longer
|
||||
// in an acceptable state.
|
||||
ClearLayers(layers_);
|
||||
ClearLayers(layers_.get());
|
||||
|
||||
// Set ourselves to have failed.
|
||||
StateChangeInt(TransportLayer::TS_ERROR);
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "mozilla/Scoped.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "transportlayer.h"
|
||||
#include "m_cpp_utils.h"
|
||||
#include "nsAutoPtr.h"
|
||||
@ -135,7 +135,7 @@ class TransportFlow final : public nsISupports,
|
||||
|
||||
std::string id_;
|
||||
TransportLayer::State state_;
|
||||
ScopedDeletePtr<std::deque<TransportLayer *> > layers_;
|
||||
UniquePtr<std::deque<TransportLayer *>> layers_;
|
||||
nsCOMPtr<nsIEventTarget> target_;
|
||||
};
|
||||
|
||||
|
@ -463,7 +463,7 @@ bool TransportLayerDtls::Setup() {
|
||||
MOZ_MTLOG(ML_ERROR, "DTLS layer with nothing below. This is useless");
|
||||
return false;
|
||||
}
|
||||
nspr_io_adapter_ = new TransportLayerNSPRAdapter(downward_);
|
||||
nspr_io_adapter_ = MakeUnique<TransportLayerNSPRAdapter>(downward_);
|
||||
|
||||
if (!identity_) {
|
||||
MOZ_MTLOG(ML_ERROR, "Can't start DTLS without an identity");
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include "sigslot.h"
|
||||
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/Scoped.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIEventTarget.h"
|
||||
#include "nsITimer.h"
|
||||
@ -177,7 +177,7 @@ class TransportLayerDtls final : public TransportLayer {
|
||||
|
||||
// Must delete nspr_io_adapter after ssl_fd_ b/c ssl_fd_ causes an alert
|
||||
// (ssl_fd_ contains an un-owning pointer to nspr_io_adapter_)
|
||||
ScopedDeletePtr<TransportLayerNSPRAdapter> nspr_io_adapter_;
|
||||
UniquePtr<TransportLayerNSPRAdapter> nspr_io_adapter_;
|
||||
ScopedPRFileDesc ssl_fd_;
|
||||
|
||||
ScopedCERTCertificate peer_cert_;
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include "sigslot.h"
|
||||
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/Scoped.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIEventTarget.h"
|
||||
#include "nsITimer.h"
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include <vector>
|
||||
|
||||
#include "mozilla/Move.h"
|
||||
#include "mozilla/Scoped.h"
|
||||
#include "mozilla/SyncRunnable.h"
|
||||
#include "VideoConduit.h"
|
||||
#include "AudioConduit.h"
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include "MediaCodec.h"
|
||||
#include "WebrtcMediaCodecVP8VideoCodec.h"
|
||||
#include "AndroidJNIWrapper.h"
|
||||
#include "mozilla/Scoped.h"
|
||||
#include "mozilla/ArrayUtils.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "mozilla/Monitor.h"
|
||||
|
@ -513,11 +513,10 @@ void MediaPipeline::RtpPacketReceived(TransportLayer *layer,
|
||||
}
|
||||
|
||||
// Make a copy rather than cast away constness
|
||||
ScopedDeletePtr<unsigned char> inner_data(
|
||||
new unsigned char[len]);
|
||||
memcpy(inner_data, data, len);
|
||||
auto inner_data = MakeUnique<unsigned char[]>(len);
|
||||
memcpy(inner_data.get(), data, len);
|
||||
int out_len = 0;
|
||||
nsresult res = rtp_.recv_srtp_->UnprotectRtp(inner_data,
|
||||
nsresult res = rtp_.recv_srtp_->UnprotectRtp(inner_data.get(),
|
||||
len, len, &out_len);
|
||||
if (!NS_SUCCEEDED(res)) {
|
||||
char tmp[16];
|
||||
@ -536,7 +535,7 @@ void MediaPipeline::RtpPacketReceived(TransportLayer *layer,
|
||||
MOZ_MTLOG(ML_DEBUG, description_ << " received RTP packet.");
|
||||
increment_rtp_packets_received(out_len);
|
||||
|
||||
(void)conduit_->ReceivedRTPPacket(inner_data, out_len); // Ignore error codes
|
||||
(void)conduit_->ReceivedRTPPacket(inner_data.get(), out_len); // Ignore error codes
|
||||
}
|
||||
|
||||
void MediaPipeline::RtcpPacketReceived(TransportLayer *layer,
|
||||
@ -572,12 +571,11 @@ void MediaPipeline::RtcpPacketReceived(TransportLayer *layer,
|
||||
}
|
||||
|
||||
// Make a copy rather than cast away constness
|
||||
ScopedDeletePtr<unsigned char> inner_data(
|
||||
new unsigned char[len]);
|
||||
memcpy(inner_data, data, len);
|
||||
auto inner_data = MakeUnique<unsigned char[]>(len);
|
||||
memcpy(inner_data.get(), data, len);
|
||||
int out_len;
|
||||
|
||||
nsresult res = rtcp_.recv_srtp_->UnprotectRtcp(inner_data,
|
||||
nsresult res = rtcp_.recv_srtp_->UnprotectRtcp(inner_data.get(),
|
||||
len,
|
||||
len,
|
||||
&out_len);
|
||||
@ -588,7 +586,7 @@ void MediaPipeline::RtcpPacketReceived(TransportLayer *layer,
|
||||
// We do not filter RTCP for send pipelines, since the webrtc.org code for
|
||||
// senders already has logic to ignore RRs that do not apply.
|
||||
if (filter_ && direction_ == RECEIVE) {
|
||||
if (!filter_->FilterSenderReport(inner_data, out_len)) {
|
||||
if (!filter_->FilterSenderReport(inner_data.get(), out_len)) {
|
||||
MOZ_MTLOG(ML_NOTICE, "Dropping rtcp packet");
|
||||
return;
|
||||
}
|
||||
@ -599,7 +597,7 @@ void MediaPipeline::RtcpPacketReceived(TransportLayer *layer,
|
||||
|
||||
MOZ_ASSERT(rtcp_.recv_srtp_); // This should never happen
|
||||
|
||||
(void)conduit_->ReceivedRTCPPacket(inner_data, out_len); // Ignore error codes
|
||||
(void)conduit_->ReceivedRTCPPacket(inner_data.get(), out_len); // Ignore error codes
|
||||
}
|
||||
|
||||
bool MediaPipeline::IsRtp(const unsigned char *data, size_t len) {
|
||||
|
@ -125,10 +125,10 @@ JsepCodecDescToCodecConfig(const JsepCodecDescription& aCodec,
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ScopedDeletePtr<VideoCodecConfigH264> h264Config;
|
||||
UniquePtr<VideoCodecConfigH264> h264Config;
|
||||
|
||||
if (desc.mName == "H264") {
|
||||
h264Config = new VideoCodecConfigH264;
|
||||
h264Config = MakeUnique<VideoCodecConfigH264>();
|
||||
size_t spropSize = sizeof(h264Config->sprop_parameter_sets);
|
||||
strncpy(h264Config->sprop_parameter_sets,
|
||||
desc.mSpropParameterSets.c_str(),
|
||||
@ -141,7 +141,7 @@ JsepCodecDescToCodecConfig(const JsepCodecDescription& aCodec,
|
||||
|
||||
VideoCodecConfig* configRaw;
|
||||
configRaw = new VideoCodecConfig(
|
||||
pt, desc.mName, desc.mConstraints, h264Config);
|
||||
pt, desc.mName, desc.mConstraints, h264Config.get());
|
||||
|
||||
configRaw->mAckFbTypes = desc.mAckFbTypes;
|
||||
configRaw->mNackFbTypes = desc.mNackFbTypes;
|
||||
|
@ -157,12 +157,11 @@ public:
|
||||
bool addStunServer(const std::string& addr, uint16_t port,
|
||||
const char* transport)
|
||||
{
|
||||
NrIceStunServer* server(NrIceStunServer::Create(addr, port, transport));
|
||||
UniquePtr<NrIceStunServer> server(NrIceStunServer::Create(addr, port, transport));
|
||||
if (!server) {
|
||||
return false;
|
||||
}
|
||||
addStunServer(*server);
|
||||
delete server;
|
||||
return true;
|
||||
}
|
||||
bool addTurnServer(const std::string& addr, uint16_t port,
|
||||
@ -174,13 +173,12 @@ public:
|
||||
// username and password. Bug # ???
|
||||
std::vector<unsigned char> password(pwd.begin(), pwd.end());
|
||||
|
||||
NrIceTurnServer* server(NrIceTurnServer::Create(addr, port, username, password,
|
||||
transport));
|
||||
UniquePtr<NrIceTurnServer> server(NrIceTurnServer::Create(addr, port, username, password,
|
||||
transport));
|
||||
if (!server) {
|
||||
return false;
|
||||
}
|
||||
addTurnServer(*server);
|
||||
delete server;
|
||||
return true;
|
||||
}
|
||||
void addStunServer(const NrIceStunServer& server) { mStunServers.push_back (server); }
|
||||
|
@ -11,8 +11,8 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "mozilla/Scoped.h"
|
||||
#include "mozilla/SyncRunnable.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include <MediaConduitInterface.h>
|
||||
#include "GmpVideoCodec.h"
|
||||
#include "nsIEventTarget.h"
|
||||
@ -92,8 +92,8 @@ public:
|
||||
{
|
||||
mSession = aSession;
|
||||
mLen = ((width * height) * 3 / 2);
|
||||
mFrame = (uint8_t*) PR_MALLOC(mLen);
|
||||
memset(mFrame, COLOR, mLen);
|
||||
mFrame = mozilla::MakeUnique<uint8_t[]>(mLen);
|
||||
memset(mFrame.get(), COLOR, mLen);
|
||||
numFrames = 121;
|
||||
}
|
||||
|
||||
@ -101,7 +101,7 @@ public:
|
||||
{
|
||||
do
|
||||
{
|
||||
mSession->SendVideoFrame((unsigned char*)mFrame,
|
||||
mSession->SendVideoFrame(reinterpret_cast<unsigned char*>(mFrame.get()),
|
||||
mLen,
|
||||
width,
|
||||
height,
|
||||
@ -115,7 +115,7 @@ public:
|
||||
|
||||
private:
|
||||
RefPtr<mozilla::VideoSessionConduit> mSession;
|
||||
mozilla::ScopedDeletePtr<uint8_t> mFrame;
|
||||
mozilla::UniquePtr<uint8_t[]> mFrame;
|
||||
int mLen;
|
||||
int width, height;
|
||||
int rate;
|
||||
@ -290,8 +290,8 @@ void AudioSendAndReceive::GenerateMusic(short* buf, int len)
|
||||
//Hardcoded for 16 bit samples for now
|
||||
void AudioSendAndReceive::GenerateAndReadSamples()
|
||||
{
|
||||
mozilla::ScopedDeletePtr<int16_t> audioInput(new int16_t [PLAYOUT_SAMPLE_LENGTH]);
|
||||
mozilla::ScopedDeletePtr<int16_t> audioOutput(new int16_t [PLAYOUT_SAMPLE_LENGTH]);
|
||||
auto audioInput = mozilla::MakeUnique<int16_t []>(PLAYOUT_SAMPLE_LENGTH);
|
||||
auto audioOutput = mozilla::MakeUnique<int16_t []>(PLAYOUT_SAMPLE_LENGTH);
|
||||
short* inbuf;
|
||||
int sampleLengthDecoded = 0;
|
||||
unsigned int SAMPLES = (PLAYOUT_SAMPLE_FREQUENCY * 10); //10 seconds
|
||||
|
@ -1688,19 +1688,19 @@ class SignalingAgentTest : public ::testing::Test {
|
||||
}
|
||||
|
||||
bool CreateAgent(const std::string stun_addr, uint16_t stun_port) {
|
||||
ScopedDeletePtr<SignalingAgent> agent(
|
||||
UniquePtr<SignalingAgent> agent(
|
||||
new SignalingAgent("agent", stun_addr, stun_port));
|
||||
|
||||
agent->Init();
|
||||
|
||||
agents_.push_back(agent.forget());
|
||||
agents_.push_back(agent.release());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CreateAgentNoInit() {
|
||||
ScopedDeletePtr<SignalingAgent> agent(new SignalingAgent("agent"));
|
||||
agents_.push_back(agent.forget());
|
||||
UniquePtr<SignalingAgent> agent(new SignalingAgent("agent"));
|
||||
agents_.push_back(agent.release());
|
||||
}
|
||||
|
||||
SignalingAgent *agent(size_t i) {
|
||||
@ -1749,8 +1749,8 @@ public:
|
||||
if (init_)
|
||||
return;
|
||||
|
||||
a1_ = new SignalingAgent(callerName, stun_addr_, stun_port_);
|
||||
a2_ = new SignalingAgent(calleeName, stun_addr_, stun_port_);
|
||||
a1_ = MakeUnique<SignalingAgent>(callerName, stun_addr_, stun_port_);
|
||||
a2_ = MakeUnique<SignalingAgent>(calleeName, stun_addr_, stun_port_);
|
||||
|
||||
if (GetParam() == "no_bundle") {
|
||||
a1_->SetBundleEnabled(false);
|
||||
@ -2170,8 +2170,8 @@ public:
|
||||
|
||||
protected:
|
||||
bool init_;
|
||||
ScopedDeletePtr<SignalingAgent> a1_; // Canonically "caller"
|
||||
ScopedDeletePtr<SignalingAgent> a2_; // Canonically "callee"
|
||||
UniquePtr<SignalingAgent> a1_; // Canonically "caller"
|
||||
UniquePtr<SignalingAgent> a2_; // Canonically "callee"
|
||||
std::string stun_addr_;
|
||||
uint16_t stun_port_;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user