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