Title: [223157] branches/safari-604-branch
Revision
223157
Author
jmarc...@apple.com
Date
2017-10-10 16:46:05 -0700 (Tue, 10 Oct 2017)

Log Message

Cherry-pick r222478. rdar://problem/34771020

Modified Paths

Added Paths

Diff

Modified: branches/safari-604-branch/LayoutTests/ChangeLog (223156 => 223157)


--- branches/safari-604-branch/LayoutTests/ChangeLog	2017-10-10 23:40:39 UTC (rev 223156)
+++ branches/safari-604-branch/LayoutTests/ChangeLog	2017-10-10 23:46:05 UTC (rev 223157)
@@ -1,3 +1,18 @@
+2017-10-10  Jason Marcell  <jmarc...@apple.com>
+
+        Cherry-pick r222478. rdar://problem/34771020
+
+    2017-09-25  Youenn Fablet  <you...@apple.com>
+
+            WebRTC video does not resume receiving when switching back to Safari 11 on iOS
+            https://bugs.webkit.org/show_bug.cgi?id=175472
+            <rdar://problem/33860863>
+
+            Reviewed by Darin Adler.
+
+            * webrtc/video-interruption-expected.txt: Added.
+            * webrtc/video-interruption.html: Added.
+
 2017-10-09  Jason Marcell  <jmarc...@apple.com>
 
         Cherry-pick r222779. rdar://problem/34820881

Added: branches/safari-604-branch/LayoutTests/webrtc/video-interruption-expected.txt (0 => 223157)


--- branches/safari-604-branch/LayoutTests/webrtc/video-interruption-expected.txt	                        (rev 0)
+++ branches/safari-604-branch/LayoutTests/webrtc/video-interruption-expected.txt	2017-10-10 23:46:05 UTC (rev 223157)
@@ -0,0 +1,4 @@
+ 
+
+PASS Basic video exchange with media session interruption 
+

Added: branches/safari-604-branch/LayoutTests/webrtc/video-interruption.html (0 => 223157)


--- branches/safari-604-branch/LayoutTests/webrtc/video-interruption.html	                        (rev 0)
+++ branches/safari-604-branch/LayoutTests/webrtc/video-interruption.html	2017-10-10 23:46:05 UTC (rev 223157)
@@ -0,0 +1,85 @@
+<!doctype html>
+<html>
+    <head>
+        <meta charset="utf-8">
+        <title>Testing basic video exchange from offerer to receiver</title>
+        <script src=""
+        <script src=""
+    </head>
+    <body>
+        <video id="video1" autoplay=""></video>
+        <video id="video2" autoplay=""></video>
+        <canvas id="canvas" width="640" height="480"></canvas>
+        <script src =""
+        <script>
+video = document.getElementById("video");
+canvas = document.getElementById("canvas");
+
+function testImage(video)
+{
+    canvas.width = video.videoWidth;
+    canvas.height = video.videoHeight;
+    canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
+
+    imageData = canvas.getContext('2d').getImageData(10, 325, 250, 1);
+    data = ""
+
+    var index = 20;
+    assert_true(data[index] < 100);
+    assert_true(data[index + 1] < 100);
+    assert_true(data[index + 2] < 100);
+
+    index = 80;
+    assert_true(data[index] > 200);
+    assert_true(data[index + 1] > 200);
+    assert_true(data[index + 2] > 200);
+
+    index += 80;
+    assert_true(data[index] > 200);
+    assert_true(data[index + 1] > 200);
+    assert_true(data[index + 2] < 100);
+}
+
+promise_test((test) => {
+    if (window.testRunner)
+        testRunner.setUserMediaPermission(true);
+
+    var stream;
+    return navigator.mediaDevices.getUserMedia({video: {advanced: [{width:{min:1280}}, {height:{min:720} } ]}}).then((stream) => {
+        return new Promise((resolve, reject) => {
+            createConnections((firstConnection) => {
+                var track = stream.getVideoTracks()[0];
+                firstConnection.addTrack(stream.getVideoTracks()[0], stream);
+            }, (secondConnection) => {
+                secondConnection._ontrack_ = (trackEvent) => {
+                    assert_true(trackEvent.track instanceof MediaStreamTrack);
+                    assert_true(trackEvent.receiver instanceof RTCRtpReceiver);
+                    assert_true(Array.isArray(trackEvent.streams), "Array.isArray() should return true");
+                    assert_true(Object.isFrozen(trackEvent.streams), "Object.isFrozen() should return true");
+                    assert_equals(trackEvent.track.id, stream.getVideoTracks()[0].id);
+                    assert_equals(trackEvent.track, trackEvent.streams[0].getVideoTracks()[0]);
+                    resolve(trackEvent.streams[0]);
+                };
+            });
+            setTimeout(() => reject("Test timed out"), 5000);
+        });
+    }).then((s) => {
+        stream = s;
+        video1.srcObject = stream;
+        return video1.play();
+    }).then(() => {
+        testImage(video1);
+    }).then(() => {
+        internals.beginMediaSessionInterruption('EnteringBackground');
+    }).then(() => {
+        internals.endMediaSessionInterruption('');
+    }).then(() => {
+        video2.srcObject = stream;
+        return video2.play();
+    }).then(() => {
+        testImage(video2);
+    });
+}, "Basic video exchange with media session interruption");
+        </script>
+    </body>
+</html>

Modified: branches/safari-604-branch/Source/ThirdParty/libwebrtc/ChangeLog (223156 => 223157)


--- branches/safari-604-branch/Source/ThirdParty/libwebrtc/ChangeLog	2017-10-10 23:40:39 UTC (rev 223156)
+++ branches/safari-604-branch/Source/ThirdParty/libwebrtc/ChangeLog	2017-10-10 23:46:05 UTC (rev 223157)
@@ -1,3 +1,26 @@
+2017-10-10  Jason Marcell  <jmarc...@apple.com>
+
+        Cherry-pick r222478. rdar://problem/34771020
+
+    2017-09-25  Youenn Fablet  <you...@apple.com>
+
+            WebRTC video does not resume receiving when switching back to Safari 11 on iOS
+            https://bugs.webkit.org/show_bug.cgi?id=175472
+            <rdar://problem/33860863>
+
+            Reviewed by Darin Adler.
+
+            Adding a method to disable any decoding/encoding task.
+            When reenabling the decoder, the decoder will request an I frame after failing the first initial decoding task.
+
+            * Source/webrtc/sdk/objc/Framework/Classes/VideoToolbox/decoder.h:
+            (webrtc::H264VideoToolboxDecoder::SetActive):
+            * Source/webrtc/sdk/objc/Framework/Classes/VideoToolbox/decoder.mm:
+            (webrtc::H264VideoToolboxDecoder::Decode):
+            * Source/webrtc/sdk/objc/Framework/Classes/VideoToolbox/encoder.h:
+            * Source/webrtc/sdk/objc/Framework/Classes/VideoToolbox/encoder.mm:
+            (webrtc::H264VideoToolboxEncoder::Encode):
+
 2017-07-03  Andy Estes  <aes...@apple.com>
 
         [Xcode] Add an experimental setting to build with ccache

Modified: branches/safari-604-branch/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/Framework/Classes/VideoToolbox/decoder.h (223156 => 223157)


--- branches/safari-604-branch/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/Framework/Classes/VideoToolbox/decoder.h	2017-10-10 23:40:39 UTC (rev 223156)
+++ branches/safari-604-branch/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/Framework/Classes/VideoToolbox/decoder.h	2017-10-10 23:46:05 UTC (rev 223157)
@@ -43,6 +43,8 @@
 
   const char* ImplementationName() const override;
 
+  void SetActive(bool is_active) { is_active_ = is_active; }
+
  private:
   int ResetDecompressionSession();
   void ConfigureDecompressionSession();
@@ -52,6 +54,7 @@
   DecodedImageCallback* callback_;
   CMVideoFormatDescriptionRef video_format_;
   VTDecompressionSessionRef decompression_session_;
+  bool is_active_ { true };
 };  // H264VideoToolboxDecoder
 
 }  // namespace webrtc

Modified: branches/safari-604-branch/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/Framework/Classes/VideoToolbox/decoder.mm (223156 => 223157)


--- branches/safari-604-branch/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/Framework/Classes/VideoToolbox/decoder.mm	2017-10-10 23:40:39 UTC (rev 223156)
+++ branches/safari-604-branch/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/Framework/Classes/VideoToolbox/decoder.mm	2017-10-10 23:46:05 UTC (rev 223157)
@@ -95,8 +95,12 @@
     int64_t render_time_ms) {
   RTC_DCHECK(input_image._buffer);
 
-#if defined(WEBRTC_IOS) && !defined(WEBRTC_WEBKIT_BUILD)
+#if defined(WEBRTC_IOS)
+#if !defined(WEBRTC_WEBKIT_BUILD)
   if (![[RTCUIApplicationStatusObserver sharedInstance] isApplicationActive]) {
+#else
+  if (!is_active_) {
+#endif
     // Ignore all decode requests when app isn't active. In this state, the
     // hardware decoder has been invalidated by the OS.
     // Reset video format so that we won't process frames until the next

Modified: branches/safari-604-branch/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/Framework/Classes/VideoToolbox/encoder.h (223156 => 223157)


--- branches/safari-604-branch/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/Framework/Classes/VideoToolbox/encoder.h	2017-10-10 23:40:39 UTC (rev 223156)
+++ branches/safari-604-branch/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/Framework/Classes/VideoToolbox/encoder.h	2017-10-10 23:46:05 UTC (rev 223157)
@@ -69,6 +69,8 @@
 
   ScalingSettings GetScalingSettings() const override;
 
+  void SetActive(bool is_active) { is_active_ = is_active; }
+
  protected:
   virtual int CreateCompressionSession(VTCompressionSessionRef&, VTCompressionOutputCallback, int32_t width, int32_t height, bool useHardwareEncoder = true);
   void DestroyCompressionSession();
@@ -94,6 +96,7 @@
 
   H264BitstreamParser h264_bitstream_parser_;
   std::vector<uint8_t> nv12_scale_buffer_;
+  bool is_active_ { true };
 };  // H264VideoToolboxEncoder
 
 }  // namespace webrtc

Modified: branches/safari-604-branch/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/Framework/Classes/VideoToolbox/encoder.mm (223156 => 223157)


--- branches/safari-604-branch/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/Framework/Classes/VideoToolbox/encoder.mm	2017-10-10 23:40:39 UTC (rev 223156)
+++ branches/safari-604-branch/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/Framework/Classes/VideoToolbox/encoder.mm	2017-10-10 23:46:05 UTC (rev 223157)
@@ -384,8 +384,13 @@
   if (!callback_ || !compression_session_) {
     return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
   }
-#if defined(WEBRTC_IOS) && !defined(WEBRTC_WEBKIT_BUILD)
-  if (![[RTCUIApplicationStatusObserver sharedInstance] isApplicationActive]) {
+
+#if defined(WEBRTC_IOS)
+#if !defined(WEBRTC_WEBKIT_BUILD)
+    if (![[RTCUIApplicationStatusObserver sharedInstance] isApplicationActive]) {
+#else
+    if (!is_active_) {
+#endif
     // Ignore all encode requests when app isn't active. In this state, the
     // hardware encoder has been invalidated by the OS.
     return WEBRTC_VIDEO_CODEC_OK;

Modified: branches/safari-604-branch/Source/WebCore/ChangeLog (223156 => 223157)


--- branches/safari-604-branch/Source/WebCore/ChangeLog	2017-10-10 23:40:39 UTC (rev 223156)
+++ branches/safari-604-branch/Source/WebCore/ChangeLog	2017-10-10 23:46:05 UTC (rev 223157)
@@ -1,3 +1,50 @@
+2017-10-10  Jason Marcell  <jmarc...@apple.com>
+
+        Cherry-pick r222478. rdar://problem/34771020
+
+    2017-09-25  Youenn Fablet  <you...@apple.com>
+
+            WebRTC video does not resume receiving when switching back to Safari 11 on iOS
+            https://bugs.webkit.org/show_bug.cgi?id=175472
+            <rdar://problem/33860863>
+
+            Reviewed by Darin Adler.
+
+            Test: webrtc/video-interruption.html and manual testing.
+
+            Using new SetActive method from libwebrtc encoder/decoder to enable/disable them based on interuptions.
+            For that purpose, LibWebRTCProvider is now storing the peer connection factory and keeping track of the encoder/decoder factories.
+            LibWebRTCProvider is then notified by WebPage when backgrounded/foregrounded.
+
+            * WebCore.xcodeproj/project.pbxproj:
+            * platform/mediastream/libwebrtc/LibWebRTCProvider.cpp:
+            (WebCore::staticFactoryAndThreads):
+            (WebCore::initializePeerConnectionFactoryAndThreads):
+            (WebCore::LibWebRTCProvider::factory):
+            (WebCore::LibWebRTCProvider::setPeerConnectionFactory):
+            (WebCore::LibWebRTCProvider::createPeerConnection):
+            (WebCore::LibWebRTCProvider::setActive):
+            (WebCore::LibWebRTCProvider::webRTCAvailable):
+            (WebCore::LibWebRTCProvider::mayResumePlayback): Deleted.
+            (WebCore::LibWebRTCProvider::suspendPlayback): Deleted.
+            * platform/mediastream/libwebrtc/LibWebRTCProvider.h:
+            * platform/mediastream/libwebrtc/VideoToolBoxDecoderFactory.cpp: Copied from Source/WebCore/platform/mediastream/libwebrtc/VideoToolBoxEncoderFactory.cpp.
+            (WebCore::VideoToolboxVideoDecoderFactory::setActive):
+            (WebCore::VideoToolboxVideoDecoderFactory::CreateVideoDecoder):
+            (WebCore::VideoToolboxVideoDecoderFactory::DestroyVideoDecoder):
+            * platform/mediastream/libwebrtc/VideoToolBoxDecoderFactory.h: Copied from Source/WebCore/platform/mediastream/libwebrtc/VideoToolBoxEncoderFactory.h.
+            * platform/mediastream/libwebrtc/VideoToolBoxEncoderFactory.cpp:
+            (WebCore::VideoToolboxVideoEncoderFactory::setActive):
+            (WebCore::VideoToolboxVideoEncoderFactory::CreateSupportedVideoEncoder):
+            (WebCore::VideoToolboxVideoEncoderFactory::DestroyVideoEncoder):
+            * platform/mediastream/libwebrtc/VideoToolBoxEncoderFactory.h:
+            * testing/Internals.cpp:
+            (WebCore::Internals::resetToConsistentState):
+            * testing/MockLibWebRTCPeerConnection.cpp:
+            (WebCore::useRealRTCPeerConnectionFactory):
+            (WebCore::useMockRTCPeerConnectionFactory):
+            * testing/MockLibWebRTCPeerConnection.h:
+
 2017-10-09  Jason Marcell  <jmarc...@apple.com>
 
         Cherry-pick r221430. rdar://problem/34770998

Modified: branches/safari-604-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj (223156 => 223157)


--- branches/safari-604-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-10-10 23:40:39 UTC (rev 223156)
+++ branches/safari-604-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-10-10 23:46:05 UTC (rev 223157)
@@ -1798,6 +1798,7 @@
 		41CF8BE71D46226700707DC9 /* FetchBodyConsumer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41CF8BE41D46222000707DC9 /* FetchBodyConsumer.cpp */; };
 		41D015CA0F4B5C71004A662F /* ContentType.h in Headers */ = {isa = PBXBuildFile; fileRef = 41D015C80F4B5C71004A662F /* ContentType.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		41D015CB0F4B5C71004A662F /* ContentType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41D015C90F4B5C71004A662F /* ContentType.cpp */; };
+		41D7E5571F73085500E26991 /* VideoToolBoxDecoderFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41D7E5551F73085000E26991 /* VideoToolBoxDecoderFactory.cpp */; };
 		41DEFCB51E56C1BD000D9E5F /* JSDOMMapLike.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41DEFCB31E56C1B9000D9E5F /* JSDOMMapLike.cpp */; };
 		41DEFCB61E56C1BD000D9E5F /* JSDOMMapLike.h in Headers */ = {isa = PBXBuildFile; fileRef = 41DEFCB41E56C1B9000D9E5F /* JSDOMMapLike.h */; };
 		41E1B1D00FF5986900576B3B /* AbstractWorker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41E1B1CA0FF5986900576B3B /* AbstractWorker.cpp */; };
@@ -9467,6 +9468,8 @@
 		41D015C80F4B5C71004A662F /* ContentType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContentType.h; sourceTree = "<group>"; };
 		41D015C90F4B5C71004A662F /* ContentType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ContentType.cpp; sourceTree = "<group>"; };
 		41D51BB21E4E2E8100131A5B /* LibWebRTCAudioFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LibWebRTCAudioFormat.h; path = libwebrtc/LibWebRTCAudioFormat.h; sourceTree = "<group>"; };
+		41D7E5541F73085000E26991 /* VideoToolBoxDecoderFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VideoToolBoxDecoderFactory.h; path = libwebrtc/VideoToolBoxDecoderFactory.h; sourceTree = "<group>"; };
+		41D7E5551F73085000E26991 /* VideoToolBoxDecoderFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = VideoToolBoxDecoderFactory.cpp; path = libwebrtc/VideoToolBoxDecoderFactory.cpp; sourceTree = "<group>"; };
 		41DEFCB21E56C1B9000D9E5F /* JSDOMBindingInternals.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode._javascript_; path = JSDOMBindingInternals.js; sourceTree = "<group>"; };
 		41DEFCB31E56C1B9000D9E5F /* JSDOMMapLike.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMMapLike.cpp; sourceTree = "<group>"; };
 		41DEFCB41E56C1B9000D9E5F /* JSDOMMapLike.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMMapLike.h; sourceTree = "<group>"; };
@@ -17662,6 +17665,8 @@
 				415747431E38699E00E914D8 /* LibWebRTCMacros.h */,
 				41A1B00D1E52656E007F3769 /* LibWebRTCProvider.cpp */,
 				415747441E38699E00E914D8 /* LibWebRTCProvider.h */,
+				41D7E5551F73085000E26991 /* VideoToolBoxDecoderFactory.cpp */,
+				41D7E5541F73085000E26991 /* VideoToolBoxDecoderFactory.h */,
 				41CAD71C1EA0905700178164 /* VideoToolBoxEncoderFactory.cpp */,
 				41CAD71D1EA0905700178164 /* VideoToolBoxEncoderFactory.h */,
 			);
@@ -33696,6 +33701,7 @@
 				52D5A18F1C54592300DE34A3 /* VideoFullscreenLayerManager.mm in Sources */,
 				CDE83DB1183C44060031EAA3 /* VideoPlaybackQuality.cpp in Sources */,
 				CD9D82791C7B8EE1006FF066 /* VideoTextureCopierCV.cpp in Sources */,
+				41D7E5571F73085500E26991 /* VideoToolBoxDecoderFactory.cpp in Sources */,
 				41CAD71E1EA090A100178164 /* VideoToolBoxEncoderFactory.cpp in Sources */,
 				CDC939A71E9BDFB100BB768D /* VideoToolboxSoftLink.cpp in Sources */,
 				BE88E0DE1715D2A200658D98 /* VideoTrack.cpp in Sources */,

Modified: branches/safari-604-branch/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.cpp (223156 => 223157)


--- branches/safari-604-branch/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.cpp	2017-10-10 23:40:39 UTC (rev 223156)
+++ branches/safari-604-branch/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.cpp	2017-10-10 23:46:05 UTC (rev 223157)
@@ -29,6 +29,7 @@
 #if USE(LIBWEBRTC)
 #include "LibWebRTCAudioModule.h"
 #include "Logging.h"
+#include "VideoToolBoxDecoderFactory.h"
 #include "VideoToolBoxEncoderFactory.h"
 #include <dlfcn.h>
 #include <webrtc/api/peerconnectionfactoryproxy.h>
@@ -35,7 +36,6 @@
 #include <webrtc/base/physicalsocketserver.h>
 #include <webrtc/p2p/client/basicportallocator.h>
 #include <webrtc/pc/peerconnectionfactory.h>
-#include <webrtc/sdk/objc/Framework/Classes/VideoToolbox/videocodecfactory.h>
 #include <wtf/Function.h>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/darwin/WeakLinking.h>
@@ -45,31 +45,62 @@
 
 #if USE(LIBWEBRTC)
 struct PeerConnectionFactoryAndThreads : public rtc::MessageHandler {
-    std::unique_ptr<LibWebRTCAudioModule> audioDeviceModule;
     std::unique_ptr<rtc::Thread> networkThread;
     std::unique_ptr<rtc::Thread> signalingThread;
-    rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory;
     bool networkThreadWithSocketServer { false };
-    Function<std::unique_ptr<cricket::WebRtcVideoEncoderFactory>()> encoderFactoryGetter;
-    Function<std::unique_ptr<cricket::WebRtcVideoDecoderFactory>()> decoderFactoryGetter;
+    std::unique_ptr<LibWebRTCAudioModule> audioDeviceModule;
 
 private:
     void OnMessage(rtc::Message*);
 };
 
+static void initializePeerConnectionFactoryAndThreads(PeerConnectionFactoryAndThreads& factoryAndThreads)
+{
+    ASSERT(!factoryAndThreads.networkThread);
+
+#if defined(NDEBUG)
+#if !LOG_DISABLED || !RELEASE_LOG_DISABLED
+    rtc::LogMessage::LogToDebug(LogWebRTC.state != WTFLogChannelOn ? rtc::LS_NONE : rtc::LS_INFO);
+#else
+    rtc::LogMessage::LogToDebug(rtc::LS_NONE);
+#endif
+#else
+    rtc::LogMessage::LogToDebug(LogWebRTC.state != WTFLogChannelOn ? rtc::LS_WARNING : rtc::LS_INFO);
+#endif
+
+    factoryAndThreads.networkThread = factoryAndThreads.networkThreadWithSocketServer ? rtc::Thread::CreateWithSocketServer() : rtc::Thread::Create();
+    factoryAndThreads.networkThread->SetName("WebKitWebRTCNetwork", nullptr);
+    bool result = factoryAndThreads.networkThread->Start();
+    ASSERT_UNUSED(result, result);
+
+    factoryAndThreads.signalingThread = rtc::Thread::Create();
+    factoryAndThreads.signalingThread->SetName("WebKitWebRTCSignaling", nullptr);
+
+    result = factoryAndThreads.signalingThread->Start();
+    ASSERT(result);
+
+    factoryAndThreads.audioDeviceModule = std::make_unique<LibWebRTCAudioModule>();
+}
+
 static inline PeerConnectionFactoryAndThreads& staticFactoryAndThreads()
 {
     static NeverDestroyed<PeerConnectionFactoryAndThreads> factoryAndThreads;
-#if PLATFORM(COCOA)
-    static std::once_flag once;
-    std::call_once(once, [] {
-        factoryAndThreads.get().encoderFactoryGetter = []() -> std::unique_ptr<cricket::WebRtcVideoEncoderFactory> { return std::make_unique<VideoToolboxVideoEncoderFactory>(); };
-        factoryAndThreads.get().decoderFactoryGetter = []() -> std::unique_ptr<cricket::WebRtcVideoDecoderFactory> { return std::make_unique<webrtc::VideoToolboxVideoDecoderFactory>(); };
-    });
-#endif
     return factoryAndThreads.get();
 }
 
+static inline PeerConnectionFactoryAndThreads& getStaticFactoryAndThreads(bool useNetworkThreadWithSocketServer)
+{
+    auto& factoryAndThreads = staticFactoryAndThreads();
+
+    ASSERT(!factoryAndThreads.networkThread || factoryAndThreads.networkThreadWithSocketServer == useNetworkThreadWithSocketServer);
+
+    if (!factoryAndThreads.networkThread) {
+        factoryAndThreads.networkThreadWithSocketServer = useNetworkThreadWithSocketServer;
+        initializePeerConnectionFactoryAndThreads(factoryAndThreads);
+    }
+    return factoryAndThreads;
+}
+
 struct ThreadMessageData : public rtc::MessageData {
     ThreadMessageData(Function<void()>&& callback)
         : callback(WTFMove(callback))
@@ -97,107 +128,51 @@
     threads.signalingThread->Post(RTC_FROM_HERE, &threads, 1, new ThreadMessageData(WTFMove(callback)));
 }
 
-static void initializePeerConnectionFactoryAndThreads()
+webrtc::PeerConnectionFactoryInterface* LibWebRTCProvider::factory()
 {
-#if defined(NDEBUG)
-#if !LOG_DISABLED || !RELEASE_LOG_DISABLED
-    rtc::LogMessage::LogToDebug(LogWebRTC.state != WTFLogChannelOn ? rtc::LS_NONE : rtc::LS_INFO);
-#else
-    rtc::LogMessage::LogToDebug(rtc::LS_NONE);
-#endif
-#else
-    rtc::LogMessage::LogToDebug(LogWebRTC.state != WTFLogChannelOn ? rtc::LS_WARNING : rtc::LS_INFO);
-#endif
-    auto& factoryAndThreads = staticFactoryAndThreads();
+    if (m_factory)
+        return m_factory.get();
 
-    ASSERT(!factoryAndThreads.factory);
-
-    factoryAndThreads.networkThread = factoryAndThreads.networkThreadWithSocketServer ? rtc::Thread::CreateWithSocketServer() : rtc::Thread::Create();
-    factoryAndThreads.networkThread->SetName("WebKitWebRTCNetwork", nullptr);
-    bool result = factoryAndThreads.networkThread->Start();
-    ASSERT_UNUSED(result, result);
-
-    factoryAndThreads.signalingThread = rtc::Thread::Create();
-    factoryAndThreads.signalingThread->SetName("WebKitWebRTCSignaling", nullptr);
-    
-    result = factoryAndThreads.signalingThread->Start();
-    ASSERT(result);
-
-    factoryAndThreads.audioDeviceModule = std::make_unique<LibWebRTCAudioModule>();
-
-    std::unique_ptr<cricket::WebRtcVideoEncoderFactory> encoderFactory = factoryAndThreads.encoderFactoryGetter ? factoryAndThreads.encoderFactoryGetter() : nullptr;
-    std::unique_ptr<cricket::WebRtcVideoDecoderFactory> decoderFactory = factoryAndThreads.decoderFactoryGetter ? factoryAndThreads.decoderFactoryGetter() : nullptr;
-
-    factoryAndThreads.factory = webrtc::CreatePeerConnectionFactory(factoryAndThreads.networkThread.get(), factoryAndThreads.networkThread.get(), factoryAndThreads.signalingThread.get(), factoryAndThreads.audioDeviceModule.get(), encoderFactory.release(), decoderFactory.release());
-
-    ASSERT(factoryAndThreads.factory);
-}
-
-webrtc::PeerConnectionFactoryInterface* LibWebRTCProvider::factory()
-{
     if (!webRTCAvailable())
         return nullptr;
-    if (!staticFactoryAndThreads().factory) {
-        staticFactoryAndThreads().networkThreadWithSocketServer = m_useNetworkThreadWithSocketServer;
-        initializePeerConnectionFactoryAndThreads();
-    }
-    return staticFactoryAndThreads().factory;
-}
 
-void LibWebRTCProvider::setDecoderFactoryGetter(Function<std::unique_ptr<cricket::WebRtcVideoDecoderFactory>()>&& getter)
-{
-    if (!staticFactoryAndThreads().factory)
-        initializePeerConnectionFactoryAndThreads();
+    auto& factoryAndThreads = getStaticFactoryAndThreads(m_useNetworkThreadWithSocketServer);
 
-    staticFactoryAndThreads().decoderFactoryGetter = WTFMove(getter);
-}
+    auto decoderFactory = std::make_unique<VideoToolboxVideoDecoderFactory>();
+    auto encoderFactory = std::make_unique<VideoToolboxVideoEncoderFactory>();
 
-void LibWebRTCProvider::setEncoderFactoryGetter(Function<std::unique_ptr<cricket::WebRtcVideoEncoderFactory>()>&& getter)
-{
-    if (!staticFactoryAndThreads().factory)
-        initializePeerConnectionFactoryAndThreads();
+    m_decoderFactory = decoderFactory.get();
+    m_encoderFactory = encoderFactory.get();
 
-    staticFactoryAndThreads().encoderFactoryGetter = WTFMove(getter);
+    m_factory = webrtc::CreatePeerConnectionFactory(factoryAndThreads.networkThread.get(), factoryAndThreads.networkThread.get(), factoryAndThreads.signalingThread.get(), factoryAndThreads.audioDeviceModule.get(), encoderFactory.release(), decoderFactory.release());
+
+    return m_factory;
 }
 
 void LibWebRTCProvider::setPeerConnectionFactory(rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>&& factory)
 {
-    if (!staticFactoryAndThreads().factory)
-        initializePeerConnectionFactoryAndThreads();
-
-    staticFactoryAndThreads().factory = webrtc::PeerConnectionFactoryProxy::Create(staticFactoryAndThreads().signalingThread.get(), WTFMove(factory));
+    m_factory = webrtc::PeerConnectionFactoryProxy::Create(getStaticFactoryAndThreads(m_useNetworkThreadWithSocketServer).signalingThread.get(), WTFMove(factory));
 }
 
-static rtc::scoped_refptr<webrtc::PeerConnectionInterface> createActualPeerConnection(webrtc::PeerConnectionObserver& observer, std::unique_ptr<cricket::BasicPortAllocator>&& portAllocator, webrtc::PeerConnectionInterface::RTCConfiguration&& configuration)
-{
-    ASSERT(staticFactoryAndThreads().factory);
-
-    return staticFactoryAndThreads().factory->CreatePeerConnection(configuration, WTFMove(portAllocator), nullptr, &observer);
-}
-
 rtc::scoped_refptr<webrtc::PeerConnectionInterface> LibWebRTCProvider::createPeerConnection(webrtc::PeerConnectionObserver& observer, webrtc::PeerConnectionInterface::RTCConfiguration&& configuration)
 {
     // Default WK1 implementation.
-    auto& factoryAndThreads = staticFactoryAndThreads();
-    if (!factoryAndThreads.factory) {
-        staticFactoryAndThreads().networkThreadWithSocketServer = true;
-        initializePeerConnectionFactoryAndThreads();
-    }
-    ASSERT(staticFactoryAndThreads().networkThreadWithSocketServer);
+    ASSERT(m_useNetworkThreadWithSocketServer);
+    auto* factory = this->factory();
+    if (!factory)
+        return nullptr;
 
-    return createActualPeerConnection(observer, nullptr, WTFMove(configuration));
+    return m_factory->CreatePeerConnection(configuration, nullptr, nullptr, &observer);
 }
 
 rtc::scoped_refptr<webrtc::PeerConnectionInterface> LibWebRTCProvider::createPeerConnection(webrtc::PeerConnectionObserver& observer, rtc::NetworkManager& networkManager, rtc::PacketSocketFactory& packetSocketFactory, webrtc::PeerConnectionInterface::RTCConfiguration&& configuration)
 {
-    ASSERT(!staticFactoryAndThreads().networkThreadWithSocketServer);
+    ASSERT(!m_useNetworkThreadWithSocketServer);
 
-    auto& factoryAndThreads = staticFactoryAndThreads();
-    if (!factoryAndThreads.factory)
-        initializePeerConnectionFactoryAndThreads();
+    auto& factoryAndThreads = getStaticFactoryAndThreads(m_useNetworkThreadWithSocketServer);
 
     std::unique_ptr<cricket::BasicPortAllocator> portAllocator;
-    staticFactoryAndThreads().signalingThread->Invoke<void>(RTC_FROM_HERE, [&]() {
+    factoryAndThreads.signalingThread->Invoke<void>(RTC_FROM_HERE, [&]() {
         auto basicPortAllocator = std::make_unique<cricket::BasicPortAllocator>(&networkManager, &packetSocketFactory);
         if (!m_enableEnumeratingAllNetworkInterfaces)
             basicPortAllocator->set_flags(basicPortAllocator->flags() | cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION);
@@ -204,11 +179,27 @@
         portAllocator = WTFMove(basicPortAllocator);
     });
 
-    return createActualPeerConnection(observer, WTFMove(portAllocator), WTFMove(configuration));
+    auto* factory = this->factory();
+    if (!factory)
+        return nullptr;
+
+    return m_factory->CreatePeerConnection(configuration, WTFMove(portAllocator), nullptr, &observer);
 }
 
 #endif // USE(LIBWEBRTC)
 
+void LibWebRTCProvider::setActive(bool value)
+{
+#if USE(LIBWEBRTC)
+    if (m_decoderFactory)
+        m_decoderFactory->setActive(value);
+    if (m_encoderFactory)
+        m_encoderFactory->setActive(value);
+#else
+    UNUSED_PARAM(value);
+#endif
+}
+
 bool LibWebRTCProvider::webRTCAvailable()
 {
 #if USE(LIBWEBRTC)

Modified: branches/safari-604-branch/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.h (223156 => 223157)


--- branches/safari-604-branch/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.h	2017-10-10 23:40:39 UTC (rev 223156)
+++ branches/safari-604-branch/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.h	2017-10-10 23:46:05 UTC (rev 223157)
@@ -45,6 +45,9 @@
 
 namespace WebCore {
 
+class VideoToolboxVideoDecoderFactory;
+class VideoToolboxVideoEncoderFactory;
+
 class WEBCORE_EXPORT LibWebRTCProvider {
 public:
     LibWebRTCProvider() = default;
@@ -51,6 +54,9 @@
     virtual ~LibWebRTCProvider() = default;
 
     static bool webRTCAvailable();
+
+    void setActive(bool);
+
 #if USE(LIBWEBRTC)
     WEBCORE_EXPORT virtual rtc::scoped_refptr<webrtc::PeerConnectionInterface> createPeerConnection(webrtc::PeerConnectionObserver&, webrtc::PeerConnectionInterface::RTCConfiguration&&);
 
@@ -59,11 +65,9 @@
     // FIXME: Make these methods not static.
     static WEBCORE_EXPORT void callOnWebRTCNetworkThread(Function<void()>&&);
     static WEBCORE_EXPORT void callOnWebRTCSignalingThread(Function<void()>&&);
-    static WEBCORE_EXPORT void setDecoderFactoryGetter(Function<std::unique_ptr<cricket::WebRtcVideoDecoderFactory>()>&&);
-    static WEBCORE_EXPORT void setEncoderFactoryGetter(Function<std::unique_ptr<cricket::WebRtcVideoEncoderFactory>()>&&);
 
     // Used for mock testing
-    static void setPeerConnectionFactory(rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>&&);
+    void setPeerConnectionFactory(rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>&&);
 
     void disableEnumeratingAllNetworkInterfaces() { m_enableEnumeratingAllNetworkInterfaces = false; }
     void enableEnumeratingAllNetworkInterfaces() { m_enableEnumeratingAllNetworkInterfaces = true; }
@@ -72,7 +76,12 @@
     WEBCORE_EXPORT rtc::scoped_refptr<webrtc::PeerConnectionInterface> createPeerConnection(webrtc::PeerConnectionObserver&, rtc::NetworkManager&, rtc::PacketSocketFactory&, webrtc::PeerConnectionInterface::RTCConfiguration&&);
 
     bool m_enableEnumeratingAllNetworkInterfaces { false };
+    // FIXME: Remove m_useNetworkThreadWithSocketServer member variable and make it a global.
     bool m_useNetworkThreadWithSocketServer { true };
+
+    rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> m_factory;
+    VideoToolboxVideoDecoderFactory* m_decoderFactory { nullptr };
+    VideoToolboxVideoEncoderFactory* m_encoderFactory { nullptr };
 #endif
 };
 

Copied: branches/safari-604-branch/Source/WebCore/platform/mediastream/libwebrtc/VideoToolBoxDecoderFactory.cpp (from rev 223120, branches/safari-604-branch/Source/WebCore/platform/mediastream/libwebrtc/VideoToolBoxEncoderFactory.cpp) (0 => 223157)


--- branches/safari-604-branch/Source/WebCore/platform/mediastream/libwebrtc/VideoToolBoxDecoderFactory.cpp	                        (rev 0)
+++ branches/safari-604-branch/Source/WebCore/platform/mediastream/libwebrtc/VideoToolBoxDecoderFactory.cpp	2017-10-10 23:46:05 UTC (rev 223157)
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "VideoToolBoxDecoderFactory.h"
+
+#if USE(LIBWEBRTC) && PLATFORM(COCOA)
+
+namespace WebCore {
+
+void VideoToolboxVideoDecoderFactory::setActive(bool isActive)
+{
+    if (m_isActive == isActive)
+        return;
+
+    m_isActive = isActive;
+    for (webrtc::H264VideoToolboxDecoder& decoder : m_decoders)
+        decoder.SetActive(isActive);
+}
+
+webrtc::VideoDecoder* VideoToolboxVideoDecoderFactory::CreateVideoDecoder(webrtc::VideoCodecType type)
+{
+    auto* decoder = webrtc::VideoToolboxVideoDecoderFactory::CreateVideoDecoder(type);
+    if (decoder)
+        m_decoders.append(static_cast<webrtc::H264VideoToolboxDecoder&>(*decoder));
+
+    return decoder;
+}
+
+void VideoToolboxVideoDecoderFactory::DestroyVideoDecoder(webrtc::VideoDecoder* decoder)
+{
+    m_decoders.removeFirstMatching([&] (const auto& item) {
+        return &item.get() == decoder;
+    });
+    webrtc::VideoToolboxVideoDecoderFactory::DestroyVideoDecoder(decoder);
+}
+
+}
+#endif

Copied: branches/safari-604-branch/Source/WebCore/platform/mediastream/libwebrtc/VideoToolBoxDecoderFactory.h (from rev 223120, branches/safari-604-branch/Source/WebCore/platform/mediastream/libwebrtc/VideoToolBoxEncoderFactory.h) (0 => 223157)


--- branches/safari-604-branch/Source/WebCore/platform/mediastream/libwebrtc/VideoToolBoxDecoderFactory.h	                        (rev 0)
+++ branches/safari-604-branch/Source/WebCore/platform/mediastream/libwebrtc/VideoToolBoxDecoderFactory.h	2017-10-10 23:46:05 UTC (rev 223157)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if USE(LIBWEBRTC) && PLATFORM(COCOA)
+
+#include "LibWebRTCMacros.h"
+#include <webrtc/sdk/objc/Framework/Classes/VideoToolbox/decoder.h>
+#include <webrtc/sdk/objc/Framework/Classes/VideoToolbox/videocodecfactory.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+class VideoToolboxVideoDecoderFactory final : public webrtc::VideoToolboxVideoDecoderFactory {
+public:
+    VideoToolboxVideoDecoderFactory() = default;
+
+    void setActive(bool isActive);
+
+private:
+    webrtc::VideoDecoder* CreateVideoDecoder(webrtc::VideoCodecType) final;
+    void DestroyVideoDecoder(webrtc::VideoDecoder*) final;
+
+    Vector<std::reference_wrapper<webrtc::H264VideoToolboxDecoder>> m_decoders;
+    bool m_isActive { true };
+};
+
+}
+
+#endif

Modified: branches/safari-604-branch/Source/WebCore/platform/mediastream/libwebrtc/VideoToolBoxEncoderFactory.cpp (223156 => 223157)


--- branches/safari-604-branch/Source/WebCore/platform/mediastream/libwebrtc/VideoToolBoxEncoderFactory.cpp	2017-10-10 23:40:39 UTC (rev 223156)
+++ branches/safari-604-branch/Source/WebCore/platform/mediastream/libwebrtc/VideoToolBoxEncoderFactory.cpp	2017-10-10 23:46:05 UTC (rev 223157)
@@ -32,15 +32,31 @@
 
 namespace WebCore {
 
+void VideoToolboxVideoEncoderFactory::setActive(bool isActive)
+{
+    if (m_isActive == isActive)
+        return;
+
+    m_isActive = isActive;
+    for (H264VideoToolboxEncoder& encoder : m_encoders)
+        encoder.SetActive(isActive);
+}
+
 webrtc::VideoEncoder* VideoToolboxVideoEncoderFactory::CreateSupportedVideoEncoder(const cricket::VideoCodec& codec)
 {
-    return new H264VideoToolboxEncoder(codec);
+    auto* encoder = new H264VideoToolboxEncoder(codec);
+    m_encoders.append(*encoder);
+
+    return encoder;
 }
 
 void VideoToolboxVideoEncoderFactory::DestroyVideoEncoder(webrtc::VideoEncoder* encoder)
 {
+    m_encoders.removeFirstMatching([&] (const auto& item) {
+        return &item.get() == encoder;
+    });
+
     delete encoder;
-    encoder = nullptr;
 }
 
 }

Modified: branches/safari-604-branch/Source/WebCore/platform/mediastream/libwebrtc/VideoToolBoxEncoderFactory.h (223156 => 223157)


--- branches/safari-604-branch/Source/WebCore/platform/mediastream/libwebrtc/VideoToolBoxEncoderFactory.h	2017-10-10 23:40:39 UTC (rev 223156)
+++ branches/safari-604-branch/Source/WebCore/platform/mediastream/libwebrtc/VideoToolBoxEncoderFactory.h	2017-10-10 23:46:05 UTC (rev 223157)
@@ -29,16 +29,24 @@
 
 #include "LibWebRTCMacros.h"
 #include <webrtc/sdk/objc/Framework/Classes/VideoToolbox/videocodecfactory.h>
+#include <wtf/Vector.h>
 
 namespace WebCore {
 
+class H264VideoToolboxEncoder;
+
 class VideoToolboxVideoEncoderFactory final : public webrtc::VideoToolboxVideoEncoderFactory {
 public:
     VideoToolboxVideoEncoderFactory() = default;
 
+    void setActive(bool isActive);
+
 private:
     webrtc::VideoEncoder* CreateSupportedVideoEncoder(const cricket::VideoCodec&) final;
     void DestroyVideoEncoder(webrtc::VideoEncoder*) final;
+
+    Vector<std::reference_wrapper<H264VideoToolboxEncoder>> m_encoders;
+    bool m_isActive { true };
 };
 
 }

Modified: branches/safari-604-branch/Source/WebCore/testing/Internals.cpp (223156 => 223157)


--- branches/safari-604-branch/Source/WebCore/testing/Internals.cpp	2017-10-10 23:40:39 UTC (rev 223156)
+++ branches/safari-604-branch/Source/WebCore/testing/Internals.cpp	2017-10-10 23:46:05 UTC (rev 223157)
@@ -465,7 +465,7 @@
 #endif
 
 #if USE(LIBWEBRTC)
-    WebCore::useRealRTCPeerConnectionFactory();
+    WebCore::useRealRTCPeerConnectionFactory(page.libWebRTCProvider());
 #endif
 
     printContextForTesting() = nullptr;

Modified: branches/safari-604-branch/Source/WebCore/testing/MockLibWebRTCPeerConnection.cpp (223156 => 223157)


--- branches/safari-604-branch/Source/WebCore/testing/MockLibWebRTCPeerConnection.cpp	2017-10-10 23:40:39 UTC (rev 223156)
+++ branches/safari-604-branch/Source/WebCore/testing/MockLibWebRTCPeerConnection.cpp	2017-10-10 23:46:05 UTC (rev 223157)
@@ -47,23 +47,25 @@
     return getRealPeerConnectionFactory().get();
 }
 
-void useRealRTCPeerConnectionFactory()
+void useRealRTCPeerConnectionFactory(LibWebRTCProvider& provider)
 {
     auto& factory = getRealPeerConnectionFactory();
     if (!factory)
         return;
-    LibWebRTCProvider::setPeerConnectionFactory(factory.get());
+    provider.setPeerConnectionFactory(factory.get());
     factory = nullptr;
 }
 
 void useMockRTCPeerConnectionFactory(LibWebRTCProvider* provider, const String& testCase)
 {
-    if (provider && !realPeerConnectionFactory()) {
+    if (!provider)
+        return;
+
+    if (!realPeerConnectionFactory()) {
         auto& factory = getRealPeerConnectionFactory();
         factory = provider->factory();
     }
-
-    LibWebRTCProvider::setPeerConnectionFactory(MockLibWebRTCPeerConnectionFactory::create(String(testCase)));
+    provider->setPeerConnectionFactory(MockLibWebRTCPeerConnectionFactory::create(String(testCase)));
 }
 
 class MockLibWebRTCPeerConnectionForIceCandidates : public MockLibWebRTCPeerConnection {

Modified: branches/safari-604-branch/Source/WebCore/testing/MockLibWebRTCPeerConnection.h (223156 => 223157)


--- branches/safari-604-branch/Source/WebCore/testing/MockLibWebRTCPeerConnection.h	2017-10-10 23:40:39 UTC (rev 223156)
+++ branches/safari-604-branch/Source/WebCore/testing/MockLibWebRTCPeerConnection.h	2017-10-10 23:46:05 UTC (rev 223157)
@@ -37,7 +37,7 @@
 class MockRtpSender;
 
 void useMockRTCPeerConnectionFactory(LibWebRTCProvider*, const String&);
-void useRealRTCPeerConnectionFactory();
+void useRealRTCPeerConnectionFactory(LibWebRTCProvider&);
 
 class MockLibWebRTCPeerConnection : public webrtc::PeerConnectionInterface {
 public:

Modified: branches/safari-604-branch/Source/WebKit/ChangeLog (223156 => 223157)


--- branches/safari-604-branch/Source/WebKit/ChangeLog	2017-10-10 23:40:39 UTC (rev 223156)
+++ branches/safari-604-branch/Source/WebKit/ChangeLog	2017-10-10 23:46:05 UTC (rev 223157)
@@ -1,3 +1,21 @@
+2017-10-10  Jason Marcell  <jmarc...@apple.com>
+
+        Cherry-pick r222478. rdar://problem/34771020
+
+    2017-09-25  Youenn Fablet  <you...@apple.com>
+
+            WebRTC video does not resume receiving when switching back to Safari 11 on iOS
+            https://bugs.webkit.org/show_bug.cgi?id=175472
+            <rdar://problem/33860863>
+
+            Reviewed by Darin Adler.
+
+            Notifying LibWebRTC of backgrounding/foregrouding.
+
+            * WebProcess/WebPage/ios/WebPageIOS.mm:
+            (WebKit::WebPage::applicationDidEnterBackground):
+            (WebKit::WebPage::applicationWillEnterForeground):
+
 2017-10-09  Jason Marcell  <jmarc...@apple.com>
 
         Cherry-pick r220412. rdar://problem/34771061

Modified: branches/safari-604-branch/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (223156 => 223157)


--- branches/safari-604-branch/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2017-10-10 23:40:39 UTC (rev 223156)
+++ branches/safari-604-branch/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2017-10-10 23:46:05 UTC (rev 223157)
@@ -86,6 +86,7 @@
 #import <WebCore/HistoryItem.h>
 #import <WebCore/HitTestResult.h>
 #import <WebCore/KeyboardEvent.h>
+#import <WebCore/LibWebRTCProvider.h>
 #import <WebCore/MainFrame.h>
 #import <WebCore/MediaSessionManagerIOS.h>
 #import <WebCore/Node.h>
@@ -3122,6 +3123,8 @@
 
     m_isSuspendedUnderLock = isSuspendedUnderLock;
     setLayerTreeStateIsFrozen(true);
+
+    m_page->libWebRTCProvider().setActive(false);
 }
 
 void WebPage::applicationDidFinishSnapshottingAfterEnteringBackground()
@@ -3136,6 +3139,8 @@
     setLayerTreeStateIsFrozen(false);
 
     [[NSNotificationCenter defaultCenter] postNotificationName:WebUIApplicationWillEnterForegroundNotification object:nil userInfo:@{@"isSuspendedUnderLock": @(isSuspendedUnderLock)}];
+
+    m_page->libWebRTCProvider().setActive(true);
 }
 
 void WebPage::applicationDidBecomeActive()

Modified: branches/safari-604-branch/WebKit.xcworkspace/xcshareddata/xcschemes/All Source.xcscheme (223156 => 223157)


--- branches/safari-604-branch/WebKit.xcworkspace/xcshareddata/xcschemes/All Source.xcscheme	2017-10-10 23:40:39 UTC (rev 223156)
+++ branches/safari-604-branch/WebKit.xcworkspace/xcshareddata/xcschemes/All Source.xcscheme	2017-10-10 23:46:05 UTC (rev 223157)
@@ -155,6 +155,7 @@
       buildConfiguration = "Debug"
       selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
       selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      language = ""
       shouldUseLaunchSchemeArgsEnv = "YES">
       <Testables>
       </Testables>
@@ -174,6 +175,7 @@
       buildConfiguration = "Debug"
       selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
       selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      language = ""
       launchStyle = "0"
       useCustomWorkingDirectory = "NO"
       ignoresPersistentStateOnLaunch = "YES"
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to