speex_header.h 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* Copyright (C) 2002 Jean-Marc Valin */
  2. /**
  3. @file speex_header.h
  4. @brief Describes the Speex header
  5. */
  6. /*
  7. Redistribution and use in source and binary forms, with or without
  8. modification, are permitted provided that the following conditions
  9. are met:
  10. - Redistributions of source code must retain the above copyright
  11. notice, this list of conditions and the following disclaimer.
  12. - Redistributions in binary form must reproduce the above copyright
  13. notice, this list of conditions and the following disclaimer in the
  14. documentation and/or other materials provided with the distribution.
  15. - Neither the name of the Xiph.org Foundation nor the names of its
  16. contributors may be used to endorse or promote products derived from
  17. this software without specific prior written permission.
  18. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
  22. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  25. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  26. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef SPEEX_HEADER_H
  31. #define SPEEX_HEADER_H
  32. /** @defgroup SpeexHeader SpeexHeader: Makes it easy to write/parse an Ogg/Speex header
  33. * This is the Speex header for the Ogg encapsulation. You don't need that if you just use RTP.
  34. * @{
  35. */
  36. #include "speex/speex_types.h"
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. struct SpeexMode;
  41. /** Length of the Speex header identifier */
  42. #define SPEEX_HEADER_STRING_LENGTH 8
  43. /** Maximum number of characters for encoding the Speex version number in the header */
  44. #define SPEEX_HEADER_VERSION_LENGTH 20
  45. /** Speex header info for file-based formats */
  46. typedef struct SpeexHeader {
  47. char speex_string[SPEEX_HEADER_STRING_LENGTH]; /**< Identifies a Speex bit-stream, always set to "Speex " */
  48. char speex_version[SPEEX_HEADER_VERSION_LENGTH]; /**< Speex version */
  49. spx_int32_t speex_version_id; /**< Version for Speex (for checking compatibility) */
  50. spx_int32_t header_size; /**< Total size of the header ( sizeof(SpeexHeader) ) */
  51. spx_int32_t rate; /**< Sampling rate used */
  52. spx_int32_t mode; /**< Mode used (0 for narrowband, 1 for wideband) */
  53. spx_int32_t mode_bitstream_version; /**< Version ID of the bit-stream */
  54. spx_int32_t nb_channels; /**< Number of channels encoded */
  55. spx_int32_t bitrate; /**< Bit-rate used */
  56. spx_int32_t frame_size; /**< Size of frames */
  57. spx_int32_t vbr; /**< 1 for a VBR encoding, 0 otherwise */
  58. spx_int32_t frames_per_packet; /**< Number of frames stored per Ogg packet */
  59. spx_int32_t extra_headers; /**< Number of additional headers after the comments */
  60. spx_int32_t reserved1; /**< Reserved for future use, must be zero */
  61. spx_int32_t reserved2; /**< Reserved for future use, must be zero */
  62. } SpeexHeader;
  63. /** Initializes a SpeexHeader using basic information */
  64. void speex_init_header(SpeexHeader *header, int rate, int nb_channels, const struct SpeexMode *m);
  65. /** Creates the header packet from the header itself (mostly involves endianness conversion) */
  66. char *speex_header_to_packet(SpeexHeader *header, int *size);
  67. /** Creates a SpeexHeader from a packet */
  68. SpeexHeader *speex_packet_to_header(char *packet, int size);
  69. /** Frees the memory allocated by either speex_header_to_packet() or speex_packet_to_header() */
  70. void speex_header_free(void *ptr);
  71. #ifdef __cplusplus
  72. }
  73. #endif
  74. /** @} */
  75. #endif