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 char *csock;
21 3baa2617 2022-02-16 op extern int debug;
22 3baa2617 2022-02-16 op extern int verbose;
23 3baa2617 2022-02-16 op extern int playing;
24 3baa2617 2022-02-16 op extern struct imsgev *iev_player;
25 3baa2617 2022-02-16 op
26 3baa2617 2022-02-16 op #define IMSG_DATA_SIZE(imsg) ((imsg).hdr.len - IMSG_HEADER_SIZE)
27 3baa2617 2022-02-16 op
28 3baa2617 2022-02-16 op enum imsg_type {
29 3baa2617 2022-02-16 op IMSG_PLAY, /* fd + filename */
30 3baa2617 2022-02-16 op IMSG_RESUME,
31 3baa2617 2022-02-16 op IMSG_PAUSE,
32 3baa2617 2022-02-16 op IMSG_STOP,
33 ff06024f 2022-07-08 op IMSG_POS,
34 ff06024f 2022-07-08 op IMSG_LEN,
35 3baa2617 2022-02-16 op IMSG_EOF,
36 17ef54d6 2022-06-22 op IMSG_ERR, /* error string */
37 3baa2617 2022-02-16 op
38 a913de21 2022-02-17 op IMSG_CTL_PLAY, /* with optional filename */
39 3baa2617 2022-02-16 op IMSG_CTL_TOGGLE_PLAY,
40 3baa2617 2022-02-16 op IMSG_CTL_PAUSE,
41 3baa2617 2022-02-16 op IMSG_CTL_STOP,
42 3baa2617 2022-02-16 op IMSG_CTL_RESTART,
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 a913de21 2022-02-17 op IMSG_CTL_JUMP,
49 310ef57c 2022-02-19 op IMSG_CTL_REPEAT, /* struct player_repeat */
50 3baa2617 2022-02-16 op
51 19d6b480 2022-02-17 op IMSG_CTL_BEGIN,
52 19d6b480 2022-02-17 op IMSG_CTL_ADD, /* path to a file */
53 3af93963 2022-03-02 op IMSG_CTL_COMMIT, /* offset of the track to jump to */
54 19d6b480 2022-02-17 op
55 87f575c3 2022-02-21 op IMSG_CTL_MONITOR,
56 87f575c3 2022-02-21 op
57 3baa2617 2022-02-16 op IMSG_CTL_ERR,
58 90122a37 2022-05-14 op IMSG__LAST,
59 3baa2617 2022-02-16 op };
60 3baa2617 2022-02-16 op
61 3baa2617 2022-02-16 op struct imsgev {
62 3baa2617 2022-02-16 op struct imsgbuf ibuf;
63 3baa2617 2022-02-16 op void (*handler)(int, short, void *);
64 3baa2617 2022-02-16 op struct event ev;
65 3baa2617 2022-02-16 op short events;
66 3baa2617 2022-02-16 op };
67 3baa2617 2022-02-16 op
68 3baa2617 2022-02-16 op enum actions {
69 3baa2617 2022-02-16 op NONE,
70 3baa2617 2022-02-16 op PLAY,
71 3baa2617 2022-02-16 op PAUSE,
72 3baa2617 2022-02-16 op TOGGLE,
73 3baa2617 2022-02-16 op STOP,
74 3baa2617 2022-02-16 op RESTART,
75 3baa2617 2022-02-16 op ADD,
76 3baa2617 2022-02-16 op FLUSH,
77 3baa2617 2022-02-16 op SHOW,
78 bb3f279f 2022-02-16 op STATUS,
79 af27e631 2022-02-17 op PREV,
80 af27e631 2022-02-17 op NEXT,
81 14be015f 2022-02-17 op LOAD,
82 a913de21 2022-02-17 op JUMP,
83 310ef57c 2022-02-19 op REPEAT,
84 6b47a39f 2022-02-21 op MONITOR,
85 3baa2617 2022-02-16 op };
86 3baa2617 2022-02-16 op
87 3baa2617 2022-02-16 op struct ctl_command;
88 3baa2617 2022-02-16 op
89 310ef57c 2022-02-19 op struct player_repeat {
90 310ef57c 2022-02-19 op int repeat_one;
91 310ef57c 2022-02-19 op int repeat_all;
92 310ef57c 2022-02-19 op };
93 310ef57c 2022-02-19 op
94 44398779 2022-02-19 op struct player_status {
95 44398779 2022-02-19 op char path[PATH_MAX];
96 44398779 2022-02-19 op int status;
97 ff06024f 2022-07-08 op int64_t position;
98 ff06024f 2022-07-08 op int64_t duration;
99 44398779 2022-02-19 op struct player_repeat rp;
100 44398779 2022-02-19 op };
101 44398779 2022-02-19 op
102 3baa2617 2022-02-16 op struct parse_result {
103 3baa2617 2022-02-16 op enum actions action;
104 3baa2617 2022-02-16 op char **files;
105 ec1fb0c7 2022-02-17 op const char *file;
106 8e916714 2022-02-17 op int pretty;
107 90122a37 2022-05-14 op int monitor[IMSG__LAST];
108 310ef57c 2022-02-19 op struct player_repeat rep;
109 3baa2617 2022-02-16 op struct ctl_command *ctl;
110 3baa2617 2022-02-16 op };
111 3baa2617 2022-02-16 op
112 3baa2617 2022-02-16 op struct ctl_command {
113 3baa2617 2022-02-16 op const char *name;
114 3baa2617 2022-02-16 op enum actions action;
115 3baa2617 2022-02-16 op int (*main)(struct parse_result *, int, char **);
116 3baa2617 2022-02-16 op const char *usage;
117 3baa2617 2022-02-16 op int has_pledge;
118 3baa2617 2022-02-16 op };
119 3baa2617 2022-02-16 op
120 19d6b480 2022-02-17 op struct playlist;
121 19d6b480 2022-02-17 op
122 3baa2617 2022-02-16 op /* amused.c */
123 fea541a8 2022-02-16 op void spawn_daemon(void);
124 3baa2617 2022-02-16 op void imsg_event_add(struct imsgev *iev);
125 3baa2617 2022-02-16 op int imsg_compose_event(struct imsgev *, uint16_t, uint32_t,
126 3baa2617 2022-02-16 op pid_t, int, const void *, uint16_t);
127 5d86bc14 2022-05-10 op int main_send_player(uint16_t, int);
128 f3bd773b 2022-02-19 op int main_play_song(const char *);
129 a913de21 2022-02-17 op void main_playlist_jump(struct imsgev *, struct imsg *);
130 2f589330 2022-02-17 op void main_playlist_resume(void);
131 aaccc123 2022-02-16 op void main_playlist_advance(void);
132 af27e631 2022-02-17 op void main_playlist_previous(void);
133 aaccc123 2022-02-16 op void main_restart_track(void);
134 19d6b480 2022-02-17 op void main_senderr(struct imsgev *, const char *);
135 19d6b480 2022-02-17 op void main_enqueue(int, struct playlist *, struct imsgev *, struct imsg *);
136 d980494c 2022-02-16 op void main_send_playlist(struct imsgev *);
137 bb3f279f 2022-02-16 op void main_send_status(struct imsgev *);
138 3baa2617 2022-02-16 op
139 3baa2617 2022-02-16 op /* ctl.c */
140 3baa2617 2022-02-16 op __dead void usage(void);
141 3baa2617 2022-02-16 op __dead void ctl(int, char **);
142 3baa2617 2022-02-16 op
143 3baa2617 2022-02-16 op /* player.c */
144 e24324f1 2022-02-21 op int player_setup(int, int, int);
145 ff06024f 2022-07-08 op void player_setduration(int64_t);
146 2139c525 2022-03-09 op int play(const void *, size_t);
147 3baa2617 2022-02-16 op int player(int, int);
148 3baa2617 2022-02-16 op
149 17ef54d6 2022-06-22 op int play_oggvorbis(int, const char **);
150 17ef54d6 2022-06-22 op int play_mp3(int, const char **);
151 17ef54d6 2022-06-22 op int play_flac(int, const char **);
152 17ef54d6 2022-06-22 op int play_opus(int, const char **);
153 3baa2617 2022-02-16 op
154 3baa2617 2022-02-16 op #endif