From b938c57967773a09b6d51afb6dfeb145aafd24d3 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Wed, 2 Mar 2016 15:28:27 -0500 Subject: [PATCH] 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 x = ...; ... return x.release(); } into: UniquePtr foo() with corresponding changes inside |foo|'s body. - The attentive reader will note that: auto x = MakeUnique(...); is used sometimes and: UniquePtr 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.) --- media/mtransport/nricectx.h | 22 +++--- media/mtransport/nricemediastream.cpp | 21 +++-- media/mtransport/nricemediastream.h | 5 +- .../test/buffered_stun_socket_unittest.cpp | 2 - media/mtransport/test/ice_unittest.cpp | 77 +++++++++---------- .../test/multi_tcp_socket_unittest.cpp | 3 +- .../test/proxy_tunnel_socket_unittest.cpp | 2 - media/mtransport/test/stunserver.cpp | 27 +++---- media/mtransport/test/stunserver.h | 5 +- media/mtransport/test/turn_unittest.cpp | 1 - media/mtransport/transportflow.cpp | 12 +-- media/mtransport/transportflow.h | 4 +- media/mtransport/transportlayerdtls.cpp | 2 +- media/mtransport/transportlayerdtls.h | 4 +- media/mtransport/transportlayerice.h | 1 - .../src/media-conduit/WebrtcGmpVideoCodec.cpp | 1 - .../WebrtcMediaCodecVP8VideoCodec.cpp | 1 - .../src/mediapipeline/MediaPipeline.cpp | 20 +++-- .../peerconnection/MediaPipelineFactory.cpp | 6 +- .../src/peerconnection/PeerConnectionImpl.h | 8 +- .../signaling/test/mediaconduit_unittests.cpp | 14 ++-- .../signaling/test/signaling_unittests.cpp | 16 ++-- 22 files changed, 118 insertions(+), 136 deletions(-) diff --git a/media/mtransport/nricectx.h b/media/mtransport/nricectx.h index b17210f01f20..fe925def2ddf 100644 --- a/media/mtransport/nricectx.h +++ b/media/mtransport/nricectx.h @@ -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 Create(const std::string& addr, uint16_t port, const char *transport = kNrIceTransportUdp) { - ScopedDeletePtr server( - new NrIceStunServer(transport)); + UniquePtr 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& password, - const char *transport = kNrIceTransportUdp) { - ScopedDeletePtr server( - new NrIceTurnServer(username, password, transport)); + static UniquePtr Create(const std::string& addr, uint16_t port, + const std::string& username, + const std::vector& password, + const char *transport = kNrIceTransportUdp) { + UniquePtr 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; diff --git a/media/mtransport/nricemediastream.cpp b/media/mtransport/nricemediastream.cpp index 31ab2bb5f5e2..731fbe4fc7e3 100644 --- a/media/mtransport/nricemediastream.cpp +++ b/media/mtransport/nricemediastream.cpp @@ -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 out(new NrIceCandidate()); +static UniquePtr MakeNrIceCandidate(const nr_ice_candidate& candc) { + UniquePtr 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* localp, + UniquePtr* 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 local( + UniquePtr local( MakeNrIceCandidate(*local_int)); if (!local) return NS_ERROR_FAILURE; - ScopedDeletePtr remote( + UniquePtr 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; } diff --git a/media/mtransport/nricemediastream.h b/media/mtransport/nricemediastream.h index 16e14fc2ec1a..aaac61b8d26e 100644 --- a/media/mtransport/nricemediastream.h +++ b/media/mtransport/nricemediastream.h @@ -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* local, + UniquePtr* remote); // The number of components size_t components() const { return components_; } diff --git a/media/mtransport/test/buffered_stun_socket_unittest.cpp b/media/mtransport/test/buffered_stun_socket_unittest.cpp index ee615b95af6f..32565215cb23 100644 --- a/media/mtransport/test/buffered_stun_socket_unittest.cpp +++ b/media/mtransport/test/buffered_stun_socket_unittest.cpp @@ -12,8 +12,6 @@ #include "nss.h" #include "ssl.h" -#include "mozilla/Scoped.h" - extern "C" { #include "nr_api.h" #include "nr_socket.h" diff --git a/media/mtransport/test/ice_unittest.cpp b/media/mtransport/test/ice_unittest.cpp index f5a5b289e644..4cafff5cedd5 100644 --- a/media/mtransport/test/ice_unittest.cpp +++ b/media/mtransport/test/ice_unittest.cpp @@ -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 stun_servers; - ScopedDeletePtr server(NrIceStunServer::Create( + UniquePtr 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 password, const char* transport) { std::vector turn_servers; - ScopedDeletePtr server(NrIceTurnServer::Create( + UniquePtr 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 local; + UniquePtr 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("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 peer_; + mozilla::UniquePtr 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("P1", test_utils_, true, allow_loopback, + enable_tcp, false, default_only); + p2_ = MakeUnique("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 target_; - mozilla::ScopedDeletePtr p1_; - mozilla::ScopedDeletePtr p2_; + mozilla::UniquePtr p1_; + mozilla::UniquePtr 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("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("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("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("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("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 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 pairs1; std::vector 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 pairs1; std::vector pairs2; diff --git a/media/mtransport/test/multi_tcp_socket_unittest.cpp b/media/mtransport/test/multi_tcp_socket_unittest.cpp index 9bd7f18cfc48..625b088ff746 100644 --- a/media/mtransport/test/multi_tcp_socket_unittest.cpp +++ b/media/mtransport/test/multi_tcp_socket_unittest.cpp @@ -7,7 +7,6 @@ #include #include -#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 stun_servers; - ScopedDeletePtr server(NrIceStunServer::Create( + UniquePtr server(NrIceStunServer::Create( stun_server_addr, stun_server_port, kNrIceTransportTcp)); stun_servers.push_back(*server); diff --git a/media/mtransport/test/proxy_tunnel_socket_unittest.cpp b/media/mtransport/test/proxy_tunnel_socket_unittest.cpp index 3b07011fc43d..facd0c04c728 100644 --- a/media/mtransport/test/proxy_tunnel_socket_unittest.cpp +++ b/media/mtransport/test/proxy_tunnel_socket_unittest.cpp @@ -12,8 +12,6 @@ #include "nss.h" #include "ssl.h" -#include "mozilla/Scoped.h" - extern "C" { #include "nr_api.h" #include "nr_socket.h" diff --git a/media/mtransport/test/stunserver.cpp b/media/mtransport/test/stunserver.cpp index 65933197414e..8a66219bf9ec 100644 --- a/media/mtransport/test/stunserver.cpp +++ b/media/mtransport/test/stunserver.cpp @@ -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 wrapped(new nr_socket_wrapped()); + auto wrapped = MakeUnique(); 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::Create(int address_family) { NR_reg_init(NR_REG_MODE_LOCAL); - ScopedDeletePtr server(new TestStunServer()); + UniquePtr 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::Create(int address_family) { NR_reg_init(NR_REG_MODE_LOCAL); - ScopedDeletePtr server(new TestStunTcpServer()); + UniquePtr 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() { diff --git a/media/mtransport/test/stunserver.h b/media/mtransport/test/stunserver.h index c1a8c9e93541..33f1b2a318f5 100644 --- a/media/mtransport/test/stunserver.h +++ b/media/mtransport/test/stunserver.h @@ -13,6 +13,7 @@ #include #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 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 Create(int address_family); static TestStunTcpServer *instance; static TestStunTcpServer *instance6; diff --git a/media/mtransport/test/turn_unittest.cpp b/media/mtransport/test/turn_unittest.cpp index 6a7bb9edbaad..2a17bf3bc042 100644 --- a/media/mtransport/test/turn_unittest.cpp +++ b/media/mtransport/test/turn_unittest.cpp @@ -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" diff --git a/media/mtransport/transportflow.cpp b/media/mtransport/transportflow.cpp index e06b45552118..6f9ba6c42743 100644 --- a/media/mtransport/transportflow.cpp +++ b/media/mtransport/transportflow.cpp @@ -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 > layers_tmp(layers_.forget()); + nsAutoPtr> layers_tmp(layers_.release()); RUN_ON_THREAD(target_, WrapRunnableNM(&TransportFlow::DestroyFinal, layers_tmp), NS_DISPATCH_NORMAL); } void TransportFlow::DestroyFinal(nsAutoPtr > layers) { - ClearLayers(layers); + ClearLayers(layers.get()); } void TransportFlow::ClearLayers(std::queue* layers) { @@ -61,7 +61,7 @@ void TransportFlow::ClearLayers(std::deque* layers) { nsresult TransportFlow::PushLayer(TransportLayer *layer) { CheckThread(); - ScopedDeletePtr layer_tmp(layer); // Destroy on failure. + UniquePtr 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 > 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); diff --git a/media/mtransport/transportflow.h b/media/mtransport/transportflow.h index d0fe48445657..b21764046810 100644 --- a/media/mtransport/transportflow.h +++ b/media/mtransport/transportflow.h @@ -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 > layers_; + UniquePtr> layers_; nsCOMPtr target_; }; diff --git a/media/mtransport/transportlayerdtls.cpp b/media/mtransport/transportlayerdtls.cpp index 10c32d39a18c..66313174a221 100644 --- a/media/mtransport/transportlayerdtls.cpp +++ b/media/mtransport/transportlayerdtls.cpp @@ -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(downward_); if (!identity_) { MOZ_MTLOG(ML_ERROR, "Can't start DTLS without an identity"); diff --git a/media/mtransport/transportlayerdtls.h b/media/mtransport/transportlayerdtls.h index cc72ee7cbc86..d350fc0fe77e 100644 --- a/media/mtransport/transportlayerdtls.h +++ b/media/mtransport/transportlayerdtls.h @@ -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 nspr_io_adapter_; + UniquePtr nspr_io_adapter_; ScopedPRFileDesc ssl_fd_; ScopedCERTCertificate peer_cert_; diff --git a/media/mtransport/transportlayerice.h b/media/mtransport/transportlayerice.h index bff301280826..50637660087e 100644 --- a/media/mtransport/transportlayerice.h +++ b/media/mtransport/transportlayerice.h @@ -15,7 +15,6 @@ #include "sigslot.h" #include "mozilla/RefPtr.h" -#include "mozilla/Scoped.h" #include "nsCOMPtr.h" #include "nsIEventTarget.h" #include "nsITimer.h" diff --git a/media/webrtc/signaling/src/media-conduit/WebrtcGmpVideoCodec.cpp b/media/webrtc/signaling/src/media-conduit/WebrtcGmpVideoCodec.cpp index 5b2a92a852b5..59f50196ff57 100644 --- a/media/webrtc/signaling/src/media-conduit/WebrtcGmpVideoCodec.cpp +++ b/media/webrtc/signaling/src/media-conduit/WebrtcGmpVideoCodec.cpp @@ -8,7 +8,6 @@ #include #include "mozilla/Move.h" -#include "mozilla/Scoped.h" #include "mozilla/SyncRunnable.h" #include "VideoConduit.h" #include "AudioConduit.h" diff --git a/media/webrtc/signaling/src/media-conduit/WebrtcMediaCodecVP8VideoCodec.cpp b/media/webrtc/signaling/src/media-conduit/WebrtcMediaCodecVP8VideoCodec.cpp index 3a817e24ac9a..5faacfb32cc1 100644 --- a/media/webrtc/signaling/src/media-conduit/WebrtcMediaCodecVP8VideoCodec.cpp +++ b/media/webrtc/signaling/src/media-conduit/WebrtcMediaCodecVP8VideoCodec.cpp @@ -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" diff --git a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp index 01f318ac6e67..a5f88df1c61c 100644 --- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp +++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp @@ -513,11 +513,10 @@ void MediaPipeline::RtpPacketReceived(TransportLayer *layer, } // Make a copy rather than cast away constness - ScopedDeletePtr inner_data( - new unsigned char[len]); - memcpy(inner_data, data, len); + auto inner_data = MakeUnique(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 inner_data( - new unsigned char[len]); - memcpy(inner_data, data, len); + auto inner_data = MakeUnique(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) { diff --git a/media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.cpp b/media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.cpp index 59a55be7de37..8498e4881b0d 100644 --- a/media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.cpp +++ b/media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.cpp @@ -125,10 +125,10 @@ JsepCodecDescToCodecConfig(const JsepCodecDescription& aCodec, return NS_ERROR_INVALID_ARG; } - ScopedDeletePtr h264Config; + UniquePtr h264Config; if (desc.mName == "H264") { - h264Config = new VideoCodecConfigH264; + h264Config = MakeUnique(); 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; diff --git a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h index d14d8a05b839..bc2d684a72c0 100644 --- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h +++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h @@ -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 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 password(pwd.begin(), pwd.end()); - NrIceTurnServer* server(NrIceTurnServer::Create(addr, port, username, password, - transport)); + UniquePtr 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); } diff --git a/media/webrtc/signaling/test/mediaconduit_unittests.cpp b/media/webrtc/signaling/test/mediaconduit_unittests.cpp index 3578e45d3560..df60efd3c421 100644 --- a/media/webrtc/signaling/test/mediaconduit_unittests.cpp +++ b/media/webrtc/signaling/test/mediaconduit_unittests.cpp @@ -11,8 +11,8 @@ using namespace std; -#include "mozilla/Scoped.h" #include "mozilla/SyncRunnable.h" +#include "mozilla/UniquePtr.h" #include #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(mLen); + memset(mFrame.get(), COLOR, mLen); numFrames = 121; } @@ -101,7 +101,7 @@ public: { do { - mSession->SendVideoFrame((unsigned char*)mFrame, + mSession->SendVideoFrame(reinterpret_cast(mFrame.get()), mLen, width, height, @@ -115,7 +115,7 @@ public: private: RefPtr mSession; -mozilla::ScopedDeletePtr mFrame; +mozilla::UniquePtr 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 audioInput(new int16_t [PLAYOUT_SAMPLE_LENGTH]); - mozilla::ScopedDeletePtr audioOutput(new int16_t [PLAYOUT_SAMPLE_LENGTH]); + auto audioInput = mozilla::MakeUnique(PLAYOUT_SAMPLE_LENGTH); + auto audioOutput = mozilla::MakeUnique(PLAYOUT_SAMPLE_LENGTH); short* inbuf; int sampleLengthDecoded = 0; unsigned int SAMPLES = (PLAYOUT_SAMPLE_FREQUENCY * 10); //10 seconds diff --git a/media/webrtc/signaling/test/signaling_unittests.cpp b/media/webrtc/signaling/test/signaling_unittests.cpp index 640e8263f4fe..1ae3a5e21d89 100644 --- a/media/webrtc/signaling/test/signaling_unittests.cpp +++ b/media/webrtc/signaling/test/signaling_unittests.cpp @@ -1688,19 +1688,19 @@ class SignalingAgentTest : public ::testing::Test { } bool CreateAgent(const std::string stun_addr, uint16_t stun_port) { - ScopedDeletePtr agent( + UniquePtr 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 agent(new SignalingAgent("agent")); - agents_.push_back(agent.forget()); + UniquePtr 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(callerName, stun_addr_, stun_port_); + a2_ = MakeUnique(calleeName, stun_addr_, stun_port_); if (GetParam() == "no_bundle") { a1_->SetBundleEnabled(false); @@ -2170,8 +2170,8 @@ public: protected: bool init_; - ScopedDeletePtr a1_; // Canonically "caller" - ScopedDeletePtr a2_; // Canonically "callee" + UniquePtr a1_; // Canonically "caller" + UniquePtr a2_; // Canonically "callee" std::string stun_addr_; uint16_t stun_port_; };