Bug 1404198: Part 2g - Switch to NS_NewTimer* in media. r=njn
authorKris Maglione <maglione.k@gmail.com>
Sun, 15 Oct 2017 23:14:33 -0700
changeset 386360 71117dd0686c940af0e41834895c86a5abf1cc4d
parent 386359 08f1f4f0aa5399f25fbe71ccd4900582e4cda039
child 386361 247d3966c7ac1220c39a86b31b8a98bfbc4895fe
push id96230
push usermaglione.k@gmail.com
push dateMon, 16 Oct 2017 20:44:15 +0000
treeherdermozilla-inbound@33b50e696014 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1404198
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1404198: Part 2g - Switch to NS_NewTimer* in media. r=njn MozReview-Commit-ID: 3ydSj5HfYzZ
media/mtransport/nr_timer.cpp
media/mtransport/test/sctp_unittest.cpp
media/mtransport/transportlayerdtls.cpp
media/mtransport/transportlayerloopback.cpp
media/webrtc/signaling/gtest/mediapipeline_unittest.cpp
media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.cpp
media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
media/webrtc/signaling/test/FakeMediaStreamsImpl.h
--- a/media/mtransport/nr_timer.cpp
+++ b/media/mtransport/nr_timer.cpp
@@ -202,24 +202,22 @@ static int nr_async_timer_set_zero(NR_as
 }
 
 static int nr_async_timer_set_nonzero(int timeout, NR_async_cb cb, void *arg,
                                       char *func, int l,
                                       nrappkitCallback **handle) {
   nsresult rv;
   CheckSTSThread();
 
-  nsCOMPtr<nsITimer> timer = do_CreateInstance(NS_TIMER_CONTRACTID, &rv);
-  if (NS_FAILED(rv)) {
-    return(R_FAILED);
-  }
-
   nrappkitTimerCallback* callback =
       new nrappkitTimerCallback(cb, arg, func, l);
-  rv = timer->InitWithCallback(callback, timeout, nsITimer::TYPE_ONE_SHOT);
+
+  nsCOMPtr<nsITimer> timer;
+  rv = NS_NewTimerWithCallback(getter_AddRefs(timer),
+                               callback, timeout, nsITimer::TYPE_ONE_SHOT);
   if (NS_FAILED(rv)) {
     return R_FAILED;
   }
 
   // Move the ownership of the timer to the callback object, which holds the
   // timer alive per spec.
   callback->SetTimer(timer.forget());
 
--- a/media/mtransport/test/sctp_unittest.cpp
+++ b/media/mtransport/test/sctp_unittest.cpp
@@ -63,17 +63,17 @@ class TransportTestPeer : public sigslot
  public:
   TransportTestPeer(std::string name, int local_port, int remote_port,
                     MtransportTestUtils* utils)
       : name_(name), connected_(false),
         sent_(0), received_(0),
         flow_(new TransportFlow()),
         loopback_(new TransportLayerLoopback()),
         sctp_(usrsctp_socket(AF_CONN, SOCK_STREAM, IPPROTO_SCTP, receive_cb, nullptr, 0, nullptr)),
-        timer_(do_CreateInstance(NS_TIMER_CONTRACTID)),
+        timer_(NS_NewTimer()),
         periodic_(nullptr),
         test_utils_(utils) {
     std::cerr << "Creating TransportTestPeer; flow=" <<
         static_cast<void *>(flow_.get()) <<
         " local=" << local_port <<
         " remote=" << remote_port << std::endl;
 
     usrsctp_register_address(static_cast<void *>(this));
--- a/media/mtransport/transportlayerdtls.cpp
+++ b/media/mtransport/transportlayerdtls.cpp
@@ -384,18 +384,18 @@ nsresult TransportLayerDtls::InitInterna
   nsresult rv;
   target_ = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
 
   if (NS_FAILED(rv)) {
     MOZ_MTLOG(ML_ERROR, "Couldn't get socket transport service");
     return rv;
   }
 
-  timer_ = do_CreateInstance(NS_TIMER_CONTRACTID, &rv);
-  if (NS_FAILED(rv)) {
+  timer_ = NS_NewTimer();
+  if (!timer_) {
     MOZ_MTLOG(ML_ERROR, "Couldn't get timer");
     return rv;
   }
 
   return NS_OK;
 }
 
 
--- a/media/mtransport/transportlayerloopback.cpp
+++ b/media/mtransport/transportlayerloopback.cpp
@@ -24,28 +24,26 @@
 #include "transportflow.h"
 #include "transportlayerloopback.h"
 
 namespace mozilla {
 
 MOZ_MTLOG_MODULE("mtransport")
 
 nsresult TransportLayerLoopback::Init() {
-  timer_ = do_CreateInstance(NS_TIMER_CONTRACTID);
-  MOZ_ASSERT(timer_);
-  if (!timer_)
-    return NS_ERROR_FAILURE;
-
   nsresult rv;
   target_ = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
   MOZ_ASSERT(NS_SUCCEEDED(rv));
   if (!NS_SUCCEEDED(rv))
     return rv;
 
-  timer_->SetTarget(target_);
+  timer_ = NS_NewTimer(target_);
+  MOZ_ASSERT(timer_);
+  if (!timer_)
+    return NS_ERROR_FAILURE;
 
   packets_lock_ = PR_NewLock();
   MOZ_ASSERT(packets_lock_);
   if (!packets_lock_)
     return NS_ERROR_FAILURE;
 
   deliverer_ = new Deliverer(this);
 
--- a/media/webrtc/signaling/gtest/mediapipeline_unittest.cpp
+++ b/media/webrtc/signaling/gtest/mediapipeline_unittest.cpp
@@ -84,21 +84,21 @@ public:
 
   FakeAudioStreamTrack()
     : AudioStreamTrack(new DOMMediaStream(nullptr, nullptr), 0, 1,
                        new FakeMediaStreamTrackSource())
     , mMutex("Fake AudioStreamTrack")
     , mStop(false)
     , mCount(0)
   {
-    mTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
-    mTimer->SetTarget(test_utils->sts_target());
-    mTimer->InitWithNamedFuncCallback(FakeAudioStreamTrackGenerateData, this, 20,
-                                      nsITimer::TYPE_REPEATING_SLACK,
-                                      "FakeAudioStreamTrack::FakeAudioStreamTrackGenerateData");
+    NS_NewTimerWithFuncCallback(getter_AddRefs(mTimer),
+                                FakeAudioStreamTrackGenerateData, this, 20,
+                                nsITimer::TYPE_REPEATING_SLACK,
+                                "FakeAudioStreamTrack::FakeAudioStreamTrackGenerateData",
+                                test_utils->sts_target());
 
   }
 
   void Stop()
   {
     mozilla::MutexAutoLock lock(mMutex);
     mStop = true;
     mTimer->Cancel();
--- a/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
+++ b/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
@@ -269,17 +269,17 @@ WebrtcVideoConduit::WebrtcVideoConduit(R
   , mCodecMode(webrtc::kRealtimeVideo)
   , mCall(aCall) // refcounted store of the call object
   , mSendStreamConfig(this) // 'this' is stored but not  dereferenced in the constructor.
   , mRecvStreamConfig(this) // 'this' is stored but not  dereferenced in the constructor.
   , mRecvSSRC(0)
   , mRecvSSRCSetInProgress(false)
   , mSendCodecPlugin(nullptr)
   , mRecvCodecPlugin(nullptr)
-  , mVideoStatsTimer(do_CreateInstance(NS_TIMER_CONTRACTID))
+  , mVideoStatsTimer(NS_NewTimer())
 {
   mRecvStreamConfig.renderer = this;
 
   // Video Stats Callback
   nsTimerCallbackFunc callback = [](nsITimer* aTimer, void* aClosure) {
     CSFLogDebug(LOGTAG, "StreamStats polling scheduled for VideoConduit: %p", aClosure);
     auto self = static_cast<WebrtcVideoConduit*>(aClosure);
     MutexAutoLock lock(self->mCodecMutex);
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.cpp
@@ -365,23 +365,22 @@ PeerConnectionCtx::UpdateNetworkState(bo
   for (auto pc : ctx->mPeerConnections) {
     pc.second->UpdateNetworkState(online);
   }
 }
 
 nsresult PeerConnectionCtx::Initialize() {
   initGMP();
 
-  mTelemetryTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
-  MOZ_ASSERT(mTelemetryTimer);
-  nsresult rv = mTelemetryTimer->SetTarget(SystemGroup::EventTargetFor(TaskCategory::Other));
+  nsresult rv = NS_NewTimerWithFuncCallback(getter_AddRefs(mTelemetryTimer),
+                                            EverySecondTelemetryCallback_m, this, 1000,
+                                            nsITimer::TYPE_REPEATING_PRECISE_CAN_SKIP,
+                                            "EverySecondTelemetryCallback_m",
+                                            SystemGroup::EventTargetFor(TaskCategory::Other));
   NS_ENSURE_SUCCESS(rv, rv);
-  mTelemetryTimer->InitWithNamedFuncCallback(EverySecondTelemetryCallback_m, this, 1000,
-                                             nsITimer::TYPE_REPEATING_PRECISE_CAN_SKIP,
-                                             "EverySecondTelemetryCallback_m");
 
   if (XRE_IsContentProcess()) {
     WebrtcGlobalChild::Create();
   }
 
   return NS_OK;
 }
 
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
@@ -2631,18 +2631,17 @@ PeerConnectionImpl::InsertDTMF(mozilla::
     }
   }
 
   // No state yet, create a new one
   if (!state) {
     state = mDTMFStates.AppendElement();
     state->mPeerConnectionImpl = this;
     state->mTrackId = senderTrackId;
-    state->mSendTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
-    MOZ_ASSERT(state->mSendTimer);
+    state->mSendTimer = NS_NewTimer();
   }
   MOZ_ASSERT(state);
 
   auto trackPairs = mJsepSession->GetNegotiatedTrackPairs();
   state->mLevel = -1;
   for (auto& trackPair : trackPairs) {
     if (state->mTrackId.EqualsASCII(trackPair.mSending->GetTrackId().c_str())) {
       if (trackPair.HasBundleLevel()) {
--- a/media/webrtc/signaling/test/FakeMediaStreamsImpl.h
+++ b/media/webrtc/signaling/test/FakeMediaStreamsImpl.h
@@ -32,24 +32,18 @@ mozilla::TrackTicks Fake_MediaStream::Ti
 mozilla::StreamTime
 Fake_MediaStream::TicksToTimeRoundDown(mozilla::TrackRate aRate,
                                        mozilla::TrackTicks aTicks) {
   return aTicks * GRAPH_RATE / aRate;
 }
 
 // Fake_SourceMediaStream
 nsresult Fake_SourceMediaStream::Start() {
-  mTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
-  if (!mTimer) {
-    return NS_ERROR_FAILURE;
-  }
-
-  mTimer->InitWithCallback(mPeriodic, 100, nsITimer::TYPE_REPEATING_SLACK);
-
-  return NS_OK;
+  return NS_NewTimerWithCallback(getter_AddRefs(mTimer),
+                                 mPeriodic, 100, nsITimer::TYPE_REPEATING_SLACK);
 }
 
 nsresult Fake_SourceMediaStream::Stop() {
   mozilla::MutexAutoLock lock(mMutex);
   if (mTimer)
     mTimer->Cancel();
   mPeriodic->Detach();
   return NS_OK;
@@ -78,24 +72,18 @@ void Fake_MediaStreamTrack::AddListener(
 }
 void Fake_MediaStreamTrack::RemoveListener(Fake_MediaStreamTrackListener *aListener)
 {
   mOwningStream->GetInputStream()->RemoveTrackListener(aListener, mTrackID);
 }
 
 // Fake_MediaStreamBase
 nsresult Fake_MediaStreamBase::Start() {
-  mTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
-  if (!mTimer) {
-    return NS_ERROR_FAILURE;
-  }
-
-  mTimer->InitWithCallback(mPeriodic, 100, nsITimer::TYPE_REPEATING_SLACK);
-
-  return NS_OK;
+  return NS_NewTimerWithCallback(getter_AddRefs(mTimer),
+                                 mPeriodic, 100, nsITimer::TYPE_REPEATING_SLACK);
 }
 
 nsresult Fake_MediaStreamBase::Stop() {
   // Lock the mutex so that we know that after this
   // has returned, periodic will not be firing again
   // and so it's safe to destruct.
   mozilla::MutexAutoLock lock(mMutex);
   mTimer->Cancel();