| 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 // Audio rendering unit utilizing audio output stream provided by browser | 5 // Audio rendering unit utilizing audio output stream provided by browser |
| 6 // process through IPC. | 6 // process through IPC. |
| 7 // | 7 // |
| 8 // Relationship of classes. | 8 // Relationship of classes. |
| 9 // | 9 // |
| 10 // AudioOutputController AudioOutputDevice | 10 // AudioOutputController AudioOutputDevice |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 // turn calls AudioRendererSink::RenderCallback which feeds audio samples to | 51 // turn calls AudioRendererSink::RenderCallback which feeds audio samples to |
| 52 // the audio layer in the browser process using sync sockets and shared | 52 // the audio layer in the browser process using sync sockets and shared |
| 53 // memory. | 53 // memory. |
| 54 // | 54 // |
| 55 // Implementation notes: | 55 // Implementation notes: |
| 56 // - The user must call Stop() before deleting the class instance. | 56 // - The user must call Stop() before deleting the class instance. |
| 57 | 57 |
| 58 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_ | 58 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_ |
| 59 #define MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_ | 59 #define MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_ |
| 60 | 60 |
| 61 #include <string> |
| 62 |
| 61 #include "base/basictypes.h" | 63 #include "base/basictypes.h" |
| 62 #include "base/bind.h" | 64 #include "base/bind.h" |
| 63 #include "base/memory/scoped_ptr.h" | 65 #include "base/memory/scoped_ptr.h" |
| 64 #include "base/memory/shared_memory.h" | 66 #include "base/memory/shared_memory.h" |
| 65 #include "media/audio/audio_device_thread.h" | 67 #include "media/audio/audio_device_thread.h" |
| 66 #include "media/audio/audio_output_ipc.h" | 68 #include "media/audio/audio_output_ipc.h" |
| 67 #include "media/audio/audio_parameters.h" | 69 #include "media/audio/audio_parameters.h" |
| 68 #include "media/audio/scoped_task_runner_observer.h" | 70 #include "media/audio/scoped_task_runner_observer.h" |
| 69 #include "media/base/audio_renderer_sink.h" | 71 #include "media/base/audio_renderer_sink.h" |
| 70 #include "media/base/media_export.h" | 72 #include "media/base/media_export.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 88 int session_id); | 90 int session_id); |
| 89 | 91 |
| 90 // AudioRendererSink implementation. | 92 // AudioRendererSink implementation. |
| 91 void Initialize(const AudioParameters& params, | 93 void Initialize(const AudioParameters& params, |
| 92 RenderCallback* callback) override; | 94 RenderCallback* callback) override; |
| 93 void Start() override; | 95 void Start() override; |
| 94 void Stop() override; | 96 void Stop() override; |
| 95 void Play() override; | 97 void Play() override; |
| 96 void Pause() override; | 98 void Pause() override; |
| 97 bool SetVolume(double volume) override; | 99 bool SetVolume(double volume) override; |
| 100 void SwitchOutputDevice( |
| 101 const std::string& device_id, |
| 102 const GURL& security_origin, |
| 103 scoped_ptr<SwitchOutputDeviceCallbackRunner> callback_runner) override; |
| 98 | 104 |
| 99 // Methods called on IO thread ---------------------------------------------- | 105 // Methods called on IO thread ---------------------------------------------- |
| 100 // AudioOutputIPCDelegate methods. | 106 // AudioOutputIPCDelegate methods. |
| 101 void OnStateChanged(AudioOutputIPCDelegate::State state) override; | 107 void OnStateChanged(AudioOutputIPCDelegate::State state) override; |
| 102 void OnStreamCreated(base::SharedMemoryHandle handle, | 108 void OnStreamCreated(base::SharedMemoryHandle handle, |
| 103 base::SyncSocket::Handle socket_handle, | 109 base::SyncSocket::Handle socket_handle, |
| 104 int length) override; | 110 int length) override; |
| 111 void OnOutputDeviceSwitched(int request_id, |
| 112 SwitchOutputDeviceResult result) override; |
| 105 void OnIPCClosed() override; | 113 void OnIPCClosed() override; |
| 106 | 114 |
| 107 protected: | 115 protected: |
| 108 // Magic required by ref_counted.h to avoid any code deleting the object | 116 // Magic required by ref_counted.h to avoid any code deleting the object |
| 109 // accidentally while there are references to it. | 117 // accidentally while there are references to it. |
| 110 friend class base::RefCountedThreadSafe<AudioOutputDevice>; | 118 friend class base::RefCountedThreadSafe<AudioOutputDevice>; |
| 111 ~AudioOutputDevice() override; | 119 ~AudioOutputDevice() override; |
| 112 | 120 |
| 113 private: | 121 private: |
| 114 // Note: The ordering of members in this enum is critical to correct behavior! | 122 // Note: The ordering of members in this enum is critical to correct behavior! |
| 115 enum State { | 123 enum State { |
| 116 IPC_CLOSED, // No more IPCs can take place. | 124 IPC_CLOSED, // No more IPCs can take place. |
| 117 IDLE, // Not started. | 125 IDLE, // Not started. |
| 118 CREATING_STREAM, // Waiting for OnStreamCreated() to be called back. | 126 CREATING_STREAM, // Waiting for OnStreamCreated() to be called back. |
| 119 PAUSED, // Paused. OnStreamCreated() has been called. Can Play()/Stop(). | 127 PAUSED, // Paused. OnStreamCreated() has been called. Can Play()/Stop(). |
| 120 PLAYING, // Playing back. Can Pause()/Stop(). | 128 PLAYING, // Playing back. Can Pause()/Stop(). |
| 121 }; | 129 }; |
| 122 | 130 |
| 123 // Methods called on IO thread ---------------------------------------------- | 131 // Methods called on IO thread ---------------------------------------------- |
| 124 // The following methods are tasks posted on the IO thread that need to | 132 // The following methods are tasks posted on the IO thread that need to |
| 125 // be executed on that thread. They use AudioOutputIPC to send IPC messages | 133 // be executed on that thread. They use AudioOutputIPC to send IPC messages |
| 126 // upon state changes. | 134 // upon state changes. |
| 127 void CreateStreamOnIOThread(const AudioParameters& params); | 135 void CreateStreamOnIOThread(const AudioParameters& params); |
| 128 void PlayOnIOThread(); | 136 void PlayOnIOThread(); |
| 129 void PauseOnIOThread(); | 137 void PauseOnIOThread(); |
| 130 void ShutDownOnIOThread(); | 138 void ShutDownOnIOThread(); |
| 131 void SetVolumeOnIOThread(double volume); | 139 void SetVolumeOnIOThread(double volume); |
| 140 void SwitchOutputDeviceOnIOThread( |
| 141 const std::string& device_id, |
| 142 const GURL& security_origin, |
| 143 scoped_ptr<SwitchOutputDeviceCallbackRunner> callback_runner); |
| 132 | 144 |
| 133 // base::MessageLoop::DestructionObserver implementation for the IO loop. | 145 // base::MessageLoop::DestructionObserver implementation for the IO loop. |
| 134 // If the IO loop dies before we do, we shut down the audio thread from here. | 146 // If the IO loop dies before we do, we shut down the audio thread from here. |
| 135 void WillDestroyCurrentMessageLoop() override; | 147 void WillDestroyCurrentMessageLoop() override; |
| 136 | 148 |
| 149 void SetCurrentSwitchRequest( |
| 150 scoped_ptr<SwitchOutputDeviceCallbackRunner> callback_runner); |
| 151 |
| 137 AudioParameters audio_parameters_; | 152 AudioParameters audio_parameters_; |
| 138 | 153 |
| 139 RenderCallback* callback_; | 154 RenderCallback* callback_; |
| 140 | 155 |
| 141 // A pointer to the IPC layer that takes care of sending requests over to | 156 // A pointer to the IPC layer that takes care of sending requests over to |
| 142 // the AudioRendererHost. Only valid when state_ != IPC_CLOSED and must only | 157 // the AudioRendererHost. Only valid when state_ != IPC_CLOSED and must only |
| 143 // be accessed on the IO thread. | 158 // be accessed on the IO thread. |
| 144 scoped_ptr<AudioOutputIPC> ipc_; | 159 scoped_ptr<AudioOutputIPC> ipc_; |
| 145 | 160 |
| 146 // Current state (must only be accessed from the IO thread). See comments for | 161 // Current state (must only be accessed from the IO thread). See comments for |
| (...skipping 17 matching lines...) Expand all Loading... |
| 164 scoped_ptr<AudioOutputDevice::AudioThreadCallback> audio_callback_; | 179 scoped_ptr<AudioOutputDevice::AudioThreadCallback> audio_callback_; |
| 165 | 180 |
| 166 // Temporary hack to ignore OnStreamCreated() due to the user calling Stop() | 181 // Temporary hack to ignore OnStreamCreated() due to the user calling Stop() |
| 167 // so we don't start the audio thread pointing to a potentially freed | 182 // so we don't start the audio thread pointing to a potentially freed |
| 168 // |callback_|. | 183 // |callback_|. |
| 169 // | 184 // |
| 170 // TODO(scherkus): Replace this by changing AudioRendererSink to either accept | 185 // TODO(scherkus): Replace this by changing AudioRendererSink to either accept |
| 171 // the callback via Start(). See http://crbug.com/151051 for details. | 186 // the callback via Start(). See http://crbug.com/151051 for details. |
| 172 bool stopping_hack_; | 187 bool stopping_hack_; |
| 173 | 188 |
| 189 int current_switch_request_id_; |
| 190 scoped_ptr<SwitchOutputDeviceCallbackRunner> current_switch_callback_runner_; |
| 191 |
| 174 DISALLOW_COPY_AND_ASSIGN(AudioOutputDevice); | 192 DISALLOW_COPY_AND_ASSIGN(AudioOutputDevice); |
| 175 }; | 193 }; |
| 176 | 194 |
| 177 } // namespace media | 195 } // namespace media |
| 178 | 196 |
| 179 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_ | 197 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_ |
| OLD | NEW |