Diff
Modified: trunk/Source/WebCore/ChangeLog (167766 => 167767)
--- trunk/Source/WebCore/ChangeLog 2014-04-24 17:48:28 UTC (rev 167766)
+++ trunk/Source/WebCore/ChangeLog 2014-04-24 19:04:01 UTC (rev 167767)
@@ -1,3 +1,48 @@
+2014-04-24 Eric Carlson <[email protected]>
+
+ [iOS] Manage AudioSession category according to media type
+ https://bugs.webkit.org/show_bug.cgi?id=132096
+
+ Reviewed by Jer Noble.
+
+ * WebCore.exp.in: Export setting.
+
+ * html/HTMLMediaSession.cpp:
+ (WebCore::HTMLMediaSession::HTMLMediaSession):
+ (WebCore::initializeAudioSession): Deleted.
+
+ * page/Settings.cpp:
+ * page/Settings.h:
+ (WebCore::Settings::setShouldManageAudioSession): New.
+ (WebCore::Settings::shouldManageAudioSession): Ditto.
+
+ * platform/audio/ios/AudioDestinationIOS.cpp:
+ (WebCore::AudioDestinationIOS::AudioDestinationIOS): Use a MediaSession instead of inheriting
+ from AudioListener and calling the AudioSession directly.
+ (WebCore::AudioDestinationIOS::~AudioDestinationIOS): Ditto.
+ (WebCore::AudioDestinationIOS::start): Notify session.
+ (WebCore::AudioDestinationIOS::stop): Ditto.
+ (WebCore::AudioDestinationIOS::beganAudioInterruption): Deleted.
+ (WebCore::AudioDestinationIOS::endedAudioInterruption): Deleted.
+ * platform/audio/ios/AudioDestinationIOS.h:
+ (WebCore::AudioDestinationIOS::mediaType):
+ (WebCore::AudioDestinationIOS::canReceiveRemoteControlCommands):
+ (WebCore::AudioDestinationIOS::didReceiveRemoteControlCommand):
+ (WebCore::AudioDestinationIOS::isPlaying): Deleted.
+
+ * platform/audio/ios/AudioSessionIOS.mm:
+ (WebCore::categoryName): Debug-only logging function.
+ (WebCore::AudioSession::setCategory): Don't stick with "media" once it is set.
+
+ * platform/audio/ios/MediaSessionManagerIOS.mm:
+ (WebCore::MediaSessionManageriOS::resetRestrictions): Set up restrictions for WebAudio.
+ (WebCore::MediaSessionManageriOS::updateNowPlayingInfo): Don't set invalid start time.
+
+ * platform/audio/mac/MediaSessionManagerMac.cpp:
+ (MediaSessionManager::updateSessionState): Manage AudioSession.active when WebAudio clients
+ come and go. Manage AudioSession.category according to the number of WebAudio and
+ HTMLMediaElement clients.
+
2014-04-24 David Hyatt <[email protected]>
[New Multicolumn] Client rects don't work with column spans.
Modified: trunk/Source/WebCore/WebCore.exp.in (167766 => 167767)
--- trunk/Source/WebCore/WebCore.exp.in 2014-04-24 17:48:28 UTC (rev 167766)
+++ trunk/Source/WebCore/WebCore.exp.in 2014-04-24 19:04:01 UTC (rev 167767)
@@ -2647,6 +2647,7 @@
__ZN7WebCore8SVGNames4initEv
__ZN7WebCore8Settings13gAVKitEnabledE
__ZN7WebCore8Settings23setNetworkInterfaceNameERKN3WTF6StringE
+__ZN7WebCore8Settings19gManageAudioSessionE
__ZN7WebCore8Settings31setAudioSessionCategoryOverrideEj
__ZN7WebCore8Settings34setNetworkDataUsageTrackingEnabledEb
__ZN7WebCore8Settings38gShouldOptOutOfNetworkStateObservationE
Modified: trunk/Source/WebCore/html/HTMLMediaSession.cpp (167766 => 167767)
--- trunk/Source/WebCore/html/HTMLMediaSession.cpp 2014-04-24 17:48:28 UTC (rev 167766)
+++ trunk/Source/WebCore/html/HTMLMediaSession.cpp 2014-04-24 19:04:01 UTC (rev 167767)
@@ -69,21 +69,6 @@
}
#endif
-static void initializeAudioSession()
-{
-#if PLATFORM(IOS)
- static bool wasAudioSessionInitialized;
- if (wasAudioSessionInitialized)
- return;
-
- wasAudioSessionInitialized = true;
- if (!WebCore::applicationIsMobileSafari())
- return;
-
- AudioSession::sharedSession().setCategory(AudioSession::MediaPlayback);
-#endif
-}
-
std::unique_ptr<HTMLMediaSession> HTMLMediaSession::create(MediaSessionClient& client)
{
return std::make_unique<HTMLMediaSession>(client);
@@ -93,7 +78,6 @@
: MediaSession(client)
, m_restrictions(NoRestrictions)
{
- initializeAudioSession();
}
void HTMLMediaSession::addBehaviorRestriction(BehaviorRestrictions restriction)
Modified: trunk/Source/WebCore/page/Settings.cpp (167766 => 167767)
--- trunk/Source/WebCore/page/Settings.cpp 2014-04-24 17:48:28 UTC (rev 167766)
+++ trunk/Source/WebCore/page/Settings.cpp 2014-04-24 19:04:01 UTC (rev 167767)
@@ -100,6 +100,7 @@
bool Settings::gNetworkDataUsageTrackingEnabled = false;
bool Settings::gAVKitEnabled = false;
bool Settings::gShouldOptOutOfNetworkStateObservation = false;
+bool Settings::gManageAudioSession = false;
#endif
// NOTEs
Modified: trunk/Source/WebCore/page/Settings.h (167766 => 167767)
--- trunk/Source/WebCore/page/Settings.h 2014-04-24 17:48:28 UTC (rev 167766)
+++ trunk/Source/WebCore/page/Settings.h 2014-04-24 19:04:01 UTC (rev 167767)
@@ -270,6 +270,9 @@
static void setShouldOptOutOfNetworkStateObservation(bool flag) { gShouldOptOutOfNetworkStateObservation = flag; }
static bool shouldOptOutOfNetworkStateObservation() { return gShouldOptOutOfNetworkStateObservation; }
+
+ static void setShouldManageAudioSession(bool flag) { gManageAudioSession = flag; }
+ static bool shouldManageAudioSession() { return gManageAudioSession; }
#endif
private:
@@ -351,6 +354,7 @@
static bool gNetworkDataUsageTrackingEnabled;
static bool gAVKitEnabled;
static bool gShouldOptOutOfNetworkStateObservation;
+ static bool gManageAudioSession;
#endif
static double gHiddenPageDOMTimerAlignmentInterval;
Modified: trunk/Source/WebCore/platform/audio/ios/AudioDestinationIOS.cpp (167766 => 167767)
--- trunk/Source/WebCore/platform/audio/ios/AudioDestinationIOS.cpp 2014-04-24 17:48:28 UTC (rev 167766)
+++ trunk/Source/WebCore/platform/audio/ios/AudioDestinationIOS.cpp 2014-04-24 19:04:01 UTC (rev 167767)
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2010 Google Inc. All rights reserved.
- * Copyright (C) 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2011, 2014 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -100,17 +100,11 @@
: m_outputUnit(0)
, m_callback(callback)
, m_renderBus(AudioBus::create(2, kRenderBufferSize, false))
+ , m_mediaSession(MediaSession::create(*this))
, m_sampleRate(sampleRate)
, m_isPlaying(false)
- , m_interruptedOnPlayback(false)
{
- AudioSession& session = AudioSession::sharedSession();
- session.addListener(this);
- session.setCategory(AudioSession::AmbientSound);
-
audioDestinations().add(this);
- if (audioDestinations().size() == 1)
- session.setActive(1);
// Open and initialize DefaultOutputUnit
AudioComponent comp;
@@ -148,10 +142,7 @@
AudioDestinationIOS::~AudioDestinationIOS()
{
- AudioSession::sharedSession().removeListener(this);
audioDestinations().remove(this);
- if (!audioDestinations().size())
- AudioSession::sharedSession().setActive(0);
if (m_outputUnit)
AudioComponentInstanceDispose(m_outputUnit);
@@ -192,38 +183,30 @@
void AudioDestinationIOS::start()
{
- OSStatus result = AudioOutputUnitStart(m_outputUnit);
+ LOG(Media, "AudioDestinationIOS::start");
+ if (!m_mediaSession->clientWillBeginPlayback()) {
+ LOG(Media, " returning because of interruption");
+ return;
+ }
+ OSStatus result = AudioOutputUnitStart(m_outputUnit);
if (!result)
m_isPlaying = true;
}
void AudioDestinationIOS::stop()
{
- OSStatus result = AudioOutputUnitStop(m_outputUnit);
+ LOG(Media, "AudioDestinationIOS::stop");
+ if (!m_mediaSession->clientWillPausePlayback()) {
+ LOG(Media, " returning because of interruption");
+ return;
+ }
+ OSStatus result = AudioOutputUnitStop(m_outputUnit);
if (!result)
m_isPlaying = false;
}
-void AudioDestinationIOS::beganAudioInterruption()
-{
- if (!m_isPlaying)
- return;
-
- stop();
- m_interruptedOnPlayback = true;
-}
-
-void AudioDestinationIOS::endedAudioInterruption()
-{
- if (!m_interruptedOnPlayback)
- return;
-
- m_interruptedOnPlayback = false;
- start();
-}
-
// Pulls on our provider to get rendered audio stream.
OSStatus AudioDestinationIOS::render(UInt32 numberOfFrames, AudioBufferList* ioData)
{
Modified: trunk/Source/WebCore/platform/audio/ios/AudioDestinationIOS.h (167766 => 167767)
--- trunk/Source/WebCore/platform/audio/ios/AudioDestinationIOS.h 2014-04-24 17:48:28 UTC (rev 167766)
+++ trunk/Source/WebCore/platform/audio/ios/AudioDestinationIOS.h 2014-04-24 19:04:01 UTC (rev 167767)
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2010 Google Inc. All rights reserved.
- * Copyright (C) 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2011, 2014 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -33,6 +33,7 @@
#include "AudioBus.h"
#include "AudioDestination.h"
#include "AudioSessionListener.h"
+#include "MediaSession.h"
#include <AudioUnit/AudioUnit.h>
#include <wtf/RefPtr.h>
@@ -40,22 +41,27 @@
// An AudioDestination using CoreAudio's default output AudioUnit
-class AudioDestinationIOS : public AudioDestination, public AudioSessionListener {
+class AudioDestinationIOS final : public AudioDestination, private MediaSessionClient {
public:
AudioDestinationIOS(AudioIOCallback&, double sampleRate);
virtual ~AudioDestinationIOS();
- virtual void start();
- virtual void stop();
- bool isPlaying() { return m_isPlaying; }
-
- float sampleRate() const { return m_sampleRate; }
-
private:
void configure();
- virtual void beganAudioInterruption() override;
- virtual void endedAudioInterruption() override;
+ // AudioDestination
+ virtual void start() override;
+ virtual void stop() override;
+ virtual bool isPlaying() override { return m_isPlaying; }
+ virtual float sampleRate() const override { return m_sampleRate; }
+
+ // MediaSessionClient
+ virtual MediaSession::MediaType mediaType() const { return MediaSession::WebAudio; }
+ virtual bool canReceiveRemoteControlCommands() const { return false; }
+ virtual void didReceiveRemoteControlCommand(MediaSession::RemoteControlCommandType) { }
+ virtual void pausePlayback() override { stop(); }
+ virtual void resumePlayback() override { start(); }
+
// DefaultOutputUnit callback
static OSStatus inputProc(void* userData, AudioUnitRenderActionFlags*, const AudioTimeStamp*, UInt32 busNumber, UInt32 numberOfFrames, AudioBufferList* ioData);
static void frameSizeChangedProc(void *inRefCon, AudioUnit inUnit, AudioUnitPropertyID inID, AudioUnitScope inScope, AudioUnitElement inElement);
@@ -67,10 +73,10 @@
AudioUnit m_outputUnit;
AudioIOCallback& m_callback;
RefPtr<AudioBus> m_renderBus;
+ std::unique_ptr<MediaSession> m_mediaSession;
double m_sampleRate;
bool m_isPlaying;
- bool m_interruptedOnPlayback;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/audio/ios/AudioSessionIOS.mm (167766 => 167767)
--- trunk/Source/WebCore/platform/audio/ios/AudioSessionIOS.mm 2014-04-24 17:48:28 UTC (rev 167766)
+++ trunk/Source/WebCore/platform/audio/ios/AudioSessionIOS.mm 2014-04-24 19:04:01 UTC (rev 167767)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2014 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -28,6 +28,7 @@
#if USE(AUDIO_SESSION) && PLATFORM(IOS)
+#import "Logging.h"
#import "SoftLinking.h"
#import <AVFoundation/AVAudioSession.h>
#import <objc/runtime.h>
@@ -104,6 +105,26 @@
namespace WebCore {
+
+#if !LOG_DISABLED
+static const char* categoryName(AudioSession::CategoryType category)
+{
+#define CASE(category) case AudioSession::category: return #category
+ switch (category) {
+ CASE(None);
+ CASE(AmbientSound);
+ CASE(SoloAmbientSound);
+ CASE(MediaPlayback);
+ CASE(RecordAudio);
+ CASE(PlayAndRecord);
+ CASE(AudioProcessing);
+ }
+
+ ASSERT_NOT_REACHED();
+ return "";
+}
+#endif
+
class AudioSessionPrivate {
public:
AudioSessionPrivate(AudioSession*);
@@ -128,18 +149,14 @@
void AudioSession::setCategory(CategoryType newCategory)
{
- if (categoryOverride() && categoryOverride() != newCategory)
+ LOG(Media, "AudioSession::setCategory() - category = %s", categoryName(newCategory));
+
+ if (categoryOverride() && categoryOverride() != newCategory) {
+ LOG(Media, "AudioSession::setCategory() - override set, NOT changing");
return;
-
- if (!categoryOverride()) {
- // If a page plays only WebAudio we set the audio category to "ambient" so it is muted by the ringer switch.
- // However, audio from an HTML5 media element or from a plug-in should always play as "media" so don't change the
- // category once it has already been set to media.
- if (newCategory == AudioSession::AmbientSound && category() == AudioSession::MediaPlayback)
- return;
}
- NSString* categoryString;
+ NSString *categoryString;
switch (newCategory) {
case AmbientSound:
categoryString = AVAudioSessionCategoryAmbient;
@@ -171,7 +188,7 @@
AudioSession::CategoryType AudioSession::category() const
{
- NSString* categoryString = [[AVAudioSession sharedInstance] category];
+ NSString *categoryString = [[AVAudioSession sharedInstance] category];
if ([categoryString isEqual:AVAudioSessionCategoryAmbient])
return AmbientSound;
if ([categoryString isEqual:AVAudioSessionCategorySoloAmbient])
Modified: trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm (167766 => 167767)
--- trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm 2014-04-24 17:48:28 UTC (rev 167766)
+++ trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm 2014-04-24 19:04:01 UTC (rev 167767)
@@ -136,8 +136,15 @@
addRestriction(MediaSession::Video, ConcurrentPlaybackNotPermitted);
addRestriction(MediaSession::Video, BackgroundPlaybackNotPermitted);
+ removeRestriction(MediaSession::Audio, ConcurrentPlaybackNotPermitted);
+ removeRestriction(MediaSession::Audio, BackgroundPlaybackNotPermitted);
+
+ removeRestriction(MediaSession::WebAudio, ConcurrentPlaybackNotPermitted);
+ removeRestriction(MediaSession::WebAudio, BackgroundPlaybackNotPermitted);
+
removeRestriction(MediaSession::Audio, MetadataPreloadingNotPermitted);
removeRestriction(MediaSession::Video, MetadataPreloadingNotPermitted);
+
addRestriction(MediaSession::Audio, AutoPreloadingNotPermitted);
addRestriction(MediaSession::Video, AutoPreloadingNotPermitted);
}
@@ -193,7 +200,7 @@
[info setValue:@(duration) forKey:MPMediaItemPropertyPlaybackDuration];
double currentTime = currentSession->currentTime();
- if (std::isfinite(currentTime))
+ if (std::isfinite(currentTime) && currentTime != MediaPlayer::invalidTime())
[info setValue:@(currentTime) forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime];
[info setValue:(currentSession->state() == MediaSession::Playing ? @YES : @NO) forKey:MPNowPlayingInfoPropertyPlaybackRate];
Modified: trunk/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.cpp (167766 => 167767)
--- trunk/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.cpp 2014-04-24 17:48:28 UTC (rev 167766)
+++ trunk/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.cpp 2014-04-24 19:04:01 UTC (rev 167767)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2014 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -46,12 +46,28 @@
if (has(MediaSession::WebAudio))
AudioSession::sharedSession().setPreferredBufferSize(kWebAudioBufferSize);
- // FIXME: <http://webkit.org/b/116725> Figure out why enabling the code below
- // causes media LayoutTests to fail on 10.8.
#if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
- else if ((has(MediaSession::Video) || has(MediaSession::Audio)) && Settings::lowPowerVideoAudioBufferSizeEnabled())
+ else if ((has(MediaSession::Video) || has(MediaSession::Audio)) && Settings::lowPowerVideoAudioBufferSizeEnabled()) {
+ // FIXME: <http://webkit.org/b/116725> Figure out why enabling the code below
+ // causes media LayoutTests to fail on 10.8.
AudioSession::sharedSession().setPreferredBufferSize(kLowPowerVideoBufferSize);
+ }
#endif
+
+#if PLATFORM(IOS)
+ if (has(MediaSession::WebAudio))
+ AudioSession::sharedSession().setActive(true);
+ else
+ AudioSession::sharedSession().setActive(false);
+
+ if (!Settings::shouldManageAudioSession())
+ return;
+
+ if (has(MediaSession::Video) || has(MediaSession::Audio))
+ AudioSession::sharedSession().setCategory(AudioSession::MediaPlayback);
+ else if (has(MediaSession::WebAudio))
+ AudioSession::sharedSession().setCategory(AudioSession::AmbientSound);
+#endif
}
#endif // USE(AUDIO_SESSION)
Modified: trunk/Source/WebKit/mac/ChangeLog (167766 => 167767)
--- trunk/Source/WebKit/mac/ChangeLog 2014-04-24 17:48:28 UTC (rev 167766)
+++ trunk/Source/WebKit/mac/ChangeLog 2014-04-24 19:04:01 UTC (rev 167767)
@@ -1,3 +1,14 @@
+2014-04-24 Eric Carlson <[email protected]>
+
+ [iOS] Manage AudioSession category according to media type
+ https://bugs.webkit.org/show_bug.cgi?id=132096
+
+ Reviewed by Jer Noble.
+
+ * WebView/WebView.mm:
+ (-[WebView _commonInitializationWithFrameName:groupName:]): Tell
+ WebCore to manage the AudioSession when running in MobileSafari.
+
2014-04-23 Andreas Kling <[email protected]>
Remove Apple Dictionary workaround in WebFrameLoaderClient.
Modified: trunk/Source/WebKit/mac/WebView/WebView.mm (167766 => 167767)
--- trunk/Source/WebKit/mac/WebView/WebView.mm 2014-04-24 17:48:28 UTC (rev 167766)
+++ trunk/Source/WebKit/mac/WebView/WebView.mm 2014-04-24 19:04:01 UTC (rev 167767)
@@ -902,6 +902,11 @@
Settings::setShouldRespectPriorityInCSSAttributeSetters(shouldRespectPriorityInCSSAttributeSetters());
+#if PLATFORM(IOS)
+ if (applicationIsMobileSafari())
+ Settings::setShouldManageAudioSession(true);
+#endif
+
didOneTimeInitialization = true;
}
Modified: trunk/Source/WebKit2/ChangeLog (167766 => 167767)
--- trunk/Source/WebKit2/ChangeLog 2014-04-24 17:48:28 UTC (rev 167766)
+++ trunk/Source/WebKit2/ChangeLog 2014-04-24 19:04:01 UTC (rev 167767)
@@ -1,3 +1,13 @@
+2014-04-24 Eric Carlson <[email protected]>
+
+ [iOS] Manage AudioSession category according to media type
+ https://bugs.webkit.org/show_bug.cgi?id=132096
+
+ Reviewed by Jer Noble.
+
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::WebPage::WebPage): Tell WebCore to manage the AudioSession.
+
2014-04-24 Tim Horton <[email protected]>
[wk2] Provide SPI allowing clients to hand events directly to swipe code, bypassing scrolling
Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (167766 => 167767)
--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp 2014-04-24 17:48:28 UTC (rev 167766)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp 2014-04-24 19:04:01 UTC (rev 167767)
@@ -310,6 +310,10 @@
// 4ms should be adopted project-wide now, https://bugs.webkit.org/show_bug.cgi?id=61214
Settings::setDefaultMinDOMTimerInterval(0.004);
+#if PLATFORM(IOS)
+ Settings::setShouldManageAudioSession(true);
+#endif
+
Page::PageClients pageClients;
pageClients.chromeClient = new WebChromeClient(this);
#if ENABLE(CONTEXT_MENUS)