2
0

shout.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /* shout.h
  2. *
  3. * API for libshout, the streaming library for icecast
  4. *
  5. * Copyright (C) 2002-2003 the Icecast team <team@icecast.org>
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Library General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Library General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Library General Public
  18. * License along with this library; if not, write to the Free
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #ifndef __LIBSHOUT_SHOUT_H__
  22. #define __LIBSHOUT_SHOUT_H__
  23. #include <sys/types.h>
  24. #ifdef WIN32
  25. #include <os.h>
  26. # ifdef _MSC_VER
  27. # undef inline
  28. # define inline __inline
  29. #if (_MSC_VER >= 1400) // VC8+
  30. #ifndef _CRT_SECURE_NO_DEPRECATE
  31. #define _CRT_SECURE_NO_DEPRECATE
  32. #endif
  33. #ifndef _CRT_NONSTDC_NO_DEPRECATE
  34. #define _CRT_NONSTDC_NO_DEPRECATE
  35. #endif
  36. #endif // VC8+
  37. # endif
  38. #ifndef __MINGW32__
  39. #define va_copy(ap1, ap2) memcpy(&ap1, &ap2, sizeof(va_list))
  40. #endif
  41. #endif
  42. #define SHOUTERR_SUCCESS (0)
  43. #define SHOUTERR_INSANE (-1)
  44. #define SHOUTERR_NOCONNECT (-2)
  45. #define SHOUTERR_NOLOGIN (-3)
  46. #define SHOUTERR_SOCKET (-4)
  47. #define SHOUTERR_MALLOC (-5)
  48. #define SHOUTERR_METADATA (-6)
  49. #define SHOUTERR_CONNECTED (-7)
  50. #define SHOUTERR_UNCONNECTED (-8)
  51. #define SHOUTERR_UNSUPPORTED (-9)
  52. #define SHOUTERR_BUSY (-10)
  53. #define SHOUT_FORMAT_OGG (0)
  54. #define SHOUT_FORMAT_MP3 (1)
  55. /* backward-compatibility alias */
  56. #define SHOUT_FORMAT_VORBIS SHOUT_FORMAT_OGG
  57. #define SHOUT_PROTOCOL_HTTP (0)
  58. #define SHOUT_PROTOCOL_XAUDIOCAST (1)
  59. #define SHOUT_PROTOCOL_ICY (2)
  60. #define SHOUT_AI_BITRATE "bitrate"
  61. #define SHOUT_AI_SAMPLERATE "samplerate"
  62. #define SHOUT_AI_CHANNELS "channels"
  63. #define SHOUT_AI_QUALITY "quality"
  64. typedef struct shout shout_t;
  65. typedef struct _util_dict shout_metadata_t;
  66. #ifdef __cplusplus
  67. extern "C" {
  68. #endif
  69. /* initializes the shout library. Must be called before anything else */
  70. void shout_init(void);
  71. /* shuts down the shout library, deallocating any global storage. Don't call
  72. * anything afterwards */
  73. void shout_shutdown(void);
  74. /* returns a static version string. Non-null parameters will be set to the
  75. * value of the library major, minor, and patch levels, respectively */
  76. const char *shout_version(int *major, int *minor, int *patch);
  77. /* Allocates and sets up a new shout_t. Returns NULL if it can't get enough
  78. * memory. The returns shout_t must be disposed of with shout_free. */
  79. shout_t *shout_new(void);
  80. /* Free all memory allocated by a shout_t */
  81. void shout_free(shout_t *self);
  82. /* Returns a statically allocated string describing the last shout error
  83. * to occur. Only valid until the next libshout call on this shout_t */
  84. const char *shout_get_error(shout_t *self);
  85. /* Return the error code (e.g. SHOUTERR_SOCKET) for this shout instance */
  86. int shout_get_errno(shout_t *self);
  87. /* returns SHOUTERR_CONNECTED or SHOUTERR_UNCONNECTED */
  88. int shout_get_connected(shout_t *self);
  89. /* Parameter manipulation functions. libshout makes copies of all parameters,
  90. * the caller may free its copies after giving them to libshout. May return
  91. * SHOUTERR_MALLOC */
  92. int shout_set_host(shout_t *self, const char *host);
  93. const char *shout_get_host(shout_t *self);
  94. int shout_set_port(shout_t *self, unsigned short port);
  95. unsigned short shout_get_port(shout_t *self);
  96. int shout_set_password(shout_t *, const char *password);
  97. const char *shout_get_password(shout_t *self);
  98. int shout_set_mount(shout_t *self, const char *mount);
  99. const char *shout_get_mount(shout_t *self);
  100. int shout_set_name(shout_t *self, const char *name);
  101. const char *shout_get_name(shout_t *self);
  102. int shout_set_url(shout_t *self, const char *url);
  103. const char *shout_get_url(shout_t *self);
  104. int shout_set_genre(shout_t *self, const char *genre);
  105. const char *shout_get_genre(shout_t *self);
  106. int shout_set_user(shout_t *self, const char *username);
  107. const char *shout_get_user(shout_t *self);
  108. int shout_set_agent(shout_t *self, const char *username);
  109. const char *shout_get_agent(shout_t *self);
  110. int shout_set_description(shout_t *self, const char *description);
  111. const char *shout_get_description(shout_t *self);
  112. int shout_set_dumpfile(shout_t *self, const char *dumpfile);
  113. const char *shout_get_dumpfile(shout_t *self);
  114. int shout_set_audio_info(shout_t *self, const char *name, const char *value);
  115. const char *shout_get_audio_info(shout_t *self, const char *name);
  116. int shout_set_public(shout_t *self, unsigned int make_public);
  117. unsigned int shout_get_public(shout_t *self);
  118. /* takes a SHOUT_FORMAT_xxxx argument */
  119. int shout_set_format(shout_t *self, unsigned int format);
  120. unsigned int shout_get_format(shout_t *self);
  121. /* takes a SHOUT_PROTOCOL_xxxxx argument */
  122. int shout_set_protocol(shout_t *self, unsigned int protocol);
  123. unsigned int shout_get_protocol(shout_t *self);
  124. /* Instructs libshout to use nonblocking I/O. Must be called before
  125. * shout_open (no switching back and forth midstream at the moment). */
  126. int shout_set_nonblocking(shout_t* self, unsigned int nonblocking);
  127. unsigned int shout_get_nonblocking(shout_t *self);
  128. /* Opens a connection to the server. All parameters must already be set */
  129. int shout_open(shout_t *self);
  130. /* Closes a connection to the server */
  131. int shout_close(shout_t *self);
  132. /* Send data to the server, parsing it for format specific timing info */
  133. int shout_send(shout_t *self, const unsigned char *data, size_t len);
  134. /* Send unparsed data to the server. Do not use this unless you know
  135. * what you are doing.
  136. * Returns the number of bytes written, or < 0 on error.
  137. */
  138. ssize_t shout_send_raw(shout_t *self, const unsigned char *data, size_t len);
  139. /* return the number of bytes currently on the write queue (only makes sense in
  140. * nonblocking mode). */
  141. ssize_t shout_queuelen(shout_t *self);
  142. /* Puts caller to sleep until it is time to send more data to the server */
  143. void shout_sync(shout_t *self);
  144. /* Amount of time in ms caller should wait before sending again */
  145. int shout_delay(shout_t *self);
  146. /* Sets MP3 metadata.
  147. * Returns:
  148. * SHOUTERR_SUCCESS
  149. * SHOUTERR_UNSUPPORTED if format isn't MP3
  150. * SHOUTERR_MALLOC
  151. * SHOUTERR_INSANE
  152. * SHOUTERR_NOCONNECT
  153. * SHOUTERR_SOCKET
  154. */
  155. int shout_set_metadata(shout_t *self, shout_metadata_t *metadata);
  156. /* Allocates a new metadata structure. Must be freed by shout_metadata_free. */
  157. shout_metadata_t *shout_metadata_new(void);
  158. /* Free resources allocated by shout_metadata_t */
  159. void shout_metadata_free(shout_metadata_t *self);
  160. /* Add a parameter to the metadata structure.
  161. * Returns:
  162. * SHOUTERR_SUCCESS on success
  163. * SHOUTERR_INSANE if self isn't a valid shout_metadata_t* or name is null
  164. * SHOUTERR_MALLOC if memory can't be allocated */
  165. int shout_metadata_add(shout_metadata_t *self, const char *name, const char *value);
  166. #ifdef __cplusplus
  167. }
  168. #endif
  169. /* --- Compiled features --- */
  170. #define SHOUT_THREADSAFE @SHOUT_THREADSAFE@
  171. #endif /* __LIBSHOUT_SHOUT_H__ */