Chromium Code Reviews| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 #include <string> | 47 #include <string> |
| 48 #include <utility> | 48 #include <utility> |
| 49 | 49 |
| 50 #include "base/atomic_ref_count.h" | 50 #include "base/atomic_ref_count.h" |
| 51 #include "base/gtest_prod_util.h" | 51 #include "base/gtest_prod_util.h" |
| 52 #include "base/logging.h" | 52 #include "base/logging.h" |
| 53 #include "base/macros.h" | 53 #include "base/macros.h" |
| 54 #include "base/memory/ref_counted.h" | 54 #include "base/memory/ref_counted.h" |
| 55 #include "base/process/process.h" | 55 #include "base/process/process.h" |
| 56 #include "base/sequenced_task_runner_helpers.h" | 56 #include "base/sequenced_task_runner_helpers.h" |
| 57 #include "content/browser/renderer_host/media/audio_output_authorization_handler .h" | |
| 57 #include "content/browser/renderer_host/media/media_devices_manager.h" | 58 #include "content/browser/renderer_host/media/media_devices_manager.h" |
| 58 #include "content/common/content_export.h" | 59 #include "content/common/content_export.h" |
| 59 #include "content/public/browser/browser_message_filter.h" | 60 #include "content/public/browser/browser_message_filter.h" |
| 60 #include "content/public/browser/browser_thread.h" | 61 #include "content/public/browser/browser_thread.h" |
| 61 #include "content/public/browser/render_process_host.h" | 62 #include "content/public/browser/render_process_host.h" |
| 62 #include "content/public/browser/resource_context.h" | 63 #include "content/public/browser/resource_context.h" |
| 63 #include "media/audio/audio_io.h" | 64 #include "media/audio/audio_io.h" |
| 64 #include "media/audio/audio_logging.h" | 65 #include "media/audio/audio_logging.h" |
| 65 #include "media/audio/audio_output_controller.h" | 66 #include "media/audio/audio_output_controller.h" |
| 66 #include "media/audio/simple_sources.h" | 67 #include "media/audio/simple_sources.h" |
| 68 #include "media/base/output_device_info.h" | |
| 67 #include "url/origin.h" | 69 #include "url/origin.h" |
| 68 | 70 |
| 69 namespace media { | 71 namespace media { |
| 70 class AudioManager; | 72 class AudioManager; |
| 71 class AudioParameters; | 73 class AudioParameters; |
| 72 } | 74 } |
| 73 | 75 |
| 74 namespace content { | 76 namespace content { |
| 75 | 77 |
| 76 class AudioMirroringManager; | 78 class AudioMirroringManager; |
| 77 class MediaInternals; | 79 class MediaInternals; |
| 78 class MediaStreamManager; | 80 class MediaStreamManager; |
| 79 class MediaStreamUIProxy; | |
| 80 class ResourceContext; | |
| 81 | 81 |
| 82 class CONTENT_EXPORT AudioRendererHost : public BrowserMessageFilter { | 82 class CONTENT_EXPORT AudioRendererHost : public BrowserMessageFilter { |
| 83 public: | 83 public: |
| 84 // Called from UI thread from the owner of this object. | 84 // Called from UI thread from the owner of this object. |
| 85 AudioRendererHost(int render_process_id, | 85 AudioRendererHost(int render_process_id, |
| 86 media::AudioManager* audio_manager, | 86 media::AudioManager* audio_manager, |
| 87 AudioMirroringManager* mirroring_manager, | 87 AudioMirroringManager* mirroring_manager, |
| 88 MediaInternals* media_internals, | 88 MediaInternals* media_internals, |
| 89 MediaStreamManager* media_stream_manager, | 89 MediaStreamManager* media_stream_manager, |
| 90 const std::string& salt); | 90 const std::string& salt); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 // |session_id| will be ignored and the given |device_id| and | 140 // |session_id| will be ignored and the given |device_id| and |
| 141 // |security_origin| will be used to select the output device. | 141 // |security_origin| will be used to select the output device. |
| 142 // Upon completion of the process, the peer is notified with the device output | 142 // Upon completion of the process, the peer is notified with the device output |
| 143 // parameters via the NotifyDeviceAuthorized message. | 143 // parameters via the NotifyDeviceAuthorized message. |
| 144 void OnRequestDeviceAuthorization(int stream_id, | 144 void OnRequestDeviceAuthorization(int stream_id, |
| 145 int render_frame_id, | 145 int render_frame_id, |
| 146 int session_id, | 146 int session_id, |
| 147 const std::string& device_id, | 147 const std::string& device_id, |
| 148 const url::Origin& security_origin); | 148 const url::Origin& security_origin); |
| 149 | 149 |
| 150 void AuthorizationCompleted(int stream_id, | |
| 151 base::TimeTicks auth_start_time, | |
| 152 media::OutputDeviceStatus status, | |
| 153 media::AudioParameters params, | |
| 154 const std::string& unique_id); | |
| 155 | |
| 150 // Creates an audio output stream with the specified format. | 156 // Creates an audio output stream with the specified format. |
| 151 // Upon success/failure, the peer is notified via the NotifyStreamCreated | 157 // Upon success/failure, the peer is notified via the NotifyStreamCreated |
| 152 // message. | 158 // message. |
| 153 void OnCreateStream(int stream_id, | 159 void OnCreateStream(int stream_id, |
| 154 int render_frame_id, | 160 int render_frame_id, |
| 155 const media::AudioParameters& params); | 161 const media::AudioParameters& params); |
| 156 | 162 |
| 157 // Play the audio stream referenced by |stream_id|. | 163 // Play the audio stream referenced by |stream_id|. |
| 158 void OnPlayStream(int stream_id); | 164 void OnPlayStream(int stream_id); |
| 159 | 165 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 void ReportErrorAndClose(int stream_id); | 200 void ReportErrorAndClose(int stream_id); |
| 195 | 201 |
| 196 // A helper method to look up a AudioEntry identified by |stream_id|. | 202 // A helper method to look up a AudioEntry identified by |stream_id|. |
| 197 // Returns NULL if not found. | 203 // Returns NULL if not found. |
| 198 AudioEntry* LookupById(int stream_id); | 204 AudioEntry* LookupById(int stream_id); |
| 199 | 205 |
| 200 // A helper method to update the number of playing streams and alert the | 206 // A helper method to update the number of playing streams and alert the |
| 201 // ResourceScheduler when the renderer starts or stops playing an audiostream. | 207 // ResourceScheduler when the renderer starts or stops playing an audiostream. |
| 202 void UpdateNumPlayingStreams(AudioEntry* entry, bool is_playing); | 208 void UpdateNumPlayingStreams(AudioEntry* entry, bool is_playing); |
| 203 | 209 |
| 204 // Check if the renderer process has access to the requested output device. | |
| 205 void CheckOutputDeviceAccess(int render_frame_id, | |
| 206 const std::string& device_id, | |
| 207 const url::Origin& security_origin, | |
| 208 int stream_id, | |
| 209 base::TimeTicks auth_start_time); | |
| 210 | |
| 211 // Proceed with device authorization after checking permissions. | |
| 212 void AccessChecked(std::unique_ptr<MediaStreamUIProxy> ui_proxy, | |
| 213 const std::string& device_id, | |
| 214 const url::Origin& security_origin, | |
| 215 int stream_id, | |
| 216 base::TimeTicks auth_start_time, | |
| 217 bool have_access); | |
| 218 | |
| 219 // Translate the hashed |device_id| to a unique device ID. | |
| 220 void TranslateDeviceID(const std::string& device_id, | |
| 221 const url::Origin& security_origin, | |
| 222 int stream_id, | |
| 223 base::TimeTicks auth_start_time, | |
| 224 const MediaDeviceEnumeration& enumeration); | |
| 225 | |
| 226 // Get audio hardware parameters on the device thread. | |
| 227 media::AudioParameters GetDeviceParametersOnDeviceThread( | |
| 228 const std::string& device_id); | |
| 229 | |
| 230 // Proceed with device authorization after translating device ID and | |
| 231 // receiving hardware parameters. | |
| 232 void DeviceParametersReceived(int stream_id, | |
| 233 base::TimeTicks auth_start_time, | |
| 234 bool device_found, | |
| 235 const std::string& unique_id, | |
| 236 const media::AudioParameters& output_params); | |
| 237 | |
| 238 // Helper method to check if the authorization procedure for stream | 210 // Helper method to check if the authorization procedure for stream |
| 239 // |stream_id| has started. | 211 // |stream_id| has started. |
| 240 bool IsAuthorizationStarted(int stream_id); | 212 bool IsAuthorizationStarted(int stream_id); |
| 241 | 213 |
| 214 void OnBadMessage(content::bad_message::BadMessageReason reason); | |
| 215 | |
| 242 // Called from AudioRendererHostTest to override the function that checks for | 216 // Called from AudioRendererHostTest to override the function that checks for |
| 243 // the existence of the RenderFrameHost at stream creation time. | 217 // the existence of the RenderFrameHost at stream creation time. |
| 244 void set_render_frame_id_validate_function_for_testing( | 218 void set_render_frame_id_validate_function_for_testing( |
| 245 ValidateRenderFrameIdFunction function) { | 219 ValidateRenderFrameIdFunction function) { |
| 246 validate_render_frame_id_function_ = function; | 220 validate_render_frame_id_function_ = function; |
| 247 } | 221 } |
| 248 | 222 |
| 249 // ID of the RenderProcessHost that owns this instance. | 223 // ID of the RenderProcessHost that owns this instance. |
| 250 const int render_process_id_; | 224 const int render_process_id_; |
| 251 | 225 |
| 252 media::AudioManager* const audio_manager_; | 226 media::AudioManager* const audio_manager_; |
| 253 AudioMirroringManager* const mirroring_manager_; | 227 AudioMirroringManager* const mirroring_manager_; |
| 254 std::unique_ptr<media::AudioLog> audio_log_; | 228 std::unique_ptr<media::AudioLog> audio_log_; |
| 255 | 229 |
| 256 // Used to access to AudioInputDeviceManager. | |
| 257 MediaStreamManager* media_stream_manager_; | |
| 258 | |
| 259 // A map of stream IDs to audio sources. | 230 // A map of stream IDs to audio sources. |
| 260 AudioEntryMap audio_entries_; | 231 AudioEntryMap audio_entries_; |
| 261 | 232 |
| 262 // The number of streams in the playing state. Atomic read safe from any | 233 // The number of streams in the playing state. Atomic read safe from any |
| 263 // thread, but should only be updated from the IO thread. | 234 // thread, but should only be updated from the IO thread. |
| 264 base::AtomicRefCount num_playing_streams_; | 235 base::AtomicRefCount num_playing_streams_; |
| 265 | 236 |
| 266 // Salt required to translate renderer device IDs to raw device unique IDs | |
| 267 std::string salt_; | |
| 268 | |
| 269 // Map of device authorizations for streams that are not yet created | 237 // Map of device authorizations for streams that are not yet created |
| 270 // The key is the stream ID, and the value is a pair. The pair's first element | 238 // The key is the stream ID, and the value is a pair. The pair's first element |
| 271 // is a bool that is true if the authorization process completes successfully. | 239 // is a bool that is true if the authorization process completes successfully. |
| 272 // The second element contains the unique ID of the authorized device. | 240 // The second element contains the unique ID of the authorized device. |
| 273 std::map<int, std::pair<bool, std::string>> authorizations_; | 241 std::map<int, std::pair<bool, std::string>> authorizations_; |
|
o1ka
2016/10/28 08:12:20
Guido, why do we actually need a stream id for aut
Guido Urdaneta
2016/10/28 08:39:32
Because the user can revoke permissions at any tim
| |
| 274 | 242 |
| 275 // At stream creation time, AudioRendererHost will call this function on the | 243 // At stream creation time, AudioRendererHost will call this function on the |
| 276 // UI thread to validate render frame IDs. A default is set by the | 244 // UI thread to validate render frame IDs. A default is set by the |
| 277 // constructor, but this can be overridden by unit tests. | 245 // constructor, but this can be overridden by unit tests. |
| 278 ValidateRenderFrameIdFunction validate_render_frame_id_function_; | 246 ValidateRenderFrameIdFunction validate_render_frame_id_function_; |
| 279 | 247 |
| 280 // The maximum number of simultaneous streams during the lifetime of this | 248 // The maximum number of simultaneous streams during the lifetime of this |
| 281 // host. Reported as UMA stat at shutdown. | 249 // host. Reported as UMA stat at shutdown. |
| 282 size_t max_simultaneous_streams_; | 250 size_t max_simultaneous_streams_; |
| 283 | 251 |
| 252 AudioOutputAuthorizationHandler authorization_manager_; | |
| 253 | |
| 284 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); | 254 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); |
| 285 }; | 255 }; |
| 286 | 256 |
| 287 } // namespace content | 257 } // namespace content |
| 288 | 258 |
| 289 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ | 259 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ |
| OLD | NEW |