Report active video and audio capture devices separately
authorjonlee@apple.com <jonlee@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Nov 2016 02:55:22 +0000 (02:55 +0000)
committerjonlee@apple.com <jonlee@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Nov 2016 02:55:22 +0000 (02:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=164769

Reviewed by Eric Carlson.

Source/WebCore:

For UI purposes, separate the notion of any active capture device to
an active audio and video capture device.

* page/MediaProducer.h: Replace HasActiveMediaCaptureDevice with
HasActiveAudioCaptureDevice and HasActiveVideoCaptureDevice.

* Modules/mediastream/MediaStream.cpp:
(WebCore::MediaStream::mediaState): Update the logic for mediaState().
Since it is possible to arbitrarily add tracks from various sources,
check specifically for a local AV source (meaning a capture device) that
is producing data.
* platform/mediastream/MediaStreamPrivate.cpp:
(WebCore::MediaStreamPrivate::hasLocalVideoSource): Iterate over the tracks
and look for video sources that are not remote.
(WebCore::MediaStreamPrivate::hasLocalAudioSource): Ditto for audio.
* platform/mediastream/MediaStreamPrivate.h:
* testing/Internals.cpp:
(WebCore::Internals::pageMediaState): Update internals reporting.

Source/WebKit2:

Replace kWKMediaHasActiveCaptureDevice with kWKMediaHasActiveAudioCaptureDevice and
kWKMediaHasActiveVideoCaptureDevice

* UIProcess/API/C/WKPage.cpp:
(WKPageGetMediaState):
* UIProcess/API/C/WKPagePrivate.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::isPlayingMediaDidChange): Update the mask to include the two
bits.

LayoutTests:

* fast/mediastream/MediaStream-page-muted-expected.txt: Update test.
* fast/mediastream/MediaStream-page-muted.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208778 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/mediastream/MediaStream-page-muted-expected.txt
LayoutTests/fast/mediastream/MediaStream-page-muted.html
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/MediaStream.cpp
Source/WebCore/page/MediaProducer.h
Source/WebCore/platform/mediastream/MediaStreamPrivate.cpp
Source/WebCore/platform/mediastream/MediaStreamPrivate.h
Source/WebCore/testing/Internals.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/C/WKPage.cpp
Source/WebKit2/UIProcess/API/C/WKPagePrivate.h
Source/WebKit2/UIProcess/WebPageProxy.cpp

index 0ee0f18..c87f61e 100644 (file)
@@ -1,3 +1,13 @@
+2016-11-15  Jon Lee  <jonlee@apple.com>
+
+        Report active video and audio capture devices separately
+        https://bugs.webkit.org/show_bug.cgi?id=164769
+
+        Reviewed by Eric Carlson.
+
+        * fast/mediastream/MediaStream-page-muted-expected.txt: Update test.
+        * fast/mediastream/MediaStream-page-muted.html:
+
 2016-11-15  Ryan Haddad  <ryanhaddad@apple.com>
 
         Marking js/regress-141098.html as flaky on ios-simulator.
index 05b3d16..234a31e 100644 (file)
@@ -7,7 +7,7 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
 *** Mock capture devices should be enabled by default
 PASS mediaStream is an instance of Object
 PASS mediaStream.getTracks().length is 2
-PASS window.internals.pageMediaState().includes('HasActiveMediaCaptureDevice') became true
+PASS window.internals.pageMediaState().includes('HasActiveAudioCaptureDevice') && window.internals.pageMediaState().includes('HasActiveVideoCaptureDevice') became true
 
 *** Muting capture devices
 EVENT: mute
@@ -15,7 +15,7 @@ PASS muteChangedEvent.target.muted is true
 EVENT: mute
 PASS muteChangedEvent.target.muted is true
 
-PASS window.internals.pageMediaState().includes('HasActiveMediaCaptureDevice') became false
+PASS window.internals.pageMediaState().includes('HasActiveAudioCaptureDevice') && window.internals.pageMediaState().includes('HasActiveVideoCaptureDevice') became false
 
 *** Unmuting capture devices
 EVENT: unmute
@@ -23,7 +23,7 @@ PASS muteChangedEvent.target.muted is false
 EVENT: unmute
 PASS muteChangedEvent.target.muted is false
 
-PASS window.internals.pageMediaState().includes('HasActiveMediaCaptureDevice') became true
+PASS window.internals.pageMediaState().includes('HasActiveAudioCaptureDevice') && window.internals.pageMediaState().includes('HasActiveVideoCaptureDevice') became true
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 3fa487d..f8d276c 100644 (file)
@@ -28,7 +28,7 @@
                 if (++eventCount == 2) {
                     debug("");
                     let shouldBeActive = muteChangedEvent.type == "mute" ? "false" : "true";
-                    shouldBecomeEqual("window.internals.pageMediaState().includes('HasActiveMediaCaptureDevice')", shouldBeActive, nextStep);
+                    shouldBecomeEqual("window.internals.pageMediaState().includes('HasActiveAudioCaptureDevice') && window.internals.pageMediaState().includes('HasActiveVideoCaptureDevice')", shouldBeActive, nextStep);
                 }
             }
             
@@ -53,7 +53,7 @@
                             tracks[i].onunmute = muteChanged;
                         }
 
-                        shouldBecomeEqual("window.internals.pageMediaState().includes('HasActiveMediaCaptureDevice')", "true", muteCaptureDevices);
+                        shouldBecomeEqual("window.internals.pageMediaState().includes('HasActiveAudioCaptureDevice') && window.internals.pageMediaState().includes('HasActiveVideoCaptureDevice')", "true", muteCaptureDevices);
                     })
                     .catch((err) => {
                         testFailed(`mediaDevices.getUserMedia() failed with ${err.name}`);
index ac16e30..ff44a9f 100644 (file)
@@ -1,3 +1,29 @@
+2016-11-15  Jon Lee  <jonlee@apple.com>
+
+        Report active video and audio capture devices separately
+        https://bugs.webkit.org/show_bug.cgi?id=164769
+
+        Reviewed by Eric Carlson.
+
+        For UI purposes, separate the notion of any active capture device to
+        an active audio and video capture device.
+
+        * page/MediaProducer.h: Replace HasActiveMediaCaptureDevice with
+        HasActiveAudioCaptureDevice and HasActiveVideoCaptureDevice.
+
+        * Modules/mediastream/MediaStream.cpp:
+        (WebCore::MediaStream::mediaState): Update the logic for mediaState().
+        Since it is possible to arbitrarily add tracks from various sources,
+        check specifically for a local AV source (meaning a capture device) that
+        is producing data.
+        * platform/mediastream/MediaStreamPrivate.cpp:
+        (WebCore::MediaStreamPrivate::hasLocalVideoSource): Iterate over the tracks
+        and look for video sources that are not remote.
+        (WebCore::MediaStreamPrivate::hasLocalAudioSource): Ditto for audio.
+        * platform/mediastream/MediaStreamPrivate.h:
+        * testing/Internals.cpp:
+        (WebCore::Internals::pageMediaState): Update internals reporting.
+
 2016-11-15  Chris Dumez  <cdumez@apple.com>
 
         Avoid copying vector of attributes as much as possible in the HTML parser
index e28e7b0..1d52a48 100644 (file)
@@ -312,11 +312,17 @@ MediaProducer::MediaStateFlags MediaStream::mediaState() const
     if (!m_isActive)
         return state;
 
-    if (m_private->isProducingData())
-        state |= HasActiveMediaCaptureDevice;
+    if (m_private->hasAudio()) {
+        state |= HasAudioOrVideo;
+        if (m_private->hasLocalAudioSource() && m_private->isProducingData())
+            state |= HasActiveAudioCaptureDevice;
+    }
 
-    if (m_private->hasAudio() || m_private->hasVideo())
+    if (m_private->hasVideo()) {
         state |= HasAudioOrVideo;
+        if (m_private->hasLocalVideoSource() && m_private->isProducingData())
+            state |= HasActiveVideoCaptureDevice;
+    }
 
     return state;
 }
index 15e9928..2f97296 100644 (file)
@@ -42,7 +42,8 @@ public:
         IsPreviousTrackControlEnabled = 1 << 8,
         HasPlaybackTargetAvailabilityListener = 1 << 9,
         HasAudioOrVideo = 1 << 10,
-        HasActiveMediaCaptureDevice = 1 << 11,
+        HasActiveAudioCaptureDevice = 1 << 11,
+        HasActiveVideoCaptureDevice = 1 << 12,
     };
     typedef unsigned MediaStateFlags;
 
index 8071412..e435760 100644 (file)
@@ -199,6 +199,24 @@ bool MediaStreamPrivate::hasAudio() const
     return false;
 }
 
+bool MediaStreamPrivate::hasLocalVideoSource() const
+{
+    for (auto& track : m_trackSet.values()) {
+        if (track->type() == RealtimeMediaSource::Type::Video && !track->remote())
+            return true;
+    }
+    return false;
+}
+
+bool MediaStreamPrivate::hasLocalAudioSource() const
+{
+    for (auto& track : m_trackSet.values()) {
+        if (track->type() == RealtimeMediaSource::Type::Audio && !track->remote())
+            return true;
+    }
+    return false;
+}
+
 bool MediaStreamPrivate::muted() const
 {
     for (auto& track : m_trackSet.values()) {
index cde3d5d..b1e30ed 100644 (file)
@@ -101,6 +101,9 @@ public:
     bool hasAudio() const;
     bool muted() const;
 
+    bool hasLocalVideoSource() const;
+    bool hasLocalAudioSource() const;
+
     FloatSize intrinsicSize() const;
 
     WeakPtr<MediaStreamPrivate> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(); }
index 04ee454..ec56f2e 100644 (file)
@@ -3010,8 +3010,10 @@ String Internals::pageMediaState()
         string.append("HasPlaybackTargetAvailabilityListener,");
     if (state & MediaProducer::HasAudioOrVideo)
         string.append("HasAudioOrVideo,");
-    if (state & MediaProducer::HasActiveMediaCaptureDevice)
-        string.append("HasActiveMediaCaptureDevice,");
+    if (state & MediaProducer::HasActiveAudioCaptureDevice)
+        string.append("HasActiveAudioCaptureDevice,");
+    if (state & MediaProducer::HasActiveVideoCaptureDevice)
+        string.append("HasActiveVideoCaptureDevice,");
 
     if (string.isEmpty())
         string.append("IsNotPlaying");
index a43d2ac..735a2c1 100644 (file)
@@ -1,3 +1,20 @@
+2016-11-15  Jon Lee  <jonlee@apple.com>
+
+        Report active video and audio capture devices separately
+        https://bugs.webkit.org/show_bug.cgi?id=164769
+
+        Reviewed by Eric Carlson.
+
+        Replace kWKMediaHasActiveCaptureDevice with kWKMediaHasActiveAudioCaptureDevice and
+        kWKMediaHasActiveVideoCaptureDevice
+
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageGetMediaState):
+        * UIProcess/API/C/WKPagePrivate.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::isPlayingMediaDidChange): Update the mask to include the two
+        bits.
+
 2016-11-14  Simon Fraser  <simon.fraser@apple.com>
 
         [iOS WK2] Implement support for visual viewports
index bb60d3d..5d1b09e 100644 (file)
@@ -2748,8 +2748,10 @@ WKMediaState WKPageGetMediaState(WKPageRef page)
         state |= kWKMediaIsPlayingAudio;
     if (coreState & WebCore::MediaProducer::IsPlayingVideo)
         state |= kWKMediaIsPlayingVideo;
-    if (coreState & WebCore::MediaProducer::HasActiveMediaCaptureDevice)
-        state |= kWKMediaHasActiveCaptureDevice;
+    if (coreState & WebCore::MediaProducer::HasActiveAudioCaptureDevice)
+        state |= kWKMediaHasActiveAudioCaptureDevice;
+    if (coreState & WebCore::MediaProducer::HasActiveVideoCaptureDevice)
+        state |= kWKMediaHasActiveVideoCaptureDevice;
 
     return state;
 }
index e4c2f11..e20ff26 100644 (file)
@@ -133,7 +133,8 @@ enum {
     kWKMediaIsNotPlaying = 0,
     kWKMediaIsPlayingAudio = 1 << 0,
     kWKMediaIsPlayingVideo = 1 << 1,
-    kWKMediaHasActiveCaptureDevice = 1 << 2,
+    kWKMediaHasActiveAudioCaptureDevice = 1 << 2,
+    kWKMediaHasActiveVideoCaptureDevice = 1 << 3,
 };
 typedef uint32_t WKMediaState;
 
index e012c68..be2f221 100644 (file)
@@ -6388,7 +6388,7 @@ void WebPageProxy::isPlayingMediaDidChange(MediaProducer::MediaStateFlags state,
 
     activityStateDidChange(ActivityState::IsAudible);
 
-    playingMediaMask |= MediaProducer::HasActiveMediaCaptureDevice;
+    playingMediaMask |= MediaProducer::HasActiveAudioCaptureDevice | MediaProducer::HasActiveVideoCaptureDevice;
     if ((oldState & playingMediaMask) != (m_mediaState & playingMediaMask))
         m_uiClient->isPlayingAudioDidChange(*this);
 #if PLATFORM(MAC)