Definitions for audio control on Linux. More...
#include <algorithm>#include <array>#include <bitset>#include <sstream>#include <thread>#include <boost/regex.hpp>#include <pulse/error.h>#include <pulse/pulseaudio.h>#include <pulse/simple.h>#include "src/config.h"#include "src/logging.h"#include "src/platform/common.h"#include "src/thread_safe.h"Classes | |
| struct | platf::pa::add_const_helper< false, T > |
| Template helper that leaves non-const inputs mutable. More... | |
| struct | platf::pa::add_const_helper< true, T > |
| Template helper that preserves constness for const inputs. More... | |
| struct | platf::mic_attr_t |
| PulseAudio recording stream and channel metadata. More... | |
| class | platf::pa::server_t |
| PulseAudio server controller that creates and removes Sunshine sinks. More... | |
Typedefs | |
| template<class T> | |
| using | platf::pa::add_const_t = typename add_const_helper<std::is_pointer_v<T>, T>::type |
| PulseAudio callback info type with pointer constness normalized. | |
| template<class T> | |
| using | platf::pa::cb_simple_t = std::function<void(ctx_t::pointer, add_const_t<T> i)> |
| Callback wrapper for PulseAudio introspection results without an end marker. | |
| template<class T> | |
| using | platf::pa::cb_t = std::function<void(ctx_t::pointer, add_const_t<T> i, int eol)> |
| Callback wrapper for PulseAudio introspection results with an end marker. | |
| using | platf::pa::ctx_t = util::safe_ptr<pa_context, &pa_context_unref> |
| Owning pointer for a PulseAudio context. | |
| using | platf::pa::loop_t = util::safe_ptr<pa_mainloop, &pa_mainloop_free> |
| Owning pointer for a PulseAudio mainloop. | |
| using | platf::pa::op_t = util::safe_ptr<pa_operation, &pa_operation_unref> |
| Owning pointer for a PulseAudio asynchronous operation. | |
| using | platf::pa::string_t = util::safe_ptr<char, &pa_free<char>> |
| Owning pointer for PulseAudio strings allocated with pa_xmalloc. | |
Functions | |
| std::unique_ptr< audio_control_t > | platf::audio_control () |
| Create the platform audio controller. | |
| template<class T> | |
| void | platf::pa::cb (ctx_t::pointer ctx, add_const_t< T > i, int eol, void *userdata) |
| Handle PulseAudio source introspection results. | |
| template<class T> | |
| void | platf::pa::cb (ctx_t::pointer ctx, add_const_t< T > i, void *userdata) |
| Handle PulseAudio sink-input introspection results. | |
| void | platf::pa::cb_i (ctx_t::pointer, std::uint32_t i, void *userdata) |
| Forward a PulseAudio integer callback value into a Sunshine alarm. | |
| void | platf::pa::ctx_state_cb (ctx_t::pointer ctx, void *userdata) |
| Translate PulseAudio context state changes into server events. | |
| bool | platf::fill_canonical_channel_map (int channels, pa_channel_map &pa_map) |
| Fill a PulseAudio channel map with the canonical layout for a channel count. | |
| std::unique_ptr< mic_t > | platf::microphone (int channels, std::uint32_t sample_rate, std::uint32_t frame_size, std::string source_name) |
| Create a microphone capture stream for the requested layout. | |
| template<class T> | |
| void | platf::pa::pa_free (T *p) |
| Release memory allocated by PulseAudio. | |
| void | platf::pa::success_cb (ctx_t::pointer, int status, void *userdata) |
| Record completion of a PulseAudio asynchronous operation. | |
| std::string | platf::to_string (const char *name, const std::uint8_t *mapping, int channels) |
| Convert a PulseAudio operation result to a log string. | |
Variables | |
| constexpr std::array< pa_channel_position_t, speaker::MAX_SPEAKERS > | platf::position_mapping |
| PulseAudio position for each speaker::speaker_e, in speaker_e order. | |
Definitions for audio control on Linux.
| std::unique_ptr< audio_control_t > platf::audio_control | ( | ) |
Create the platform audio controller.
| void platf::pa::cb | ( | ctx_t::pointer | ctx, |
| add_const_t< T > | i, | ||
| int | eol, | ||
| void * | userdata ) |
Handle PulseAudio source introspection results.
| ctx | Native context object used by the operation or callback. |
| i | PulseAudio introspection info supplied to the callback. |
| eol | PulseAudio end-of-list marker. |
| userdata | Caller-provided pointer passed through the callback. |
| void platf::pa::cb | ( | ctx_t::pointer | ctx, |
| add_const_t< T > | i, | ||
| void * | userdata ) |
Handle PulseAudio sink-input introspection results.
| ctx | Native context object used by the operation or callback. |
| i | PulseAudio introspection info supplied to the callback. |
| userdata | Caller-provided pointer passed through the callback. |
| void platf::pa::cb_i | ( | ctx_t::pointer | , |
| std::uint32_t | i, | ||
| void * | userdata ) |
Forward a PulseAudio integer callback value into a Sunshine alarm.
The PulseAudio callback signature supplies a context that is not needed to ring the alarm.
| i | Integer value returned by the PulseAudio operation. |
| userdata | Caller-provided pointer passed through the callback. |
| void platf::pa::ctx_state_cb | ( | ctx_t::pointer | ctx, |
| void * | userdata ) |
Translate PulseAudio context state changes into server events.
| ctx | Native context object used by the operation or callback. |
| userdata | Caller-provided pointer passed through the callback. |
| bool platf::fill_canonical_channel_map | ( | int | channels, |
| pa_channel_map & | pa_map ) |
Fill a PulseAudio channel map with the canonical layout for a channel count.
Capture always uses the canonical layout, never the Opus channel mapping: the Opus mapping is applied by the multistream encoder and undone by the client, so applying it here too would leave the samples permuted. speaker::map_stereo, map_surround51 and map_surround71 are the identity over speaker::speaker_e, so the canonical position of channel i is position_mapping[i].
| channels | Number of audio channels in the stream. |
| pa_map | Channel map to fill; left untouched when channels is out of range. |
| std::unique_ptr< mic_t > platf::microphone | ( | int | channels, |
| std::uint32_t | sample_rate, | ||
| std::uint32_t | frame_size, | ||
| std::string | source_name ) |
Create a microphone capture stream for the requested layout.
Capture always uses the canonical channel layout; Opus mapping is applied by the encoder.
| channels | Number of audio channels in the stream. |
| sample_rate | Audio sample rate in hertz. |
| frame_size | Number of samples captured per audio frame. |
| source_name | Source name. |
| void platf::pa::pa_free | ( | T * | p | ) |
Release memory allocated by PulseAudio.
| p | Pointer allocated by PulseAudio and released with pa_xfree. |
| void platf::pa::success_cb | ( | ctx_t::pointer | , |
| int | status, | ||
| void * | userdata ) |
Record completion of a PulseAudio asynchronous operation.
The PulseAudio callback signature supplies a context that is not needed to report completion.
| status | Native status code returned by the platform API. |
| userdata | Caller-provided pointer passed through the callback. |
| std::string platf::to_string | ( | const char * | name, |
| const std::uint8_t * | mapping, | ||
| int | channels ) |
Convert a PulseAudio operation result to a log string.
| name | Human-readable name to assign. |
| mapping | Opus channel mapping table for the requested layout. |
| channels | Number of audio channels in the stream. |
|
constexpr |
PulseAudio position for each speaker::speaker_e, in speaker_e order.