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/bind.h" | |
11 #include "base/memory/ptr_util.h" | |
10 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
11 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "media/audio/audio_debug_recording_helper.h" | |
12 #include "media/audio/audio_device_description.h" | 15 #include "media/audio/audio_device_description.h" |
16 #include "media/audio/audio_file_writer.h" | |
13 #include "media/audio/audio_manager_base.h" | 17 #include "media/audio/audio_manager_base.h" |
14 #include "media/audio/pulse/pulse_util.h" | 18 #include "media/audio/pulse/pulse_util.h" |
15 #include "media/base/audio_sample_types.h" | 19 #include "media/base/audio_sample_types.h" |
16 | 20 |
17 namespace media { | 21 namespace media { |
18 | 22 |
19 using pulse::AutoPulseLock; | 23 using pulse::AutoPulseLock; |
20 using pulse::WaitForOperationCompletion; | 24 using pulse::WaitForOperationCompletion; |
21 | 25 |
22 // static, pa_stream_notify_cb | 26 // static, pa_stream_notify_cb |
(...skipping 28 matching lines...) Expand all Loading... | |
51 // want 32 because we're outputting | 55 // want 32 because we're outputting |
52 // floats. | 56 // floats. |
53 32, | 57 32, |
54 params.frames_per_buffer())), | 58 params.frames_per_buffer())), |
55 device_id_(device_id), | 59 device_id_(device_id), |
56 manager_(manager), | 60 manager_(manager), |
57 pa_context_(NULL), | 61 pa_context_(NULL), |
58 pa_mainloop_(NULL), | 62 pa_mainloop_(NULL), |
59 pa_stream_(NULL), | 63 pa_stream_(NULL), |
60 volume_(1.0f), | 64 volume_(1.0f), |
61 source_callback_(NULL) { | 65 source_callback_(NULL), |
66 debug_recording_helper_(base::MakeUnique<AudioDebugRecordingHelper>( | |
67 manager, | |
68 manager_->GetTaskRunner())) { | |
62 CHECK(params_.IsValid()); | 69 CHECK(params_.IsValid()); |
63 audio_bus_ = AudioBus::Create(params_); | 70 audio_bus_ = AudioBus::Create(params_); |
64 } | 71 } |
65 | 72 |
66 PulseAudioOutputStream::~PulseAudioOutputStream() { | 73 PulseAudioOutputStream::~PulseAudioOutputStream() { |
67 // All internal structures should already have been freed in Close(), which | 74 // All internal structures should already have been freed in Close(), which |
68 // calls AudioManagerBase::ReleaseOutputStream() which deletes this object. | 75 // calls AudioManagerBase::ReleaseOutputStream() which deletes this object. |
69 DCHECK(!pa_stream_); | 76 DCHECK(!pa_stream_); |
70 DCHECK(!pa_context_); | 77 DCHECK(!pa_context_); |
71 DCHECK(!pa_mainloop_); | 78 DCHECK(!pa_mainloop_); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 if (frames_filled < audio_bus_->frames()) { | 156 if (frames_filled < audio_bus_->frames()) { |
150 audio_bus_->ZeroFramesPartial( | 157 audio_bus_->ZeroFramesPartial( |
151 frames_filled, audio_bus_->frames() - frames_filled); | 158 frames_filled, audio_bus_->frames() - frames_filled); |
152 } | 159 } |
153 | 160 |
154 audio_bus_->Scale(volume_); | 161 audio_bus_->Scale(volume_); |
155 audio_bus_->ToInterleaved<Float32SampleTypeTraits>( | 162 audio_bus_->ToInterleaved<Float32SampleTypeTraits>( |
156 audio_bus_->frames(), reinterpret_cast<float*>(buffer)); | 163 audio_bus_->frames(), reinterpret_cast<float*>(buffer)); |
157 } else { | 164 } else { |
158 memset(buffer, 0, bytes_to_fill); | 165 memset(buffer, 0, bytes_to_fill); |
166 | |
167 // If we'll write the data to a debug file, also zero out the |audio_bus_| | |
168 // as it will be copied. | |
169 if (debug_recording_helper_->WillWrite()) | |
170 audio_bus_->Zero(); | |
159 } | 171 } |
160 | 172 |
173 debug_recording_helper_->MaybeWrite(audio_bus_.get()); | |
Max Morin
2017/01/20 07:49:09
Move this below call to PA, to reduce risk of time
Henrik Grunell
2017/01/20 10:38:56
Good point. Done.
| |
174 | |
161 if (pa_stream_write(pa_stream_, buffer, bytes_to_fill, NULL, 0LL, | 175 if (pa_stream_write(pa_stream_, buffer, bytes_to_fill, NULL, 0LL, |
162 PA_SEEK_RELATIVE) < 0) { | 176 PA_SEEK_RELATIVE) < 0) { |
163 if (source_callback_) { | 177 if (source_callback_) { |
164 source_callback_->OnError(this); | 178 source_callback_->OnError(this); |
165 } | 179 } |
166 } | 180 } |
167 | 181 |
168 // NOTE: As mentioned above, |bytes_remaining| may be negative after this. | 182 // NOTE: As mentioned above, |bytes_remaining| may be negative after this. |
169 bytes_remaining -= bytes_to_fill; | 183 bytes_remaining -= bytes_to_fill; |
170 | 184 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 AutoPulseLock auto_lock(pa_mainloop_); | 252 AutoPulseLock auto_lock(pa_mainloop_); |
239 volume_ = static_cast<float>(volume); | 253 volume_ = static_cast<float>(volume); |
240 } | 254 } |
241 | 255 |
242 void PulseAudioOutputStream::GetVolume(double* volume) { | 256 void PulseAudioOutputStream::GetVolume(double* volume) { |
243 DCHECK(thread_checker_.CalledOnValidThread()); | 257 DCHECK(thread_checker_.CalledOnValidThread()); |
244 | 258 |
245 *volume = volume_; | 259 *volume = volume_; |
246 } | 260 } |
247 | 261 |
262 void PulseAudioOutputStream::EnableDebugRecording( | |
263 const base::FilePath& file_name) { | |
264 debug_recording_helper_->EnableDebugRecording(params_, file_name); | |
265 } | |
266 | |
267 void PulseAudioOutputStream::DisableDebugRecording() { | |
268 debug_recording_helper_->DisableDebugRecording(); | |
269 } | |
270 | |
248 } // namespace media | 271 } // namespace media |
OLD | NEW |