2021-05-05 21:05:05 +02:00
|
|
|
#if defined(__linux__)
|
|
|
|
#include "forward.hpp"
|
2021-05-17 11:19:02 +02:00
|
|
|
#include <core/global/globals.hpp>
|
2021-05-05 21:05:05 +02:00
|
|
|
#include <dlfcn.h>
|
2021-05-17 11:19:02 +02:00
|
|
|
#include <fancy.hpp>
|
2021-05-05 21:05:05 +02:00
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
template <typename T> void loadFunc(void *so, T &function, const std::string &name)
|
|
|
|
{
|
|
|
|
function = reinterpret_cast<T>(dlsym(so, name.c_str()));
|
|
|
|
|
|
|
|
if (function == nullptr)
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Failed to load function " + name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-17 11:19:02 +02:00
|
|
|
bool Soundux::PulseApi::setup()
|
2021-05-05 21:05:05 +02:00
|
|
|
{
|
2021-05-17 13:54:05 +02:00
|
|
|
#if defined(USE_FLATPAK)
|
|
|
|
#define load(name) _##name = reinterpret_cast<decltype(_##name)>(name);
|
|
|
|
load(pa_mainloop_new);
|
|
|
|
load(pa_mainloop_iterate);
|
|
|
|
load(pa_mainloop_get_api);
|
|
|
|
load(pa_context_new);
|
|
|
|
load(pa_context_connect);
|
|
|
|
load(pa_context_set_state_callback);
|
|
|
|
load(pa_context_load_module);
|
|
|
|
load(pa_context_get_module_info_list);
|
|
|
|
load(pa_context_get_source_output_info_list);
|
|
|
|
load(pa_context_get_sink_input_info_list);
|
|
|
|
load(pa_context_get_server_info);
|
|
|
|
load(pa_proplist_gets);
|
|
|
|
load(pa_context_set_default_source);
|
|
|
|
load(pa_context_move_sink_input_by_name);
|
|
|
|
load(pa_context_get_server_info);
|
|
|
|
load(pa_context_move_sink_input_by_index);
|
|
|
|
load(pa_context_move_source_output_by_name);
|
|
|
|
load(pa_context_move_source_output_by_index);
|
|
|
|
load(pa_context_set_sink_input_mute);
|
|
|
|
load(pa_context_unload_module);
|
|
|
|
load(pa_context_get_state);
|
|
|
|
load(pa_operation_get_state);
|
|
|
|
return true;
|
|
|
|
#else
|
2021-05-05 21:05:05 +02:00
|
|
|
auto *libpulse = dlopen("libpulse.so", RTLD_LAZY);
|
|
|
|
if (libpulse)
|
|
|
|
{
|
2021-05-17 13:54:05 +02:00
|
|
|
#define load(name) loadFunc(libpulse, _##name, #name)
|
2021-05-05 21:05:05 +02:00
|
|
|
load(pa_mainloop_new);
|
|
|
|
load(pa_mainloop_iterate);
|
|
|
|
load(pa_mainloop_get_api);
|
|
|
|
load(pa_context_new);
|
|
|
|
load(pa_context_connect);
|
|
|
|
load(pa_context_set_state_callback);
|
|
|
|
load(pa_context_load_module);
|
|
|
|
load(pa_context_get_module_info_list);
|
|
|
|
load(pa_context_get_source_output_info_list);
|
|
|
|
load(pa_context_get_sink_input_info_list);
|
|
|
|
load(pa_context_get_server_info);
|
|
|
|
load(pa_proplist_gets);
|
|
|
|
load(pa_context_set_default_source);
|
|
|
|
load(pa_context_move_sink_input_by_name);
|
|
|
|
load(pa_context_get_server_info);
|
|
|
|
load(pa_context_move_sink_input_by_index);
|
|
|
|
load(pa_context_move_source_output_by_name);
|
|
|
|
load(pa_context_move_source_output_by_index);
|
|
|
|
load(pa_context_set_sink_input_mute);
|
|
|
|
load(pa_context_unload_module);
|
|
|
|
load(pa_context_get_state);
|
|
|
|
load(pa_operation_get_state);
|
2021-05-17 11:19:02 +02:00
|
|
|
return true;
|
2021-05-05 21:05:05 +02:00
|
|
|
}
|
2021-05-17 11:19:02 +02:00
|
|
|
|
|
|
|
Fancy::fancy.logTime().failure() << "Failed to load pulseaudio" << std::endl;
|
|
|
|
Globals::gAudioBackend = std::make_shared<Objects::AudioBackend>();
|
|
|
|
return false;
|
2021-05-17 13:54:05 +02:00
|
|
|
#endif
|
2021-05-05 21:05:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|