| 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_device_enumerator.h" | 57 #include "content/browser/renderer_host/media/media_devices_manager.h" |
| 58 #include "content/common/content_export.h" | 58 #include "content/common/content_export.h" |
| 59 #include "content/public/browser/browser_message_filter.h" | 59 #include "content/public/browser/browser_message_filter.h" |
| 60 #include "content/public/browser/browser_thread.h" | 60 #include "content/public/browser/browser_thread.h" |
| 61 #include "content/public/browser/render_process_host.h" | 61 #include "content/public/browser/render_process_host.h" |
| 62 #include "content/public/browser/resource_context.h" | 62 #include "content/public/browser/resource_context.h" |
| 63 #include "media/audio/audio_io.h" | 63 #include "media/audio/audio_io.h" |
| 64 #include "media/audio/audio_logging.h" | 64 #include "media/audio/audio_logging.h" |
| 65 #include "media/audio/audio_output_controller.h" | 65 #include "media/audio/audio_output_controller.h" |
| 66 #include "media/audio/simple_sources.h" | 66 #include "media/audio/simple_sources.h" |
| 67 #include "url/origin.h" | 67 #include "url/origin.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream); | 112 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream); |
| 113 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, MockStreamDataConversation); | 113 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, MockStreamDataConversation); |
| 114 | 114 |
| 115 class AudioEntry; | 115 class AudioEntry; |
| 116 typedef std::map<int, AudioEntry*> AudioEntryMap; | 116 typedef std::map<int, AudioEntry*> AudioEntryMap; |
| 117 | 117 |
| 118 // Internal callback type for access requests to output devices. | 118 // Internal callback type for access requests to output devices. |
| 119 // |have_access| is true only if there is permission to access the device. | 119 // |have_access| is true only if there is permission to access the device. |
| 120 typedef base::Callback<void(bool have_access)> OutputDeviceAccessCB; | 120 typedef base::Callback<void(bool have_access)> OutputDeviceAccessCB; |
| 121 | 121 |
| 122 // Internal callback type for information requests about an output device. | |
| 123 // |success| indicates the operation was successful. If true, |device_info| | |
| 124 // contains data about the device. | |
| 125 typedef base::Callback<void(bool success, | |
| 126 const AudioOutputDeviceInfo& device_info)> | |
| 127 OutputDeviceInfoCB; | |
| 128 | |
| 129 // The type of a function that is run on the UI thread to check whether the | 122 // The type of a function that is run on the UI thread to check whether the |
| 130 // routing IDs reference a valid RenderFrameHost. The function then runs | 123 // routing IDs reference a valid RenderFrameHost. The function then runs |
| 131 // |callback| on the IO thread with true/false if valid/invalid. | 124 // |callback| on the IO thread with true/false if valid/invalid. |
| 132 using ValidateRenderFrameIdFunction = | 125 using ValidateRenderFrameIdFunction = |
| 133 void (*)(int render_process_id, | 126 void (*)(int render_process_id, |
| 134 int render_frame_id, | 127 int render_frame_id, |
| 135 const base::Callback<void(bool)>& callback); | 128 const base::Callback<void(bool)>& callback); |
| 136 | 129 |
| 137 ~AudioRendererHost() override; | 130 ~AudioRendererHost() override; |
| 138 | 131 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 168 void OnPauseStream(int stream_id); | 161 void OnPauseStream(int stream_id); |
| 169 | 162 |
| 170 // Close the audio stream referenced by |stream_id|. | 163 // Close the audio stream referenced by |stream_id|. |
| 171 void OnCloseStream(int stream_id); | 164 void OnCloseStream(int stream_id); |
| 172 | 165 |
| 173 // Set the volume of the audio stream referenced by |stream_id|. | 166 // Set the volume of the audio stream referenced by |stream_id|. |
| 174 void OnSetVolume(int stream_id, double volume); | 167 void OnSetVolume(int stream_id, double volume); |
| 175 | 168 |
| 176 // Helper methods. | 169 // Helper methods. |
| 177 | 170 |
| 178 // Proceed with device authorization after checking permissions. | |
| 179 void OnDeviceAuthorized(int stream_id, | |
| 180 const std::string& device_id, | |
| 181 const url::Origin& security_origin, | |
| 182 base::TimeTicks auth_start_time, | |
| 183 bool have_access); | |
| 184 | |
| 185 // Proceed with device authorization after translating device ID. | |
| 186 void OnDeviceIDTranslated(int stream_id, | |
| 187 base::TimeTicks auth_start_time, | |
| 188 bool device_found, | |
| 189 const AudioOutputDeviceInfo& device_info); | |
| 190 | |
| 191 // Complete the process of creating an audio stream. This will set up the | 171 // 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 | 172 // shared memory or shared socket in low latency mode and send the |
| 193 // NotifyStreamCreated message to the peer. | 173 // NotifyStreamCreated message to the peer. |
| 194 void DoCompleteCreation(int stream_id); | 174 void DoCompleteCreation(int stream_id); |
| 195 | 175 |
| 196 // Called after the |render_frame_id| provided to OnCreateStream() was | 176 // Called after the |render_frame_id| provided to OnCreateStream() was |
| 197 // validated. When |is_valid| is false, this calls ReportErrorAndClose(). | 177 // validated. When |is_valid| is false, this calls ReportErrorAndClose(). |
| 198 void DidValidateRenderFrame(int stream_id, bool is_valid); | 178 void DidValidateRenderFrame(int stream_id, bool is_valid); |
| 199 | 179 |
| 200 // Send playing/paused status to the renderer. | 180 // Send playing/paused status to the renderer. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 217 AudioEntry* LookupById(int stream_id); | 197 AudioEntry* LookupById(int stream_id); |
| 218 | 198 |
| 219 // A helper method to update the number of playing streams and alert the | 199 // A helper method to update the number of playing streams and alert the |
| 220 // ResourceScheduler when the renderer starts or stops playing an audiostream. | 200 // ResourceScheduler when the renderer starts or stops playing an audiostream. |
| 221 void UpdateNumPlayingStreams(AudioEntry* entry, bool is_playing); | 201 void UpdateNumPlayingStreams(AudioEntry* entry, bool is_playing); |
| 222 | 202 |
| 223 // Check if the renderer process has access to the requested output device. | 203 // Check if the renderer process has access to the requested output device. |
| 224 void CheckOutputDeviceAccess(int render_frame_id, | 204 void CheckOutputDeviceAccess(int render_frame_id, |
| 225 const std::string& device_id, | 205 const std::string& device_id, |
| 226 const url::Origin& security_origin, | 206 const url::Origin& security_origin, |
| 227 const OutputDeviceAccessCB& callback); | 207 int stream_id, |
| 208 base::TimeTicks auth_start_time); |
| 228 | 209 |
| 229 // Invoke |callback| after permission to use a device has been checked. | 210 // Proceed with device authorization after checking permissions. |
| 230 void AccessChecked(std::unique_ptr<MediaStreamUIProxy> ui_proxy, | 211 void AccessChecked(std::unique_ptr<MediaStreamUIProxy> ui_proxy, |
| 231 const OutputDeviceAccessCB& callback, | 212 const std::string& device_id, |
| 213 const url::Origin& security_origin, |
| 214 int stream_id, |
| 215 base::TimeTicks auth_start_time, |
| 232 bool have_access); | 216 bool have_access); |
| 233 | 217 |
| 234 // Translate the hashed |device_id| to a unique device ID. | 218 // Translate the hashed |device_id| to a unique device ID. |
| 235 void TranslateDeviceID(const std::string& device_id, | 219 void TranslateDeviceID(const std::string& device_id, |
| 236 const url::Origin& security_origin, | 220 const url::Origin& security_origin, |
| 237 const OutputDeviceInfoCB& callback, | 221 int stream_id, |
| 238 const AudioOutputDeviceEnumeration& enumeration); | 222 base::TimeTicks auth_start_time, |
| 223 const MediaDeviceEnumeration& enumeration); |
| 224 |
| 225 // Get audio hardware parameters on the device thread. |
| 226 media::AudioParameters GetDeviceParametersOnDeviceThread( |
| 227 const std::string& device_id); |
| 228 |
| 229 // Proceed with device authorization after translating device ID and |
| 230 // receiving hardware parameters. |
| 231 void DeviceParametersReceived(int stream_id, |
| 232 base::TimeTicks auth_start_time, |
| 233 bool device_found, |
| 234 const std::string& unique_id, |
| 235 const media::AudioParameters& output_params); |
| 239 | 236 |
| 240 // Helper method to check if the authorization procedure for stream | 237 // Helper method to check if the authorization procedure for stream |
| 241 // |stream_id| has started. | 238 // |stream_id| has started. |
| 242 bool IsAuthorizationStarted(int stream_id); | 239 bool IsAuthorizationStarted(int stream_id); |
| 243 | 240 |
| 244 // Called from AudioRendererHostTest to override the function that checks for | 241 // Called from AudioRendererHostTest to override the function that checks for |
| 245 // the existence of the RenderFrameHost at stream creation time. | 242 // the existence of the RenderFrameHost at stream creation time. |
| 246 void set_render_frame_id_validate_function_for_testing( | 243 void set_render_frame_id_validate_function_for_testing( |
| 247 ValidateRenderFrameIdFunction function) { | 244 ValidateRenderFrameIdFunction function) { |
| 248 validate_render_frame_id_function_ = function; | 245 validate_render_frame_id_function_ = function; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 // The maximum number of simultaneous streams during the lifetime of this | 279 // The maximum number of simultaneous streams during the lifetime of this |
| 283 // host. Reported as UMA stat at shutdown. | 280 // host. Reported as UMA stat at shutdown. |
| 284 size_t max_simultaneous_streams_; | 281 size_t max_simultaneous_streams_; |
| 285 | 282 |
| 286 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); | 283 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); |
| 287 }; | 284 }; |
| 288 | 285 |
| 289 } // namespace content | 286 } // namespace content |
| 290 | 287 |
| 291 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ | 288 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ |
| OLD | NEW |