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_POS,
34 IMSG_LEN,
35 IMSG_EOF,
36 IMSG_ERR, /* error string */
38 IMSG_CTL_PLAY, /* with optional filename */
39 IMSG_CTL_TOGGLE_PLAY,
40 IMSG_CTL_PAUSE,
41 IMSG_CTL_STOP,
42 IMSG_CTL_RESTART,
43 IMSG_CTL_FLUSH,
44 IMSG_CTL_SHOW,
45 IMSG_CTL_STATUS,
46 IMSG_CTL_NEXT,
47 IMSG_CTL_PREV,
48 IMSG_CTL_JUMP,
49 IMSG_CTL_REPEAT, /* struct player_repeat */
50 IMSG_CTL_SEEK, /* struct player_seek */
52 IMSG_CTL_BEGIN,
53 IMSG_CTL_ADD, /* path to a file */
54 IMSG_CTL_COMMIT, /* offset of the track to jump to */
56 IMSG_CTL_MONITOR,
58 IMSG_CTL_ERR,
59 IMSG__LAST,
60 };
62 struct imsgev {
63 struct imsgbuf ibuf;
64 void (*handler)(int, short, void *);
65 struct event ev;
66 short events;
67 };
69 enum actions {
70 NONE,
71 PLAY,
72 PAUSE,
73 TOGGLE,
74 STOP,
75 RESTART,
76 ADD,
77 FLUSH,
78 SHOW,
79 STATUS,
80 PREV,
81 NEXT,
82 LOAD,
83 JUMP,
84 REPEAT,
85 MONITOR,
86 SEEK,
87 };
89 struct player_seek {
90 int64_t offset;
91 int relative;
92 };
94 struct ctl_command;
96 struct player_repeat {
97 int repeat_one;
98 int repeat_all;
99 };
101 struct player_status {
102 char path[PATH_MAX];
103 int status;
104 int64_t position;
105 int64_t duration;
106 struct player_repeat rp;
107 };
109 struct parse_result {
110 enum actions action;
111 char **files;
112 const char *file;
113 int pretty;
114 int monitor[IMSG__LAST];
115 struct player_repeat rep;
116 struct player_seek seek;
117 struct ctl_command *ctl;
118 };
120 struct ctl_command {
121 const char *name;
122 enum actions action;
123 int (*main)(struct parse_result *, int, char **);
124 const char *usage;
125 int has_pledge;
126 };
128 struct playlist;
130 /* amused.c */
131 void spawn_daemon(void);
132 void imsg_event_add(struct imsgev *iev);
133 int imsg_compose_event(struct imsgev *, uint16_t, uint32_t,
134 pid_t, int, const void *, uint16_t);
135 int main_send_player(uint16_t, int, const void *, size_t);
136 int main_play_song(const char *);
137 void main_playlist_jump(struct imsgev *, struct imsg *);
138 void main_playlist_resume(void);
139 void main_playlist_advance(void);
140 void main_playlist_previous(void);
141 void main_restart_track(void);
142 void main_senderr(struct imsgev *, const char *);
143 void main_enqueue(int, struct playlist *, struct imsgev *, struct imsg *);
144 void main_send_playlist(struct imsgev *);
145 void main_send_status(struct imsgev *);
147 /* ctl.c */
148 __dead void usage(void);
149 __dead void ctl(int, char **);
151 /* player.c */
152 int player_setup(unsigned int, unsigned int, unsigned int);
153 void player_setduration(int64_t);
154 void player_setpos(int64_t);
155 int play(const void *, size_t, int64_t *);
156 int player(int, int);
158 int play_oggvorbis(int, const char **);
159 int play_mp3(int, const char **);
160 int play_flac(int, const char **);
161 int play_opus(int, const char **);
163 #endif