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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 size_t bytes_to_fill = params_.GetBytesPerBuffer(); | 126 size_t bytes_to_fill = params_.GetBytesPerBuffer(); |
126 CHECK_GE(pa_stream_begin_write(pa_stream_, &buffer, &bytes_to_fill), 0); | 127 CHECK_GE(pa_stream_begin_write(pa_stream_, &buffer, &bytes_to_fill), 0); |
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 base::TimeDelta delay = pulse::GetHardwareLatency(pa_stream_); |
136 pa_stream_, params_.sample_rate(), params_.GetBytesPerFrame()); | 137 frames_filled = source_callback_->OnMoreData( |
137 frames_filled = | 138 delay, base::TimeTicks::Now(), 0, audio_bus_.get()); |
138 source_callback_->OnMoreData(audio_bus_.get(), hardware_delay, 0); | |
139 | 139 |
140 // Zero any unfilled data so it plays back as silence. | 140 // Zero any unfilled data so it plays back as silence. |
141 if (frames_filled < audio_bus_->frames()) { | 141 if (frames_filled < audio_bus_->frames()) { |
142 audio_bus_->ZeroFramesPartial( | 142 audio_bus_->ZeroFramesPartial( |
143 frames_filled, audio_bus_->frames() - frames_filled); | 143 frames_filled, audio_bus_->frames() - frames_filled); |
144 } | 144 } |
145 | 145 |
146 // Note: If this ever changes to output raw float the data must be clipped | 146 // 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. | 147 // and sanitized since it may come from an untrusted source such as NaCl. |
148 audio_bus_->Scale(volume_); | 148 audio_bus_->Scale(volume_); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 volume_ = static_cast<float>(volume); | 230 volume_ = static_cast<float>(volume); |
231 } | 231 } |
232 | 232 |
233 void PulseAudioOutputStream::GetVolume(double* volume) { | 233 void PulseAudioOutputStream::GetVolume(double* volume) { |
234 DCHECK(thread_checker_.CalledOnValidThread()); | 234 DCHECK(thread_checker_.CalledOnValidThread()); |
235 | 235 |
236 *volume = volume_; | 236 *volume = volume_; |
237 } | 237 } |
238 | 238 |
239 } // namespace media | 239 } // namespace media |
OLD | NEW |