~schnouki/pustule

ref: 2e90522e70214bb6d1bb88aef6f7d8c06152a99f pustule/pustule.h -rw-r--r-- 4.1 KiB
2e90522e — Thomas Jost Expose log functions in Lua 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
 * 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