Commit | Line | Data |
---|---|---|
ea410ba1 | 1 | /* |
2 | * This file is part of DisOrder | |
5aff007d | 3 | * Copyright (C) 2005, 2007, 2008 Richard Kettlewell |
ea410ba1 | 4 | * |
e7eb3a27 | 5 | * This program is free software: you can redistribute it and/or modify |
ea410ba1 | 6 | * it under the terms of the GNU General Public License as published by |
e7eb3a27 | 7 | * the Free Software Foundation, either version 3 of the License, or |
ea410ba1 | 8 | * (at your option) any later version. |
e7eb3a27 RK |
9 | * |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
ea410ba1 | 15 | * You should have received a copy of the GNU General Public License |
e7eb3a27 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
ea410ba1 | 17 | */ |
fbf86993 | 18 | /** @file lib/speaker-protocol.h |
ea410ba1 | 19 | * @brief Speaker/server protocol support |
20 | * | |
21 | * This file defines the protocol by which the main server and the speaker | |
22 | * process communicate. | |
23 | */ | |
24 | ||
cf714d85 | 25 | #ifndef SPEAKER_PROTOCOL_H |
26 | #define SPEAKER_PROTOCOL_H | |
ea410ba1 | 27 | |
929f577e RK |
28 | #include "byte-order.h" |
29 | ||
ea410ba1 | 30 | /** @brief A message from the main server to the speaker, or vica versa */ |
31 | struct speaker_message { | |
32 | /** @brief Message type | |
33 | * | |
34 | * Messges from the main server: | |
ea410ba1 | 35 | * - @ref SM_PLAY |
36 | * - @ref SM_PAUSE | |
37 | * - @ref SM_RESUME | |
38 | * - @ref SM_CANCEL | |
39 | * - @ref SM_RELOAD | |
40 | * | |
41 | * Messages from the speaker: | |
42 | * - @ref SM_PAUSED | |
43 | * - @ref SM_FINISHED | |
44 | * - @ref SM_PLAYING | |
2b2a5fed | 45 | * - @ref SM_UNKNOWN |
ea410ba1 | 46 | */ |
47 | int type; | |
48 | ||
49 | /** @brief Message-specific data */ | |
50 | long data; | |
51 | ||
52 | /** @brief Track ID (including 0 terminator) */ | |
53 | char id[24]; /* ID including terminator */ | |
54 | }; | |
55 | ||
56 | /* messages from the main DisOrder server */ | |
ea410ba1 | 57 | |
58 | /** @brief Play track @c id | |
59 | * | |
60 | * The track must already have been prepared. | |
61 | */ | |
62 | #define SM_PLAY 1 | |
63 | ||
64 | /** @brief Pause current track */ | |
65 | #define SM_PAUSE 2 | |
66 | ||
67 | /** @brief Resume current track */ | |
68 | #define SM_RESUME 3 | |
69 | ||
70 | /** @brief Cancel track @c id */ | |
71 | #define SM_CANCEL 4 | |
72 | ||
73 | /** @brief Reload configuration */ | |
74 | #define SM_RELOAD 5 | |
75 | ||
76 | /* messages from the speaker */ | |
77 | /** @brief Paused track @c id, @c data seconds in | |
78 | * | |
79 | * There is no @c SM_RESUMED, instead @ref SM_PLAYING is sent after the track | |
80 | * starts playing again. | |
81 | */ | |
82 | #define SM_PAUSED 128 | |
83 | ||
84 | /** @brief Finished playing track @c id */ | |
85 | #define SM_FINISHED 129 | |
86 | ||
2b2a5fed RK |
87 | /** @brief Never heard of track @c id */ |
88 | #define SM_UNKNOWN 130 | |
89 | ||
ea410ba1 | 90 | /** @brief Currently track @c id, @c data seconds in |
91 | * | |
92 | * This is sent from time to time while a track is playing. | |
93 | */ | |
94 | #define SM_PLAYING 131 | |
95 | ||
937be4c0 RK |
96 | /** @brief Speaker process is ready |
97 | * | |
98 | * This is sent once at startup when the speaker has finished its | |
99 | * initialization. */ | |
100 | #define SM_READY 132 | |
101 | ||
819f5988 RK |
102 | /** @brief Cancelled track @c id which wasn't playing */ |
103 | #define SM_STILLBORN 133 | |
104 | ||
84aa9f93 RK |
105 | void speaker_send(int fd, const struct speaker_message *sm); |
106 | /* Send a message. */ | |
ea410ba1 | 107 | |
84aa9f93 RK |
108 | int speaker_recv(int fd, struct speaker_message *sm); |
109 | /* Receive a message. Return 0 on EOF, +ve if a message is read, -1 on EAGAIN, | |
110 | * terminates on any other error. */ | |
ea410ba1 | 111 | |
6d2d327c RK |
112 | /** @brief One chunk in a stream */ |
113 | struct stream_header { | |
937be4c0 RK |
114 | /** @brief Number of bytes */ |
115 | uint32_t nbytes; | |
116 | ||
6d2d327c RK |
117 | /** @brief Frames per second */ |
118 | uint32_t rate; | |
119 | ||
120 | /** @brief Samples per frames */ | |
121 | uint8_t channels; | |
122 | ||
123 | /** @brief Bits per sample */ | |
124 | uint8_t bits; | |
125 | ||
126 | /** @brief Endianness */ | |
127 | uint8_t endian; | |
6d2d327c RK |
128 | } attribute((packed)); |
129 | ||
130 | static inline int formats_equal(const struct stream_header *a, | |
131 | const struct stream_header *b) { | |
132 | return (a->rate == b->rate | |
133 | && a->channels == b->channels | |
134 | && a->bits == b->bits | |
135 | && a->endian == b->endian); | |
136 | } | |
137 | ||
cf714d85 | 138 | #endif /* SPEAKER_PROTOCOL_H */ |
ea410ba1 | 139 | |
140 | /* | |
141 | Local Variables: | |
142 | c-basic-offset:2 | |
143 | comment-column:40 | |
144 | fill-column:79 | |
145 | indent-tabs-mode:nil | |
146 | End: | |
147 | */ |