| 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 // |have_access| is true only if there is permission to access the device. | 122 // |have_access| is true only if there is permission to access the device. |
| 123 typedef base::Callback<void(bool have_access)> OutputDeviceAccessCB; | 123 typedef base::Callback<void(bool have_access)> OutputDeviceAccessCB; |
| 124 | 124 |
| 125 // Internal callback type for information requests about an output device. | 125 // Internal callback type for information requests about an output device. |
| 126 // |success| indicates the operation was successful. If true, |device_info| | 126 // |success| indicates the operation was successful. If true, |device_info| |
| 127 // contains data about the device. | 127 // contains data about the device. |
| 128 typedef base::Callback<void(bool success, | 128 typedef base::Callback<void(bool success, |
| 129 const AudioOutputDeviceInfo& device_info)> | 129 const AudioOutputDeviceInfo& device_info)> |
| 130 OutputDeviceInfoCB; | 130 OutputDeviceInfoCB; |
| 131 | 131 |
| 132 // Function that is run on the UI thread to check whether the routing IDs |
| 133 // reference a valid RenderFrameHost. The function then runs |callback| on the |
| 134 // IO thread with true/false if valid/invalid. |
| 135 using ValidateRenderFrameIdFunction = |
| 136 void (*)(int render_process_id, |
| 137 int render_frame_id, |
| 138 const base::Callback<void(bool)>& callback); |
| 139 |
| 132 ~AudioRendererHost() override; | 140 ~AudioRendererHost() override; |
| 133 | 141 |
| 134 // Methods called on IO thread ---------------------------------------------- | 142 // Methods called on IO thread ---------------------------------------------- |
| 135 | 143 |
| 136 // Audio related IPC message handlers. | 144 // Audio related IPC message handlers. |
| 137 | 145 |
| 138 // Request permission to use an output device for use by a stream produced | 146 // Request permission to use an output device for use by a stream produced |
| 139 // in the RenderFrame referenced by |render_frame_id|. | 147 // in the RenderFrame referenced by |render_frame_id|. |
| 140 // |session_id| is used for unified IO to find out which input device to be | 148 // |session_id| is used for unified IO to find out which input device to be |
| 141 // opened for the stream. For clients that do not use unified IO, | 149 // opened for the stream. For clients that do not use unified IO, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 // Proceed with device authorization after translating device ID. | 187 // Proceed with device authorization after translating device ID. |
| 180 void OnDeviceIDTranslated(int stream_id, | 188 void OnDeviceIDTranslated(int stream_id, |
| 181 bool device_found, | 189 bool device_found, |
| 182 const AudioOutputDeviceInfo& device_info); | 190 const AudioOutputDeviceInfo& device_info); |
| 183 | 191 |
| 184 // Start the actual creation of an audio stream, after the device | 192 // Start the actual creation of an audio stream, after the device |
| 185 // authorization process is complete. | 193 // authorization process is complete. |
| 186 void DoCreateStream(int stream_id, | 194 void DoCreateStream(int stream_id, |
| 187 int render_frame_id, | 195 int render_frame_id, |
| 188 const media::AudioParameters& params, | 196 const media::AudioParameters& params, |
| 189 const std::string& device_unique_id); | 197 const std::string& device_unique_id, |
| 198 bool render_frame_is_valid); |
| 190 | 199 |
| 191 // Complete the process of creating an audio stream. This will set up the | 200 // Complete the process of creating an audio stream. This will set up the |
| 192 // shared memory or shared socket in low latency mode and send the | 201 // shared memory or shared socket in low latency mode and send the |
| 193 // NotifyStreamCreated message to the peer. | 202 // NotifyStreamCreated message to the peer. |
| 194 void DoCompleteCreation(int stream_id); | 203 void DoCompleteCreation(int stream_id); |
| 195 | 204 |
| 196 // Send playing/paused status to the renderer. | 205 // Send playing/paused status to the renderer. |
| 197 void DoNotifyStreamStateChanged(int stream_id, bool is_playing); | 206 void DoNotifyStreamStateChanged(int stream_id, bool is_playing); |
| 198 | 207 |
| 199 RenderProcessHost::AudioOutputControllerList DoGetOutputControllers() const; | 208 RenderProcessHost::AudioOutputControllerList DoGetOutputControllers() const; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 230 // Translate the hashed |device_id| to a unique device ID. | 239 // Translate the hashed |device_id| to a unique device ID. |
| 231 void TranslateDeviceID(const std::string& device_id, | 240 void TranslateDeviceID(const std::string& device_id, |
| 232 const url::Origin& security_origin, | 241 const url::Origin& security_origin, |
| 233 const OutputDeviceInfoCB& callback, | 242 const OutputDeviceInfoCB& callback, |
| 234 const AudioOutputDeviceEnumeration& enumeration); | 243 const AudioOutputDeviceEnumeration& enumeration); |
| 235 | 244 |
| 236 // Helper method to check if the authorization procedure for stream | 245 // Helper method to check if the authorization procedure for stream |
| 237 // |stream_id| has started. | 246 // |stream_id| has started. |
| 238 bool IsAuthorizationStarted(int stream_id); | 247 bool IsAuthorizationStarted(int stream_id); |
| 239 | 248 |
| 249 // Called from AudioRendererHostTest to override the function that checks for |
| 250 // the existence of the render frame at stream creation time. |
| 251 void set_render_frame_id_validate_function_for_testing( |
| 252 ValidateRenderFrameIdFunction function) { |
| 253 validate_render_frame_id_function_ = function; |
| 254 } |
| 255 |
| 240 // ID of the RenderProcessHost that owns this instance. | 256 // ID of the RenderProcessHost that owns this instance. |
| 241 const int render_process_id_; | 257 const int render_process_id_; |
| 242 | 258 |
| 243 media::AudioManager* const audio_manager_; | 259 media::AudioManager* const audio_manager_; |
| 244 AudioMirroringManager* const mirroring_manager_; | 260 AudioMirroringManager* const mirroring_manager_; |
| 245 std::unique_ptr<media::AudioLog> audio_log_; | 261 std::unique_ptr<media::AudioLog> audio_log_; |
| 246 | 262 |
| 247 // Used to access to AudioInputDeviceManager. | 263 // Used to access to AudioInputDeviceManager. |
| 248 MediaStreamManager* media_stream_manager_; | 264 MediaStreamManager* media_stream_manager_; |
| 249 | 265 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 260 // Map of device authorizations for streams that are not yet created | 276 // Map of device authorizations for streams that are not yet created |
| 261 // The key is the stream ID, and the value is a pair. The pair's first element | 277 // The key is the stream ID, and the value is a pair. The pair's first element |
| 262 // is a bool that is true if the authorization process completes successfully. | 278 // is a bool that is true if the authorization process completes successfully. |
| 263 // The second element contains the unique ID of the authorized device. | 279 // The second element contains the unique ID of the authorized device. |
| 264 std::map<int, std::pair<bool, std::string>> authorizations_; | 280 std::map<int, std::pair<bool, std::string>> authorizations_; |
| 265 | 281 |
| 266 // The maximum number of simultaneous streams during the lifetime of this | 282 // The maximum number of simultaneous streams during the lifetime of this |
| 267 // host. Reported as UMA stat at shutdown. | 283 // host. Reported as UMA stat at shutdown. |
| 268 size_t max_simultaneous_streams_; | 284 size_t max_simultaneous_streams_; |
| 269 | 285 |
| 286 // Function to use to validate render frame IDs. This is only overridden for |
| 287 // testing. |
| 288 ValidateRenderFrameIdFunction validate_render_frame_id_function_; |
| 289 |
| 270 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); | 290 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); |
| 271 }; | 291 }; |
| 272 | 292 |
| 273 } // namespace content | 293 } // namespace content |
| 274 | 294 |
| 275 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ | 295 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ |
| OLD | NEW |