Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MEDIA_AUDIO_PULSE_PULSE_UTIL_H_ | |
| 6 #define MEDIA_AUDIO_PULSE_PULSE_UTIL_H_ | |
| 7 | |
| 8 #include <pulse/pulseaudio.h> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "media/audio/audio_device_name.h" | |
| 12 #include "media/base/channel_layout.h" | |
| 13 | |
| 14 namespace media { | |
| 15 | |
| 16 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.
| |
| 17 public: | |
| 18 PulseInputObject(); | |
| 19 ~PulseInputObject(); | |
| 20 | |
| 21 void GetInputDevices(AudioDeviceNames* device_names); | |
| 22 int GetNativeSampleRate(); | |
| 23 | |
| 24 bool has_pulse() const { return initialized_; } | |
| 25 pa_threaded_mainloop* mainloop() const { return pa_mainloop_; } | |
| 26 pa_context* context() const { return pa_context_; } | |
| 27 | |
| 28 private: | |
| 29 void Initialize(); | |
| 30 void Terminate(); | |
| 31 | |
| 32 // Called by PulseAudio when |pa_context_| and |pa_stream_| change state. | |
| 33 static void ContextStateCallback(pa_context* context, void* user_data); | |
| 34 | |
| 35 // Callback to get the devices' info like names, used by GetInputDevices(). | |
| 36 static void DevicesInfoCallback(pa_context* context, | |
| 37 const pa_source_info* info, | |
| 38 int error, void* user_data); | |
| 39 | |
| 40 // Callback to get the native sample rate of PulseAudio, used by | |
| 41 // GetNativeSampleRate(). | |
| 42 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.
| |
| 43 const pa_server_info* info, | |
| 44 void* user_data); | |
| 45 | |
| 46 pa_threaded_mainloop* pa_mainloop_; | |
| 47 pa_context* pa_context_; | |
| 48 AudioDeviceNames* devices; | |
| 49 int sample_rate_; | |
| 50 bool initialized_; | |
| 51 | |
| 52 DISALLOW_COPY_AND_ASSIGN(PulseInputObject); | |
| 53 }; | |
| 54 | |
| 55 // A helper class that acquires pa_threaded_mainloop_lock() while in scope. | |
| 56 class AutoPulseLock { | |
| 57 public: | |
| 58 explicit AutoPulseLock(pa_threaded_mainloop* pa_mainloop) | |
| 59 : pa_mainloop_(pa_mainloop) { | |
| 60 pa_threaded_mainloop_lock(pa_mainloop_); | |
| 61 } | |
| 62 | |
| 63 ~AutoPulseLock() { | |
| 64 pa_threaded_mainloop_unlock(pa_mainloop_); | |
| 65 } | |
| 66 | |
| 67 private: | |
| 68 pa_threaded_mainloop* pa_mainloop_; | |
| 69 DISALLOW_COPY_AND_ASSIGN(AutoPulseLock); | |
| 70 }; | |
| 71 | |
| 72 // Triggers pa_threaded_mainloop_signal() to avoid deadlocks. | |
| 73 void StreamSuccessCallback(pa_stream* s, int error, void* mainloop); | |
| 74 | |
| 75 pa_sample_format_t BitsToPASampleFormat(int bits_per_sample); | |
| 76 | |
| 77 pa_channel_map ChannelLayoutToPAChannelMap(ChannelLayout channel_layout); | |
| 78 | |
| 79 void WaitForOperationCompletion(pa_threaded_mainloop* pa_mainloop, | |
| 80 pa_operation* operation); | |
| 81 } | |
| 82 | |
| 83 #endif // MEDIA_AUDIO_PULSE_PULSE_UTIL_H_ | |
| OLD | NEW |