Changeset 150651 in webkit


Ignore:
Timestamp:
May 24, 2013 11:54:23 AM (11 years ago)
Author:
jer.noble@apple.com
Message:

Mac: Set the default audio buffer size to a large value for <video> elements.
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.
Location:
trunk/Source
Files:
1 added
13 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r150621 r150651  
     12013-05-25  Jer Noble  <jer.noble@apple.com>
     2
     3        Mac: Set the default audio buffer size to a large value for <video> elements.
     4        https://bugs.webkit.org/show_bug.cgi?id=116342
     5
     6        Reviewed by Eric Carlson.
     7
     8        * wtf/Platform.h: Add a WTF_USE_AUDIO_SESSION setting.
     9
    1102013-05-23  Brent Fulgham  <bfulgham@apple.com>
    211
  • trunk/Source/WTF/wtf/Platform.h

    r150603 r150651  
    10241024#endif /* #if PLATFORM(MAC) && (PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070) */
    10251025
     1026#if PLATFORM(MAC) || PLATFORM(IOS)
     1027#define WTF_USE_AUDIO_SESSION 1
     1028#endif
     1029
    10261030#endif /* WTF_Platform_h */
  • trunk/Source/WebCore/ChangeLog

    r150646 r150651  
     12013-05-24  Jer Noble  <jer.noble@apple.com>
     2
     3        Mac: Set the default audio buffer size to a large value for <video> elements.
     4        https://bugs.webkit.org/show_bug.cgi?id=116342
     5
     6        Reviewed by Eric Carlson.
     7        Roll-in rubber stamped by Eric Carlson.
     8
     9        To enable power savings by waking up the audio hardware less often, set the
     10        requested buffer frame size to a large value, such as 4096. Since this results
     11        in approximately 100ms worth of buffer, set the buffer size to a much lower
     12        value when playing WebAudio, which is much more sensitive to latency than video
     13        or audio elements.
     14
     15        Introduce a new class, AudioSessionManager, as well as a helper class,
     16        AudioSessionManagerToken. Audio elements, video elements, and WebAudio destination
     17        nodes will create and retain a token, and release the token in their destructor.
     18        This allows the AudioSessionManager to track how many of what type of audio-
     19        generating objects are in existence.
     20
     21        This requires implementing AudioSession for Mac platforms. Move the implementation
     22        for retrieving the hardware sample rate and setting the buffer duration into
     23        AudioSessionMac from AudioDestinationMac, to be shared with AudioSessionManagerMac.
     24
     25        Change the AudioSession method preferredBufferLength() into preferredBufferSize(),
     26        as the callers really want to specify a buffer size, not a buffer duration. On iOS,
     27        where the available API requires a duration, perform the conversion from duration to
     28        size on behalf of the caller.
     29
     30        However, since the original version of this patch caused media test
     31        failures on the Mac ML and Lion bots, only enable the buffer size
     32        change for OS X > ML.
     33
     34        * html/HTMLMediaElement.h:  Add a AudioSessionManagerToken member.
     35        * html/HTMLMediaElement.cpp:
     36        (WebCore::HTMLMediaElement::HTMLMediaElement): Initialize the token.
     37        * platform/audio/AudioSession.cpp:
     38        (WebCore::AudioSession::preferredBufferSize): Renamed from preferredBufferLength.
     39        (WebCore::AudioSession::setPreferredBufferSize): Renamed from setPreferredBufferLength.
     40        * platform/audio/AudioSession.h:
     41        * platform/audio/AudioSessionManager.cpp:
     42        (AudioSessionManagerToken::create): Simple factory method.
     43        (AudioSessionManagerToken::AudioSessionManagerToken): Call AudioSessionManager::incrementCount().
     44        (AudioSessionManagerToken::~AudioSessionManagerToken): Call AudioSessionManager::decrementCount().
     45        (AudioSessionManager::sharedManager): Simple singleton method.
     46        (AudioSessionManager::AudioSessionManager): Simple constructor.
     47        (AudioSessionManager::has): Return whether the type is present.
     48        (AudioSessionManager::incrementCount): Increment, then call updateSessionState()
     49        (AudioSessionManager::decrementCount): Decrement, then call updateSessionState()
     50        (AudioSessionManager::updateSessionState): Stub, does nothing.
     51        * platform/audio/AudioSessionManager.h:
     52        * platform/audio/ios/AudioDestinationIOS.cpp:
     53        (WebCore::AudioDestinationIOS::configure): Call setPreferredBufferSize() instead of setPreferredBufferLength()
     54        * platform/audio/ios/AudioSessionIOS.mm:
     55        (WebCore::AudioSession::preferredBufferSize): Renamed from preferredBufferLength.
     56        (WebCore::AudioSession::setPreferredBufferSize): Renamed from setPreferredBufferLength
     57        * platform/audio/mac/AudioDestinationMac.cpp:
     58        (WebCore::AudioDestination::hardwareSampleRate): Call AudioSession::sampleRate().
     59        (WebCore::AudioDestinationMac::AudioDestinationMac): Create the AudioSessionManagerToken.
     60        (WebCore::AudioDestinationMac::configure): Do not set the buffer size (this is done in AudioSessionManagerMac).
     61        * platform/audio/mac/AudioDestinationMac.h:
     62        * platform/audio/mac/AudioSessionMac.cpp: Added.
     63        (WebCore::defaultDevice): Added, returns the default audio device.
     64        (WebCore::AudioSession::AudioSession): Simple constructor.
     65        (WebCore::AudioSession::~AudioSession): Simple destructor.
     66        (WebCore::AudioSession::category): Stub, unimplemented.
     67        (WebCore::AudioSession::setCategory): Ditto.
     68        (WebCore::AudioSession::categoryOverride): Ditto.
     69        (WebCore::AudioSession::setCategoryOverride): Ditto.
     70        (WebCore::AudioSession::numberOfOutputChannels): Ditto.
     71        (WebCore::AudioSession::setActive): Ditto.
     72        (WebCore::AudioSession::sampleRate): Use the HAL to return the default audio device sample rate.
     73        (WebCore::AudioSession::preferredBufferSize): Return the current HAL setting.
     74        (WebCore::AudioSession::setPreferredBufferSize): Set the buffer size.
     75        * platform/audio/mac/AudioSessionManagerMac.cpp:
     76        (AudioSessionManager::updateSessionState): Set the buffer size depending on what audio outputs are present.
     77        * WebCore.xcodeproj/project.pbxproj: Add the new files to the project.
     78
    1792013-05-24  Alberto Garcia  <agarcia@igalia.com>
    280
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r150561 r150651  
    52085208                CD47B3FC16CC34F800A21EC8 /* CDMPrivateAVFoundation.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD47B3FA16CC34F800A21EC8 /* CDMPrivateAVFoundation.mm */; };
    52095209                CD4AC52A1496AE9A0087C4EF /* Composite.wav in Copy Audio Resources */ = {isa = PBXBuildFile; fileRef = CD4AC5281496AE2F0087C4EF /* Composite.wav */; };
     5210                CD54DE4717468B6F005E5B36 /* AudioSessionManagerMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD54DE4517468B6F005E5B36 /* AudioSessionManagerMac.cpp */; };
     5211                CD54DE4B17469C6D005E5B36 /* AudioSessionMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD54DE4917469C6D005E5B36 /* AudioSessionMac.cpp */; };
    52105212                CD7E05221651C28200C1201F /* WebCoreAVFResourceLoader.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD7E05211651A84100C1201F /* WebCoreAVFResourceLoader.mm */; };
    52115213                CD82030A1395AB6A00F956C6 /* WebVideoFullscreenController.h in Headers */ = {isa = PBXBuildFile; fileRef = CD8203061395AB6A00F956C6 /* WebVideoFullscreenController.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    52285230                CDA98E0E1603FE5800FEA3B1 /* MediaKeySession.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDA98DC716014F2C00FEA3B1 /* MediaKeySession.cpp */; };
    52295231                CDAA8D0A14D71B2E0061EA60 /* PlatformClockCM.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDAA8D0814D385600061EA60 /* PlatformClockCM.mm */; };
     5232                CDAE8C091746B95700532D78 /* AudioSessionManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDAE8C071746B95700532D78 /* AudioSessionManager.cpp */; };
    52305233                CDB859F7160D48A400E5B07F /* MediaKeyEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDB859F4160D489900E5B07F /* MediaKeyEvent.cpp */; };
    52315234                CDB859FA160D494900E5B07F /* JSMediaKeyEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDB859F8160D493E00E5B07F /* JSMediaKeyEvent.cpp */; };
     
    1195711960                CD4AC5281496AE2F0087C4EF /* Composite.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; name = Composite.wav; path = platform/audio/resources/Composite.wav; sourceTree = SOURCE_ROOT; };
    1195811961                CD4E0AFA11F7BC27009D3811 /* fullscreen.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; path = fullscreen.css; sourceTree = "<group>"; };
     11962                CD54DE4517468B6F005E5B36 /* AudioSessionManagerMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AudioSessionManagerMac.cpp; sourceTree = "<group>"; };
     11963                CD54DE4917469C6D005E5B36 /* AudioSessionMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AudioSessionMac.cpp; sourceTree = "<group>"; };
    1195911964                CD7E05201651A84100C1201F /* WebCoreAVFResourceLoader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WebCoreAVFResourceLoader.h; path = objc/WebCoreAVFResourceLoader.h; sourceTree = "<group>"; };
    1196011965                CD7E05211651A84100C1201F /* WebCoreAVFResourceLoader.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = WebCoreAVFResourceLoader.mm; path = objc/WebCoreAVFResourceLoader.mm; sourceTree = "<group>"; };
     
    1199612001                CDAA8D0714D385600061EA60 /* PlatformClockCM.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformClockCM.h; sourceTree = "<group>"; };
    1199712002                CDAA8D0814D385600061EA60 /* PlatformClockCM.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PlatformClockCM.mm; sourceTree = "<group>"; };
     12003                CDAE8C071746B95700532D78 /* AudioSessionManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AudioSessionManager.cpp; sourceTree = "<group>"; };
     12004                CDAE8C081746B95700532D78 /* AudioSessionManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioSessionManager.h; sourceTree = "<group>"; };
    1199812005                CDB859F2160D489900E5B07F /* MediaKeyError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaKeyError.h; sourceTree = "<group>"; };
    1199912006                CDB859F3160D489900E5B07F /* MediaKeyError.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = MediaKeyError.idl; sourceTree = "<group>"; };
     
    2076320770                                CDA79823170A258300D45C55 /* AudioSession.cpp */,
    2076420771                                CDA79822170A24F400D45C55 /* AudioSessionListener.h */,
     20772                                CDAE8C071746B95700532D78 /* AudioSessionManager.cpp */,
     20773                                CDAE8C081746B95700532D78 /* AudioSessionManager.h */,
    2076520774                                FD31605312B026F700C1A359 /* AudioSourceProvider.h */,
    2076620775                                FD62F52D145898D80094B0ED /* AudioSourceProviderClient.h */,
     
    2082920838                                FD3160B912B0272A00C1A359 /* AudioFileReaderMac.h */,
    2083020839                                FD3160BA12B0272A00C1A359 /* FFTFrameMac.cpp */,
     20840                                CD54DE4517468B6F005E5B36 /* AudioSessionManagerMac.cpp */,
     20841                                CD54DE4917469C6D005E5B36 /* AudioSessionMac.cpp */,
    2083120842                        );
    2083220843                        path = mac;
     
    2502725038                                4358E8801360A31700E4748C /* FEDropShadow.cpp in Sources */,
    2502825039                                84730D7E1248F0B300D3A9C9 /* FEFlood.cpp in Sources */,
     25040                                CD54DE4B17469C6D005E5B36 /* AudioSessionMac.cpp in Sources */,
    2502925041                                84801954108BAFB300CB2B1F /* FEGaussianBlur.cpp in Sources */,
    2503025042                                84730D801248F0B300D3A9C9 /* FELighting.cpp in Sources */,
     
    2635826370                                F55B3DCF1251F12D003EF269 /* ResetInputType.cpp in Sources */,
    2635926371                                514BC842161CF05C004D52F4 /* ResourceBuffer.cpp in Sources */,
     26372                                CD54DE4717468B6F005E5B36 /* AudioSessionManagerMac.cpp in Sources */,
    2636026373                                514BC83F161CF04A004D52F4 /* ResourceBuffer.mm in Sources */,
    2636126374                                934F713E0D5A6F2800018D69 /* ResourceErrorBase.cpp in Sources */,
     
    2680026813                                B2C3DA4A0D006C1D00EF6F26 /* TextStream.cpp in Sources */,
    2680126814                                9759E93F14EF1CF80026A2DD /* TextTrack.cpp in Sources */,
     26815                                CDAE8C091746B95700532D78 /* AudioSessionManager.cpp in Sources */,
    2680226816                                9759E94214EF1CF80026A2DD /* TextTrackCue.cpp in Sources */,
    2680326817                                071A9EC2168FBC43002629F9 /* TextTrackCueGeneric.cpp in Sources */,
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r150561 r150651  
    137137#endif
    138138
     139#if USE(AUDIO_SESSION)
     140#include "AudioSessionManager.h"
     141#endif
     142
    139143using namespace std;
    140144
     
    316320#if ENABLE(WEB_AUDIO)
    317321    , m_audioSourceNode(0)
     322#endif
     323#if USE(AUDIO_SESSION)
     324    , m_audioSessionManagerToken(AudioSessionManagerToken::create(tagName == videoTag ? AudioSessionManager::Video : AudioSessionManager::Audio))
    318325#endif
    319326{
  • trunk/Source/WebCore/html/HTMLMediaElement.h

    r150561 r150651  
    5050namespace WebCore {
    5151
     52#if USE(AUDIO_SESSION)
     53class AudioSessionManagerToken;
     54#endif
    5255#if ENABLE(WEB_AUDIO)
    5356class AudioSourceProvider;
     
    766769    RefPtr<PlatformTextTrackMenuInterface> m_platformMenu;
    767770#endif
     771
     772#if USE(AUDIO_SESSION)
     773    OwnPtr<AudioSessionManagerToken> m_audioSessionManagerToken;
     774#endif
    768775};
    769776
  • trunk/Source/WebCore/platform/audio/AudioSession.cpp

    r150561 r150651  
    2626#include "config.h"
    2727#include "AudioSession.h"
     28
     29#if USE(AUDIO_SESSION)
    2830
    2931#include "AudioSessionListener.h"
     
    6062}
    6163
    62 #if !PLATFORM(IOS)
     64#if !PLATFORM(IOS) && !PLATFORM(MAC)
    6365class AudioSessionPrivate {
    6466};
    6567
    6668AudioSession::AudioSession()
    67     : m_private(0)
     69    : m_private(nullptr)
    6870{
    6971    notImplemented();
     
    113115}
    114116
    115 float AudioSession::preferredBufferDuration() const
     117size_t AudioSession::preferredBufferSize() const
    116118{
    117119    notImplemented();
     
    119121}
    120122
    121 void AudioSession::setPreferredBufferDuration(float)
     123void AudioSession::setPreferredBufferSize(size_t)
    122124{
    123125    notImplemented();
     
    126128
    127129}
     130
     131#endif // USE(AUDIO_SESSION)
  • trunk/Source/WebCore/platform/audio/AudioSession.h

    r150561 r150651  
    2626#ifndef AudioSession_h
    2727#define AudioSession_h
     28
     29#if USE(AUDIO_SESSION)
    2830
    2931#include <wtf/HashSet.h>
     
    6365    void setActive(bool);
    6466
    65     float preferredBufferDuration() const;
    66     void setPreferredBufferDuration(float seconds);
     67    size_t preferredBufferSize() const;
     68    void setPreferredBufferSize(size_t);
    6769
    6870    void beganAudioInterruption();
     
    7981}
    8082
     83#endif // USE(AUDIO_SESSION)
     84
    8185#endif // AudioSession_h
  • trunk/Source/WebCore/platform/audio/AudioSessionListener.h

    r150561 r150651  
    2727#define AudioSessionListener_h
    2828
     29#if USE(AUDIO_SESSION)
     30
    2931namespace WebCore {
    3032
    3133class AudioSessionListener {
    32     WTF_MAKE_NONCOPYABLE(AudioSessionListener)
     34    WTF_MAKE_NONCOPYABLE(AudioSessionListener);
    3335public:
    3436    virtual void beganAudioInterruption() = 0;
     
    4143}
    4244
     45#endif // USE(AUDIO_SESSION)
     46
    4347#endif // AudioSessionListener_h
  • trunk/Source/WebCore/platform/audio/AudioSessionManager.cpp

    r150648 r150651  
    2424 */
    2525
    26 #ifndef AudioSession_h
    27 #define AudioSession_h
     26#include "config.h"
     27#include "AudioSessionManager.h"
    2828
    29 #include <wtf/HashSet.h>
    30 #include <wtf/OwnPtr.h>
     29#if USE(AUDIO_SESSION)
    3130
    32 namespace WebCore {
     31using namespace WebCore;
    3332
    34 class AudioSessionListener;
    35 class AudioSessionPrivate;
    36 
    37 class AudioSession {
    38     WTF_MAKE_NONCOPYABLE(AudioSession);
    39 public:
    40     static AudioSession& sharedSession();
    41 
    42     enum CategoryType {
    43         None,
    44         AmbientSound,
    45         SoloAmbientSound,
    46         MediaPlayback,
    47         RecordAudio,
    48         PlayAndRecord,
    49         AudioProcessing,
    50     };
    51     void setCategory(CategoryType);
    52     CategoryType category() const;
    53 
    54     void setCategoryOverride(CategoryType);
    55     CategoryType categoryOverride() const;
    56 
    57     void addListener(AudioSessionListener*);
    58     void removeListener(AudioSessionListener*);
    59 
    60     float sampleRate() const;
    61     size_t numberOfOutputChannels() const;
    62 
    63     void setActive(bool);
    64 
    65     float preferredBufferDuration() const;
    66     void setPreferredBufferDuration(float seconds);
    67 
    68     void beganAudioInterruption();
    69     void endedAudioInterruption();
    70 
    71 private:
    72     AudioSession();
    73     ~AudioSession();
    74 
    75     OwnPtr<AudioSessionPrivate> m_private;
    76     HashSet<AudioSessionListener*> m_listeners;
    77 };
    78 
     33PassOwnPtr<AudioSessionManagerToken> AudioSessionManagerToken::create(AudioSessionManager::AudioType type)
     34{
     35    return adoptPtr(new AudioSessionManagerToken(type));
    7936}
    8037
    81 #endif // AudioSession_h
     38AudioSessionManagerToken::AudioSessionManagerToken(AudioSessionManager::AudioType type)
     39    : m_type(type)
     40{
     41    AudioSessionManager::sharedManager().incrementCount(type);
     42}
     43
     44AudioSessionManagerToken::~AudioSessionManagerToken()
     45{
     46    AudioSessionManager::sharedManager().decrementCount(m_type);
     47}
     48
     49AudioSessionManager& AudioSessionManager::sharedManager()
     50{
     51    DEFINE_STATIC_LOCAL(AudioSessionManager, manager, ());
     52    return manager;
     53}
     54
     55AudioSessionManager::AudioSessionManager()
     56{
     57}
     58
     59bool AudioSessionManager::has(AudioSessionManager::AudioType type)
     60{
     61    ASSERT(type >= 0);
     62    return m_typeCount.contains(type);
     63}
     64
     65void AudioSessionManager::incrementCount(AudioSessionManager::AudioType type)
     66{
     67    ASSERT(type >= 0);
     68    m_typeCount.add(type);
     69    updateSessionState();
     70}
     71
     72void AudioSessionManager::decrementCount(AudioSessionManager::AudioType type)
     73{
     74    ASSERT(type >= 0);
     75    m_typeCount.remove(type);
     76    updateSessionState();
     77}
     78
     79#if !PLATFORM(MAC)
     80void AudioSessionManager::updateSessionState()
     81{
     82}
     83#endif
     84
     85#endif // USE(AUDIO_SESSION)
  • trunk/Source/WebCore/platform/audio/AudioSessionManager.h

    r150648 r150651  
    2424 */
    2525
    26 #ifndef AudioSessionListener_h
    27 #define AudioSessionListener_h
     26#ifndef AudioSessionManager_h
     27#define AudioSessionManager_h
     28
     29#if USE(AUDIO_SESSION)
     30
     31#include "AudioSession.h"
     32#include <wtf/HashCountedSet.h>
     33#include <wtf/PassOwnPtr.h>
    2834
    2935namespace WebCore {
    3036
    31 class AudioSessionListener {
    32     WTF_MAKE_NONCOPYABLE(AudioSessionListener)
     37class AudioSessionManager {
    3338public:
    34     virtual void beganAudioInterruption() = 0;
    35     virtual void endedAudioInterruption() = 0;
     39    static AudioSessionManager& sharedManager();
     40
     41    enum AudioType {
     42        None,
     43        Video,
     44        Audio,
     45        WebAudio,
     46    };
     47
     48    bool has(AudioType);
     49
    3650protected:
    37     AudioSessionListener() { }
    38     virtual ~AudioSessionListener() { }
     51    friend class AudioSessionManagerToken;
     52    void incrementCount(AudioType);
     53    void decrementCount(AudioType);
     54   
     55private:
     56    AudioSessionManager();
     57
     58    void updateSessionState();
     59
     60    HashCountedSet<size_t> m_typeCount;
    3961};
    4062
     63class AudioSessionManagerToken {
     64public:
     65    static PassOwnPtr<AudioSessionManagerToken> create(AudioSessionManager::AudioType);
     66    ~AudioSessionManagerToken();
     67
     68private:
     69    AudioSessionManagerToken(AudioSessionManager::AudioType);
     70
     71    AudioSessionManager::AudioType m_type;
     72};
    4173}
    4274
    43 #endif // AudioSessionListener_h
     75#endif // USE(AUDIO_SESSION)
     76
     77#endif // AudioSessionManager_h
  • trunk/Source/WebCore/platform/audio/ios/AudioDestinationIOS.cpp

    r150561 r150651  
    189189    ASSERT(!result);
    190190
    191     AudioSession::sharedSession().setPreferredBufferDuration(narrowPrecisionToFloat(kPreferredBufferSize / m_sampleRate));
     191    AudioSession::sharedSession().setPreferredBufferSize(kPreferredBufferSize);
    192192}
    193193
  • trunk/Source/WebCore/platform/audio/ios/AudioSessionIOS.mm

    r150561 r150651  
    2727#import "AudioSession.h"
    2828
    29 #if PLATFORM(IOS)
     29#if USE(AUDIO_SESSION) && PLATFORM(IOS)
    3030
    3131#import "SoftLinking.h"
     
    202202}
    203203
    204 float AudioSession::preferredBufferDuration() const
    205 {
    206     return [[AVAudioSession sharedInstance] preferredIOBufferDuration];
    207 }
    208 
    209 void AudioSession::setPreferredBufferDuration(float duration)
     204size_t AudioSession::preferredBufferSize() const
     205{
     206    return [[AVAudioSession sharedInstance] preferredIOBufferDuration] * sampleRate();
     207}
     208
     209void AudioSession::setPreferredBufferSize(size_t bufferSize)
    210210{
    211211    NSError *error = nil;
     212    float duration = bufferSize / sampleRate();
    212213    [[AVAudioSession sharedInstance] setPreferredIOBufferDuration:duration error:&error];
    213214    ASSERT(!error);
     
    216217}
    217218
    218 #endif // PLATFORM(IOS)
     219#endif // USE(AUDIO_SESSION) && PLATFORM(IOS)
  • trunk/Source/WebCore/platform/audio/mac/AudioDestinationMac.cpp

    r150561 r150651  
    3434
    3535#include "AudioIOCallback.h"
     36#include "AudioSessionManager.h"
    3637#include "FloatConversion.h"
    3738#include "Logging.h"
     
    6465{
    6566    // Determine the default output device's sample-rate.
    66     AudioDeviceID deviceID = kAudioDeviceUnknown;
    67     UInt32 infoSize = sizeof(deviceID);
    68 
    69     AudioObjectPropertyAddress defaultOutputDeviceAddress = { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
    70     OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject, &defaultOutputDeviceAddress, 0, 0, &infoSize, (void*)&deviceID);
    71     if (result)
    72         return 0; // error
    73 
    74     Float64 nominalSampleRate;
    75     infoSize = sizeof(Float64);
    76 
    77     AudioObjectPropertyAddress nominalSampleRateAddress = { kAudioDevicePropertyNominalSampleRate, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
    78     result = AudioObjectGetPropertyData(deviceID, &nominalSampleRateAddress, 0, 0, &infoSize, (void*)&nominalSampleRate);
    79     if (result)
    80         return 0; // error
    81 
    82     return narrowPrecisionToFloat(nominalSampleRate);
     67    return AudioSession::sharedSession().sampleRate();
    8368}
    8469
     
    9883    , m_sampleRate(sampleRate)
    9984    , m_isPlaying(false)
     85    , m_audioSessionManagerToken(AudioSessionManagerToken::create(AudioSessionManager::WebAudio))
    10086{
    10187    // Open and initialize DefaultOutputUnit
     
    149135    result = AudioUnitSetProperty(m_outputUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, (void*)&streamFormat, sizeof(AudioStreamBasicDescription));
    150136    ASSERT(!result);
    151 
    152     // Set the buffer frame size.
    153     UInt32 bufferSize = kBufferSize;
    154     result = AudioUnitSetProperty(m_outputUnit, kAudioDevicePropertyBufferFrameSize, kAudioUnitScope_Output, 0, (void*)&bufferSize, sizeof(bufferSize));
    155     ASSERT(!result);
    156137}
    157138
  • trunk/Source/WebCore/platform/audio/mac/AudioDestinationMac.h

    r150561 r150651  
    3333#include "AudioDestination.h"
    3434#include <AudioUnit/AudioUnit.h>
     35#include <wtf/OwnPtr.h>
    3536#include <wtf/RefPtr.h>
    3637
    3738namespace WebCore {
     39
     40class AudioSessionManagerToken;
    3841
    3942// An AudioDestination using CoreAudio's default output AudioUnit
     
    6467    float m_sampleRate;
    6568    bool m_isPlaying;
     69
     70#if USE(AUDIO_SESSION)
     71    OwnPtr<AudioSessionManagerToken> m_audioSessionManagerToken;
     72#endif
    6673};
    6774
  • trunk/Source/WebCore/platform/audio/mac/AudioSessionManagerMac.cpp

    r150648 r150651  
    2424 */
    2525
    26 #ifndef AudioSessionListener_h
    27 #define AudioSessionListener_h
     26#include "config.h"
     27#include "AudioSessionManager.h"
    2828
    29 namespace WebCore {
     29#if USE(AUDIO_SESSION) && PLATFORM(MAC)
    3030
    31 class AudioSessionListener {
    32     WTF_MAKE_NONCOPYABLE(AudioSessionListener)
    33 public:
    34     virtual void beganAudioInterruption() = 0;
    35     virtual void endedAudioInterruption() = 0;
    36 protected:
    37     AudioSessionListener() { }
    38     virtual ~AudioSessionListener() { }
    39 };
     31#include "Logging.h"
    4032
     33using namespace WebCore;
     34
     35static const size_t kWebAudioBufferSize = 128;
     36static const size_t kLowPowerVideoBufferSize = 4096;
     37
     38void AudioSessionManager::updateSessionState()
     39{
     40    // FIXME: <http://webkit.org/b/116725> Figure out why enabling the code below
     41    // causes media LayoutTests to fail on 10.8.
     42#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
     43    LOG(Media, "AudioSessionManager::updateSessionState() - types: Video(%d), Audio(%d), WebAudio(%d)", m_typeCount.count(Video), m_typeCount.count(Audio), m_typeCount.count(WebAudio));
     44
     45    if (has(WebAudio))
     46        AudioSession::sharedSession().setPreferredBufferSize(kWebAudioBufferSize);
     47    else if (has(Video) || has(Audio))
     48        AudioSession::sharedSession().setPreferredBufferSize(kLowPowerVideoBufferSize);
     49#endif
    4150}
    4251
    43 #endif // AudioSessionListener_h
     52#endif // USE(AUDIO_SESSION) && PLATFORM(MAC)
Note: See TracChangeset for help on using the changeset viewer.