AudioSessionManager should be MediaSessionManager
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Dec 2013 18:24:06 +0000 (18:24 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Dec 2013 18:24:06 +0000 (18:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=126087

Reviewed by Jer Noble.

No new tests, no change in functionality.

* WebCore.xcodeproj/project.pbxproj: Change file names.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::HTMLMediaElement): MediaSessionManagerToken::create() takes a client
    interface instead of the media type.
* html/HTMLMediaElement.h:

* platform/audio/AudioSessionListener.h: Include <wtf/Noncopyable.h>.

AudioSessionManager.* -> MediaSessionManager.*
* platform/audio/AudioSessionManager.cpp: Removed.
* platform/audio/AudioSessionManager.h: Removed.
* platform/audio/MediaSessionManager.cpp: Copied from Source/WebCore/platform/audio/AudioSessionManager.cpp.
(MediaSessionManagerToken::create):
(MediaSessionManagerToken::MediaSessionManagerToken):
(MediaSessionManagerToken::~MediaSessionManagerToken):
(MediaSessionManager::sharedManager):
(MediaSessionManager::MediaSessionManager):
(MediaSessionManager::has):
(MediaSessionManager::count):
(MediaSessionManager::addToken):
(MediaSessionManager::removeToken):
(MediaSessionManager::updateSessionState):
* platform/audio/MediaSessionManager.h: Copied from Source/WebCore/platform/audio/AudioSessionManager.h.

* platform/audio/mac/AudioDestinationMac.cpp:
(WebCore::AudioDestinationMac::AudioDestinationMac): MediaSessionManagerToken::create() takes a
    client interface instead of the media type.
* platform/audio/mac/AudioDestinationMac.h:

* platform/audio/mac/AudioSessionMac.cpp:
* platform/audio/mac/AudioSessionManagerMac.cpp: Removed.
* platform/audio/mac/MediaSessionManagerMac.cpp: Copied from Source/WebCore/platform/audio/mac/AudioSessionManagerMac.cpp.
(MediaSessionManager::updateSessionState):

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

Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/platform/audio/AudioSessionListener.h
Source/WebCore/platform/audio/AudioSessionManager.cpp [deleted file]
Source/WebCore/platform/audio/MediaSessionManager.cpp [new file with mode: 0644]
Source/WebCore/platform/audio/MediaSessionManager.h [moved from Source/WebCore/platform/audio/AudioSessionManager.h with 57% similarity]
Source/WebCore/platform/audio/mac/AudioDestinationMac.cpp
Source/WebCore/platform/audio/mac/AudioDestinationMac.h
Source/WebCore/platform/audio/mac/MediaSessionManagerMac.cpp [moved from Source/WebCore/platform/audio/mac/AudioSessionManagerMac.cpp with 89% similarity]

index 7eeb792..76fe5c0 100644 (file)
@@ -1,3 +1,47 @@
+2013-12-23  Eric Carlson  <eric.carlson@apple.com>
+
+        AudioSessionManager should be MediaSessionManager
+        https://bugs.webkit.org/show_bug.cgi?id=126087
+
+        Reviewed by Jer Noble.
+
+        No new tests, no change in functionality.
+
+        * WebCore.xcodeproj/project.pbxproj: Change file names.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::HTMLMediaElement): MediaSessionManagerToken::create() takes a client
+            interface instead of the media type.
+        * html/HTMLMediaElement.h:
+
+        * platform/audio/AudioSessionListener.h: Include <wtf/Noncopyable.h>.
+        
+        AudioSessionManager.* -> MediaSessionManager.*
+        * platform/audio/AudioSessionManager.cpp: Removed.
+        * platform/audio/AudioSessionManager.h: Removed.
+        * platform/audio/MediaSessionManager.cpp: Copied from Source/WebCore/platform/audio/AudioSessionManager.cpp.
+        (MediaSessionManagerToken::create):
+        (MediaSessionManagerToken::MediaSessionManagerToken):
+        (MediaSessionManagerToken::~MediaSessionManagerToken):
+        (MediaSessionManager::sharedManager):
+        (MediaSessionManager::MediaSessionManager):
+        (MediaSessionManager::has):
+        (MediaSessionManager::count):
+        (MediaSessionManager::addToken):
+        (MediaSessionManager::removeToken):
+        (MediaSessionManager::updateSessionState):
+        * platform/audio/MediaSessionManager.h: Copied from Source/WebCore/platform/audio/AudioSessionManager.h.
+
+        * platform/audio/mac/AudioDestinationMac.cpp:
+        (WebCore::AudioDestinationMac::AudioDestinationMac): MediaSessionManagerToken::create() takes a
+            client interface instead of the media type.
+        * platform/audio/mac/AudioDestinationMac.h:
+
+        * platform/audio/mac/AudioSessionMac.cpp:
+        * platform/audio/mac/AudioSessionManagerMac.cpp: Removed.
+        * platform/audio/mac/MediaSessionManagerMac.cpp: Copied from Source/WebCore/platform/audio/mac/AudioSessionManagerMac.cpp.
+        (MediaSessionManager::updateSessionState):
+
 2013-12-23  Zan Dobersek  <zdobersek@igalia.com>
 
         webkit gtk 2.2.3 stable tarball compilation error
index b6e2ca9..fe10f31 100644 (file)
                07DC5FD417D3EEE90099F890 /* JSRTCStatsResponseCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 07DC5FD317D3EEE90099F890 /* JSRTCStatsResponseCustom.cpp */; };
                07E116B11489C9A100EC5ACE /* JSTextTrackCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 07E116B01489C9A100EC5ACE /* JSTextTrackCustom.cpp */; };
                07E117071489EBEB00EC5ACE /* JSTextTrackCueCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 07E117061489EBEB00EC5ACE /* JSTextTrackCueCustom.cpp */; };
+               07F944161864D046005D31CB /* MediaSessionManager.h in Headers */ = {isa = PBXBuildFile; fileRef = CDAE8C081746B95700532D78 /* MediaSessionManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
                07FFDE68181AED420072D409 /* MediaStreamTrackPrivate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 07FFDE66181AED420072D409 /* MediaStreamTrackPrivate.cpp */; };
                07FFDE69181AED420072D409 /* MediaStreamTrackPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 07FFDE67181AED420072D409 /* MediaStreamTrackPrivate.h */; };
                0806E57A12893045007CED32 /* SVGMatrix.h in Headers */ = {isa = PBXBuildFile; fileRef = 0806E57912893045007CED32 /* SVGMatrix.h */; settings = {ATTRIBUTES = (Private, ); }; };
                CD5393D4175E018600C07123 /* JSMemoryInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = CD5393D2175E018600C07123 /* JSMemoryInfo.h */; };
                CD54A762180F9F7000B076C9 /* AudioTrackPrivateMediaSourceAVFObjC.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD54A760180F9F7000B076C9 /* AudioTrackPrivateMediaSourceAVFObjC.cpp */; };
                CD54A763180F9F7000B076C9 /* AudioTrackPrivateMediaSourceAVFObjC.h in Headers */ = {isa = PBXBuildFile; fileRef = CD54A761180F9F7000B076C9 /* AudioTrackPrivateMediaSourceAVFObjC.h */; };
-               CD54DE4717468B6F005E5B36 /* AudioSessionManagerMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD54DE4517468B6F005E5B36 /* AudioSessionManagerMac.cpp */; };
+               CD54DE4717468B6F005E5B36 /* MediaSessionManagerMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD54DE4517468B6F005E5B36 /* MediaSessionManagerMac.cpp */; };
                CD54DE4B17469C6D005E5B36 /* AudioSessionMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD54DE4917469C6D005E5B36 /* AudioSessionMac.cpp */; };
                CD61FE671794AADB004101EB /* MediaSourceRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B1A942E115B5CE2200D525D1 /* MediaSourceRegistry.cpp */; };
                CD61FE681794AADB004101EB /* MediaSourceRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = B1A942E215B5CE2200D525D1 /* MediaSourceRegistry.h */; };
                CDAB6D2E17C814EE00C60B34 /* JSMediaControlsHost.h in Headers */ = {isa = PBXBuildFile; fileRef = CDAB6D2C17C814EE00C60B34 /* JSMediaControlsHost.h */; };
                CDAB6D3117C9259500C60B34 /* UserAgentScripts.h in Headers */ = {isa = PBXBuildFile; fileRef = CDAB6D2F17C9259500C60B34 /* UserAgentScripts.h */; };
                CDAB6D3217C9259500C60B34 /* UserAgentScriptsData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDAB6D3017C9259500C60B34 /* UserAgentScriptsData.cpp */; };
-               CDAE8C091746B95700532D78 /* AudioSessionManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDAE8C071746B95700532D78 /* AudioSessionManager.cpp */; };
+               CDAE8C091746B95700532D78 /* MediaSessionManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDAE8C071746B95700532D78 /* MediaSessionManager.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 */; };
                CD54A75E180F535000B076C9 /* MediaSourcePrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaSourcePrivate.h; sourceTree = "<group>"; };
                CD54A760180F9F7000B076C9 /* AudioTrackPrivateMediaSourceAVFObjC.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AudioTrackPrivateMediaSourceAVFObjC.cpp; path = objc/AudioTrackPrivateMediaSourceAVFObjC.cpp; sourceTree = "<group>"; };
                CD54A761180F9F7000B076C9 /* AudioTrackPrivateMediaSourceAVFObjC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AudioTrackPrivateMediaSourceAVFObjC.h; path = objc/AudioTrackPrivateMediaSourceAVFObjC.h; sourceTree = "<group>"; };
-               CD54DE4517468B6F005E5B36 /* AudioSessionManagerMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AudioSessionManagerMac.cpp; sourceTree = "<group>"; };
+               CD54DE4517468B6F005E5B36 /* MediaSessionManagerMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaSessionManagerMac.cpp; sourceTree = "<group>"; };
                CD54DE4917469C6D005E5B36 /* AudioSessionMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AudioSessionMac.cpp; sourceTree = "<group>"; };
                CD641EB11818F5ED00EE4C41 /* MediaSourcePrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaSourcePrivate.h; sourceTree = "<group>"; };
                CD641EB21818F5ED00EE4C41 /* SourceBufferPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SourceBufferPrivate.h; sourceTree = "<group>"; };
                CDAB6D2C17C814EE00C60B34 /* JSMediaControlsHost.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSMediaControlsHost.h; sourceTree = "<group>"; };
                CDAB6D2F17C9259500C60B34 /* UserAgentScripts.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserAgentScripts.h; sourceTree = "<group>"; };
                CDAB6D3017C9259500C60B34 /* UserAgentScriptsData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UserAgentScriptsData.cpp; 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>"; };
+               CDAE8C071746B95700532D78 /* MediaSessionManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaSessionManager.cpp; sourceTree = "<group>"; };
+               CDAE8C081746B95700532D78 /* MediaSessionManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaSessionManager.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>"; };
                                CDA79823170A258300D45C55 /* AudioSession.cpp */,
                                CDA79821170A22DC00D45C55 /* AudioSession.h */,
                                CDA79822170A24F400D45C55 /* AudioSessionListener.h */,
-                               CDAE8C071746B95700532D78 /* AudioSessionManager.cpp */,
-                               CDAE8C081746B95700532D78 /* AudioSessionManager.h */,
+                               CDAE8C071746B95700532D78 /* MediaSessionManager.cpp */,
+                               CDAE8C081746B95700532D78 /* MediaSessionManager.h */,
                                FD31605312B026F700C1A359 /* AudioSourceProvider.h */,
                                FD62F52D145898D80094B0ED /* AudioSourceProviderClient.h */,
                                FD31605412B026F700C1A359 /* AudioUtilities.cpp */,
                                FD3160B812B0272A00C1A359 /* AudioFileReaderMac.cpp */,
                                FD3160B912B0272A00C1A359 /* AudioFileReaderMac.h */,
                                CD54DE4917469C6D005E5B36 /* AudioSessionMac.cpp */,
-                               CD54DE4517468B6F005E5B36 /* AudioSessionManagerMac.cpp */,
+                               CD54DE4517468B6F005E5B36 /* MediaSessionManagerMac.cpp */,
                                FD3160BA12B0272A00C1A359 /* FFTFrameMac.cpp */,
                        );
                        path = mac;
                                B2FA3D4F0AB75A6F000E5AC4 /* JSSVGAnimatedString.h in Headers */,
                                B2FA3D510AB75A6F000E5AC4 /* JSSVGAnimatedTransformList.h in Headers */,
                                076306E117E16089005A7C4E /* JSSourceInfo.h in Headers */,
+                               07F944161864D046005D31CB /* MediaSessionManager.h in Headers */,
                                B2FA3D530AB75A6F000E5AC4 /* JSSVGAnimateElement.h in Headers */,
                                4496E39E1398136C003EE32A /* JSSVGAnimateMotionElement.h in Headers */,
                                B2FA3D550AB75A6F000E5AC4 /* JSSVGAnimateTransformElement.h in Headers */,
                                CDA79824170A258300D45C55 /* AudioSession.cpp in Sources */,
                                CDA79827170A279100D45C55 /* AudioSessionIOS.mm in Sources */,
                                CD54DE4B17469C6D005E5B36 /* AudioSessionMac.cpp in Sources */,
-                               CDAE8C091746B95700532D78 /* AudioSessionManager.cpp in Sources */,
-                               CD54DE4717468B6F005E5B36 /* AudioSessionManagerMac.cpp in Sources */,
+                               CDAE8C091746B95700532D78 /* MediaSessionManager.cpp in Sources */,
+                               CD54DE4717468B6F005E5B36 /* MediaSessionManagerMac.cpp in Sources */,
                                FDB052DF1561A42C00B500D6 /* AudioSummingJunction.cpp in Sources */,
                                BE88E0D81715D2A200658D98 /* AudioTrack.cpp in Sources */,
                                BE88E0DB1715D2A200658D98 /* AudioTrackList.cpp in Sources */,
index 7ab0fc2..3aa295a 100644 (file)
 #endif
 
 #if USE(AUDIO_SESSION)
-#include "AudioSessionManager.h"
+#include "MediaSessionManager.h"
 #endif
 
 #if ENABLE(MEDIA_CONTROLS_SCRIPT)
@@ -342,7 +342,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document& docum
     , m_audioSourceNode(0)
 #endif
 #if USE(AUDIO_SESSION)
-    , m_audioSessionManagerToken(AudioSessionManagerToken::create(tagName == videoTag ? AudioSessionManager::Video : AudioSessionManager::Audio))
+    , m_mediaSessionManagerToken(MediaSessionManagerToken::create(*this))
 #endif
     , m_reportedExtraMemoryCost(0)
 #if ENABLE(MEDIA_STREAM)
@@ -5703,6 +5703,16 @@ unsigned long long HTMLMediaElement::fileSize() const
     return 0;
 }
 
+#if USE(AUDIO_SESSION)
+MediaSessionManager::MediaType HTMLMediaElement::mediaType() const
+{
+    if (hasTagName(HTMLNames::videoTag))
+        return MediaSessionManager::Video;
+
+    return MediaSessionManager::Audio;
+}
+#endif
+
 }
 
 #endif
index c9ba219..095c4b7 100644 (file)
 #include "MediaStream.h"
 #endif
 
-namespace WebCore {
-
 #if USE(AUDIO_SESSION)
-class AudioSessionManagerToken;
+#include "MediaSessionManager.h"
 #endif
+
+namespace WebCore {
+
 #if ENABLE(WEB_AUDIO)
 class AudioSourceProvider;
 class MediaElementAudioSourceNode;
@@ -113,6 +114,9 @@ class HTMLMediaElement
 #if USE(PLATFORM_TEXT_TRACK_MENU)
     , public PlatformTextTrackMenuClient
 #endif
+#if USE(AUDIO_SESSION)
+    , public MediaSessionManagerClient
+#endif
 {
 public:
     MediaPlayer* player() const { return m_player.get(); }
@@ -691,6 +695,10 @@ private:
     bool ensureMediaControlsInjectedScript();
 #endif
 
+#if USE(AUDIO_SESSION)
+    virtual MediaSessionManager::MediaType mediaType() const OVERRIDE;
+#endif
+
     Timer<HTMLMediaElement> m_loadTimer;
     Timer<HTMLMediaElement> m_progressEventTimer;
     Timer<HTMLMediaElement> m_playbackProgressTimer;
@@ -846,7 +854,7 @@ private:
 #endif
 
 #if USE(AUDIO_SESSION)
-    OwnPtr<AudioSessionManagerToken> m_audioSessionManagerToken;
+    std::unique_ptr<MediaSessionManagerToken> m_mediaSessionManagerToken;
 #endif
 
     std::unique_ptr<PageActivityAssertionToken> m_activityToken;
index d8b82e7..f25551a 100644 (file)
@@ -28,6 +28,8 @@
 
 #if USE(AUDIO_SESSION)
 
+#include <wtf/Noncopyable.h>
+
 namespace WebCore {
 
 class AudioSessionListener {
diff --git a/Source/WebCore/platform/audio/AudioSessionManager.cpp b/Source/WebCore/platform/audio/AudioSessionManager.cpp
deleted file mode 100644 (file)
index 12a1b95..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * 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/MediaSessionManager.cpp b/Source/WebCore/platform/audio/MediaSessionManager.cpp
new file mode 100644 (file)
index 0000000..d2f6a15
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * 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 "MediaSessionManager.h"
+
+using namespace WebCore;
+
+
+std::unique_ptr<MediaSessionManagerToken> MediaSessionManagerToken::create(MediaSessionManagerClient& client)
+{
+    return std::make_unique<MediaSessionManagerToken>(client);
+}
+
+MediaSessionManagerToken::MediaSessionManagerToken(MediaSessionManagerClient& client)
+    : m_client(client)
+{
+    m_type = m_client.mediaType();
+    MediaSessionManager::sharedManager().addToken(*this);
+}
+
+MediaSessionManagerToken::~MediaSessionManagerToken()
+{
+    MediaSessionManager::sharedManager().removeToken(*this);
+}
+
+MediaSessionManager& MediaSessionManager::sharedManager()
+{
+    DEFINE_STATIC_LOCAL(MediaSessionManager, manager, ());
+    return manager;
+}
+
+MediaSessionManager::MediaSessionManager()
+{
+}
+
+bool MediaSessionManager::has(MediaSessionManager::MediaType type) const
+{
+    ASSERT(type >= MediaSessionManager::None && type <= MediaSessionManager::WebAudio);
+
+    for (auto it = m_tokens.begin(), end = m_tokens.end(); it != end; ++it) {
+        if ((*it)->mediaType() == type)
+            return true;
+    }
+    
+    return false;
+}
+
+int MediaSessionManager::count(MediaSessionManager::MediaType type) const
+{
+    ASSERT(type >= MediaSessionManager::None && type <= MediaSessionManager::WebAudio);
+    
+    int count = 0;
+    for (auto it = m_tokens.begin(), end = m_tokens.end(); it != end; ++it) {
+        if ((*it)->mediaType() == type)
+            ++count;
+    }
+    
+    return count;
+}
+
+void MediaSessionManager::addToken(MediaSessionManagerToken& token)
+{
+    m_tokens.append(&token);
+    updateSessionState();
+}
+
+void MediaSessionManager::removeToken(MediaSessionManagerToken& token)
+{
+    size_t index = m_tokens.find(&token);
+    ASSERT(index != notFound);
+    if (index == notFound)
+        return;
+
+    m_tokens.remove(index);
+    updateSessionState();
+}
+
+#if !PLATFORM(MAC)
+void MediaSessionManager::updateSessionState()
+{
+}
+#endif
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef AudioSessionManager_h
-#define AudioSessionManager_h
+#ifndef MediaSessionManager_h
+#define MediaSessionManager_h
 
-#if USE(AUDIO_SESSION)
-
-#include "AudioSession.h"
-#include <wtf/HashCountedSet.h>
 #include <wtf/PassOwnPtr.h>
+#include <wtf/Vector.h>
 
 namespace WebCore {
 
-class AudioSessionManager {
+class MediaSessionManagerToken;
+
+class MediaSessionManager {
 public:
-    static AudioSessionManager& sharedManager();
+    static MediaSessionManager& sharedManager();
 
-    enum AudioType {
+    enum MediaType {
         None,
         Video,
         Audio,
         WebAudio,
     };
 
-    bool has(AudioType);
+    bool has(MediaType) const;
+    int count(MediaType) const;
 
 protected:
-    friend class AudioSessionManagerToken;
-    void incrementCount(AudioType);
-    void decrementCount(AudioType);
-    
+    friend class MediaSessionManagerToken;
+    void addToken(MediaSessionManagerToken&);
+    void removeToken(MediaSessionManagerToken&);
+
 private:
-    AudioSessionManager();
+    MediaSessionManager();
 
     void updateSessionState();
 
-    HashCountedSet<size_t> m_typeCount;
+    Vector<MediaSessionManagerToken*> m_tokens;
 };
 
-class AudioSessionManagerToken {
+class MediaSessionManagerClient {
+    WTF_MAKE_NONCOPYABLE(MediaSessionManagerClient);
 public:
-    static PassOwnPtr<AudioSessionManagerToken> create(AudioSessionManager::AudioType);
-    ~AudioSessionManagerToken();
+    MediaSessionManagerClient() { }
+
+    virtual MediaSessionManager::MediaType mediaType() const = 0;
+
+protected:
+    virtual ~MediaSessionManagerClient() { }
+};
+
+class MediaSessionManagerToken {
+public:
+    static std::unique_ptr<MediaSessionManagerToken> create(MediaSessionManagerClient&);
+
+    MediaSessionManagerToken(MediaSessionManagerClient&);
+    ~MediaSessionManagerToken();
+
+    MediaSessionManager::MediaType mediaType() const { return m_type; }
 
 private:
-    AudioSessionManagerToken(AudioSessionManager::AudioType);
 
-    AudioSessionManager::AudioType m_type;
+    MediaSessionManagerClient& m_client;
+    MediaSessionManager::MediaType m_type;
 };
-}
 
-#endif // USE(AUDIO_SESSION)
+}
 
-#endif // AudioSessionManager_h
+#endif // MediaSessionManager_h
index ae4b33b..f651339 100644 (file)
 #include "AudioDestinationMac.h"
 
 #include "AudioIOCallback.h"
-#include "AudioSessionManager.h"
+#include "AudioSession.h"
 #include "FloatConversion.h"
 #include "Logging.h"
+#include "MediaSessionManager.h"
 #include "VectorMath.h"
 #include <CoreAudio/AudioHardware.h>
 
@@ -82,7 +83,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))
+    , m_mediaSessionManagerToken(MediaSessionManagerToken::create(*this))
 {
     // Open and initialize DefaultOutputUnit
     AudioComponent comp;
index 485e2fe..4b028ae 100644 (file)
 
 #include "AudioBus.h"
 #include "AudioDestination.h"
+#include "MediaSessionManager.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 {
+class AudioDestinationMac : public AudioDestination, public MediaSessionManagerClient {
 public:
     AudioDestinationMac(AudioIOCallback&, float sampleRate);
     virtual ~AudioDestinationMac();
@@ -60,6 +59,8 @@ private:
 
     OSStatus render(UInt32 numberOfFrames, AudioBufferList* ioData);
 
+    virtual MediaSessionManager::MediaType mediaType() const { return MediaSessionManager::WebAudio; }
+
     AudioUnit m_outputUnit;
     AudioIOCallback& m_callback;
     RefPtr<AudioBus> m_renderBus;
@@ -68,7 +69,7 @@ private:
     bool m_isPlaying;
 
 #if USE(AUDIO_SESSION)
-    OwnPtr<AudioSessionManagerToken> m_audioSessionManagerToken;
+    std::unique_ptr<MediaSessionManagerToken> m_mediaSessionManagerToken;
 #endif
 };
 
  */
 
 #include "config.h"
-#include "AudioSessionManager.h"
+#include "MediaSessionManager.h"
 
 #if USE(AUDIO_SESSION) && PLATFORM(MAC)
 
+#include "AudioSession.h"
 #include "Logging.h"
 #include "Settings.h"
 
@@ -39,9 +40,9 @@ static const size_t kWebAudioBufferSize = 128;
 static const size_t kLowPowerVideoBufferSize = 4096;
 #endif
 
-void AudioSessionManager::updateSessionState()
+void MediaSessionManager::updateSessionState()
 {
-    LOG(Media, "AudioSessionManager::updateSessionState() - types: Video(%d), Audio(%d), WebAudio(%d)", m_typeCount.count(Video), m_typeCount.count(Audio), m_typeCount.count(WebAudio));
+    LOG(Media, "MediaSessionManager::updateSessionState() - types: Video(%d), Audio(%d), WebAudio(%d)", count(Video), count(Audio), count(WebAudio));
 
     if (has(WebAudio))
         AudioSession::sharedSession().setPreferredBufferSize(kWebAudioBufferSize);