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,
38 IMSG_CTL_TOGGLE_PLAY,
39 IMSG_CTL_PAUSE,
40 IMSG_CTL_STOP,
41 IMSG_CTL_RESTART,
42 IMSG_CTL_ADD,
43 IMSG_CTL_FLUSH,
44 IMSG_CTL_SHOW,
45 IMSG_CTL_STATUS,
46 IMSG_CTL_NEXT,
47 IMSG_CTL_PREV,
49 IMSG_CTL_ERR,
50 };
52 struct imsgev {
53 struct imsgbuf ibuf;
54 void (*handler)(int, short, void *);
55 struct event ev;
56 short events;
57 };
59 enum actions {
60 NONE,
61 PLAY,
62 PAUSE,
63 TOGGLE,
64 STOP,
65 RESTART,
66 ADD,
67 FLUSH,
68 SHOW,
69 STATUS,
70 PREV,
71 NEXT,
72 LOAD,
73 };
75 struct ctl_command;
77 struct parse_result {
78 enum actions action;
79 char **files;
80 FILE *file;
81 struct ctl_command *ctl;
82 };
84 struct ctl_command {
85 const char *name;
86 enum actions action;
87 int (*main)(struct parse_result *, int, char **);
88 const char *usage;
89 int has_pledge;
90 };
92 struct player_status {
93 char path[PATH_MAX];
94 int status;
95 };
97 /* amused.c */
98 void spawn_daemon(void);
99 void imsg_event_add(struct imsgev *iev);
100 int imsg_compose_event(struct imsgev *, uint16_t, uint32_t,
101 pid_t, int, const void *, uint16_t);
102 int main_send_player(uint16_t, int, const void *, uint16_t);
103 void main_playlist_resume(void);
104 void main_playlist_advance(void);
105 void main_playlist_previous(void);
106 void main_restart_track(void);
107 void main_enqueue(struct imsgev *, struct imsg *);
108 void main_send_playlist(struct imsgev *);
109 void main_send_status(struct imsgev *);
111 /* ctl.c */
112 __dead void usage(void);
113 __dead void ctl(int, char **);
115 /* player.c */
116 int player_setrate(int);
117 void player_senderr(void);
118 void player_sendeof(void);
119 int player_shouldstop(void);
120 int player(int, int);
122 void play_oggvorbis(int fd);
123 void play_mp3(int fd);
124 void play_flac(int fd);
125 void play_opus(int fd);
127 #endif