diff --git a/dom/media/webrtc/libwebrtcglue/WebrtcVideoCodecFactory.cpp b/dom/media/webrtc/libwebrtcglue/WebrtcVideoCodecFactory.cpp index 3d9edf41f6f6..a1e3d1e7d276 100644 --- a/dom/media/webrtc/libwebrtcglue/WebrtcVideoCodecFactory.cpp +++ b/dom/media/webrtc/libwebrtcglue/WebrtcVideoCodecFactory.cpp @@ -13,6 +13,7 @@ // libwebrtc includes #include "api/rtp_headers.h" #include "api/video_codecs/video_codec.h" +#include "api/video_codecs/video_encoder_software_fallback_wrapper.h" #include "media/engine/encoder_simulcast_proxy.h" #include "modules/video_coding/codecs/vp8/include/vp8.h" #include "modules/video_coding/codecs/vp9/include/vp9.h" @@ -92,13 +93,15 @@ std::unique_ptr WebrtcVideoEncoderFactory::InternalFactory::CreateVideoEncoder( const webrtc::SdpVideoFormat& aFormat) { MOZ_ASSERT(Supports(aFormat)); - std::unique_ptr encoder; - encoder.reset(MediaDataCodec::CreateEncoder(aFormat)); - if (encoder) { - return encoder; + std::unique_ptr platformEncoder; + platformEncoder.reset(MediaDataCodec::CreateEncoder(aFormat)); + const bool fallback = StaticPrefs::media_webrtc_software_encoder_fallback(); + if (!fallback && platformEncoder) { + return platformEncoder; } + std::unique_ptr encoder; switch (webrtc::PayloadStringToCodecType(aFormat.name)) { case webrtc::VideoCodecType::kVideoCodecH264: { // get an external encoder @@ -121,6 +124,13 @@ WebrtcVideoEncoderFactory::InternalFactory::CreateVideoEncoder( default: break; } + if (fallback && encoder && platformEncoder) { + return webrtc::CreateVideoEncoderSoftwareFallbackWrapper( + std::move(encoder), std::move(platformEncoder), false); + } + if (platformEncoder) { + return platformEncoder; + } return encoder; } diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index ac6002a17e74..447fc50074e5 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -3821,7 +3821,7 @@ mirror: always # Points in the native bounds geometry are required to be quantized -# sufficiently to prevent fingerprinting. The WebXR spec suggests +# sufficiently to prevent fingerprinting. The WebXR spec suggests # quantizing to the nearest 5 centimeters. - name: dom.vr.webxr.quantization type: AtomicFloat @@ -8935,6 +8935,15 @@ #endif mirror: always +- name: media.webrtc.software_encoder.fallback + type: RelaxedAtomicBool +#if defined(MOZ_WIDGET_ANDROID) || defined(NIGHTLY_BUILD) + value: true +#else + value: false +#endif + mirror: always + - name: media.block-autoplay-until-in-foreground type: bool #if !defined(MOZ_WIDGET_ANDROID)