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 // Low-latency audio rendering unit utilizing audio output stream provided | 5 // Low-latency audio rendering unit utilizing audio output stream provided |
| 6 // by browser process through IPC. | 6 // by browser process through IPC. |
| 7 // | 7 // |
| 8 // Relationship of classes. | 8 // Relationship of classes. |
| 9 // | 9 // |
| 10 // AudioOutputController AudioDevice | 10 // AudioOutputController AudioDevice |
| 11 // ^ ^ | 11 // ^ ^ |
| 12 // | | | 12 // | | |
| 13 // v IPC v | 13 // v IPC v |
| 14 // AudioRendererHost <---------> AudioMessageFilter | 14 // AudioRendererHost <---------> AudioMessageFilter |
| 15 // | 15 // |
| 16 // Transportation of audio samples from the render to the browser process | 16 // Transportation of audio samples from the render to the browser process |
| 17 // is done by using shared memory in combination with a sync socket pair | 17 // is done by using shared memory in combination with a sync socket pair |
| 18 // to generate a low latency transport. The AudioDevice user registers an | 18 // to generate a low latency transport. The AudioDevice user registers an |
| 19 // AudioDevice::RenderCallback at construction and will be polled by the | 19 // AudioDevice::RenderCallback at construction and will be polled by the |
|
scherkus (not reviewing)
2012/02/01 22:56:12
update docs?
vrk (LEFT CHROMIUM)
2012/02/02 21:05:41
Changed a few words, but otherwise these comments
| |
| 20 // AudioDevice for audio to be played out by the underlying audio layers. | 20 // AudioDevice for audio to be played out by the underlying audio layers. |
| 21 // | 21 // |
| 22 // State sequences. | 22 // State sequences. |
| 23 // | 23 // |
| 24 // Task [IO thread] IPC [IO thread] | 24 // Task [IO thread] IPC [IO thread] |
| 25 // | 25 // |
| 26 // Start -> InitializeOnIOThread ------> AudioHostMsg_CreateStream --------> | 26 // Start -> InitializeOnIOThread ------> AudioHostMsg_CreateStream --------> |
| 27 // <- OnLowLatencyCreated <- AudioMsg_NotifyLowLatencyStreamCreated <- | 27 // <- OnStreamCreated <- AudioMsg_NotifyStreamCreated <- |
| 28 // ---> PlayOnIOThread -----------> AudioHostMsg_PlayStream --------> | 28 // ---> PlayOnIOThread -----------> AudioHostMsg_PlayStream --------> |
| 29 // | 29 // |
| 30 // Optionally Play() / Pause() sequences may occur: | 30 // Optionally Play() / Pause() sequences may occur: |
| 31 // Play -> PlayOnIOThread --------------> AudioHostMsg_PlayStream ---------> | 31 // Play -> PlayOnIOThread --------------> AudioHostMsg_PlayStream ---------> |
| 32 // Pause -> PauseOnIOThread ------------> AudioHostMsg_PauseStream --------> | 32 // Pause -> PauseOnIOThread ------------> AudioHostMsg_PauseStream --------> |
| 33 // (note that Play() / Pause() sequences before OnLowLatencyCreated are | 33 // (note that Play() / Pause() sequences before OnStreamCreated are |
| 34 // deferred until OnLowLatencyCreated, with the last valid state being used) | 34 // deferred until OnStreamCreated, with the last valid state being used) |
| 35 // | 35 // |
| 36 // AudioDevice::Render => audio transport on audio thread with low latency => | 36 // AudioDevice::Render => audio transport on audio thread with low latency => |
| 37 // | | 37 // | |
| 38 // Stop --> ShutDownOnIOThread --------> AudioHostMsg_CloseStream -> Close | 38 // Stop --> ShutDownOnIOThread --------> AudioHostMsg_CloseStream -> Close |
| 39 // | 39 // |
| 40 // This class utilizes several threads during its lifetime, namely: | 40 // This class utilizes several threads during its lifetime, namely: |
| 41 // 1. Creating thread. | 41 // 1. Creating thread. |
| 42 // Must be the main render thread. | 42 // Must be the main render thread. |
| 43 // 2. Control thread (may be the main render thread or another thread). | 43 // 2. Control thread (may be the main render thread or another thread). |
| 44 // The methods: Start(), Stop(), Play(), Pause(), SetVolume() | 44 // The methods: Start(), Stop(), Play(), Pause(), SetVolume() |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 virtual bool SetVolume(double volume) OVERRIDE; | 125 virtual bool SetVolume(double volume) OVERRIDE; |
| 126 | 126 |
| 127 // Gets the playback volume, with range [0.0, 1.0] inclusive. | 127 // Gets the playback volume, with range [0.0, 1.0] inclusive. |
| 128 virtual void GetVolume(double* volume) OVERRIDE; | 128 virtual void GetVolume(double* volume) OVERRIDE; |
| 129 | 129 |
| 130 double sample_rate() const { return sample_rate_; } | 130 double sample_rate() const { return sample_rate_; } |
| 131 size_t buffer_size() const { return buffer_size_; } | 131 size_t buffer_size() const { return buffer_size_; } |
| 132 | 132 |
| 133 // Methods called on IO thread ---------------------------------------------- | 133 // Methods called on IO thread ---------------------------------------------- |
| 134 // AudioMessageFilter::Delegate methods, called by AudioMessageFilter. | 134 // AudioMessageFilter::Delegate methods, called by AudioMessageFilter. |
| 135 virtual void OnRequestPacket(AudioBuffersState buffers_state) OVERRIDE; | |
| 136 virtual void OnStateChanged(AudioStreamState state) OVERRIDE; | 135 virtual void OnStateChanged(AudioStreamState state) OVERRIDE; |
| 137 virtual void OnCreated(base::SharedMemoryHandle handle, | 136 virtual void OnStreamCreated(base::SharedMemoryHandle handle, |
| 138 uint32 length) OVERRIDE; | 137 base::SyncSocket::Handle socket_handle, |
| 139 virtual void OnLowLatencyCreated(base::SharedMemoryHandle handle, | 138 uint32 length) OVERRIDE; |
| 140 base::SyncSocket::Handle socket_handle, | |
| 141 uint32 length) OVERRIDE; | |
| 142 virtual void OnVolume(double volume) OVERRIDE; | |
| 143 | 139 |
| 144 private: | 140 private: |
| 145 // Magic required by ref_counted.h to avoid any code deleting the object | 141 // Magic required by ref_counted.h to avoid any code deleting the object |
| 146 // accidentally while there are references to it. | 142 // accidentally while there are references to it. |
| 147 friend class base::RefCountedThreadSafe<AudioDevice>; | 143 friend class base::RefCountedThreadSafe<AudioDevice>; |
| 148 virtual ~AudioDevice(); | 144 virtual ~AudioDevice(); |
| 149 | 145 |
| 150 // Methods called on IO thread ---------------------------------------------- | 146 // Methods called on IO thread ---------------------------------------------- |
| 151 // The following methods are tasks posted on the IO thread that needs to | 147 // The following methods are tasks posted on the IO thread that needs to |
| 152 // be executed on that thread. They interact with AudioMessageFilter and | 148 // be executed on that thread. They interact with AudioMessageFilter and |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 // Must only be modified on the IO thread and when the thread is not running. | 196 // Must only be modified on the IO thread and when the thread is not running. |
| 201 scoped_ptr<base::DelegateSimpleThread> audio_thread_; | 197 scoped_ptr<base::DelegateSimpleThread> audio_thread_; |
| 202 | 198 |
| 203 // Cached audio message filter (lives on the main render thread). | 199 // Cached audio message filter (lives on the main render thread). |
| 204 scoped_refptr<AudioMessageFilter> filter_; | 200 scoped_refptr<AudioMessageFilter> filter_; |
| 205 | 201 |
| 206 // Our stream ID on the message filter. Only accessed on the IO thread. | 202 // Our stream ID on the message filter. Only accessed on the IO thread. |
| 207 // Must only be modified on the IO thread. | 203 // Must only be modified on the IO thread. |
| 208 int32 stream_id_; | 204 int32 stream_id_; |
| 209 | 205 |
| 210 // State of Play() / Pause() calls before OnLowLatencyCreated() is called. | 206 // State of Play() / Pause() calls before OnStreamCreated() is called. |
| 211 bool play_on_start_; | 207 bool play_on_start_; |
| 212 | 208 |
| 213 // Set to |true| when OnLowLatencyCreated() is called. | 209 // Set to |true| when OnStreamCreated() is called. |
| 214 // Set to |false| when ShutDownOnIOThread() is called. | 210 // Set to |false| when ShutDownOnIOThread() is called. |
| 215 // This is for use with play_on_start_ to track Play() / Pause() state. | 211 // This is for use with play_on_start_ to track Play() / Pause() state. |
| 216 // Must only be touched from the IO thread. | 212 // Must only be touched from the IO thread. |
| 217 bool is_started_; | 213 bool is_started_; |
| 218 | 214 |
| 219 // Data transfer between browser and render process uses a combination | 215 // Data transfer between browser and render process uses a combination |
| 220 // of sync sockets and shared memory to provide lowest possible latency. | 216 // of sync sockets and shared memory to provide lowest possible latency. |
| 221 // These variables must only be set on the IO thread while the audio_thread_ | 217 // These variables must only be set on the IO thread while the audio_thread_ |
| 222 // is not running. | 218 // is not running. |
| 223 base::SharedMemoryHandle shared_memory_handle_; | 219 base::SharedMemoryHandle shared_memory_handle_; |
| 224 scoped_ptr<base::CancelableSyncSocket> audio_socket_; | 220 scoped_ptr<base::CancelableSyncSocket> audio_socket_; |
| 225 int memory_length_; | 221 int memory_length_; |
| 226 | 222 |
| 227 DISALLOW_COPY_AND_ASSIGN(AudioDevice); | 223 DISALLOW_COPY_AND_ASSIGN(AudioDevice); |
| 228 }; | 224 }; |
| 229 | 225 |
| 230 #endif // CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_H_ | 226 #endif // CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_H_ |
| OLD | NEW |