chiark / gitweb /
move speaker declarations to speaker.h
authorrjk@greenend.org.uk <>
Mon, 24 Sep 2007 11:38:18 +0000 (12:38 +0100)
committerrjk@greenend.org.uk <>
Mon, 24 Sep 2007 11:38:18 +0000 (12:38 +0100)
lib/speaker-protocol.h
server/Makefile.am
server/speaker.c
server/speaker.h [new file with mode: 0644]

index b7f27e797110d3d18f55999d282aa8d3cf184044..eb2a1ae116d2316181a907a4bbbba1a2596b7d28 100644 (file)
@@ -24,8 +24,8 @@
  * process communicate.
  */
 
-#ifndef SPEAKER_H
-#define SPEAKER_H
+#ifndef SPEAKER_PROTOCOL_H
+#define SPEAKER_PROTOCOL_H
 
 /** @brief A message from the main server to the speaker, or vica versa */
 struct speaker_message {
@@ -104,7 +104,7 @@ int speaker_recv(int fd, struct speaker_message *sm, int *datafd);
  * on EOF, +ve if a message is read, -1 on EAGAIN, terminates on any other
  * error. */
 
-#endif /* SPEAKER_H */
+#endif /* SPEAKER_PROTOCOL_H */
 
 /*
 Local Variables:
index 906ce98ecb8e65116466713716571421d590238c..290393b7d19e24de9e76e0f31ccef5c381167512 100644 (file)
@@ -45,7 +45,7 @@ disorder_deadlock_LDADD=$(LIBOBJS) ../lib/libdisorder.a \
        $(LIBDB) $(LIBPCRE) $(LIBICONV)
 disorder_deadlock_DEPENDENCIES=../lib/libdisorder.a
 
-disorder_speaker_SOURCES=speaker.c
+disorder_speaker_SOURCES=speaker.c speaker.h
 disorder_speaker_LDADD=$(LIBOBJS) ../lib/libdisorder.a \
        $(LIBASOUND) $(LIBPCRE) $(LIBICONV) $(LIBGCRYPT)
 disorder_speaker_DEPENDENCIES=../lib/libdisorder.a
index 2114db49aeca66671bcacb5b0feaefcecaeb143e..172671b0ec8d994ad8042899f667b297bb8f1421 100644 (file)
@@ -18,7 +18,7 @@
  * USA
  */
 /** @file server/speaker.c
- * @brief Speaker processs
+ * @brief Speaker process
  *
  * This program is responsible for transmitting a single coherent audio stream
  * to its destination (over the network, to some sound API, to some
 #include "addr.h"
 #include "timeval.h"
 #include "rtp.h"
+#include "speaker.h"
 
 #if API_ALSA
 #include <alsa/asoundlib.h>
 #endif
 
-#ifdef WORDS_BIGENDIAN
-# define MACHINE_AO_FMT AO_FMT_BIG
-#else
-# define MACHINE_AO_FMT AO_FMT_LITTLE
-#endif
-
-/** @brief How many seconds of input to buffer
- *
- * While any given connection has this much audio buffered, no more reads will
- * be issued for that connection.  The decoder will have to wait.
- */
-#define BUFFER_SECONDS 5
-
-/** @brief Frame batch size
- *
- * This controls how many frames are written in one go.
- *
- * For ALSA we request a buffer of three times this size and set the low
- * watermark to this amount.  The goal is then to keep between 1 and 3 times
- * this many frames in play.
- *
- * For all backends we attempt to play up to three times this many frames per
- * shot.  In practice we will often only send much less than this.
- */
-#define FRAMES 4096
-
-/** @brief Bytes to send per network packet
- *
- * Don't make this too big or arithmetic will start to overflow.
- */
-#define NETWORK_BYTES (1024+sizeof(struct rtp_header))
+/** @brief Linked list of all prepared tracks */
+struct track *tracks;
 
-/** @brief Maximum RTP playahead (ms) */
-#define RTP_AHEAD_MS 1000
-
-/** @brief Maximum number of FDs to poll for */
-#define NFDS 256
-
-/** @brief Track structure
- *
- * Known tracks are kept in a linked list.  Usually there will be at most two
- * of these but rearranging the queue can cause there to be more.
- */
-static struct track {
-  struct track *next;                   /* next track */
-  int fd;                               /* input FD */
-  char id[24];                          /* ID */
-  size_t start, used;                   /* start + bytes used */
-  int eof;                              /* input is at EOF */
-  int got_format;                       /* got format yet? */
-  ao_sample_format format;              /* sample format */
-  unsigned long long played;            /* number of frames played */
-  char *buffer;                         /* sample buffer */
-  size_t size;                          /* sample buffer size */
-  int slot;                             /* poll array slot */
-} *tracks, *playing;                    /* all tracks + playing track */
+/** @brief Playing track, or NULL */
+struct track *playing;
 
 static time_t last_report;              /* when we last reported */
 static int paused;                      /* pause status */
@@ -226,77 +176,6 @@ static int idled;                       /* set when idled */
 /** @brief Error counter */
 static int audio_errors;
 
-/** @brief Structure of a backend */
-struct speaker_backend {
-  /** @brief Which backend this is
-   *
-   * @c -1 terminates the list.
-   */
-  int backend;
-
-  /** @brief Flags
-   *
-   * Possible values
-   * - @ref FIXED_FORMAT
-   */
-  unsigned flags;
-/** @brief Lock to configured sample format */
-#define FIXED_FORMAT 0x0001
-  
-  /** @brief Initialization
-   *
-   * Called once at startup.  This is responsible for one-time setup
-   * operations, for instance opening a network socket to transmit to.
-   *
-   * When writing to a native sound API this might @b not imply opening the
-   * native sound device - that might be done by @c activate below.
-   */
-  void (*init)(void);
-
-  /** @brief Activation
-   * @return 0 on success, non-0 on error
-   *
-   * Called to activate the output device.
-   *
-   * After this function succeeds, @ref ready should be non-0.  As well as
-   * opening the audio device, this function is responsible for reconfiguring
-   * if it necessary to cope with different samples formats (for backends that
-   * don't demand a single fixed sample format for the lifetime of the server).
-   */
-  int (*activate)(void);
-
-  /** @brief Play sound
-   * @param frames Number of frames to play
-   * @return Number of frames actually played
-   */
-  size_t (*play)(size_t frames);
-  
-  /** @brief Deactivation
-   *
-   * Called to deactivate the sound device.  This is the inverse of
-   * @c activate above.
-   */
-  void (*deactivate)(void);
-
-  /** @brief Called before poll()
-   *
-   * Called before the call to poll().  Should call addfd() to update the FD
-   * array and stash the slot number somewhere safe.
-   */
-  void (*beforepoll)(void);
-
-  /** @brief Called after poll()
-   * @return 0 if we could play, non-0 if not
-   *
-   * Called after the call to poll().  Should arrange to play some audio if the
-   * output device is ready.
-   *
-   * The return value should be 0 if the device was ready to play, or nonzero
-   * if it was not.
-   */
-  int (*afterpoll)(void);
-};
-
 /** @brief Selected backend */
 static const struct speaker_backend *backend;
 
diff --git a/server/speaker.h b/server/speaker.h
new file mode 100644 (file)
index 0000000..81c2ff4
--- /dev/null
@@ -0,0 +1,169 @@
+/*
+ * This file is part of DisOrder
+ * Copyright (C) 2005, 2006, 2007 Richard Kettlewell
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+/** @file server/speaker.h
+ * @brief Speaker process
+ */
+#ifndef SPEAKER_H
+#define SPEAKER_H
+
+#ifdef WORDS_BIGENDIAN
+# define MACHINE_AO_FMT AO_FMT_BIG
+#else
+# define MACHINE_AO_FMT AO_FMT_LITTLE
+#endif
+
+/** @brief How many seconds of input to buffer
+ *
+ * While any given connection has this much audio buffered, no more reads will
+ * be issued for that connection.  The decoder will have to wait.
+ */
+#define BUFFER_SECONDS 5
+
+/** @brief Frame batch size
+ *
+ * This controls how many frames are written in one go.
+ *
+ * For ALSA we request a buffer of three times this size and set the low
+ * watermark to this amount.  The goal is then to keep between 1 and 3 times
+ * this many frames in play.
+ *
+ * For all backends we attempt to play up to three times this many frames per
+ * shot.  In practice we will often only send much less than this.
+ */
+#define FRAMES 4096
+
+/** @brief Bytes to send per network packet
+ *
+ * Don't make this too big or arithmetic will start to overflow.
+ */
+#define NETWORK_BYTES (1024+sizeof(struct rtp_header))
+
+/** @brief Maximum RTP playahead (ms) */
+#define RTP_AHEAD_MS 1000
+
+/** @brief Maximum number of FDs to poll for */
+#define NFDS 256
+
+/** @brief Track structure
+ *
+ * Known tracks are kept in a linked list.  Usually there will be at most two
+ * of these but rearranging the queue can cause there to be more.
+ */
+struct track {
+  struct track *next;                   /* next track */
+  int fd;                               /* input FD */
+  char id[24];                          /* ID */
+  size_t start, used;                   /* start + bytes used */
+  int eof;                              /* input is at EOF */
+  int got_format;                       /* got format yet? */
+  ao_sample_format format;              /* sample format */
+  unsigned long long played;            /* number of frames played */
+  char *buffer;                         /* sample buffer */
+  size_t size;                          /* sample buffer size */
+  int slot;                             /* poll array slot */
+};
+
+/** @brief Structure of a backend */
+struct speaker_backend {
+  /** @brief Which backend this is
+   *
+   * @c -1 terminates the list.
+   */
+  int backend;
+
+  /** @brief Flags
+   *
+   * Possible values
+   * - @ref FIXED_FORMAT
+   */
+  unsigned flags;
+/** @brief Lock to configured sample format */
+#define FIXED_FORMAT 0x0001
+  
+  /** @brief Initialization
+   *
+   * Called once at startup.  This is responsible for one-time setup
+   * operations, for instance opening a network socket to transmit to.
+   *
+   * When writing to a native sound API this might @b not imply opening the
+   * native sound device - that might be done by @c activate below.
+   */
+  void (*init)(void);
+
+  /** @brief Activation
+   * @return 0 on success, non-0 on error
+   *
+   * Called to activate the output device.
+   *
+   * After this function succeeds, @ref ready should be non-0.  As well as
+   * opening the audio device, this function is responsible for reconfiguring
+   * if it necessary to cope with different samples formats (for backends that
+   * don't demand a single fixed sample format for the lifetime of the server).
+   */
+  int (*activate)(void);
+
+  /** @brief Play sound
+   * @param frames Number of frames to play
+   * @return Number of frames actually played
+   */
+  size_t (*play)(size_t frames);
+  
+  /** @brief Deactivation
+   *
+   * Called to deactivate the sound device.  This is the inverse of
+   * @c activate above.
+   */
+  void (*deactivate)(void);
+
+  /** @brief Called before poll()
+   *
+   * Called before the call to poll().  Should call addfd() to update the FD
+   * array and stash the slot number somewhere safe.
+   */
+  void (*beforepoll)(void);
+
+  /** @brief Called after poll()
+   * @return 0 if we could play, non-0 if not
+   *
+   * Called after the call to poll().  Should arrange to play some audio if the
+   * output device is ready.
+   *
+   * The return value should be 0 if the device was ready to play, or nonzero
+   * if it was not.
+   */
+  int (*afterpoll)(void);
+};
+
+/** @brief Linked list of all prepared tracks */
+extern struct track *tracks;
+
+/** @brief Playing track, or NULL */
+extern struct track *playing;
+
+#endif /* SPEAKER_H */
+
+/*
+Local Variables:
+c-basic-offset:2
+comment-column:40
+fill-column:79
+indent-tabs-mode:nil
+End:
+*/