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 struct sio_hdl *hdl;
21 extern char *csock;
22 extern int debug;
23 extern int verbose;
24 extern int playing;
25 extern struct imsgev *iev_player;
27 #define IMSG_DATA_SIZE(imsg) ((imsg).hdr.len - IMSG_HEADER_SIZE)
29 enum imsg_type {
30 IMSG_PLAY, /* fd + filename */
31 IMSG_RESUME,
32 IMSG_PAUSE,
33 IMSG_STOP,
34 IMSG_EOF,
35 IMSG_ERR,
37 IMSG_CTL_PLAY, /* with optional filename */
38 IMSG_CTL_TOGGLE_PLAY,
39 IMSG_CTL_PAUSE,
40 IMSG_CTL_STOP,
41 IMSG_CTL_RESTART,
42 IMSG_CTL_FLUSH,
43 IMSG_CTL_SHOW,
44 IMSG_CTL_STATUS,
45 IMSG_CTL_NEXT,
46 IMSG_CTL_PREV,
47 IMSG_CTL_JUMP,
49 IMSG_CTL_BEGIN,
50 IMSG_CTL_ADD, /* path to a file */
51 IMSG_CTL_COMMIT,
53 IMSG_CTL_ERR,
54 };
56 struct imsgev {
57 struct imsgbuf ibuf;
58 void (*handler)(int, short, void *);
59 struct event ev;
60 short events;
61 };
63 enum actions {
64 NONE,
65 PLAY,
66 PAUSE,
67 TOGGLE,
68 STOP,
69 RESTART,
70 ADD,
71 FLUSH,
72 SHOW,
73 STATUS,
74 PREV,
75 NEXT,
76 LOAD,
77 JUMP,
78 };
80 struct ctl_command;
82 struct parse_result {
83 enum actions action;
84 char **files;
85 const char *file;
86 int pretty;
87 struct ctl_command *ctl;
88 };
90 struct ctl_command {
91 const char *name;
92 enum actions action;
93 int (*main)(struct parse_result *, int, char **);
94 const char *usage;
95 int has_pledge;
96 };
98 struct player_status {
99 char path[PATH_MAX];
100 int status;
101 };
103 struct playlist;
105 /* amused.c */
106 void spawn_daemon(void);
107 void imsg_event_add(struct imsgev *iev);
108 int imsg_compose_event(struct imsgev *, uint16_t, uint32_t,
109 pid_t, int, const void *, uint16_t);
110 int main_send_player(uint16_t, int, const void *, uint16_t);
111 void main_playlist_jump(struct imsgev *, struct imsg *);
112 void main_playlist_resume(void);
113 void main_playlist_advance(void);
114 void main_playlist_previous(void);
115 void main_restart_track(void);
116 void main_senderr(struct imsgev *, const char *);
117 void main_enqueue(int, struct playlist *, struct imsgev *, struct imsg *);
118 void main_send_playlist(struct imsgev *);
119 void main_send_status(struct imsgev *);
121 /* ctl.c */
122 __dead void usage(void);
123 __dead void ctl(int, char **);
125 /* player.c */
126 int player_setup(int, int);
127 void player_senderr(void);
128 void player_sendeof(void);
129 int player_shouldstop(void);
130 int player(int, int);
132 void play_oggvorbis(int fd);
133 void play_mp3(int fd);
134 void play_flac(int fd);
135 void play_opus(int fd);
137 #endif