Blob


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