blob: da0cb0f42d70e9aa8fda6d7d016ff30d973b0109 [file] [log] [blame]
// 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.
#include <pulse/pulseaudio.h>
#include "base/basictypes.h"
#include "media/audio/audio_device_name.h"
#include "media/base/channel_layout.h"
namespace media {
class AudioParameters;
namespace pulse {
// A helper class that acquires pa_threaded_mainloop_lock() while in scope.
class AutoPulseLock {
explicit AutoPulseLock(pa_threaded_mainloop* pa_mainloop)
: pa_mainloop_(pa_mainloop) {
~AutoPulseLock() {
pa_threaded_mainloop* pa_mainloop_;
// Triggers pa_threaded_mainloop_signal() to avoid deadlocks.
void StreamSuccessCallback(pa_stream* s, int error, void* mainloop);
void ContextStateCallback(pa_context* context, void* mainloop);
pa_sample_format_t BitsToPASampleFormat(int bits_per_sample);
pa_channel_map ChannelLayoutToPAChannelMap(ChannelLayout channel_layout);
void WaitForOperationCompletion(pa_threaded_mainloop* mainloop,
pa_operation* operation);
int GetHardwareLatencyInBytes(pa_stream* stream,
int sample_rate,
int bytes_per_frame);
// Create a recording stream for the threaded mainloop, return true if success,
// otherwise false. |mainloop| and |context| have to be from a valid Pulse
// threaded mainloop and the handle of the created stream will be returned by
// |stream|.
bool CreateInputStream(pa_threaded_mainloop* mainloop,
pa_context* context,
pa_stream** stream,
const AudioParameters& params,
const std::string& device_id,
pa_stream_notify_cb_t stream_callback,
void* user_data);
// Create a playback stream for the threaded mainloop, return true if success,
// otherwise false. This function will create a new Pulse threaded mainloop,
// and the handles of the mainloop, context and stream will be returned by
// |mainloop|, |context| and |stream|.
bool CreateOutputStream(pa_threaded_mainloop** mainloop,
pa_context** context,
pa_stream** stream,
const AudioParameters& params,
pa_stream_notify_cb_t stream_callback,
pa_stream_request_cb_t write_callback,
void* user_data);
} // namespace pulse
} // namespace media