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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 | 42 |
| 43 #include <stddef.h> | 43 #include <stddef.h> |
| 44 | 44 |
| 45 #include <map> | 45 #include <map> |
| 46 #include <memory> | 46 #include <memory> |
| 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/macros.h" | 53 #include "base/macros.h" |
| 53 #include "base/memory/ref_counted.h" | 54 #include "base/memory/ref_counted.h" |
| 54 #include "base/process/process.h" | 55 #include "base/process/process.h" |
| 55 #include "base/sequenced_task_runner_helpers.h" | 56 #include "base/sequenced_task_runner_helpers.h" |
| 56 #include "content/browser/renderer_host/media/audio_output_device_enumerator.h" | 57 #include "content/browser/renderer_host/media/audio_output_device_enumerator.h" |
| 57 #include "content/common/content_export.h" | 58 #include "content/common/content_export.h" |
| 58 #include "content/public/browser/browser_message_filter.h" | 59 #include "content/public/browser/browser_message_filter.h" |
| 59 #include "content/public/browser/browser_thread.h" | 60 #include "content/public/browser/browser_thread.h" |
| 60 #include "content/public/browser/render_process_host.h" | 61 #include "content/public/browser/render_process_host.h" |
| 61 #include "content/public/browser/resource_context.h" | 62 #include "content/public/browser/resource_context.h" |
| (...skipping 60 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. | 123 // |have_access| is true only if there is permission to access the device. |
| 123 typedef base::Callback<void(bool have_access)> OutputDeviceAccessCB; | 124 typedef base::Callback<void(bool have_access)> OutputDeviceAccessCB; |
| 124 | 125 |
| 125 // Internal callback type for information requests about an output device. | 126 // Internal callback type for information requests about an output device. |
| 126 // |success| indicates the operation was successful. If true, |device_info| | 127 // |success| indicates the operation was successful. If true, |device_info| |
| 127 // contains data about the device. | 128 // contains data about the device. |
| 128 typedef base::Callback<void(bool success, | 129 typedef base::Callback<void(bool success, |
| 129 const AudioOutputDeviceInfo& device_info)> | 130 const AudioOutputDeviceInfo& device_info)> |
| 130 OutputDeviceInfoCB; | 131 OutputDeviceInfoCB; |
| 131 | 132 |
| 133 // The type of a function that is run on the UI thread to check whether the | |
| 134 // routing IDs reference a valid RenderFrameHost. The function then runs | |
| 135 // |callback| on the IO thread with true/false if valid/invalid. | |
| 136 using ValidateRenderFrameIdFunction = | |
|
o1ka
2016/07/11 10:35:50
probably #ifdef this as well?
miu
2016/07/14 21:36:12
Based on past experience, we generally don't condi
| |
| 137 void (*)(int render_process_id, | |
| 138 int render_frame_id, | |
| 139 const base::Callback<void(bool)>& callback); | |
| 140 | |
| 132 ~AudioRendererHost() override; | 141 ~AudioRendererHost() override; |
| 133 | 142 |
| 134 // Methods called on IO thread ---------------------------------------------- | 143 // Methods called on IO thread ---------------------------------------------- |
| 135 | 144 |
| 136 // Audio related IPC message handlers. | 145 // Audio related IPC message handlers. |
| 137 | 146 |
| 138 // Request permission to use an output device for use by a stream produced | 147 // Request permission to use an output device for use by a stream produced |
| 139 // in the RenderFrame referenced by |render_frame_id|. | 148 // in the RenderFrame referenced by |render_frame_id|. |
| 140 // |session_id| is used for unified IO to find out which input device to be | 149 // |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, | 150 // 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. | 188 // Proceed with device authorization after translating device ID. |
| 180 void OnDeviceIDTranslated(int stream_id, | 189 void OnDeviceIDTranslated(int stream_id, |
| 181 bool device_found, | 190 bool device_found, |
| 182 const AudioOutputDeviceInfo& device_info); | 191 const AudioOutputDeviceInfo& device_info); |
| 183 | 192 |
| 184 // Start the actual creation of an audio stream, after the device | 193 // Start the actual creation of an audio stream, after the device |
| 185 // authorization process is complete. | 194 // authorization process is complete. |
| 186 void DoCreateStream(int stream_id, | 195 void DoCreateStream(int stream_id, |
| 187 int render_frame_id, | 196 int render_frame_id, |
| 188 const media::AudioParameters& params, | 197 const media::AudioParameters& params, |
| 189 const std::string& device_unique_id); | 198 const std::string& device_unique_id, |
| 199 bool render_frame_id_is_valid); | |
| 190 | 200 |
| 191 // Complete the process of creating an audio stream. This will set up the | 201 // 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 | 202 // shared memory or shared socket in low latency mode and send the |
| 193 // NotifyStreamCreated message to the peer. | 203 // NotifyStreamCreated message to the peer. |
| 194 void DoCompleteCreation(int stream_id); | 204 void DoCompleteCreation(int stream_id); |
| 195 | 205 |
| 196 // Send playing/paused status to the renderer. | 206 // Send playing/paused status to the renderer. |
| 197 void DoNotifyStreamStateChanged(int stream_id, bool is_playing); | 207 void DoNotifyStreamStateChanged(int stream_id, bool is_playing); |
| 198 | 208 |
| 199 RenderProcessHost::AudioOutputControllerList DoGetOutputControllers() const; | 209 RenderProcessHost::AudioOutputControllerList DoGetOutputControllers() const; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 230 // Translate the hashed |device_id| to a unique device ID. | 240 // Translate the hashed |device_id| to a unique device ID. |
| 231 void TranslateDeviceID(const std::string& device_id, | 241 void TranslateDeviceID(const std::string& device_id, |
| 232 const url::Origin& security_origin, | 242 const url::Origin& security_origin, |
| 233 const OutputDeviceInfoCB& callback, | 243 const OutputDeviceInfoCB& callback, |
| 234 const AudioOutputDeviceEnumeration& enumeration); | 244 const AudioOutputDeviceEnumeration& enumeration); |
| 235 | 245 |
| 236 // Helper method to check if the authorization procedure for stream | 246 // Helper method to check if the authorization procedure for stream |
| 237 // |stream_id| has started. | 247 // |stream_id| has started. |
| 238 bool IsAuthorizationStarted(int stream_id); | 248 bool IsAuthorizationStarted(int stream_id); |
| 239 | 249 |
| 250 #if DCHECK_IS_ON() | |
| 251 // Called from AudioRendererHostTest to override the function that checks for | |
| 252 // the existence of the RenderFrameHost at stream creation time. | |
| 253 void set_render_frame_id_validate_function_for_testing( | |
| 254 ValidateRenderFrameIdFunction function) { | |
| 255 validate_render_frame_id_function_ = function; | |
| 256 } | |
| 257 #endif // DCHECK_IS_ON() | |
| 258 | |
| 240 // ID of the RenderProcessHost that owns this instance. | 259 // ID of the RenderProcessHost that owns this instance. |
| 241 const int render_process_id_; | 260 const int render_process_id_; |
| 242 | 261 |
| 243 media::AudioManager* const audio_manager_; | 262 media::AudioManager* const audio_manager_; |
| 244 AudioMirroringManager* const mirroring_manager_; | 263 AudioMirroringManager* const mirroring_manager_; |
| 245 std::unique_ptr<media::AudioLog> audio_log_; | 264 std::unique_ptr<media::AudioLog> audio_log_; |
| 246 | 265 |
| 247 // Used to access to AudioInputDeviceManager. | 266 // Used to access to AudioInputDeviceManager. |
| 248 MediaStreamManager* media_stream_manager_; | 267 MediaStreamManager* media_stream_manager_; |
| 249 | 268 |
| 250 // A map of stream IDs to audio sources. | 269 // A map of stream IDs to audio sources. |
| 251 AudioEntryMap audio_entries_; | 270 AudioEntryMap audio_entries_; |
| 252 | 271 |
| 253 // The number of streams in the playing state. Atomic read safe from any | 272 // The number of streams in the playing state. Atomic read safe from any |
| 254 // thread, but should only be updated from the IO thread. | 273 // thread, but should only be updated from the IO thread. |
| 255 base::AtomicRefCount num_playing_streams_; | 274 base::AtomicRefCount num_playing_streams_; |
| 256 | 275 |
| 257 // Salt required to translate renderer device IDs to raw device unique IDs | 276 // Salt required to translate renderer device IDs to raw device unique IDs |
| 258 std::string salt_; | 277 std::string salt_; |
| 259 | 278 |
| 260 // Map of device authorizations for streams that are not yet created | 279 // 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 | 280 // 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. | 281 // is a bool that is true if the authorization process completes successfully. |
| 263 // The second element contains the unique ID of the authorized device. | 282 // The second element contains the unique ID of the authorized device. |
| 264 std::map<int, std::pair<bool, std::string>> authorizations_; | 283 std::map<int, std::pair<bool, std::string>> authorizations_; |
| 265 | 284 |
| 285 #if DCHECK_IS_ON() | |
| 286 // When DCHECKs are turned on, AudioRendererHost will call this function on | |
| 287 // the UI thread to validate render frame IDs. A default is set by the | |
| 288 // constructor, but this can be overridden by unit tests. | |
| 289 ValidateRenderFrameIdFunction validate_render_frame_id_function_; | |
|
o1ka
2016/07/11 10:35:50
AudioRendererHost is exported from content.
Is a s
miu
2016/07/14 21:36:12
This shouldn't be an issue in the Chromium project
| |
| 290 #endif // DCHECK_IS_ON() | |
| 291 | |
| 266 // The maximum number of simultaneous streams during the lifetime of this | 292 // The maximum number of simultaneous streams during the lifetime of this |
| 267 // host. Reported as UMA stat at shutdown. | 293 // host. Reported as UMA stat at shutdown. |
| 268 size_t max_simultaneous_streams_; | 294 size_t max_simultaneous_streams_; |
| 269 | 295 |
| 270 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); | 296 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); |
| 271 }; | 297 }; |
| 272 | 298 |
| 273 } // namespace content | 299 } // namespace content |
| 274 | 300 |
| 275 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ | 301 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ |
| OLD | NEW |