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