#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 AudioParameters;
namespace pulse {
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);
};
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);
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);
bool CreateOutputStream(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,
pa_stream_request_cb_t write_callback,
void* user_data);
}
}
#endif