RTS API Documentation  1.10.11
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() [1/4]

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)

Referenced by DoxyDefine(), and while().

◆ DoxyDefine() [2/4]

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, DoxyDefine(), in, 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:235
static void pack_check_over(switch_bitpack_t *pack)

◆ DoxyDefine() [3/4]

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() [4/4]

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() [1/3]

if ( (uint32_t)(unpack->cur - unpack->buf ,
unpack->  buflen 
)

◆ if() [2/3]

if ( (uint32_t)(pack->cur - pack->buf ,
pack->  buflen 
)

Definition at line 228 of file switch_bitpack.h.

228  {
229  return -1;
230  }

◆ if() [3/3]

if ( next  ,
SWITCH_BITS_PER_BYTE   
)

Definition at line 234 of file switch_bitpack.h.

References b, 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, SWITCH_BITPACKED_MASKS, 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 {
const cJSON *const b
Definition: switch_cJSON.h:243
static const uint8_t SWITCH_BITPACKED_MASKS[]
uint8_t switch_byte_t
Definition: switch_types.h:256
#define SWITCH_BITS_PER_BYTE
Definition: switch_types.h:235
switch_byte_t in

◆ memset()

memset ( buf  ,
,
buflen   
)

Referenced by add_xml_header(), cJSON_New_Item(), clear_ice(), collect_thread_run(), db_pick_path(), do_2833(), dtls_state_setup(), early_thread_run(), ecd_deliver(), fct_dotted_line_start(), fct_logger__init(), fct_namespace_init(), fct_timer__init(), fctkern__init(), fetch_device_stats(), SimpleGlobBase< SOCHAR >::FindDone(), freeswitch_kill_background(), generate_m(), CoreSession::getDigits(), handle_ice(), hashtable_expand(), inband_dtmf_generate_callback(), inet_pton4(), init_upnp(), main(), meta_on_dtmf(), new_header(), play_and_collect(), CoreSession::playAndGetDigits(), preprocess(), print(), read_displace_callback(), read_rtp_packet(), CoreSession::recordFile(), reincarnate_protect(), rtp_common_read(), session_audio_callback(), setup_ringback(), SimpleGlobBase< SOCHAR >::SimpleGlobBase(), CoreSession::streamFile(), switch_apr_queue_create(), switch_ast2regex(), switch_buffer_create_dynamic(), switch_buffer_write(), 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_chromakey_autocolor(), switch_chromakey_clear_colors(), switch_config_close_file(), switch_config_open_file(), switch_console_loop(), switch_console_save_history(), 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_gen_encoded_silence(), switch_core_get_stacksizes(), switch_core_hash_insert_alloc_destructor(), 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_expand_headers_check(), switch_fd_read_dline(), switch_find_local_ip(), switch_fp_read_dline(), switch_g711a_decode(), switch_g711u_decode(), switch_generate_sln_silence(), switch_get_addr(), switch_img_fill(), switch_img_gray(), switch_img_sepia(), switch_img_write_text_img(), switch_ivr_digit_stream_new(), switch_ivr_digit_stream_parser_new(), switch_ivr_dmachine_check_match(), 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_event(), 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_jb_set_jitter_estimator(), switch_load_core_config(), switch_load_network_lists(), switch_load_timezones(), switch_loadable_module_init(), switch_log_meta_vprintf(), SWITCH_MODULE_LOAD_FUNCTION(), switch_msrp_init(), switch_msrp_msg_create(), switch_msrp_msg_dup(), switch_nat_init(), switch_nat_multicast_runtime(), switch_odbc_handle_callback_exec_detailed(), switch_odbc_handle_new(), switch_packetizer_create(), switch_packetizer_feed(), 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_separate_string_cheap(), switch_socket_create_pollfd(), switch_speex_init(), switch_stream_spawn(), switch_stristr(), switch_system_fork(), switch_vad_init(), switch_xml_add_child(), switch_xml_locate_language(), switch_xml_new(), switch_xml_toxml_buf_ex(), system_thread(), teletone_init_session(), teletone_mux_tones(), teletone_run(), tm2switchtime(), tztime(), and write_displace_callback().

◆ pack_check_over() [1/2]

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_BITPACKED_MASKS, SWITCH_BITS_PER_BYTE, SWITCH_REVERSE_BITPACKED_MASKS, 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:546
static const uint8_t SWITCH_BITPACKED_MASKS[]
uint8_t switch_byte_t
Definition: switch_types.h:256
unpack this_byte
#define SWITCH_BITS_PER_BYTE
Definition: switch_types.h:235
switch_byte_t bits_cur
Definition: switch_types.h:539
switch_byte_t this_byte
Definition: switch_types.h:543
switch_byte_t under
Definition: switch_types.h:544
switch_byte_t * cur
Definition: switch_types.h:536
switch_byte_t over
Definition: switch_types.h:545
#define switch_assert(expr)

◆ pack_check_over() [2/2]

pack_check_over ( unpack  )

◆ while()

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, DoxyDefine(), switch_bitpack_t::frame_bits, switch_bitpack_t::mode, switch_bitpack_t::over, SWITCH_BITPACK_MODE_RFC3551, SWITCH_BITPACKED_MASKS, SWITCH_BITS_PER_BYTE, SWITCH_REVERSE_BITPACKED_MASKS, this_byte, switch_bitpack_t::this_byte, and switch_bitpack_t::under.

Referenced by switch_core_perform_file_open(), switch_xml_child(), switch_xml_locate_language(), 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:256
unpack this_byte
#define SWITCH_BITS_PER_BYTE
Definition: switch_types.h:235

Variable Documentation

◆ bitlen

switch_byte_t bitlen

Definition at line 76 of file switch_bitpack.h.

◆ bits_cur

unpack bits_cur = 0

Definition at line 161 of file switch_bitpack.h.

◆ bits_tot

pack bits_tot = pack->frame_bits

Definition at line 232 of file switch_bitpack.h.

◆ buf

pack buf = buf

Definition at line 76 of file switch_bitpack.h.

Referenced by build_red_packet(), collect_thread_run(), do_dtls(), eavesdrop_callback(), ecd_deliver(), expand_vars(), find_delim(), get_addr(), get_addr6(), CoreSession::get_cb_args(), get_rtt_payload(), get_rtt_red_seq(), handle_ice(), ice_out(), inband_dtmf_generate_callback(), main(), merge_recording_variables(), msrp_parse_buffer(), msrp_reply(), msrp_report(), msrp_worker(), preprocess(), preprocess_exec(), read_displace_callback(), reincarnate_protect(), separate_string_blank_delim(), separate_string_blank_delim_cheap(), separate_string_char_delim(), separate_string_char_delim_cheap(), switch_amp_encode(), switch_channel_event_set_extended_data(), switch_console_complete(), switch_console_save_history(), switch_core_media_gen_local_sdp(), switch_core_media_read_frame(), switch_core_media_sdp_map(), switch_core_media_set_r_sdp_codec_string(), switch_core_media_set_udptl_image_sdp(), switch_core_session_get_text_buffer(), switch_core_session_write_blank_video(), switch_core_speech_open(), switch_dir_next_file(), switch_escape_string_pool(), switch_event_serialize(), switch_false(), switch_fd_read_dline(), switch_fd_read_line(), switch_fp_read_dline(), switch_get_addr(), switch_ivr_eavesdrop_session(), switch_ivr_originate(), switch_known_bitrate(), switch_loadable_module_get_codecs_sorted(), switch_msrp_do_send(), switch_nat_multicast_runtime(), switch_network_port_range_to_string(), switch_parse_codec_buf(), switch_print_bits(), switch_print_host(), switch_say_file(), switch_separate_string_string(), switch_simple_email(), switch_speex_decode(), switch_speex_encode(), SWITCH_STANDARD_APP(), switch_strerror_r(), switch_string_has_escaped_data(), 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_ex(), teletone_handler(), video_bug_thread(), video_helper_thread(), video_write_thread(), vxprintf(), and write_displace_callback().

◆ buflen

pack buflen = buflen

◆ cur

pack cur = pack->buf

◆ else

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:256
#define SWITCH_BITS_PER_BYTE
Definition: switch_types.h:235
switch_byte_t in

Definition at line 258 of file switch_bitpack.h.

◆ frame_bits

pack frame_bits = bitlen

Definition at line 85 of file switch_bitpack.h.

◆ in

◆ mode

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:235
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

return

Definition at line 91 of file switch_bitpack.h.

◆ SWITCH_BITPACKED_MASKS

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.

Referenced by if(), pack_check_over(), and while().

◆ SWITCH_REVERSE_BITPACKED_MASKS

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.

Referenced by pack_check_over(), and while().

◆ this_byte

unpack this_byte = this_byte = in

Definition at line 162 of file switch_bitpack.h.

Referenced by pack_check_over(), and while().