Chromium Code Reviews| Index: media/audio/pulse/pulse_util.h |
| diff --git a/media/audio/pulse/pulse_util.h b/media/audio/pulse/pulse_util.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4c2d376f736dc95320e1b898ed1987d94f1b95fe |
| --- /dev/null |
| +++ b/media/audio/pulse/pulse_util.h |
| @@ -0,0 +1,83 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef MEDIA_AUDIO_PULSE_PULSE_UTIL_H_ |
| +#define MEDIA_AUDIO_PULSE_PULSE_UTIL_H_ |
| + |
| +#include <pulse/pulseaudio.h> |
| + |
| +#include "base/basictypes.h" |
| +#include "media/audio/audio_device_name.h" |
| +#include "media/base/channel_layout.h" |
| + |
| +namespace media { |
| + |
| +class PulseInputObject { |
|
DaleCurtis
2013/01/30 02:54:30
Why have this here vs in the pulse input stream?
no longer working on chromium
2013/02/12 17:35:59
It is moved to AudioManagerPulse.
|
| + public: |
| + PulseInputObject(); |
| + ~PulseInputObject(); |
| + |
| + void GetInputDevices(AudioDeviceNames* device_names); |
| + int GetNativeSampleRate(); |
| + |
| + bool has_pulse() const { return initialized_; } |
| + pa_threaded_mainloop* mainloop() const { return pa_mainloop_; } |
| + pa_context* context() const { return pa_context_; } |
| + |
| + private: |
| + void Initialize(); |
| + void Terminate(); |
| + |
| + // Called by PulseAudio when |pa_context_| and |pa_stream_| change state. |
| + static void ContextStateCallback(pa_context* context, void* user_data); |
| + |
| + // Callback to get the devices' info like names, used by GetInputDevices(). |
| + static void DevicesInfoCallback(pa_context* context, |
| + const pa_source_info* info, |
| + int error, void* user_data); |
| + |
| + // Callback to get the native sample rate of PulseAudio, used by |
| + // GetNativeSampleRate(). |
| + static void SamplerateInfoCallback(pa_context* context, |
|
DaleCurtis
2013/01/30 02:54:30
Is this going to pipe into AudioUtil:: somehow? (A
no longer working on chromium
2013/02/12 17:35:59
Done.
|
| + const pa_server_info* info, |
| + void* user_data); |
| + |
| + pa_threaded_mainloop* pa_mainloop_; |
| + pa_context* pa_context_; |
| + AudioDeviceNames* devices; |
| + int sample_rate_; |
| + bool initialized_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PulseInputObject); |
| +}; |
| + |
| +// A helper class that acquires pa_threaded_mainloop_lock() while in scope. |
| +class AutoPulseLock { |
| + public: |
| + explicit AutoPulseLock(pa_threaded_mainloop* pa_mainloop) |
| + : pa_mainloop_(pa_mainloop) { |
| + pa_threaded_mainloop_lock(pa_mainloop_); |
| + } |
| + |
| + ~AutoPulseLock() { |
| + pa_threaded_mainloop_unlock(pa_mainloop_); |
| + } |
| + |
| + private: |
| + pa_threaded_mainloop* pa_mainloop_; |
| + DISALLOW_COPY_AND_ASSIGN(AutoPulseLock); |
| +}; |
| + |
| +// Triggers pa_threaded_mainloop_signal() to avoid deadlocks. |
| +void StreamSuccessCallback(pa_stream* s, int error, void* mainloop); |
| + |
| +pa_sample_format_t BitsToPASampleFormat(int bits_per_sample); |
| + |
| +pa_channel_map ChannelLayoutToPAChannelMap(ChannelLayout channel_layout); |
| + |
| +void WaitForOperationCompletion(pa_threaded_mainloop* pa_mainloop, |
| + pa_operation* operation); |
| +} |
| + |
| +#endif // MEDIA_AUDIO_PULSE_PULSE_UTIL_H_ |