Blame


1 3baa2617 2022-02-16 op /*
2 578f8d0c 2023-05-02 op * Copyright (c) 2022, 2023 Omar Polo <op@omarpolo.com>
3 3baa2617 2022-02-16 op *
4 3baa2617 2022-02-16 op * Permission to use, copy, modify, and distribute this software for any
5 3baa2617 2022-02-16 op * purpose with or without fee is hereby granted, provided that the above
6 3baa2617 2022-02-16 op * copyright notice and this permission notice appear in all copies.
7 3baa2617 2022-02-16 op *
8 3baa2617 2022-02-16 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 3baa2617 2022-02-16 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 3baa2617 2022-02-16 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 3baa2617 2022-02-16 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 3baa2617 2022-02-16 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 3baa2617 2022-02-16 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 3baa2617 2022-02-16 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 3baa2617 2022-02-16 op */
16 3baa2617 2022-02-16 op
17 3baa2617 2022-02-16 op #ifndef AMUSED_H
18 3baa2617 2022-02-16 op #define AMUSED_H
19 3baa2617 2022-02-16 op
20 3baa2617 2022-02-16 op extern char *csock;
21 3baa2617 2022-02-16 op extern int debug;
22 3baa2617 2022-02-16 op extern int verbose;
23 3baa2617 2022-02-16 op extern int playing;
24 3baa2617 2022-02-16 op extern struct imsgev *iev_player;
25 3baa2617 2022-02-16 op
26 3baa2617 2022-02-16 op #define IMSG_DATA_SIZE(imsg) ((imsg).hdr.len - IMSG_HEADER_SIZE)
27 3baa2617 2022-02-16 op
28 3baa2617 2022-02-16 op enum imsg_type {
29 3baa2617 2022-02-16 op IMSG_PLAY, /* fd + filename */
30 3baa2617 2022-02-16 op IMSG_RESUME,
31 3baa2617 2022-02-16 op IMSG_PAUSE,
32 3baa2617 2022-02-16 op IMSG_STOP,
33 ff06024f 2022-07-08 op IMSG_POS,
34 ff06024f 2022-07-08 op IMSG_LEN,
35 3baa2617 2022-02-16 op IMSG_EOF,
36 17ef54d6 2022-06-22 op IMSG_ERR, /* error string */
37 3baa2617 2022-02-16 op
38 a913de21 2022-02-17 op IMSG_CTL_PLAY, /* with optional filename */
39 3baa2617 2022-02-16 op IMSG_CTL_TOGGLE_PLAY,
40 3baa2617 2022-02-16 op IMSG_CTL_PAUSE,
41 3baa2617 2022-02-16 op IMSG_CTL_STOP,
42 3baa2617 2022-02-16 op IMSG_CTL_FLUSH,
43 3baa2617 2022-02-16 op IMSG_CTL_SHOW,
44 bb3f279f 2022-02-16 op IMSG_CTL_STATUS,
45 af27e631 2022-02-17 op IMSG_CTL_NEXT,
46 af27e631 2022-02-17 op IMSG_CTL_PREV,
47 a913de21 2022-02-17 op IMSG_CTL_JUMP,
48 9fb94242 2022-07-13 op IMSG_CTL_MODE, /* struct player_mode */
49 791d3db3 2022-07-09 op IMSG_CTL_SEEK, /* struct player_seek */
50 3baa2617 2022-02-16 op
51 19d6b480 2022-02-17 op IMSG_CTL_BEGIN,
52 19d6b480 2022-02-17 op IMSG_CTL_ADD, /* path to a file */
53 3af93963 2022-03-02 op IMSG_CTL_COMMIT, /* offset of the track to jump to */
54 19d6b480 2022-02-17 op
55 3dd90731 2023-01-09 op IMSG_CTL_MONITOR, /* struct player_event */
56 87f575c3 2022-02-21 op
57 3baa2617 2022-02-16 op IMSG_CTL_ERR,
58 90122a37 2022-05-14 op IMSG__LAST,
59 3baa2617 2022-02-16 op };
60 3baa2617 2022-02-16 op
61 3baa2617 2022-02-16 op struct imsgev {
62 50e0da0e 2024-01-21 op struct imsgbuf imsgbuf;
63 0a53bd62 2023-08-16 op void (*handler)(int, int, void *);
64 0a53bd62 2023-08-16 op int events;
65 3baa2617 2022-02-16 op };
66 3baa2617 2022-02-16 op
67 3baa2617 2022-02-16 op enum actions {
68 3baa2617 2022-02-16 op NONE,
69 3baa2617 2022-02-16 op PLAY,
70 3baa2617 2022-02-16 op PAUSE,
71 3baa2617 2022-02-16 op TOGGLE,
72 3baa2617 2022-02-16 op STOP,
73 8d087670 2022-07-09 op RESTART, /* seek to zero */
74 3baa2617 2022-02-16 op ADD,
75 3baa2617 2022-02-16 op FLUSH,
76 3baa2617 2022-02-16 op SHOW,
77 bb3f279f 2022-02-16 op STATUS,
78 af27e631 2022-02-17 op PREV,
79 af27e631 2022-02-17 op NEXT,
80 14be015f 2022-02-17 op LOAD,
81 a913de21 2022-02-17 op JUMP,
82 9fb94242 2022-07-13 op MODE,
83 6b47a39f 2022-02-21 op MONITOR,
84 791d3db3 2022-07-09 op SEEK,
85 3baa2617 2022-02-16 op };
86 3baa2617 2022-02-16 op
87 791d3db3 2022-07-09 op struct player_seek {
88 791d3db3 2022-07-09 op int64_t offset;
89 791d3db3 2022-07-09 op int relative;
90 60a09ce7 2022-07-09 op int percent;
91 791d3db3 2022-07-09 op };
92 791d3db3 2022-07-09 op
93 3baa2617 2022-02-16 op struct ctl_command;
94 3baa2617 2022-02-16 op
95 9881c98c 2022-07-13 op #define MODE_ON +1
96 9881c98c 2022-07-13 op #define MODE_OFF 0
97 9881c98c 2022-07-13 op #define MODE_UNDEF -1
98 9881c98c 2022-07-13 op #define MODE_TOGGLE -2
99 9fb94242 2022-07-13 op struct player_mode {
100 310ef57c 2022-02-19 op int repeat_one;
101 310ef57c 2022-02-19 op int repeat_all;
102 9fb94242 2022-07-13 op int consume;
103 310ef57c 2022-02-19 op };
104 310ef57c 2022-02-19 op
105 44398779 2022-02-19 op struct player_status {
106 44398779 2022-02-19 op char path[PATH_MAX];
107 44398779 2022-02-19 op int status;
108 ff06024f 2022-07-08 op int64_t position;
109 ff06024f 2022-07-08 op int64_t duration;
110 9fb94242 2022-07-13 op struct player_mode mode;
111 44398779 2022-02-19 op };
112 44398779 2022-02-19 op
113 3dd90731 2023-01-09 op struct player_event {
114 3dd90731 2023-01-09 op int event;
115 3dd90731 2023-01-09 op int64_t position;
116 3dd90731 2023-01-09 op int64_t duration;
117 3dd90731 2023-01-09 op struct player_mode mode;
118 3dd90731 2023-01-09 op };
119 3dd90731 2023-01-09 op
120 3baa2617 2022-02-16 op struct parse_result {
121 3baa2617 2022-02-16 op enum actions action;
122 3baa2617 2022-02-16 op char **files;
123 4b42d3a3 2022-07-13 op FILE *fp;
124 8e916714 2022-02-17 op int pretty;
125 90122a37 2022-05-14 op int monitor[IMSG__LAST];
126 9fb94242 2022-07-13 op struct player_mode mode;
127 791d3db3 2022-07-09 op struct player_seek seek;
128 68e4f29e 2022-07-10 op const char *status_format;
129 3baa2617 2022-02-16 op struct ctl_command *ctl;
130 3baa2617 2022-02-16 op };
131 3baa2617 2022-02-16 op
132 3baa2617 2022-02-16 op struct ctl_command {
133 3baa2617 2022-02-16 op const char *name;
134 3baa2617 2022-02-16 op enum actions action;
135 3baa2617 2022-02-16 op int (*main)(struct parse_result *, int, char **);
136 3baa2617 2022-02-16 op const char *usage;
137 3baa2617 2022-02-16 op };
138 3baa2617 2022-02-16 op
139 19d6b480 2022-02-17 op struct playlist;
140 06ceb376 2023-03-23 op struct pollfd;
141 19d6b480 2022-02-17 op
142 3baa2617 2022-02-16 op /* amused.c */
143 fea541a8 2022-02-16 op void spawn_daemon(void);
144 3baa2617 2022-02-16 op void imsg_event_add(struct imsgev *iev);
145 3baa2617 2022-02-16 op int imsg_compose_event(struct imsgev *, uint16_t, uint32_t,
146 3baa2617 2022-02-16 op pid_t, int, const void *, uint16_t);
147 791d3db3 2022-07-09 op int main_send_player(uint16_t, int, const void *, size_t);
148 f3bd773b 2022-02-19 op int main_play_song(const char *);
149 a913de21 2022-02-17 op void main_playlist_jump(struct imsgev *, struct imsg *);
150 2f589330 2022-02-17 op void main_playlist_resume(void);
151 aaccc123 2022-02-16 op void main_playlist_advance(void);
152 af27e631 2022-02-17 op void main_playlist_previous(void);
153 19d6b480 2022-02-17 op void main_senderr(struct imsgev *, const char *);
154 19d6b480 2022-02-17 op void main_enqueue(int, struct playlist *, struct imsgev *, struct imsg *);
155 d980494c 2022-02-16 op void main_send_playlist(struct imsgev *);
156 bb3f279f 2022-02-16 op void main_send_status(struct imsgev *);
157 15aecb89 2022-07-12 op void main_seek(struct player_seek *);
158 3baa2617 2022-02-16 op
159 06ceb376 2023-03-23 op /* audio_*.c */
160 06ceb376 2023-03-23 op int audio_open(void (*)(void *, int));
161 06ceb376 2023-03-23 op int audio_setup(unsigned int, unsigned int, unsigned int,
162 b02dadd3 2023-05-13 op struct pollfd *, int);
163 06ceb376 2023-03-23 op int audio_nfds(void);
164 b02dadd3 2023-05-13 op int audio_pollfd(struct pollfd *, int, int);
165 b02dadd3 2023-05-13 op int audio_revents(struct pollfd *, int);
166 06ceb376 2023-03-23 op size_t audio_write(const void *, size_t);
167 06ceb376 2023-03-23 op int audio_flush(void);
168 06ceb376 2023-03-23 op int audio_stop(void);
169 06ceb376 2023-03-23 op
170 3baa2617 2022-02-16 op /* ctl.c */
171 3baa2617 2022-02-16 op __dead void usage(void);
172 3baa2617 2022-02-16 op __dead void ctl(int, char **);
173 3baa2617 2022-02-16 op
174 3baa2617 2022-02-16 op /* player.c */
175 b9d2a697 2022-07-08 op int player_setup(unsigned int, unsigned int, unsigned int);
176 ff06024f 2022-07-08 op void player_setduration(int64_t);
177 791d3db3 2022-07-09 op void player_setpos(int64_t);
178 791d3db3 2022-07-09 op int play(const void *, size_t, int64_t *);
179 3baa2617 2022-02-16 op int player(int, int);
180 3baa2617 2022-02-16 op
181 17ef54d6 2022-06-22 op int play_oggvorbis(int, const char **);
182 17ef54d6 2022-06-22 op int play_mp3(int, const char **);
183 17ef54d6 2022-06-22 op int play_flac(int, const char **);
184 17ef54d6 2022-06-22 op int play_opus(int, const char **);
185 3baa2617 2022-02-16 op
186 3baa2617 2022-02-16 op #endif