Source code pulled from OpenBSD for OpenNTPD. The place to contribute to this code is via the OpenBSD CVS tree.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

164 lines
4.7 KiB

  1. /* $OpenBSD: sndio.h,v 1.3 2009/07/25 11:27:14 ratchov Exp $ */
  2. /*
  3. * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
  4. *
  5. * Permission to use, copy, modify, and distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #ifndef SNDIO_H
  18. #define SNDIO_H
  19. #include <sys/param.h>
  20. /*
  21. * private ``handle'' structure
  22. */
  23. struct sio_hdl;
  24. struct mio_hdl;
  25. /*
  26. * parameters of a full-duplex stream
  27. */
  28. struct sio_par {
  29. unsigned bits; /* bits per sample */
  30. unsigned bps; /* bytes per sample */
  31. unsigned sig; /* 1 = signed, 0 = unsigned */
  32. unsigned le; /* 1 = LE, 0 = BE byte order */
  33. unsigned msb; /* 1 = MSB, 0 = LSB aligned */
  34. unsigned rchan; /* number channels for recording direction */
  35. unsigned pchan; /* number channels for playback direction */
  36. unsigned rate; /* frames per second */
  37. unsigned bufsz; /* end-to-end buffer size */
  38. #define SIO_IGNORE 0 /* pause during xrun */
  39. #define SIO_SYNC 1 /* resync after xrun */
  40. #define SIO_ERROR 2 /* terminate on xrun */
  41. unsigned xrun; /* what to do on overruns/underruns */
  42. unsigned round; /* optimal bufsz divisor */
  43. unsigned appbufsz; /* minimum buffer size */
  44. int __pad[3]; /* for future use */
  45. int __magic; /* for internal/debug purposes only */
  46. };
  47. /*
  48. * capabilities of a stream
  49. */
  50. struct sio_cap {
  51. #define SIO_NENC 8
  52. #define SIO_NCHAN 8
  53. #define SIO_NRATE 16
  54. #define SIO_NCONF 4
  55. struct sio_enc { /* allowed sample encodings */
  56. unsigned bits;
  57. unsigned bps;
  58. unsigned sig;
  59. unsigned le;
  60. unsigned msb;
  61. } enc[SIO_NENC];
  62. unsigned rchan[SIO_NCHAN]; /* allowed values for rchan */
  63. unsigned pchan[SIO_NCHAN]; /* allowed values for pchan */
  64. unsigned rate[SIO_NRATE]; /* allowed rates */
  65. int __pad[7]; /* for future use */
  66. unsigned nconf; /* number of elements in confs[] */
  67. struct sio_conf {
  68. unsigned enc; /* mask of enc[] indexes */
  69. unsigned rchan; /* mask of chan[] indexes (rec) */
  70. unsigned pchan; /* mask of chan[] indexes (play) */
  71. unsigned rate; /* mask of rate[] indexes */
  72. } confs[SIO_NCONF];
  73. };
  74. #define SIO_XSTRINGS { "ignore", "sync", "error" }
  75. /*
  76. * mode bitmap
  77. */
  78. #define SIO_PLAY 1
  79. #define SIO_REC 2
  80. #define MIO_OUT 4
  81. #define MIO_IN 8
  82. /*
  83. * maximum size of the encording string (the longest possible
  84. * encoding is ``s24le3msb'')
  85. */
  86. #define SIO_ENCMAX 10
  87. /*
  88. * default bytes per sample for the given bits per sample
  89. */
  90. #define SIO_BPS(bits) (((bits) <= 8) ? 1 : (((bits) <= 16) ? 2 : 4))
  91. /*
  92. * default value of "sio_par->le" flag
  93. */
  94. #if BYTE_ORDER == LITTLE_ENDIAN
  95. #define SIO_LE_NATIVE 1
  96. #else
  97. #define SIO_LE_NATIVE 0
  98. #endif
  99. /*
  100. * default device for the sun audio(4) back-end
  101. */
  102. #define SIO_SUN_PATH "/dev/audio"
  103. /*
  104. * default socket name for the aucat(1) back-end
  105. */
  106. #define SIO_AUCAT_PATH "default"
  107. /*
  108. * maximum value of volume, eg. for sio_setvol()
  109. */
  110. #define SIO_MAXVOL 127
  111. #ifdef __cplusplus
  112. extern "C" {
  113. #endif
  114. struct pollfd;
  115. int sio_strtoenc(struct sio_par *, char *);
  116. int sio_enctostr(struct sio_par *, char *);
  117. void sio_initpar(struct sio_par *);
  118. struct sio_hdl *sio_open(const char *, unsigned, int);
  119. void sio_close(struct sio_hdl *);
  120. int sio_setpar(struct sio_hdl *, struct sio_par *);
  121. int sio_getpar(struct sio_hdl *, struct sio_par *);
  122. int sio_getcap(struct sio_hdl *, struct sio_cap *);
  123. void sio_onmove(struct sio_hdl *, void (*)(void *, int), void *);
  124. size_t sio_write(struct sio_hdl *, const void *, size_t);
  125. size_t sio_read(struct sio_hdl *, void *, size_t);
  126. int sio_start(struct sio_hdl *);
  127. int sio_stop(struct sio_hdl *);
  128. int sio_nfds(struct sio_hdl *);
  129. int sio_pollfd(struct sio_hdl *, struct pollfd *, int);
  130. int sio_revents(struct sio_hdl *, struct pollfd *);
  131. int sio_eof(struct sio_hdl *);
  132. int sio_setvol(struct sio_hdl *, unsigned);
  133. void sio_onvol(struct sio_hdl *, void (*)(void *, unsigned), void *);
  134. struct mio_hdl *mio_open(const char *, unsigned, int);
  135. void mio_close(struct mio_hdl *);
  136. size_t mio_write(struct mio_hdl *, const void *, size_t);
  137. size_t mio_read(struct mio_hdl *, void *, size_t);
  138. int mio_nfds(struct mio_hdl *);
  139. int mio_pollfd(struct mio_hdl *, struct pollfd *, int);
  140. int mio_revents(struct mio_hdl *, struct pollfd *);
  141. int mio_eof(struct mio_hdl *);
  142. #ifdef __cplusplus
  143. }
  144. #endif
  145. #endif /* !defined(SNDIO_H) */