[MediaStream] Add "has capture device" bit to media state flags
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 25 Oct 2016 20:07:25 +0000 (20:07 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 25 Oct 2016 20:07:25 +0000 (20:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=163952

Source/WebCore:

Reviewed by Jer Noble.

No new tests, updated fast/mediastream/MediaStream-page-muted.html, media/muted-video-is-playing-audio.html,
and webaudio/web-audio-is-playing.html.

* Modules/mediastream/MediaStream.cpp:
(WebCore::MediaStream::mediaState): Set HasMediaCaptureDevice, only set HasActiveMediaCaptureDevice when
  actually producing data.

* page/MediaProducer.h: Add HasMediaCaptureDevice bit.

* testing/Internals.cpp:
(WebCore::Internals::pageMediaState): Return a string representing MediaStateFlags.
(WebCore::Internals::isPagePlayingAudio): Deleted.
* testing/Internals.h:
* testing/Internals.idl:

Source/WebKit2:

Reviewed by Sam Weinig.

* UIProcess/API/C/WKPage.cpp:
(WKPageGetMediaState): Support MediaProducer::HasMediaCaptureDevice.
* UIProcess/API/C/WKPagePrivate.h: Define kWKMediaHasCaptureDevice.

LayoutTests:

Reviewed by Jer Noble.

* fast/mediastream/MediaStream-page-muted-expected.txt:
* fast/mediastream/MediaStream-page-muted.html:
* media/muted-video-is-playing-audio-expected.txt:
* media/muted-video-is-playing-audio.html:
* webaudio/web-audio-is-playing.html:
* webaudio/web-audio-is-playing-expected.txt:

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

16 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/mediastream/MediaStream-page-muted-expected.txt
LayoutTests/fast/mediastream/MediaStream-page-muted.html
LayoutTests/media/muted-video-is-playing-audio-expected.txt
LayoutTests/media/muted-video-is-playing-audio.html
LayoutTests/webaudio/web-audio-is-playing-expected.txt
LayoutTests/webaudio/web-audio-is-playing.html
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/MediaStream.cpp
Source/WebCore/page/MediaProducer.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/C/WKPage.cpp
Source/WebKit2/UIProcess/API/C/WKPagePrivate.h

index 6072e19..66abdf6 100644 (file)
@@ -1,3 +1,17 @@
+2016-10-25  Eric Carlson  <eric.carlson@apple.com>
+
+        [MediaStream] Add "has capture device" bit to media state flags
+        https://bugs.webkit.org/show_bug.cgi?id=163952
+
+        Reviewed by Jer Noble.
+
+        * fast/mediastream/MediaStream-page-muted-expected.txt:
+        * fast/mediastream/MediaStream-page-muted.html:
+        * media/muted-video-is-playing-audio-expected.txt:
+        * media/muted-video-is-playing-audio.html:
+        * webaudio/web-audio-is-playing.html:
+        * webaudio/web-audio-is-playing-expected.txt:
+
 2016-10-25  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r207827 and r207828.
index 0d93fc2..7fd0a89 100644 (file)
@@ -7,22 +7,27 @@ 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
 
 *** Muting capture devices
 EVENT: mute
-PASS event.target.muted is true
-
+PASS muteChangedEvent.target.muted is true
+PASS window.internals.pageMediaState().includes('HasMediaCaptureDevice') is true
 EVENT: mute
-PASS event.target.muted is true
+PASS muteChangedEvent.target.muted is true
+PASS window.internals.pageMediaState().includes('HasMediaCaptureDevice') is true
 
+PASS window.internals.pageMediaState().includes('HasActiveMediaCaptureDevice') became false
 
 *** Unmuting capture devices
 EVENT: unmute
-PASS event.target.muted is false
-
+PASS muteChangedEvent.target.muted is false
+PASS window.internals.pageMediaState().includes('HasMediaCaptureDevice') is true
 EVENT: unmute
-PASS event.target.muted is false
+PASS muteChangedEvent.target.muted is false
+PASS window.internals.pageMediaState().includes('HasMediaCaptureDevice') is true
 
+PASS window.internals.pageMediaState().includes('HasActiveMediaCaptureDevice') became true
 PASS successfullyParsed is true
 
 TEST COMPLETE
index d6a5f44..e16775e 100644 (file)
@@ -5,29 +5,40 @@
         <script>
             let mediaStream;
             let eventCount = 0;
+            let muteChangedEvent;
 
-            function muteChanged(ev)
+            function nextStep()
             {
-                event = ev;
-                debug(`EVENT: ${ev.type}`);
-                shouldBe('event.target.muted', (ev.type == "mute").toString());
-                debug("");
+                if (muteChangedEvent.type == "unmute") {
+                    finishJSTest();
+                    return;
+                }
 
-                if (++eventCount == 2) {
-                    eventCount = 0;
+                debug("<br>*** Unmuting capture devices");
+                eventCount = 0;
+                internals.setPageMuted("");
+            }
 
-                    if (ev.type == "unmute") {
-                        finishJSTest();
-                        return;
-                    }
+            function muteChanged(ev)
+            {
+                muteChangedEvent = ev;
+                debug(`EVENT: ${muteChangedEvent.type}`);
+                shouldBe('muteChangedEvent.target.muted', (muteChangedEvent.type == "mute").toString());
+                shouldBe("window.internals.pageMediaState().includes('HasMediaCaptureDevice')", "true");
 
-                    if (window.internals) {
-                        debug("<br>*** Unmuting capture devices");
-                        internals.setPageMuted("");
-                    }
+                if (++eventCount == 2) {
+                    debug("");
+                    let shouldBeActive = muteChangedEvent.type == "mute" ? "false" : "true";
+                    shouldBecomeEqual("window.internals.pageMediaState().includes('HasActiveMediaCaptureDevice')", shouldBeActive, nextStep);
                 }
             }
             
+            function muteCaptureDevices()
+            {
+                debug("<br>*** Muting capture devices");
+                internals.setPageMuted("capturedevices");
+            }
+            
             function testWhenEnabled()
             {
                 navigator.mediaDevices
                             tracks[i].onunmute = muteChanged;
                         }
 
-                        if (window.internals) {
-                            debug("<br>*** Muting capture devices");
-                            internals.setPageMuted("capturedevices");
-                        }
+                        shouldBecomeEqual("window.internals.pageMediaState().includes('HasActiveMediaCaptureDevice')", "true", muteCaptureDevices);
                     })
                     .catch((err) => {
                         testFailed(`mediaDevices.getUserMedia() failed with ${err.name}`);
index 90790ac..9c79777 100644 (file)
@@ -3,9 +3,9 @@ Testing that muting a video element should result in page's audio playing state
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS window.internals.isPagePlayingAudio() became true
-PASS window.internals.isPagePlayingAudio() became false
-PASS window.internals.isPagePlayingAudio() became true
+PASS window.internals.pageMediaState().includes('IsPlayingAudio') became true
+PASS window.internals.pageMediaState().includes('IsPlayingAudio') became false
+PASS window.internals.pageMediaState().includes('IsPlayingAudio') became true
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 3c08179..becdeac 100644 (file)
             function testUnmutingVideo()
             {
                 run("video.muted = false");
-                shouldBecomeEqual("window.internals.isPagePlayingAudio()", "true", finishJSTest);
+                shouldBecomeEqual("window.internals.pageMediaState().includes('IsPlayingAudio')", "true", finishJSTest);
             }
 
             function testMutingVideo()
             {
                 run("video.muted = true");
-                shouldBecomeEqual("window.internals.isPagePlayingAudio()", "false", testUnmutingVideo);
+                shouldBecomeEqual("window.internals.pageMediaState().includes('IsPlayingAudio')", "false", testUnmutingVideo);
             }
 
-            shouldBecomeEqual("window.internals.isPagePlayingAudio()", "true", testMutingVideo);
+            shouldBecomeEqual("window.internals.pageMediaState().includes('IsPlayingAudio')", "true", testMutingVideo);
         </script>
         <script src="../resources/js-test-post.js"></script>
     </body>
index f813fbb..15a485f 100644 (file)
@@ -3,9 +3,9 @@ Testing Page::isPlayingAudio() with web audio
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS window.internals.isPagePlayingAudio() is false
-PASS window.internals.isPagePlayingAudio() is false
-PASS window.internals.isPagePlayingAudio() became true
+PASS window.internals.pageMediaState().includes('IsPlayingAudio') is false
+PASS window.internals.pageMediaState().includes('IsPlayingAudio') is false
+PASS window.internals.pageMediaState().includes('IsPlayingAudio') became true
 PASS successfullyParsed is true
 
 TEST COMPLETE
index fcf04f5..5364587 100644 (file)
         jsTestIsAsync = true;
 
         if (window.internals)
-            shouldBeFalse("window.internals.isPagePlayingAudio()");
+            shouldBeFalse("window.internals.pageMediaState().includes('IsPlayingAudio')");
 
         var context = new webkitAudioContext();
         var frequency = 300;
         var oscillator = context.createOscillator();
 
         if (window.internals)
-            shouldBeFalse("window.internals.isPagePlayingAudio()");
+            shouldBeFalse("window.internals.pageMediaState().includes('IsPlayingAudio')");
 
         oscillator.frequency.value = frequency;
         oscillator.type = 0;
         oscillator.connect(context.destination);
         oscillator.start(0);
 
-        shouldBecomeEqual("window.internals.isPagePlayingAudio()", "true", finishJSTest);
+        shouldBecomeEqual("window.internals.pageMediaState().includes('IsPlayingAudio')", "true", finishJSTest);
     </script>
     <script src="../resources/js-test-post.js"></script>
 </body>
index f1635fc..bd3089b 100644 (file)
@@ -1,3 +1,25 @@
+2016-10-25  Eric Carlson  <eric.carlson@apple.com>
+
+        [MediaStream] Add "has capture device" bit to media state flags
+        https://bugs.webkit.org/show_bug.cgi?id=163952
+
+        Reviewed by Jer Noble.
+
+        No new tests, updated fast/mediastream/MediaStream-page-muted.html, media/muted-video-is-playing-audio.html,
+        and webaudio/web-audio-is-playing.html.
+
+        * Modules/mediastream/MediaStream.cpp:
+        (WebCore::MediaStream::mediaState): Set HasMediaCaptureDevice, only set HasActiveMediaCaptureDevice when
+          actually producing data.
+
+        * page/MediaProducer.h: Add HasMediaCaptureDevice bit.
+
+        * testing/Internals.cpp:
+        (WebCore::Internals::pageMediaState): Return a string representing MediaStateFlags.
+        (WebCore::Internals::isPagePlayingAudio): Deleted.
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2016-10-25  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r207827 and r207828.
index 096110e..7508a03 100644 (file)
@@ -274,7 +274,8 @@ MediaProducer::MediaStateFlags MediaStream::mediaState() const
     if (!m_isActive)
         return state;
 
-    if (m_externallyMuted || m_private->isProducingData())
+    state |= HasMediaCaptureDevice;
+    if (m_private->isProducingData())
         state |= HasActiveMediaCaptureDevice;
 
     if (m_private->hasAudio() || m_private->hasVideo())
index 5ae1737..9480949 100644 (file)
@@ -44,6 +44,7 @@ public:
         HasPlaybackTargetAvailabilityListener = 1 << 9,
         HasAudioOrVideo = 1 << 10,
         HasActiveMediaCaptureDevice = 1 << 11,
+        HasMediaCaptureDevice = 1 << 12,
     };
     typedef unsigned MediaStateFlags;
 
index 48a175e..100da5e 100644 (file)
@@ -2966,13 +2966,49 @@ void Internals::setPageMuted(const String& states)
         page->setMuted(state);
 }
 
-bool Internals::isPagePlayingAudio()
+String Internals::pageMediaState()
 {
     Document* document = contextDocument();
     if (!document || !document->page())
-        return false;
+        return emptyString();
+
+    WebCore::MediaProducer::MediaStateFlags state = document->page()->mediaState();
+    StringBuilder string;
+    if (state & MediaProducer::IsPlayingAudio)
+        string.append("IsPlayingAudio,");
+    if (state & MediaProducer::IsPlayingVideo)
+        string.append("IsPlayingVideo,");
+    if (state & MediaProducer::IsPlayingToExternalDevice)
+        string.append("IsPlayingToExternalDevice,");
+    if (state & MediaProducer::RequiresPlaybackTargetMonitoring)
+        string.append("RequiresPlaybackTargetMonitoring,");
+    if (state & MediaProducer::ExternalDeviceAutoPlayCandidate)
+        string.append("ExternalDeviceAutoPlayCandidate,");
+    if (state & MediaProducer::DidPlayToEnd)
+        string.append("DidPlayToEnd,");
+    if (state & MediaProducer::IsSourceElementPlaying)
+        string.append("IsSourceElementPlaying,");
+
+    if (state & MediaProducer::IsNextTrackControlEnabled)
+        string.append("IsNextTrackControlEnabled,");
+    if (state & MediaProducer::IsPreviousTrackControlEnabled)
+        string.append("IsPreviousTrackControlEnabled,");
+
+    if (state & MediaProducer::HasPlaybackTargetAvailabilityListener)
+        string.append("HasPlaybackTargetAvailabilityListener,");
+    if (state & MediaProducer::HasAudioOrVideo)
+        string.append("HasAudioOrVideo,");
+    if (state & MediaProducer::HasActiveMediaCaptureDevice)
+        string.append("HasActiveMediaCaptureDevice,");
+    if (state & MediaProducer::HasMediaCaptureDevice)
+        string.append("HasMediaCaptureDevice,");
+
+    if (string.isEmpty())
+        string.append("IsNotPlaying");
+    else
+        string.resize(string.length() - 1);
 
-    return !!(document->page()->mediaState() & MediaProducer::IsPlayingAudio);
+    return string.toString();
 }
 
 void Internals::setPageDefersLoading(bool defersLoading)
index 8aebc6d..2a49aaa 100644 (file)
@@ -441,7 +441,7 @@ public:
     ExceptionOr<String> pageOverlayLayerTreeAsText() const;
 
     void setPageMuted(const String&);
-    bool isPagePlayingAudio();
+    String pageMediaState();
 
     void setPageDefersLoading(bool);
 
index a83e65b..4a66c46 100644 (file)
@@ -418,7 +418,7 @@ enum UserInterfaceLayoutDirection {
     [MayThrowException] DOMString pageOverlayLayerTreeAsText();
 
     void setPageMuted(DOMString mutedState);
-    boolean isPagePlayingAudio();
+    DOMString pageMediaState();
 
     void setPageDefersLoading(boolean defersLoading);
 
index 77778c4..ef7d112 100644 (file)
@@ -1,3 +1,14 @@
+2016-10-25  Eric Carlson  <eric.carlson@apple.com>
+
+        [MediaStream] Add "has capture device" bit to media state flags
+        https://bugs.webkit.org/show_bug.cgi?id=163952
+
+        Reviewed by Sam Weinig.
+
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageGetMediaState): Support MediaProducer::HasMediaCaptureDevice.
+        * UIProcess/API/C/WKPagePrivate.h: Define kWKMediaHasCaptureDevice.
+
 2016-10-25  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r207827 and r207828.
index bb60d3d..cea6049 100644 (file)
@@ -2748,6 +2748,8 @@ WKMediaState WKPageGetMediaState(WKPageRef page)
         state |= kWKMediaIsPlayingAudio;
     if (coreState & WebCore::MediaProducer::IsPlayingVideo)
         state |= kWKMediaIsPlayingVideo;
+    if (coreState & WebCore::MediaProducer::HasMediaCaptureDevice)
+        state |= kWKMediaHasCaptureDevice;
     if (coreState & WebCore::MediaProducer::HasActiveMediaCaptureDevice)
         state |= kWKMediaHasActiveCaptureDevice;
 
index e4c2f11..dae51fa 100644 (file)
@@ -134,6 +134,7 @@ enum {
     kWKMediaIsPlayingAudio = 1 << 0,
     kWKMediaIsPlayingVideo = 1 << 1,
     kWKMediaHasActiveCaptureDevice = 1 << 2,
+    kWKMediaHasCaptureDevice = 1 << 3,
 };
 typedef uint32_t WKMediaState;