12 #ifndef ROC_SNDIO_PULSEAUDIO_DEVICE_H_
13 #define ROC_SNDIO_PULSEAUDIO_DEVICE_H_
15 #include <pulse/pulseaudio.h>
39 bool open(
const char* device);
84 static void context_state_cb_(pa_context* context,
void* userdata);
87 device_info_cb_(pa_context* context,
const void* info,
int eol,
void* userdata);
89 static void stream_state_cb_(pa_stream* stream,
void* userdata);
90 static void stream_request_cb_(pa_stream* stream,
size_t length,
void* userdata);
92 static void timer_cb_(pa_mainloop_api* mainloop,
94 const struct timeval* tv,
99 void want_mainloop_()
const;
100 bool start_mainloop_();
101 void stop_mainloop_();
105 void set_opened_(
bool opened);
107 bool open_context_();
108 void close_context_();
110 bool start_device_info_op_();
111 void cancel_device_info_op_();
113 bool load_device_params_(
const pa_sample_spec& device_spec);
114 void init_stream_params_(
const pa_sample_spec& device_spec);
116 void close_stream_();
120 ssize_t wait_stream_();
123 void report_latency_();
143 size_t record_frag_size_;
144 bool record_frag_flag_;
149 pa_threaded_mainloop* mainloop_;
150 pa_context* context_;
151 pa_operation* device_info_op_;
153 pa_time_event* timer_;
157 pa_sample_spec stream_spec_;
158 pa_buffer_attr buff_attrs_;
Sample specification. Describes sample rate and channels.
Base class for non-copyable objects.
PulseAudio device. Can be either source or sink depending on constructor parameter.
virtual void pause()
Pause reading.
virtual bool has_clock() const
Check if the device has own clock.
virtual bool restart()
Restart reading from the beginning.
bool open(const char *device)
Open output device.
virtual DeviceState state() const
Get device state.
virtual ISink * to_sink()
Cast IDevice to ISink.
virtual audio::SampleSpec sample_spec() const
Get sample specification of the sink.
PulseaudioDevice(const Config &config, DeviceType device_type)
Initialize.
virtual bool read(audio::Frame &frame)
Read audio frame.
virtual bool has_latency() const
Check if the device supports latency reports.
virtual DeviceType type() const
Get device type.
virtual bool resume()
Resume paused reading.
virtual ISource * to_source()
Cast IDevice to ISink.
virtual void write(audio::Frame &frame)
Write audio frame.
virtual void reclock(core::nanoseconds_t timestamp)
Adjust source clock to match consumer clock.
virtual core::nanoseconds_t latency() const
Get latency of the sink.
float sample_t
Raw audio sample.
nanoseconds_t timestamp(clock_t clock)
Get current timestamp in nanoseconds.
int64_t nanoseconds_t
Nanoseconds.
int32_t stream_timestamp_diff_t
Packet stream timestamp delta.
Commonly used types and functions.
Various units used in packets.