Commit | Line | Data |
---|---|---|
ea410ba1 | 1 | /* |
2 | * This file is part of DisOrder | |
e3953a41 | 3 | * Copyright (C) 2005, 2007, 2008, 2013 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 | 28 | #include "byte-order.h" |
cca89d7c RK |
29 | #if HAVE_NETINET_IN_H |
30 | # include <netinet/in.h> | |
31 | #endif | |
929f577e | 32 | |
ea410ba1 | 33 | /** @brief A message from the main server to the speaker, or vica versa */ |
34 | struct speaker_message { | |
35 | /** @brief Message type | |
36 | * | |
e3953a41 | 37 | * Messages from the main server: |
ea410ba1 | 38 | * - @ref SM_PLAY |
39 | * - @ref SM_PAUSE | |
40 | * - @ref SM_RESUME | |
41 | * - @ref SM_CANCEL | |
42 | * - @ref SM_RELOAD | |
7f97fda7 RK |
43 | * - @ref SM_RTP_REQUEST |
44 | * - @ref SM_RTP_CANCEL | |
ea410ba1 | 45 | * |
46 | * Messages from the speaker: | |
47 | * - @ref SM_PAUSED | |
48 | * - @ref SM_FINISHED | |
49 | * - @ref SM_PLAYING | |
2b2a5fed | 50 | * - @ref SM_UNKNOWN |
2a1c84fb | 51 | * - @ref SM_ARRIVED |
ea410ba1 | 52 | */ |
53 | int type; | |
54 | ||
55 | /** @brief Message-specific data */ | |
56 | long data; | |
57 | ||
e3953a41 RK |
58 | union { |
59 | /** @brief Track ID (including 0 terminator) */ | |
60 | char id[24]; /* ID including terminator */ | |
7f97fda7 RK |
61 | |
62 | /** @brief An IP address (for @ref SM_RTP_REQUEST and @ref SM_RTP_CANCEL) */ | |
63 | struct sockaddr_storage address; | |
e3953a41 | 64 | } u; |
ea410ba1 | 65 | }; |
66 | ||
67 | /* messages from the main DisOrder server */ | |
ea410ba1 | 68 | |
69 | /** @brief Play track @c id | |
70 | * | |
71 | * The track must already have been prepared. | |
72 | */ | |
73 | #define SM_PLAY 1 | |
74 | ||
75 | /** @brief Pause current track */ | |
76 | #define SM_PAUSE 2 | |
77 | ||
78 | /** @brief Resume current track */ | |
79 | #define SM_RESUME 3 | |
80 | ||
81 | /** @brief Cancel track @c id */ | |
82 | #define SM_CANCEL 4 | |
83 | ||
84 | /** @brief Reload configuration */ | |
85 | #define SM_RELOAD 5 | |
86 | ||
7f97fda7 RK |
87 | /** @brief Reload configuration */ |
88 | #define SM_RTP_REQUEST 6 | |
89 | ||
90 | /** @brief Reload configuration */ | |
91 | #define SM_RTP_CANCEL 7 | |
92 | ||
ea410ba1 | 93 | /* messages from the speaker */ |
94 | /** @brief Paused track @c id, @c data seconds in | |
95 | * | |
96 | * There is no @c SM_RESUMED, instead @ref SM_PLAYING is sent after the track | |
97 | * starts playing again. | |
98 | */ | |
99 | #define SM_PAUSED 128 | |
100 | ||
101 | /** @brief Finished playing track @c id */ | |
102 | #define SM_FINISHED 129 | |
103 | ||
2b2a5fed RK |
104 | /** @brief Never heard of track @c id */ |
105 | #define SM_UNKNOWN 130 | |
106 | ||
ea410ba1 | 107 | /** @brief Currently track @c id, @c data seconds in |
108 | * | |
109 | * This is sent from time to time while a track is playing. | |
110 | */ | |
111 | #define SM_PLAYING 131 | |
112 | ||
937be4c0 RK |
113 | /** @brief Speaker process is ready |
114 | * | |
115 | * This is sent once at startup when the speaker has finished its | |
116 | * initialization. */ | |
117 | #define SM_READY 132 | |
118 | ||
819f5988 RK |
119 | /** @brief Cancelled track @c id which wasn't playing */ |
120 | #define SM_STILLBORN 133 | |
121 | ||
2a1c84fb RK |
122 | /** @brief A connection for track @c id arrived */ |
123 | #define SM_ARRIVED 134 | |
124 | ||
84aa9f93 RK |
125 | void speaker_send(int fd, const struct speaker_message *sm); |
126 | /* Send a message. */ | |
ea410ba1 | 127 | |
84aa9f93 RK |
128 | int speaker_recv(int fd, struct speaker_message *sm); |
129 | /* Receive a message. Return 0 on EOF, +ve if a message is read, -1 on EAGAIN, | |
130 | * terminates on any other error. */ | |
ea410ba1 | 131 | |
6d2d327c RK |
132 | /** @brief One chunk in a stream */ |
133 | struct stream_header { | |
937be4c0 RK |
134 | /** @brief Number of bytes */ |
135 | uint32_t nbytes; | |
136 | ||
6d2d327c RK |
137 | /** @brief Frames per second */ |
138 | uint32_t rate; | |
139 | ||
140 | /** @brief Samples per frames */ | |
141 | uint8_t channels; | |
142 | ||
143 | /** @brief Bits per sample */ | |
144 | uint8_t bits; | |
145 | ||
146 | /** @brief Endianness */ | |
147 | uint8_t endian; | |
6d2d327c RK |
148 | } attribute((packed)); |
149 | ||
150 | static inline int formats_equal(const struct stream_header *a, | |
151 | const struct stream_header *b) { | |
152 | return (a->rate == b->rate | |
153 | && a->channels == b->channels | |
154 | && a->bits == b->bits | |
155 | && a->endian == b->endian); | |
156 | } | |
157 | ||
cf714d85 | 158 | #endif /* SPEAKER_PROTOCOL_H */ |
ea410ba1 | 159 | |
160 | /* | |
161 | Local Variables: | |
162 | c-basic-offset:2 | |
163 | comment-column:40 | |
164 | fill-column:79 | |
165 | indent-tabs-mode:nil | |
166 | End: | |
167 | */ |