2 * This file is part of DisOrder
3 * Copyright (C) 2005, 2007, 2008 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 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * 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, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 /** @file lib/speaker-protocol.h
21 * @brief Speaker/server protocol support
23 * This file defines the protocol by which the main server and the speaker
24 * process communicate.
27 #ifndef SPEAKER_PROTOCOL_H
28 #define SPEAKER_PROTOCOL_H
30 /** @brief A message from the main server to the speaker, or vica versa */
31 struct speaker_message {
32 /** @brief Message type
34 * Messges from the main server:
41 * Messages from the speaker:
49 /** @brief Message-specific data */
52 /** @brief Track ID (including 0 terminator) */
53 char id[24]; /* ID including terminator */
56 /* messages from the main DisOrder server */
58 /** @brief Play track @c id
60 * The track must already have been prepared.
64 /** @brief Pause current track */
67 /** @brief Resume current track */
70 /** @brief Cancel track @c id */
73 /** @brief Reload configuration */
76 /* messages from the speaker */
77 /** @brief Paused track @c id, @c data seconds in
79 * There is no @c SM_RESUMED, instead @ref SM_PLAYING is sent after the track
80 * starts playing again.
84 /** @brief Finished playing track @c id */
85 #define SM_FINISHED 129
87 /** @brief Never heard of track @c id */
88 #define SM_UNKNOWN 130
90 /** @brief Currently track @c id, @c data seconds in
92 * This is sent from time to time while a track is playing.
94 #define SM_PLAYING 131
96 /** @brief Speaker process is ready
98 * This is sent once at startup when the speaker has finished its
102 /** @brief Cancelled track @c id which wasn't playing */
103 #define SM_STILLBORN 133
105 void speaker_send(int fd, const struct speaker_message *sm);
106 /* Send a message. */
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. */
112 /** @brief One chunk in a stream */
113 struct stream_header {
114 /** @brief Number of bytes */
117 /** @brief Frames per second */
120 /** @brief Samples per frames */
123 /** @brief Bits per sample */
126 /** @brief Endianness */
129 #define ENDIAN_LITTLE 2
130 #ifdef WORDS_BIGENDIAN
131 # define ENDIAN_NATIVE ENDIAN_BIG
133 # define ENDIAN_NATIVE ENDIAN_LITTLE
135 } attribute((packed));
137 static inline int formats_equal(const struct stream_header *a,
138 const struct stream_header *b) {
139 return (a->rate == b->rate
140 && a->channels == b->channels
141 && a->bits == b->bits
142 && a->endian == b->endian);
145 #endif /* SPEAKER_PROTOCOL_H */