Title: [217999] trunk
Revision
217999
Author
jer.no...@apple.com
Date
2017-06-09 10:57:06 -0700 (Fri, 09 Jun 2017)

Log Message

[iOS] Video occasionally mixes with other system audio instead of interrupting
https://bugs.webkit.org/show_bug.cgi?id=173127

Reviewed by Eric Carlson.

Source/WebCore:

Tests: platform/mac/audio-session-category-video-track-change.html

When an HTMLMediaElement's tracks change their enabled state, make sure to update
the PlatformMediaElement, for canProduceAudio() may have changed.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::mediaPlayerCharacteristicChanged):
* platform/audio/cocoa/MediaSessionManagerCocoa.cpp:
(PlatformMediaSessionManager::updateSessionState):

The rest of the changes in this revision are to allow the above to be testable.

* page/Settings.cpp:
* page/Settings.h:
* platform/audio/AudioSession.h:
* platform/audio/mac/AudioSessionMac.cpp:
(WebCore::AudioSession::category):
(WebCore::AudioSession::setCategory):
* testing/InternalSettings.cpp:
(WebCore::InternalSettings::Backup::Backup):
(WebCore::InternalSettings::Backup::restoreTo):
(WebCore::InternalSettings::setShouldManageAudioSessionCategory):
* testing/InternalSettings.h:
* testing/InternalSettings.idl:
* testing/Internals.cpp:
(WebCore::Internals::audioSessionCategory):
* testing/Internals.h:
* testing/Internals.idl:

LayoutTests:

* platform/mac/media/audio-session-category-video-track-change-expected.txt: Added.
* platform/mac/media/audio-session-category-video-track-change.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (217998 => 217999)


--- trunk/LayoutTests/ChangeLog	2017-06-09 17:54:16 UTC (rev 217998)
+++ trunk/LayoutTests/ChangeLog	2017-06-09 17:57:06 UTC (rev 217999)
@@ -1,3 +1,13 @@
+2017-06-09  Jer Noble  <jer.no...@apple.com>
+
+        [iOS] Video occasionally mixes with other system audio instead of interrupting
+        https://bugs.webkit.org/show_bug.cgi?id=173127
+
+        Reviewed by Eric Carlson.
+
+        * platform/mac/media/audio-session-category-video-track-change-expected.txt: Added.
+        * platform/mac/media/audio-session-category-video-track-change.html: Added.
+
 2017-06-09  Chris Dumez  <cdu...@apple.com>
 
         CSS transitions added while page is not visible do not start when the page becomes visible

Added: trunk/LayoutTests/platform/mac/media/audio-session-category-video-track-change-expected.txt (0 => 217999)


--- trunk/LayoutTests/platform/mac/media/audio-session-category-video-track-change-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/media/audio-session-category-video-track-change-expected.txt	2017-06-09 17:57:06 UTC (rev 217999)
@@ -0,0 +1,19 @@
+
+RUN(internals.settings.setShouldManageAudioSessionCategory(true))
+RUN(video.src = "" "../../../media/content/test"))
+EVENT(canplay)
+EXPECTED (internals.audioSessionCategory() == 'None') OK
+RUN(video.audioTracks[0].enabled = false)
+EVENT(change)
+EXPECTED (internals.audioSessionCategory() == 'None') OK
+RUN(video.muted = false)
+EVENT(volumechange)
+EXPECTED (internals.audioSessionCategory() == 'None') OK
+RUN(video.play())
+EVENT(playing)
+EXPECTED (internals.audioSessionCategory() == 'None') OK
+RUN(video.audioTracks[0].enabled = true)
+EVENT(change)
+EXPECTED (internals.audioSessionCategory() == 'MediaPlayback') OK
+END OF TEST
+

Added: trunk/LayoutTests/platform/mac/media/audio-session-category-video-track-change.html (0 => 217999)


--- trunk/LayoutTests/platform/mac/media/audio-session-category-video-track-change.html	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/media/audio-session-category-video-track-change.html	2017-06-09 17:57:06 UTC (rev 217999)
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <title>audio-session-category-track-change</title>
+    <script src=""
+    <script src=""
+    <script>
+    function go() {
+        findMediaElement();
+        run('internals.settings.setShouldManageAudioSessionCategory(true)');
+        run('video.src = "" "../../../media/content/test")');
+        waitForEvent('canplay', canplay);
+    }
+
+    function canplay() {
+        testExpected('internals.audioSessionCategory()', 'None');
+        run('video.audioTracks[0].enabled = false');
+        waitForEventOnceOn(video.audioTracks, 'change', trackDisabled);
+    }
+
+    function trackDisabled() {
+        testExpected('internals.audioSessionCategory()', 'None');
+        run('video.muted = false');
+        waitForEvent('volumechange', volumechange);
+    }
+
+    function volumechange() {
+        testExpected('internals.audioSessionCategory()', 'None');
+        run('video.play()');
+        waitForEvent('playing', playing);
+    }
+
+    function playing() {
+        testExpected('internals.audioSessionCategory()', 'None');
+        run('video.audioTracks[0].enabled = true');
+        waitForEventOnceOn(video.audioTracks, 'change', trackEnabled);
+    }
+
+    function trackEnabled() {
+        testExpected('internals.audioSessionCategory()', 'MediaPlayback');
+        endTest();
+    }
+    </script>
+</head>
+<body _onload_="go()">
+    <video controls muted></video>
+</body>
+</html>
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (217998 => 217999)


--- trunk/Source/WebCore/ChangeLog	2017-06-09 17:54:16 UTC (rev 217998)
+++ trunk/Source/WebCore/ChangeLog	2017-06-09 17:57:06 UTC (rev 217999)
@@ -1,3 +1,39 @@
+2017-06-09  Jer Noble  <jer.no...@apple.com>
+
+        [iOS] Video occasionally mixes with other system audio instead of interrupting
+        https://bugs.webkit.org/show_bug.cgi?id=173127
+
+        Reviewed by Eric Carlson.
+
+        Tests: platform/mac/audio-session-category-video-track-change.html
+
+        When an HTMLMediaElement's tracks change their enabled state, make sure to update
+        the PlatformMediaElement, for canProduceAudio() may have changed. 
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::mediaPlayerCharacteristicChanged):
+        * platform/audio/cocoa/MediaSessionManagerCocoa.cpp:
+        (PlatformMediaSessionManager::updateSessionState):
+
+        The rest of the changes in this revision are to allow the above to be testable.
+
+        * page/Settings.cpp:
+        * page/Settings.h:
+        * platform/audio/AudioSession.h:
+        * platform/audio/mac/AudioSessionMac.cpp:
+        (WebCore::AudioSession::category):
+        (WebCore::AudioSession::setCategory):
+        * testing/InternalSettings.cpp:
+        (WebCore::InternalSettings::Backup::Backup):
+        (WebCore::InternalSettings::Backup::restoreTo):
+        (WebCore::InternalSettings::setShouldManageAudioSessionCategory):
+        * testing/InternalSettings.h:
+        * testing/InternalSettings.idl:
+        * testing/Internals.cpp:
+        (WebCore::Internals::audioSessionCategory):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2017-06-09  Chris Dumez  <cdu...@apple.com>
 
         CSS transitions added while page is not visible do not start when the page becomes visible

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (217998 => 217999)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2017-06-09 17:54:16 UTC (rev 217998)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2017-06-09 17:57:06 UTC (rev 217999)
@@ -4770,6 +4770,8 @@
     m_hasEverHadAudio |= hasAudio();
     m_hasEverHadVideo |= hasVideo();
 
+    m_mediaSession->canProduceAudioChanged();
+
     endProcessingMediaPlayerCallback();
 }
 

Modified: trunk/Source/WebCore/page/Settings.cpp (217998 => 217999)


--- trunk/Source/WebCore/page/Settings.cpp	2017-06-09 17:54:16 UTC (rev 217998)
+++ trunk/Source/WebCore/page/Settings.cpp	2017-06-09 17:57:06 UTC (rev 217999)
@@ -113,8 +113,8 @@
 bool Settings::gNetworkDataUsageTrackingEnabled = false;
 bool Settings::gAVKitEnabled = false;
 bool Settings::gShouldOptOutOfNetworkStateObservation = false;
+#endif
 bool Settings::gManageAudioSession = false;
-#endif
 
 // NOTEs
 //  1) EditingMacBehavior comprises Tiger, Leopard, SnowLeopard and iOS builds, as well as QtWebKit when built on Mac;

Modified: trunk/Source/WebCore/page/Settings.h (217998 => 217999)


--- trunk/Source/WebCore/page/Settings.h	2017-06-09 17:54:16 UTC (rev 217998)
+++ trunk/Source/WebCore/page/Settings.h	2017-06-09 17:57:06 UTC (rev 217999)
@@ -291,7 +291,9 @@
 
     static void setShouldOptOutOfNetworkStateObservation(bool flag) { gShouldOptOutOfNetworkStateObservation = flag; }
     static bool shouldOptOutOfNetworkStateObservation() { return gShouldOptOutOfNetworkStateObservation; }
+#endif
 
+#if USE(AUDIO_SESSION)
     static void setShouldManageAudioSessionCategory(bool flag) { gManageAudioSession = flag; }
     static bool shouldManageAudioSessionCategory() { return gManageAudioSession; }
 #endif
@@ -409,8 +411,8 @@
     static bool gNetworkDataUsageTrackingEnabled;
     WEBCORE_EXPORT static bool gAVKitEnabled;
     WEBCORE_EXPORT static bool gShouldOptOutOfNetworkStateObservation;
+#endif
     WEBCORE_EXPORT static bool gManageAudioSession;
-#endif
 
 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
     String m_mediaKeysStorageDirectory;

Modified: trunk/Source/WebCore/platform/audio/AudioSession.h (217998 => 217999)


--- trunk/Source/WebCore/platform/audio/AudioSession.h	2017-06-09 17:54:16 UTC (rev 217998)
+++ trunk/Source/WebCore/platform/audio/AudioSession.h	2017-06-09 17:57:06 UTC (rev 217999)
@@ -54,7 +54,7 @@
         AudioProcessing,
     };
     WEBCORE_EXPORT void setCategory(CategoryType);
-    CategoryType category() const;
+    WEBCORE_EXPORT CategoryType category() const;
 
     void setCategoryOverride(CategoryType);
     CategoryType categoryOverride() const;

Modified: trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.cpp (217998 => 217999)


--- trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.cpp	2017-06-09 17:54:16 UTC (rev 217998)
+++ trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.cpp	2017-06-09 17:57:06 UTC (rev 217999)
@@ -57,16 +57,15 @@
         AudioSession::sharedSession().setPreferredBufferSize(bufferSize);
     }
 
-#if PLATFORM(IOS)
     if (!Settings::shouldManageAudioSessionCategory())
         return;
 
-    bool hasAudioMediaType = false;
+    bool hasWebAudioType = false;
     bool hasAudibleAudioOrVideoMediaType = false;
-    bool hasAudioCapture = anyOfSessions([this, &hasAudioMediaType, &hasAudibleAudioOrVideoMediaType] (PlatformMediaSession& session, size_t) mutable {
+    bool hasAudioCapture = anyOfSessions([this, &hasWebAudioType, &hasAudibleAudioOrVideoMediaType] (PlatformMediaSession& session, size_t) mutable {
         auto type = session.mediaType();
-        if (type == PlatformMediaSession::VideoAudio || type == PlatformMediaSession::Audio || type == PlatformMediaSession::WebAudio)
-            hasAudioMediaType = true;
+        if (type == PlatformMediaSession::WebAudio)
+            hasWebAudioType = true;
         if ((type == PlatformMediaSession::VideoAudio || type == PlatformMediaSession::Audio) && session.canProduceAudio())
             hasAudibleAudioOrVideoMediaType = true;
         return (type == PlatformMediaSession::MediaStreamCapturingAudio);
@@ -76,11 +75,10 @@
         AudioSession::sharedSession().setCategory(AudioSession::PlayAndRecord);
     else if (hasAudibleAudioOrVideoMediaType)
         AudioSession::sharedSession().setCategory(AudioSession::MediaPlayback);
-    else if (hasAudioMediaType)
+    else if (hasWebAudioType)
         AudioSession::sharedSession().setCategory(AudioSession::AmbientSound);
     else
         AudioSession::sharedSession().setCategory(AudioSession::None);
-#endif
 }
 
 #endif // USE(AUDIO_SESSION)

Modified: trunk/Source/WebCore/platform/audio/mac/AudioSessionMac.cpp (217998 => 217999)


--- trunk/Source/WebCore/platform/audio/mac/AudioSessionMac.cpp	2017-06-09 17:54:16 UTC (rev 217998)
+++ trunk/Source/WebCore/platform/audio/mac/AudioSessionMac.cpp	2017-06-09 17:57:06 UTC (rev 217999)
@@ -56,6 +56,7 @@
     AudioSessionPrivate(bool mutedState)
         : lastMutedState(mutedState) { }
     bool lastMutedState;
+    AudioSession::CategoryType category { AudioSession::None };
 };
 
 AudioSession::AudioSession()
@@ -69,13 +70,12 @@
 
 AudioSession::CategoryType AudioSession::category() const
 {
-    notImplemented();
-    return None;
+    return m_private->category;
 }
 
-void AudioSession::setCategory(CategoryType)
+void AudioSession::setCategory(CategoryType category)
 {
-    notImplemented();
+    m_private->category = category;
 }
 
 AudioSession::CategoryType AudioSession::categoryOverride() const

Modified: trunk/Source/WebCore/testing/InternalSettings.cpp (217998 => 217999)


--- trunk/Source/WebCore/testing/InternalSettings.cpp	2017-06-09 17:54:16 UTC (rev 217998)
+++ trunk/Source/WebCore/testing/InternalSettings.cpp	2017-06-09 17:57:06 UTC (rev 217999)
@@ -111,6 +111,9 @@
     , m_webGPUEnabled(RuntimeEnabledFeatures::sharedFeatures().webGPUEnabled())
 #endif
     , m_shouldMockBoldSystemFontForAccessibility(RenderTheme::singleton().shouldMockBoldSystemFontForAccessibility())
+#if USE(AUDIO_SESSION)
+    , m_shouldManageAudioSessionCategory(Settings::shouldManageAudioSessionCategory())
+#endif
 {
 }
 
@@ -201,6 +204,10 @@
 #if ENABLE(WEBGPU)
     RuntimeEnabledFeatures::sharedFeatures().setWebGPUEnabled(m_webGPUEnabled);
 #endif
+
+#if USE(AUDIO_SESSION)
+    Settings::setShouldManageAudioSessionCategory(m_shouldManageAudioSessionCategory);
+#endif
 }
 
 class InternalSettingsWrapper : public Supplement<Page> {
@@ -804,6 +811,16 @@
     return { };
 }
 
+ExceptionOr<void> InternalSettings::setShouldManageAudioSessionCategory(bool should)
+{
+#if USE(AUDIO_SESSION)
+    Settings::setShouldManageAudioSessionCategory(should);
+    return { };
+#else
+    return Exception { INVALID_ACCESS_ERR };
+#endif
+}
+
 static InternalSettings::ForcedAccessibilityValue settingsToInternalSettingsValue(Settings::ForcedAccessibilityValue value)
 {
     switch (value) {

Modified: trunk/Source/WebCore/testing/InternalSettings.h (217998 => 217999)


--- trunk/Source/WebCore/testing/InternalSettings.h	2017-06-09 17:54:16 UTC (rev 217998)
+++ trunk/Source/WebCore/testing/InternalSettings.h	2017-06-09 17:57:06 UTC (rev 217999)
@@ -96,6 +96,7 @@
     ExceptionOr<String> systemLayoutDirection();
     ExceptionOr<void> setSystemLayoutDirection(const String&);
     ExceptionOr<void> setShouldMockBoldSystemFontForAccessibility(bool);
+    ExceptionOr<void> setShouldManageAudioSessionCategory(bool);
     
     static void setAllowsAnySSLCertificate(bool);
 
@@ -194,6 +195,9 @@
         bool m_webGPUEnabled;
         
         bool m_shouldMockBoldSystemFontForAccessibility;
+#if USE(AUDIO_SESSION)
+        bool m_shouldManageAudioSessionCategory;
+#endif
     };
 
     Page* m_page;

Modified: trunk/Source/WebCore/testing/InternalSettings.idl (217998 => 217999)


--- trunk/Source/WebCore/testing/InternalSettings.idl	2017-06-09 17:54:16 UTC (rev 217998)
+++ trunk/Source/WebCore/testing/InternalSettings.idl	2017-06-09 17:57:06 UTC (rev 217999)
@@ -101,5 +101,7 @@
     attribute ForcedAccessibilityValue forcedColorsAreInvertedAccessibilityValue;
     attribute ForcedAccessibilityValue forcedDisplayIsMonochromeAccessibilityValue;
     attribute ForcedAccessibilityValue forcedPrefersReducedMotionAccessibilityValue;
+
+    [MayThrowException] void setShouldManageAudioSessionCategory(boolean should);
 };
 

Modified: trunk/Source/WebCore/testing/Internals.cpp (217998 => 217999)


--- trunk/Source/WebCore/testing/Internals.cpp	2017-06-09 17:54:16 UTC (rev 217998)
+++ trunk/Source/WebCore/testing/Internals.cpp	2017-06-09 17:57:06 UTC (rev 217999)
@@ -30,6 +30,7 @@
 #include "AXObjectCache.h"
 #include "ActiveDOMCallbackMicrotask.h"
 #include "ApplicationCacheStorage.h"
+#include "AudioSession.h"
 #include "Autofill.h"
 #include "BackForwardController.h"
 #include "BitmapImage.h"
@@ -4100,4 +4101,27 @@
 
 #endif
 
+String Internals::audioSessionCategory() const
+{
+#if USE(AUDIO_SESSION)
+    switch (AudioSession::sharedSession().category()) {
+    case AudioSession::AmbientSound:
+        return ASCIILiteral("AmbientSound");
+    case AudioSession::SoloAmbientSound:
+        return ASCIILiteral("SoloAmbientSound");
+    case AudioSession::MediaPlayback:
+        return ASCIILiteral("MediaPlayback");
+    case AudioSession::RecordAudio:
+        return ASCIILiteral("RecordAudio");
+    case AudioSession::PlayAndRecord:
+        return ASCIILiteral("PlayAndRecord");
+    case AudioSession::AudioProcessing:
+        return ASCIILiteral("AudioProcessing");
+    case AudioSession::None:
+        return ASCIILiteral("None");
+    }
+#endif
+    return emptyString();
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/testing/Internals.h (217998 => 217999)


--- trunk/Source/WebCore/testing/Internals.h	2017-06-09 17:54:16 UTC (rev 217998)
+++ trunk/Source/WebCore/testing/Internals.h	2017-06-09 17:57:06 UTC (rev 217999)
@@ -589,6 +589,8 @@
     void removeMediaStreamTrack(MediaStream&, MediaStreamTrack&);
 #endif
 
+    String audioSessionCategory() const;
+
 private:
     explicit Internals(Document&);
     Document* contextDocument() const;

Modified: trunk/Source/WebCore/testing/Internals.idl (217998 => 217999)


--- trunk/Source/WebCore/testing/Internals.idl	2017-06-09 17:54:16 UTC (rev 217998)
+++ trunk/Source/WebCore/testing/Internals.idl	2017-06-09 17:57:06 UTC (rev 217999)
@@ -545,4 +545,6 @@
     [Conditional=MEDIA_STREAM] void delayMediaStreamTrackSamples(MediaStreamTrack track, float delay);
     [Conditional=MEDIA_STREAM] void setMediaStreamTrackMuted(MediaStreamTrack track, boolean muted);
     [Conditional=MEDIA_STREAM] void removeMediaStreamTrack(MediaStream stream, MediaStreamTrack track);
+
+    DOMString audioSessionCategory();
 };
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to