| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // AudioRendererHost serves audio related requests from AudioRenderer which | 5 // AudioRendererHost serves audio related requests from AudioRenderer which |
| 6 // lives inside the render process and provide access to audio hardware. | 6 // lives inside the render process and provide access to audio hardware. |
| 7 // | 7 // |
| 8 // This class is owned by RenderProcessHostImpl, and instantiated on UI | 8 // This class is owned by RenderProcessHostImpl, and instantiated on UI |
| 9 // thread, but all other operations and method calls happen on IO thread, so we | 9 // thread, but all other operations and method calls happen on IO thread, so we |
| 10 // need to be extra careful about the lifetime of this object. AudioManager is a | 10 // need to be extra careful about the lifetime of this object. AudioManager is a |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 // BrowserMessageFilter implementation. | 86 // BrowserMessageFilter implementation. |
| 87 void OnChannelClosing() override; | 87 void OnChannelClosing() override; |
| 88 void OnDestruct() const override; | 88 void OnDestruct() const override; |
| 89 bool OnMessageReceived(const IPC::Message& message) override; | 89 bool OnMessageReceived(const IPC::Message& message) override; |
| 90 | 90 |
| 91 // AudioOutputDelegate::EventHandler implementation | 91 // AudioOutputDelegate::EventHandler implementation |
| 92 void OnStreamCreated(int stream_id, | 92 void OnStreamCreated(int stream_id, |
| 93 base::SharedMemory* shared_memory, | 93 base::SharedMemory* shared_memory, |
| 94 base::CancelableSyncSocket* foreign_socket) override; | 94 base::CancelableSyncSocket* foreign_socket) override; |
| 95 void OnStreamError(int stream_id) override; | 95 void OnStreamError(int stream_id) override; |
| 96 void OnStreamStateChanged(bool is_playing) override; | |
| 97 | |
| 98 // Returns true if any streams managed by this host are actively playing. Can | |
| 99 // be called from any thread. | |
| 100 bool HasActiveAudio(); | |
| 101 | 96 |
| 102 void OverrideDevicePermissionsForTesting(bool has_access); | 97 void OverrideDevicePermissionsForTesting(bool has_access); |
| 103 | 98 |
| 104 private: | 99 private: |
| 105 friend class AudioRendererHostTest; | 100 friend class AudioRendererHostTest; |
| 106 friend class BrowserThread; | 101 friend class BrowserThread; |
| 107 friend class base::DeleteHelper<AudioRendererHost>; | 102 friend class base::DeleteHelper<AudioRendererHost>; |
| 108 friend class MockAudioRendererHost; | 103 friend class MockAudioRendererHost; |
| 109 friend class TestAudioRendererHost; | 104 friend class TestAudioRendererHost; |
| 110 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream); | 105 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 | 204 |
| 210 media::AudioManager* const audio_manager_; | 205 media::AudioManager* const audio_manager_; |
| 211 AudioMirroringManager* const mirroring_manager_; | 206 AudioMirroringManager* const mirroring_manager_; |
| 212 | 207 |
| 213 // Used to access to AudioInputDeviceManager. | 208 // Used to access to AudioInputDeviceManager. |
| 214 MediaStreamManager* media_stream_manager_; | 209 MediaStreamManager* media_stream_manager_; |
| 215 | 210 |
| 216 // A list of the current open streams. | 211 // A list of the current open streams. |
| 217 AudioOutputDelegateVector delegates_; | 212 AudioOutputDelegateVector delegates_; |
| 218 | 213 |
| 219 // The number of streams in the playing state. Atomic read safe from any | |
| 220 // thread, but should only be updated from the IO thread. | |
| 221 base::AtomicRefCount num_playing_streams_; | |
| 222 | |
| 223 // Salt required to translate renderer device IDs to raw device unique IDs | 214 // Salt required to translate renderer device IDs to raw device unique IDs |
| 224 std::string salt_; | 215 std::string salt_; |
| 225 | 216 |
| 226 // Map of device authorizations for streams that are not yet created | 217 // Map of device authorizations for streams that are not yet created |
| 227 // The key is the stream ID, and the value is a pair. The pair's first element | 218 // The key is the stream ID, and the value is a pair. The pair's first element |
| 228 // is a bool that is true if the authorization process completes successfully. | 219 // is a bool that is true if the authorization process completes successfully. |
| 229 // The second element contains the unique ID of the authorized device. | 220 // The second element contains the unique ID of the authorized device. |
| 230 std::map<int, std::pair<bool, std::string>> authorizations_; | 221 std::map<int, std::pair<bool, std::string>> authorizations_; |
| 231 | 222 |
| 232 // At stream creation time, AudioRendererHost will call this function on the | 223 // At stream creation time, AudioRendererHost will call this function on the |
| 233 // UI thread to validate render frame IDs. A default is set by the | 224 // UI thread to validate render frame IDs. A default is set by the |
| 234 // constructor, but this can be overridden by unit tests. | 225 // constructor, but this can be overridden by unit tests. |
| 235 ValidateRenderFrameIdFunction validate_render_frame_id_function_; | 226 ValidateRenderFrameIdFunction validate_render_frame_id_function_; |
| 236 | 227 |
| 237 // The maximum number of simultaneous streams during the lifetime of this | |
| 238 // host. Reported as UMA stat at shutdown. | |
| 239 size_t max_simultaneous_streams_; | |
| 240 | |
| 241 AudioOutputAuthorizationHandler authorization_handler_; | 228 AudioOutputAuthorizationHandler authorization_handler_; |
| 242 | 229 |
| 243 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); | 230 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); |
| 244 }; | 231 }; |
| 245 | 232 |
| 246 } // namespace content | 233 } // namespace content |
| 247 | 234 |
| 248 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ | 235 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ |
| OLD | NEW |