FreeSWITCH API Documentation  1.7.0
Functions | Variables
Bitpacking
+ Collaboration diagram for Bitpacking:

Functions

 DoxyDefine (void switch_bitpack_init(switch_bitpack_t *pack, int32_t bitlen, switch_byte_t *buf, uint32_t buflen, switch_bitpack_mode_t mode)) static inline int8_t switch_bitpack_init(switch_bitpack_t *pack
 Initialize a bitpack object. More...
 
 memset (buf, 0, buflen)
 
static void pack_check_over (switch_bitpack_t *pack)
 
 DoxyDefine (int8_t switch_bitpack_done(switch_bitpack_t *pack)) static inline int8_t switch_bitpack_done(switch_bitpack_t *pack)
 finalize a bitpack object More...
 
 DoxyDefine (int8_t switch_bitpack_out(switch_bitpack_t *unpack, switch_byte_t in)) static inline int8_t switch_bitpack_out(switch_bitpack_t *unpack
 pull data out of a bitpack object into it's buffer More...
 
 if ((uint32_t)(unpack->cur-unpack->buf) > unpack->buflen)
 
 pack_check_over (unpack)
 
 while (unpack->bits_cur<=SWITCH_BITS_PER_BYTE)
 
 DoxyDefine (int8_t switch_bitpack_in(switch_bitpack_t *pack, switch_byte_t in)) static inline int8_t switch_bitpack_in(switch_bitpack_t *pack
 pack data into a bitpack object's buffer More...
 
 if ((uint32_t)(pack->cur-pack->buf) > pack->buflen)
 
 if (next > SWITCH_BITS_PER_BYTE)
 

Variables

static const uint8_t SWITCH_BITPACKED_MASKS [] = { 0, 1, 3, 7, 15, 31, 63, 127, 255 }
 
static const uint8_t SWITCH_REVERSE_BITPACKED_MASKS [] = { 255, 254, 252, 248, 240, 224, 192, 128 }
 
switch_byte_t bitlen
 
switch_byte_t switch_byte_tbuf = buf
 
switch_byte_t switch_byte_t
uint32_t 
buflen = buflen
 
switch_byte_t switch_byte_t
uint32_t switch_bitpack_mode_t 
mode
 
pack frame_bits = bitlen
 
pack cur = pack->buf
 
 return
 
switch_byte_t in
 
unpack bits_cur = 0
 
unpack this_byte = this_byte = in
 
pack bits_tot = pack->frame_bits
 
 else
 

Detailed Description

Function Documentation

DoxyDefine ( void   switch_bitpack_initswitch_bitpack_t *pack, int32_t bitlen, switch_byte_t *buf, uint32_t buflen, switch_bitpack_mode_t mode)

Initialize a bitpack object.

Parameters
packthe pack object
bitlenthe number of bits per packet
bufthe buffer to use for storage
buflenthe length of the storage buffer
modeRFC3551 or AAL2 mode (curse you backwards folks)
DoxyDefine ( int8_t   switch_bitpack_doneswitch_bitpack_t *pack)

finalize a bitpack object

Parameters
packthe pack/unpack object

Definition at line 128 of file switch_bitpack.h.

References switch_bitpack_t::bits_cur, switch_bitpack_t::bytes, switch_bitpack_t::cur, switch_bitpack_t::mode, switch_bitpack_t::over, pack_check_over(), SWITCH_BITPACK_MODE_AAL2, and SWITCH_BITS_PER_BYTE.

130 {
131 
132  if (pack->bits_cur && pack->bits_cur < SWITCH_BITS_PER_BYTE) {
133  pack->bytes++;
134  if (pack->mode == SWITCH_BITPACK_MODE_AAL2) {
135  *pack->cur <<= SWITCH_BITS_PER_BYTE - pack->bits_cur;
136  }
137  }
138 
139  if (pack->over) {
140  pack_check_over(pack);
141  }
142  return 0;
143 }
#define SWITCH_BITS_PER_BYTE
Definition: switch_types.h:228
static void pack_check_over(switch_bitpack_t *pack)
DoxyDefine ( int8_t   switch_bitpack_outswitch_bitpack_t *unpack, switch_byte_t in)

pull data out of a bitpack object into it's buffer

Parameters
unpackthe pack/unpack object
ina 1 byte int packed with bits
Returns
-1 if the buffer is full otherwise 0
DoxyDefine ( int8_t   switch_bitpack_inswitch_bitpack_t *pack, switch_byte_t in)

pack data into a bitpack object's buffer

Parameters
packthe pack/unpack object
ina 1 byte int with 1 packet worth of bits
Returns
-1 if the buffer is full otherwise 0
if ( (uint32_t)(unpack->cur-unpack->buf ,
unpack->  buflen 
)
if ( (uint32_t)(pack->cur-pack->buf ,
pack->  buflen 
)

Definition at line 228 of file switch_bitpack.h.

228  {
229  return -1;
230  }
if ( next  ,
SWITCH_BITS_PER_BYTE   
)

Definition at line 234 of file switch_bitpack.h.

References switch_bitpack_t::bits_cur, switch_bitpack_t::bytes, switch_bitpack_t::cur, switch_bitpack_t::frame_bits, switch_bitpack_t::mode, switch_bitpack_t::shiftby, SWITCH_BITPACK_MODE_RFC3551, and SWITCH_BITS_PER_BYTE.

234  {
235  switch_byte_t a = 0, b = 0, rem, nxt;
236  rem = SWITCH_BITS_PER_BYTE - pack->bits_cur;
237  nxt = pack->frame_bits - rem;
238  if (pack->mode == SWITCH_BITPACK_MODE_RFC3551) {
239  a = in & SWITCH_BITPACKED_MASKS[rem];
240  b = in >> rem;
241  a <<= pack->shiftby;
242  *pack->cur |= a;
243  pack->cur++;
244  *pack->cur |= b;
245  pack->bits_cur = pack->shiftby = nxt;
246  } else {
247  a = in >> nxt;
248  b = in & SWITCH_BITPACKED_MASKS[nxt];
249  *pack->cur <<= rem;
250  *pack->cur |= a;
251  pack->cur++;
252  *pack->cur |= b;
253  pack->bits_cur = nxt;
254 
255  }
256  pack->bytes++;
257 
258  } else {
static const uint8_t SWITCH_BITPACKED_MASKS[]
uint8_t switch_byte_t
Definition: switch_types.h:246
#define SWITCH_BITS_PER_BYTE
Definition: switch_types.h:228
switch_byte_t in
memset ( buf  ,
,
buflen   
)

Referenced by add_xml_header(), cJSON_New_Item(), clear_ice(), collect_thread_run(), db_pick_path(), do_2833(), early_thread_run(), fetch_device_stats(), SimpleGlobBase< SOCHAR >::FindDone(), generate_m(), CoreSession::getDigits(), handle_ice(), hashtable_expand(), inband_dtmf_generate_callback(), init_upnp(), main(), meta_on_dtmf(), new_header(), play_and_collect(), CoreSession::playAndGetDigits(), preprocess(), print_array(), print_object(), process_rtcp_report(), read_displace_callback(), read_rtp_packet(), CoreSession::recordFile(), reincarnate_protect(), rtp_common_read(), session_audio_callback(), setup_ringback(), SimpleGlobBase< SOCHAR >::SimpleGlobBase(), CoreSession::streamFile(), switch_ast2regex(), switch_buffer_create_dynamic(), switch_cache_db_execute_sql2str(), switch_cache_db_status(), switch_caller_profile_new(), switch_change_sln_volume_granular(), switch_channel_dequeue_dtmf_string(), switch_channel_expand_variables_check(), switch_channel_global_init(), switch_channel_set_timestamps(), switch_config_close_file(), switch_config_open_file(), switch_console_loop(), switch_core_codec_add_video_implementation(), switch_core_codec_decode(), switch_core_codec_destroy(), switch_core_codec_init_with_bitrate(), switch_core_codec_parse_fmtp(), switch_core_db_column_text(), switch_core_gen_encoded_silence(), switch_core_get_stacksizes(), switch_core_init(), switch_core_measure_time(), switch_core_media_activate_rtp(), switch_core_media_bug_read(), switch_core_media_gen_local_sdp(), switch_core_media_negotiate_sdp(), switch_core_media_read_frame(), switch_core_memory_init(), switch_core_perform_alloc(), switch_core_perform_permanent_alloc(), switch_core_perform_session_alloc(), switch_core_session_clear_crypto(), switch_core_session_get_read_impl(), switch_core_session_get_video_read_impl(), switch_core_session_get_video_write_impl(), switch_core_session_get_write_impl(), switch_core_session_init(), switch_core_session_queue_indication(), switch_core_session_raw_read(), switch_core_session_read_frame(), switch_core_session_set_codec_slin(), switch_core_session_set_read_codec(), switch_core_session_set_real_read_codec(), switch_core_session_set_video_read_codec(), switch_core_session_write_frame(), switch_core_setrlimits(), switch_core_timer_destroy(), switch_core_timer_init(), switch_create_hashtable(), switch_dir_open(), switch_event_add_array(), switch_event_create_subclass_detailed(), switch_event_del_header_val(), switch_event_expand_headers_check(), switch_fd_read_dline(), switch_find_local_ip(), switch_fp_read_dline(), switch_fulldate_cmp(), switch_g711a_decode(), switch_g711u_decode(), switch_generate_sln_silence(), switch_get_addr(), switch_img_fill(), switch_img_write_text_img(), switch_ivr_digit_stream_new(), switch_ivr_digit_stream_parser_new(), switch_ivr_dmachine_clear(), switch_ivr_gentones(), switch_ivr_menu_execute(), switch_ivr_originate(), switch_ivr_park(), switch_ivr_phrase_macro_event(), switch_ivr_play_file(), switch_ivr_read(), switch_ivr_record_file(), switch_ivr_set_json_chan_vars(), switch_ivr_set_xml_chan_var(), switch_ivr_speak_text(), switch_ivr_speak_text_handle(), switch_ivr_tone_detect_session(), switch_ivr_unbind_dtmf_meta_session(), switch_ivr_wait_for_answer(), switch_load_core_config(), switch_load_network_lists(), switch_load_timezones(), switch_loadable_module_init(), switch_log_vprintf(), SWITCH_MODULE_LOAD_FUNCTION(), switch_nat_init(), switch_nat_multicast_runtime(), switch_odbc_handle_callback_exec_detailed(), switch_odbc_handle_new(), switch_pgsql_cancel_real(), switch_pgsql_handle_new(), switch_pgsql_next_result_timed(), switch_play_and_get_digits(), switch_rtp_add_crypto_key(), switch_rtp_change_interval(), switch_rtp_create(), switch_rtp_enable_vad(), switch_rtp_reset(), switch_rtp_udptl_mode(), switch_say_file_handle_create(), switch_separate_string(), switch_sockaddr_create(), switch_socket_create_pollfd(), switch_speex_init(), switch_system_fork(), switch_xml_add_child(), switch_xml_new(), switch_xml_toxml_buf(), system_thread(), teletone_init_session(), teletone_mux_tones(), teletone_run(), tm2switchtime(), tztime(), and write_displace_callback().

static void pack_check_over ( switch_bitpack_t pack)
inlinestatic

Definition at line 94 of file switch_bitpack.h.

References switch_bitpack_t::bits_cur, switch_bitpack_t::bytes, switch_bitpack_t::cur, switch_bitpack_t::mode, switch_bitpack_t::over, switch_assert, SWITCH_BITPACK_MODE_RFC3551, SWITCH_BITS_PER_BYTE, this_byte, switch_bitpack_t::this_byte, and switch_bitpack_t::under.

Referenced by DoxyDefine().

95 {
97 
98  if (pack->over) {
99  pack->bits_cur = pack->over;
100 
101  if (pack->mode == SWITCH_BITPACK_MODE_RFC3551) {
102  switch_assert(pack->over <= 8);
103  this_byte &= SWITCH_BITPACKED_MASKS[pack->over];
104  this_byte <<= pack->under;
105  *pack->cur |= this_byte;
106  pack->cur++;
107  } else {
108  switch_byte_t mask = SWITCH_BITS_PER_BYTE - pack->over;
109  switch_assert(mask < 8); /* if pack->over this will allways be true */
110  this_byte &= SWITCH_REVERSE_BITPACKED_MASKS[mask];
111  this_byte >>= mask;
112 
113  *pack->cur <<= pack->over;
114  *pack->cur |= this_byte;
115  pack->cur++;
116  }
117 
118 
119  pack->bytes++;
120  pack->over = pack->under = 0;
121  }
122 }
static const uint8_t SWITCH_REVERSE_BITPACKED_MASKS[]
switch_bitpack_mode_t mode
Definition: switch_types.h:513
static const uint8_t SWITCH_BITPACKED_MASKS[]
uint8_t switch_byte_t
Definition: switch_types.h:246
unpack this_byte
#define SWITCH_BITS_PER_BYTE
Definition: switch_types.h:228
switch_byte_t bits_cur
Definition: switch_types.h:506
switch_byte_t this_byte
Definition: switch_types.h:510
switch_byte_t under
Definition: switch_types.h:511
switch_byte_t * cur
Definition: switch_types.h:503
switch_byte_t over
Definition: switch_types.h:512
#define switch_assert(expr)
pack_check_over ( unpack  )
while ( unpack->bits_cur<=  SWITCH_BITS_PER_BYTE)

Definition at line 167 of file switch_bitpack.h.

References switch_bitpack_t::bits_cur, switch_bitpack_t::bytes, switch_bitpack_t::cur, switch_bitpack_t::frame_bits, switch_bitpack_t::mode, switch_bitpack_t::over, SWITCH_BITPACK_MODE_RFC3551, SWITCH_BITS_PER_BYTE, this_byte, switch_bitpack_t::this_byte, and switch_bitpack_t::under.

Referenced by switch_xml_child(), and timesub().

167  {
168  switch_byte_t next = unpack->bits_cur + unpack->frame_bits;
169  switch_byte_t under_in;
170  switch_byte_t mask;
171  this_byte = unpack->this_byte;
172 
173  if (next > SWITCH_BITS_PER_BYTE) {
174  unpack->over = next - SWITCH_BITS_PER_BYTE;
175  unpack->under = unpack->frame_bits - unpack->over;
176 
177  if (unpack->mode == SWITCH_BITPACK_MODE_RFC3551) {
178  mask = SWITCH_BITS_PER_BYTE - unpack->under;
179 
180  under_in = this_byte & SWITCH_REVERSE_BITPACKED_MASKS[mask];
181  under_in >>= mask;
182  *unpack->cur |= under_in;
183  } else {
184  mask = unpack->under;
185  under_in = this_byte & SWITCH_BITPACKED_MASKS[mask];
186  *unpack->cur <<= mask;
187  *unpack->cur |= under_in;
188  }
189 
190  break;
191  }
192 
193  if (unpack->mode == SWITCH_BITPACK_MODE_RFC3551) {
194  this_byte >>= unpack->bits_cur;
195  this_byte &= SWITCH_BITPACKED_MASKS[unpack->frame_bits];
196  *unpack->cur |= this_byte;
197  unpack->cur++;
198  } else {
199  this_byte >>= (SWITCH_BITS_PER_BYTE - next);
200  this_byte &= SWITCH_BITPACKED_MASKS[unpack->frame_bits];
201 
202  *unpack->cur |= this_byte;
203  unpack->cur++;
204  }
205 
206  unpack->bits_cur = next;
207  unpack->bytes++;
208 
209 
210  }
static const uint8_t SWITCH_REVERSE_BITPACKED_MASKS[]
static const uint8_t SWITCH_BITPACKED_MASKS[]
uint8_t switch_byte_t
Definition: switch_types.h:246
unpack this_byte
#define SWITCH_BITS_PER_BYTE
Definition: switch_types.h:228

Variable Documentation

switch_byte_t bitlen

Definition at line 76 of file switch_bitpack.h.

unpack bits_cur = 0

Definition at line 161 of file switch_bitpack.h.

pack bits_tot = pack->frame_bits

Definition at line 232 of file switch_bitpack.h.

pack buf = buf

Definition at line 76 of file switch_bitpack.h.

Referenced by collect_thread_run(), do_dtls(), expand_vars(), get_addr(), get_addr6(), handle_ice(), ice_out(), inband_dtmf_generate_callback(), main(), play_and_collect(), preprocess(), preprocess_exec(), read_displace_callback(), reincarnate_protect(), separate_string_blank_delim(), separate_string_char_delim(), switch_amp_encode(), switch_channel_event_set_extended_data(), switch_console_complete(), switch_console_stream_write(), switch_core_asr_open(), switch_core_media_gen_local_sdp(), switch_core_media_sdp_map(), switch_core_media_set_r_sdp_codec_string(), switch_core_media_set_udptl_image_sdp(), switch_core_speech_open(), switch_dir_next_file(), switch_escape_string_pool(), switch_event_serialize(), switch_fd_read_dline(), switch_fd_read_line(), switch_fp_read_dline(), switch_get_addr(), switch_ivr_eavesdrop_session(), switch_ivr_originate(), switch_loadable_module_get_codecs_sorted(), switch_nat_multicast_runtime(), switch_parse_codec_buf(), switch_print_host(), switch_say_file(), switch_separate_string_string(), switch_simple_email(), switch_speex_decode(), switch_speex_encode(), switch_strerror_r(), switch_stun_host_lookup(), switch_stun_lookup(), switch_stun_packet_attribute_add_controlled(), switch_stun_packet_attribute_add_controlling(), switch_stun_packet_build_header(), switch_url_encode_opt(), switch_uuid_format(), switch_uuid_str(), switch_vasprintf(), switch_xml_parse_section_string(), switch_xml_toxml_buf(), teletone_handler(), video_bug_thread(), video_helper_thread(), video_write_thread(), vxprintf(), and write_displace_callback().

pack buflen = buflen
pack cur = pack->buf
else
Initial value:
{
if (pack->mode == SWITCH_BITPACK_MODE_RFC3551) {
in <<= pack->shiftby;
*pack->cur |= in;
pack->shiftby = (switch_byte_t) (pack->shiftby + pack->frame_bits);
} else {
*pack->cur <<= pack->frame_bits;
*pack->cur |= in;
}
if (next == SWITCH_BITS_PER_BYTE) {
pack->cur++;
pack->bytes++;
pack->bits_cur = pack->shiftby = 0;
} else {
pack->bits_cur = (switch_byte_t) next;
}
}
return 0
uint8_t switch_byte_t
Definition: switch_types.h:246
#define SWITCH_BITS_PER_BYTE
Definition: switch_types.h:228
switch_byte_t in

Definition at line 258 of file switch_bitpack.h.

pack frame_bits = bitlen

Definition at line 85 of file switch_bitpack.h.

pack mode
Initial value:
{
if (!pack || (bitlen > SWITCH_BITS_PER_BYTE) || !buf || !buflen) {
return -1;
}
memset(pack, 0, sizeof(*pack))
switch_byte_t bitlen
#define SWITCH_BITS_PER_BYTE
Definition: switch_types.h:228
switch_byte_t switch_byte_t * buf
switch_byte_t switch_byte_t uint32_t buflen
memset(buf, 0, buflen)

Definition at line 78 of file switch_bitpack.h.

Referenced by switch_speex_fmtp_parse(), and switch_speex_init().

return

Definition at line 91 of file switch_bitpack.h.

const uint8_t SWITCH_BITPACKED_MASKS[] = { 0, 1, 3, 7, 15, 31, 63, 127, 255 }
static

Definition at line 64 of file switch_bitpack.h.

const uint8_t SWITCH_REVERSE_BITPACKED_MASKS[] = { 255, 254, 252, 248, 240, 224, 192, 128 }
static

Definition at line 65 of file switch_bitpack.h.

unpack this_byte = this_byte = in

Definition at line 162 of file switch_bitpack.h.

Referenced by pack_check_over(), and while().