ROHC compression/decompression library
interval.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2011,2012,2013 Didier Barvaux
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00017  */
00018 
00019 /**
00020  * @file interval.h
00021  * @brief Compute the interpretation interval for LSB and W-LSB encoding
00022  * @author Didier Barvaux <didier.barvaux@toulouse.viveris.com>
00023  */
00024 
00025 #ifndef ROHC_COMMON_INTERVAL_H
00026 #define ROHC_COMMON_INTERVAL_H
00027 
00028 #include "dllexport.h"
00029 
00030 #include <stdlib.h>
00031 #include <stdint.h>
00032 
00033 
00034 /**
00035  * @brief the different values of the shift parameter of the LSB algorithm
00036  *
00037  * The shift parameter is also named 'p' in some RFCs.
00038  *
00039  * Some values are the real values to use directly. Some others are code
00040  * that means that the real value to use shall be computed from the number
00041  * of least significant bits that are transmitted.
00042  */
00043 typedef enum
00044 {
00045         ROHC_LSB_SHIFT_IP_ID  =  0,  /**< real value for IP-ID */
00046         ROHC_LSB_SHIFT_RTP_TS =  2,  /**< need to compute real value for RTP TS */
00047         ROHC_LSB_SHIFT_RTP_SN =  3,  /**< need to compute real value for RTP SN */
00048         ROHC_LSB_SHIFT_ESP_SN =  3,  /**< need to compute real value for ESP SN */
00049         ROHC_LSB_SHIFT_SN     = -1,  /**< real value for non-RTP SN */
00050         ROHC_LSB_SHIFT_VAR    =  1,  /**< real value is variable */
00051 } rohc_lsb_shift_t;
00052 
00053 
00054 /**
00055  * @brief An interval of 16-bit values
00056  *
00057  * Lower and upper bound values are always included in the interval.
00058  *
00059  * The upper bound may be greater that the lower bound of the interval if the
00060  * interval straddles the interval boundaries.
00061  *
00062  * Example of interval that does not straddle field boundaries:
00063  *   [1, 3]
00064  *
00065  * Example of interval that straddles field boundaries (16-bit field):
00066  *   [65530, 4]
00067  */
00068 struct rohc_interval16
00069 {
00070         uint16_t min;  /**< The lower bound of the interval */
00071         uint16_t max;  /**< The upper bound of the interval */
00072 };
00073 
00074 
00075 /**
00076  * @brief An interval of 32-bit values
00077  *
00078  * Lower and upper bound values are always included in the interval.
00079  *
00080  * The upper bound may be greater that the lower bound of the interval if the
00081  * interval straddles the interval boundaries.
00082  *
00083  * Example of interval that does not straddle field boundaries:
00084  *   [1, 3]
00085  *
00086  * Example of interval that straddles field boundaries (32-bit field):
00087  *   [65530, 4]
00088  */
00089 struct rohc_interval32
00090 {
00091         uint32_t min;  /**< The lower bound of the interval */
00092         uint32_t max;  /**< The upper bound of the interval */
00093 };
00094 
00095 
00096 /*
00097  * Public function prototypes:
00098  */
00099 
00100 static inline int32_t rohc_interval_compute_p(const size_t k,
00101                                               const rohc_lsb_shift_t p)
00102         __attribute__((warn_unused_result, const));
00103 
00104 struct rohc_interval16 ROHC_EXPORT rohc_f_16bits(const uint16_t v_ref,
00105                                                  const size_t k,
00106                                                  const rohc_lsb_shift_t p)
00107         __attribute__((warn_unused_result, const));
00108 
00109 struct rohc_interval32 ROHC_EXPORT rohc_f_32bits(const uint32_t v_ref,
00110                                                  const size_t k,
00111                                                  const rohc_lsb_shift_t p)
00112         __attribute__((warn_unused_result, const));
00113 
00114 
00115 /**
00116  * @brief Compute the shift parameter p for the f function
00117  *
00118  * @param k  The number of least significant bits of the value that are
00119  *           transmitted
00120  * @param p  The shift parameter (may be negative)
00121  * @return   The computed shift parameter p
00122  */
00123 static inline int32_t rohc_interval_compute_p(const size_t k,
00124                                               const rohc_lsb_shift_t p)
00125 {
00126         int32_t computed_p;
00127 
00128         /* determine the real p value to use */
00129         switch(p)
00130         {
00131                 case ROHC_LSB_SHIFT_RTP_TS: /* special computation for RTP TS encoding */
00132                 {
00133                         if(k <= 2)
00134                         {
00135                                 computed_p = 0;
00136                         }
00137                         else
00138                         {
00139                                 computed_p = (1 << (k - 2)) - 1;
00140                         }
00141                 }
00142                 break;
00143 
00144                 /* special computation for RTP and ESP SN encoding */
00145                 case ROHC_LSB_SHIFT_RTP_SN: /* = ROHC_LSB_SHIFT_ESP_SN */
00146                 {
00147                         if(k <= 4)
00148                         {
00149                                 computed_p = 1;
00150                         }
00151                         else
00152                         {
00153                                 computed_p = (1 << (k - 5)) - 1;
00154                         }
00155                 }
00156                 break;
00157 
00158                 default: /* otherwise: use the p value given as parameter */
00159                 {
00160                         computed_p = p;
00161                 }
00162         }
00163 
00164         return computed_p;
00165 }
00166 
00167 #endif
00168