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 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 |
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 -> CreateStreamOnIOThread -----> AudioHostMsg_CreateStream ------> |
27 // <- OnStreamCreated <- AudioMsg_NotifyStreamCreated <- | 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 OnStreamCreated are | 33 // (note that Play() / Pause() sequences before OnStreamCreated are |
34 // deferred until OnStreamCreated, 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 => | 36 // AudioDevice::Render => audio transport on audio thread => |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 89 |
90 // Minimal constructor where Initialize() must be called later. | 90 // Minimal constructor where Initialize() must be called later. |
91 AudioDevice(); | 91 AudioDevice(); |
92 | 92 |
93 AudioDevice(const media::AudioParameters& params, RenderCallback* callback); | 93 AudioDevice(const media::AudioParameters& params, RenderCallback* callback); |
94 | 94 |
95 // AudioRendererSink implementation. | 95 // AudioRendererSink implementation. |
96 | 96 |
97 virtual void Initialize(const media::AudioParameters& params, | 97 virtual void Initialize(const media::AudioParameters& params, |
98 RenderCallback* callback) OVERRIDE; | 98 RenderCallback* callback) OVERRIDE; |
99 // Starts audio playback. | |
100 virtual void Start() OVERRIDE; | 99 virtual void Start() OVERRIDE; |
101 | |
102 // Stops audio playback. | |
103 virtual void Stop() OVERRIDE; | 100 virtual void Stop() OVERRIDE; |
104 | |
105 // Resumes playback if currently paused. | |
106 virtual void Play() OVERRIDE; | 101 virtual void Play() OVERRIDE; |
107 | |
108 // Pauses playback. | |
109 // If |flush| is true then any pending audio that is in the pipeline | |
110 // (has not yet reached the hardware) will be discarded. In this case, | |
111 // when Play() is later called, no previous pending audio will be | |
112 // rendered. | |
113 virtual void Pause(bool flush) OVERRIDE; | 102 virtual void Pause(bool flush) OVERRIDE; |
114 | |
115 // Sets the playback volume, with range [0.0, 1.0] inclusive. | |
116 // Returns |true| on success. | |
117 virtual bool SetVolume(double volume) OVERRIDE; | 103 virtual bool SetVolume(double volume) OVERRIDE; |
118 | |
119 // Gets the playback volume, with range [0.0, 1.0] inclusive. | |
120 virtual void GetVolume(double* volume) OVERRIDE; | 104 virtual void GetVolume(double* volume) OVERRIDE; |
121 | 105 |
122 // Methods called on IO thread ---------------------------------------------- | 106 // Methods called on IO thread ---------------------------------------------- |
123 // AudioMessageFilter::Delegate methods, called by AudioMessageFilter. | 107 // AudioMessageFilter::Delegate methods, called by AudioMessageFilter. |
124 virtual void OnStateChanged(AudioStreamState state) OVERRIDE; | 108 virtual void OnStateChanged(AudioStreamState state) OVERRIDE; |
125 virtual void OnStreamCreated(base::SharedMemoryHandle handle, | 109 virtual void OnStreamCreated(base::SharedMemoryHandle handle, |
126 base::SyncSocket::Handle socket_handle, | 110 base::SyncSocket::Handle socket_handle, |
127 uint32 length) OVERRIDE; | 111 uint32 length) OVERRIDE; |
128 | 112 |
129 private: | 113 private: |
130 // Magic required by ref_counted.h to avoid any code deleting the object | 114 // Magic required by ref_counted.h to avoid any code deleting the object |
131 // accidentally while there are references to it. | 115 // accidentally while there are references to it. |
132 friend class base::RefCountedThreadSafe<AudioDevice>; | 116 friend class base::RefCountedThreadSafe<AudioDevice>; |
133 virtual ~AudioDevice(); | 117 virtual ~AudioDevice(); |
134 | 118 |
135 // Methods called on IO thread ---------------------------------------------- | 119 // Methods called on IO thread ---------------------------------------------- |
136 // The following methods are tasks posted on the IO thread that needs to | 120 // The following methods are tasks posted on the IO thread that needs to |
137 // be executed on that thread. They interact with AudioMessageFilter and | 121 // be executed on that thread. They interact with AudioMessageFilter and |
138 // sends IPC messages on that thread. | 122 // sends IPC messages on that thread. |
139 void InitializeOnIOThread(const media::AudioParameters& params); | 123 void CreateStreamOnIOThread(const media::AudioParameters& params); |
140 void PlayOnIOThread(); | 124 void PlayOnIOThread(); |
141 void PauseOnIOThread(bool flush); | 125 void PauseOnIOThread(bool flush); |
142 void ShutDownOnIOThread(); | 126 void ShutDownOnIOThread(); |
143 void SetVolumeOnIOThread(double volume); | 127 void SetVolumeOnIOThread(double volume); |
144 | 128 |
145 void Send(IPC::Message* message); | 129 void Send(IPC::Message* message); |
146 | 130 |
147 // MessageLoop::DestructionObserver implementation for the IO loop. | 131 // MessageLoop::DestructionObserver implementation for the IO loop. |
148 // If the IO loop dies before we do, we shut down the audio thread from here. | 132 // If the IO loop dies before we do, we shut down the audio thread from here. |
149 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; | 133 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; |
(...skipping 28 matching lines...) Expand all Loading... |
178 // guard to control stopping and starting the audio thread. | 162 // guard to control stopping and starting the audio thread. |
179 base::Lock audio_thread_lock_; | 163 base::Lock audio_thread_lock_; |
180 AudioDeviceThread audio_thread_; | 164 AudioDeviceThread audio_thread_; |
181 scoped_ptr<AudioDevice::AudioThreadCallback> audio_callback_; | 165 scoped_ptr<AudioDevice::AudioThreadCallback> audio_callback_; |
182 | 166 |
183 | 167 |
184 DISALLOW_COPY_AND_ASSIGN(AudioDevice); | 168 DISALLOW_COPY_AND_ASSIGN(AudioDevice); |
185 }; | 169 }; |
186 | 170 |
187 #endif // CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_H_ | 171 #endif // CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_H_ |
OLD | NEW |