diff --git a/dom/media/MediaManager.cpp b/dom/media/MediaManager.cpp index 4e82f06757c..a5ad9d09d5e 100644 --- a/dom/media/MediaManager.cpp +++ b/dom/media/MediaManager.cpp @@ -1103,7 +1103,7 @@ static auto& MediaManager_AnonymizeDevices = MediaManager::AnonymizeDevices; already_AddRefed MediaManager::SelectSettings( MediaStreamConstraints& aConstraints, - RefPtr>>& aSources) + RefPtr>>& aSources) { MOZ_ASSERT(NS_IsMainThread()); RefPtr p = new PledgeChar(); @@ -1414,7 +1414,7 @@ MediaManager::EnumerateRawDevices(uint64_t aWindowId, realBackend = manager->GetBackend(aWindowId); } - auto result = MakeUnique(); + ScopedDeletePtr result(new SourceSet); if (hasVideo) { nsTArray> videos; @@ -1432,16 +1432,16 @@ MediaManager::EnumerateRawDevices(uint64_t aWindowId, result->AppendElement(source); } } - SourceSet* handoff = result.release(); + SourceSet* handoff = result.forget(); NS_DispatchToMainThread(do_AddRef(NewRunnableFrom([id, handoff]() mutable { - UniquePtr result(handoff); // grab result + ScopedDeletePtr result(handoff); // grab result RefPtr mgr = MediaManager_GetInstance(); if (!mgr) { return NS_OK; } RefPtr p = mgr->mOutstandingPledges.Remove(id); if (p) { - p->Resolve(result.release()); + p->Resolve(result.forget()); } return NS_OK; }))); @@ -1609,9 +1609,9 @@ media::Parent* MediaManager::GetNonE10sParent() { if (!mNonE10sParent) { - mNonE10sParent = MakeUnique>(true); + mNonE10sParent = new media::Parent(true); } - return mNonE10sParent.get(); + return mNonE10sParent; } /* static */ void @@ -2115,8 +2115,8 @@ MediaManager::GetUserMedia(nsPIDOMWindowInner* aWindow, p->Then([this, onSuccess, onFailure, windowID, c, listener, askPermission, prefs, isHTTPS, callID, origin](SourceSet*& aDevices) mutable { - RefPtr>> devices( - new Refcountable>(aDevices)); // grab result + RefPtr>> devices( + new Refcountable>(aDevices)); // grab result // Ensure that the captured 'this' pointer and our windowID are still good. if (!MediaManager::Exists() || @@ -2176,7 +2176,7 @@ MediaManager::GetUserMedia(nsPIDOMWindowInner* aWindow, onFailure.forget(), windowID, listener, prefs, origin, - devices->release())); + devices->forget())); // Store the task w/callbacks. mActiveCallbacks.Put(callID, task.forget()); @@ -2335,7 +2335,7 @@ MediaManager::EnumerateDevicesImpl(uint64_t aWindowId, aVideoType, aAudioType, aFake, aFakeTracks); p->Then([id, aWindowId, aOriginKey](SourceSet*& aDevices) mutable { - UniquePtr devices(aDevices); // secondary result + ScopedDeletePtr devices(aDevices); // secondary result // Only run if window is still on our active list. RefPtr mgr = MediaManager_GetInstance(); @@ -2347,7 +2347,7 @@ MediaManager::EnumerateDevicesImpl(uint64_t aWindowId, return NS_OK; } MediaManager_AnonymizeDevices(*devices, aOriginKey); - p->Resolve(devices.release()); + p->Resolve(devices.forget()); return NS_OK; }); }); @@ -2381,7 +2381,7 @@ MediaManager::EnumerateDevices(nsPIDOMWindowInner* aWindow, MediaSourceEnum::Microphone, fake); p->Then([onSuccess, windowId, listener](SourceSet*& aDevices) mutable { - UniquePtr devices(aDevices); // grab result + ScopedDeletePtr devices(aDevices); // grab result RefPtr mgr = MediaManager_GetInstance(); mgr->RemoveFromWindowList(windowId, listener); nsCOMPtr array = MediaManager_ToJSArray(*devices); diff --git a/dom/media/MediaManager.h b/dom/media/MediaManager.h index fbc9891c2e3..62db1408e5c 100644 --- a/dom/media/MediaManager.h +++ b/dom/media/MediaManager.h @@ -30,7 +30,6 @@ #include "mozilla/media/MediaChild.h" #include "mozilla/media/MediaParent.h" #include "mozilla/Logging.h" -#include "mozilla/UniquePtr.h" #include "DOMMediaStream.h" #ifdef MOZ_WEBRTC @@ -502,7 +501,7 @@ private: already_AddRefed SelectSettings( dom::MediaStreamConstraints& aConstraints, - RefPtr>>& aSources); + RefPtr>>& aSources); StreamListeners* AddWindowID(uint64_t aWindowId); WindowTable *GetActiveWindows() { @@ -551,7 +550,7 @@ private: #endif public: media::CoatCheck> mGetOriginKeyPledges; - UniquePtr> mNonE10sParent; + ScopedDeletePtr> mNonE10sParent; }; } // namespace mozilla diff --git a/dom/media/VideoSegment.cpp b/dom/media/VideoSegment.cpp index 115bdc1d5c9..e382eacfabb 100644 --- a/dom/media/VideoSegment.cpp +++ b/dom/media/VideoSegment.cpp @@ -8,7 +8,6 @@ #include "gfx2DGlue.h" #include "ImageContainer.h" #include "Layers.h" -#include "mozilla/UniquePtr.h" namespace mozilla { @@ -53,18 +52,18 @@ VideoFrame::CreateBlackImage(const gfx::IntSize& aSize) int len = ((aSize.width * aSize.height) * 3 / 2); // Generate a black image. - auto frame = MakeUnique(len); + ScopedDeletePtr frame(new uint8_t[len]); int y = aSize.width * aSize.height; // Fill Y plane. - memset(frame.get(), 0x10, y); + memset(frame.rwget(), 0x10, y); // Fill Cb/Cr planes. - memset(frame.get() + y, 0x80, (len - y)); + memset(frame.rwget() + y, 0x80, (len - y)); const uint8_t lumaBpp = 8; const uint8_t chromaBpp = 4; layers::PlanarYCbCrData data; - data.mYChannel = frame.get(); + data.mYChannel = frame.rwget(); data.mYSize = gfx::IntSize(aSize.width, aSize.height); data.mYStride = (int32_t) (aSize.width * lumaBpp / 8.0); data.mCbCrStride = (int32_t) (aSize.width * chromaBpp / 8.0); diff --git a/dom/media/systemservices/MediaChild.cpp b/dom/media/systemservices/MediaChild.cpp index 5d04f5f823d..0ff3ac08176 100644 --- a/dom/media/systemservices/MediaChild.cpp +++ b/dom/media/systemservices/MediaChild.cpp @@ -46,7 +46,7 @@ SanitizeOriginKeys(const uint64_t& aSinceWhen, bool aOnlyPrivateBrowsing) if (XRE_GetProcessType() == GeckoProcessType_Default) { // Avoid opening MediaManager in this case, since this is called by // sanitize.js when cookies are cleared, which can happen on startup. - auto tmpParent = MakeUnique>(true); + ScopedDeletePtr> tmpParent(new Parent(true)); tmpParent->RecvSanitizeOriginKeys(aSinceWhen, aOnlyPrivateBrowsing); } else { Child::Get()->SendSanitizeOriginKeys(aSinceWhen, aOnlyPrivateBrowsing); diff --git a/dom/media/systemservices/MediaUtils.h b/dom/media/systemservices/MediaUtils.h index d6cdc0cc5c9..dad43bd3499 100644 --- a/dom/media/systemservices/MediaUtils.h +++ b/dom/media/systemservices/MediaUtils.h @@ -10,7 +10,6 @@ #include "nsAutoPtr.h" #include "nsThreadUtils.h" #include "nsIAsyncShutdown.h" -#include "mozilla/UniquePtr.h" #include "base/task.h" namespace mozilla { @@ -97,8 +96,8 @@ public: OnSuccessType mOnSuccess; OnFailureType mOnFailure; }; - mFunctors = MakeUnique(Forward(aOnSuccess), - Forward(aOnFailure)); + mFunctors = new Functors(Forward(aOnSuccess), + Forward(aOnFailure)); if (mDone) { if (!mRejected) { mFunctors->Succeed(mValue); @@ -143,7 +142,7 @@ private: bool mDone; bool mRejected; ErrorType mError; - UniquePtr mFunctors; + ScopedDeletePtr mFunctors; }; /* media::NewRunnableFrom() - Create an nsRunnable from a lambda. @@ -338,7 +337,7 @@ private: * (or owning smart-pointers to such objects) refcountable. * * Technical limitation: A template specialization is needed for types that take - * a constructor. Please add below (UniquePtr covers a lot of ground though). + * a constructor. Please add below (ScopedDeletePtr covers a lot of ground though). */ template @@ -351,13 +350,13 @@ private: }; template -class Refcountable> : public UniquePtr +class Refcountable> : public ScopedDeletePtr { public: - explicit Refcountable>(T* aPtr) : UniquePtr(aPtr) {} + explicit Refcountable>(T* aPtr) : ScopedDeletePtr(aPtr) {} NS_INLINE_DECL_THREADSAFE_REFCOUNTING(Refcountable) private: - ~Refcountable>() {} + ~Refcountable>() {} }; /* media::ShutdownBlocker - Async shutdown helper. diff --git a/media/mtransport/nricectx.h b/media/mtransport/nricectx.h index fe925def2dd..b17210f01f2 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,15 +99,16 @@ class NrIceStunServer { } // The main function to use. Will take either an address or a hostname. - static UniquePtr Create(const std::string& addr, uint16_t port, + static NrIceStunServer* Create(const std::string& addr, uint16_t port, const char *transport = kNrIceTransportUdp) { - UniquePtr server(new NrIceStunServer(transport)); + ScopedDeletePtr server( + new NrIceStunServer(transport)); nsresult rv = server->Init(addr, port); if (NS_FAILED(rv)) return nullptr; - return server; + return server.forget(); } nsresult ToNicerStunStruct(nr_ice_stun_server* server) const; @@ -145,17 +146,18 @@ class NrIceStunServer { class NrIceTurnServer : public NrIceStunServer { public: - 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)); + 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)); nsresult rv = server->Init(addr, port); if (NS_FAILED(rv)) return nullptr; - return server; + return server.forget(); } nsresult ToNicerTurnStruct(nr_ice_turn_server *server) const; diff --git a/media/mtransport/nricemediastream.cpp b/media/mtransport/nricemediastream.cpp index 731fbe4fc7e..31ab2bb5f5e 100644 --- a/media/mtransport/nricemediastream.cpp +++ b/media/mtransport/nricemediastream.cpp @@ -46,6 +46,7 @@ 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" { @@ -168,13 +169,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 UniquePtr MakeNrIceCandidate(const nr_ice_candidate& candc) { - UniquePtr out(new NrIceCandidate()); +static NrIceCandidate* MakeNrIceCandidate(const nr_ice_candidate& candc) { + ScopedDeletePtr out(new NrIceCandidate()); - if (!ToNrIceCandidate(candc, out.get())) { + if (!ToNrIceCandidate(candc, out)) { return nullptr; } - return out; + return out.forget(); } // NrIceMediaStream @@ -258,8 +259,8 @@ nsresult NrIceMediaStream::ParseTrickleCandidate(const std::string& candidate) { // Returns NS_ERROR_NOT_AVAILABLE if component is unpaired or disabled. nsresult NrIceMediaStream::GetActivePair(int component, - UniquePtr* localp, - UniquePtr* remotep) { + NrIceCandidate **localp, + NrIceCandidate **remotep) { int r; nr_ice_candidate *local_int; nr_ice_candidate *remote_int; @@ -279,20 +280,20 @@ nsresult NrIceMediaStream::GetActivePair(int component, if (r) return NS_ERROR_FAILURE; - UniquePtr local( + ScopedDeletePtr local( MakeNrIceCandidate(*local_int)); if (!local) return NS_ERROR_FAILURE; - UniquePtr remote( + ScopedDeletePtr remote( MakeNrIceCandidate(*remote_int)); if (!remote) return NS_ERROR_FAILURE; if (localp) - *localp = Move(local); + *localp = local.forget(); if (remotep) - *remotep = Move(remote); + *remotep = remote.forget(); return NS_OK; } diff --git a/media/mtransport/nricemediastream.h b/media/mtransport/nricemediastream.h index aaac61b8d26..16e14fc2ec1 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/UniquePtr.h" +#include "mozilla/Scoped.h" #include "nsCOMPtr.h" #include "nsIEventTarget.h" #include "nsITimer.h" @@ -159,8 +159,7 @@ class NrIceMediaStream { // Get the candidate pair currently active. It's the // caller's responsibility to free these. nsresult GetActivePair(int component, - UniquePtr* local, - UniquePtr* remote); + NrIceCandidate** local, NrIceCandidate** 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 32565215cb2..ee615b95af6 100644 --- a/media/mtransport/test/buffered_stun_socket_unittest.cpp +++ b/media/mtransport/test/buffered_stun_socket_unittest.cpp @@ -12,6 +12,8 @@ #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 4cafff5cedd..f5a5b289e64 100644 --- a/media/mtransport/test/ice_unittest.cpp +++ b/media/mtransport/test/ice_unittest.cpp @@ -22,6 +22,7 @@ #include "ssl.h" #include "mozilla/Preferences.h" +#include "mozilla/Scoped.h" #include "nsThreadUtils.h" #include "nsXPCOM.h" @@ -470,7 +471,7 @@ class IceTestPeer : public sigslot::has_slots<> { } std::vector stun_servers; - UniquePtr server(NrIceStunServer::Create( + ScopedDeletePtr server(NrIceStunServer::Create( addr, port, transport)); stun_servers.push_back(*server); SetStunServers(stun_servers); @@ -499,7 +500,7 @@ class IceTestPeer : public sigslot::has_slots<> { const std::vector password, const char* transport) { std::vector turn_servers; - UniquePtr server(NrIceTurnServer::Create( + ScopedDeletePtr server(NrIceTurnServer::Create( addr, port, username, password, transport)); turn_servers.push_back(*server); ASSERT_TRUE(NS_SUCCEEDED(ice_ctx_->SetTurnServers(turn_servers))); @@ -843,8 +844,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; - UniquePtr local; - UniquePtr remote; + NrIceCandidate *local; + NrIceCandidate *remote; nsresult res = streams_[i]->GetActivePair(j+1, &local, &remote); if (res == NS_ERROR_NOT_AVAILABLE) { @@ -875,6 +876,8 @@ class IceTestPeer : public sigslot::has_slots<> { if (!expected_remote_addr_.empty()) { ASSERT_EQ(expected_remote_addr_, remote->cand_addr.host); } + delete local; + delete remote; } } } @@ -1312,12 +1315,12 @@ class IceGatherTest : public StunTest { void EnsurePeer(const unsigned int flags = ICE_TEST_PEER_OFFERER) { if (!peer_) { - 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_ = 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_->AddStream(1); } } @@ -1450,7 +1453,7 @@ class IceGatherTest : public StunTest { } protected: - mozilla::UniquePtr peer_; + mozilla::ScopedDeletePtr peer_; }; class IceConnectTest : public StunTest { @@ -1490,10 +1493,10 @@ class IceConnectTest : public StunTest { void Init(bool allow_loopback, bool enable_tcp, bool default_only = false) { if (!initted_) { - 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); + 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); } initted_ = true; } @@ -1590,8 +1593,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_.get(), TRICKLE_NONE); - p1_->Connect(p2_.get(), TRICKLE_NONE); + p2_->Connect(p1_, TRICKLE_NONE); + p1_->Connect(p2_, TRICKLE_NONE); ASSERT_TRUE_WAIT(p1_->ready_ct() == 1 && p2_->ready_ct() == 1, kDefaultTimeout); @@ -1621,11 +1624,11 @@ class IceConnectTest : public StunTest { } void ConnectP1(TrickleMode mode = TRICKLE_NONE) { - p1_->Connect(p2_.get(), mode); + p1_->Connect(p2_, mode); } void ConnectP2(TrickleMode mode = TRICKLE_NONE) { - p2_->Connect(p1_.get(), mode); + p2_->Connect(p1_, mode); } void WaitForComplete(int expected_streams = 1) { @@ -1646,8 +1649,8 @@ class IceConnectTest : public StunTest { } void ConnectTrickle(TrickleMode trickle = TRICKLE_SIMULATE) { - p2_->Connect(p1_.get(), trickle); - p1_->Connect(p2_.get(), trickle); + p2_->Connect(p1_, trickle); + p1_->Connect(p2_, trickle); } void SimulateTrickle(size_t stream) { @@ -1673,8 +1676,8 @@ class IceConnectTest : public StunTest { } void ConnectThenDelete() { - p2_->Connect(p1_.get(), TRICKLE_NONE, false); - p1_->Connect(p2_.get(), TRICKLE_NONE, true); + p2_->Connect(p1_, TRICKLE_NONE, false); + p1_->Connect(p2_, TRICKLE_NONE, true); test_utils_->sts_target()->Dispatch(WrapRunnable(this, &IceConnectTest::CloseP1), NS_DISPATCH_SYNC); @@ -1698,8 +1701,8 @@ class IceConnectTest : public StunTest { protected: bool initted_; nsCOMPtr target_; - mozilla::UniquePtr p1_; - mozilla::UniquePtr p2_; + mozilla::ScopedDeletePtr p1_; + mozilla::ScopedDeletePtr p2_; bool use_nat_; TestNat::NatBehavior filtering_type_; TestNat::NatBehavior mapping_type_; @@ -1857,7 +1860,7 @@ TEST_F(IceGatherTest, TestGatherStunServerIpAddressDefaultRouteOnly) { return; } - peer_ = MakeUnique("P1", test_utils_, true, false, false, false, true); + peer_ = new 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_); @@ -2046,7 +2049,7 @@ TEST_F(IceGatherTest, TestGatherVerifyNoLoopback) { TEST_F(IceGatherTest, TestGatherAllowLoopback) { // Set up peer with loopback allowed. - peer_ = MakeUnique("P1", test_utils_, true, true); + peer_ = new IceTestPeer("P1", test_utils_, true, true); peer_->AddStream(1); Gather(); ASSERT_TRUE(StreamHasMatchingCandidate(0, "127.0.0.1")); @@ -2054,7 +2057,7 @@ TEST_F(IceGatherTest, TestGatherAllowLoopback) { TEST_F(IceGatherTest, TestGatherTcpDisabled) { // Set up peer with tcp disabled. - peer_ = MakeUnique("P1", test_utils_, true, false, false); + peer_ = new IceTestPeer("P1", test_utils_, true, false, false); peer_->AddStream(1); Gather(); ASSERT_FALSE(StreamHasMatchingCandidate(0, " TCP ")); @@ -2157,7 +2160,7 @@ TEST_F(IceGatherTest, TestStunServerTrickle) { // Test default route only with our fake STUN server and // apparently NATted. TEST_F(IceGatherTest, TestFakeStunServerNatedDefaultRouteOnly) { - peer_ = MakeUnique("P1", test_utils_, true, false, false, false, true); + peer_ = new IceTestPeer("P1", test_utils_, true, false, false, false, true); peer_->AddStream(1); UseFakeStunUdpServerWithResponse("192.0.2.1", 3333); Gather(0); @@ -2175,7 +2178,7 @@ TEST_F(IceGatherTest, TestFakeStunServerNatedDefaultRouteOnly) { // Test default route only with our fake STUN server and // apparently non-NATted. TEST_F(IceGatherTest, TestFakeStunServerNoNatDefaultRouteOnly) { - peer_ = MakeUnique("P1", test_utils_, true, false, false, false, true); + peer_ = new IceTestPeer("P1", test_utils_, true, false, false, false, true); peer_->AddStream(1); UseTestStunServer(); Gather(0); @@ -3054,8 +3057,10 @@ TEST_F(IceConnectTest, TestHostCandPairingFilter) { } ConnectTrickle(); - AddNonPairableCandidates(p1_->ControlTrickle(0), p1_.get(), 0, host_net, test_utils_); - AddNonPairableCandidates(p2_->ControlTrickle(0), p2_.get(), 0, host_net, test_utils_); + AddNonPairableCandidates(p1_->ControlTrickle(0), p1_, 0, host_net, + test_utils_); + AddNonPairableCandidates(p2_->ControlTrickle(0), p2_, 0, host_net, + test_utils_); std::vector pairs; p1_->GetCandidatePairs(0, &pairs); @@ -3116,8 +3121,8 @@ TEST_F(IceConnectTest, TestPollCandPairsDuringConnect) { AddStream("first", 1); ASSERT_TRUE(Gather()); - p2_->Connect(p1_.get(), TRICKLE_NONE, false); - p1_->Connect(p2_.get(), TRICKLE_NONE, false); + p2_->Connect(p1_, TRICKLE_NONE, false); + p1_->Connect(p2_, TRICKLE_NONE, false); std::vector pairs1; std::vector pairs2; @@ -3141,8 +3146,8 @@ TEST_F(IceConnectTest, TestRLogRingBuffer) { AddStream("first", 1); ASSERT_TRUE(Gather()); - p2_->Connect(p1_.get(), TRICKLE_NONE, false); - p1_->Connect(p2_.get(), TRICKLE_NONE, false); + p2_->Connect(p1_, TRICKLE_NONE, false); + p1_->Connect(p2_, 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 625b088ff74..9bd7f18cfc4 100644 --- a/media/mtransport/test/multi_tcp_socket_unittest.cpp +++ b/media/mtransport/test/multi_tcp_socket_unittest.cpp @@ -7,6 +7,7 @@ #include #include +#include "mozilla/Scoped.h" #include "mozilla/Atomics.h" #include "runnable_utils.h" #include "nss.h" @@ -105,7 +106,7 @@ class MultiTcpSocketTest : public MtransportTest { if (!stun_server_addr.empty()) { std::vector stun_servers; - UniquePtr server(NrIceStunServer::Create( + ScopedDeletePtr 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 facd0c04c72..3b07011fc43 100644 --- a/media/mtransport/test/proxy_tunnel_socket_unittest.cpp +++ b/media/mtransport/test/proxy_tunnel_socket_unittest.cpp @@ -12,6 +12,8 @@ #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 d49f5828f32..c2f14d67004 100644 --- a/media/mtransport/test/stunserver.cpp +++ b/media/mtransport/test/stunserver.cpp @@ -78,8 +78,7 @@ nrappkit copyright: ekr@rtfm.com Thu Dec 20 20:14:49 2001 */ #include "logging.h" -#include "mozilla/UniquePtr.h" -#include "mozilla/unused.h" +#include "mozilla/Scoped.h" #include "databuffer.h" extern "C" { @@ -175,7 +174,7 @@ static nr_socket_vtbl nr_socket_wrapped_vtbl = { }; int nr_socket_wrapped_create(nr_socket *inner, nr_socket **outp) { - auto wrapped = MakeUnique(); + ScopedDeletePtr wrapped(new nr_socket_wrapped()); wrapped->sock_ = inner; @@ -183,7 +182,7 @@ int nr_socket_wrapped_create(nr_socket *inner, nr_socket **outp) { if (r) return r; - Unused << wrapped.release(); + wrapped.forget(); return 0; } @@ -191,10 +190,10 @@ int nr_socket_wrapped_create(nr_socket *inner, nr_socket **outp) { // Instance static. // Note: Calling Create() at static init time is not going to be safe, since // we have no reason to expect this will be initted to a nullptr yet. -UniquePtr TestStunServer::instance; -UniquePtr TestStunTcpServer::instance; -UniquePtr TestStunServer::instance6; -UniquePtr TestStunTcpServer::instance6; +TestStunServer *TestStunServer::instance; +TestStunTcpServer *TestStunTcpServer::instance; +TestStunServer *TestStunServer::instance6; +TestStunTcpServer *TestStunTcpServer::instance6; uint16_t TestStunServer::instance_port = 3478; uint16_t TestStunTcpServer::instance_port = 3478; @@ -324,10 +323,10 @@ int TestStunServer::Initialize(int address_family) { return 0; } -UniquePtr TestStunServer::Create(int address_family) { +TestStunServer* TestStunServer::Create(int address_family) { NR_reg_init(NR_REG_MODE_LOCAL); - UniquePtr server(new TestStunServer()); + ScopedDeletePtr server(new TestStunServer()); if (server->Initialize(address_family)) return nullptr; @@ -341,7 +340,7 @@ UniquePtr TestStunServer::Create(int address_family) { NR_ASYNC_WAIT(fd, NR_ASYNC_WAIT_READ, &TestStunServer::readable_cb, server.get()); - return server; + return server.forget(); } void TestStunServer::ConfigurePort(uint16_t port) { @@ -355,19 +354,21 @@ TestStunServer* TestStunServer::GetInstance(int address_family) { instance = Create(address_family); MOZ_ASSERT(instance); - return instance.get(); + return instance; case AF_INET6: if (!instance6) instance6 = Create(address_family); - return instance6.get(); + return instance6; default: MOZ_CRASH(); } } void TestStunServer::ShutdownInstance() { + delete instance; instance = nullptr; + delete instance6; instance6 = nullptr; } @@ -536,19 +537,21 @@ TestStunTcpServer* TestStunTcpServer::GetInstance(int address_family) { instance = Create(address_family); MOZ_ASSERT(instance); - return instance.get(); + return instance; case AF_INET6: if (!instance6) instance6 = Create(address_family); - return instance6.get(); + return instance6; default: MOZ_CRASH(); } } void TestStunTcpServer::ShutdownInstance() { + delete instance; instance = nullptr; + delete instance6; instance6 = nullptr; } @@ -628,10 +631,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); } - UniquePtr TestStunTcpServer::Create(int address_family) { +TestStunTcpServer* TestStunTcpServer::Create(int address_family) { NR_reg_init(NR_REG_MODE_LOCAL); - UniquePtr server(new TestStunTcpServer()); + ScopedDeletePtr server(new TestStunTcpServer()); if (server->Initialize(address_family)) { return nullptr; @@ -645,7 +648,7 @@ void TestStunTcpServer::accept_cb(NR_SOCKET s, int how, void *cb_arg) { NR_ASYNC_WAIT(fd, NR_ASYNC_WAIT_READ, &TestStunTcpServer::accept_cb, server.get()); - return server; + return server.forget(); } TestStunTcpServer::~TestStunTcpServer() { diff --git a/media/mtransport/test/stunserver.h b/media/mtransport/test/stunserver.h index 8e14d7115f5..c1a8c9e9354 100644 --- a/media/mtransport/test/stunserver.h +++ b/media/mtransport/test/stunserver.h @@ -13,7 +13,6 @@ #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; @@ -32,7 +31,7 @@ class TestStunServer { // to |GetInstance| (possibly following a |ShutdownInstance| call) static void ConfigurePort(uint16_t port); // AF_INET, AF_INET6 - static UniquePtr Create(int address_family); + static TestStunServer *Create(int address_family); virtual ~TestStunServer(); @@ -90,8 +89,8 @@ class TestStunServer { void *timer_handle_; std::map received_ct_; - static UniquePtr instance; - static UniquePtr instance6; + static TestStunServer *instance; + static TestStunServer *instance6; static uint16_t instance_port; }; @@ -111,10 +110,10 @@ class TestStunTcpServer: public TestStunServer { private: virtual int TryOpenListenSocket(nr_local_addr *addr, uint16_t port); - static UniquePtr Create(int address_family); + static TestStunTcpServer *Create(int address_family); - static UniquePtr instance; - static UniquePtr instance6; + static TestStunTcpServer *instance; + static TestStunTcpServer *instance6; static uint16_t instance_port; std::map connections_; diff --git a/media/mtransport/test/turn_unittest.cpp b/media/mtransport/test/turn_unittest.cpp index 2a17bf3bc04..6a7bb9edbaa 100644 --- a/media/mtransport/test/turn_unittest.cpp +++ b/media/mtransport/test/turn_unittest.cpp @@ -49,6 +49,7 @@ 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 6f9ba6c4274..e06b4555211 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_.release()); + nsAutoPtr > layers_tmp(layers_.forget()); RUN_ON_THREAD(target_, WrapRunnableNM(&TransportFlow::DestroyFinal, layers_tmp), NS_DISPATCH_NORMAL); } void TransportFlow::DestroyFinal(nsAutoPtr > layers) { - ClearLayers(layers.get()); + ClearLayers(layers); } void TransportFlow::ClearLayers(std::queue* layers) { @@ -61,7 +61,7 @@ void TransportFlow::ClearLayers(std::deque* layers) { nsresult TransportFlow::PushLayer(TransportLayer *layer) { CheckThread(); - UniquePtr layer_tmp(layer); // Destroy on failure. + ScopedDeletePtr 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.release()); + layers_->push_front(layer_tmp.forget()); 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.get()); + ClearLayers(layers); // Now destroy the rest of the flow, because it's no longer // in an acceptable state. - ClearLayers(layers_.get()); + ClearLayers(layers_); // Set ourselves to have failed. StateChangeInt(TransportLayer::TS_ERROR); diff --git a/media/mtransport/transportflow.h b/media/mtransport/transportflow.h index b2176404681..d0fe4844565 100644 --- a/media/mtransport/transportflow.h +++ b/media/mtransport/transportflow.h @@ -15,7 +15,7 @@ #include "nscore.h" #include "nsISupportsImpl.h" -#include "mozilla/UniquePtr.h" +#include "mozilla/Scoped.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_; - UniquePtr> layers_; + ScopedDeletePtr > layers_; nsCOMPtr target_; }; diff --git a/media/mtransport/transportlayerdtls.cpp b/media/mtransport/transportlayerdtls.cpp index 66313174a22..10c32d39a18 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_ = MakeUnique(downward_); + nspr_io_adapter_ = new TransportLayerNSPRAdapter(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 d350fc0fe77..cc72ee7cbc8 100644 --- a/media/mtransport/transportlayerdtls.h +++ b/media/mtransport/transportlayerdtls.h @@ -15,7 +15,7 @@ #include "sigslot.h" #include "mozilla/RefPtr.h" -#include "mozilla/UniquePtr.h" +#include "mozilla/Scoped.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_) - UniquePtr nspr_io_adapter_; + ScopedDeletePtr nspr_io_adapter_; ScopedPRFileDesc ssl_fd_; ScopedCERTCertificate peer_cert_; diff --git a/media/mtransport/transportlayerice.h b/media/mtransport/transportlayerice.h index 50637660087..bff30128082 100644 --- a/media/mtransport/transportlayerice.h +++ b/media/mtransport/transportlayerice.h @@ -15,6 +15,7 @@ #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 59f50196ff5..5b2a92a852b 100644 --- a/media/webrtc/signaling/src/media-conduit/WebrtcGmpVideoCodec.cpp +++ b/media/webrtc/signaling/src/media-conduit/WebrtcGmpVideoCodec.cpp @@ -8,6 +8,7 @@ #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 7b56b22e868..6ef04f13aff 100644 --- a/media/webrtc/signaling/src/media-conduit/WebrtcMediaCodecVP8VideoCodec.cpp +++ b/media/webrtc/signaling/src/media-conduit/WebrtcMediaCodecVP8VideoCodec.cpp @@ -12,6 +12,7 @@ #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 a5f88df1c61..01f318ac6e6 100644 --- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp +++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp @@ -513,10 +513,11 @@ void MediaPipeline::RtpPacketReceived(TransportLayer *layer, } // Make a copy rather than cast away constness - auto inner_data = MakeUnique(len); - memcpy(inner_data.get(), data, len); + ScopedDeletePtr inner_data( + new unsigned char[len]); + memcpy(inner_data, data, len); int out_len = 0; - nsresult res = rtp_.recv_srtp_->UnprotectRtp(inner_data.get(), + nsresult res = rtp_.recv_srtp_->UnprotectRtp(inner_data, len, len, &out_len); if (!NS_SUCCEEDED(res)) { char tmp[16]; @@ -535,7 +536,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.get(), out_len); // Ignore error codes + (void)conduit_->ReceivedRTPPacket(inner_data, out_len); // Ignore error codes } void MediaPipeline::RtcpPacketReceived(TransportLayer *layer, @@ -571,11 +572,12 @@ void MediaPipeline::RtcpPacketReceived(TransportLayer *layer, } // Make a copy rather than cast away constness - auto inner_data = MakeUnique(len); - memcpy(inner_data.get(), data, len); + ScopedDeletePtr inner_data( + new unsigned char[len]); + memcpy(inner_data, data, len); int out_len; - nsresult res = rtcp_.recv_srtp_->UnprotectRtcp(inner_data.get(), + nsresult res = rtcp_.recv_srtp_->UnprotectRtcp(inner_data, len, len, &out_len); @@ -586,7 +588,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.get(), out_len)) { + if (!filter_->FilterSenderReport(inner_data, out_len)) { MOZ_MTLOG(ML_NOTICE, "Dropping rtcp packet"); return; } @@ -597,7 +599,7 @@ void MediaPipeline::RtcpPacketReceived(TransportLayer *layer, MOZ_ASSERT(rtcp_.recv_srtp_); // This should never happen - (void)conduit_->ReceivedRTCPPacket(inner_data.get(), out_len); // Ignore error codes + (void)conduit_->ReceivedRTCPPacket(inner_data, 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 8498e4881b0..59a55be7de3 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; } - UniquePtr h264Config; + ScopedDeletePtr h264Config; if (desc.mName == "H264") { - h264Config = MakeUnique(); + h264Config = new 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.get()); + pt, desc.mName, desc.mConstraints, h264Config); 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 bc2d684a72c..d14d8a05b83 100644 --- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h +++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h @@ -157,11 +157,12 @@ public: bool addStunServer(const std::string& addr, uint16_t port, const char* transport) { - UniquePtr server(NrIceStunServer::Create(addr, port, transport)); + 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, @@ -173,12 +174,13 @@ public: // username and password. Bug # ??? std::vector password(pwd.begin(), pwd.end()); - UniquePtr server(NrIceTurnServer::Create(addr, port, username, password, - transport)); + 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); } diff --git a/media/webrtc/signaling/test/mediaconduit_unittests.cpp b/media/webrtc/signaling/test/mediaconduit_unittests.cpp index 91e42940bf8..3578e45d356 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 = mozilla::MakeUnique(mLen); - memset(mFrame.get(), COLOR, mLen); + mFrame = (uint8_t*) PR_MALLOC(mLen); + memset(mFrame, COLOR, mLen); numFrames = 121; } @@ -101,7 +101,7 @@ public: { do { - mSession->SendVideoFrame(reinterpret_cast(mFrame.get()), + mSession->SendVideoFrame((unsigned char*)mFrame, mLen, width, height, @@ -115,7 +115,7 @@ public: private: RefPtr mSession; -mozilla::UniquePtr mFrame; +mozilla::ScopedDeletePtr 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::UniquePtr audioInput(mozilla::MakeUnique(PLAYOUT_SAMPLE_LENGTH)); - mozilla::UniquePtr audioOutput(mozilla::MakeUnique(PLAYOUT_SAMPLE_LENGTH)); + mozilla::ScopedDeletePtr audioInput(new int16_t [PLAYOUT_SAMPLE_LENGTH]); + mozilla::ScopedDeletePtr audioOutput(new int16_t [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 1ae3a5e21d8..640e8263f4f 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) { - UniquePtr agent( + ScopedDeletePtr agent( new SignalingAgent("agent", stun_addr, stun_port)); agent->Init(); - agents_.push_back(agent.release()); + agents_.push_back(agent.forget()); return true; } void CreateAgentNoInit() { - UniquePtr agent(new SignalingAgent("agent")); - agents_.push_back(agent.release()); + ScopedDeletePtr agent(new SignalingAgent("agent")); + agents_.push_back(agent.forget()); } SignalingAgent *agent(size_t i) { @@ -1749,8 +1749,8 @@ public: if (init_) return; - a1_ = MakeUnique(callerName, stun_addr_, stun_port_); - a2_ = MakeUnique(calleeName, stun_addr_, stun_port_); + a1_ = new SignalingAgent(callerName, stun_addr_, stun_port_); + a2_ = new SignalingAgent(calleeName, stun_addr_, stun_port_); if (GetParam() == "no_bundle") { a1_->SetBundleEnabled(false); @@ -2170,8 +2170,8 @@ public: protected: bool init_; - UniquePtr a1_; // Canonically "caller" - UniquePtr a2_; // Canonically "callee" + ScopedDeletePtr a1_; // Canonically "caller" + ScopedDeletePtr a2_; // Canonically "callee" std::string stun_addr_; uint16_t stun_port_; };