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