Mac: Set the default audio buffer size to a large value for <video> elements.
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 May 2013 18:54:23 +0000 (18:54 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 May 2013 18:54:23 +0000 (18:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=116342

Source/WebCore:

Reviewed by Eric Carlson.
Roll-in rubber stamped by Eric Carlson.

To enable power savings by waking up the audio hardware less often, set the
requested buffer frame size to a large value, such as 4096. Since this results
in approximately 100ms worth of buffer, set the buffer size to a much lower
value when playing WebAudio, which is much more sensitive to latency than video
or audio elements.

Introduce a new class, AudioSessionManager, as well as a helper class,
AudioSessionManagerToken. Audio elements, video elements, and WebAudio destination
nodes will create and retain a token, and release the token in their destructor.
This allows the AudioSessionManager to track how many of what type of audio-
generating objects are in existence.

This requires implementing AudioSession for Mac platforms. Move the implementation
for retrieving the hardware sample rate and setting the buffer duration into
AudioSessionMac from AudioDestinationMac, to be shared with AudioSessionManagerMac.

Change the AudioSession method preferredBufferLength() into preferredBufferSize(),
as the callers really want to specify a buffer size, not a buffer duration. On iOS,
where the available API requires a duration, perform the conversion from duration to
size on behalf of the caller.

However, since the original version of this patch caused media test
failures on the Mac ML and Lion bots, only enable the buffer size
change for OS X > ML.

* html/HTMLMediaElement.h:  Add a AudioSessionManagerToken member.
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::HTMLMediaElement): Initialize the token.
* platform/audio/AudioSession.cpp:
(WebCore::AudioSession::preferredBufferSize): Renamed from preferredBufferLength.
(WebCore::AudioSession::setPreferredBufferSize): Renamed from setPreferredBufferLength.
* platform/audio/AudioSession.h:
* platform/audio/AudioSessionManager.cpp:
(AudioSessionManagerToken::create): Simple factory method.
(AudioSessionManagerToken::AudioSessionManagerToken): Call AudioSessionManager::incrementCount().
(AudioSessionManagerToken::~AudioSessionManagerToken): Call AudioSessionManager::decrementCount().
(AudioSessionManager::sharedManager): Simple singleton method.
(AudioSessionManager::AudioSessionManager): Simple constructor.
(AudioSessionManager::has): Return whether the type is present.
(AudioSessionManager::incrementCount): Increment, then call updateSessionState()
(AudioSessionManager::decrementCount): Decrement, then call updateSessionState()
(AudioSessionManager::updateSessionState): Stub, does nothing.
* platform/audio/AudioSessionManager.h:
* platform/audio/ios/AudioDestinationIOS.cpp:
(WebCore::AudioDestinationIOS::configure): Call setPreferredBufferSize() instead of setPreferredBufferLength()
* platform/audio/ios/AudioSessionIOS.mm:
(WebCore::AudioSession::preferredBufferSize): Renamed from preferredBufferLength.
(WebCore::AudioSession::setPreferredBufferSize): Renamed from setPreferredBufferLength
* platform/audio/mac/AudioDestinationMac.cpp:
(WebCore::AudioDestination::hardwareSampleRate): Call AudioSession::sampleRate().
(WebCore::AudioDestinationMac::AudioDestinationMac): Create the AudioSessionManagerToken.
(WebCore::AudioDestinationMac::configure): Do not set the buffer size (this is done in AudioSessionManagerMac).
* platform/audio/mac/AudioDestinationMac.h:
* platform/audio/mac/AudioSessionMac.cpp: Added.
(WebCore::defaultDevice): Added, returns the default audio device.
(WebCore::AudioSession::AudioSession): Simple constructor.
(WebCore::AudioSession::~AudioSession): Simple destructor.
(WebCore::AudioSession::category): Stub, unimplemented.
(WebCore::AudioSession::setCategory): Ditto.
(WebCore::AudioSession::categoryOverride): Ditto.
(WebCore::AudioSession::setCategoryOverride): Ditto.
(WebCore::AudioSession::numberOfOutputChannels): Ditto.
(WebCore::AudioSession::setActive): Ditto.
(WebCore::AudioSession::sampleRate): Use the HAL to return the default audio device sample rate.
(WebCore::AudioSession::preferredBufferSize): Return the current HAL setting.
(WebCore::AudioSession::setPreferredBufferSize): Set the buffer size.
* platform/audio/mac/AudioSessionManagerMac.cpp:
(AudioSessionManager::updateSessionState): Set the buffer size depending on what audio outputs are present.
* WebCore.xcodeproj/project.pbxproj: Add the new files to the project.

Source/WTF:

Reviewed by Eric Carlson.

* wtf/Platform.h: Add a WTF_USE_AUDIO_SESSION setting.

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

17 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/Platform.h
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/platform/audio/AudioSession.cpp
Source/WebCore/platform/audio/AudioSession.h
Source/WebCore/platform/audio/AudioSessionListener.h
Source/WebCore/platform/audio/AudioSessionManager.cpp [new file with mode: 0644]
Source/WebCore/platform/audio/AudioSessionManager.h [new file with mode: 0644]
Source/WebCore/platform/audio/ios/AudioDestinationIOS.cpp
Source/WebCore/platform/audio/ios/AudioSessionIOS.mm
Source/WebCore/platform/audio/mac/AudioDestinationMac.cpp
Source/WebCore/platform/audio/mac/AudioDestinationMac.h
Source/WebCore/platform/audio/mac/AudioSessionMac.cpp [new file with mode: 0644]
Source/WebCore/platform/audio/mac/AudioSessionManagerMac.cpp [new file with mode: 0644]

index 8d9688a..8754ad9 100644 (file)
@@ -1,3 +1,12 @@
+2013-05-25  Jer Noble  <jer.noble@apple.com>
+
+        Mac: Set the default audio buffer size to a large value for <video> elements.
+        https://bugs.webkit.org/show_bug.cgi?id=116342
+
+        Reviewed by Eric Carlson.
+
+        * wtf/Platform.h: Add a WTF_USE_AUDIO_SESSION setting.
+
 2013-05-23  Brent Fulgham  <bfulgham@apple.com>
 
         [Windows] Rolling back r150600 as it breaks the VS2010 builds.
index 6a6c818..77eb92d 100644 (file)
 #define WTF_USE_MARKER_REMOVAL_UPON_EDITING 1
 #endif /* #if PLATFORM(MAC) && (PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070) */
 
+#if PLATFORM(MAC) || PLATFORM(IOS)
+#define WTF_USE_AUDIO_SESSION 1
+#endif
+
 #endif /* WTF_Platform_h */
index d7eaa53..b515ec8 100644 (file)
@@ -1,3 +1,81 @@
+2013-05-24  Jer Noble  <jer.noble@apple.com>
+
+        Mac: Set the default audio buffer size to a large value for <video> elements.
+        https://bugs.webkit.org/show_bug.cgi?id=116342
+
+        Reviewed by Eric Carlson.
+        Roll-in rubber stamped by Eric Carlson.
+
+        To enable power savings by waking up the audio hardware less often, set the
+        requested buffer frame size to a large value, such as 4096. Since this results
+        in approximately 100ms worth of buffer, set the buffer size to a much lower
+        value when playing WebAudio, which is much more sensitive to latency than video
+        or audio elements.
+
+        Introduce a new class, AudioSessionManager, as well as a helper class,
+        AudioSessionManagerToken. Audio elements, video elements, and WebAudio destination
+        nodes will create and retain a token, and release the token in their destructor.
+        This allows the AudioSessionManager to track how many of what type of audio-
+        generating objects are in existence.
+
+        This requires implementing AudioSession for Mac platforms. Move the implementation
+        for retrieving the hardware sample rate and setting the buffer duration into
+        AudioSessionMac from AudioDestinationMac, to be shared with AudioSessionManagerMac.
+
+        Change the AudioSession method preferredBufferLength() into preferredBufferSize(),
+        as the callers really want to specify a buffer size, not a buffer duration. On iOS,
+        where the available API requires a duration, perform the conversion from duration to
+        size on behalf of the caller.
+
+        However, since the original version of this patch caused media test
+        failures on the Mac ML and Lion bots, only enable the buffer size
+        change for OS X > ML.
+
+        * html/HTMLMediaElement.h:  Add a AudioSessionManagerToken member.
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::HTMLMediaElement): Initialize the token.
+        * platform/audio/AudioSession.cpp:
+        (WebCore::AudioSession::preferredBufferSize): Renamed from preferredBufferLength.
+        (WebCore::AudioSession::setPreferredBufferSize): Renamed from setPreferredBufferLength.
+        * platform/audio/AudioSession.h:
+        * platform/audio/AudioSessionManager.cpp:
+        (AudioSessionManagerToken::create): Simple factory method.
+        (AudioSessionManagerToken::AudioSessionManagerToken): Call AudioSessionManager::incrementCount().
+        (AudioSessionManagerToken::~AudioSessionManagerToken): Call AudioSessionManager::decrementCount().
+        (AudioSessionManager::sharedManager): Simple singleton method.
+        (AudioSessionManager::AudioSessionManager): Simple constructor.
+        (AudioSessionManager::has): Return whether the type is present.
+        (AudioSessionManager::incrementCount): Increment, then call updateSessionState()
+        (AudioSessionManager::decrementCount): Decrement, then call updateSessionState()
+        (AudioSessionManager::updateSessionState): Stub, does nothing.
+        * platform/audio/AudioSessionManager.h:
+        * platform/audio/ios/AudioDestinationIOS.cpp:
+        (WebCore::AudioDestinationIOS::configure): Call setPreferredBufferSize() instead of setPreferredBufferLength()
+        * platform/audio/ios/AudioSessionIOS.mm:
+        (WebCore::AudioSession::preferredBufferSize): Renamed from preferredBufferLength.
+        (WebCore::AudioSession::setPreferredBufferSize): Renamed from setPreferredBufferLength
+        * platform/audio/mac/AudioDestinationMac.cpp:
+        (WebCore::AudioDestination::hardwareSampleRate): Call AudioSession::sampleRate().
+        (WebCore::AudioDestinationMac::AudioDestinationMac): Create the AudioSessionManagerToken.
+        (WebCore::AudioDestinationMac::configure): Do not set the buffer size (this is done in AudioSessionManagerMac).
+        * platform/audio/mac/AudioDestinationMac.h:
+        * platform/audio/mac/AudioSessionMac.cpp: Added.
+        (WebCore::defaultDevice): Added, returns the default audio device.
+        (WebCore::AudioSession::AudioSession): Simple constructor.
+        (WebCore::AudioSession::~AudioSession): Simple destructor.
+        (WebCore::AudioSession::category): Stub, unimplemented.
+        (WebCore::AudioSession::setCategory): Ditto.
+        (WebCore::AudioSession::categoryOverride): Ditto.
+        (WebCore::AudioSession::setCategoryOverride): Ditto.
+        (WebCore::AudioSession::numberOfOutputChannels): Ditto.
+        (WebCore::AudioSession::setActive): Ditto.
+        (WebCore::AudioSession::sampleRate): Use the HAL to return the default audio device sample rate.
+        (WebCore::AudioSession::preferredBufferSize): Return the current HAL setting.
+        (WebCore::AudioSession::setPreferredBufferSize): Set the buffer size.
+        * platform/audio/mac/AudioSessionManagerMac.cpp:
+        (AudioSessionManager::updateSessionState): Set the buffer size depending on what audio outputs are present.
+        * WebCore.xcodeproj/project.pbxproj: Add the new files to the project.
+
 2013-05-24  Alberto Garcia  <agarcia@igalia.com>
 
         Path: upstream the missing bits from the BlackBerry port
index d664d52..d3f73dd 100644 (file)
                CD37B39815C1B971006DC898 /* DiagnosticLoggingKeys.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD37B37415C1A7E1006DC898 /* DiagnosticLoggingKeys.cpp */; };
                CD47B3FC16CC34F800A21EC8 /* CDMPrivateAVFoundation.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD47B3FA16CC34F800A21EC8 /* CDMPrivateAVFoundation.mm */; };
                CD4AC52A1496AE9A0087C4EF /* Composite.wav in Copy Audio Resources */ = {isa = PBXBuildFile; fileRef = CD4AC5281496AE2F0087C4EF /* Composite.wav */; };
+               CD54DE4717468B6F005E5B36 /* AudioSessionManagerMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD54DE4517468B6F005E5B36 /* AudioSessionManagerMac.cpp */; };
+               CD54DE4B17469C6D005E5B36 /* AudioSessionMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD54DE4917469C6D005E5B36 /* AudioSessionMac.cpp */; };
                CD7E05221651C28200C1201F /* WebCoreAVFResourceLoader.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD7E05211651A84100C1201F /* WebCoreAVFResourceLoader.mm */; };
                CD82030A1395AB6A00F956C6 /* WebVideoFullscreenController.h in Headers */ = {isa = PBXBuildFile; fileRef = CD8203061395AB6A00F956C6 /* WebVideoFullscreenController.h */; settings = {ATTRIBUTES = (Private, ); }; };
                CD82030B1395AB6A00F956C6 /* WebVideoFullscreenController.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD8203071395AB6A00F956C6 /* WebVideoFullscreenController.mm */; settings = {COMPILER_FLAGS = "-Wno-undef -Wno-deprecated-declarations"; }; };
                CDA98E0D1603FE4A00FEA3B1 /* MediaKeys.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDA98DCA1601508A00FEA3B1 /* MediaKeys.cpp */; };
                CDA98E0E1603FE5800FEA3B1 /* MediaKeySession.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDA98DC716014F2C00FEA3B1 /* MediaKeySession.cpp */; };
                CDAA8D0A14D71B2E0061EA60 /* PlatformClockCM.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDAA8D0814D385600061EA60 /* PlatformClockCM.mm */; };
+               CDAE8C091746B95700532D78 /* AudioSessionManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDAE8C071746B95700532D78 /* AudioSessionManager.cpp */; };
                CDB859F7160D48A400E5B07F /* MediaKeyEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDB859F4160D489900E5B07F /* MediaKeyEvent.cpp */; };
                CDB859FA160D494900E5B07F /* JSMediaKeyEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDB859F8160D493E00E5B07F /* JSMediaKeyEvent.cpp */; };
                CDC26B40160A8CC60026757B /* MockCDM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDC26B3C160A62B00026757B /* MockCDM.cpp */; };
                CD47B3FA16CC34F800A21EC8 /* CDMPrivateAVFoundation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = CDMPrivateAVFoundation.mm; path = Modules/encryptedmedia/CDMPrivateAVFoundation.mm; sourceTree = "<group>"; };
                CD4AC5281496AE2F0087C4EF /* Composite.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; name = Composite.wav; path = platform/audio/resources/Composite.wav; sourceTree = SOURCE_ROOT; };
                CD4E0AFA11F7BC27009D3811 /* fullscreen.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; path = fullscreen.css; sourceTree = "<group>"; };
+               CD54DE4517468B6F005E5B36 /* AudioSessionManagerMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AudioSessionManagerMac.cpp; sourceTree = "<group>"; };
+               CD54DE4917469C6D005E5B36 /* AudioSessionMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AudioSessionMac.cpp; sourceTree = "<group>"; };
                CD7E05201651A84100C1201F /* WebCoreAVFResourceLoader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WebCoreAVFResourceLoader.h; path = objc/WebCoreAVFResourceLoader.h; sourceTree = "<group>"; };
                CD7E05211651A84100C1201F /* WebCoreAVFResourceLoader.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = WebCoreAVFResourceLoader.mm; path = objc/WebCoreAVFResourceLoader.mm; sourceTree = "<group>"; };
                CD8203061395AB6A00F956C6 /* WebVideoFullscreenController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebVideoFullscreenController.h; sourceTree = "<group>"; };
                CDA98E0C1603CF3C00FEA3B1 /* CDMPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDMPrivate.h; path = Modules/encryptedmedia/CDMPrivate.h; sourceTree = "<group>"; };
                CDAA8D0714D385600061EA60 /* PlatformClockCM.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformClockCM.h; sourceTree = "<group>"; };
                CDAA8D0814D385600061EA60 /* PlatformClockCM.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PlatformClockCM.mm; sourceTree = "<group>"; };
+               CDAE8C071746B95700532D78 /* AudioSessionManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AudioSessionManager.cpp; sourceTree = "<group>"; };
+               CDAE8C081746B95700532D78 /* AudioSessionManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioSessionManager.h; sourceTree = "<group>"; };
                CDB859F2160D489900E5B07F /* MediaKeyError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaKeyError.h; sourceTree = "<group>"; };
                CDB859F3160D489900E5B07F /* MediaKeyError.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = MediaKeyError.idl; sourceTree = "<group>"; };
                CDB859F4160D489900E5B07F /* MediaKeyEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaKeyEvent.cpp; sourceTree = "<group>"; };
                                CDA79821170A22DC00D45C55 /* AudioSession.h */,
                                CDA79823170A258300D45C55 /* AudioSession.cpp */,
                                CDA79822170A24F400D45C55 /* AudioSessionListener.h */,
+                               CDAE8C071746B95700532D78 /* AudioSessionManager.cpp */,
+                               CDAE8C081746B95700532D78 /* AudioSessionManager.h */,
                                FD31605312B026F700C1A359 /* AudioSourceProvider.h */,
                                FD62F52D145898D80094B0ED /* AudioSourceProviderClient.h */,
                                FD31605412B026F700C1A359 /* AudioUtilities.cpp */,
                                FD3160B812B0272A00C1A359 /* AudioFileReaderMac.cpp */,
                                FD3160B912B0272A00C1A359 /* AudioFileReaderMac.h */,
                                FD3160BA12B0272A00C1A359 /* FFTFrameMac.cpp */,
+                               CD54DE4517468B6F005E5B36 /* AudioSessionManagerMac.cpp */,
+                               CD54DE4917469C6D005E5B36 /* AudioSessionMac.cpp */,
                        );
                        path = mac;
                        sourceTree = "<group>";
                                84730D7C1248F0B300D3A9C9 /* FEDisplacementMap.cpp in Sources */,
                                4358E8801360A31700E4748C /* FEDropShadow.cpp in Sources */,
                                84730D7E1248F0B300D3A9C9 /* FEFlood.cpp in Sources */,
+                               CD54DE4B17469C6D005E5B36 /* AudioSessionMac.cpp in Sources */,
                                84801954108BAFB300CB2B1F /* FEGaussianBlur.cpp in Sources */,
                                84730D801248F0B300D3A9C9 /* FELighting.cpp in Sources */,
                                84730D821248F0B300D3A9C9 /* FEMerge.cpp in Sources */,
                                93309E09099E64920056E581 /* ReplaceSelectionCommand.cpp in Sources */,
                                F55B3DCF1251F12D003EF269 /* ResetInputType.cpp in Sources */,
                                514BC842161CF05C004D52F4 /* ResourceBuffer.cpp in Sources */,
+                               CD54DE4717468B6F005E5B36 /* AudioSessionManagerMac.cpp in Sources */,
                                514BC83F161CF04A004D52F4 /* ResourceBuffer.mm in Sources */,
                                934F713E0D5A6F2800018D69 /* ResourceErrorBase.cpp in Sources */,
                                7EE6846B12D26E3800E79415 /* ResourceErrorCF.cpp in Sources */,
                                376DCCE113B4F966002EBEFC /* TextRun.cpp in Sources */,
                                B2C3DA4A0D006C1D00EF6F26 /* TextStream.cpp in Sources */,
                                9759E93F14EF1CF80026A2DD /* TextTrack.cpp in Sources */,
+                               CDAE8C091746B95700532D78 /* AudioSessionManager.cpp in Sources */,
                                9759E94214EF1CF80026A2DD /* TextTrackCue.cpp in Sources */,
                                071A9EC2168FBC43002629F9 /* TextTrackCueGeneric.cpp in Sources */,
                                9759E94514EF1CF80026A2DD /* TextTrackCueList.cpp in Sources */,
index a1d4b0a..ac2b72a 100644 (file)
 #include "PlatformTextTrack.h"
 #endif
 
+#if USE(AUDIO_SESSION)
+#include "AudioSessionManager.h"
+#endif
+
 using namespace std;
 
 namespace WebCore {
@@ -316,6 +320,9 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document* docum
 #if ENABLE(WEB_AUDIO)
     , m_audioSourceNode(0)
 #endif
+#if USE(AUDIO_SESSION)
+    , m_audioSessionManagerToken(AudioSessionManagerToken::create(tagName == videoTag ? AudioSessionManager::Video : AudioSessionManager::Audio))
+#endif
 {
     LOG(Media, "HTMLMediaElement::HTMLMediaElement");
     document->registerForMediaVolumeCallbacks(this);
index 30dc124..c5721f1 100644 (file)
@@ -49,6 +49,9 @@
 
 namespace WebCore {
 
+#if USE(AUDIO_SESSION)
+class AudioSessionManagerToken;
+#endif
 #if ENABLE(WEB_AUDIO)
 class AudioSourceProvider;
 class MediaElementAudioSourceNode;
@@ -765,6 +768,10 @@ private:
 #if USE(PLATFORM_TEXT_TRACK_MENU)
     RefPtr<PlatformTextTrackMenuInterface> m_platformMenu;
 #endif
+
+#if USE(AUDIO_SESSION)
+    OwnPtr<AudioSessionManagerToken> m_audioSessionManagerToken;
+#endif
 };
 
 #if ENABLE(VIDEO_TRACK)
index cdf8337..7529a1b 100644 (file)
@@ -26,6 +26,8 @@
 #include "config.h"
 #include "AudioSession.h"
 
+#if USE(AUDIO_SESSION)
+
 #include "AudioSessionListener.h"
 #include "NotImplemented.h"
 
@@ -59,12 +61,12 @@ void AudioSession::endedAudioInterruption()
         (*i)->endedAudioInterruption();
 }
 
-#if !PLATFORM(IOS)
+#if !PLATFORM(IOS) && !PLATFORM(MAC)
 class AudioSessionPrivate {
 };
 
 AudioSession::AudioSession()
-    : m_private(0)
+    : m_private(nullptr)
 {
     notImplemented();
 }
@@ -112,16 +114,18 @@ void AudioSession::setActive(bool)
     notImplemented();
 }
 
-float AudioSession::preferredBufferDuration() const
+size_t AudioSession::preferredBufferSize() const
 {
     notImplemented();
     return 0;
 }
 
-void AudioSession::setPreferredBufferDuration(float)
+void AudioSession::setPreferredBufferSize(size_t)
 {
     notImplemented();
 }
 #endif // !PLATFORM(IOS)
 
 }
+
+#endif // USE(AUDIO_SESSION)
index 7c202eb..0ea664c 100644 (file)
@@ -26,6 +26,8 @@
 #ifndef AudioSession_h
 #define AudioSession_h
 
+#if USE(AUDIO_SESSION)
+
 #include <wtf/HashSet.h>
 #include <wtf/OwnPtr.h>
 
@@ -62,8 +64,8 @@ public:
 
     void setActive(bool);
 
-    float preferredBufferDuration() const;
-    void setPreferredBufferDuration(float seconds);
+    size_t preferredBufferSize() const;
+    void setPreferredBufferSize(size_t);
 
     void beganAudioInterruption();
     void endedAudioInterruption();
@@ -78,4 +80,6 @@ private:
 
 }
 
+#endif // USE(AUDIO_SESSION)
+
 #endif // AudioSession_h
index 62c5b11..d8b82e7 100644 (file)
 #ifndef AudioSessionListener_h
 #define AudioSessionListener_h
 
+#if USE(AUDIO_SESSION)
+
 namespace WebCore {
 
 class AudioSessionListener {
-    WTF_MAKE_NONCOPYABLE(AudioSessionListener)
+    WTF_MAKE_NONCOPYABLE(AudioSessionListener);
 public:
     virtual void beganAudioInterruption() = 0;
     virtual void endedAudioInterruption() = 0;
@@ -40,4 +42,6 @@ protected:
 
 }
 
+#endif // USE(AUDIO_SESSION)
+
 #endif // AudioSessionListener_h
diff --git a/Source/WebCore/platform/audio/AudioSessionManager.cpp b/Source/WebCore/platform/audio/AudioSessionManager.cpp
new file mode 100644 (file)
index 0000000..12a1b95
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2013 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 "AudioSessionManager.h"
+
+#if USE(AUDIO_SESSION)
+
+using namespace WebCore;
+
+PassOwnPtr<AudioSessionManagerToken> AudioSessionManagerToken::create(AudioSessionManager::AudioType type)
+{
+    return adoptPtr(new AudioSessionManagerToken(type));
+}
+
+AudioSessionManagerToken::AudioSessionManagerToken(AudioSessionManager::AudioType type)
+    : m_type(type)
+{
+    AudioSessionManager::sharedManager().incrementCount(type);
+}
+
+AudioSessionManagerToken::~AudioSessionManagerToken()
+{
+    AudioSessionManager::sharedManager().decrementCount(m_type);
+}
+
+AudioSessionManager& AudioSessionManager::sharedManager()
+{
+    DEFINE_STATIC_LOCAL(AudioSessionManager, manager, ());
+    return manager;
+}
+
+AudioSessionManager::AudioSessionManager()
+{
+}
+
+bool AudioSessionManager::has(AudioSessionManager::AudioType type)
+{
+    ASSERT(type >= 0);
+    return m_typeCount.contains(type);
+}
+
+void AudioSessionManager::incrementCount(AudioSessionManager::AudioType type)
+{
+    ASSERT(type >= 0);
+    m_typeCount.add(type);
+    updateSessionState();
+}
+
+void AudioSessionManager::decrementCount(AudioSessionManager::AudioType type)
+{
+    ASSERT(type >= 0);
+    m_typeCount.remove(type);
+    updateSessionState();
+}
+
+#if !PLATFORM(MAC)
+void AudioSessionManager::updateSessionState()
+{
+}
+#endif
+
+#endif // USE(AUDIO_SESSION)
diff --git a/Source/WebCore/platform/audio/AudioSessionManager.h b/Source/WebCore/platform/audio/AudioSessionManager.h
new file mode 100644 (file)
index 0000000..28a5c6a
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+#ifndef AudioSessionManager_h
+#define AudioSessionManager_h
+
+#if USE(AUDIO_SESSION)
+
+#include "AudioSession.h"
+#include <wtf/HashCountedSet.h>
+#include <wtf/PassOwnPtr.h>
+
+namespace WebCore {
+
+class AudioSessionManager {
+public:
+    static AudioSessionManager& sharedManager();
+
+    enum AudioType {
+        None,
+        Video,
+        Audio,
+        WebAudio,
+    };
+
+    bool has(AudioType);
+
+protected:
+    friend class AudioSessionManagerToken;
+    void incrementCount(AudioType);
+    void decrementCount(AudioType);
+    
+private:
+    AudioSessionManager();
+
+    void updateSessionState();
+
+    HashCountedSet<size_t> m_typeCount;
+};
+
+class AudioSessionManagerToken {
+public:
+    static PassOwnPtr<AudioSessionManagerToken> create(AudioSessionManager::AudioType);
+    ~AudioSessionManagerToken();
+
+private:
+    AudioSessionManagerToken(AudioSessionManager::AudioType);
+
+    AudioSessionManager::AudioType m_type;
+};
+}
+
+#endif // USE(AUDIO_SESSION)
+
+#endif // AudioSessionManager_h
index 34b288c..95e8a45 100644 (file)
@@ -188,7 +188,7 @@ void AudioDestinationIOS::configure()
     result = AudioUnitSetProperty(m_outputUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, (void*)&streamFormat, sizeof(AudioStreamBasicDescription));
     ASSERT(!result);
 
-    AudioSession::sharedSession().setPreferredBufferDuration(narrowPrecisionToFloat(kPreferredBufferSize / m_sampleRate));
+    AudioSession::sharedSession().setPreferredBufferSize(kPreferredBufferSize);
 }
 
 void AudioDestinationIOS::start()
index 9fa8e3b..79e261a 100644 (file)
@@ -26,7 +26,7 @@
 #import "config.h"
 #import "AudioSession.h"
 
-#if PLATFORM(IOS)
+#if USE(AUDIO_SESSION) && PLATFORM(IOS)
 
 #import "SoftLinking.h"
 #import <AVFoundation/AVAudioSession.h>
@@ -201,18 +201,19 @@ void AudioSession::setActive(bool active)
     ASSERT(!error);
 }
 
-float AudioSession::preferredBufferDuration() const
+size_t AudioSession::preferredBufferSize() const
 {
-    return [[AVAudioSession sharedInstance] preferredIOBufferDuration];
+    return [[AVAudioSession sharedInstance] preferredIOBufferDuration] * sampleRate();
 }
 
-void AudioSession::setPreferredBufferDuration(float duration)
+void AudioSession::setPreferredBufferSize(size_t bufferSize)
 {
     NSError *error = nil;
+    float duration = bufferSize / sampleRate();
     [[AVAudioSession sharedInstance] setPreferredIOBufferDuration:duration error:&error];
     ASSERT(!error);
 }
 
 }
 
-#endif // PLATFORM(IOS)
+#endif // USE(AUDIO_SESSION) && PLATFORM(IOS)
index a1a54c3..ae4b33b 100644 (file)
@@ -33,6 +33,7 @@
 #include "AudioDestinationMac.h"
 
 #include "AudioIOCallback.h"
+#include "AudioSessionManager.h"
 #include "FloatConversion.h"
 #include "Logging.h"
 #include "VectorMath.h"
@@ -63,23 +64,7 @@ PassOwnPtr<AudioDestination> AudioDestination::create(AudioIOCallback& callback,
 float AudioDestination::hardwareSampleRate()
 {
     // Determine the default output device's sample-rate.
-    AudioDeviceID deviceID = kAudioDeviceUnknown;
-    UInt32 infoSize = sizeof(deviceID);
-
-    AudioObjectPropertyAddress defaultOutputDeviceAddress = { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
-    OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject, &defaultOutputDeviceAddress, 0, 0, &infoSize, (void*)&deviceID);
-    if (result)
-        return 0; // error
-
-    Float64 nominalSampleRate;
-    infoSize = sizeof(Float64);
-
-    AudioObjectPropertyAddress nominalSampleRateAddress = { kAudioDevicePropertyNominalSampleRate, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
-    result = AudioObjectGetPropertyData(deviceID, &nominalSampleRateAddress, 0, 0, &infoSize, (void*)&nominalSampleRate);
-    if (result)
-        return 0; // error
-
-    return narrowPrecisionToFloat(nominalSampleRate);
+    return AudioSession::sharedSession().sampleRate();
 }
 
 unsigned long AudioDestination::maxChannelCount()
@@ -97,6 +82,7 @@ AudioDestinationMac::AudioDestinationMac(AudioIOCallback& callback, float sample
     , m_renderBus(AudioBus::create(2, kBufferSize, false))
     , m_sampleRate(sampleRate)
     , m_isPlaying(false)
+    , m_audioSessionManagerToken(AudioSessionManagerToken::create(AudioSessionManager::WebAudio))
 {
     // Open and initialize DefaultOutputUnit
     AudioComponent comp;
@@ -148,11 +134,6 @@ void AudioDestinationMac::configure()
 
     result = AudioUnitSetProperty(m_outputUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, (void*)&streamFormat, sizeof(AudioStreamBasicDescription));
     ASSERT(!result);
-
-    // Set the buffer frame size.
-    UInt32 bufferSize = kBufferSize;
-    result = AudioUnitSetProperty(m_outputUnit, kAudioDevicePropertyBufferFrameSize, kAudioUnitScope_Output, 0, (void*)&bufferSize, sizeof(bufferSize));
-    ASSERT(!result);
 }
 
 void AudioDestinationMac::start()
index 062c969..928aac0 100644 (file)
 #include "AudioBus.h"
 #include "AudioDestination.h"
 #include <AudioUnit/AudioUnit.h>
+#include <wtf/OwnPtr.h>
 #include <wtf/RefPtr.h>
 
 namespace WebCore {
 
+class AudioSessionManagerToken;
+
 // An AudioDestination using CoreAudio's default output AudioUnit
 
 class AudioDestinationMac : public AudioDestination {
@@ -63,6 +66,10 @@ private:
 
     float m_sampleRate;
     bool m_isPlaying;
+
+#if USE(AUDIO_SESSION)
+    OwnPtr<AudioSessionManagerToken> m_audioSessionManagerToken;
+#endif
 };
 
 } // namespace WebCore
diff --git a/Source/WebCore/platform/audio/mac/AudioSessionMac.cpp b/Source/WebCore/platform/audio/mac/AudioSessionMac.cpp
new file mode 100644 (file)
index 0000000..7788472
--- /dev/null
@@ -0,0 +1,168 @@
+/*
+ * Copyright (C) 2013 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 "AudioSession.h"
+
+#if USE(AUDIO_SESSION) && PLATFORM(MAC)
+
+#include "FloatConversion.h"
+#include "Logging.h"
+#include "NotImplemented.h"
+#include <CoreAudio/AudioHardware.h>
+#include <wtf/PassOwnPtr.h>
+
+namespace WebCore {
+
+static AudioDeviceID defaultDevice()
+{
+    AudioDeviceID deviceID = kAudioDeviceUnknown;
+    UInt32 infoSize = sizeof(deviceID);
+
+    AudioObjectPropertyAddress defaultOutputDeviceAddress = {
+        kAudioHardwarePropertyDefaultOutputDevice,
+        kAudioObjectPropertyScopeGlobal,
+        kAudioObjectPropertyElementMaster };
+    OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject, &defaultOutputDeviceAddress, 0, 0, &infoSize, (void*)&deviceID);
+    if (result)
+        return 0; // error
+    return deviceID;
+}
+
+class AudioSessionPrivate {
+public:    
+};
+
+AudioSession::AudioSession()
+    : m_private(adoptPtr(new AudioSessionPrivate()))
+{
+}
+
+AudioSession::~AudioSession()
+{
+}
+
+AudioSession::CategoryType AudioSession::category() const
+{
+    notImplemented();
+    return None;
+}
+
+void AudioSession::setCategory(CategoryType)
+{
+    notImplemented();
+}
+
+AudioSession::CategoryType AudioSession::categoryOverride() const
+{
+    notImplemented();
+    return None;
+}
+
+void AudioSession::setCategoryOverride(CategoryType)
+{
+    notImplemented();
+}
+
+float AudioSession::sampleRate() const
+{
+    Float64 nominalSampleRate;
+    UInt32 nominalSampleRateSize = sizeof(Float64);
+
+    AudioObjectPropertyAddress nominalSampleRateAddress = {
+        kAudioDevicePropertyNominalSampleRate,
+        kAudioObjectPropertyScopeGlobal,
+        kAudioObjectPropertyElementMaster };
+    OSStatus result = AudioObjectGetPropertyData(defaultDevice(), &nominalSampleRateAddress, 0, 0, &nominalSampleRateSize, (void*)&nominalSampleRate);
+    if (result)
+        return 0;
+
+    return narrowPrecisionToFloat(nominalSampleRate);
+}
+
+size_t AudioSession::numberOfOutputChannels() const
+{
+    notImplemented();
+    return 0;
+}
+
+void AudioSession::setActive(bool)
+{
+    notImplemented();
+}
+
+size_t AudioSession::preferredBufferSize() const
+{
+    UInt32 bufferSize;
+    UInt32 bufferSizeSize = sizeof(bufferSize);
+
+    AudioObjectPropertyAddress preferredBufferSizeAddress = {
+        kAudioDevicePropertyBufferFrameSizeRange,
+        kAudioObjectPropertyScopeGlobal,
+        kAudioObjectPropertyElementMaster };
+    OSStatus result = AudioObjectGetPropertyData(defaultDevice(), &preferredBufferSizeAddress, 0, 0, &bufferSizeSize, &bufferSize);
+
+    if (result)
+        return 0;
+    return bufferSize;
+}
+
+void AudioSession::setPreferredBufferSize(size_t bufferSize)
+{
+    AudioValueRange bufferSizeRange = {0, 0};
+    UInt32 bufferSizeRangeSize = sizeof(AudioValueRange);
+    AudioObjectPropertyAddress bufferSizeRangeAddress = {
+        kAudioDevicePropertyBufferFrameSizeRange,
+        kAudioObjectPropertyScopeGlobal,
+        kAudioObjectPropertyElementMaster
+    };
+    OSStatus result = AudioObjectGetPropertyData(defaultDevice(), &bufferSizeRangeAddress, 0, 0, &bufferSizeRangeSize, &bufferSizeRange);
+    if (result)
+        return;
+
+    size_t minBufferSize = static_cast<size_t>(bufferSizeRange.mMinimum);
+    size_t maxBufferSize = static_cast<size_t>(bufferSizeRange.mMaximum);
+    UInt32 bufferSizeOut = std::min(maxBufferSize, std::max(minBufferSize, bufferSize));
+
+    AudioObjectPropertyAddress preferredBufferSizeAddress = {
+        kAudioDevicePropertyBufferFrameSize,
+        kAudioObjectPropertyScopeGlobal,
+        kAudioObjectPropertyElementMaster };
+
+    result = AudioObjectSetPropertyData(defaultDevice(), &preferredBufferSizeAddress, 0, 0, sizeof(bufferSizeOut), (void*)&bufferSizeOut);
+
+#if LOG_DISABLED
+    UNUSED_PARAM(result);
+#else
+    if (result)
+        LOG(Media, "AudioSession::setPreferredBufferSize(%zu) - failed with error %d", bufferSize, static_cast<int>(result));
+    else
+        LOG(Media, "AudioSession::setPreferredBufferSize(%zu)", bufferSize);
+#endif
+}
+
+}
+
+#endif // USE(AUDIO_SESSION) && PLATFORM(MAC)
diff --git a/Source/WebCore/platform/audio/mac/AudioSessionManagerMac.cpp b/Source/WebCore/platform/audio/mac/AudioSessionManagerMac.cpp
new file mode 100644 (file)
index 0000000..f1736af
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2013 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 "AudioSessionManager.h"
+
+#if USE(AUDIO_SESSION) && PLATFORM(MAC)
+
+#include "Logging.h"
+
+using namespace WebCore;
+
+static const size_t kWebAudioBufferSize = 128;
+static const size_t kLowPowerVideoBufferSize = 4096;
+
+void AudioSessionManager::updateSessionState()
+{
+    // FIXME: <http://webkit.org/b/116725> Figure out why enabling the code below
+    // causes media LayoutTests to fail on 10.8.
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
+    LOG(Media, "AudioSessionManager::updateSessionState() - types: Video(%d), Audio(%d), WebAudio(%d)", m_typeCount.count(Video), m_typeCount.count(Audio), m_typeCount.count(WebAudio));
+
+    if (has(WebAudio))
+        AudioSession::sharedSession().setPreferredBufferSize(kWebAudioBufferSize);
+    else if (has(Video) || has(Audio))
+        AudioSession::sharedSession().setPreferredBufferSize(kLowPowerVideoBufferSize);
+#endif
+}
+
+#endif // USE(AUDIO_SESSION) && PLATFORM(MAC)