From 2c32da060a8138f99b82f05b275996cdc2e8c1f5 Mon Sep 17 00:00:00 2001 From: Andreas Pehrson Date: Wed, 7 Apr 2021 09:44:33 +0200 Subject: [PATCH] Bug 1654112 - Constify VideoConduit members that are based on prefs. r=ng Differential Revision: https://phabricator.services.mozilla.com/D112848 --- dom/media/webrtc/jsapi/TransceiverImpl.cpp | 41 +++++++- .../libwebrtcglue/MediaConduitInterface.h | 21 ++-- .../webrtc/libwebrtcglue/VideoConduit.cpp | 97 +++---------------- dom/media/webrtc/libwebrtcglue/VideoConduit.h | 35 +++---- .../gtest/mediapipeline_unittest.cpp | 1 + .../gtest/videoconduit_unittests.cpp | 3 +- 6 files changed, 87 insertions(+), 111 deletions(-) diff --git a/dom/media/webrtc/jsapi/TransceiverImpl.cpp b/dom/media/webrtc/jsapi/TransceiverImpl.cpp index 0b58f52fecb9..75cd04a66531 100644 --- a/dom/media/webrtc/jsapi/TransceiverImpl.cpp +++ b/dom/media/webrtc/jsapi/TransceiverImpl.cpp @@ -143,7 +143,46 @@ void TransceiverImpl::InitAudio() { } void TransceiverImpl::InitVideo() { - mConduit = VideoSessionConduit::Create(mCallWrapper, mStsThread, mPCHandle); + VideoSessionConduit::Options options; + options.mVideoLatencyTestEnable = + Preferences::GetBool("media.video.test_latency", false); + options.mMinBitrate = std::max( + 0, + Preferences::GetInt("media.peerconnection.video.min_bitrate", 0) * 1000); + options.mStartBitrate = std::max( + 0, Preferences::GetInt("media.peerconnection.video.start_bitrate", 0) * + 1000); + options.mPrefMaxBitrate = std::max( + 0, + Preferences::GetInt("media.peerconnection.video.max_bitrate", 0) * 1000); + if (options.mMinBitrate != 0 && + options.mMinBitrate < kViEMinCodecBitrate_bps) { + options.mMinBitrate = kViEMinCodecBitrate_bps; + } + if (options.mStartBitrate < options.mMinBitrate) { + options.mStartBitrate = options.mMinBitrate; + } + if (options.mPrefMaxBitrate && + options.mStartBitrate > options.mPrefMaxBitrate) { + options.mStartBitrate = options.mPrefMaxBitrate; + } + // XXX We'd love if this was a live param for testing adaptation/etc + // in automation + options.mMinBitrateEstimate = + std::max(0, Preferences::GetInt( + "media.peerconnection.video.min_bitrate_estimate", 0) * + 1000); + options.mSpatialLayers = std::max( + 1, Preferences::GetInt("media.peerconnection.video.svc.spatial", 0)); + options.mTemporalLayers = std::max( + 1, Preferences::GetInt("media.peerconnection.video.svc.temporal", 0)); + options.mDenoising = + Preferences::GetBool("media.peerconnection.video.denoising", false); + options.mLockScaling = + Preferences::GetBool("media.peerconnection.video.lock_scaling", false); + + mConduit = VideoSessionConduit::Create(mCallWrapper, mStsThread, + std::move(options), mPCHandle); if (!mConduit) { MOZ_MTLOG(ML_ERROR, mPCHandle << "[" << mMid << "]: " << __FUNCTION__ diff --git a/dom/media/webrtc/libwebrtcglue/MediaConduitInterface.h b/dom/media/webrtc/libwebrtcglue/MediaConduitInterface.h index ca6edb08fb61..482f1e135ca7 100644 --- a/dom/media/webrtc/libwebrtcglue/MediaConduitInterface.h +++ b/dom/media/webrtc/libwebrtcglue/MediaConduitInterface.h @@ -6,18 +6,14 @@ #define MEDIA_CONDUIT_ABSTRACTION_ #include -#include #include #include #include "CodecConfig.h" #include "ImageContainer.h" -#include "jsapi/PeerConnectionCtx.h" #include "jsapi/RTCStatsReport.h" #include "MediaConduitErrors.h" #include "mozilla/media/MediaUtils.h" -#include "mozilla/RefCounted.h" -#include "TaskQueueWrapper.h" #include "VideoTypes.h" #include "WebrtcVideoCodecFactory.h" #include "RtcpEventObserver.h" @@ -25,7 +21,6 @@ #include "mozilla/dom/RTCRtpSourcesBinding.h" // libwebrtc includes -#include "api/video/builtin_video_bitrate_allocator_factory.h" #include "api/video/video_frame_buffer.h" #include "call/call.h" @@ -319,6 +314,19 @@ class VideoDecoder : public CodecPluginID { */ class VideoSessionConduit : public MediaSessionConduit { public: + struct Options { + bool mVideoLatencyTestEnable = false; + // All in bps. + int mMinBitrate = 0; + int mStartBitrate = 0; + int mPrefMaxBitrate = 0; + int mMinBitrateEstimate = 0; + bool mDenoising = false; + bool mLockScaling = false; + uint8_t mSpatialLayers = 1; + uint8_t mTemporalLayers = 1; + }; + /** * Factory function to create and initialize a Video Conduit Session * @param webrtc::Call instance shared by paired audio and video @@ -328,7 +336,8 @@ class VideoSessionConduit : public MediaSessionConduit { */ static RefPtr Create( RefPtr aCall, - nsCOMPtr aStsThread, std::string aPCHandle); + nsCOMPtr aStsThread, Options aOptions, + std::string aPCHandle); enum FrameRequestType { FrameRequestNone, diff --git a/dom/media/webrtc/libwebrtcglue/VideoConduit.cpp b/dom/media/webrtc/libwebrtcglue/VideoConduit.cpp index 1bec046bfd29..6b21e36687b6 100644 --- a/dom/media/webrtc/libwebrtcglue/VideoConduit.cpp +++ b/dom/media/webrtc/libwebrtcglue/VideoConduit.cpp @@ -289,7 +289,7 @@ bool operator!=(const rtc::VideoSinkWants& aThis, */ RefPtr VideoSessionConduit::Create( RefPtr aCall, nsCOMPtr aStsThread, - std::string aPCHandle) { + Options aOptions, std::string aPCHandle) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(aCall, "missing required parameter: aCall"); CSFLogVerbose(LOGTAG, "%s", __FUNCTION__); @@ -298,8 +298,8 @@ RefPtr VideoSessionConduit::Create( return nullptr; } - auto obj = - MakeRefPtr(aCall, aStsThread, std::move(aPCHandle)); + auto obj = MakeRefPtr( + aCall, aStsThread, std::move(aOptions), std::move(aPCHandle)); if (obj->Init() != kMediaConduitNoError) { CSFLogError(LOGTAG, "%s VideoConduit Init Failed ", __FUNCTION__); return nullptr; @@ -310,7 +310,7 @@ RefPtr VideoSessionConduit::Create( WebrtcVideoConduit::WebrtcVideoConduit( RefPtr aCall, nsCOMPtr aStsThread, - std::string aPCHandle) + Options aOptions, std::string aPCHandle) : mTransportMonitor("WebrtcVideoConduit"), mStsThread(aStsThread), mMutex("WebrtcVideoConduit::mMutex"), @@ -322,6 +322,15 @@ WebrtcVideoConduit::WebrtcVideoConduit( mEngineTransmitting(false), mEngineReceiving(false), mSendingFramerate(DEFAULT_VIDEO_MAX_FRAMERATE), + mVideoLatencyTestEnable(aOptions.mVideoLatencyTestEnable), + mMinBitrate(aOptions.mMinBitrate), + mStartBitrate(aOptions.mStartBitrate), + mPrefMaxBitrate(aOptions.mPrefMaxBitrate), + mMinBitrateEstimate(aOptions.mMinBitrateEstimate), + mDenoising(aOptions.mDenoising), + mLockScaling(aOptions.mLockScaling), + mSpatialLayers(aOptions.mSpatialLayers), + mTemporalLayers(aOptions.mTemporalLayers), mActiveCodecMode(webrtc::VideoCodecMode::kRealtimeVideo), mCodecMode(webrtc::VideoCodecMode::kRealtimeVideo), mCall(aCall), @@ -869,93 +878,17 @@ webrtc::Call::Stats WebrtcVideoConduit::GetCallStats() const { return mCall->Call()->GetStats(); } -MediaConduitErrorCode WebrtcVideoConduit::InitMain() { +MediaConduitErrorCode WebrtcVideoConduit::Init() { MOZ_ASSERT(NS_IsMainThread()); - nsresult rv; - nsCOMPtr prefs = - do_GetService("@mozilla.org/preferences-service;1", &rv); - if (!NS_WARN_IF(NS_FAILED(rv))) { - nsCOMPtr branch = do_QueryInterface(prefs); + CSFLogDebug(LOGTAG, "%s this=%p", __FUNCTION__, this); - if (branch) { - int32_t temp; - Unused << NS_WARN_IF(NS_FAILED(branch->GetBoolPref( - "media.video.test_latency", &mVideoLatencyTestEnable))); - if (!NS_WARN_IF(NS_FAILED(branch->GetIntPref( - "media.peerconnection.video.min_bitrate", &temp)))) { - if (temp >= 0) { - mMinBitrate = KBPS(temp); - } - } - if (!NS_WARN_IF(NS_FAILED(branch->GetIntPref( - "media.peerconnection.video.start_bitrate", &temp)))) { - if (temp >= 0) { - mStartBitrate = KBPS(temp); - } - } - if (!NS_WARN_IF(NS_FAILED(branch->GetIntPref( - "media.peerconnection.video.max_bitrate", &temp)))) { - if (temp >= 0) { - mPrefMaxBitrate = KBPS(temp); - } - } - if (mMinBitrate != 0 && mMinBitrate < kViEMinCodecBitrate_bps) { - mMinBitrate = kViEMinCodecBitrate_bps; - } - if (mStartBitrate < mMinBitrate) { - mStartBitrate = mMinBitrate; - } - if (mPrefMaxBitrate && mStartBitrate > mPrefMaxBitrate) { - mStartBitrate = mPrefMaxBitrate; - } - // XXX We'd love if this was a live param for testing adaptation/etc - // in automation - if (!NS_WARN_IF(NS_FAILED(branch->GetIntPref( - "media.peerconnection.video.min_bitrate_estimate", &temp)))) { - if (temp >= 0) { - mMinBitrateEstimate = temp; // bps! - } - } - if (!NS_WARN_IF(NS_FAILED(branch->GetIntPref( - "media.peerconnection.video.svc.spatial", &temp)))) { - if (temp >= 0) { - mSpatialLayers = temp; - } - } - if (!NS_WARN_IF(NS_FAILED(branch->GetIntPref( - "media.peerconnection.video.svc.temporal", &temp)))) { - if (temp >= 0) { - mTemporalLayers = temp; - } - } - Unused << NS_WARN_IF(NS_FAILED(branch->GetBoolPref( - "media.peerconnection.video.denoising", &mDenoising))); - Unused << NS_WARN_IF(NS_FAILED(branch->GetBoolPref( - "media.peerconnection.video.lock_scaling", &mLockScaling))); - } - } #ifdef MOZ_WIDGET_ANDROID if (mozilla::camera::VideoEngine::SetAndroidObjects() != 0) { CSFLogError(LOGTAG, "%s: could not set Android objects", __FUNCTION__); return kMediaConduitSessionNotInited; } #endif // MOZ_WIDGET_ANDROID - return kMediaConduitNoError; -} - -/** - * Performs initialization of the MANDATORY components of the Video Engine - */ -MediaConduitErrorCode WebrtcVideoConduit::Init() { - MOZ_ASSERT(NS_IsMainThread()); - - CSFLogDebug(LOGTAG, "%s this=%p", __FUNCTION__, this); - MediaConduitErrorCode result; - result = InitMain(); - if (result != kMediaConduitNoError) { - return result; - } CSFLogDebug(LOGTAG, "%s Initialization Done", __FUNCTION__); return kMediaConduitNoError; diff --git a/dom/media/webrtc/libwebrtcglue/VideoConduit.h b/dom/media/webrtc/libwebrtcglue/VideoConduit.h index 01c55b257e8e..df64f7b31d03 100644 --- a/dom/media/webrtc/libwebrtcglue/VideoConduit.h +++ b/dom/media/webrtc/libwebrtcglue/VideoConduit.h @@ -222,11 +222,10 @@ class WebrtcVideoConduit WebrtcVideoConduit(RefPtr aCall, nsCOMPtr aStsThread, - std::string aPCHandle); + Options aOptions, std::string aPCHandle); virtual ~WebrtcVideoConduit(); - MediaConduitErrorCode InitMain(); - virtual MediaConduitErrorCode Init(); + MediaConduitErrorCode Init(); std::vector GetLocalSSRCs() override; bool SetLocalSSRCs(const std::vector& ssrcs, @@ -375,34 +374,28 @@ class WebrtcVideoConduit // Accessed under mMutex. unsigned int mSendingFramerate; - // Written on main thread at creation, - // then written or read on any thread under mTransportMonitor. - bool mVideoLatencyTestEnable = false; - // Accessed from any thread under mTransportMonitor. uint64_t mVideoLatencyAvg = 0; + const bool mVideoLatencyTestEnable; + // All in bps. - // All written on main thread and guarded by mMutex, except for reads on main. - int mMinBitrate = 0; - int mStartBitrate = 0; - int mPrefMaxBitrate = 0; + const int mMinBitrate; + const int mStartBitrate; + const int mPrefMaxBitrate; + const int mMinBitrateEstimate; + + // Max bitrate in bps as provided by negotiation. Call thread only. int mNegotiatedMaxBitrate = 0; - int mMinBitrateEstimate = 0; // Set to true to force denoising on. - // Written at creation, then read anywhere. - bool mDenoising = false; + const bool mDenoising; // Set to true to ignore sink wants (scaling due to bwe and cpu usage). - // Written at creation, then read anywhere. - bool mLockScaling = false; + const bool mLockScaling; - // Written at creation, then read anywhere. - uint8_t mSpatialLayers = 1; - - // Written at creation, then read anywhere. - uint8_t mTemporalLayers = 1; + const uint8_t mSpatialLayers; + const uint8_t mTemporalLayers; static const unsigned int sAlphaNum = 7; static const unsigned int sAlphaDen = 8; diff --git a/media/webrtc/signaling/gtest/mediapipeline_unittest.cpp b/media/webrtc/signaling/gtest/mediapipeline_unittest.cpp index f1ae7a44ba34..58c42b498f9e 100644 --- a/media/webrtc/signaling/gtest/mediapipeline_unittest.cpp +++ b/media/webrtc/signaling/gtest/mediapipeline_unittest.cpp @@ -25,6 +25,7 @@ #include "MediaTrackGraph.h" #include "MediaTrackListener.h" #include "MediaStreamTrack.h" +#include "TaskQueueWrapper.h" #include "transportflow.h" #include "transportlayerloopback.h" #include "transportlayerdtls.h" diff --git a/media/webrtc/signaling/gtest/videoconduit_unittests.cpp b/media/webrtc/signaling/gtest/videoconduit_unittests.cpp index 20b9ef947fda..959ae115561b 100644 --- a/media/webrtc/signaling/gtest/videoconduit_unittests.cpp +++ b/media/webrtc/signaling/gtest/videoconduit_unittests.cpp @@ -46,7 +46,8 @@ class VideoConduitTest : public Test { VideoConduitTest() : mCallWrapper(MockCallWrapper::Create()), mVideoConduit(MakeRefPtr( - mCallWrapper, GetCurrentSerialEventTarget(), "")) { + mCallWrapper, GetCurrentSerialEventTarget(), + VideoSessionConduit::Options(), "")) { NSS_NoDB_Init(nullptr); mVideoConduit->SetLocalSSRCs({42}, {43});