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/pulse/pulse_output.h" | 5 #include "media/audio/pulse/pulse_output.h" |
6 | 6 |
7 #include <pulse/pulseaudio.h> | 7 #include <pulse/pulseaudio.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 11 #include "base/time/time.h" |
11 #include "media/audio/audio_device_description.h" | 12 #include "media/audio/audio_device_description.h" |
12 #include "media/audio/audio_manager_base.h" | 13 #include "media/audio/audio_manager_base.h" |
13 #include "media/audio/pulse/pulse_util.h" | 14 #include "media/audio/pulse/pulse_util.h" |
14 | 15 |
15 namespace media { | 16 namespace media { |
16 | 17 |
17 using pulse::AutoPulseLock; | 18 using pulse::AutoPulseLock; |
18 using pulse::WaitForOperationCompletion; | 19 using pulse::WaitForOperationCompletion; |
19 | 20 |
20 // static, pa_stream_notify_cb | 21 // static, pa_stream_notify_cb |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 CHECK_EQ(bytes_to_fill, static_cast<size_t>(params_.GetBytesPerBuffer())); | 128 CHECK_EQ(bytes_to_fill, static_cast<size_t>(params_.GetBytesPerBuffer())); |
128 | 129 |
129 // NOTE: |bytes_to_fill| may be larger than |requested_bytes| now, this is | 130 // NOTE: |bytes_to_fill| may be larger than |requested_bytes| now, this is |
130 // okay since pa_stream_begin_write() is the authoritative source on how | 131 // okay since pa_stream_begin_write() is the authoritative source on how |
131 // much can be written. | 132 // much can be written. |
132 | 133 |
133 int frames_filled = 0; | 134 int frames_filled = 0; |
134 if (source_callback_) { | 135 if (source_callback_) { |
135 const uint32_t hardware_delay = pulse::GetHardwareLatencyInBytes( | 136 const uint32_t hardware_delay = pulse::GetHardwareLatencyInBytes( |
136 pa_stream_, params_.sample_rate(), params_.GetBytesPerFrame()); | 137 pa_stream_, params_.sample_rate(), params_.GetBytesPerFrame()); |
137 frames_filled = | 138 frames_filled = source_callback_->OnMoreData( |
138 source_callback_->OnMoreData(audio_bus_.get(), hardware_delay, 0); | 139 audio_bus_.get(), hardware_delay, base::TimeDelta(), 0); |
139 | 140 |
140 // Zero any unfilled data so it plays back as silence. | 141 // Zero any unfilled data so it plays back as silence. |
141 if (frames_filled < audio_bus_->frames()) { | 142 if (frames_filled < audio_bus_->frames()) { |
142 audio_bus_->ZeroFramesPartial( | 143 audio_bus_->ZeroFramesPartial( |
143 frames_filled, audio_bus_->frames() - frames_filled); | 144 frames_filled, audio_bus_->frames() - frames_filled); |
144 } | 145 } |
145 | 146 |
146 // Note: If this ever changes to output raw float the data must be clipped | 147 // Note: If this ever changes to output raw float the data must be clipped |
147 // and sanitized since it may come from an untrusted source such as NaCl. | 148 // and sanitized since it may come from an untrusted source such as NaCl. |
148 audio_bus_->Scale(volume_); | 149 audio_bus_->Scale(volume_); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 volume_ = static_cast<float>(volume); | 231 volume_ = static_cast<float>(volume); |
231 } | 232 } |
232 | 233 |
233 void PulseAudioOutputStream::GetVolume(double* volume) { | 234 void PulseAudioOutputStream::GetVolume(double* volume) { |
234 DCHECK(thread_checker_.CalledOnValidThread()); | 235 DCHECK(thread_checker_.CalledOnValidThread()); |
235 | 236 |
236 *volume = volume_; | 237 *volume = volume_; |
237 } | 238 } |
238 | 239 |
239 } // namespace media | 240 } // namespace media |
OLD | NEW |