ROHC compression/decompression library
wlsb.h
Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 2 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * This program is distributed in the hope that it will be useful,
00008  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  * GNU General Public License for more details.
00011  *
00012  * You should have received a copy of the GNU General Public License
00013  * along with this program; if not, write to the Free Software
00014  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00015  */
00016 
00017 /**
00018  * @file wlsb.h
00019  * @brief Window-based Least Significant Bits (W-LSB) encoding
00020  * @author Didier Barvaux <didier.barvaux@toulouse.viveris.com>
00021  * @author David Moreau from TAS
00022  * @author The hackers from ROHC for Linux
00023  */
00024 
00025 #ifndef WLSB_H
00026 #define WLSB_H
00027 
00028 #include <stdlib.h>
00029 #include <stdint.h>
00030 
00031 
00032 /// Default window width for W-LSB encoding
00033 #define C_WINDOW_WIDTH 4
00034 
00035 
00036 /**
00037  * @brief Defines a W-LSB window entry
00038  */
00039 struct c_window
00040 {
00041         /// @brief The Sequence Number (SN) associated with the entry (used to
00042         ///        acknowledge the entry)
00043         uint16_t sn;
00044 
00045         /// The value stored in the window entry
00046         uint32_t value;
00047 
00048         /**
00049          * @brief Whether the window entry is used or not
00050          *
00051          * 1 if the window entry is used, 0 if not
00052          */
00053         int is_used;
00054 };
00055 
00056 
00057 /**
00058  * @brief Defines a W-LSB encoding object
00059  */
00060 struct c_wlsb
00061 {
00062         /// @brief The window in which numerous previous values of the encoded value
00063         ///        are stored to help recreate the value
00064         struct c_window *window;
00065         /// The width of the window
00066         size_t window_width;
00067 
00068         /// A pointer on the oldest entry in the window (change on acknowledgement)
00069         size_t oldest;
00070         /// A pointer on the current entry in the window  (change on add and ack)
00071         size_t next;
00072 
00073         /// The maximal number of bits for representing the value
00074         size_t bits;
00075         /// Shift parameter (see 4.5.2 in the RFC 3095)
00076         int32_t p;
00077 };
00078 
00079 
00080 /*
00081  * Public function prototypes:
00082  */
00083 
00084 struct c_wlsb * c_create_wlsb(const size_t bits,
00085                               const size_t window_width,
00086                               const int32_t p);
00087 void c_destroy_wlsb(struct c_wlsb *s);
00088 
00089 void c_add_wlsb(struct c_wlsb *const wlsb,
00090                 const uint16_t sn,
00091                 const uint32_t value);
00092 int c_get_k_wlsb(const struct c_wlsb *const wlsb,
00093                  const uint32_t value,
00094                  size_t *const bits_nr);
00095 
00096 void c_ack_sn_wlsb(struct c_wlsb *s, int sn);
00097 
00098 int c_sum_wlsb(struct c_wlsb *s);
00099 int c_mean_wlsb(struct c_wlsb *s);
00100 
00101 #endif
00102