Revert "Omit calls to set composing region when pasting image."
[chromium-blink-merge.git] / media / audio / pulse / pulse_util.h
blob94c4aa4a44627bd2ee86429f349bfc77e58a16b8
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.
5 #ifndef MEDIA_AUDIO_PULSE_PULSE_UTIL_H_
6 #define MEDIA_AUDIO_PULSE_PULSE_UTIL_H_
8 #include <pulse/pulseaudio.h>
10 #include "base/basictypes.h"
11 #include "media/audio/audio_device_name.h"
12 #include "media/base/channel_layout.h"
14 namespace media {
16 class AudioParameters;
18 namespace pulse {
20 // A helper class that acquires pa_threaded_mainloop_lock() while in scope.
21 class AutoPulseLock {
22 public:
23 explicit AutoPulseLock(pa_threaded_mainloop* pa_mainloop)
24 : pa_mainloop_(pa_mainloop) {
25 pa_threaded_mainloop_lock(pa_mainloop_);
28 ~AutoPulseLock() {
29 pa_threaded_mainloop_unlock(pa_mainloop_);
32 private:
33 pa_threaded_mainloop* pa_mainloop_;
34 DISALLOW_COPY_AND_ASSIGN(AutoPulseLock);
37 // Triggers pa_threaded_mainloop_signal() to avoid deadlocks.
38 void StreamSuccessCallback(pa_stream* s, int error, void* mainloop);
39 void ContextStateCallback(pa_context* context, void* mainloop);
41 pa_sample_format_t BitsToPASampleFormat(int bits_per_sample);
43 pa_channel_map ChannelLayoutToPAChannelMap(ChannelLayout channel_layout);
45 void WaitForOperationCompletion(pa_threaded_mainloop* mainloop,
46 pa_operation* operation);
48 int GetHardwareLatencyInBytes(pa_stream* stream,
49 int sample_rate,
50 int bytes_per_frame);
52 // Create a recording stream for the threaded mainloop, return true if success,
53 // otherwise false. |mainloop| and |context| have to be from a valid Pulse
54 // threaded mainloop and the handle of the created stream will be returned by
55 // |stream|.
56 bool CreateInputStream(pa_threaded_mainloop* mainloop,
57 pa_context* context,
58 pa_stream** stream,
59 const AudioParameters& params,
60 const std::string& device_id,
61 pa_stream_notify_cb_t stream_callback,
62 void* user_data);
64 // Create a playback stream for the threaded mainloop, return true if success,
65 // otherwise false. This function will create a new Pulse threaded mainloop,
66 // and the handles of the mainloop, context and stream will be returned by
67 // |mainloop|, |context| and |stream|.
68 bool CreateOutputStream(pa_threaded_mainloop** mainloop,
69 pa_context** context,
70 pa_stream** stream,
71 const AudioParameters& params,
72 const std::string& device_id,
73 const std::string& app_name,
74 pa_stream_notify_cb_t stream_callback,
75 pa_stream_request_cb_t write_callback,
76 void* user_data);
78 } // namespace pulse
80 } // namespace media
82 #endif // MEDIA_AUDIO_PULSE_PULSE_UTIL_H_