00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * bitstream.h - Bitstream composition and decomposition routines. 00005 * 00006 * Written by Steve Underwood <steveu@coppice.org> 00007 * 00008 * Copyright (C) 2006 Steve Underwood 00009 * 00010 * All rights reserved. 00011 * 00012 * This program is free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU Lesser General Public License version 2.1, 00014 * as published by the Free Software Foundation. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public 00022 * License along with this program; if not, write to the Free Software 00023 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00024 */ 00025 00026 /*! \file */ 00027 00028 #if !defined(_SPANDSP_BITSTREAM_H_) 00029 #define _SPANDSP_BITSTREAM_H_ 00030 00031 /*! \page bitstream_page Bitstream composition and decomposition 00032 \section bitstream_page_sec_1 What does it do? 00033 00034 \section bitstream_page_sec_2 How does it work? 00035 */ 00036 00037 /*! Bitstream handler state */ 00038 typedef struct bitstream_state_s bitstream_state_t; 00039 00040 #if defined(__cplusplus) 00041 extern "C" 00042 { 00043 #endif 00044 00045 /*! \brief Put a chunk of bits into the output buffer. 00046 \param s A pointer to the bitstream context. 00047 \param c A pointer to the bitstream output buffer. 00048 \param value The value to be pushed into the output buffer. 00049 \param bits The number of bits of value to be pushed. 1 to 25 bits is valid. */ 00050 SPAN_DECLARE(void) bitstream_put(bitstream_state_t *s, uint8_t **c, uint32_t value, int bits); 00051 00052 /*! \brief Get a chunk of bits from the input buffer. 00053 \param s A pointer to the bitstream context. 00054 \param c A pointer to the bitstream input buffer. 00055 \param bits The number of bits of value to be grabbed. 1 to 25 bits is valid. 00056 \return The value retrieved from the input buffer. */ 00057 SPAN_DECLARE(uint32_t) bitstream_get(bitstream_state_t *s, const uint8_t **c, int bits); 00058 00059 /*! \brief Emit any residual bits to the output buffer, without actually flushing them. 00060 This is useful for getting the buffer fully up to date, ready for things 00061 like CRC calculations, while allowing bitstream_put() to be used to continue 00062 the message later. 00063 \param s A pointer to the bitstream context. 00064 \param c A pointer to the bitstream output buffer. */ 00065 SPAN_DECLARE(void) bitstream_emit(bitstream_state_t *s, uint8_t **c); 00066 00067 /*! \brief Flush any residual bits to the output buffer. 00068 \param s A pointer to the bitstream context. 00069 \param c A pointer to the bitstream output buffer. */ 00070 SPAN_DECLARE(void) bitstream_flush(bitstream_state_t *s, uint8_t **c); 00071 00072 /*! \brief Initialise a bitstream context. 00073 \param s A pointer to the bitstream context. 00074 \param lsb_first TRUE if the bit stream is LSB first, else its MSB first. 00075 \return A pointer to the bitstream context. */ 00076 SPAN_DECLARE(bitstream_state_t *) bitstream_init(bitstream_state_t *s, int direction); 00077 00078 SPAN_DECLARE(int) bitstream_release(bitstream_state_t *s); 00079 00080 SPAN_DECLARE(int) bitstream_free(bitstream_state_t *s); 00081 00082 #if defined(__cplusplus) 00083 } 00084 #endif 00085 00086 #endif 00087 /*- End of file ------------------------------------------------------------*/