/**
* pustule
* Copyright 2014-2020 Thomas Jost <schnouki@schnouki.net>
*
* This file is part of pustule.
*
* pustule is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* pustule is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* pustule. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PUSTULE_H
#define PUSTULE_H
#define PUSTULE_VERSION "pustule 0.1"
#include <stdbool.h>
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include <pulse/pulseaudio.h>
/* Data structures */
typedef struct {
uint32_t index;
char* name;
char* driver;
int mute;
int volume_writable;
int has_volume;
pa_cvolume volume;
pa_proplist* proplist;
} pustule_input_event_t;
typedef struct {
uint32_t index;
char* name;
char* description;
int mute;
pa_cvolume volume;
pa_proplist* proplist;
} pustule_device_event_t;
typedef struct {
enum {
INPUT_ADDED,
INPUT_REMOVED,
DEVICE_ADDED,
DEVICE_REMOVED,
} type;
union {
pustule_input_event_t input_event;
pustule_device_event_t device_event;
};
} pustule_event_t;
typedef void (*pustule_volume_callback_t)(double volume, void* userdata);
typedef struct {
const char* user_name;
const char* host_name;
const char* server_name;
const char* server_version;
const char* default_sink_name;
} pustule_server_info_t;
typedef void (*pustule_server_info_callback_t)(pustule_server_info_t* info, void* userdata);
typedef struct {
size_t capacity;
size_t size;
intptr_t* array;
} array_t;
/* PulseAudio callbacks */
void event_callback(pa_context* ctx, pa_subscription_event_type_t t, uint32_t idx, void* userdata);
void input_info_callback(pa_context* ctx, const pa_sink_input_info* i, int eol, void* userdata);
void device_info_callback(pa_context* ctx, const pa_sink_info* i, int eol, void* userdata);
void state_callback(pa_context* ctx, void* userdata);
/* PulseAudio query functions */
void input_get_volume(uint32_t idx, pustule_volume_callback_t callback, void* userdata);
void device_get_volume(uint32_t idx, pustule_volume_callback_t callback, void* userdata);
void server_get_info(pustule_server_info_callback_t callback, void* userdata);
/* Dynamic array functions */
void array_init(array_t* arr);
void array_push(array_t* arr, intptr_t value);
bool array_find(array_t* arr, intptr_t value, size_t* idx);
void array_remove(array_t* arr, intptr_t value);
/* Lua module */
void init_lua_module(lua_State* L);
int luaopen_pustule(lua_State* L);
/* Functions exported in the Lua module */
int pustule_connect_signal(lua_State* L);
int pustule_disconnect_signal(lua_State* L);
/* Lua query functions */
int pustule_get_input_volume(lua_State* L);
int pustule_set_input_volume(lua_State* L);
int pustule_get_device_volume(lua_State* L);
int pustule_set_device_volume(lua_State* L);
int pustule_get_default_device(lua_State* L);
int pustule_set_default_device(lua_State* L);
int pustule_suspend_device(lua_State* L);
/* Lua log functions */
int lua_log_debug(lua_State* L);
int lua_log_info(lua_State* L);
int lua_log_warn(lua_State* L);
int lua_log_error(lua_State* L);
/* Lua helpers */
void pustule_push_input_event(lua_State* L, pustule_input_event_t* event);
void pustule_push_device_event(lua_State* L, pustule_device_event_t* event);
bool check_pcall_error(lua_State* L, int res);
/* Pustule event loop */
void pustule_handle_event(pustule_event_t* event);
/* Global variables */
extern pa_context* pactx;
extern pa_mainloop* paloop;
extern lua_State* g_L;
extern array_t input_added_listeners;
extern array_t input_removed_listeners;
extern array_t device_added_listeners;
extern array_t device_removed_listeners;
#endif