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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 // Methods called on IO thread ---------------------------------------------- | 92 // Methods called on IO thread ---------------------------------------------- |
93 // AudioOutputIPCDelegate methods. | 93 // AudioOutputIPCDelegate methods. |
94 virtual void OnStateChanged(AudioOutputIPCDelegate::State state) OVERRIDE; | 94 virtual void OnStateChanged(AudioOutputIPCDelegate::State state) OVERRIDE; |
95 virtual void OnStreamCreated(base::SharedMemoryHandle handle, | 95 virtual void OnStreamCreated(base::SharedMemoryHandle handle, |
96 base::SyncSocket::Handle socket_handle, | 96 base::SyncSocket::Handle socket_handle, |
97 int length) OVERRIDE; | 97 int length) OVERRIDE; |
98 virtual void OnIPCClosed() OVERRIDE; | 98 virtual void OnIPCClosed() OVERRIDE; |
99 | 99 |
100 // Creates an uninitialized AudioOutputDevice. Clients must call Initialize() | 100 // Creates an uninitialized AudioOutputDevice. Clients must call Initialize() |
101 // before using. | 101 // before using. |
102 // TODO(tommi): When all dependencies on |content| have been removed | |
103 // from AudioOutputDevice, move this class over to media/audio. | |
104 AudioOutputDevice(AudioOutputIPC* ipc, | 102 AudioOutputDevice(AudioOutputIPC* ipc, |
105 const scoped_refptr<base::MessageLoopProxy>& io_loop); | 103 const scoped_refptr<base::MessageLoopProxy>& io_loop); |
106 | 104 |
105 // Returns the stream id used with the AudioOutputIPC interface. | |
106 int stream_id() const; | |
107 | |
107 protected: | 108 protected: |
108 // Magic required by ref_counted.h to avoid any code deleting the object | 109 // Magic required by ref_counted.h to avoid any code deleting the object |
109 // accidentally while there are references to it. | 110 // accidentally while there are references to it. |
110 friend class base::RefCountedThreadSafe<AudioOutputDevice>; | 111 friend class base::RefCountedThreadSafe<AudioOutputDevice>; |
111 virtual ~AudioOutputDevice(); | 112 virtual ~AudioOutputDevice(); |
112 | 113 |
113 private: | 114 private: |
115 enum State { | |
116 kIpcClosed, // No more IPCs can take place. | |
scherkus (not reviewing)
2012/11/27 22:55:26
chromium has decreed SHOUTING_STYLE for enum const
miu
2012/11/28 07:26:20
Done.
| |
117 kIdle, // Not started. | |
118 kCreatingStream, // Waiting for OnStreamCreated() to be called back. | |
119 kPaused, // Paused. OnStreamCreated() has been called. Can Play()/Stop(). | |
120 kPlaying, // Playing back. Can Pause()/Stop(). | |
121 }; | |
122 | |
114 // Methods called on IO thread ---------------------------------------------- | 123 // Methods called on IO thread ---------------------------------------------- |
115 // The following methods are tasks posted on the IO thread that needs to | 124 // The following methods are tasks posted on the IO thread that needs to |
116 // be executed on that thread. They interact with AudioMessageFilter and | 125 // be executed on that thread. They interact with AudioMessageFilter and |
117 // sends IPC messages on that thread. | 126 // sends IPC messages on that thread. |
127 void RegisterDelegateOnIOThread(AudioOutputIPC* ipc); | |
118 void CreateStreamOnIOThread(const AudioParameters& params, | 128 void CreateStreamOnIOThread(const AudioParameters& params, |
119 int input_channels); | 129 int input_channels); |
120 void PlayOnIOThread(); | 130 void PlayOnIOThread(); |
121 void PauseOnIOThread(bool flush); | 131 void PauseOnIOThread(bool flush); |
122 void ShutDownOnIOThread(); | 132 void ShutDownOnIOThread(); |
123 void SetVolumeOnIOThread(double volume); | 133 void SetVolumeOnIOThread(double volume); |
124 | 134 |
125 // MessageLoop::DestructionObserver implementation for the IO loop. | 135 // MessageLoop::DestructionObserver implementation for the IO loop. |
126 // If the IO loop dies before we do, we shut down the audio thread from here. | 136 // If the IO loop dies before we do, we shut down the audio thread from here. |
127 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; | 137 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; |
128 | 138 |
129 AudioParameters audio_parameters_; | 139 AudioParameters audio_parameters_; |
130 | 140 |
131 // The number of optional synchronized input channels having the same | 141 // The number of optional synchronized input channels having the same |
132 // sample-rate and buffer-size as specified in audio_parameters_. | 142 // sample-rate and buffer-size as specified in audio_parameters_. |
133 int input_channels_; | 143 int input_channels_; |
134 | 144 |
135 RenderCallback* callback_; | 145 RenderCallback* callback_; |
136 | 146 |
137 // A pointer to the IPC layer that takes care of sending requests over to | 147 // A pointer to the IPC layer that takes care of sending requests over to |
138 // the AudioRendererHost. | 148 // the AudioRendererHost. |
139 AudioOutputIPC* ipc_; | 149 base::WeakPtr<AudioOutputIPC> ipc_; |
140 | 150 |
141 // Our stream ID on the message filter. Only accessed on the IO thread. | 151 // Our stream ID on the message filter. Only accessed on the IO thread. |
142 // Must only be modified on the IO thread. | 152 // Must only be modified on the IO thread. |
143 int stream_id_; | 153 int stream_id_; |
144 | 154 |
155 // Current state (must only be accessed from the IO thread). See comments for | |
156 // State enum above. | |
157 State state_; | |
158 | |
145 // State of Play() / Pause() calls before OnStreamCreated() is called. | 159 // State of Play() / Pause() calls before OnStreamCreated() is called. |
146 bool play_on_start_; | 160 bool play_on_start_; |
147 | 161 |
148 // Set to |true| when OnStreamCreated() is called. | |
149 // Set to |false| when ShutDownOnIOThread() is called. | |
150 // This is for use with play_on_start_ to track Play() / Pause() state. | |
151 // Must only be touched from the IO thread. | |
152 bool is_started_; | |
153 | |
154 // Our audio thread callback class. See source file for details. | 162 // Our audio thread callback class. See source file for details. |
155 class AudioThreadCallback; | 163 class AudioThreadCallback; |
156 | 164 |
157 // In order to avoid a race between OnStreamCreated and Stop(), we use this | 165 // In order to avoid a race between OnStreamCreated and Stop(), we use this |
158 // guard to control stopping and starting the audio thread. | 166 // guard to control stopping and starting the audio thread. |
159 base::Lock audio_thread_lock_; | 167 base::Lock audio_thread_lock_; |
160 AudioDeviceThread audio_thread_; | 168 AudioDeviceThread audio_thread_; |
161 scoped_ptr<AudioOutputDevice::AudioThreadCallback> audio_callback_; | 169 scoped_ptr<AudioOutputDevice::AudioThreadCallback> audio_callback_; |
162 | 170 |
163 // Temporary hack to ignore OnStreamCreated() due to the user calling Stop() | 171 // Temporary hack to ignore OnStreamCreated() due to the user calling Stop() |
164 // so we don't start the audio thread pointing to a potentially freed | 172 // so we don't start the audio thread pointing to a potentially freed |
165 // |callback_|. | 173 // |callback_|. |
166 // | 174 // |
167 // TODO(scherkus): Replace this by changing AudioRendererSink to either accept | 175 // TODO(scherkus): Replace this by changing AudioRendererSink to either accept |
168 // the callback via Start(). See http://crbug.com/151051 for details. | 176 // the callback via Start(). See http://crbug.com/151051 for details. |
169 bool stopping_hack_; | 177 bool stopping_hack_; |
170 | 178 |
171 DISALLOW_COPY_AND_ASSIGN(AudioOutputDevice); | 179 DISALLOW_COPY_AND_ASSIGN(AudioOutputDevice); |
172 }; | 180 }; |
173 | 181 |
174 } // namespace media | 182 } // namespace media |
175 | 183 |
176 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_ | 184 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_ |
OLD | NEW |