| 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 BrowserRenderProcessHost, and instantiated on UI | 8 // This class is owned by BrowserRenderProcessHost, 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 20 matching lines...) Expand all Loading... |
| 31 // | ... | | 31 // | ... | |
| 32 // | CloseStream > | | 32 // | CloseStream > | |
| 33 // v v | 33 // v v |
| 34 | 34 |
| 35 // A SyncSocket pair is used to signal buffer readiness between processes. | 35 // A SyncSocket pair is used to signal buffer readiness between processes. |
| 36 | 36 |
| 37 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ | 37 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ |
| 38 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ | 38 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ |
| 39 | 39 |
| 40 #include <map> | 40 #include <map> |
| 41 #include <string> |
| 41 | 42 |
| 42 #include "base/atomic_ref_count.h" | 43 #include "base/atomic_ref_count.h" |
| 43 #include "base/gtest_prod_util.h" | 44 #include "base/gtest_prod_util.h" |
| 44 #include "base/memory/ref_counted.h" | 45 #include "base/memory/ref_counted.h" |
| 45 #include "base/memory/scoped_ptr.h" | 46 #include "base/memory/scoped_ptr.h" |
| 46 #include "base/process/process.h" | 47 #include "base/process/process.h" |
| 47 #include "base/sequenced_task_runner_helpers.h" | 48 #include "base/sequenced_task_runner_helpers.h" |
| 48 #include "content/common/content_export.h" | 49 #include "content/common/content_export.h" |
| 49 #include "content/public/browser/browser_message_filter.h" | 50 #include "content/public/browser/browser_message_filter.h" |
| 50 #include "content/public/browser/browser_thread.h" | 51 #include "content/public/browser/browser_thread.h" |
| 51 #include "content/public/browser/render_process_host.h" | 52 #include "content/public/browser/render_process_host.h" |
| 53 #include "content/public/browser/resource_context.h" |
| 52 #include "media/audio/audio_io.h" | 54 #include "media/audio/audio_io.h" |
| 53 #include "media/audio/audio_logging.h" | 55 #include "media/audio/audio_logging.h" |
| 54 #include "media/audio/audio_output_controller.h" | 56 #include "media/audio/audio_output_controller.h" |
| 55 #include "media/audio/simple_sources.h" | 57 #include "media/audio/simple_sources.h" |
| 58 #include "url/gurl.h" |
| 56 | 59 |
| 57 namespace media { | 60 namespace media { |
| 58 class AudioManager; | 61 class AudioManager; |
| 59 class AudioParameters; | 62 class AudioParameters; |
| 60 } | 63 } |
| 61 | 64 |
| 62 namespace content { | 65 namespace content { |
| 63 | 66 |
| 64 class AudioMirroringManager; | 67 class AudioMirroringManager; |
| 65 class MediaInternals; | 68 class MediaInternals; |
| 66 class MediaStreamManager; | 69 class MediaStreamManager; |
| 70 class MediaStreamUIProxy; |
| 67 class ResourceContext; | 71 class ResourceContext; |
| 68 | 72 |
| 69 class CONTENT_EXPORT AudioRendererHost : public BrowserMessageFilter { | 73 class CONTENT_EXPORT AudioRendererHost : public BrowserMessageFilter { |
| 70 public: | 74 public: |
| 71 // Called from UI thread from the owner of this object. | 75 // Called from UI thread from the owner of this object. |
| 72 AudioRendererHost(int render_process_id, | 76 AudioRendererHost(int render_process_id, |
| 73 media::AudioManager* audio_manager, | 77 media::AudioManager* audio_manager, |
| 74 AudioMirroringManager* mirroring_manager, | 78 AudioMirroringManager* mirroring_manager, |
| 75 MediaInternals* media_internals, | 79 MediaInternals* media_internals, |
| 76 MediaStreamManager* media_stream_manager); | 80 MediaStreamManager* media_stream_manager, |
| 81 const ResourceContext::SaltCallback& salt_callback); |
| 77 | 82 |
| 78 // Calls |callback| with the list of AudioOutputControllers for this object. | 83 // Calls |callback| with the list of AudioOutputControllers for this object. |
| 79 void GetOutputControllers( | 84 void GetOutputControllers( |
| 80 const RenderProcessHost::GetAudioOutputControllersCallback& | 85 const RenderProcessHost::GetAudioOutputControllersCallback& |
| 81 callback) const; | 86 callback) const; |
| 82 | 87 |
| 83 // BrowserMessageFilter implementation. | 88 // BrowserMessageFilter implementation. |
| 84 void OnChannelClosing() override; | 89 void OnChannelClosing() override; |
| 85 void OnDestruct() const override; | 90 void OnDestruct() const override; |
| 86 bool OnMessageReceived(const IPC::Message& message) override; | 91 bool OnMessageReceived(const IPC::Message& message) override; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 133 |
| 129 // Pause the audio stream referenced by |stream_id|. | 134 // Pause the audio stream referenced by |stream_id|. |
| 130 void OnPauseStream(int stream_id); | 135 void OnPauseStream(int stream_id); |
| 131 | 136 |
| 132 // Close the audio stream referenced by |stream_id|. | 137 // Close the audio stream referenced by |stream_id|. |
| 133 void OnCloseStream(int stream_id); | 138 void OnCloseStream(int stream_id); |
| 134 | 139 |
| 135 // Set the volume of the audio stream referenced by |stream_id|. | 140 // Set the volume of the audio stream referenced by |stream_id|. |
| 136 void OnSetVolume(int stream_id, double volume); | 141 void OnSetVolume(int stream_id, double volume); |
| 137 | 142 |
| 143 // Set the output device of the audio stream referenced by |stream_id|. |
| 144 void OnSwitchOutputDevice(int stream_id, |
| 145 int render_frame_id, |
| 146 const std::string& device_id, |
| 147 const GURL& security_origin, |
| 148 int request_id); |
| 149 |
| 150 void OutputDeviceAccessChecked(scoped_ptr<MediaStreamUIProxy> ui_proxy, |
| 151 int stream_id, |
| 152 const std::string& device_id, |
| 153 const GURL& security_origin, |
| 154 int render_frame_id, |
| 155 int request_id, |
| 156 bool have_access); |
| 157 |
| 158 void StartTranslateOutputDeviceName(int stream_id, |
| 159 const std::string& device_id, |
| 160 const GURL& security_origin, |
| 161 int request_id); |
| 162 |
| 163 void FinishTranslateOutputDeviceName(int stream_id, |
| 164 const std::string& device_id, |
| 165 const GURL& security_origin, |
| 166 int request_id, |
| 167 media::AudioDeviceNames*); |
| 168 |
| 169 void DoSwitchOutputDevice(int stream_id, |
| 170 const std::string& raw_device_id, |
| 171 int request_id); |
| 172 |
| 173 void DoOutputDeviceSwitched(int stream_id, int request_id); |
| 174 |
| 138 // Complete the process of creating an audio stream. This will set up the | 175 // Complete the process of creating an audio stream. This will set up the |
| 139 // shared memory or shared socket in low latency mode and send the | 176 // shared memory or shared socket in low latency mode and send the |
| 140 // NotifyStreamCreated message to the peer. | 177 // NotifyStreamCreated message to the peer. |
| 141 void DoCompleteCreation(int stream_id); | 178 void DoCompleteCreation(int stream_id); |
| 142 | 179 |
| 143 // Send playing/paused status to the renderer. | 180 // Send playing/paused status to the renderer. |
| 144 void DoNotifyStreamStateChanged(int stream_id, bool is_playing); | 181 void DoNotifyStreamStateChanged(int stream_id, bool is_playing); |
| 145 | 182 |
| 146 RenderProcessHost::AudioOutputControllerList DoGetOutputControllers() const; | 183 RenderProcessHost::AudioOutputControllerList DoGetOutputControllers() const; |
| 147 | 184 |
| 148 // Send an error message to the renderer. | 185 // Send an error message to the renderer. |
| 149 void SendErrorMessage(int stream_id); | 186 void SendErrorMessage(int stream_id); |
| 150 | 187 |
| 151 // Delete an audio entry, notifying observers first. This is called by | 188 // Delete an audio entry, notifying observers first. This is called by |
| 152 // AudioOutputController after it has closed. | 189 // AudioOutputController after it has closed. |
| 153 void DeleteEntry(scoped_ptr<AudioEntry> entry); | 190 void DeleteEntry(scoped_ptr<AudioEntry> entry); |
| 154 | 191 |
| 155 // Send an error message to the renderer, then close the stream. | 192 // Send an error message to the renderer, then close the stream. |
| 156 void ReportErrorAndClose(int stream_id); | 193 void ReportErrorAndClose(int stream_id); |
| 157 | 194 |
| 158 // A helper method to look up a AudioEntry identified by |stream_id|. | 195 // A helper method to look up a AudioEntry identified by |stream_id|. |
| 159 // Returns NULL if not found. | 196 // Returns NULL if not found. |
| 160 AudioEntry* LookupById(int stream_id); | 197 AudioEntry* LookupById(int stream_id); |
| 161 | 198 |
| 162 // 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 |
| 163 // ResourceScheduler when the renderer starts or stops playing an audiostream. | 200 // ResourceScheduler when the renderer starts or stops playing an audiostream. |
| 164 void UpdateNumPlayingStreams(AudioEntry* entry, bool is_playing); | 201 void UpdateNumPlayingStreams(AudioEntry* entry, bool is_playing); |
| 165 | 202 |
| 203 // Checks that the renderer process supplies a URL it is allowed to use |
| 204 bool IsURLAllowed(const GURL& url); |
| 205 |
| 166 // ID of the RenderProcessHost that owns this instance. | 206 // ID of the RenderProcessHost that owns this instance. |
| 167 const int render_process_id_; | 207 const int render_process_id_; |
| 168 | 208 |
| 169 media::AudioManager* const audio_manager_; | 209 media::AudioManager* const audio_manager_; |
| 170 AudioMirroringManager* const mirroring_manager_; | 210 AudioMirroringManager* const mirroring_manager_; |
| 171 scoped_ptr<media::AudioLog> audio_log_; | 211 scoped_ptr<media::AudioLog> audio_log_; |
| 172 | 212 |
| 173 // Used to access to AudioInputDeviceManager. | 213 // Used to access to AudioInputDeviceManager. |
| 174 MediaStreamManager* media_stream_manager_; | 214 MediaStreamManager* media_stream_manager_; |
| 175 | 215 |
| 176 // A map of stream IDs to audio sources. | 216 // A map of stream IDs to audio sources. |
| 177 AudioEntryMap audio_entries_; | 217 AudioEntryMap audio_entries_; |
| 178 | 218 |
| 179 // The number of streams in the playing state. | 219 // The number of streams in the playing state. |
| 180 base::AtomicRefCount num_playing_streams_; | 220 base::AtomicRefCount num_playing_streams_; |
| 181 | 221 |
| 222 // Salt required to translate renderer device IDs to raw device IDs |
| 223 ResourceContext::SaltCallback salt_callback_; |
| 224 |
| 182 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); | 225 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); |
| 183 }; | 226 }; |
| 184 | 227 |
| 185 } // namespace content | 228 } // namespace content |
| 186 | 229 |
| 187 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ | 230 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ |
| OLD | NEW |