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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 82 |
83 message_loop()->PostTask(FROM_HERE, | 83 message_loop()->PostTask(FROM_HERE, |
84 base::Bind(&AudioOutputDevice::ShutDownOnIOThread, this)); | 84 base::Bind(&AudioOutputDevice::ShutDownOnIOThread, this)); |
85 } | 85 } |
86 | 86 |
87 void AudioOutputDevice::Play() { | 87 void AudioOutputDevice::Play() { |
88 message_loop()->PostTask(FROM_HERE, | 88 message_loop()->PostTask(FROM_HERE, |
89 base::Bind(&AudioOutputDevice::PlayOnIOThread, this)); | 89 base::Bind(&AudioOutputDevice::PlayOnIOThread, this)); |
90 } | 90 } |
91 | 91 |
92 void AudioOutputDevice::Pause(bool flush) { | 92 void AudioOutputDevice::Pause() { |
93 message_loop()->PostTask(FROM_HERE, | 93 message_loop()->PostTask(FROM_HERE, |
94 base::Bind(&AudioOutputDevice::PauseOnIOThread, this, flush)); | 94 base::Bind(&AudioOutputDevice::PauseOnIOThread, this)); |
95 } | 95 } |
96 | 96 |
97 bool AudioOutputDevice::SetVolume(double volume) { | 97 bool AudioOutputDevice::SetVolume(double volume) { |
98 if (volume < 0 || volume > 1.0) | 98 if (volume < 0 || volume > 1.0) |
99 return false; | 99 return false; |
100 | 100 |
101 if (!message_loop()->PostTask(FROM_HERE, | 101 if (!message_loop()->PostTask(FROM_HERE, |
102 base::Bind(&AudioOutputDevice::SetVolumeOnIOThread, this, volume))) { | 102 base::Bind(&AudioOutputDevice::SetVolumeOnIOThread, this, volume))) { |
103 return false; | 103 return false; |
104 } | 104 } |
(...skipping 14 matching lines...) Expand all Loading... |
119 DCHECK(message_loop()->BelongsToCurrentThread()); | 119 DCHECK(message_loop()->BelongsToCurrentThread()); |
120 if (state_ == PAUSED) { | 120 if (state_ == PAUSED) { |
121 ipc_->PlayStream(stream_id_); | 121 ipc_->PlayStream(stream_id_); |
122 state_ = PLAYING; | 122 state_ = PLAYING; |
123 play_on_start_ = false; | 123 play_on_start_ = false; |
124 } else { | 124 } else { |
125 play_on_start_ = true; | 125 play_on_start_ = true; |
126 } | 126 } |
127 } | 127 } |
128 | 128 |
129 void AudioOutputDevice::PauseOnIOThread(bool flush) { | 129 void AudioOutputDevice::PauseOnIOThread() { |
130 DCHECK(message_loop()->BelongsToCurrentThread()); | 130 DCHECK(message_loop()->BelongsToCurrentThread()); |
131 if (state_ == PLAYING) { | 131 if (state_ == PLAYING) { |
132 ipc_->PauseStream(stream_id_); | 132 ipc_->PauseStream(stream_id_); |
133 if (flush) | |
134 ipc_->FlushStream(stream_id_); | |
135 state_ = PAUSED; | 133 state_ = PAUSED; |
136 } else { | |
137 // Note that |flush| isn't relevant here since this is the case where | |
138 // the stream is first starting. | |
139 } | 134 } |
140 play_on_start_ = false; | 135 play_on_start_ = false; |
141 } | 136 } |
142 | 137 |
143 void AudioOutputDevice::ShutDownOnIOThread() { | 138 void AudioOutputDevice::ShutDownOnIOThread() { |
144 DCHECK(message_loop()->BelongsToCurrentThread()); | 139 DCHECK(message_loop()->BelongsToCurrentThread()); |
145 | 140 |
146 // Make sure we don't call shutdown more than once. | 141 // Make sure we don't call shutdown more than once. |
147 if (state_ >= CREATING_STREAM) { | 142 if (state_ >= CREATING_STREAM) { |
148 ipc_->CloseStream(stream_id_); | 143 ipc_->CloseStream(stream_id_); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 // TODO(dalecurtis): Technically this is not always correct. Due to channel | 320 // TODO(dalecurtis): Technically this is not always correct. Due to channel |
326 // padding for alignment, there may be more data available than this. We're | 321 // padding for alignment, there may be more data available than this. We're |
327 // relying on AudioSyncReader::Read() to parse this with that in mind. Rename | 322 // relying on AudioSyncReader::Read() to parse this with that in mind. Rename |
328 // these methods to Set/GetActualFrameCount(). | 323 // these methods to Set/GetActualFrameCount(). |
329 SetActualDataSizeInBytes( | 324 SetActualDataSizeInBytes( |
330 &shared_memory_, memory_length_, | 325 &shared_memory_, memory_length_, |
331 num_frames * sizeof(*output_bus_->channel(0)) * output_bus_->channels()); | 326 num_frames * sizeof(*output_bus_->channel(0)) * output_bus_->channels()); |
332 } | 327 } |
333 | 328 |
334 } // namespace media. | 329 } // namespace media. |
OLD | NEW |