198913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project/* Copyright (C) 2002 Jean-Marc Valin */
298913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project/**
398913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   @file speex_header.h
498913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   @brief Describes the Speex header
598913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project*/
698913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project/*
798913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   Redistribution and use in source and binary forms, with or without
898913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   modification, are permitted provided that the following conditions
998913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   are met:
1098913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
1198913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   - Redistributions of source code must retain the above copyright
1298913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   notice, this list of conditions and the following disclaimer.
1398913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
1498913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   - Redistributions in binary form must reproduce the above copyright
1598913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   notice, this list of conditions and the following disclaimer in the
1698913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   documentation and/or other materials provided with the distribution.
1798913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
1898913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   - Neither the name of the Xiph.org Foundation nor the names of its
1998913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   contributors may be used to endorse or promote products derived from
2098913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   this software without specific prior written permission.
2198913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
2298913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2398913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2498913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2598913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
2698913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
2798913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2898913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2998913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
3098913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
3198913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3298913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3398913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
3498913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project*/
3598913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
3698913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
3798913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project#ifndef SPEEX_HEADER_H
3898913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project#define SPEEX_HEADER_H
3998913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project/** @defgroup SpeexHeader SpeexHeader: Makes it easy to write/parse an Ogg/Speex header
4098913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project *  This is the Speex header for the Ogg encapsulation. You don't need that if you just use RTP.
4198913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project *  @{
4298913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project */
4398913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
4498913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project#include "speex/speex_types.h"
4598913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
4698913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project#ifdef __cplusplus
4798913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Projectextern "C" {
4898913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project#endif
4998913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
5098913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Projectstruct SpeexMode;
5198913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
5298913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project/** Length of the Speex header identifier */
5398913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project#define SPEEX_HEADER_STRING_LENGTH 8
5498913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
5598913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project/** Maximum number of characters for encoding the Speex version number in the header */
5698913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project#define SPEEX_HEADER_VERSION_LENGTH 20
5798913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
5898913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project/** Speex header info for file-based formats */
5998913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Projecttypedef struct SpeexHeader {
6098913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   char speex_string[SPEEX_HEADER_STRING_LENGTH];   /**< Identifies a Speex bit-stream, always set to "Speex   " */
6198913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   char speex_version[SPEEX_HEADER_VERSION_LENGTH]; /**< Speex version */
6298913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   spx_int32_t speex_version_id;       /**< Version for Speex (for checking compatibility) */
6398913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   spx_int32_t header_size;            /**< Total size of the header ( sizeof(SpeexHeader) ) */
6498913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   spx_int32_t rate;                   /**< Sampling rate used */
6598913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   spx_int32_t mode;                   /**< Mode used (0 for narrowband, 1 for wideband) */
6698913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   spx_int32_t mode_bitstream_version; /**< Version ID of the bit-stream */
6798913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   spx_int32_t nb_channels;            /**< Number of channels encoded */
6898913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   spx_int32_t bitrate;                /**< Bit-rate used */
6998913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   spx_int32_t frame_size;             /**< Size of frames */
7098913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   spx_int32_t vbr;                    /**< 1 for a VBR encoding, 0 otherwise */
7198913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   spx_int32_t frames_per_packet;      /**< Number of frames stored per Ogg packet */
7298913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   spx_int32_t extra_headers;          /**< Number of additional headers after the comments */
7398913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   spx_int32_t reserved1;              /**< Reserved for future use, must be zero */
7498913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   spx_int32_t reserved2;              /**< Reserved for future use, must be zero */
7598913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project} SpeexHeader;
7698913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
7798913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project/** Initializes a SpeexHeader using basic information */
7898913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Projectvoid speex_init_header(SpeexHeader *header, int rate, int nb_channels, const struct SpeexMode *m);
7998913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
8098913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project/** Creates the header packet from the header itself (mostly involves endianness conversion) */
8198913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Projectchar *speex_header_to_packet(SpeexHeader *header, int *size);
8298913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
8398913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project/** Creates a SpeexHeader from a packet */
8498913fed6520d8849fb2e246be943e04474aefaThe Android Open Source ProjectSpeexHeader *speex_packet_to_header(char *packet, int size);
8598913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
8698913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project/** Frees the memory allocated by either speex_header_to_packet() or speex_packet_to_header() */
8798913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Projectvoid speex_header_free(void *ptr);
8898913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
8998913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project#ifdef __cplusplus
9098913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project}
9198913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project#endif
9298913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
9398913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project/** @} */
9498913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project#endif
95