Chromium Code Reviews| 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 "base/time/time.h" |
| 12 #include "media/audio/audio_device_description.h" | 12 #include "media/audio/audio_device_description.h" |
| 13 #include "media/audio/audio_manager_base.h" | 13 #include "media/audio/audio_manager_base.h" |
| 14 #include "media/audio/pulse/pulse_util.h" | 14 #include "media/audio/pulse/pulse_util.h" |
| 15 #include "media/base/audio_sample_types.h" | 15 #include "media/base/audio_sample_types.h" |
| 16 | 16 |
| 17 #include "base/debug/stack_trace.h" | |
| 18 | |
| 17 namespace media { | 19 namespace media { |
| 18 | 20 |
| 19 using pulse::AutoPulseLock; | 21 using pulse::AutoPulseLock; |
| 20 using pulse::WaitForOperationCompletion; | 22 using pulse::WaitForOperationCompletion; |
| 21 | 23 |
| 22 // static, pa_stream_notify_cb | 24 // static, pa_stream_notify_cb |
| 23 void PulseAudioOutputStream::StreamNotifyCallback(pa_stream* s, void* p_this) { | 25 void PulseAudioOutputStream::StreamNotifyCallback(pa_stream* s, void* p_this) { |
| 24 PulseAudioOutputStream* stream = static_cast<PulseAudioOutputStream*>(p_this); | 26 PulseAudioOutputStream* stream = static_cast<PulseAudioOutputStream*>(p_this); |
| 25 | 27 |
| 26 // Forward unexpected failures to the AudioSourceCallback if available. All | 28 // Forward unexpected failures to the AudioSourceCallback if available. All |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 52 // floats. | 54 // floats. |
| 53 32, | 55 32, |
| 54 params.frames_per_buffer())), | 56 params.frames_per_buffer())), |
| 55 device_id_(device_id), | 57 device_id_(device_id), |
| 56 manager_(manager), | 58 manager_(manager), |
| 57 pa_context_(NULL), | 59 pa_context_(NULL), |
| 58 pa_mainloop_(NULL), | 60 pa_mainloop_(NULL), |
| 59 pa_stream_(NULL), | 61 pa_stream_(NULL), |
| 60 volume_(1.0f), | 62 volume_(1.0f), |
| 61 source_callback_(NULL) { | 63 source_callback_(NULL) { |
| 64 // base::debug::StackTrace().Print(); | |
| 62 CHECK(params_.IsValid()); | 65 CHECK(params_.IsValid()); |
| 63 audio_bus_ = AudioBus::Create(params_); | 66 audio_bus_ = AudioBus::Create(params_); |
| 64 } | 67 } |
| 65 | 68 |
| 66 PulseAudioOutputStream::~PulseAudioOutputStream() { | 69 PulseAudioOutputStream::~PulseAudioOutputStream() { |
| 67 // All internal structures should already have been freed in Close(), which | 70 // All internal structures should already have been freed in Close(), which |
| 68 // calls AudioManagerBase::ReleaseOutputStream() which deletes this object. | 71 // calls AudioManagerBase::ReleaseOutputStream() which deletes this object. |
| 69 DCHECK(!pa_stream_); | 72 DCHECK(!pa_stream_); |
| 70 DCHECK(!pa_context_); | 73 DCHECK(!pa_context_); |
| 71 DCHECK(!pa_mainloop_); | 74 DCHECK(!pa_mainloop_); |
| 72 } | 75 } |
| 73 | 76 |
| 74 bool PulseAudioOutputStream::Open() { | 77 bool PulseAudioOutputStream::Open() { |
| 75 DCHECK(thread_checker_.CalledOnValidThread()); | 78 DCHECK(thread_checker_.CalledOnValidThread()); |
| 79 // base::debug::StackTrace().Print(); | |
| 76 return pulse::CreateOutputStream( | 80 return pulse::CreateOutputStream( |
| 77 &pa_mainloop_, &pa_context_, &pa_stream_, params_, device_id_, | 81 &pa_mainloop_, &pa_context_, &pa_stream_, params_, device_id_, |
| 78 AudioManager::GetGlobalAppName(), &StreamNotifyCallback, | 82 AudioManager::GetGlobalAppName(), &StreamNotifyCallback, |
| 79 &StreamRequestCallback, this); | 83 &StreamRequestCallback, this); |
| 80 } | 84 } |
| 81 | 85 |
| 82 void PulseAudioOutputStream::Reset() { | 86 void PulseAudioOutputStream::Reset() { |
| 83 if (!pa_mainloop_) { | 87 if (!pa_mainloop_) { |
| 84 DCHECK(!pa_stream_); | 88 DCHECK(!pa_stream_); |
| 85 DCHECK(!pa_context_); | 89 DCHECK(!pa_context_); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 // command thread. | 186 // command thread. |
| 183 if (source_callback_ && bytes_remaining > 0) | 187 if (source_callback_ && bytes_remaining > 0) |
| 184 base::PlatformThread::Sleep(params_.GetBufferDuration() / 4); | 188 base::PlatformThread::Sleep(params_.GetBufferDuration() / 4); |
| 185 } | 189 } |
| 186 } | 190 } |
| 187 | 191 |
| 188 void PulseAudioOutputStream::Start(AudioSourceCallback* callback) { | 192 void PulseAudioOutputStream::Start(AudioSourceCallback* callback) { |
| 189 DCHECK(thread_checker_.CalledOnValidThread()); | 193 DCHECK(thread_checker_.CalledOnValidThread()); |
| 190 CHECK(callback); | 194 CHECK(callback); |
| 191 CHECK(pa_stream_); | 195 CHECK(pa_stream_); |
| 196 // base::debug::StackTrace().Print(); | |
| 192 | 197 |
| 193 AutoPulseLock auto_lock(pa_mainloop_); | 198 AutoPulseLock auto_lock(pa_mainloop_); |
| 194 | 199 |
| 195 // Ensure the context and stream are ready. | 200 // Ensure the context and stream are ready. |
| 196 if (pa_context_get_state(pa_context_) != PA_CONTEXT_READY && | 201 if (pa_context_get_state(pa_context_) != PA_CONTEXT_READY && |
| 197 pa_stream_get_state(pa_stream_) != PA_STREAM_READY) { | 202 pa_stream_get_state(pa_stream_) != PA_STREAM_READY) { |
| 198 callback->OnError(this); | 203 callback->OnError(this); |
| 199 return; | 204 return; |
| 200 } | 205 } |
| 201 | 206 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 AutoPulseLock auto_lock(pa_mainloop_); | 243 AutoPulseLock auto_lock(pa_mainloop_); |
| 239 volume_ = static_cast<float>(volume); | 244 volume_ = static_cast<float>(volume); |
| 240 } | 245 } |
| 241 | 246 |
| 242 void PulseAudioOutputStream::GetVolume(double* volume) { | 247 void PulseAudioOutputStream::GetVolume(double* volume) { |
| 243 DCHECK(thread_checker_.CalledOnValidThread()); | 248 DCHECK(thread_checker_.CalledOnValidThread()); |
| 244 | 249 |
| 245 *volume = volume_; | 250 *volume = volume_; |
| 246 } | 251 } |
| 247 | 252 |
| 253 void PulseAudioOutputStream::EnableDebugRecording( | |
| 254 const base::FilePath& file_name) {} | |
|
Henrik Grunell
2016/12/16 14:12:59
Create and start the file writer here, if OK to mo
| |
| 255 | |
| 256 void PulseAudioOutputStream::DisableDebugRecording() {} | |
| 257 | |
| 248 } // namespace media | 258 } // namespace media |
| OLD | NEW |