2 * This file is part of DisOrder
3 * Copyright (C) 2005, 2007, 2008, 2013 Richard Kettlewell
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.
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.
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/>.
18 /** @file lib/speaker-protocol.h
19 * @brief Speaker/server protocol support
21 * This file defines the protocol by which the main server and the speaker
22 * process communicate.
25 #ifndef SPEAKER_PROTOCOL_H
26 #define SPEAKER_PROTOCOL_H
28 #include "byte-order.h"
30 /** @brief A message from the main server to the speaker, or vica versa */
31 struct speaker_message {
32 /** @brief Message type
34 * Messages from the main server:
41 * Messages from the speaker:
50 /** @brief Message-specific data */
54 /** @brief Track ID (including 0 terminator) */
55 char id[24]; /* ID including terminator */
59 /* messages from the main DisOrder server */
61 /** @brief Play track @c id
63 * The track must already have been prepared.
67 /** @brief Pause current track */
70 /** @brief Resume current track */
73 /** @brief Cancel track @c id */
76 /** @brief Reload configuration */
79 /* messages from the speaker */
80 /** @brief Paused track @c id, @c data seconds in
82 * There is no @c SM_RESUMED, instead @ref SM_PLAYING is sent after the track
83 * starts playing again.
87 /** @brief Finished playing track @c id */
88 #define SM_FINISHED 129
90 /** @brief Never heard of track @c id */
91 #define SM_UNKNOWN 130
93 /** @brief Currently track @c id, @c data seconds in
95 * This is sent from time to time while a track is playing.
97 #define SM_PLAYING 131
99 /** @brief Speaker process is ready
101 * This is sent once at startup when the speaker has finished its
105 /** @brief Cancelled track @c id which wasn't playing */
106 #define SM_STILLBORN 133
108 /** @brief A connection for track @c id arrived */
109 #define SM_ARRIVED 134
111 void speaker_send(int fd, const struct speaker_message *sm);
112 /* Send a message. */
114 int speaker_recv(int fd, struct speaker_message *sm);
115 /* Receive a message. Return 0 on EOF, +ve if a message is read, -1 on EAGAIN,
116 * terminates on any other error. */
118 /** @brief One chunk in a stream */
119 struct stream_header {
120 /** @brief Number of bytes */
123 /** @brief Frames per second */
126 /** @brief Samples per frames */
129 /** @brief Bits per sample */
132 /** @brief Endianness */
134 } attribute((packed));
136 static inline int formats_equal(const struct stream_header *a,
137 const struct stream_header *b) {
138 return (a->rate == b->rate
139 && a->channels == b->channels
140 && a->bits == b->bits
141 && a->endian == b->endian);
144 #endif /* SPEAKER_PROTOCOL_H */