pulse_util.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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
14namespace media {
15
16namespace pulse {
17
18// A helper class that acquires pa_threaded_mainloop_lock() while in scope.
19class AutoPulseLock {
20 public:
21  explicit AutoPulseLock(pa_threaded_mainloop* pa_mainloop)
22      : pa_mainloop_(pa_mainloop) {
23    pa_threaded_mainloop_lock(pa_mainloop_);
24  }
25
26  ~AutoPulseLock() {
27    pa_threaded_mainloop_unlock(pa_mainloop_);
28  }
29
30 private:
31  pa_threaded_mainloop* pa_mainloop_;
32  DISALLOW_COPY_AND_ASSIGN(AutoPulseLock);
33};
34
35// Triggers pa_threaded_mainloop_signal() to avoid deadlocks.
36void StreamSuccessCallback(pa_stream* s, int error, void* mainloop);
37void ContextStateCallback(pa_context* context, void* mainloop);
38
39pa_sample_format_t BitsToPASampleFormat(int bits_per_sample);
40
41pa_channel_map ChannelLayoutToPAChannelMap(ChannelLayout channel_layout);
42
43void WaitForOperationCompletion(pa_threaded_mainloop* pa_mainloop,
44                                pa_operation* operation);
45
46int GetHardwareLatencyInBytes(pa_stream* stream,
47                              int sample_rate,
48                              int bytes_per_frame);
49
50}  // namespace pulse
51
52}  // namespace media
53
54#endif  // MEDIA_AUDIO_PULSE_PULSE_UTIL_H_
55