00001 /* 00002 * Copyright 2010,2012,2013,2014 Didier Barvaux 00003 * Copyright 2013 Friedrich 00004 * Copyright 2009,2010 Thales Communications 00005 * Copyright 2007,2009,2010,2012,2013,2014 Viveris Technologies 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 00022 /** 00023 * @file rohc_comp.h 00024 * @brief ROHC compression routines 00025 * @author Didier Barvaux <didier.barvaux@toulouse.viveris.com> 00026 * @author Didier Barvaux <didier@barvaux.org> 00027 */ 00028 00029 #ifndef ROHC_COMP_H 00030 #define ROHC_COMP_H 00031 00032 #ifdef __cplusplus 00033 extern "C" 00034 { 00035 #endif 00036 00037 #include <rohc/rohc.h> 00038 #include <rohc/rohc_packets.h> 00039 #include <rohc/rohc_traces.h> 00040 #include <rohc/rohc_time.h> 00041 #include <rohc/rohc_buf.h> 00042 00043 #include <stdlib.h> 00044 #include <stdint.h> 00045 #ifdef __KERNEL__ 00046 # include <linux/types.h> 00047 #else 00048 # include <stdbool.h> 00049 #endif 00050 00051 00052 /** Macro that handles DLL export declarations gracefully */ 00053 #ifdef DLL_EXPORT /* passed by autotools on command line */ 00054 # define ROHC_EXPORT __declspec(dllexport) 00055 #else 00056 # define ROHC_EXPORT 00057 #endif 00058 00059 00060 /* 00061 * Declare the private ROHC compressor structure that is defined inside the 00062 * library. 00063 */ 00064 00065 struct rohc_comp; 00066 00067 00068 /* 00069 * Public structures and types 00070 */ 00071 00072 00073 /** 00074 * @brief The different ROHC compressor states 00075 * 00076 * The different ROHC operation states at compressor as defined in section 00077 * 4.3.1 of RFC 3095. 00078 * 00079 * If you add a new compressor state, please also add the corresponding 00080 * textual description in \ref rohc_comp_get_state_descr. 00081 * 00082 * @ingroup rohc_comp 00083 * 00084 * @see rohc_comp_get_state_descr 00085 */ 00086 typedef enum 00087 { 00088 /** Unknown compressor state */ 00089 ROHC_COMP_STATE_UNKNOWN = 0, 00090 /** The Initialization and Refresh (IR) compressor state */ 00091 ROHC_COMP_STATE_IR = 1, 00092 /** The First Order (FO) compressor state */ 00093 ROHC_COMP_STATE_FO = 2, 00094 /** The Second Order (SO) compressor state */ 00095 ROHC_COMP_STATE_SO = 3, 00096 00097 } rohc_comp_state_t; 00098 00099 00100 /** 00101 * @brief Some information about the last compressed packet 00102 * 00103 * The structure is used by the \ref rohc_comp_get_last_packet_info2 function 00104 * to store some information about the last compressed packet. 00105 * 00106 * Versioning works as follow: 00107 * - The \e version_major field defines the compatibility level. If the major 00108 * number given by user does not match the one expected by the library, 00109 * an error is returned. 00110 * - The \e version_minor field defines the extension level. If the minor 00111 * number given by user does not match the one expected by the library, 00112 * only the fields supported in that minor version will be filled by 00113 * \ref rohc_comp_get_last_packet_info2. 00114 * 00115 * Notes for developers: 00116 * - Increase the major version if a field is removed. 00117 * - Increase the major version if a field is added at the beginning or in 00118 * the middle of the structure. 00119 * - Increase the minor version if a field is added at the very end of the 00120 * structure. 00121 * - The version_major and version_minor fields must be located at the very 00122 * beginning of the structure. 00123 * - The structure must be packed. 00124 * 00125 * Supported versions: 00126 * - Major 0 / Minor 0 contains: version_major, version_minor, context_id, 00127 * is_context_init, context_mode, context_state, context_used, profile_id, 00128 * packet_type, total_last_uncomp_size, header_last_uncomp_size, 00129 * total_last_comp_size, and header_last_comp_size 00130 * 00131 * @ingroup rohc_comp 00132 * 00133 * @see rohc_comp_get_last_packet_info2 00134 */ 00135 typedef struct 00136 { 00137 /** The major version of this structure */ 00138 unsigned short version_major; 00139 /** The minor version of this structure */ 00140 unsigned short version_minor; 00141 /** The Context ID (CID) */ 00142 unsigned int context_id; 00143 /** Whether the context was initialized (created/re-used) by the packet */ 00144 bool is_context_init; 00145 /** The mode of the last context used by the compressor */ 00146 rohc_mode_t context_mode; 00147 /** The state of the last context used by the compressor */ 00148 rohc_comp_state_t context_state; 00149 /** Whether the last context used by the compressor is still in use */ 00150 bool context_used; 00151 /** The profile ID of the last context used by the compressor */ 00152 int profile_id; 00153 /** The type of ROHC packet created for the last compressed packet */ 00154 rohc_packet_t packet_type; 00155 /** The uncompressed size (in bytes) of the last compressed packet */ 00156 unsigned long total_last_uncomp_size; 00157 /** The uncompressed size (in bytes) of the last compressed header */ 00158 unsigned long header_last_uncomp_size; 00159 /** The compressed size (in bytes) of the last compressed packet */ 00160 unsigned long total_last_comp_size; 00161 /** The compressed size (in bytes) of the last compressed header */ 00162 unsigned long header_last_comp_size; 00163 } __attribute__((packed)) rohc_comp_last_packet_info2_t; 00164 00165 00166 /** 00167 * @brief Some general information about the compressor 00168 * 00169 * The structure is used by the \ref rohc_comp_get_general_info function 00170 * to store some general information about the compressor. 00171 * 00172 * Versioning works as follow: 00173 * - The \e version_major field defines the compatibility level. If the major 00174 * number given by user does not match the one expected by the library, 00175 * an error is returned. 00176 * - The \e version_minor field defines the extension level. If the minor 00177 * number given by user does not match the one expected by the library, 00178 * only the fields supported in that minor version will be filled by 00179 * \ref rohc_comp_get_general_info. 00180 * 00181 * Notes for developers: 00182 * - Increase the major version if a field is removed. 00183 * - Increase the major version if a field is added at the beginning or in 00184 * the middle of the structure. 00185 * - Increase the minor version if a field is added at the very end of the 00186 * structure. 00187 * - The version_major and version_minor fields must be located at the very 00188 * beginning of the structure. 00189 * - The structure must be packed. 00190 * 00191 * Supported versions: 00192 * - major 0 and minor = 0 contains: version_major, version_minor, 00193 * contexts_nr, packets_nr, uncomp_bytes_nr, and comp_bytes_nr. 00194 * 00195 * @ingroup rohc_comp 00196 * 00197 * @see rohc_comp_get_general_info 00198 */ 00199 typedef struct 00200 { 00201 /** The major version of this structure */ 00202 unsigned short version_major; 00203 /** The minor version of this structure */ 00204 unsigned short version_minor; 00205 /** The number of contexts used by the compressor */ 00206 size_t contexts_nr; 00207 /** The number of packets processed by the compressor */ 00208 unsigned long packets_nr; 00209 /** The number of uncompressed bytes received by the compressor */ 00210 unsigned long uncomp_bytes_nr; 00211 /** The number of compressed bytes produced by the compressor */ 00212 unsigned long comp_bytes_nr; 00213 } __attribute__((packed)) rohc_comp_general_info_t; 00214 00215 00216 /** 00217 * @brief The different features of the ROHC compressor 00218 * 00219 * Features for the ROHC compressor control whether mechanisms defined as 00220 * optional by RFCs are enabled or not. They can be set or unset with the 00221 * function \ref rohc_comp_set_features. 00222 * 00223 * @ingroup rohc_comp 00224 * 00225 * @see rohc_comp_set_features 00226 */ 00227 typedef enum 00228 { 00229 /** No feature at all */ 00230 ROHC_COMP_FEATURE_NONE = 0, 00231 /** Be compatible with 1.6.x versions */ 00232 ROHC_COMP_FEATURE_COMPAT_1_6_x = (1 << 0), 00233 /** Do not check IP checksums at compressor */ 00234 ROHC_COMP_FEATURE_NO_IP_CHECKSUMS = (1 << 2), 00235 /** Dump content of packets in traces (beware: performance impact) */ 00236 ROHC_COMP_FEATURE_DUMP_PACKETS = (1 << 3), 00237 00238 } rohc_comp_features_t; 00239 00240 00241 /** 00242 * @brief The prototype of the RTP detection callback 00243 * 00244 * User-defined function that is called by the ROHC library for every UDP 00245 * packet to determine whether the UDP packet transports RTP data. If the 00246 * function returns true, the RTP profile is used to compress the packet. 00247 * Otherwise the UDP profile is used. 00248 * 00249 * The user-defined function is set by calling the function 00250 * \ref rohc_comp_set_rtp_detection_cb 00251 * 00252 * @param ip The innermost IP packet 00253 * @param udp The UDP header of the packet 00254 * @param payload The UDP payload of the packet 00255 * @param payload_size The size of the UDP payload (in bytes) 00256 * @param rtp_private A pointer to a memory area to be used by the callback 00257 * function, may be NULL. 00258 * @return true if the packet is an RTP packet, false otherwise 00259 * 00260 * @see rohc_comp_set_rtp_detection_cb 00261 * @ingroup rohc_comp 00262 */ 00263 typedef bool (*rohc_rtp_detection_callback_t)(const unsigned char *const ip, 00264 const unsigned char *const udp, 00265 const unsigned char *const payload, 00266 const unsigned int payload_size, 00267 void *const rtp_private) 00268 __attribute__((warn_unused_result)); 00269 00270 00271 /** 00272 * @brief The prototype of the callback for random numbers 00273 * 00274 * User-defined function that is called when the ROHC library requires a random 00275 * number. Currently, the ROHC library uses it when initializing the Sequence 00276 * Number (SN) of contexts using the IP-only, IP/UDP, and IP/UDP-Lite profiles. 00277 * 00278 * The user-defined function is set by calling the function 00279 * \ref rohc_comp_new2 00280 * 00281 * @param comp The ROHC compressor 00282 * @param user_context The context given by the user when he/she called the 00283 * \ref rohc_comp_new2 function, may be NULL. 00284 * 00285 * @see rohc_comp_new2 00286 * @ingroup rohc_comp 00287 */ 00288 typedef int (*rohc_comp_random_cb_t) (const struct rohc_comp *const comp, 00289 void *const user_context) 00290 __attribute__((warn_unused_result)); 00291 00292 00293 /* 00294 * Prototypes of main public functions related to ROHC compression 00295 */ 00296 00297 struct rohc_comp * ROHC_EXPORT rohc_comp_new2(const rohc_cid_type_t cid_type, 00298 const rohc_cid_t max_cid, 00299 const rohc_comp_random_cb_t rand_cb, 00300 void *const rand_priv) 00301 __attribute__((warn_unused_result)); 00302 00303 void ROHC_EXPORT rohc_comp_free(struct rohc_comp *const comp); 00304 00305 bool ROHC_EXPORT rohc_comp_set_traces_cb2(struct rohc_comp *const comp, 00306 rohc_trace_callback2_t callback, 00307 void *const priv_ctxt) 00308 __attribute__((warn_unused_result)); 00309 00310 rohc_status_t ROHC_EXPORT rohc_compress4(struct rohc_comp *const comp, 00311 const struct rohc_buf uncomp_packet, 00312 struct rohc_buf *const rohc_packet) 00313 __attribute__((warn_unused_result)); 00314 00315 rohc_status_t ROHC_EXPORT rohc_comp_get_segment2(struct rohc_comp *const comp, 00316 struct rohc_buf *const segment) 00317 __attribute__((warn_unused_result)); 00318 00319 bool ROHC_EXPORT rohc_comp_force_contexts_reinit(struct rohc_comp *const comp) 00320 __attribute__((warn_unused_result)); 00321 00322 00323 /* 00324 * Prototypes of public functions related to user interaction 00325 */ 00326 00327 bool ROHC_EXPORT rohc_comp_profile_enabled(const struct rohc_comp *const comp, 00328 const rohc_profile_t profile) 00329 __attribute__((warn_unused_result)); 00330 00331 bool ROHC_EXPORT rohc_comp_enable_profile(struct rohc_comp *const comp, 00332 const rohc_profile_t profile) 00333 __attribute__((warn_unused_result)); 00334 bool ROHC_EXPORT rohc_comp_disable_profile(struct rohc_comp *const comp, 00335 const rohc_profile_t profile) 00336 __attribute__((warn_unused_result)); 00337 00338 bool ROHC_EXPORT rohc_comp_enable_profiles(struct rohc_comp *const comp, 00339 ...) 00340 __attribute__((warn_unused_result)); 00341 bool ROHC_EXPORT rohc_comp_disable_profiles(struct rohc_comp *const comp, 00342 ...) 00343 __attribute__((warn_unused_result)); 00344 00345 bool ROHC_EXPORT rohc_comp_set_mrru(struct rohc_comp *const comp, 00346 const size_t mrru) 00347 __attribute__((warn_unused_result)); 00348 bool ROHC_EXPORT rohc_comp_get_mrru(const struct rohc_comp *const comp, 00349 size_t *const mrru) 00350 __attribute__((warn_unused_result)); 00351 00352 bool ROHC_EXPORT rohc_comp_get_max_cid(const struct rohc_comp *const comp, 00353 size_t *const max_cid) 00354 __attribute__((warn_unused_result)); 00355 00356 bool ROHC_EXPORT rohc_comp_get_cid_type(const struct rohc_comp *const comp, 00357 rohc_cid_type_t *const cid_type) 00358 __attribute__((warn_unused_result)); 00359 00360 bool ROHC_EXPORT rohc_comp_set_rtp_detection_cb(struct rohc_comp *const comp, 00361 rohc_rtp_detection_callback_t callback, 00362 void *const rtp_private) 00363 __attribute__((warn_unused_result)); 00364 00365 bool ROHC_EXPORT rohc_comp_set_features(struct rohc_comp *const comp, 00366 const rohc_comp_features_t features) 00367 __attribute__((warn_unused_result)); 00368 00369 bool ROHC_EXPORT rohc_comp_deliver_feedback2(struct rohc_comp *const comp, 00370 const struct rohc_buf feedback) 00371 __attribute__((warn_unused_result)); 00372 00373 00374 /* 00375 * Prototypes of public functions that configure robustness to packet 00376 * loss/damage 00377 */ 00378 00379 bool ROHC_EXPORT rohc_comp_set_wlsb_window_width(struct rohc_comp *const comp, 00380 const size_t width) 00381 __attribute__((warn_unused_result)); 00382 00383 bool ROHC_EXPORT rohc_comp_set_periodic_refreshes(struct rohc_comp *const comp, 00384 const size_t ir_timeout, 00385 const size_t fo_timeout) 00386 __attribute__((warn_unused_result)); 00387 00388 bool ROHC_EXPORT rohc_comp_set_list_trans_nr(struct rohc_comp *const comp, 00389 const size_t list_trans_nr) 00390 __attribute__((warn_unused_result)); 00391 00392 00393 /* 00394 * Prototypes of public functions related to ROHC compression statistics 00395 */ 00396 00397 bool ROHC_EXPORT rohc_comp_get_general_info(const struct rohc_comp *const comp, 00398 rohc_comp_general_info_t *const info) 00399 __attribute__((warn_unused_result)); 00400 00401 bool ROHC_EXPORT rohc_comp_get_last_packet_info2(const struct rohc_comp *const comp, 00402 rohc_comp_last_packet_info2_t *const info) 00403 __attribute__((warn_unused_result)); 00404 00405 const char * ROHC_EXPORT rohc_comp_get_state_descr(const rohc_comp_state_t state) 00406 __attribute__((warn_unused_result, const)); 00407 00408 00409 #undef ROHC_EXPORT /* do not pollute outside this header */ 00410 00411 #ifdef __cplusplus 00412 } 00413 #endif 00414 00415 #endif /* ROHC_COMP_H */ 00416
1.6.1