Bug 1322095 - Part 1b: Update callbacks to support moved args and convert nsAutoPtr usage. r=jya draft
authorEric Rahm <erahm@mozilla.com>
Thu, 16 Jan 2020 18:28:41 +0000
changeset 2598864 e6d168a3fefb4aa1c73080701bfc874f1f4fcc12
parent 2598863 151019a4d8b562149da134a729d229610ff1ceab
child 2598865 44d9f56e7f7a8aa7b3f29c629aae90d4df187dc5
push id476909
push userreviewbot
push dateThu, 16 Jan 2020 18:29:02 +0000
treeherdertry@f359ae6f022c [default view] [failures only]
reviewersjya
bugs1322095
milestone74.0a1
Bug 1322095 - Part 1b: Update callbacks to support moved args and convert nsAutoPtr usage. r=jya In order to support the update to move args when invoking callbacks we: - Convert anything that was using WrapRunnable with `nsAutoPtr` to `UniquePtr` - Convert anything that was using a non-const ref as a param to either a const ref or a by-val copy Addtionally we convert the remaining `nsAutoPtr` usage to `UniquePtr`. Differential Revision: https://phabricator.services.mozilla.com/D59961 Differential Diff: PHID-DIFF-ixd6uaco7d47rjddg4p2
dom/media/gmp/GMPServiceParent.cpp
dom/network/UDPSocketParent.cpp
dom/network/UDPSocketParent.h
media/mtransport/nr_socket_prsock.cpp
media/mtransport/nr_socket_prsock.h
media/mtransport/nr_timer.cpp
media/mtransport/nricectx.h
media/mtransport/test/sctp_unittest.cpp
media/mtransport/test/test_nr_socket_unittest.cpp
media/mtransport/test/transport_unittests.cpp
media/mtransport/transportflow.cpp
media/mtransport/transportflow.h
media/mtransport/transportlayerloopback.h
media/mtransport/transportlayersrtp.cpp
media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
media/webrtc/signaling/src/media-conduit/VideoConduit.h
media/webrtc/signaling/src/media-conduit/WebrtcGmpVideoCodec.cpp
media/webrtc/signaling/src/media-conduit/WebrtcGmpVideoCodec.h
media/webrtc/signaling/src/media-conduit/WebrtcMediaCodecVP8VideoCodec.cpp
media/webrtc/signaling/src/media-conduit/WebrtcMediaCodecVP8VideoCodec.h
media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
media/webrtc/signaling/src/peerconnection/MediaTransportHandler.cpp
media/webrtc/signaling/src/peerconnection/MediaTransportHandler.h
media/webrtc/signaling/src/peerconnection/MediaTransportParent.cpp
media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h
media/webrtc/signaling/src/peerconnection/WebrtcGlobalInformation.cpp
netwerk/sctp/datachannel/DataChannel.cpp
netwerk/sctp/datachannel/DataChannel.h
--- a/dom/media/gmp/GMPServiceParent.cpp
+++ b/dom/media/gmp/GMPServiceParent.cpp
@@ -912,17 +912,17 @@ void GeckoMediaPluginServiceParent::Remo
       nsCOMPtr<nsIRunnable> task = new NotifyObserversTask(
           "gmp-directory-deleted", nsString(aDirectory));
       mMainThread->Dispatch(task.forget());
     }
   }
 }
 
 // May remove when Bug 1043671 is fixed
-static void Dummy(RefPtr<GMPParent>& aOnDeathsDoor) {
+static void Dummy(RefPtr<GMPParent> aOnDeathsDoor) {
   // exists solely to do nothing and let the Runnable kill the GMPParent
   // when done.
 }
 
 void GeckoMediaPluginServiceParent::PluginTerminated(
     const RefPtr<GMPParent>& aPlugin) {
   MOZ_ASSERT(mGMPThread->EventTarget()->IsOnCurrentThread());
 
--- a/dom/network/UDPSocketParent.cpp
+++ b/dom/network/UDPSocketParent.cpp
@@ -244,27 +244,28 @@ mozilla::ipc::IPCResult UDPSocketParent:
 }
 
 void UDPSocketParent::DoSendConnectResponse(
     const UDPAddressInfo& aAddressInfo) {
   // can't use directly with WrapRunnable due to warnings
   mozilla::Unused << SendCallbackConnected(aAddressInfo);
 }
 
-void UDPSocketParent::SendConnectResponse(nsIEventTarget* aThread,
-                                          const UDPAddressInfo& aAddressInfo) {
+void UDPSocketParent::SendConnectResponse(
+    const nsCOMPtr<nsIEventTarget>& aThread,
+    const UDPAddressInfo& aAddressInfo) {
   Unused << NS_WARN_IF(NS_FAILED(aThread->Dispatch(
       WrapRunnable(RefPtr<UDPSocketParent>(this),
                    &UDPSocketParent::DoSendConnectResponse, aAddressInfo),
       NS_DISPATCH_NORMAL)));
 }
 
 // Runs on STS thread
-void UDPSocketParent::DoConnect(nsCOMPtr<nsIUDPSocket>& aSocket,
-                                nsCOMPtr<nsIEventTarget>& aReturnThread,
+void UDPSocketParent::DoConnect(const nsCOMPtr<nsIUDPSocket>& aSocket,
+                                const nsCOMPtr<nsIEventTarget>& aReturnThread,
                                 const UDPAddressInfo& aAddressInfo) {
   UDPSOCKET_LOG(("%s: %s:%u", __FUNCTION__, aAddressInfo.addr().get(),
                  aAddressInfo.port()));
   if (NS_FAILED(ConnectInternal(aAddressInfo.addr(), aAddressInfo.port()))) {
     SendInternalError(aReturnThread, __LINE__);
     return;
   }
   CheckSTSThread();
@@ -548,17 +549,17 @@ void UDPSocketParent::FireInternalError(
   if (!mIPCOpen) {
     return;
   }
 
   mozilla::Unused << SendCallbackError(NS_LITERAL_CSTRING("Internal error"),
                                        NS_LITERAL_CSTRING(__FILE__), aLineNo);
 }
 
-void UDPSocketParent::SendInternalError(nsIEventTarget* aThread,
+void UDPSocketParent::SendInternalError(const nsCOMPtr<nsIEventTarget>& aThread,
                                         uint32_t aLineNo) {
   UDPSOCKET_LOG(("SendInternalError: %u", aLineNo));
   Unused << NS_WARN_IF(NS_FAILED(aThread->Dispatch(
       WrapRunnable(RefPtr<UDPSocketParent>(this),
                    &UDPSocketParent::FireInternalError, aLineNo),
       NS_DISPATCH_NORMAL)));
 }
 
--- a/dom/network/UDPSocketParent.h
+++ b/dom/network/UDPSocketParent.h
@@ -33,20 +33,20 @@ class UDPSocketParent : public mozilla::
 
   mozilla::ipc::IPCResult RecvBind(const UDPAddressInfo& aAddressInfo,
                                    const bool& aAddressReuse,
                                    const bool& aLoopback,
                                    const uint32_t& recvBufferSize,
                                    const uint32_t& sendBufferSize);
   mozilla::ipc::IPCResult RecvConnect(const UDPAddressInfo& aAddressInfo);
   void DoSendConnectResponse(const UDPAddressInfo& aAddressInfo);
-  void SendConnectResponse(nsIEventTarget* aThread,
+  void SendConnectResponse(const nsCOMPtr<nsIEventTarget>& aThread,
                            const UDPAddressInfo& aAddressInfo);
-  void DoConnect(nsCOMPtr<nsIUDPSocket>& aSocket,
-                 nsCOMPtr<nsIEventTarget>& aReturnThread,
+  void DoConnect(const nsCOMPtr<nsIUDPSocket>& aSocket,
+                 const nsCOMPtr<nsIEventTarget>& aReturnThread,
                  const UDPAddressInfo& aAddressInfo);
 
   mozilla::ipc::IPCResult RecvOutgoingData(const UDPData& aData,
                                            const UDPSocketAddr& aAddr);
 
   mozilla::ipc::IPCResult RecvClose();
   mozilla::ipc::IPCResult RecvRequestDelete();
   mozilla::ipc::IPCResult RecvJoinMulticast(const nsCString& aMulticastAddress,
@@ -61,17 +61,18 @@ class UDPSocketParent : public mozilla::
   void Send(const nsTArray<uint8_t>& aData, const UDPSocketAddr& aAddr);
   void Send(const IPCStream& aStream, const UDPSocketAddr& aAddr);
   nsresult BindInternal(const nsCString& aHost, const uint16_t& aPort,
                         const bool& aAddressReuse, const bool& aLoopback,
                         const uint32_t& recvBufferSize,
                         const uint32_t& sendBufferSize);
   nsresult ConnectInternal(const nsCString& aHost, const uint16_t& aPort);
   void FireInternalError(uint32_t aLineNo);
-  void SendInternalError(nsIEventTarget* aThread, uint32_t aLineNo);
+  void SendInternalError(const nsCOMPtr<nsIEventTarget>& aThread,
+                         uint32_t aLineNo);
 
   PBackgroundParent* mBackgroundManager;
 
   bool mIPCOpen;
   nsCOMPtr<nsIUDPSocket> mSocket;
   nsCOMPtr<nsISocketFilter> mFilter;
   nsCOMPtr<nsIPrincipal> mPrincipal;
 };
--- a/media/mtransport/nr_socket_prsock.cpp
+++ b/media/mtransport/nr_socket_prsock.cpp
@@ -1137,19 +1137,19 @@ NS_IMETHODIMP NrUdpSocketIpc::CallListen
     if (PR_SUCCESS !=
         PR_SetNetAddr(PR_IpAddrNull, addr.raw.family, port, &addr)) {
       err_ = true;
       MOZ_ASSERT(false, "Failed to set port in PRNetAddr");
       return NS_OK;
     }
   }
 
-  nsAutoPtr<MediaPacket> buf(new MediaPacket);
+  auto buf = MakeUnique<MediaPacket>();
   buf->Copy(data.Elements(), data.Length());
-  RefPtr<nr_udp_message> msg(new nr_udp_message(addr, buf));
+  RefPtr<nr_udp_message> msg(new nr_udp_message(addr, std::move(buf)));
 
   RUN_ON_THREAD(sts_thread_,
                 mozilla::WrapRunnable(RefPtr<NrUdpSocketIpc>(this),
                                       &NrUdpSocketIpc::recv_callback_s, msg),
                 NS_DISPATCH_NORMAL);
   return NS_OK;
 }
 
@@ -1318,23 +1318,24 @@ int NrUdpSocketIpc::sendto(const void* m
   if ((r = nr_transport_addr_to_netaddr(to, &addr))) {
     return r;
   }
 
   if (nr_is_stun_request_message((UCHAR*)msg, len) && ShouldDrop(len)) {
     return R_WOULDBLOCK;
   }
 
-  nsAutoPtr<MediaPacket> buf(new MediaPacket);
+  UniquePtr<MediaPacket> buf(new MediaPacket);
   buf->Copy(static_cast<const uint8_t*>(msg), len);
 
-  RUN_ON_THREAD(io_thread_,
-                mozilla::WrapRunnable(RefPtr<NrUdpSocketIpc>(this),
-                                      &NrUdpSocketIpc::sendto_i, addr, buf),
-                NS_DISPATCH_NORMAL);
+  RUN_ON_THREAD(
+      io_thread_,
+      mozilla::WrapRunnable(RefPtr<NrUdpSocketIpc>(this),
+                            &NrUdpSocketIpc::sendto_i, addr, std::move(buf)),
+      NS_DISPATCH_NORMAL);
   return 0;
 }
 
 void NrUdpSocketIpc::close() {
   r_log(LOG_GENERIC, LOG_DEBUG, "NrUdpSocketIpc::close()");
 
   ASSERT_ON_THREAD(sts_thread_);
 
@@ -1527,17 +1528,17 @@ void NrUdpSocketIpc::connect_i(const nsA
     mon.NotifyAll();
     return;
   }
 
   socket_child_->Connect(proxy, host, port);
 }
 
 void NrUdpSocketIpc::sendto_i(const net::NetAddr& addr,
-                              nsAutoPtr<MediaPacket> buf) {
+                              UniquePtr<MediaPacket> buf) {
   ASSERT_ON_THREAD(io_thread_);
 
   ReentrantMonitorAutoEnter mon(monitor_);
 
   if (!socket_child_) {
     MOZ_ASSERT(false);
     err_ = true;
     return;
@@ -1559,17 +1560,17 @@ void NrUdpSocketIpc::close_i() {
 
 #if defined(MOZILLA_INTERNAL_API)
 
 static void ReleaseIOThread_s() { sThread->ReleaseUse(); }
 
 // close(), but transfer the socket_child_ reference to die as well
 // static
 void NrUdpSocketIpc::destroy_i(dom::UDPSocketChild* aChild,
-                               nsCOMPtr<nsIEventTarget>& aStsThread) {
+                               nsCOMPtr<nsIEventTarget> aStsThread) {
   RefPtr<dom::UDPSocketChild> socket_child_ref =
       already_AddRefed<dom::UDPSocketChild>(aChild);
   if (socket_child_ref) {
     socket_child_ref->Close();
   }
 
   RUN_ON_THREAD(aStsThread, WrapRunnableNM(&ReleaseIOThread_s),
                 NS_DISPATCH_NORMAL);
--- a/media/mtransport/nr_socket_prsock.h
+++ b/media/mtransport/nr_socket_prsock.h
@@ -46,17 +46,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 #define nr_socket_prsock__
 
 #include <memory>
 #include <queue>
 
 #include "nspr.h"
 #include "prio.h"
 
-#include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "nsASocketHandler.h"
 #include "nsXPCOM.h"
 #include "nsIEventTarget.h"
 #include "nsIUDPSocketChild.h"
 #include "nsProxyRelease.h"
 #include "nsThreadUtils.h"
 
@@ -191,23 +190,23 @@ class NrSocket : public NrSocketBase, pu
 
   DISALLOW_COPY_ASSIGN(NrSocket);
 
   PRFileDesc* fd_;
   nsCOMPtr<nsIEventTarget> ststhread_;
 };
 
 struct nr_udp_message {
-  nr_udp_message(const PRNetAddr& from, nsAutoPtr<MediaPacket>& data)
-      : from(from), data(data) {}
+  nr_udp_message(const PRNetAddr& from, UniquePtr<MediaPacket>&& data)
+      : from(from), data(std::move(data)) {}
 
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(nr_udp_message);
 
   PRNetAddr from;
-  nsAutoPtr<MediaPacket> data;
+  UniquePtr<MediaPacket> data;
 
  private:
   ~nr_udp_message() {}
   DISALLOW_COPY_ASSIGN(nr_udp_message);
 };
 
 class NrSocketIpc : public NrSocketBase {
  public:
@@ -267,21 +266,21 @@ class NrUdpSocketIpc : public NrSocketIp
 
   DISALLOW_COPY_ASSIGN(NrUdpSocketIpc);
 
   nsresult SetAddress();  // Set the local address from parent info.
 
   // Main or private thread executors of the NrSocketBase APIs
   void create_i(const nsACString& host, const uint16_t port);
   void connect_i(const nsACString& host, const uint16_t port);
-  void sendto_i(const net::NetAddr& addr, nsAutoPtr<MediaPacket> buf);
+  void sendto_i(const net::NetAddr& addr, UniquePtr<MediaPacket> buf);
   void close_i();
 #if defined(MOZILLA_INTERNAL_API) && !defined(MOZILLA_XPCOMRT_API)
   static void destroy_i(dom::UDPSocketChild* aChild,
-                        nsCOMPtr<nsIEventTarget>& aStsThread);
+                        nsCOMPtr<nsIEventTarget> aStsThread);
 #endif
   // STS thread executor
   void recv_callback_s(RefPtr<nr_udp_message> msg);
 
   ReentrantMonitor monitor_;  // protects err_and state_
   bool err_;
   NrSocketIpcState state_;
 
--- a/media/mtransport/nr_timer.cpp
+++ b/media/mtransport/nr_timer.cpp
@@ -46,26 +46,26 @@
    POSSIBILITY OF SUCH DAMAGE.
 
 
    ekr@rtfm.com  Sun Feb 22 19:35:24 2004
  */
 
 #include <string>
 
-#include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "nsComponentManagerUtils.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIEventTarget.h"
 #include "nsINamed.h"
 #include "nsITimer.h"
 #include "nsNetCID.h"
 #include "runnable_utils.h"
 #include "mozilla/DebugOnly.h"
+#include "mozilla/UniquePtr.h"
 
 extern "C" {
 #include "nr_api.h"
 #include "async_timer.h"
 }
 
 namespace mozilla {
 
@@ -172,17 +172,17 @@ static void CheckSTSThread() {
 }
 
 static int nr_async_timer_set_zero(NR_async_cb cb, void* arg, char* func, int l,
                                    nrappkitCallback** handle) {
   nrappkitScheduledCallback* callback(
       new nrappkitScheduledCallback(cb, arg, func, l));
 
   nsresult rv = GetSTSThread()->Dispatch(
-      WrapRunnable(nsAutoPtr<nrappkitScheduledCallback>(callback),
+      WrapRunnable(UniquePtr<nrappkitScheduledCallback>(callback),
                    &nrappkitScheduledCallback::Run),
       NS_DISPATCH_NORMAL);
   if (NS_FAILED(rv)) return R_FAILED;
 
   *handle = callback;
 
   // On exit to this function, the only strong reference to callback is in
   // the Runnable. Because we are redispatching to the same thread,
--- a/media/mtransport/nricectx.h
+++ b/media/mtransport/nricectx.h
@@ -56,17 +56,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 #include <map>
 
 #include "sigslot.h"
 
 #include "prnetdb.h"
 
 #include "mozilla/RefPtr.h"
 #include "mozilla/UniquePtr.h"
-#include "nsAutoPtr.h"
 #include "nsIEventTarget.h"
 #include "nsTArray.h"
 
 #include "m_cpp_utils.h"
 #include "nricestunaddr.h"
 #include "nricemediastream.h"
 
 typedef struct nr_ice_ctx_ nr_ice_ctx;
--- a/media/mtransport/test/sctp_unittest.cpp
+++ b/media/mtransport/test/sctp_unittest.cpp
@@ -193,35 +193,35 @@ class TransportTestPeer : public sigslot
 
     ++sent_;
   }
 
   int sent() const { return sent_; }
   int received() const { return received_; }
   bool connected() const { return connected_; }
 
-  static TransportResult SendPacket_s(nsAutoPtr<MediaPacket> packet,
+  static TransportResult SendPacket_s(UniquePtr<MediaPacket> packet,
                                       const RefPtr<TransportFlow>& flow,
                                       TransportLayer* layer) {
     return layer->SendPacket(*packet);
   }
 
   TransportResult SendPacket(const unsigned char* data, size_t len) {
-    nsAutoPtr<MediaPacket> packet(new MediaPacket);
+    UniquePtr<MediaPacket> packet(new MediaPacket);
     packet->Copy(data, len);
 
     // Uses DISPATCH_NORMAL to avoid possible deadlocks when we're called
     // from MainThread especially during shutdown (same as DataChannels).
     // RUN_ON_THREAD short-circuits if already on the STS thread, which is
     // normal for most transfers outside of connect() and close().  Passes
     // a refptr to flow_ to avoid any async deletion issues (since we can't
     // make 'this' into a refptr as it isn't refcounted)
     RUN_ON_THREAD(test_utils_->sts_target(),
-                  WrapRunnableNM(&TransportTestPeer::SendPacket_s, packet,
-                                 flow_, loopback_),
+                  WrapRunnableNM(&TransportTestPeer::SendPacket_s,
+                                 std::move(packet), flow_, loopback_),
                   NS_DISPATCH_NORMAL);
 
     return 0;
   }
 
   void PacketReceived(TransportLayer* layer, MediaPacket& packet) {
     std::cerr << "Received " << packet.len() << " bytes" << std::endl;
 
--- a/media/mtransport/test/test_nr_socket_unittest.cpp
+++ b/media/mtransport/test/test_nr_socket_unittest.cpp
@@ -18,17 +18,16 @@ extern "C" {
 #include "registry.h"
 }
 
 #include "test_nr_socket.h"
 
 #include "nsCOMPtr.h"
 #include "nsNetCID.h"
 #include "nsServiceManagerUtils.h"
-#include "nsAutoPtr.h"
 #include "runnable_utils.h"
 
 #include <vector>
 
 #define GTEST_HAS_RTTI 0
 #include "gtest/gtest.h"
 #include "gtest_utils.h"
 
--- a/media/mtransport/test/transport_unittests.cpp
+++ b/media/mtransport/test/transport_unittests.cpp
@@ -223,34 +223,34 @@ class TlsParser {
 
 class DtlsRecordParser {
  public:
   DtlsRecordParser(const unsigned char* data, size_t len)
       : buffer_(), offset_(0) {
     buffer_.Copy(data, len);
   }
 
-  bool NextRecord(uint8_t* ct, nsAutoPtr<MediaPacket>* buffer) {
+  bool NextRecord(uint8_t* ct, UniquePtr<MediaPacket>* buffer) {
     if (!remaining()) return false;
 
     CHECK_LENGTH(13U);
     const uint8_t* ctp = reinterpret_cast<const uint8_t*>(ptr());
     consume(11);  // ct + version + length
 
     const uint16_t* tmp = reinterpret_cast<const uint16_t*>(ptr());
     size_t length = ntohs(*tmp);
     consume(2);
 
     CHECK_LENGTH(length);
-    MediaPacket* db = new MediaPacket;
+    auto db = MakeUnique<MediaPacket>();
     db->Copy(ptr(), length);
     consume(length);
 
     *ct = *ctp;
-    *buffer = db;
+    *buffer = std::move(db);
 
     return true;
   }
 
  private:
   size_t remaining() const { return buffer_.len() - offset_; }
   const uint8_t* ptr() const { return buffer_.data() + offset_; }
   void consume(size_t len) { offset_ += len; }
@@ -263,17 +263,17 @@ class DtlsRecordParser {
 // them on.
 class DtlsRecordInspector : public Inspector {
  public:
   virtual void Inspect(TransportLayer* layer, const unsigned char* data,
                        size_t len) {
     DtlsRecordParser parser(data, len);
 
     uint8_t ct;
-    nsAutoPtr<MediaPacket> buf;
+    UniquePtr<MediaPacket> buf;
     while (parser.NextRecord(&ct, &buf)) {
       OnRecord(layer, ct, buf->data(), buf->len());
     }
   }
 
   virtual void OnRecord(TransportLayer* layer, uint8_t content_type,
                         const unsigned char* record, size_t len) = 0;
 };
--- a/media/mtransport/transportflow.cpp
+++ b/media/mtransport/transportflow.cpp
@@ -20,29 +20,28 @@ NS_IMPL_ISUPPORTS0(TransportFlow)
 
 // There are some hacks here to allow destruction off of
 // the main thread.
 TransportFlow::~TransportFlow() {
   // Push the destruction onto the STS thread. Note that there
   // is still some possibility that someone is accessing this
   // object simultaneously, but as long as smart pointer discipline
   // is maintained, it shouldn't be possible to access and
-  // destroy it simultaneously. The conversion to an nsAutoPtr
+  // destroy it simultaneously. The conversion to a UniquePtr
   // ensures automatic destruction of the queue at exit of
   // DestroyFinal.
   MOZ_RELEASE_ASSERT(target_);
-  nsAutoPtr<std::deque<TransportLayer*>> layers_tmp(layers_.release());
   DebugOnly<nsresult> rv = target_->Dispatch(
-      WrapRunnableNM(&TransportFlow::DestroyFinal, layers_tmp),
+      WrapRunnableNM(&TransportFlow::DestroyFinal, std::move(layers_)),
       NS_DISPATCH_NORMAL);
   MOZ_ASSERT(NS_SUCCEEDED(rv));
 }
 
 void TransportFlow::DestroyFinal(
-    nsAutoPtr<std::deque<TransportLayer*>> layers) {
+    UniquePtr<std::deque<TransportLayer*>> layers) {
   ClearLayers(layers.get());
 }
 
 void TransportFlow::ClearLayers(std::deque<TransportLayer*>* layers) {
   while (!layers->empty()) {
     delete layers->front();
     layers->pop_front();
   }
--- a/media/mtransport/transportflow.h
+++ b/media/mtransport/transportflow.h
@@ -12,17 +12,16 @@
 #include <deque>
 #include <string>
 
 #include "nscore.h"
 #include "nsISupportsImpl.h"
 #include "mozilla/UniquePtr.h"
 #include "transportlayer.h"
 #include "m_cpp_utils.h"
-#include "nsAutoPtr.h"
 
 // A stack of transport layers acts as a flow.
 // Generally, one reads and writes to the top layer.
 
 // This code has a confusing hybrid threading model which
 // probably needs some eventual refactoring.
 // TODO(ekr@rtfm.com): Bug 844891
 //
@@ -87,17 +86,17 @@ class TransportFlow final : public nsISu
       return true;
     if (NS_FAILED(target_->IsOnCurrentThread(&on))) return false;
 
     return on;
   }
 
   void EnsureSameThread(TransportLayer* layer);
 
-  static void DestroyFinal(nsAutoPtr<std::deque<TransportLayer*>> layers);
+  static void DestroyFinal(UniquePtr<std::deque<TransportLayer*>> layers);
 
   // Overload needed because we use deque internally and queue externally.
   static void ClearLayers(std::deque<TransportLayer*>* layers);
 
   std::string id_;
   UniquePtr<std::deque<TransportLayer*>> layers_;
   nsCOMPtr<nsIEventTarget> target_;
 };
--- a/media/mtransport/transportlayerloopback.h
+++ b/media/mtransport/transportlayerloopback.h
@@ -11,17 +11,16 @@
 
 #include "nspr.h"
 #include "prio.h"
 #include "prlock.h"
 
 #include <memory>
 #include <queue>
 
-#include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "nsINamed.h"
 #include "nsITimer.h"
 
 #include "m_cpp_utils.h"
 #include "transportflow.h"
 #include "transportlayer.h"
 
--- a/media/mtransport/transportlayersrtp.cpp
+++ b/media/mtransport/transportlayersrtp.cpp
@@ -9,17 +9,16 @@
 #include "transportlayersrtp.h"
 #include "transportlayerdtls.h"
 
 #include "logging.h"
 #include "nsError.h"
 #include "mozilla/Assertions.h"
 #include "transportlayerdtls.h"
 #include "srtp.h"
-#include "nsAutoPtr.h"
 
 namespace mozilla {
 
 MOZ_MTLOG_MODULE("mtransport")
 
 static char kDTLSExporterLabel[] = "EXTRACTOR-dtls_srtp";
 
 TransportLayerSrtp::TransportLayerSrtp(TransportLayerDtls& dtls) {
--- a/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
+++ b/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
@@ -8,16 +8,17 @@
 
 #include "AudioConduit.h"
 #include "VideoConduit.h"
 #include "VideoStreamFactory.h"
 #include "YuvStamper.h"
 #include "mozilla/TemplateLib.h"
 #include "mozilla/media/MediaUtils.h"
 #include "mozilla/StaticPrefs_media.h"
+#include "mozilla/UniquePtr.h"
 #include "nsComponentManagerUtils.h"
 #include "nsIPrefBranch.h"
 #include "nsIGfxInfo.h"
 #include "nsIPrefService.h"
 #include "nsServiceManagerUtils.h"
 
 #include "nsThreadUtils.h"
 
@@ -446,23 +447,23 @@ RefPtr<VideoSessionConduit> VideoSession
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aCall, "missing required parameter: aCall");
   CSFLogVerbose(LOGTAG, "%s", __FUNCTION__);
 
   if (!aCall) {
     return nullptr;
   }
 
-  nsAutoPtr<WebrtcVideoConduit> obj(new WebrtcVideoConduit(aCall, aStsThread));
+  auto obj = MakeUnique<WebrtcVideoConduit>(aCall, aStsThread);
   if (obj->Init() != kMediaConduitNoError) {
     CSFLogError(LOGTAG, "%s VideoConduit Init Failed ", __FUNCTION__);
     return nullptr;
   }
   CSFLogVerbose(LOGTAG, "%s Successfully created VideoConduit ", __FUNCTION__);
-  return obj.forget();
+  return obj.release();
 }
 
 WebrtcVideoConduit::WebrtcVideoConduit(
     RefPtr<WebRtcCallWrapper> aCall, nsCOMPtr<nsISerialEventTarget> aStsThread)
     : mTransportMonitor("WebrtcVideoConduit"),
       mStsThread(aStsThread),
       mMutex("WebrtcVideoConduit::mMutex"),
       mVideoAdapter(MakeUnique<cricket::VideoAdapter>()),
@@ -936,17 +937,17 @@ MediaConduitErrorCode WebrtcVideoConduit
     mSendStreamConfig.rtp.ulpfec.red_payload_type = -1;
     mSendStreamConfig.rtp.ulpfec.red_rtx_payload_type = -1;
   }
 
   mSendStreamConfig.rtp.nack.rtp_history_ms =
       codecConfig->RtcpFbNackIsSet("") ? 1000 : 0;
 
   // Copy the applied config for future reference.
-  mCurSendCodecConfig = new VideoCodecConfig(*codecConfig);
+  mCurSendCodecConfig = MakeUnique<VideoCodecConfig>(*codecConfig);
 
   mSendStreamConfig.rtp.rids.clear();
   bool has_rid = false;
   for (size_t idx = 0; idx < streamCount; idx++) {
     auto& encoding = mCurSendCodecConfig->mEncodings[idx];
     if (encoding.rid[0]) {
       has_rid = true;
       break;
@@ -1792,17 +1793,17 @@ void WebrtcVideoConduit::SelectSendResol
           static_cast<int>(mCurSendCodecConfig->mEncodingConstraints.maxFs *
                            (16 * 16)));
     }
     mVideoAdapter->OnResolutionFramerateRequest(
         rtc::Optional<int>(), max_fs, std::numeric_limits<int>::max());
   }
 
   unsigned int framerate = SelectSendFrameRate(
-      mCurSendCodecConfig, mSendingFramerate, width, height);
+      mCurSendCodecConfig.get(), mSendingFramerate, width, height);
   if (mSendingFramerate != framerate) {
     CSFLogDebug(LOGTAG, "%s: framerate changing to %u (from %u)", __FUNCTION__,
                 framerate, mSendingFramerate);
     mSendingFramerate = framerate;
     mVideoStreamFactory->SetSendingFramerate(mSendingFramerate);
   }
 }
 
--- a/media/webrtc/signaling/src/media-conduit/VideoConduit.h
+++ b/media/webrtc/signaling/src/media-conduit/VideoConduit.h
@@ -4,17 +4,17 @@
 
 #ifndef VIDEO_SESSION_H_
 #define VIDEO_SESSION_H_
 
 #include "mozilla/Atomics.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/ReentrantMonitor.h"
 #include "mozilla/SharedThreadPool.h"
-#include "nsAutoPtr.h"
+#include "mozilla/UniquePtr.h"
 #include "nsITimer.h"
 
 #include "MediaConduitInterface.h"
 #include "MediaEngineWrapper.h"
 #include "RunningStat.h"
 #include "RtpPacketQueue.h"
 #include "runnable_utils.h"
 
@@ -518,17 +518,17 @@ class WebrtcVideoConduit
       mEngineTransmitting;  // If true ==> Transmit Subsystem is up and running
   mozilla::Atomic<bool>
       mEngineReceiving;  // if true ==> Receive Subsystem up and running
 
   // Local database of currently applied receive codecs. Main thread only.
   nsTArray<UniquePtr<VideoCodecConfig>> mRecvCodecList;
 
   // Written only on main thread. Guarded by mMutex, except for reads on main.
-  nsAutoPtr<VideoCodecConfig> mCurSendCodecConfig;
+  UniquePtr<VideoCodecConfig> mCurSendCodecConfig;
 
   bool mUpdateResolution = false;
   int mSinkWantsPixelCount = std::numeric_limits<int>::max();
 
   // Bookkeeping of send stream stats. Sts thread only.
   SendStreamStatistics mSendStreamStats;
 
   // Bookkeeping of send stream stats. Sts thread only.
--- a/media/webrtc/signaling/src/media-conduit/WebrtcGmpVideoCodec.cpp
+++ b/media/webrtc/signaling/src/media-conduit/WebrtcGmpVideoCodec.cpp
@@ -317,17 +317,18 @@ void WebrtcGmpVideoEncoder::RegetEncoder
   if (NS_WARN_IF(NS_FAILED(mMPS->GetGMPVideoEncoder(
           nullptr, &tags, NS_LITERAL_CSTRING(""), std::move(callback))))) {
     aInitDone->Dispatch(WEBRTC_VIDEO_CODEC_ERROR,
                         "GMP Encode: GetGMPVideoEncoder failed");
   }
 }
 
 void WebrtcGmpVideoEncoder::Encode_g(
-    RefPtr<WebrtcGmpVideoEncoder>& aEncoder, webrtc::VideoFrame aInputImage,
+    const RefPtr<WebrtcGmpVideoEncoder>& aEncoder,
+    webrtc::VideoFrame aInputImage,
     std::vector<webrtc::FrameType> aFrameTypes) {
   if (!aEncoder->mGMP) {
     // destroyed via Terminate(), failed to init, or just not initted yet
     GMP_LOG_DEBUG("GMP Encode: not initted yet");
     return;
   }
   MOZ_ASSERT(aEncoder->mHost);
 
@@ -415,17 +416,17 @@ int32_t WebrtcGmpVideoEncoder::RegisterE
   MutexAutoLock lock(mCallbackMutex);
   mCallback = aCallback;
 
   return WEBRTC_VIDEO_CODEC_OK;
 }
 
 /* static */
 void WebrtcGmpVideoEncoder::ReleaseGmp_g(
-    RefPtr<WebrtcGmpVideoEncoder>& aEncoder) {
+    const RefPtr<WebrtcGmpVideoEncoder>& aEncoder) {
   aEncoder->Close_g();
 }
 
 int32_t WebrtcGmpVideoEncoder::Shutdown() {
   GMP_LOG_DEBUG("GMP Released:");
   if (mGMPThread) {
     mGMPThread->Dispatch(WrapRunnableNM(&WebrtcGmpVideoEncoder::ReleaseGmp_g,
                                         RefPtr<WebrtcGmpVideoEncoder>(this)),
@@ -738,18 +739,17 @@ int32_t WebrtcGmpVideoDecoder::GmpInitDo
   }
 
   // now release any frames that got queued waiting for InitDone
   if (!mQueuedFrames.IsEmpty()) {
     // So we're safe to call Decode_g(), which asserts it's empty
     nsTArray<UniquePtr<GMPDecodeData>> temp;
     temp.SwapElements(mQueuedFrames);
     for (auto& queued : temp) {
-      Decode_g(RefPtr<WebrtcGmpVideoDecoder>(this),
-               nsAutoPtr<GMPDecodeData>(queued.release()));
+      Decode_g(RefPtr<WebrtcGmpVideoDecoder>(this), std::move(queued));
     }
   }
 
   // This is an ugly solution to asynchronous decoding errors
   // from Decode_g() not being returned to the synchronous Decode() method.
   // If we don't return an error code at this point, our caller ultimately won't
   // know to request a PLI and the video stream will remain frozen unless an IDR
   // happens to arrive for other reasons. Bug 1492852 tracks implementing a
@@ -787,41 +787,40 @@ int32_t WebrtcGmpVideoDecoder::Decode(
   }
 
   // This is an ugly solution to asynchronous decoding errors
   // from Decode_g() not being returned to the synchronous Decode() method.
   // If we don't return an error code at this point, our caller ultimately won't
   // know to request a PLI and the video stream will remain frozen unless an IDR
   // happens to arrive for other reasons. Bug 1492852 tracks implementing a
   // proper solution.
-  nsAutoPtr<GMPDecodeData> decodeData(
-      new GMPDecodeData(aInputImage, aMissingFrames, aRenderTimeMs));
+  auto decodeData =
+      MakeUnique<GMPDecodeData>(aInputImage, aMissingFrames, aRenderTimeMs);
 
-  mGMPThread->Dispatch(
-      WrapRunnableNM(&WebrtcGmpVideoDecoder::Decode_g,
-                     RefPtr<WebrtcGmpVideoDecoder>(this), decodeData),
-      NS_DISPATCH_NORMAL);
+  mGMPThread->Dispatch(WrapRunnableNM(&WebrtcGmpVideoDecoder::Decode_g,
+                                      RefPtr<WebrtcGmpVideoDecoder>(this),
+                                      std::move(decodeData)),
+                       NS_DISPATCH_NORMAL);
 
   if (mDecoderStatus != GMPNoErr) {
     GMP_LOG_ERROR("%s: Decoder status is bad (%u)!", __PRETTY_FUNCTION__,
                   static_cast<unsigned>(mDecoderStatus));
     return WEBRTC_VIDEO_CODEC_ERROR;
   }
 
   return WEBRTC_VIDEO_CODEC_OK;
 }
 
 /* static */
-// Using nsAutoPtr because WrapRunnable doesn't support move semantics
 void WebrtcGmpVideoDecoder::Decode_g(const RefPtr<WebrtcGmpVideoDecoder>& aThis,
-                                     nsAutoPtr<GMPDecodeData> aDecodeData) {
+                                     UniquePtr<GMPDecodeData> aDecodeData) {
   if (!aThis->mGMP) {
     if (aThis->mInitting) {
       // InitDone hasn't been called yet (race)
-      aThis->mQueuedFrames.AppendElement(aDecodeData.forget());
+      aThis->mQueuedFrames.AppendElement(std::move(aDecodeData));
       return;
     }
     // destroyed via Terminate(), failed to init, or just not initted yet
     GMP_LOG_DEBUG("GMP Decode: not initted yet");
 
     aThis->mDecoderStatus = GMPDecodeErr;
     return;
   }
@@ -904,17 +903,17 @@ int32_t WebrtcGmpVideoDecoder::RegisterD
   MutexAutoLock lock(mCallbackMutex);
   mCallback = aCallback;
 
   return WEBRTC_VIDEO_CODEC_OK;
 }
 
 /* static */
 void WebrtcGmpVideoDecoder::ReleaseGmp_g(
-    RefPtr<WebrtcGmpVideoDecoder>& aDecoder) {
+    const RefPtr<WebrtcGmpVideoDecoder>& aDecoder) {
   aDecoder->Close_g();
 }
 
 int32_t WebrtcGmpVideoDecoder::ReleaseGmp() {
   GMP_LOG_DEBUG("GMP Released:");
   RegisterDecodeCompleteCallback(nullptr);
 
   if (mGMPThread) {
--- a/media/webrtc/signaling/src/media-conduit/WebrtcGmpVideoCodec.h
+++ b/media/webrtc/signaling/src/media-conduit/WebrtcGmpVideoCodec.h
@@ -212,17 +212,17 @@ class WebrtcGmpVideoEncoder : public GMP
                            const RefPtr<GmpInitDoneRunnable>& aInitDone);
   int32_t GmpInitDone(GMPVideoEncoderProxy* aGMP, GMPVideoHost* aHost,
                       const GMPVideoCodec& aCodecParams,
                       uint32_t aMaxPayloadSize, std::string* aErrorOut);
   int32_t GmpInitDone(GMPVideoEncoderProxy* aGMP, GMPVideoHost* aHost,
                       std::string* aErrorOut);
   int32_t InitEncoderForSize(unsigned short aWidth, unsigned short aHeight,
                              std::string* aErrorOut);
-  static void ReleaseGmp_g(RefPtr<WebrtcGmpVideoEncoder>& aEncoder);
+  static void ReleaseGmp_g(const RefPtr<WebrtcGmpVideoEncoder>& aEncoder);
   void Close_g();
 
   class InitDoneCallback : public GetGMPVideoEncoderCallback {
    public:
     InitDoneCallback(const RefPtr<WebrtcGmpVideoEncoder>& aEncoder,
                      const RefPtr<GmpInitDoneRunnable>& aInitDone,
                      const GMPVideoCodec& aCodecParams,
                      uint32_t aMaxPayloadSize)
@@ -242,17 +242,17 @@ class WebrtcGmpVideoEncoder : public GMP
 
    private:
     RefPtr<WebrtcGmpVideoEncoder> mEncoder;
     RefPtr<GmpInitDoneRunnable> mInitDone;
     GMPVideoCodec mCodecParams;
     uint32_t mMaxPayloadSize;
   };
 
-  static void Encode_g(RefPtr<WebrtcGmpVideoEncoder>& aEncoder,
+  static void Encode_g(const RefPtr<WebrtcGmpVideoEncoder>& aEncoder,
                        webrtc::VideoFrame aInputImage,
                        std::vector<webrtc::FrameType> aFrameTypes);
   void RegetEncoderForResolutionChange(
       uint32_t aWidth, uint32_t aHeight,
       const RefPtr<GmpInitDoneRunnable>& aInitDone);
 
   class InitDoneForResolutionChangeCallback
       : public GetGMPVideoEncoderCallback {
@@ -400,17 +400,17 @@ class WebrtcGmpVideoDecoder : public GMP
   virtual ~WebrtcGmpVideoDecoder();
 
   static void InitDecode_g(const RefPtr<WebrtcGmpVideoDecoder>& aThis,
                            const webrtc::VideoCodec* aCodecSettings,
                            int32_t aNumberOfCores,
                            const RefPtr<GmpInitDoneRunnable>& aInitDone);
   int32_t GmpInitDone(GMPVideoDecoderProxy* aGMP, GMPVideoHost* aHost,
                       std::string* aErrorOut);
-  static void ReleaseGmp_g(RefPtr<WebrtcGmpVideoDecoder>& aDecoder);
+  static void ReleaseGmp_g(const RefPtr<WebrtcGmpVideoDecoder>& aDecoder);
   void Close_g();
 
   class InitDoneCallback : public GetGMPVideoDecoderCallback {
    public:
     explicit InitDoneCallback(const RefPtr<WebrtcGmpVideoDecoder>& aDecoder,
                               const RefPtr<GmpInitDoneRunnable>& aInitDone)
         : mDecoder(aDecoder), mInitDone(aInitDone) {}
 
@@ -423,17 +423,17 @@ class WebrtcGmpVideoDecoder : public GMP
     }
 
    private:
     RefPtr<WebrtcGmpVideoDecoder> mDecoder;
     RefPtr<GmpInitDoneRunnable> mInitDone;
   };
 
   static void Decode_g(const RefPtr<WebrtcGmpVideoDecoder>& aThis,
-                       nsAutoPtr<GMPDecodeData> aDecodeData);
+                       UniquePtr<GMPDecodeData> aDecodeData);
 
   nsCOMPtr<mozIGeckoMediaPluginService> mMPS;
   nsCOMPtr<nsIThread> mGMPThread;
   GMPVideoDecoderProxy* mGMP;  // Addref is held for us
   // Used to handle a race where Release() is called while init is in progress
   bool mInitting;
   // Frames queued for decode while mInitting is true
   nsTArray<UniquePtr<GMPDecodeData>> mQueuedFrames;
--- a/media/webrtc/signaling/src/media-conduit/WebrtcMediaCodecVP8VideoCodec.cpp
+++ b/media/webrtc/signaling/src/media-conduit/WebrtcMediaCodecVP8VideoCodec.cpp
@@ -165,17 +165,17 @@ static java::sdk::MediaCodec::LocalRef C
     return nullptr;
   }
 
   java::sdk::MediaCodec::LocalRef codec;
   java::sdk::MediaCodec::CreateEncoderByType(aMimeType, &codec);
   return codec;
 }
 
-static void ShutdownThread(nsCOMPtr<nsIThread>& aThread) {
+static void ShutdownThread(const nsCOMPtr<nsIThread>& aThread) {
   aThread->Shutdown();
 }
 
 // Base runnable class to repeatly pull MediaCodec output buffers in seperate
 // thread. How to use:
 // - implementing DrainOutput() to get output. Remember to return false to tell
 //   drain not to pop input queue.
 // - call QueueInput() to schedule a run to drain output. The input, aFrame,
--- a/media/webrtc/signaling/src/media-conduit/WebrtcMediaCodecVP8VideoCodec.h
+++ b/media/webrtc/signaling/src/media-conduit/WebrtcMediaCodecVP8VideoCodec.h
@@ -4,17 +4,16 @@
 
 #ifndef WebrtcMediaCodecVP8VideoCodec_h__
 #define WebrtcMediaCodecVP8VideoCodec_h__
 
 #include <jni.h>
 
 #include "mozilla/Mutex.h"
 #include "nsThreadUtils.h"
-#include "nsAutoPtr.h"
 
 #include "MediaConduitInterface.h"
 #include "AudioConduit.h"
 #include "VideoConduit.h"
 #include "GeneratedJNIWrappers.h"
 
 #include "webrtc/modules/video_coding/include/video_codec_interface.h"
 
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
@@ -480,17 +480,17 @@ void MediaPipeline::IncrementRtcpPackets
   ++mRtcpPacketsReceived;
   if (!(mRtcpPacketsReceived % 100)) {
     MOZ_LOG(gMediaPipelineLog, LogLevel::Info,
             ("RTCP received packet count for %s Pipeline %p: %u",
              mDescription.c_str(), this, mRtcpPacketsReceived));
   }
 }
 
-void MediaPipeline::RtpPacketReceived(MediaPacket& packet) {
+void MediaPipeline::RtpPacketReceived(const MediaPacket& packet) {
   if (mDirection == DirectionType::TRANSMIT) {
     return;
   }
 
   if (!mTransport->Pipeline()) {
     MOZ_LOG(gMediaPipelineLog, LogLevel::Error,
             ("Discarding incoming packet; transport disconnected"));
     return;
@@ -567,17 +567,17 @@ void MediaPipeline::RtpPacketReceived(Me
 
   mPacketDumper->Dump(mLevel, dom::mozPacketDumpType::Rtp, false, packet.data(),
                       packet.len());
 
   (void)mConduit->ReceivedRTPPacket(packet.data(), packet.len(),
                                     header.ssrc);  // Ignore error codes
 }
 
-void MediaPipeline::RtcpPacketReceived(MediaPacket& packet) {
+void MediaPipeline::RtcpPacketReceived(const MediaPacket& packet) {
   if (!mTransport->Pipeline()) {
     MOZ_LOG(gMediaPipelineLog, LogLevel::Debug,
             ("Discarding incoming packet; transport disconnected"));
     return;
   }
 
   if (!mConduit) {
     MOZ_LOG(gMediaPipelineLog, LogLevel::Debug,
@@ -615,17 +615,17 @@ void MediaPipeline::RtcpPacketReceived(M
     return;
   }
 
   (void)mConduit->ReceivedRTCPPacket(packet.data(),
                                      packet.len());  // Ignore error codes
 }
 
 void MediaPipeline::PacketReceived(const std::string& aTransportId,
-                                   MediaPacket& packet) {
+                                   const MediaPacket& packet) {
   if (mTransportId != aTransportId) {
     return;
   }
 
   if (!mTransport->Pipeline()) {
     MOZ_LOG(gMediaPipelineLog, LogLevel::Debug,
             ("Discarding incoming packet; transport disconnected"));
     return;
@@ -645,17 +645,17 @@ void MediaPipeline::PacketReceived(const
 void MediaPipeline::AlpnNegotiated(const std::string& aAlpn,
                                    bool aPrivacyRequested) {
   if (aPrivacyRequested) {
     MakePrincipalPrivate_s();
   }
 }
 
 void MediaPipeline::EncryptedPacketSending(const std::string& aTransportId,
-                                           MediaPacket& aPacket) {
+                                           const MediaPacket& aPacket) {
   if (mTransportId == aTransportId) {
     dom::mozPacketDumpType type;
     if (aPacket.type() == MediaPacket::SRTP) {
       type = dom::mozPacketDumpType::Srtp;
     } else if (aPacket.type() == MediaPacket::SRTCP) {
       type = dom::mozPacketDumpType::Srtcp;
     } else if (aPacket.type() == MediaPacket::DTLS) {
       // TODO(bug 1497936): Implement packet dump for DTLS
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
@@ -202,24 +202,25 @@ class MediaPipeline : public sigslot::ha
   void IncrementRtcpPacketsReceived();
 
   virtual void SendPacket(MediaPacket&& packet);
 
   // Process slots on transports
   void RtpStateChange(const std::string& aTransportId, TransportLayer::State);
   void RtcpStateChange(const std::string& aTransportId, TransportLayer::State);
   virtual void CheckTransportStates();
-  void PacketReceived(const std::string& aTransportId, MediaPacket& packet);
+  void PacketReceived(const std::string& aTransportId,
+                      const MediaPacket& packet);
   void AlpnNegotiated(const std::string& aAlpn, bool aPrivacyRequested);
 
-  void RtpPacketReceived(MediaPacket& packet);
-  void RtcpPacketReceived(MediaPacket& packet);
+  void RtpPacketReceived(const MediaPacket& packet);
+  void RtcpPacketReceived(const MediaPacket& packet);
 
   void EncryptedPacketSending(const std::string& aTransportId,
-                              MediaPacket& aPacket);
+                              const MediaPacket& aPacket);
 
   void SetDescription_s(const std::string& description);
 
   // Called when ALPN is negotiated and is requesting privacy, so receive
   // pipelines do not enter data into the graph under a content principal.
   virtual void MakePrincipalPrivate_s() {}
 
   const DirectionType mDirection;
--- a/media/webrtc/signaling/src/peerconnection/MediaTransportHandler.cpp
+++ b/media/webrtc/signaling/src/peerconnection/MediaTransportHandler.cpp
@@ -864,36 +864,36 @@ void MediaTransportHandler::OnConnection
         NS_DISPATCH_NORMAL);
     return;
   }
 
   SignalConnectionStateChange(aState);
 }
 
 void MediaTransportHandler::OnPacketReceived(const std::string& aTransportId,
-                                             MediaPacket& aPacket) {
+                                             const MediaPacket& aPacket) {
   if (mCallbackThread && !mCallbackThread->IsOnCurrentThread()) {
     mCallbackThread->Dispatch(
         WrapRunnable(RefPtr<MediaTransportHandler>(this),
                      &MediaTransportHandler::OnPacketReceived, aTransportId,
-                     aPacket),
+                     const_cast<MediaPacket&>(aPacket)),
         NS_DISPATCH_NORMAL);
     return;
   }
 
   SignalPacketReceived(aTransportId, aPacket);
 }
 
 void MediaTransportHandler::OnEncryptedSending(const std::string& aTransportId,
-                                               MediaPacket& aPacket) {
+                                               const MediaPacket& aPacket) {
   if (mCallbackThread && !mCallbackThread->IsOnCurrentThread()) {
     mCallbackThread->Dispatch(
         WrapRunnable(RefPtr<MediaTransportHandler>(this),
                      &MediaTransportHandler::OnEncryptedSending, aTransportId,
-                     aPacket),
+                     const_cast<MediaPacket&>(aPacket)),
         NS_DISPATCH_NORMAL);
     return;
   }
 
   SignalEncryptedSending(aTransportId, aPacket);
 }
 
 void MediaTransportHandler::OnStateChange(const std::string& aTransportId,
@@ -953,22 +953,22 @@ RefPtr<dom::RTCStatsPromise> MediaTransp
 }
 
 RefPtr<MediaTransportHandler::IceLogPromise>
 MediaTransportHandlerSTS::GetIceLog(const nsCString& aPattern) {
   return InvokeAsync(
       mStsThread, __func__, [=, self = RefPtr<MediaTransportHandlerSTS>(this)] {
         dom::Sequence<nsString> converted;
         RLogConnector* logs = RLogConnector::GetInstance();
-        nsAutoPtr<std::deque<std::string>> result(new std::deque<std::string>);
+        std::deque<std::string> result;
         // Might not exist yet.
         if (logs) {
-          logs->Filter(aPattern.get(), 0, result);
+          logs->Filter(aPattern.get(), 0, &result);
         }
-        for (auto& line : *result) {
+        for (auto& line : result) {
           converted.AppendElement(NS_ConvertUTF8toUTF16(line.c_str()),
                                   fallible);
         }
         return IceLogPromise::CreateAndResolve(std::move(converted), __func__);
       });
 }
 
 void MediaTransportHandlerSTS::ClearIceLog() {
--- a/media/webrtc/signaling/src/peerconnection/MediaTransportHandler.h
+++ b/media/webrtc/signaling/src/peerconnection/MediaTransportHandler.h
@@ -118,35 +118,37 @@ class MediaTransportHandler {
   virtual RefPtr<dom::RTCStatsPromise> GetIceStats(
       const std::string& aTransportId, DOMHighResTimeStamp aNow) = 0;
 
   sigslot::signal2<const std::string&, const CandidateInfo&> SignalCandidate;
   sigslot::signal2<const std::string&, bool> SignalAlpnNegotiated;
   sigslot::signal1<dom::RTCIceGatheringState> SignalGatheringStateChange;
   sigslot::signal1<dom::RTCIceConnectionState> SignalConnectionStateChange;
 
-  sigslot::signal2<const std::string&, MediaPacket&> SignalPacketReceived;
-  sigslot::signal2<const std::string&, MediaPacket&> SignalEncryptedSending;
+  sigslot::signal2<const std::string&, const MediaPacket&> SignalPacketReceived;
+  sigslot::signal2<const std::string&, const MediaPacket&>
+      SignalEncryptedSending;
   sigslot::signal2<const std::string&, TransportLayer::State> SignalStateChange;
   sigslot::signal2<const std::string&, TransportLayer::State>
       SignalRtcpStateChange;
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaTransportHandler)
 
   TransportLayer::State GetState(const std::string& aTransportId,
                                  bool aRtcp) const;
 
  protected:
   void OnCandidate(const std::string& aTransportId,
                    const CandidateInfo& aCandidateInfo);
   void OnAlpnNegotiated(const std::string& aAlpn);
   void OnGatheringStateChange(dom::RTCIceGatheringState aState);
   void OnConnectionStateChange(dom::RTCIceConnectionState aState);
-  void OnPacketReceived(const std::string& aTransportId, MediaPacket& aPacket);
+  void OnPacketReceived(const std::string& aTransportId,
+                        const MediaPacket& aPacket);
   void OnEncryptedSending(const std::string& aTransportId,
-                          MediaPacket& aPacket);
+                          const MediaPacket& aPacket);
   void OnStateChange(const std::string& aTransportId,
                      TransportLayer::State aState);
   void OnRtcpStateChange(const std::string& aTransportId,
                          TransportLayer::State aState);
   virtual ~MediaTransportHandler() = default;
   std::map<std::string, TransportLayer::State> mStateCache;
   std::map<std::string, TransportLayer::State> mRtcpStateCache;
   RefPtr<nsISerialEventTarget> mCallbackThread;
--- a/media/webrtc/signaling/src/peerconnection/MediaTransportParent.cpp
+++ b/media/webrtc/signaling/src/peerconnection/MediaTransportParent.cpp
@@ -56,22 +56,23 @@ class MediaTransportParent::Impl : publi
         mParent->SendOnGatheringStateChange(static_cast<int>(aState)));
   }
 
   void OnConnectionStateChange(dom::RTCIceConnectionState aState) {
     NS_ENSURE_TRUE_VOID(
         mParent->SendOnConnectionStateChange(static_cast<int>(aState)));
   }
 
-  void OnPacketReceived(const std::string& aTransportId, MediaPacket& aPacket) {
+  void OnPacketReceived(const std::string& aTransportId,
+                        const MediaPacket& aPacket) {
     NS_ENSURE_TRUE_VOID(mParent->SendOnPacketReceived(aTransportId, aPacket));
   }
 
   void OnEncryptedSending(const std::string& aTransportId,
-                          MediaPacket& aPacket) {
+                          const MediaPacket& aPacket) {
     NS_ENSURE_TRUE_VOID(mParent->SendOnEncryptedSending(aTransportId, aPacket));
   }
 
   void OnStateChange(const std::string& aTransportId,
                      TransportLayer::State aState) {
     NS_ENSURE_TRUE_VOID(mParent->SendOnStateChange(aTransportId, aState));
   }
 
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h
@@ -7,17 +7,16 @@
 
 #include <string>
 #include <vector>
 #include <map>
 #include <cmath>
 
 #include "prlock.h"
 #include "mozilla/RefPtr.h"
-#include "nsAutoPtr.h"
 #include "nsComponentManagerUtils.h"
 #include "nsPIDOMWindow.h"
 #include "nsIUUIDGenerator.h"
 #include "nsIThread.h"
 #include "mozilla/Mutex.h"
 
 // Work around nasty macro in webrtc/voice_engine/voice_engine_defines.h
 #ifdef GetLastError
--- a/media/webrtc/signaling/src/peerconnection/WebrtcGlobalInformation.cpp
+++ b/media/webrtc/signaling/src/peerconnection/WebrtcGlobalInformation.cpp
@@ -14,17 +14,16 @@
 #include <map>
 #include <queue>
 
 #include "CSFLog.h"
 #include "WebRtcLog.h"
 #include "mozilla/dom/WebrtcGlobalInformationBinding.h"
 #include "mozilla/dom/ContentChild.h"
 
-#include "nsAutoPtr.h"
 #include "nsNetCID.h"               // NS_SOCKETTRANSPORTSERVICE_CONTRACTID
 #include "nsServiceManagerUtils.h"  // do_GetService
 #include "mozilla/ErrorResult.h"
 #include "mozilla/Vector.h"
 #include "nsProxyRelease.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/Unused.h"
 #include "mozilla/StaticMutex.h"
--- a/netwerk/sctp/datachannel/DataChannel.cpp
+++ b/netwerk/sctp/datachannel/DataChannel.cpp
@@ -839,17 +839,17 @@ void DataChannelConnection::ProcessQueue
       NS_ASSERTION(
           false,
           "How did a DataChannel get queued without the FINISH_OPEN flag?");
     }
   }
 }
 
 void DataChannelConnection::SctpDtlsInput(const std::string& aTransportId,
-                                          MediaPacket& packet) {
+                                          const MediaPacket& packet) {
   if ((packet.type() != MediaPacket::SCTP) || (mTransportId != aTransportId)) {
     return;
   }
 
   if (MOZ_LOG_TEST(gSCTPLog, LogLevel::Debug)) {
     char* buf;
 
     if ((buf = usrsctp_dumppacket((void*)packet.data(), packet.len(),
--- a/netwerk/sctp/datachannel/DataChannel.h
+++ b/netwerk/sctp/datachannel/DataChannel.h
@@ -237,17 +237,18 @@ class DataChannelConnection final : publ
   }
 
   // Caller must hold mLock
   void SetReadyState(const uint16_t aState);
 
 #ifdef SCTP_DTLS_SUPPORTED
   static void DTLSConnectThread(void* data);
   void SendPacket(std::unique_ptr<MediaPacket>&& packet);
-  void SctpDtlsInput(const std::string& aTransportId, MediaPacket& packet);
+  void SctpDtlsInput(const std::string& aTransportId,
+                     const MediaPacket& packet);
   static int SctpDtlsOutput(void* addr, void* buffer, size_t length,
                             uint8_t tos, uint8_t set_df);
 #endif
   DataChannel* FindChannelByStream(uint16_t stream);
   uint16_t FindFreeStream();
   bool RequestMoreStreams(int32_t aNeeded = 16);
   uint32_t UpdateCurrentStreamIndex();
   uint32_t GetCurrentStreamIndex();