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 #include "media/audio/audio_output_device.h" | 5 #include "media/audio/audio_output_device.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 RenderCallback* callback) { | 66 RenderCallback* callback) { |
67 DCHECK_GE(input_channels, 0); | 67 DCHECK_GE(input_channels, 0); |
68 DCHECK_LT(input_channels, limits::kMaxChannels); | 68 DCHECK_LT(input_channels, limits::kMaxChannels); |
69 input_channels_ = input_channels; | 69 input_channels_ = input_channels; |
70 Initialize(params, callback); | 70 Initialize(params, callback); |
71 } | 71 } |
72 | 72 |
73 AudioOutputDevice::~AudioOutputDevice() { | 73 AudioOutputDevice::~AudioOutputDevice() { |
74 // The current design requires that the user calls Stop() before deleting | 74 // The current design requires that the user calls Stop() before deleting |
75 // this class. | 75 // this class. |
| 76 LOG(ERROR) << "AudioOutputDevice::~@" << this; |
76 DCHECK(audio_thread_.IsStopped()); | 77 DCHECK(audio_thread_.IsStopped()); |
77 | 78 |
78 if (ipc_) | 79 if (ipc_) |
79 ipc_->RemoveDelegate(stream_id_); | 80 ipc_->RemoveDelegate(stream_id_); |
80 } | 81 } |
81 | 82 |
82 void AudioOutputDevice::Start() { | 83 void AudioOutputDevice::Start() { |
83 DCHECK(callback_) << "Initialize hasn't been called"; | 84 DCHECK(callback_) << "Initialize hasn't been called"; |
84 message_loop()->PostTask(FROM_HERE, | 85 message_loop()->PostTask(FROM_HERE, |
85 base::Bind(&AudioOutputDevice::CreateStreamOnIOThread, this, | 86 base::Bind(&AudioOutputDevice::CreateStreamOnIOThread, this, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 180 |
180 void AudioOutputDevice::SetVolumeOnIOThread(double volume) { | 181 void AudioOutputDevice::SetVolumeOnIOThread(double volume) { |
181 DCHECK(message_loop()->BelongsToCurrentThread()); | 182 DCHECK(message_loop()->BelongsToCurrentThread()); |
182 if (state_ >= CREATING_STREAM) | 183 if (state_ >= CREATING_STREAM) |
183 ipc_->SetVolume(stream_id_, volume); | 184 ipc_->SetVolume(stream_id_, volume); |
184 } | 185 } |
185 | 186 |
186 void AudioOutputDevice::OnStateChanged(AudioOutputIPCDelegate::State state) { | 187 void AudioOutputDevice::OnStateChanged(AudioOutputIPCDelegate::State state) { |
187 DCHECK(message_loop()->BelongsToCurrentThread()); | 188 DCHECK(message_loop()->BelongsToCurrentThread()); |
188 | 189 |
189 // Do nothing if the stream has been closed. | 190 // Do nothing if the stream has been closed. Don't dereference the callback |
190 if (state_ < CREATING_STREAM) | 191 // object if the audio thread is stopped or stopping. That could mean that |
| 192 // the callback object has been deleted. |
| 193 // TODO(tommi): Add an explicit contract for clearing the callback object. |
| 194 // Possibly require calling Initialize again or provide a callback object via |
| 195 // Start() and clear it in Stop(). |
| 196 if (state_ < CREATING_STREAM || audio_thread_.IsStopped()) |
191 return; | 197 return; |
192 | 198 |
193 if (state == AudioOutputIPCDelegate::kError) { | 199 if (state == AudioOutputIPCDelegate::kError) { |
194 DLOG(WARNING) << "AudioOutputDevice::OnStateChanged(kError)"; | 200 DLOG(WARNING) << "AudioOutputDevice::OnStateChanged(kError)"; |
195 // Don't dereference the callback object if the audio thread | 201 // Don't dereference the callback object if the audio thread |
196 // is stopped or stopping. That could mean that the callback | 202 // is stopped or stopping. That could mean that the callback |
197 // object has been deleted. | 203 // object has been deleted. |
198 // TODO(tommi): Add an explicit contract for clearing the callback | 204 // TODO(tommi): Add an explicit contract for clearing the callback |
199 // object. Possibly require calling Initialize again or provide | 205 // object. Possibly require calling Initialize again or provide |
200 // a callback object via Start() and clear it in Stop(). | 206 // a callback object via Start() and clear it in Stop(). |
201 if (!audio_thread_.IsStopped()) | 207 // if (!audio_thread_.IsStopped()) |
202 callback_->OnRenderError(); | 208 // callback_->OnRenderError(); |
| 209 } else if (state == AudioOutputIPCDelegate::kDeviceChange) { |
| 210 LOG(ERROR) << "AudioOutputDevice::kDeviceChange@" << this; |
| 211 callback_->OnDeviceChange(); |
203 } | 212 } |
204 } | 213 } |
205 | 214 |
206 void AudioOutputDevice::OnStreamCreated( | 215 void AudioOutputDevice::OnStreamCreated( |
207 base::SharedMemoryHandle handle, | 216 base::SharedMemoryHandle handle, |
208 base::SyncSocket::Handle socket_handle, | 217 base::SyncSocket::Handle socket_handle, |
209 int length) { | 218 int length) { |
210 DCHECK(message_loop()->BelongsToCurrentThread()); | 219 DCHECK(message_loop()->BelongsToCurrentThread()); |
211 #if defined(OS_WIN) | 220 #if defined(OS_WIN) |
212 DCHECK(handle); | 221 DCHECK(handle); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 // TODO(dalecurtis): Technically this is not always correct. Due to channel | 343 // TODO(dalecurtis): Technically this is not always correct. Due to channel |
335 // padding for alignment, there may be more data available than this. We're | 344 // padding for alignment, there may be more data available than this. We're |
336 // relying on AudioSyncReader::Read() to parse this with that in mind. Rename | 345 // relying on AudioSyncReader::Read() to parse this with that in mind. Rename |
337 // these methods to Set/GetActualFrameCount(). | 346 // these methods to Set/GetActualFrameCount(). |
338 SetActualDataSizeInBytes( | 347 SetActualDataSizeInBytes( |
339 &shared_memory_, memory_length_, | 348 &shared_memory_, memory_length_, |
340 num_frames * sizeof(*output_bus_->channel(0)) * output_bus_->channels()); | 349 num_frames * sizeof(*output_bus_->channel(0)) * output_bus_->channels()); |
341 } | 350 } |
342 | 351 |
343 } // namespace media. | 352 } // namespace media. |
OLD | NEW |