| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 } | 58 } |
| 59 | 59 |
| 60 namespace media { | 60 namespace media { |
| 61 class AudioManager; | 61 class AudioManager; |
| 62 class AudioParameters; | 62 class AudioParameters; |
| 63 } | 63 } |
| 64 | 64 |
| 65 namespace content { | 65 namespace content { |
| 66 | 66 |
| 67 class AudioMirroringManager; | 67 class AudioMirroringManager; |
| 68 class AudioStreamRegistry; |
| 68 class MediaStreamManager; | 69 class MediaStreamManager; |
| 69 | 70 |
| 70 class CONTENT_EXPORT AudioRendererHost | 71 class CONTENT_EXPORT AudioRendererHost |
| 71 : public BrowserMessageFilter, | 72 : public BrowserMessageFilter, |
| 72 public AudioOutputDelegate::EventHandler { | 73 public AudioOutputDelegate::EventHandler { |
| 73 public: | 74 public: |
| 74 // Called from UI thread from the owner of this object. | 75 // Called from UI thread from the owner of this object. |
| 75 AudioRendererHost(int render_process_id, | 76 AudioRendererHost(int render_process_id, |
| 77 AudioStreamRegistry* stream_registry, |
| 76 media::AudioManager* audio_manager, | 78 media::AudioManager* audio_manager, |
| 77 AudioMirroringManager* mirroring_manager, | 79 AudioMirroringManager* mirroring_manager, |
| 78 MediaStreamManager* media_stream_manager, | 80 MediaStreamManager* media_stream_manager, |
| 79 const std::string& salt); | 81 const std::string& salt); |
| 80 | 82 |
| 81 // Calls |callback| with the list of AudioOutputControllers for this object. | 83 // Calls |callback| with the list of AudioOutputControllers for this object. |
| 82 void GetOutputControllers( | 84 void GetOutputControllers( |
| 83 const RenderProcessHost::GetAudioOutputControllersCallback& | 85 const RenderProcessHost::GetAudioOutputControllersCallback& |
| 84 callback) const; | 86 callback) const; |
| 85 | 87 |
| 86 // BrowserMessageFilter implementation. | 88 // BrowserMessageFilter implementation. |
| 87 void OnChannelClosing() override; | 89 void OnChannelClosing() override; |
| 88 void OnDestruct() const override; | 90 void OnDestruct() const override; |
| 89 bool OnMessageReceived(const IPC::Message& message) override; | 91 bool OnMessageReceived(const IPC::Message& message) override; |
| 90 | 92 |
| 91 // AudioOutputDelegate::EventHandler implementation | 93 // AudioOutputDelegate::EventHandler implementation |
| 92 void OnStreamCreated(int stream_id, | 94 void OnStreamCreated(int stream_id, |
| 93 base::SharedMemory* shared_memory, | 95 base::SharedMemory* shared_memory, |
| 94 base::CancelableSyncSocket* foreign_socket) override; | 96 base::CancelableSyncSocket* foreign_socket) override; |
| 95 void OnStreamError(int stream_id) override; | 97 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 | 98 |
| 102 void OverrideDevicePermissionsForTesting(bool has_access); | 99 void OverrideDevicePermissionsForTesting(bool has_access); |
| 103 | 100 |
| 104 private: | 101 private: |
| 105 friend class AudioRendererHostTest; | 102 friend class AudioRendererHostTest; |
| 106 friend class BrowserThread; | 103 friend class BrowserThread; |
| 107 friend class base::DeleteHelper<AudioRendererHost>; | 104 friend class base::DeleteHelper<AudioRendererHost>; |
| 108 friend class MockAudioRendererHost; | 105 friend class MockAudioRendererHost; |
| 109 friend class TestAudioRendererHost; | 106 friend class TestAudioRendererHost; |
| 110 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream); | 107 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 167 |
| 171 // Set the volume of the audio stream referenced by |stream_id|. | 168 // Set the volume of the audio stream referenced by |stream_id|. |
| 172 void OnSetVolume(int stream_id, double volume); | 169 void OnSetVolume(int stream_id, double volume); |
| 173 | 170 |
| 174 // Helper methods. | 171 // Helper methods. |
| 175 | 172 |
| 176 // Called after the |render_frame_id| provided to OnCreateStream() was | 173 // Called after the |render_frame_id| provided to OnCreateStream() was |
| 177 // validated. When |is_valid| is false, this calls OnStreamError(). | 174 // validated. When |is_valid| is false, this calls OnStreamError(). |
| 178 void DidValidateRenderFrame(int stream_id, bool is_valid); | 175 void DidValidateRenderFrame(int stream_id, bool is_valid); |
| 179 | 176 |
| 180 // Updates status of stream for AudioStreamMonitor and updates | |
| 181 // the number of playing streams. | |
| 182 void StreamStateChanged(int stream_id, bool is_playing); | |
| 183 | |
| 184 RenderProcessHost::AudioOutputControllerList DoGetOutputControllers() const; | 177 RenderProcessHost::AudioOutputControllerList DoGetOutputControllers() const; |
| 185 | 178 |
| 186 // Send an error message to the renderer. | 179 // Send an error message to the renderer. |
| 187 void SendErrorMessage(int stream_id); | 180 void SendErrorMessage(int stream_id); |
| 188 | 181 |
| 189 // Helper methods to look up a AudioOutputDelegate identified by |stream_id|. | 182 // Helper methods to look up a AudioOutputDelegate identified by |stream_id|. |
| 190 // Returns delegates_.end() if not found. | 183 // Returns delegates_.end() if not found. |
| 191 AudioOutputDelegateVector::iterator LookupIteratorById(int stream_id); | 184 AudioOutputDelegateVector::iterator LookupIteratorById(int stream_id); |
| 192 // Returns nullptr if not found. | 185 // Returns nullptr if not found. |
| 193 AudioOutputDelegate* LookupById(int stream_id); | 186 AudioOutputDelegate* LookupById(int stream_id); |
| 194 | 187 |
| 195 // Helper method to check if the authorization procedure for stream | 188 // Helper method to check if the authorization procedure for stream |
| 196 // |stream_id| has started. | 189 // |stream_id| has started. |
| 197 bool IsAuthorizationStarted(int stream_id); | 190 bool IsAuthorizationStarted(int stream_id); |
| 198 | 191 |
| 199 // Called from AudioRendererHostTest to override the function that checks for | 192 // Called from AudioRendererHostTest to override the function that checks for |
| 200 // the existence of the RenderFrameHost at stream creation time. | 193 // the existence of the RenderFrameHost at stream creation time. |
| 201 void set_render_frame_id_validate_function_for_testing( | 194 void set_render_frame_id_validate_function_for_testing( |
| 202 ValidateRenderFrameIdFunction function) { | 195 ValidateRenderFrameIdFunction function) { |
| 203 validate_render_frame_id_function_ = function; | 196 validate_render_frame_id_function_ = function; |
| 204 } | 197 } |
| 205 | 198 |
| 206 // ID of the RenderProcessHost that owns this instance. | 199 // ID of the RenderProcessHost that owns this instance. |
| 207 const int render_process_id_; | 200 const int render_process_id_; |
| 208 | 201 |
| 202 AudioStreamRegistry* stream_registry_; |
| 209 media::AudioManager* const audio_manager_; | 203 media::AudioManager* const audio_manager_; |
| 210 AudioMirroringManager* const mirroring_manager_; | 204 AudioMirroringManager* const mirroring_manager_; |
| 211 | 205 |
| 212 // Used to access to AudioInputDeviceManager. | 206 // Used to access to AudioInputDeviceManager. |
| 213 MediaStreamManager* media_stream_manager_; | 207 MediaStreamManager* media_stream_manager_; |
| 214 | 208 |
| 215 // A list of the current open streams. | 209 // A list of the current open streams. |
| 216 AudioOutputDelegateVector delegates_; | 210 AudioOutputDelegateVector delegates_; |
| 217 | 211 |
| 218 // The number of streams in the playing state. Atomic read safe from any | |
| 219 // thread, but should only be updated from the IO thread. | |
| 220 base::AtomicRefCount num_playing_streams_; | |
| 221 | |
| 222 // Salt required to translate renderer device IDs to raw device unique IDs | 212 // Salt required to translate renderer device IDs to raw device unique IDs |
| 223 std::string salt_; | 213 std::string salt_; |
| 224 | 214 |
| 225 // Map of device authorizations for streams that are not yet created | 215 // Map of device authorizations for streams that are not yet created |
| 226 // The key is the stream ID, and the value is a pair. The pair's first element | 216 // The key is the stream ID, and the value is a pair. The pair's first element |
| 227 // is a bool that is true if the authorization process completes successfully. | 217 // is a bool that is true if the authorization process completes successfully. |
| 228 // The second element contains the unique ID of the authorized device. | 218 // The second element contains the unique ID of the authorized device. |
| 229 std::map<int, std::pair<bool, std::string>> authorizations_; | 219 std::map<int, std::pair<bool, std::string>> authorizations_; |
| 230 | 220 |
| 231 // At stream creation time, AudioRendererHost will call this function on the | 221 // At stream creation time, AudioRendererHost will call this function on the |
| 232 // UI thread to validate render frame IDs. A default is set by the | 222 // UI thread to validate render frame IDs. A default is set by the |
| 233 // constructor, but this can be overridden by unit tests. | 223 // constructor, but this can be overridden by unit tests. |
| 234 ValidateRenderFrameIdFunction validate_render_frame_id_function_; | 224 ValidateRenderFrameIdFunction validate_render_frame_id_function_; |
| 235 | 225 |
| 236 // The maximum number of simultaneous streams during the lifetime of this | |
| 237 // host. Reported as UMA stat at shutdown. | |
| 238 size_t max_simultaneous_streams_; | |
| 239 | |
| 240 AudioOutputAuthorizationHandler authorization_handler_; | 226 AudioOutputAuthorizationHandler authorization_handler_; |
| 241 | 227 |
| 242 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); | 228 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); |
| 243 }; | 229 }; |
| 244 | 230 |
| 245 } // namespace content | 231 } // namespace content |
| 246 | 232 |
| 247 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ | 233 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ |
| OLD | NEW |