Blob


1 /*
2 * Copyright (c) 2022 Omar Polo <op@openbsd.org>
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_EOF,
34 IMSG_ERR,
36 IMSG_CTL_PLAY, /* with optional filename */
37 IMSG_CTL_TOGGLE_PLAY,
38 IMSG_CTL_PAUSE,
39 IMSG_CTL_STOP,
40 IMSG_CTL_RESTART,
41 IMSG_CTL_FLUSH,
42 IMSG_CTL_SHOW,
43 IMSG_CTL_STATUS,
44 IMSG_CTL_NEXT,
45 IMSG_CTL_PREV,
46 IMSG_CTL_JUMP,
47 IMSG_CTL_REPEAT, /* struct player_repeat */
49 IMSG_CTL_BEGIN,
50 IMSG_CTL_ADD, /* path to a file */
51 IMSG_CTL_COMMIT, /* offset of the track to jump to */
53 IMSG_CTL_MONITOR,
55 IMSG_CTL_ERR,
56 };
58 struct imsgev {
59 struct imsgbuf ibuf;
60 void (*handler)(int, short, void *);
61 struct event ev;
62 short events;
63 };
65 enum actions {
66 NONE,
67 PLAY,
68 PAUSE,
69 TOGGLE,
70 STOP,
71 RESTART,
72 ADD,
73 FLUSH,
74 SHOW,
75 STATUS,
76 PREV,
77 NEXT,
78 LOAD,
79 JUMP,
80 REPEAT,
81 MONITOR,
82 };
84 struct ctl_command;
86 struct player_repeat {
87 int repeat_one;
88 int repeat_all;
89 };
91 struct player_status {
92 char path[PATH_MAX];
93 int status;
94 struct player_repeat rp;
95 };
97 struct parse_result {
98 enum actions action;
99 char **files;
100 const char *file;
101 int pretty;
102 struct player_repeat rep;
103 struct ctl_command *ctl;
104 };
106 struct ctl_command {
107 const char *name;
108 enum actions action;
109 int (*main)(struct parse_result *, int, char **);
110 const char *usage;
111 int has_pledge;
112 };
114 struct playlist;
116 /* amused.c */
117 void spawn_daemon(void);
118 void imsg_event_add(struct imsgev *iev);
119 int imsg_compose_event(struct imsgev *, uint16_t, uint32_t,
120 pid_t, int, const void *, uint16_t);
121 int main_send_player(uint16_t, int);
122 int main_play_song(const char *);
123 void main_playlist_jump(struct imsgev *, struct imsg *);
124 void main_playlist_resume(void);
125 void main_playlist_advance(void);
126 void main_playlist_previous(void);
127 void main_restart_track(void);
128 void main_senderr(struct imsgev *, const char *);
129 void main_enqueue(int, struct playlist *, struct imsgev *, struct imsg *);
130 void main_send_playlist(struct imsgev *);
131 void main_send_status(struct imsgev *);
133 /* ctl.c */
134 __dead void usage(void);
135 __dead void ctl(int, char **);
137 /* player.c */
138 int player_setup(int, int, int);
139 int play(const void *, size_t);
140 int player(int, int);
142 int play_oggvorbis(int fd);
143 int play_mp3(int fd);
144 int play_flac(int fd);
145 int play_opus(int fd);
147 #endif