diff --git a/dom/media/MediaManager.cpp b/dom/media/MediaManager.cpp index 61de78e8760e..3a3e448685c0 100644 --- a/dom/media/MediaManager.cpp +++ b/dom/media/MediaManager.cpp @@ -356,6 +356,13 @@ public: mVideoDevice->GetMediaSource() == dom::MediaSourceEnum::Browser; } + void GetSettings(dom::MediaTrackSettings& aOutSettings) + { + if (mVideoDevice) { + mVideoDevice->GetSource()->GetSettings(aOutSettings); + } + } + // implement in .cpp to avoid circular dependency with MediaOperationTask // Can be invoked from EITHER MainThread or MSG thread void Stop(); @@ -1135,6 +1142,11 @@ public: return mListener->ApplyConstraintsToTrack(aWindow, mTrackID, aConstraints); } + void + GetSettings(dom::MediaTrackSettings& aOutSettings) override + { + mListener->GetSettings(aOutSettings); + } void Stop() override { diff --git a/dom/media/MediaStreamTrack.cpp b/dom/media/MediaStreamTrack.cpp index 39cde0c3c5f7..665994159d05 100644 --- a/dom/media/MediaStreamTrack.cpp +++ b/dom/media/MediaStreamTrack.cpp @@ -250,14 +250,16 @@ MediaStreamTrack::Stop() mReadyState = MediaStreamTrackState::Ended; } -void MediaStreamTrack::GetConstraints(dom::MediaTrackConstraints& aResult) +void +MediaStreamTrack::GetConstraints(dom::MediaTrackConstraints& aResult) { aResult = mConstraints; } -void MediaStreamTrack::GetSettings(dom::MediaTrackSettings& aResult) +void +MediaStreamTrack::GetSettings(dom::MediaTrackSettings& aResult) { - aResult = mSettings; + GetSource().GetSettings(aResult); } already_AddRefed diff --git a/dom/media/MediaStreamTrack.h b/dom/media/MediaStreamTrack.h index 14ee174b2a72..c6bdd12f3601 100644 --- a/dom/media/MediaStreamTrack.h +++ b/dom/media/MediaStreamTrack.h @@ -134,6 +134,12 @@ public: ApplyConstraints(nsPIDOMWindowInner* aWindow, const dom::MediaTrackConstraints& aConstraints); + /** + * Same for GetSettings (no-op). + */ + virtual void + GetSettings(dom::MediaTrackSettings& aResult) {}; + /** * Called by the source interface when all registered sinks have unregistered. */ @@ -213,6 +219,9 @@ public: MediaSourceEnum GetMediaSource() const override { return mMediaSource; } + void + GetSettings(dom::MediaTrackSettings& aResult) override {} + void Stop() override {} protected: @@ -436,7 +445,6 @@ protected: bool mEnabled; const bool mRemote; dom::MediaTrackConstraints mConstraints; - dom::MediaTrackSettings mSettings; }; } // namespace dom diff --git a/dom/media/webrtc/MediaEngine.h b/dom/media/webrtc/MediaEngine.h index 1eb7f1270876..39b14897e664 100644 --- a/dom/media/webrtc/MediaEngine.h +++ b/dom/media/webrtc/MediaEngine.h @@ -197,6 +197,12 @@ public: const nsTArray& aConstraintSets, const nsString& aDeviceId) const = 0; + void GetSettings(dom::MediaTrackSettings& aOutSettings) + { + MOZ_ASSERT(NS_IsMainThread()); + aOutSettings = mSettings; + } + protected: // Only class' own members can be initialized in constructor initializer list. explicit MediaEngineSource(MediaEngineState aState) @@ -217,6 +223,8 @@ protected: PRThread* mOwningThread; #endif bool mHasFakeTracks; + // Main-thread only: + dom::MediaTrackSettings mSettings; }; /** diff --git a/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp b/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp index ee21cecae957..d8c669fa802a 100644 --- a/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp +++ b/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp @@ -36,6 +36,9 @@ MediaEngineRemoteVideoSource::MediaEngineRemoteVideoSource( mInShutdown(false) { MOZ_ASSERT(aMediaSource != dom::MediaSourceEnum::Other); + mSettings.mWidth.Construct(0); + mSettings.mHeight.Construct(0); + mSettings.mFrameRate.Construct(0); Init(); } @@ -327,7 +330,7 @@ MediaEngineRemoteVideoSource::UpdateExisting(AllocationHandle* aHandle, return NS_ERROR_FAILURE; } mState = kAllocated; - mLastCapability = mCapability; + SetLastCapability(mCapability); LOG(("Video device %d allocated for %s", mCaptureIndex, aHandle->mOrigin.get())); break; @@ -342,7 +345,7 @@ MediaEngineRemoteVideoSource::UpdateExisting(AllocationHandle* aHandle, LOG(("StartCapture failed")); return NS_ERROR_FAILURE; } - mLastCapability = mCapability; + SetLastCapability(mCapability); } break; @@ -357,6 +360,23 @@ MediaEngineRemoteVideoSource::UpdateExisting(AllocationHandle* aHandle, return NS_OK; } +void +MediaEngineRemoteVideoSource::SetLastCapability( + const webrtc::CaptureCapability& aCapability) +{ + mLastCapability = mCapability; + + webrtc::CaptureCapability cap = aCapability; + RefPtr that = this; + + NS_DispatchToMainThread(media::NewRunnableFrom([this, that, cap]() mutable { + mSettings.mWidth.Value() = cap.width; + mSettings.mHeight.Value() = cap.height; + mSettings.mFrameRate.Value() = cap.maxFPS; + return NS_OK; + })); +} + void MediaEngineRemoteVideoSource::NotifyPull(MediaStreamGraph* aGraph, SourceMediaStream* aSource, diff --git a/dom/media/webrtc/MediaEngineRemoteVideoSource.h b/dom/media/webrtc/MediaEngineRemoteVideoSource.h index 907cc1b02ee9..74de4e5bed0f 100644 --- a/dom/media/webrtc/MediaEngineRemoteVideoSource.h +++ b/dom/media/webrtc/MediaEngineRemoteVideoSource.h @@ -130,6 +130,7 @@ private: void Init(); size_t NumCapabilities() const override; void GetCapability(size_t aIndex, webrtc::CaptureCapability& aOut) const override; + void SetLastCapability(const webrtc::CaptureCapability& aCapability); /* UpdateExisting - Centralized function to apply constraints and restart * device as needed, considering all allocations and changes to one.