Bug 1423253 - Change MediaEngineRemoteVideoSource to push instead of pull. r=padenot
authorAndreas Pehrson <apehrson@mozilla.com>
Fri, 22 Mar 2019 11:42:23 +0000
changeset 465635 54b4c9399b81821c28b0f6cad7be8676575c9f24
parent 465634 9e13d07d7617b480e81878c016c51145c0432569
child 465636 60d215858649ce5f058db2f715004749c17e7c93
push id35744
push userapavel@mozilla.com
push dateFri, 22 Mar 2019 16:44:08 +0000
treeherdermozilla-central@e66a2b59914d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1423253
milestone68.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 1423253 - Change MediaEngineRemoteVideoSource to push instead of pull. r=padenot Differential Revision: https://phabricator.services.mozilla.com/D22901
dom/media/MediaManager.cpp
dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
dom/media/webrtc/MediaEngineRemoteVideoSource.h
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -4286,64 +4286,65 @@ SourceListener::InitializeAsync() {
                                   __func__);
                    return;
                  }
                }
 
                LOG("started all sources");
                aHolder.Resolve(true, __func__);
              })
-      ->Then(
-          GetMainThreadSerialEventTarget(), __func__,
-          [self = RefPtr<SourceListener>(this), this]() {
-            if (mStopped) {
-              // We were shut down during the async init
-              return SourceListenerPromise::CreateAndResolve(true, __func__);
-            }
-
-            for (DeviceState* state :
-                 {mAudioDeviceState.get(), mVideoDeviceState.get()}) {
-              if (!state) {
-                continue;
-              }
-              MOZ_DIAGNOSTIC_ASSERT(!state->mTrackEnabled);
-              MOZ_DIAGNOSTIC_ASSERT(!state->mDeviceEnabled);
-              MOZ_DIAGNOSTIC_ASSERT(!state->mStopped);
-
-              state->mDeviceEnabled = true;
-              state->mTrackEnabled = true;
-              state->mTrackEnabledTime = TimeStamp::Now();
-
-              if (state == mVideoDeviceState.get() && !mStream->IsDestroyed()) {
-                mStream->SetPullingEnabled(kVideoTrack, true);
-              }
-            }
-            return SourceListenerPromise::CreateAndResolve(true, __func__);
-          },
-          [self = RefPtr<SourceListener>(this),
-           this](RefPtr<MediaMgrError>&& aResult) {
-            if (mStopped) {
-              return SourceListenerPromise::CreateAndReject(std::move(aResult),
-                                                            __func__);
-            }
-
-            for (DeviceState* state :
-                 {mAudioDeviceState.get(), mVideoDeviceState.get()}) {
-              if (!state) {
-                continue;
-              }
-              MOZ_DIAGNOSTIC_ASSERT(!state->mTrackEnabled);
-              MOZ_DIAGNOSTIC_ASSERT(!state->mDeviceEnabled);
-              MOZ_DIAGNOSTIC_ASSERT(!state->mStopped);
-
-              state->mStopped = true;
-            }
-            return SourceListenerPromise::CreateAndReject(std::move(aResult),
-                                                          __func__);
-          });
+      ->Then(GetMainThreadSerialEventTarget(), __func__,
+             [self = RefPtr<SourceListener>(this), this]() {
+               if (mStopped) {
+                 // We were shut down during the async init
+                 return SourceListenerPromise::CreateAndResolve(true, __func__);
+               }
+
+               for (DeviceState* state :
+                    {mAudioDeviceState.get(), mVideoDeviceState.get()}) {
+                 if (!state) {
+                   continue;
+                 }
+                 MOZ_DIAGNOSTIC_ASSERT(!state->mTrackEnabled);
+                 MOZ_DIAGNOSTIC_ASSERT(!state->mDeviceEnabled);
+                 MOZ_DIAGNOSTIC_ASSERT(!state->mStopped);
+
+                 state->mDeviceEnabled = true;
+                 state->mTrackEnabled = true;
+                 state->mTrackEnabledTime = TimeStamp::Now();
+
+                 if (state == mVideoDeviceState.get() &&
+                     state->mDevice->mSource->IsFake() &&
+                     !mStream->IsDestroyed()) {
+                   mStream->SetPullingEnabled(kVideoTrack, true);
+                 }
+               }
+               return SourceListenerPromise::CreateAndResolve(true, __func__);
+             },
+             [self = RefPtr<SourceListener>(this),
+              this](RefPtr<MediaMgrError>&& aResult) {
+               if (mStopped) {
+                 return SourceListenerPromise::CreateAndReject(
+                     std::move(aResult), __func__);
+               }
+
+               for (DeviceState* state :
+                    {mAudioDeviceState.get(), mVideoDeviceState.get()}) {
+                 if (!state) {
+                   continue;
+                 }
+                 MOZ_DIAGNOSTIC_ASSERT(!state->mTrackEnabled);
+                 MOZ_DIAGNOSTIC_ASSERT(!state->mDeviceEnabled);
+                 MOZ_DIAGNOSTIC_ASSERT(!state->mStopped);
+
+                 state->mStopped = true;
+               }
+               return SourceListenerPromise::CreateAndReject(std::move(aResult),
+                                                             __func__);
+             });
 }
 
 void SourceListener::Stop() {
   MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread");
 
   if (mStopped) {
     return;
   }
--- a/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
+++ b/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
@@ -381,21 +381,16 @@ nsresult MediaEngineRemoteVideoSource::S
                               mCaptureIndex)) {
     MOZ_DIAGNOSTIC_ASSERT(false, "Stopping a started capture failed");
     return NS_ERROR_FAILURE;
   }
 
   {
     MutexAutoLock lock(mMutex);
     mState = kStopped;
-
-    // Drop any cached image so we don't start with a stale image on next
-    // usage.  Also, gfx gets very upset if these are held until this object
-    // is gc'd in final-cc during shutdown (bug 1374164)
-    mImage = nullptr;
   }
 
   return NS_OK;
 }
 
 nsresult MediaEngineRemoteVideoSource::Reconfigure(
     const RefPtr<AllocationHandle>& aHandle,
     const MediaTrackConstraints& aConstraints, const MediaEnginePrefs& aPrefs,
@@ -487,47 +482,17 @@ webrtc::CaptureCapability MediaEngineRem
                           mCapEngine, mUniqueId.get(), aIndex, result);
   return result;
 }
 
 void MediaEngineRemoteVideoSource::Pull(
     const RefPtr<const AllocationHandle>& aHandle,
     const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
     StreamTime aEndOfAppendedData, StreamTime aDesiredTime,
-    const PrincipalHandle& aPrincipalHandle) {
-  TRACE_AUDIO_CALLBACK_COMMENT("SourceMediaStream %p track %i", aStream.get(),
-                               aTrackID);
-  MutexAutoLock lock(mMutex);
-  if (mState == kReleased) {
-    // We end the track before deallocating, so this is safe.
-    return;
-  }
-
-  MOZ_ASSERT(mState == kStarted || mState == kStopped);
-
-  StreamTime delta = aDesiredTime - aEndOfAppendedData;
-  MOZ_ASSERT(delta > 0);
-
-  VideoSegment segment;
-  RefPtr<layers::Image> image = mImage;
-  if (mState == kStarted) {
-    MOZ_ASSERT(!image || mImageSize == image->GetSize());
-    segment.AppendFrame(image.forget(), delta, mImageSize, aPrincipalHandle);
-  } else {
-    // nullptr images are allowed, but we force it to black and retain the size.
-    segment.AppendFrame(image.forget(), delta, mImageSize, aPrincipalHandle,
-                        true);
-  }
-
-  // This is safe from any thread, and is safe if the track is Finished
-  // or Destroyed.
-  // This can fail if either a) we haven't added the track yet, or b)
-  // we've removed or finished the track.
-  aStream->AppendToTrack(aTrackID, &segment);
-}
+    const PrincipalHandle& aPrincipalHandle) {}
 
 int MediaEngineRemoteVideoSource::DeliverFrame(
     uint8_t* aBuffer, const camera::VideoFrameProperties& aProps) {
   // Cameras IPC thread - take great care with accessing members!
 
   int32_t req_max_width;
   int32_t req_max_height;
   int32_t req_ideal_width;
@@ -665,25 +630,23 @@ int MediaEngineRemoteVideoSource::Delive
           // arrival of first frame, after correct settings values have been
           // made available (Resolve() is idempotent if already resolved).
           holder.ResolveIfExists(true, __func__);
         }));
   }
 
   {
     MutexAutoLock lock(mMutex);
-    // implicitly releases last image
-    mImage = image.forget();
-    mImageSize = mImage->GetSize();
+    MOZ_ASSERT(mState == kStarted);
+    VideoSegment segment;
+    mImageSize = image->GetSize();
+    segment.AppendFrame(image.forget(), 1, mImageSize, mPrincipal);
+    mStream->AppendToTrack(mTrackID, &segment);
   }
 
-  // We'll push the frame into the MSG on the next Pull. This will avoid
-  // swamping the MSG with frames should it be taking longer than normal to run
-  // an iteration.
-
   return 0;
 }
 
 uint32_t MediaEngineRemoteVideoSource::GetDistance(
     const webrtc::CaptureCapability& aCandidate,
     const NormalizedConstraintSet& aConstraints, const nsString& aDeviceId,
     const DistanceCalculation aCalculate) const {
   if (aCalculate == kFeasibility) {
--- a/dom/media/webrtc/MediaEngineRemoteVideoSource.h
+++ b/dom/media/webrtc/MediaEngineRemoteVideoSource.h
@@ -204,20 +204,16 @@ class MediaEngineRemoteVideoSource : pub
   // Set under mMutex on the owning thread. Accessed under one of the two.
   PrincipalHandle mPrincipal = PRINCIPAL_HANDLE_NONE;
 
   // Set in Start() and Deallocate() on the owning thread.
   // Accessed in DeliverFrame() on the camera IPC thread, guaranteed to happen
   // after Start() and before the end of Stop().
   RefPtr<layers::ImageContainer> mImageContainer;
 
-  // The latest frame delivered from the video capture backend.
-  // Protected by mMutex.
-  RefPtr<layers::Image> mImage;
-
   // A buffer pool used to manage the temporary buffer used when rescaling
   // incoming images. Cameras IPC thread only.
   webrtc::I420BufferPool mRescalingBufferPool;
 
   // The intrinsic size of the latest captured image, so we can feed black
   // images of the same size while stopped.
   // Set under mMutex on the Cameras IPC thread. Accessed under one of the two.
   gfx::IntSize mImageSize = gfx::IntSize(0, 0);