Blame


1 3baa2617 2022-02-16 op /*
2 3baa2617 2022-02-16 op * Copyright (c) 2022 Omar Polo <op@openbsd.org>
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 struct sio_hdl *hdl;
21 3baa2617 2022-02-16 op extern char *csock;
22 3baa2617 2022-02-16 op extern int debug;
23 3baa2617 2022-02-16 op extern int verbose;
24 3baa2617 2022-02-16 op extern int playing;
25 3baa2617 2022-02-16 op extern struct imsgev *iev_player;
26 3baa2617 2022-02-16 op
27 3baa2617 2022-02-16 op #define IMSG_DATA_SIZE(imsg) ((imsg).hdr.len - IMSG_HEADER_SIZE)
28 3baa2617 2022-02-16 op
29 3baa2617 2022-02-16 op enum imsg_type {
30 3baa2617 2022-02-16 op IMSG_PLAY, /* fd + filename */
31 3baa2617 2022-02-16 op IMSG_RESUME,
32 3baa2617 2022-02-16 op IMSG_PAUSE,
33 3baa2617 2022-02-16 op IMSG_STOP,
34 3baa2617 2022-02-16 op IMSG_EOF,
35 3baa2617 2022-02-16 op IMSG_ERR,
36 3baa2617 2022-02-16 op
37 3baa2617 2022-02-16 op IMSG_CTL_PLAY,
38 3baa2617 2022-02-16 op IMSG_CTL_TOGGLE_PLAY,
39 3baa2617 2022-02-16 op IMSG_CTL_PAUSE,
40 3baa2617 2022-02-16 op IMSG_CTL_STOP,
41 3baa2617 2022-02-16 op IMSG_CTL_RESTART,
42 3baa2617 2022-02-16 op IMSG_CTL_ADD,
43 3baa2617 2022-02-16 op IMSG_CTL_FLUSH,
44 3baa2617 2022-02-16 op IMSG_CTL_SHOW,
45 bb3f279f 2022-02-16 op IMSG_CTL_STATUS,
46 af27e631 2022-02-17 op IMSG_CTL_NEXT,
47 af27e631 2022-02-17 op IMSG_CTL_PREV,
48 3baa2617 2022-02-16 op
49 3baa2617 2022-02-16 op IMSG_CTL_ERR,
50 3baa2617 2022-02-16 op };
51 3baa2617 2022-02-16 op
52 3baa2617 2022-02-16 op struct imsgev {
53 3baa2617 2022-02-16 op struct imsgbuf ibuf;
54 3baa2617 2022-02-16 op void (*handler)(int, short, void *);
55 3baa2617 2022-02-16 op struct event ev;
56 3baa2617 2022-02-16 op short events;
57 3baa2617 2022-02-16 op };
58 3baa2617 2022-02-16 op
59 3baa2617 2022-02-16 op enum actions {
60 3baa2617 2022-02-16 op NONE,
61 3baa2617 2022-02-16 op PLAY,
62 3baa2617 2022-02-16 op PAUSE,
63 3baa2617 2022-02-16 op TOGGLE,
64 3baa2617 2022-02-16 op STOP,
65 3baa2617 2022-02-16 op RESTART,
66 3baa2617 2022-02-16 op ADD,
67 3baa2617 2022-02-16 op FLUSH,
68 3baa2617 2022-02-16 op SHOW,
69 bb3f279f 2022-02-16 op STATUS,
70 af27e631 2022-02-17 op PREV,
71 af27e631 2022-02-17 op NEXT,
72 14be015f 2022-02-17 op LOAD,
73 3baa2617 2022-02-16 op };
74 3baa2617 2022-02-16 op
75 3baa2617 2022-02-16 op struct ctl_command;
76 3baa2617 2022-02-16 op
77 3baa2617 2022-02-16 op struct parse_result {
78 3baa2617 2022-02-16 op enum actions action;
79 3baa2617 2022-02-16 op char **files;
80 14be015f 2022-02-17 op FILE *file;
81 3baa2617 2022-02-16 op struct ctl_command *ctl;
82 3baa2617 2022-02-16 op };
83 3baa2617 2022-02-16 op
84 3baa2617 2022-02-16 op struct ctl_command {
85 3baa2617 2022-02-16 op const char *name;
86 3baa2617 2022-02-16 op enum actions action;
87 3baa2617 2022-02-16 op int (*main)(struct parse_result *, int, char **);
88 3baa2617 2022-02-16 op const char *usage;
89 3baa2617 2022-02-16 op int has_pledge;
90 3baa2617 2022-02-16 op };
91 3baa2617 2022-02-16 op
92 bb3f279f 2022-02-16 op struct player_status {
93 bb3f279f 2022-02-16 op char path[PATH_MAX];
94 bb3f279f 2022-02-16 op int status;
95 bb3f279f 2022-02-16 op };
96 bb3f279f 2022-02-16 op
97 3baa2617 2022-02-16 op /* amused.c */
98 fea541a8 2022-02-16 op void spawn_daemon(void);
99 3baa2617 2022-02-16 op void imsg_event_add(struct imsgev *iev);
100 3baa2617 2022-02-16 op int imsg_compose_event(struct imsgev *, uint16_t, uint32_t,
101 3baa2617 2022-02-16 op pid_t, int, const void *, uint16_t);
102 06961b72 2022-02-16 op int main_send_player(uint16_t, int, const void *, uint16_t);
103 2f589330 2022-02-17 op void main_playlist_resume(void);
104 aaccc123 2022-02-16 op void main_playlist_advance(void);
105 af27e631 2022-02-17 op void main_playlist_previous(void);
106 aaccc123 2022-02-16 op void main_restart_track(void);
107 3baa2617 2022-02-16 op void main_enqueue(struct imsgev *, struct imsg *);
108 d980494c 2022-02-16 op void main_send_playlist(struct imsgev *);
109 bb3f279f 2022-02-16 op void main_send_status(struct imsgev *);
110 3baa2617 2022-02-16 op
111 3baa2617 2022-02-16 op /* ctl.c */
112 3baa2617 2022-02-16 op __dead void usage(void);
113 3baa2617 2022-02-16 op __dead void ctl(int, char **);
114 3baa2617 2022-02-16 op
115 3baa2617 2022-02-16 op /* player.c */
116 3baa2617 2022-02-16 op int player_setrate(int);
117 3baa2617 2022-02-16 op void player_senderr(void);
118 3baa2617 2022-02-16 op void player_sendeof(void);
119 3baa2617 2022-02-16 op int player_shouldstop(void);
120 3baa2617 2022-02-16 op int player(int, int);
121 3baa2617 2022-02-16 op
122 3baa2617 2022-02-16 op void play_oggvorbis(int fd);
123 3baa2617 2022-02-16 op void play_mp3(int fd);
124 3baa2617 2022-02-16 op void play_flac(int fd);
125 3baa2617 2022-02-16 op void play_opus(int fd);
126 3baa2617 2022-02-16 op
127 3baa2617 2022-02-16 op #endif