From 5b752c54a7c6c6368c97cf458340c71634c3ab39 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 22 Dec 2010 15:53:11 -0600 Subject: [PATCH 01/66] fix ignore_early_media=ring_ready --- src/switch_ivr_originate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/switch_ivr_originate.c b/src/switch_ivr_originate.c index 51032dec60..26d8374f9a 100644 --- a/src/switch_ivr_originate.c +++ b/src/switch_ivr_originate.c @@ -488,7 +488,7 @@ static uint8_t check_channel_status(originate_global_t *oglobals, originate_stat pindex = (uint32_t) i; } else if (!oglobals->sent_ring && oglobals->ignore_early_media == 2 && len == 1 && caller_channel && !oglobals->ignore_ring_ready) { switch_channel_pass_callee_id(originate_status[0].peer_channel, caller_channel); - //switch_channel_ring_ready(caller_channel); + switch_channel_ring_ready(caller_channel); oglobals->sent_ring = 1; } From ad1d1d2bab2716b9f7f4b7de2922dc2fb242780c Mon Sep 17 00:00:00 2001 From: Jeff Lenk Date: Wed, 22 Dec 2010 16:13:18 -0600 Subject: [PATCH 02/66] vs2008 express fix build --- Freeswitch.2008.express.sln | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Freeswitch.2008.express.sln b/Freeswitch.2008.express.sln index ad3cafe5cd..d9cb441e2f 100644 --- a/Freeswitch.2008.express.sln +++ b/Freeswitch.2008.express.sln @@ -1642,6 +1642,7 @@ Global {D5D2BF72-29FE-4982-A9FA-82AB2086DB1B}.All|Win32.Build.0 = Release|Win32 {D5D2BF72-29FE-4982-A9FA-82AB2086DB1B}.All|x64.ActiveCfg = Release|Win32 {D5D2BF72-29FE-4982-A9FA-82AB2086DB1B}.Debug|Win32.ActiveCfg = Debug|Win32 + {D5D2BF72-29FE-4982-A9FA-82AB2086DB1B}.Debug|Win32.Build.0 = Debug|Win32 {D5D2BF72-29FE-4982-A9FA-82AB2086DB1B}.Debug|x64.ActiveCfg = Debug|Win32 {D5D2BF72-29FE-4982-A9FA-82AB2086DB1B}.Debug|x64.Build.0 = Debug|Win32 {D5D2BF72-29FE-4982-A9FA-82AB2086DB1B}.Release|Win32.ActiveCfg = Release|Win32 @@ -2047,6 +2048,7 @@ Global {B808178B-82F0-4CF4-A2B1-921939FA24D0}.Debug|Win32.Build.0 = Debug|Win32 {B808178B-82F0-4CF4-A2B1-921939FA24D0}.Debug|x64.ActiveCfg = Debug|Win32 {B808178B-82F0-4CF4-A2B1-921939FA24D0}.Release|Win32.ActiveCfg = Release|Win32 + {B808178B-82F0-4CF4-A2B1-921939FA24D0}.Release|Win32.Build.0 = Release|Win32 {B808178B-82F0-4CF4-A2B1-921939FA24D0}.Release|x64.ActiveCfg = Release|Win32 {9778F1C0-09BC-4698-8EBC-BD982247209A}.All|Win32.ActiveCfg = Release|Win32 {9778F1C0-09BC-4698-8EBC-BD982247209A}.All|x64.ActiveCfg = Release|x64 From 7e880ee33e35986a7435d9e1bfc6e2558b2a9e56 Mon Sep 17 00:00:00 2001 From: Michal Bielicki Date: Wed, 22 Dec 2010 22:24:26 +0000 Subject: [PATCH 03/66] cleanup to debian sound file generation and packaging --- debian/changelog | 6 ++++++ .../debian/changelog | 14 ++++++++++---- .../freeswitch-sounds-en-us-callie/debian/files | 6 ------ .../freeswitch-sounds-en-us-callie/debian/rules | 0 .../freeswitch-sounds-music/debian/changelog | 8 +++++++- debian/sounds/freeswitch-sounds-music/debian/files | 6 ------ debian/sounds/freeswitch-sounds-music/debian/rules | 0 .../freeswitch-sounds-ru-RU-elena/debian/changelog | 6 ++++++ .../freeswitch-sounds-ru-RU-elena/debian/files | 6 ------ .../freeswitch-sounds-ru-RU-elena/debian/rules | 0 debian/sounds/getsounds.sh | 4 ++-- 11 files changed, 31 insertions(+), 25 deletions(-) delete mode 100644 debian/sounds/freeswitch-sounds-en-us-callie/debian/files mode change 100644 => 100755 debian/sounds/freeswitch-sounds-en-us-callie/debian/rules delete mode 100644 debian/sounds/freeswitch-sounds-music/debian/files mode change 100644 => 100755 debian/sounds/freeswitch-sounds-music/debian/rules delete mode 100644 debian/sounds/freeswitch-sounds-ru-RU-elena/debian/files mode change 100644 => 100755 debian/sounds/freeswitch-sounds-ru-RU-elena/debian/rules diff --git a/debian/changelog b/debian/changelog index 8065d932e3..158984b9b9 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +freeswitch (1.0.head~git.master.20101222.1-1) unstable; urgency=low + + * cleaning work + + -- Michal Bielicki Wed, 22 Dec 2010 22:48:02 +0200 + freeswitch (1.0.head~git.master.20101015.1-1) unstable; urgency=low * reintroduced mod_flite diff --git a/debian/sounds/freeswitch-sounds-en-us-callie/debian/changelog b/debian/sounds/freeswitch-sounds-en-us-callie/debian/changelog index 9ca1d1a933..9bb038ae96 100644 --- a/debian/sounds/freeswitch-sounds-en-us-callie/debian/changelog +++ b/debian/sounds/freeswitch-sounds-en-us-callie/debian/changelog @@ -1,11 +1,17 @@ -freeswitch-sounds-en-us-callie (1.0.head-git.master,20101014.1-1) unstable; urgency=low +freeswitch-sounds-en-us-callie (1.0.14~git.master.20101222.1-1) unstable; urgency=low - * Change upstream package version numbering scheme for unreleased versions: - new format is major.minor.micro~git.branch.date.commits-1 + * Bumped up to 1.0.14 version + * Clean ups + + -- Michal Bielicki Wed, 22 Dec 2010 22:55:02 +0200 + +freeswitch-sounds-en-us-callie (1.0.head~git.master.20101014.1-1) unstable; urgency=low + + * Change upstream package version numbering scheme for unreleased versions: new format is major.minor.micro~git.branch.date.commits-1 * Change source format to 3.0 (quilt). * Upgrade debhelper compatibility to version 7. - -- Michal Bielicki Fr, 14 Oct 2010 05:05:02 +0200 + -- Michal Bielicki Fri, 14 Oct 2010 05:05:02 +0200 freeswitch-sounds-en-us-callie (1.0.12-0ubuntu1) jaunty; urgency=low diff --git a/debian/sounds/freeswitch-sounds-en-us-callie/debian/files b/debian/sounds/freeswitch-sounds-en-us-callie/debian/files deleted file mode 100644 index 3da0b654c4..0000000000 --- a/debian/sounds/freeswitch-sounds-en-us-callie/debian/files +++ /dev/null @@ -1,6 +0,0 @@ -freeswitch-sounds-en-us-callie-8000_1.0.12-0ubuntu1_all.deb net extra -freeswitch-sounds-en-us-callie-16000_1.0.12-0ubuntu1_all.deb net extra -freeswitch-sounds-en-us-callie-32000_1.0.12-0ubuntu1_all.deb net extra -freeswitch-sounds-en-us-callie-48000_1.0.12-0ubuntu1_all.deb net extra -freeswitch-sounds-en-us-callie_1.0.12-0ubuntu1_all.deb net extra -freeswitch-sounds-en-us-callie-omega_1.0.12-0ubuntu1_all.deb net extra diff --git a/debian/sounds/freeswitch-sounds-en-us-callie/debian/rules b/debian/sounds/freeswitch-sounds-en-us-callie/debian/rules old mode 100644 new mode 100755 diff --git a/debian/sounds/freeswitch-sounds-music/debian/changelog b/debian/sounds/freeswitch-sounds-music/debian/changelog index 2d639c0691..c5c52da460 100644 --- a/debian/sounds/freeswitch-sounds-music/debian/changelog +++ b/debian/sounds/freeswitch-sounds-music/debian/changelog @@ -1,3 +1,9 @@ +freeswitch-sounds-music (1.0.8~git.master.20101222.1-1) unstable; urgency=low + + * Clean ups + + -- Michal Bielicki Wed, 22 Dec 2010 22:55:02 +0200 + freeswitch-sounds-music (1.0.head-git.master,20101014.1-1) unstable; urgency=low * Change upstream package version numbering scheme for unreleased versions: @@ -5,7 +11,7 @@ freeswitch-sounds-music (1.0.head-git.master,20101014.1-1) unstable; urgency=low * Change source format to 3.0 (quilt). * Upgrade debhelper compatibility to version 7. - -- Michal Bielicki Fr, 14 Oct 2010 05:05:02 +0200 + -- Michal Bielicki Fri, 14 Oct 2010 05:05:02 +0200 freeswitch-sounds-music (1.0.8-0ubuntu3) jaunty; urgency=low diff --git a/debian/sounds/freeswitch-sounds-music/debian/files b/debian/sounds/freeswitch-sounds-music/debian/files deleted file mode 100644 index 9251f8dd29..0000000000 --- a/debian/sounds/freeswitch-sounds-music/debian/files +++ /dev/null @@ -1,6 +0,0 @@ -freeswitch-sounds-music-8000_1.0.8-0ubuntu3_all.deb net extra -freeswitch-sounds-music-16000_1.0.8-0ubuntu3_all.deb net extra -freeswitch-sounds-music-32000_1.0.8-0ubuntu3_all.deb net extra -freeswitch-sounds-music-48000_1.0.8-0ubuntu3_all.deb net extra -freeswitch-sounds-music_1.0.8-0ubuntu3_all.deb net extra -freeswitch-sounds-music-omega_1.0.8-0ubuntu3_all.deb net extra diff --git a/debian/sounds/freeswitch-sounds-music/debian/rules b/debian/sounds/freeswitch-sounds-music/debian/rules old mode 100644 new mode 100755 diff --git a/debian/sounds/freeswitch-sounds-ru-RU-elena/debian/changelog b/debian/sounds/freeswitch-sounds-ru-RU-elena/debian/changelog index 38cc529ef6..44eb4c72b6 100644 --- a/debian/sounds/freeswitch-sounds-ru-RU-elena/debian/changelog +++ b/debian/sounds/freeswitch-sounds-ru-RU-elena/debian/changelog @@ -1,3 +1,9 @@ +freeswitch-sounds-ru-ru-elena (1.0.8~git.master.20101222.1-1) unstable; urgency=low + + * Clean ups + + -- Michal Bielicki Wed, 22 Dec 2010 22:55:02 +0200 + freeswitch-sounds-ru-ru-elena (1.0.head-git.master,20101014.1-1) unstable; urgency=low * Change upstream package version numbering scheme for unreleased versions: diff --git a/debian/sounds/freeswitch-sounds-ru-RU-elena/debian/files b/debian/sounds/freeswitch-sounds-ru-RU-elena/debian/files deleted file mode 100644 index f4b6f0c92d..0000000000 --- a/debian/sounds/freeswitch-sounds-ru-RU-elena/debian/files +++ /dev/null @@ -1,6 +0,0 @@ -freeswitch-sounds-ru-ru-elena-8000_1.0.12-0ubuntu3_all.deb net extra -freeswitch-sounds-ru-ru-elena-16000_1.0.12-0ubuntu3_all.deb net extra -freeswitch-sounds-ru-ru-elena-32000_1.0.12-0ubuntu3_all.deb net extra -freeswitch-sounds-ru-ru-elena-48000_1.0.12-0ubuntu3_all.deb net extra -freeswitch-sounds-ru-ru-elena_1.0.12-0ubuntu3_all.deb net extra -freeswitch-sounds-ru-ru-elena-omega_1.0.12-0ubuntu3_all.deb net extra diff --git a/debian/sounds/freeswitch-sounds-ru-RU-elena/debian/rules b/debian/sounds/freeswitch-sounds-ru-RU-elena/debian/rules old mode 100644 new mode 100755 diff --git a/debian/sounds/getsounds.sh b/debian/sounds/getsounds.sh index bf59a02772..b75a86f309 100755 --- a/debian/sounds/getsounds.sh +++ b/debian/sounds/getsounds.sh @@ -1,5 +1,5 @@ #!/bin/bash -sounds_en_us_callie="freeswitch-sounds-en-us-callie-48000-1.0.12.tar.gz" +sounds_en_us_callie="freeswitch-sounds-en-us-callie-48000-1.0.14.tar.gz" sounds_music="freeswitch-sounds-music-48000-1.0.8.tar.gz" sounds_ru_RU_elena="freeswitch-sounds-ru-RU-elena-48000-1.0.12.tar.gz" @@ -27,4 +27,4 @@ if [ ! -f $sounds_ru_RU_elena ] wget http://files.freeswitch.org/$sounds_ru_RU_elena fi tar zxvf $sounds_ru_RU_elena -cd .. \ No newline at end of file +cd .. From 751e0291ee9bb99119fec0c1cb5814919ec5d8f7 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 22 Dec 2010 19:10:30 -0600 Subject: [PATCH 04/66] prevent race on execute_on_answer called from the B-leg of a call --- src/include/switch_types.h | 1 + src/switch_core_session.c | 20 +++++++++++++++++--- src/switch_ivr.c | 15 +++++++++++++-- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index e04f437eb3..76af5a40ed 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -1096,6 +1096,7 @@ typedef enum { CF_RECOVERED, CF_JITTERBUFFER, CF_DIALPLAN, + CF_BLOCK_BROADCAST_UNTIL_MEDIA, /* WARNING: DO NOT ADD ANY FLAGS BELOW THIS LINE */ CF_FLAG_MAX } switch_channel_flag_t; diff --git a/src/switch_core_session.c b/src/switch_core_session.c index c2766170a8..252b5e205b 100644 --- a/src/switch_core_session.c +++ b/src/switch_core_session.c @@ -1841,6 +1841,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_execute_application_async(sw switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "execute-app-arg", arg); } + if (!switch_channel_test_flag(session->channel, CF_PROXY_MODE)) { + switch_channel_set_flag(session->channel, CF_BLOCK_BROADCAST_UNTIL_MEDIA); + } + switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "event-lock", "true"); switch_core_session_queue_private_event(session, &execute_event, SWITCH_FALSE); @@ -1891,9 +1895,19 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_execute_application_get_flag switch_goto_status(SWITCH_STATUS_FALSE, done); } } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, - "Cannot execute app '%s' media required on an outbound channel that does not have media established\n", app); - switch_goto_status(SWITCH_STATUS_FALSE, done); + uint32_t ready = 0, sanity = 2000; + + do { + sanity--; + ready = switch_channel_media_ready(session->channel); + switch_cond_next(); + } while(!ready && sanity); + + if (!ready) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, + "Cannot execute app '%s' media required on an outbound channel that does not have media established\n", app); + switch_goto_status(SWITCH_STATUS_FALSE, done); + } } } diff --git a/src/switch_ivr.c b/src/switch_ivr.c index 68d5a55b40..82c6ff4791 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -698,12 +698,23 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_parse_all_messages(switch_core_sessio SWITCH_DECLARE(switch_status_t) switch_ivr_parse_all_events(switch_core_session_t *session) { int x = 0; - + switch_channel_t *channel; switch_ivr_parse_all_messages(session); - while (switch_ivr_parse_next_event(session) == SWITCH_STATUS_SUCCESS) + channel = switch_core_session_get_channel(session); + + if (!switch_channel_test_flag(channel, CF_PROXY_MODE) && switch_channel_test_flag(channel, CF_BLOCK_BROADCAST_UNTIL_MEDIA)) { + if (switch_channel_media_ready(channel)) { + switch_channel_clear_flag(channel, CF_BLOCK_BROADCAST_UNTIL_MEDIA); + } else { + return SWITCH_STATUS_SUCCESS; + } + } + + while (switch_ivr_parse_next_event(session) == SWITCH_STATUS_SUCCESS) { x++; + } if (x) { switch_ivr_sleep(session, 0, SWITCH_TRUE, NULL); From 34a0ca50960a152c3ca9cee5099f6aa9109f7735 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 22 Dec 2010 20:38:57 -0600 Subject: [PATCH 05/66] drop rtp frame that was already replaced with a cng frame --- src/include/switch_types.h | 1 + src/mod/applications/mod_dptools/mod_dptools.c | 7 +++++++ src/switch_core_io.c | 3 ++- src/switch_rtp.c | 14 ++++++++++++-- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 76af5a40ed..830ea409e8 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -1097,6 +1097,7 @@ typedef enum { CF_JITTERBUFFER, CF_DIALPLAN, CF_BLOCK_BROADCAST_UNTIL_MEDIA, + CF_CNG_PLC, /* WARNING: DO NOT ADD ANY FLAGS BELOW THIS LINE */ CF_FLAG_MAX } switch_channel_flag_t; diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index e508486380..d5d0cb7576 100755 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -3112,6 +3112,11 @@ SWITCH_STANDARD_APP(verbose_events_function) switch_channel_set_flag(switch_core_session_get_channel(session), CF_VERBOSE_EVENTS); } +SWITCH_STANDARD_APP(cng_plc_function) +{ + switch_channel_set_flag(switch_core_session_get_channel(session), CF_CNG_PLC); +} + SWITCH_STANDARD_APP(early_hangup_function) { switch_channel_set_flag(switch_core_session_get_channel(session), CF_EARLY_HANGUP); @@ -3497,6 +3502,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load) " []", SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC); SWITCH_ADD_APP(app_interface, "verbose_events", "Make ALL Events verbose.", "Make ALL Events verbose.", verbose_events_function, "", SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC); + SWITCH_ADD_APP(app_interface, "cng_plc", "Do PLC on CNG frames", "", cng_plc_function, "", + SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC); SWITCH_ADD_APP(app_interface, "early_hangup", "Enable early hangup", "", early_hangup_function, "", SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC); SWITCH_ADD_APP(app_interface, "sleep", "Pause a channel", SLEEP_LONG_DESC, sleep_function, "", SAF_SUPPORT_NOMEDIA); SWITCH_ADD_APP(app_interface, "delay_echo", "echo audio at a specified delay", "Delay n ms", delay_function, "", SAF_NONE); diff --git a/src/switch_core_io.c b/src/switch_core_io.c index c3113e9680..49956b3172 100644 --- a/src/switch_core_io.c +++ b/src/switch_core_io.c @@ -341,7 +341,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi } if (status == SWITCH_STATUS_SUCCESS) { - if (switch_channel_test_flag(session->channel, CF_JITTERBUFFER) && !session->plc) { + if ((switch_channel_test_flag(session->channel, CF_JITTERBUFFER) || switch_channel_test_flag(session->channel, CF_CNG_PLC)) + && !session->plc) { session->plc = plc_init(NULL); } diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 1600e2858f..60c0bae973 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -175,6 +175,7 @@ struct switch_rtp { uint32_t ts; uint32_t last_write_ts; uint32_t last_read_ts; + uint32_t last_cng_ts; uint32_t last_write_samplecount; uint32_t next_write_samplecount; switch_time_t last_write_timestamp; @@ -2164,11 +2165,19 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t { switch_status_t status = SWITCH_STATUS_FALSE; stfu_frame_t *jb_frame; + uint32_t ts; switch_assert(bytes); *bytes = sizeof(rtp_msg_t); status = switch_socket_recvfrom(rtp_session->from_addr, rtp_session->sock_input, 0, (void *) &rtp_session->recv_msg, bytes); + ts = ntohl(rtp_session->recv_msg.header.ts); + + if (ts && !rtp_session->jb && ts <= rtp_session->last_cng_ts) { + /* we already sent this frame..... */ + *bytes = 0; + return SWITCH_STATUS_SUCCESS; + } if (*bytes) { rtp_session->stats.inbound.raw_bytes += *bytes; @@ -2192,7 +2201,7 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t } - rtp_session->last_read_ts = ntohl(rtp_session->recv_msg.header.ts); + rtp_session->last_read_ts = ts; if (rtp_session->jb && rtp_session->recv_msg.header.version == 2 && *bytes) { if (rtp_session->recv_msg.header.m && rtp_session->recv_msg.header.pt != rtp_session->recv_te && @@ -2920,7 +2929,8 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ if (do_cng) { uint8_t *data = (uint8_t *) rtp_session->recv_msg.body; - + rtp_session->last_cng_ts = rtp_session->last_read_ts + rtp_session->samples_per_interval; + memset(data, 0, 2); data[0] = 65; rtp_session->recv_msg.header.pt = (uint32_t) rtp_session->cng_pt ? rtp_session->cng_pt : SWITCH_RTP_CNG_PAYLOAD; From 03f5d55fc95d9c3ea2516e8d7a852d1a73cc0eac Mon Sep 17 00:00:00 2001 From: Georgiewskiy Yuriy Date: Thu, 23 Dec 2010 17:10:59 +0300 Subject: [PATCH 06/66] change terminal type --- src/mod/endpoints/mod_h323/mod_h323.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/endpoints/mod_h323/mod_h323.cpp b/src/mod/endpoints/mod_h323/mod_h323.cpp index 3d79917434..a31f9a81fc 100644 --- a/src/mod/endpoints/mod_h323/mod_h323.cpp +++ b/src/mod/endpoints/mod_h323/mod_h323.cpp @@ -589,7 +589,7 @@ FSH323EndPoint::FSH323EndPoint() ,m_fax_old_asn(false) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"======>FSH323EndPoint::FSH323EndPoint [%p]\n",this); - terminalType = e_GatewayOnly; + terminalType = e_GatewayAndMC; } FSH323EndPoint::~FSH323EndPoint() From 75198fe4cb130f3d6d0d43f50882188879a59f6f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 23 Dec 2010 13:18:41 -0600 Subject: [PATCH 07/66] audio adjustments --- .../mod_conference/mod_conference.c | 88 +++++++++++++++---- src/switch_rtp.c | 14 ++- 2 files changed, 79 insertions(+), 23 deletions(-) diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c index fa1f12c13f..2370e70ba1 100644 --- a/src/mod/applications/mod_conference/mod_conference.c +++ b/src/mod/applications/mod_conference/mod_conference.c @@ -408,7 +408,7 @@ static switch_status_t conference_local_play_file(conference_obj_t *conference, static switch_status_t conference_member_play_file(conference_member_t *member, char *file, uint32_t leadin); static switch_status_t conference_member_say(conference_member_t *member, char *text, uint32_t leadin); static uint32_t conference_member_stop_file(conference_member_t *member, file_stop_t stop); -static conference_obj_t *conference_new(char *name, conf_xml_cfg_t cfg, switch_memory_pool_t *pool); +static conference_obj_t *conference_new(char *name, conf_xml_cfg_t cfg, switch_core_session_t *session, switch_memory_pool_t *pool); static switch_status_t chat_send(const char *proto, const char *from, const char *to, const char *subject, const char *body, const char *type, const char *hint); @@ -2499,6 +2499,10 @@ static void conference_loop_output(conference_member_t *member) use_buffer = NULL; mux_used = (uint32_t) switch_buffer_inuse(member->mux_buffer); + + if (mux_used < bytes * 2) { + use_timer = 1; + } if (mux_used) { if (mux_used < bytes) { @@ -2512,10 +2516,7 @@ static void conference_loop_output(conference_member_t *member) } } - - use_timer = 1; - - if (mux_used) { + if (mux_used >= bytes) { /* Flush the output buffer and write all the data (presumably muxed) back to the channel */ switch_mutex_lock(member->audio_out_mutex); write_frame.data = data; @@ -2523,7 +2524,7 @@ static void conference_loop_output(conference_member_t *member) low_count = 0; if ((write_frame.datalen = (uint32_t) switch_buffer_read(use_buffer, write_frame.data, bytes))) { if (write_frame.datalen) { - write_frame.samples = write_frame.datalen / 2; + write_frame.samples = write_frame.datalen / 2; if( !switch_test_flag(member, MFLAG_CAN_HEAR)) { memset(write_frame.data, 255, write_frame.datalen); @@ -4347,7 +4348,7 @@ static switch_status_t conf_api_sub_transfer(conference_obj_t *conference, switc } /* Create the conference object. */ - new_conference = conference_new(conf_name, xml_cfg, pool); + new_conference = conference_new(conf_name, xml_cfg, member->session, pool); /* Release the config registry handle */ if (cxml) { @@ -5472,7 +5473,7 @@ SWITCH_STANDARD_APP(conference_function) } /* Create the conference object. */ - conference = conference_new(conf_name, xml_cfg, NULL); + conference = conference_new(conf_name, xml_cfg, session, NULL); if (!conference) { goto done; @@ -5517,7 +5518,7 @@ SWITCH_STANDARD_APP(conference_function) const char *max_members_str; /* couldn't find the conference, create one */ - conference = conference_new(conf_name, xml_cfg, NULL); + conference = conference_new(conf_name, xml_cfg, session, NULL); if (!conference) { goto done; @@ -5942,7 +5943,7 @@ static conference_obj_t *conference_find(char *name) } /* create a new conferene with a specific profile */ -static conference_obj_t *conference_new(char *name, conf_xml_cfg_t cfg, switch_memory_pool_t *pool) +static conference_obj_t *conference_new(char *name, conf_xml_cfg_t cfg, switch_core_session_t *session, switch_memory_pool_t *pool) { conference_obj_t *conference; switch_xml_t xml_kvp; @@ -5985,13 +5986,48 @@ static conference_obj_t *conference_new(char *name, conf_xml_cfg_t cfg, switch_m char *verbose_events = NULL; char *auto_record = NULL; char *terminate_on_silence = NULL; - + switch_codec_implementation_t read_impl = { 0 }; + switch_channel_t *channel = NULL; + const char *force_rate = NULL, *force_interval = NULL; + uint32_t force_rate_i = 0, force_interval_i = 0; + /* Validate the conference name */ if (zstr(name)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Record! no name.\n"); return NULL; } + if (session) { + uint32_t tmp; + + switch_core_session_get_read_impl(session, &read_impl); + channel = switch_core_session_get_channel(session); + + if ((force_rate = switch_channel_get_variable(channel, "conference_force_rate"))) { + if (!strcasecmp(force_rate, "auto")) { + force_rate_i = read_impl.actual_samples_per_second; + } else { + tmp = atoi(force_rate); + + if (tmp == 8000 || tmp == 12000 || tmp == 16000 || tmp == 24000 || tmp == 32000 || tmp == 48000) { + force_rate_i = rate = tmp; + } + } + } + + if ((force_interval = switch_channel_get_variable(channel, "conference_force_interval"))) { + if (!strcasecmp(force_interval, "auto")) { + force_interval_i = read_impl.microseconds_per_packet / 1000; + } else { + tmp = atoi(force_interval); + + if (SWITCH_ACCEPTABLE_INTERVAL(tmp)) { + force_interval_i = interval = tmp; + } + } + } + } + switch_mutex_lock(globals.hash_mutex); /* parse the profile tree for param values */ @@ -6012,20 +6048,33 @@ static conference_obj_t *conference_new(char *name, conf_xml_cfg_t cfg, switch_m var = buf; } - if (!strcasecmp(var, "rate") && !zstr(val)) { + if (!force_rate_i && !strcasecmp(var, "rate") && !zstr(val)) { uint32_t tmp = atoi(val); - if (tmp == 8000 || tmp == 12000 || tmp == 16000 || tmp == 24000 || tmp == 32000 || tmp == 48000) { - rate = tmp; + if (session && tmp == 0) { + if (!strcasecmp(val, "auto")) { + rate = read_impl.actual_samples_per_second; + } + } else { + if (tmp == 8000 || tmp == 12000 || tmp == 16000 || tmp == 24000 || tmp == 32000 || tmp == 48000) { + rate = tmp; + } } } else if (!strcasecmp(var, "domain") && !zstr(val)) { domain = val; - } else if (!strcasecmp(var, "interval") && !zstr(val)) { + } else if (!force_interval_i && !strcasecmp(var, "interval") && !zstr(val)) { uint32_t tmp = atoi(val); - if (SWITCH_ACCEPTABLE_INTERVAL(tmp)) { - interval = tmp; + + if (session && tmp == 0) { + if (!strcasecmp(val, "auto")) { + interval = read_impl.microseconds_per_packet / 1000; + } } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, - "Interval must be multipe of 10 and less than %d, Using default of 20\n", SWITCH_MAX_INTERVAL); + if (SWITCH_ACCEPTABLE_INTERVAL(tmp)) { + interval = tmp; + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, + "Interval must be multipe of 10 and less than %d, Using default of 20\n", SWITCH_MAX_INTERVAL); + } } } else if (!strcasecmp(var, "timer-name") && !zstr(val)) { timer_name = val; @@ -6296,6 +6345,7 @@ static conference_obj_t *conference_new(char *name, conf_xml_cfg_t cfg, switch_m } else { conference->domain = "cluecon.com"; } + conference->rate = rate; conference->interval = interval; diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 60c0bae973..5c4aa307fd 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -2172,8 +2172,9 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t *bytes = sizeof(rtp_msg_t); status = switch_socket_recvfrom(rtp_session->from_addr, rtp_session->sock_input, 0, (void *) &rtp_session->recv_msg, bytes); ts = ntohl(rtp_session->recv_msg.header.ts); - - if (ts && !rtp_session->jb && ts <= rtp_session->last_cng_ts) { + + if (*bytes && (!rtp_session->recv_te || rtp_session->recv_msg.header.pt != rtp_session->recv_te) && + ts && !rtp_session->jb && ts == rtp_session->last_cng_ts) { /* we already sent this frame..... */ *bytes = 0; return SWITCH_STATUS_SUCCESS; @@ -2929,8 +2930,13 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ if (do_cng) { uint8_t *data = (uint8_t *) rtp_session->recv_msg.body; - rtp_session->last_cng_ts = rtp_session->last_read_ts + rtp_session->samples_per_interval; - + + if (rtp_session->last_cng_ts == rtp_session->last_read_ts + rtp_session->samples_per_interval) { + rtp_session->last_cng_ts = 0; + } else { + rtp_session->last_cng_ts = rtp_session->last_read_ts + rtp_session->samples_per_interval; + } + memset(data, 0, 2); data[0] = 65; rtp_session->recv_msg.header.pt = (uint32_t) rtp_session->cng_pt ? rtp_session->cng_pt : SWITCH_RTP_CNG_PAYLOAD; From 08769e97b2344682a6ce856b2a69ea2e1bc34b37 Mon Sep 17 00:00:00 2001 From: Raymond Chandler Date: Thu, 23 Dec 2010 18:01:21 -0500 Subject: [PATCH 08/66] couple small usability issues --- libs/esl/perl/ESL/Dispatch.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/esl/perl/ESL/Dispatch.pm b/libs/esl/perl/ESL/Dispatch.pm index 1d21934046..d1712d1cfc 100644 --- a/libs/esl/perl/ESL/Dispatch.pm +++ b/libs/esl/perl/ESL/Dispatch.pm @@ -40,7 +40,8 @@ sub set_callback($;$$) { $self->{_callback}->{$event} = shift; my $subclass = shift; if($subclass) { - $self->{_custom_subclass} = split(/,/, $subclass); + my @subclasses = split(/,/, $subclass); + $self->{_custom_subclass} = \@subclasses; } } @@ -79,7 +80,7 @@ sub run($;) { for(;;) { # Only register for events we have callbacks for. for my $key ( keys %{$self->{_callback}} ) { - if ($key eq "CUSTOM") { + if ($key =~ m/custom/i) { foreach $subclass (@{$self->{_custom_subclass}}) { $self->{_esl}->events("plain", "$key $subclass"); } From 55dbbcf195b9ad150cf0d77c39693fe1e5f1009e Mon Sep 17 00:00:00 2001 From: Jeff Lenk Date: Fri, 24 Dec 2010 09:41:31 -0600 Subject: [PATCH 09/66] add vs2008 windows lua-esl build files --- libs/esl/lua/esl_lua.2008.sln | 26 +++ libs/esl/lua/esl_lua.2008.vcproj | 351 +++++++++++++++++++++++++++++++ 2 files changed, 377 insertions(+) create mode 100644 libs/esl/lua/esl_lua.2008.sln create mode 100644 libs/esl/lua/esl_lua.2008.vcproj diff --git a/libs/esl/lua/esl_lua.2008.sln b/libs/esl/lua/esl_lua.2008.sln new file mode 100644 index 0000000000..cdfbd44ab7 --- /dev/null +++ b/libs/esl/lua/esl_lua.2008.sln @@ -0,0 +1,26 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ESL", "esl_lua.2008.vcproj", "{86B6AB99-A261-455A-9CD6-9142A5A1652E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {86B6AB99-A261-455A-9CD6-9142A5A1652E}.Debug|Win32.ActiveCfg = Debug|Win32 + {86B6AB99-A261-455A-9CD6-9142A5A1652E}.Debug|Win32.Build.0 = Debug|Win32 + {86B6AB99-A261-455A-9CD6-9142A5A1652E}.Debug|x64.ActiveCfg = Debug|x64 + {86B6AB99-A261-455A-9CD6-9142A5A1652E}.Debug|x64.Build.0 = Debug|x64 + {86B6AB99-A261-455A-9CD6-9142A5A1652E}.Release|Win32.ActiveCfg = Release|Win32 + {86B6AB99-A261-455A-9CD6-9142A5A1652E}.Release|Win32.Build.0 = Release|Win32 + {86B6AB99-A261-455A-9CD6-9142A5A1652E}.Release|x64.ActiveCfg = Release|x64 + {86B6AB99-A261-455A-9CD6-9142A5A1652E}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/libs/esl/lua/esl_lua.2008.vcproj b/libs/esl/lua/esl_lua.2008.vcproj new file mode 100644 index 0000000000..38111c8580 --- /dev/null +++ b/libs/esl/lua/esl_lua.2008.vcproj @@ -0,0 +1,351 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From d24af1e1c2c49bd8486ec8b29a12a6e11565feaa Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Sat, 25 Dec 2010 15:02:35 +0000 Subject: [PATCH 10/66] close font tags in email templates --- conf/notify-voicemail.tpl | 1 + conf/voicemail.tpl | 1 + 2 files changed, 2 insertions(+) diff --git a/conf/notify-voicemail.tpl b/conf/notify-voicemail.tpl index 5defd74b3a..365faa2921 100644 --- a/conf/notify-voicemail.tpl +++ b/conf/notify-voicemail.tpl @@ -37,6 +37,7 @@ Content-Transfer-Encoding: 7bit Created: ${voicemail_time}
Duration: ${voicemail_message_len}
Account: ${voicemail_account}@${voicemail_domain}
+ diff --git a/conf/voicemail.tpl b/conf/voicemail.tpl index a98f9d703e..2774b78a9e 100644 --- a/conf/voicemail.tpl +++ b/conf/voicemail.tpl @@ -37,6 +37,7 @@ Content-Transfer-Encoding: 7bit Created: ${voicemail_time}
Duration: ${voicemail_message_len}
Account: ${voicemail_account}@${voicemail_domain}
+ From 5d5485708d614c16740b48919f85dafc014cd14f Mon Sep 17 00:00:00 2001 From: Steve Underwood Date: Sun, 26 Dec 2010 13:25:03 +0800 Subject: [PATCH 11/66] A bunch of tweaks to the G.722.1 codec --- libs/libg722_1/Makefile.am | 6 +- libs/libg722_1/autogen.sh | 5 - libs/libg722_1/configure.ac | 36 +- libs/libg722_1/doc/Makefile.am | 2 - libs/libg722_1/g722_1.spec.in | 3 +- libs/libg722_1/src/Makefile.am | 79 +-- libs/libg722_1/src/basop32.c | 2 - libs/libg722_1/src/basop32.h | 20 +- libs/libg722_1/src/bitstream.c | 2 - libs/libg722_1/src/bitstream.h | 2 - libs/libg722_1/src/coef2sam.c | 44 +- libs/libg722_1/src/coef2sam.h | 4 +- libs/libg722_1/src/common.c | 162 +----- libs/libg722_1/src/commonf.c | 8 +- libs/libg722_1/src/dct4.c | 72 +-- libs/libg722_1/src/dct4_a.c | 204 +++----- libs/libg722_1/src/dct4_a.h | 4 +- libs/libg722_1/src/dct4_s.c | 237 +++------ libs/libg722_1/src/dct4_s.h | 10 +- libs/libg722_1/src/decoder.c | 26 +- libs/libg722_1/src/decoderf.c | 23 +- libs/libg722_1/src/defs.h | 4 +- libs/libg722_1/src/encoder.c | 30 +- libs/libg722_1/src/encoderf.c | 24 +- libs/libg722_1/src/g722_1.h.in | 2 - libs/libg722_1/src/g722_1/g722_1.h | 4 +- libs/libg722_1/src/g722_1/version.h.in | 2 - libs/libg722_1/src/huff_tab.c | 4 +- libs/libg722_1/src/huff_tab.h | 4 +- libs/libg722_1/src/make_dct4_tables.c | 9 +- libs/libg722_1/src/make_tables.c | 26 +- libs/libg722_1/src/sam2coef.c | 49 +- libs/libg722_1/src/sam2coef.h | 4 +- libs/libg722_1/src/tables.c | 530 ++++++++++---------- libs/libg722_1/src/tables.h | 4 +- libs/libg722_1/src/utilities.c | 467 +++++++++++++++++ libs/libg722_1/src/utilities.h | 32 ++ libs/libg722_1/test-data/Makefile.am | 2 - libs/libg722_1/test-data/itu/Makefile.am | 2 - libs/libg722_1/test-data/local/Makefile.am | 2 - libs/libg722_1/tests/Makefile.am | 6 +- libs/libg722_1/tests/g192_bit_stream.c | 177 +++++++ libs/libg722_1/tests/g192_bit_stream.h | 75 +++ libs/libg722_1/tests/g722_1_tests.c | 8 +- libs/libg722_1/tests/itu_bit_stream.c | 139 ----- libs/libg722_1/tests/regression_tests.sh.in | 27 +- libs/libg722_1/tests/timing.h | 4 +- libs/libg722_1/unpack_g722_1_data.sh | 3 - 48 files changed, 1402 insertions(+), 1189 deletions(-) create mode 100644 libs/libg722_1/src/utilities.c create mode 100644 libs/libg722_1/src/utilities.h create mode 100644 libs/libg722_1/tests/g192_bit_stream.c create mode 100644 libs/libg722_1/tests/g192_bit_stream.h delete mode 100644 libs/libg722_1/tests/itu_bit_stream.c diff --git a/libs/libg722_1/Makefile.am b/libs/libg722_1/Makefile.am index f815fb8ddc..9d885335bb 100644 --- a/libs/libg722_1/Makefile.am +++ b/libs/libg722_1/Makefile.am @@ -15,8 +15,6 @@ ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -## -## $Id: Makefile.am,v 1.6 2008/09/30 14:06:39 steveu Exp $ AM_CFLAGS = $(COMP_VENDOR_CFLAGS) AM_LDFLAGS = $(COMP_VENDOR_LDFLAGS) @@ -26,6 +24,7 @@ noinst_SCRIPTS = g722_1.spec MAINTAINERCLEANFILES = Makefile.in EXTRA_DIST = autogen.sh \ + g722_1.pc \ g722_1.spec \ unpack_g722_1_data.sh \ wrapper.xsl \ @@ -50,6 +49,9 @@ SUBDIRS = src $(MAYBE_DOC) $(MAYBE_TESTS) DIST_SUBDIRS = src doc tests test-data +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = g722_1.pc + faq: faq.xml cd faq ; xsltproc ../wrapper.xsl ../faq.xml diff --git a/libs/libg722_1/autogen.sh b/libs/libg722_1/autogen.sh index 96422dbee3..98fb7e4f8a 100755 --- a/libs/libg722_1/autogen.sh +++ b/libs/libg722_1/autogen.sh @@ -16,11 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# $Id: autogen.sh,v 1.1.1.1 2008/09/20 09:47:17 steveu Exp $ -# - -UNAME=`uname` if [ "x$UNAME" = "xFreeBSD" ]; then echo "" diff --git a/libs/libg722_1/configure.ac b/libs/libg722_1/configure.ac index 64e276b280..62095ce374 100644 --- a/libs/libg722_1/configure.ac +++ b/libs/libg722_1/configure.ac @@ -15,17 +15,11 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# $Id: configure.ac,v 1.9 2008/10/09 14:17:12 steveu Exp $ # @start 1 AC_INIT -CFLAGS="$CFLAGS $CONFIGURE_CFLAGS" -CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS" -LDFLAGS="$LDFLAGS $CONFIGURE_LDFLAGS" - m4_include(config/ax_compiler_vendor.m4) m4_include(config/ax_check_real_file.m4) m4_include(config/ax_fixed_point_machine.m4) @@ -111,6 +105,22 @@ else CXXFLAGS=${CXXFLAGS-"-g -O2"} fi +AC_DEFUN([REMOVE_FROM_VAR],[ + new_val="" + removed=0 + for i in $$1; do + if test "x$i" != "x$2"; then + new_val="$new_val $i" + else + removed=1 + fi + done + if test $removed = "1"; then + echo " removed \"$2\" from $1" + $1=$new_val + fi +]) + AC_C_CONST AC_C_INLINE AC_C_VOLATILE @@ -190,7 +200,7 @@ AC_CHECK_HEADERS([audiofile.h]) AC_LANG([C]) -if test "${build}" = "${host}" +if test "${build}" == "${host}" then case "${host}" in x86_64-*) @@ -270,6 +280,7 @@ sun) COMP_VENDOR_CFLAGS="-native -fast $COMP_VENDOR_CFLAGS" fi COMP_VENDOR_LDFLAGS= + REMOVE_FROM_VAR(CFLAGS, -Xc) ;; *) COMP_VENDOR_CFLAGS="-std=c99 -Wall -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes" @@ -293,20 +304,14 @@ AM_CONDITIONAL([COND_SSE5], [test "$enable_sse5" = yes]) if test "$enable_fixed_point" = "yes" ; then AC_DEFINE([G722_1_USE_FIXED_POINT], [1], [Enable fixed point processing, where possible, instead of floating point]) G722_1_USE_FIXED_POINT="#define G722_1_USE_FIXED_POINT 1" - fixed = "yes" G722_1_VECTORS_FOR_TESTS="fixed" else AX_FIXED_POINT_MACHINE([$host], - [ - AC_DEFINE([G722_1_USE_FIXED_POINT], [1], [Enable fixed point processing, where possible, instead of floating point]) - G722_1_USE_FIXED_POINT="#define G722_1_USE_FIXED_POINT 1" - fixed = "yes" - ], + [AC_DEFINE([G722_1_USE_FIXED_POINT], [1], [Enable fixed point processing, where possible, instead of floating point]) + G722_1_USE_FIXED_POINT="#define G722_1_USE_FIXED_POINT 1"], [G722_1_USE_FIXED_POINT="#undef G722_1_USE_FIXED_POINT"]) G722_1_VECTORS_FOR_TESTS="floating" fi -AM_CONDITIONAL([COND_FIXED], [test "$fixed" = "yes"]) - AX_MISALIGNED_ACCESS_FAILS([$host], [AC_DEFINE([G722_1_MISALIGNED_ACCESS_FAILS], [1], [Do not expect a misaligned memory access to work correctly]) G722_1_MISALIGNED_ACCESS_FAILS="#define G722_1_MISALIGNED_ACCESS_FAILS 1"], @@ -363,6 +368,7 @@ AC_CONFIG_FILES([Makefile src/Makefile src/g722_1.h tests/Makefile + g722_1.pc g722_1.spec]) AC_CONFIG_FILES([tests/regression_tests.sh], [chmod +x tests/regression_tests.sh]) diff --git a/libs/libg722_1/doc/Makefile.am b/libs/libg722_1/doc/Makefile.am index 4e58bbd8b8..a56809d00a 100644 --- a/libs/libg722_1/doc/Makefile.am +++ b/libs/libg722_1/doc/Makefile.am @@ -15,8 +15,6 @@ ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -## -## $Id: Makefile.am,v 1.1.1.1 2008/09/20 09:47:17 steveu Exp $ MAINTAINERCLEANFILES = Makefile.in diff --git a/libs/libg722_1/g722_1.spec.in b/libs/libg722_1/g722_1.spec.in index db1d06a686..0c2b26dbc3 100644 --- a/libs/libg722_1/g722_1.spec.in +++ b/libs/libg722_1/g722_1.spec.in @@ -47,14 +47,13 @@ rm -rf %{buildroot} %{_libdir}/libg722_1.so.* -%{_datadir}/libg722_1 - %files devel %defattr(-,root,root,-) %doc doc/api %{_includedir}/g722_1.h %{_includedir}/g722_1 %{_libdir}/libg722_1.so +%{_libdir}/pkgconfig/g722_1.pc %post -p /sbin/ldconfig diff --git a/libs/libg722_1/src/Makefile.am b/libs/libg722_1/src/Makefile.am index 1943658d91..8600e920b2 100644 --- a/libs/libg722_1/src/Makefile.am +++ b/libs/libg722_1/src/Makefile.am @@ -15,18 +15,19 @@ ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -## -## $Id: Makefile.am,v 1.10 2008/10/16 15:46:12 steveu Exp $ AM_CFLAGS = $(COMP_VENDOR_CFLAGS) AM_LDFLAGS = $(COMP_VENDOR_LDFLAGS) MAINTAINERCLEANFILES = Makefile.in -EXTRA_DIST = g722_1/version.h.in \ +EXTRA_DIST = make_tables.c \ + g722_1/version.h.in \ libg722_1.dsp \ - libg722_1.sln \ - libg722_1.vcproj \ + libg722_1.2005.sln \ + libg722_1.2008.sln \ + libg722_1.2005.vcproj \ + libg722_1.2008.vcproj \ msvc/gettimeofday.c \ msvc/inttypes.h \ msvc/tgmath.h \ @@ -36,13 +37,16 @@ EXTRA_DIST = g722_1/version.h.in \ msvc/msvcproj.head \ msvc/msvcproj.foot \ msvc/vc8proj.head \ - msvc/vc8proj.foot + msvc/vc8proj.foot \ + msvc/vc9proj.head \ + msvc/vc9proj.foot INCLUDES = -I$(top_builddir) lib_LTLIBRARIES = libg722_1.la -libg722_1_la_SOURCES = bitstream.c \ +libg722_1_la_SOURCES = basop32.c \ + bitstream.c \ coef2sam.c \ common.c \ commonf.c \ @@ -55,11 +59,9 @@ libg722_1_la_SOURCES = bitstream.c \ encoderf.c \ huff_tab.c \ sam2coef.c \ - tables.c + tables.c \ + utilities.c -if COND_FIXED -libg722_1_la_SOURCES += basop32.c -endif libg722_1_la_LDFLAGS = -version-info @G722_1_LT_CURRENT@:@G722_1_LT_REVISION@:@G722_1_LT_AGE@ $(COMP_VENDOR_LDFLAGS) nobase_include_HEADERS = g722_1/g722_1.h \ @@ -76,10 +78,10 @@ noinst_HEADERS = basop32.h \ defs.h \ huff_tab.h \ sam2coef.h \ - tables.h + tables.h \ + utilities.h -noinst_PROGRAMS = make_dct4_tables \ - make_tables +noinst_PROGRAMS = make_dct4_tables dct4.$(OBJEXT): dct4.h @@ -88,6 +90,9 @@ dct4.lo: dct4.h dct4.h: make_dct4_tables$(EXEEXT) ./make_dct4_tables$(EXEEXT) >dct4.h +make_dct4_tables$(EXEEXT): $(top_srcdir)/src/make_dct4_tables.c + $(CC_FOR_BUILD) -o make_dct4_tables$(EXEEXT) $(top_srcdir)/src/make_dct4_tables.c -DHAVE_CONFIG_H -I$(top_builddir)/src -lm + #coef2sam.h: make_tables$(EXEEXT) # ./make_tables$(EXEEXT) coef2sam >coef2samx.h @@ -95,13 +100,15 @@ dct4.h: make_dct4_tables$(EXEEXT) # ./make_tables$(EXEEXT) sam2coef >sam2coefx.h DSP = libg722_1.dsp -VCPROJ = libg722_1.vcproj +VCPROJ8 = libg722_1.2005.vcproj +VCPROJ9 = libg722_1.2008.vcproj WIN32SOURCES = $(libg722_1_la_SOURCES) msvc/gettimeofday.c WIN32HEADERS = $(nobase_include_HEADERS) g722_1.h DSPOUT = | awk '{printf("%s\r\n", $$0)}' >> $(DSP) -VCPROJOUT = | awk '{printf("%s\r\n", $$0)}' >> $(VCPROJ) +VCPROJOUT8 = | awk '{printf("%s\r\n", $$0)}' >> $(VCPROJ8) +VCPROJOUT9 = | awk '{printf("%s\r\n", $$0)}' >> $(VCPROJ9) $(DSP): msvc/msvcproj.head msvc/msvcproj.foot Makefile.am echo "creating $(DSP)" @@ -124,26 +131,38 @@ $(DSP): msvc/msvcproj.head msvc/msvcproj.foot Makefile.am echo "# End Group" $(DSPOUT); \ cat $(srcdir)/msvc/msvcproj.foot $(DSPOUT) ) -$(VCPROJ): msvc/vc8proj.head msvc/vc8proj.foot Makefile.am - echo "creating $(VCPROJ)" - @(cp $(srcdir)/msvc/vc8proj.head $(VCPROJ); \ +$(VCPROJ8): msvc/vc8proj.head msvc/vc8proj.foot Makefile.am + echo "creating $(VCPROJ8)" + @(cp $(srcdir)/msvc/vc8proj.head $(VCPROJ8); \ for file in $(WIN32SOURCES); do \ - echo "" $(VCPROJOUT); \ + myfile=`echo $$file | sed -e 's|/|\\\\|g'`; \ + echo "" $(VCPROJOUT8); \ done; \ - echo "" $(VCPROJOUT); \ + echo "" $(VCPROJOUT8); \ for file in $(WIN32HEADERS); do \ - echo "" $(VCPROJOUT); \ + myfile=`echo $$file | sed -e 's|/|\\\\|g'`; \ + echo "" $(VCPROJOUT8); \ done; \ - cat $(srcdir)/msvc/vc8proj.foot $(VCPROJOUT) ) + cat $(srcdir)/msvc/vc8proj.foot $(VCPROJOUT8) ) + +$(VCPROJ9): msvc/vc9proj.head msvc/vc9proj.foot Makefile.am + echo "creating $(VCPROJ9)" + @(cp $(srcdir)/msvc/vc9proj.head $(VCPROJ9); \ + for file in $(WIN32SOURCES); do \ + myfile=`echo $$file | sed -e 's|/|\\\\|g'`; \ + echo "" $(VCPROJOUT9); \ + done; \ + echo "" $(VCPROJOUT9); \ + for file in $(WIN32HEADERS); do \ + myfile=`echo $$file | sed -e 's|/|\\\\|g'`; \ + echo "" $(VCPROJOUT9); \ + done; \ + cat $(srcdir)/msvc/vc9proj.foot $(VCPROJOUT9) ) + +dist-hook: g722_1/version.h g722_1/version.h: NOWDATE=`date --utc +"%Y%m%d"` ; \ NOWTIME=`date --utc +"%H%M%S"` ; \ sed 's/$$G722_1_RELEASE_DATE/'$$NOWDATE'/;s/$$G722_1_RELEASE_TIME/'$$NOWTIME'/' \ - g722_1/version.h - -dist-hook: - NOWDATE=`date --utc +"%Y%m%d"` ; \ - NOWTIME=`date --utc +"%H%M%S"` ; \ - sed 's/$$G722_1_RELEASE_DATE/'$$NOWDATE'/;s/$$G722_1_RELEASE_TIME/'$$NOWTIME'/' \ - g722_1/version.h + <$(srcdir)/g722_1/version.h.in >$@ diff --git a/libs/libg722_1/src/basop32.c b/libs/libg722_1/src/basop32.c index 54220f4fac..210e1296ec 100644 --- a/libs/libg722_1/src/basop32.c +++ b/libs/libg722_1/src/basop32.c @@ -9,8 +9,6 @@ * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: basop32.c,v 1.5 2008/09/22 13:08:31 steveu Exp $ */ /*! \file */ diff --git a/libs/libg722_1/src/basop32.h b/libs/libg722_1/src/basop32.h index abc105f35e..36dae35297 100644 --- a/libs/libg722_1/src/basop32.h +++ b/libs/libg722_1/src/basop32.h @@ -6,14 +6,12 @@ * Adapted by Steve Underwood from the reference * code supplied with ITU G.722.1, which is: * - * © 2004 Polycom, Inc. + * (C) 2004 Polycom, Inc. * All rights reserved. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: basop32.h,v 1.3 2008/09/22 13:08:31 steveu Exp $ */ #if !defined(BASOP32_H_DEFINED) @@ -104,14 +102,14 @@ static __inline__ int32_t L_mac(int32_t L_var3, int16_t var1, int16_t var2) } /*- End of function --------------------------------------------------------*/ -int16_t shl(int16_t var1, int16_t var2); /* Short shift left, 1 */ -int16_t shr(int16_t var1, int16_t var2); /* Short shift right, 1 */ -int32_t L_sub(int32_t L_var1, int32_t L_var2); /* Long sub, 2 */ -int32_t L_shl(int32_t L_var1, int16_t var2); /* Long shift left, 2 */ -int32_t L_shr(int32_t L_var1, int16_t var2); /* Long shift right, 2*/ -int16_t norm_s(int16_t var1); /* Short norm, 15 */ -int16_t div_s(int16_t var1, int16_t var2); /* Short division, 18 */ -int16_t norm_l(int32_t L_var1); /* Long norm, 30 */ +int16_t shl(int16_t var1, int16_t var2); /* Short shift left, 1 */ +int16_t shr(int16_t var1, int16_t var2); /* Short shift right, 1 */ +int32_t L_sub(int32_t L_var1, int32_t L_var2); /* Long sub, 2 */ +int32_t L_shl(int32_t L_var1, int16_t var2); /* Long shift left, 2 */ +int32_t L_shr(int32_t L_var1, int16_t var2); /* Long shift right, 2 */ +int16_t norm_s(int16_t var1); /* Short norm, 15 */ +int16_t div_s(int16_t var1, int16_t var2); /* Short division, 18 */ +int16_t norm_l(int32_t L_var1); /* Long norm, 30 */ #endif diff --git a/libs/libg722_1/src/bitstream.c b/libs/libg722_1/src/bitstream.c index ddaabd0edf..016ab8ee45 100644 --- a/libs/libg722_1/src/bitstream.c +++ b/libs/libg722_1/src/bitstream.c @@ -8,8 +8,6 @@ * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: bitstream.c,v 1.2 2008/10/17 13:18:21 steveu Exp $ */ /*! \file */ diff --git a/libs/libg722_1/src/bitstream.h b/libs/libg722_1/src/bitstream.h index 20e386513f..f2cc4b8bce 100644 --- a/libs/libg722_1/src/bitstream.h +++ b/libs/libg722_1/src/bitstream.h @@ -8,8 +8,6 @@ * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: bitstream.h,v 1.2 2008/10/17 13:18:21 steveu Exp $ */ /*! \file */ diff --git a/libs/libg722_1/src/coef2sam.c b/libs/libg722_1/src/coef2sam.c index 38d4943ca8..19f5a211ac 100644 --- a/libs/libg722_1/src/coef2sam.c +++ b/libs/libg722_1/src/coef2sam.c @@ -6,14 +6,12 @@ * Adapted by Steve Underwood from the reference * code supplied with ITU G.722.1, which is: * - * © 2004 Polycom, Inc. + * (C) 2004 Polycom, Inc. * All rights reserved. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: coef2sam.c,v 1.10 2008/10/02 11:43:54 steveu Exp $ */ /*! \file */ @@ -29,18 +27,16 @@ #include "defs.h" #include "coef2sam.h" +#include "utilities.h" -/************************************************************************************* +/* Convert Reversed MLT (Modulated Lapped Transform) Coefficients to Samples - Purpose: Convert Reversed MLT (Modulated Lapped Transform) Coefficients to Samples - - The "Reversed MLT" is an overlapped block transform which uses even symmetry - on the left, odd symmetry on the right and a Type IV DCT as the block transform. - It is thus similar to a MLT which uses odd symmetry on the left, even symmetry - on the right and a Type IV DST as the block transform. In fact, it is equivalent - to reversing the order of the samples, performing an MLT and then negating all - the even-numbered coefficients. -***************************************************************************/ + The "Reversed MLT" is an overlapped block transform which uses even symmetry + on the left, odd symmetry on the right and a Type IV DCT as the block transform. + It is thus similar to a MLT which uses odd symmetry on the left, even symmetry + on the right and a Type IV DST as the block transform. In fact, it is equivalent + to reversing the order of the samples, performing an MLT and then negating all + the even-numbered coefficients. */ #if defined(G722_1_USE_FIXED_POINT) void rmlt_coefs_to_samples(int16_t coefs[], @@ -73,29 +69,23 @@ void rmlt_coefs_to_samples(int16_t coefs[], new_samples[i] = shl(new_samples[i], mag_shift); } - if (dct_length == DCT_LENGTH) - win = rmlt_to_samples_window; - else - win = max_rmlt_to_samples_window; + win = (dct_length == DCT_LENGTH) ? rmlt_to_samples_window : max_rmlt_to_samples_window; last = half_dct_length - 1; for (i = 0; i < half_dct_length; i++) { /* Get the first half of the windowed samples */ - sum = 0L; - sum = L_mac(sum, win[i], new_samples[last - i]); + sum = L_mult(win[i], new_samples[last - i]); sum = L_mac(sum, win[dct_length - i - 1], old_samples[i]); out_samples[i] = xround(L_shl(sum, 2)); /* Get the second half of the windowed samples */ - sum = 0L; - sum = L_mac(sum, win[half_dct_length + i], new_samples[i]); + sum = L_mult(win[half_dct_length + i], new_samples[i]); sum = L_mac(sum, negate(win[last - i]), old_samples[last - i]); out_samples[half_dct_length + i] = xround(L_shl(sum, 2)); } /* Save the second half of the new samples for next time, when they will be the old samples. */ - for (i = 0; i < half_dct_length; i++) - old_samples[i] = new_samples[half_dct_length + i]; + vec_copyi16(old_samples, &new_samples[half_dct_length], half_dct_length); } /*- End of function --------------------------------------------------------*/ #else @@ -116,10 +106,7 @@ void rmlt_coefs_to_samples(float coefs[], /* Perform a Type IV (inverse) DCT on the coefficients */ dct_type_iv(coefs, new_samples, dct_length); - if (dct_length == DCT_LENGTH) - win = rmlt_to_samples_window; - else - win = max_rmlt_to_samples_window; + win = (dct_length == DCT_LENGTH) ? rmlt_to_samples_window : max_rmlt_to_samples_window; last = half_dct_length - 1; for (i = 0; i < half_dct_length; i++) { @@ -135,8 +122,7 @@ void rmlt_coefs_to_samples(float coefs[], /* Save the second half of the new samples for next time, when they will be the old samples. */ - for (i = 0; i < half_dct_length; i++) - old_samples[i] = new_samples[half_dct_length + i]; + vec_copyf(old_samples, &new_samples[half_dct_length], half_dct_length); } /*- End of function --------------------------------------------------------*/ #endif diff --git a/libs/libg722_1/src/coef2sam.h b/libs/libg722_1/src/coef2sam.h index 731d28ddeb..21590761ea 100644 --- a/libs/libg722_1/src/coef2sam.h +++ b/libs/libg722_1/src/coef2sam.h @@ -6,14 +6,12 @@ * Adapted by Steve Underwood from the reference * code supplied with ITU G.722.1, which is: * - * © 2004 Polycom, Inc. + * (C) 2004 Polycom, Inc. * All rights reserved. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: coef2sam.h,v 1.2 2008/10/02 11:43:54 steveu Exp $ */ #if defined(G722_1_USE_FIXED_POINT) diff --git a/libs/libg722_1/src/common.c b/libs/libg722_1/src/common.c index 46f6595054..b763a8465d 100644 --- a/libs/libg722_1/src/common.c +++ b/libs/libg722_1/src/common.c @@ -6,14 +6,12 @@ * Adapted by Steve Underwood from the reference * code supplied with ITU G.722.1, which is: * - * © 2004 Polycom, Inc. + * (C) 2004 Polycom, Inc. * All rights reserved. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: common.c,v 1.6 2008/09/30 14:06:39 steveu Exp $ */ /*! \file */ @@ -38,41 +36,7 @@ static void compute_raw_pow_categories(int16_t *power_categories, int16_t number_of_regions, int16_t offset); -/**************************************************************************************** - Function: categorize - - Syntax: void categorize(int16_t number_of_available_bits, - int16_t number_of_regions, - int16_t num_categorization_control_possibilities, - int16_t rms_index, - int16_t power_categories, - int16_t category_balances) - - inputs: number_of_regions - num_categorization_control_possibilities - number_of_available_bits - rms_index[MAX_NUMBER_OF_REGIONS] - - outputs: power_categories[MAX_NUMBER_OF_REGIONS] - category_balances[MAX_NUM_CATEGORIZATION_CONTROL_POSSIBILITIES-1] - - Description: Computes a series of categorizations - - WMOPS: 7kHz | 24kbit | 32kbit - -------|--------------|---------------- - AVG | 0.14 | 0.14 - -------|--------------|---------------- - MAX | 0.15 | 0.15 - -------|--------------|---------------- - - 14kHz | 24kbit | 32kbit | 48kbit - -------|--------------|----------------|---------------- - AVG | 0.42 | 0.45 | 0.48 - -------|--------------|----------------|---------------- - MAX | 0.47 | 0.52 | 0.52 - -------|--------------|----------------|---------------- - -****************************************************************************************/ +/* Compute a series of categorizations */ void categorize(int16_t number_of_available_bits, int16_t number_of_regions, int16_t num_categorization_control_possibilities, @@ -88,10 +52,7 @@ void categorize(int16_t number_of_available_bits, /* At higher bit rates, there is an increase for most categories in average bit consumption per region. We compensate for this by pretending we have fewer available bits. */ - if (number_of_regions == NUMBER_OF_REGIONS) - frame_size = DCT_LENGTH; - else - frame_size = MAX_DCT_LENGTH; + frame_size = (number_of_regions == NUMBER_OF_REGIONS) ? DCT_LENGTH : MAX_DCT_LENGTH; temp = sub(number_of_available_bits, frame_size); if (temp > 0) @@ -114,45 +75,7 @@ void categorize(int16_t number_of_available_bits, } /*- End of function --------------------------------------------------------*/ -/*************************************************************************** - Function: comp_powercat_and_catbalance - - Syntax: void comp_powercat_and_catbalance(int16_t *power_categories, - int16_t *category_balances, - int16_t *rms_index, - int16_t number_of_available_bits, - int16_t number_of_regions, - int16_t num_categorization_control_possibilities, - int16_t offset) - - - inputs: *rms_index - number_of_available_bits - number_of_regions - num_categorization_control_possibilities - offset - - outputs: *power_categories - *category_balances - - - Description: Computes the power_categories and the category balances - - WMOPS: 7kHz | 24kbit | 32kbit - -------|--------------|---------------- - AVG | 0.10 | 0.10 - -------|--------------|---------------- - MAX | 0.11 | 0.11 - -------|--------------|---------------- - - 14kHz | 24kbit | 32kbit | 48kbit - -------|--------------|----------------|---------------- - AVG | 0.32 | 0.35 | 0.38 - -------|--------------|----------------|---------------- - MAX | 0.38 | 0.42 | 0.43 - -------|--------------|----------------|---------------- - -***************************************************************************/ +/* Compute the power_categories and the category balances */ void comp_powercat_and_catbalance(int16_t *power_categories, int16_t *category_balances, int16_t *rms_index, @@ -161,7 +84,6 @@ void comp_powercat_and_catbalance(int16_t *power_categories, int16_t num_categorization_control_possibilities, int16_t offset) { - int16_t expected_number_of_code_bits; int16_t region; int16_t max_region; @@ -190,7 +112,6 @@ void comp_powercat_and_catbalance(int16_t *power_categories, for (region = 0; region < number_of_regions; region++) expected_number_of_code_bits = add(expected_number_of_code_bits, expected_bits_table[power_categories[region]]); - for (region = 0; region < number_of_regions; region++) { max_rate_categories[region] = power_categories[region]; @@ -277,42 +198,16 @@ void comp_powercat_and_catbalance(int16_t *power_categories, } /*- End of function --------------------------------------------------------*/ -/*************************************************************************** - Function: calc_offset - - Syntax: offset=calc_offset(int16_t *rms_index,int16_t number_of_regions,int16_t available_bits) - - input: int16_t *rms_index - int16_t number_of_regions - int16_t available_bits - - output: int16_t offset - - Description: Calculates the the category offset. This is the shift required - To get the most out of the number of available bits. A binary - type search is used to find the offset. - - WMOPS: 7kHz | 24kbit | 32kbit - -------|--------------|---------------- - AVG | 0.04 | 0.04 - -------|--------------|---------------- - MAX | 0.04 | 0.04 - -------|--------------|---------------- - - 14kHz | 24kbit | 32kbit | 48kbit - -------|--------------|----------------|---------------- - AVG | 0.08 | 0.08 | 0.08 - -------|--------------|----------------|---------------- - MAX | 0.09 | 0.09 | 0.09 - -------|--------------|----------------|---------------- - -***************************************************************************/ -int16_t calc_offset(int16_t *rms_index,int16_t number_of_regions,int16_t available_bits) +/* Calculate the the category offset. This is the shift required + To get the most out of the number of available bits. A binary + type search is used to find the offset. */ +int16_t calc_offset(int16_t *rms_index, int16_t number_of_regions, int16_t available_bits) { int16_t answer; int16_t delta; int16_t test_offset; - int16_t region,j; + int16_t region; + int16_t j; int16_t power_cats[MAX_NUMBER_OF_REGIONS]; int16_t bits; int16_t offset; @@ -360,40 +255,9 @@ int16_t calc_offset(int16_t *rms_index,int16_t number_of_regions,int16_t availab } /*- End of function --------------------------------------------------------*/ -/*************************************************************************** - Function: compute_raw_pow_categories - - Syntax: void compute_raw_pow_categories(int16_t *power_categories, - int16_t *rms_index, - int16_t number_of_regions, - int16_t offset) - inputs: *rms_index - number_of_regions - offset - - outputs: *power_categories - - - - Description: This function computes the power categories given the offset - This is kind of redundant since they were already computed - in calc_offset to determine the offset. - - WMOPS: | 24kbit | 32kbit - -------|--------------|---------------- - AVG | 0.01 | 0.01 - -------|--------------|---------------- - MAX | 0.01 | 0.01 - -------|--------------|---------------- - - 14kHz | 24kbit | 32kbit | 48kbit - -------|--------------|----------------|---------------- - AVG | 0.01 | 0.01 | 0.01 - -------|--------------|----------------|---------------- - MAX | 0.01 | 0.01 | 0.01 - -------|--------------|----------------|---------------- - -***************************************************************************/ +/* Compute the power categories given the offset + This is kind of redundant since they were already computed + in calc_offset to determine the offset. */ static void compute_raw_pow_categories(int16_t *power_categories, int16_t *rms_index, int16_t number_of_regions, int16_t offset) { int16_t region; diff --git a/libs/libg722_1/src/commonf.c b/libs/libg722_1/src/commonf.c index dd2050aa1b..d86d1cf3ae 100644 --- a/libs/libg722_1/src/commonf.c +++ b/libs/libg722_1/src/commonf.c @@ -6,14 +6,12 @@ * Adapted by Steve Underwood from the reference * code supplied with ITU G.722.1, which is: * - * © 2004 Polycom, Inc. + * (C) 2004 Polycom, Inc. * All rights reserved. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: commonf.c,v 1.11 2008/09/30 14:06:39 steveu Exp $ */ /*! \file */ @@ -34,9 +32,7 @@ #if !defined(G722_1_USE_FIXED_POINT) -/**************************************************************************************** - Description: Computes a series of categorizations -****************************************************************************************/ +/* Compute a series of categorizations */ void categorize(int number_of_regions, int number_of_available_bits, int rms_index[MAX_NUMBER_OF_REGIONS], diff --git a/libs/libg722_1/src/dct4.c b/libs/libg722_1/src/dct4.c index cb3a7fde03..9f0a61d6f6 100644 --- a/libs/libg722_1/src/dct4.c +++ b/libs/libg722_1/src/dct4.c @@ -6,14 +6,12 @@ * Adapted by Steve Underwood from the reference * code supplied with ITU G.722.1, which is: * - * © 2004 Polycom, Inc. + * (C)2004 Polycom, Inc. * All rights reserved. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: dct4.c,v 1.8 2008/09/29 16:09:26 steveu Exp $ */ #if defined(HAVE_CONFIG_H) @@ -29,6 +27,7 @@ #include "g722_1/g722_1.h" #include "defs.h" +#include "utilities.h" #if !defined(G722_1_USE_FIXED_POINT) @@ -52,9 +51,7 @@ static const cos_msin_t *cos_msin_table[] = cos_msin_640 }; -/********************************************************************************* - Description: Discrete Cosine Transform, Type IV -*********************************************************************************/ +/* Discrete Cosine Transform, Type IV */ void dct_type_iv(float input[], float output[], int dct_length) { float buffer_a[MAX_DCT_LENGTH]; @@ -64,22 +61,20 @@ void dct_type_iv(float input[], float output[], int dct_length) float *in_ptr_low; float *in_ptr_high; float *next_in_base; - float *out_ptr_low; - float *out_ptr_high; + float *out_ptr; float *next_out_base; float *out_buffer; float *in_buffer; float *buffer_swap; float *fptr0; - const float *fptr2; - const float *core_a; float in_val_low; float in_val_high; float cos_even; float cos_odd; float msin_even; float msin_odd; - float sum; + const float *fptr2; + const float *core_a; const cos_msin_t **table_ptr_ptr; const cos_msin_t *cos_msin_ptr; int set_span; @@ -120,29 +115,24 @@ void dct_type_iv(float input[], float output[], int dct_length) for (sets_left = set_count; sets_left > 0; sets_left--) { /* Set up output pointers for the current set */ - out_ptr_low = next_out_base; + out_ptr = next_out_base; next_out_base += set_span; - out_ptr_high = next_out_base; /* Loop over all the butterflies in the current set */ - do + for (i = 0; i < (set_span >> 1); i++) { in_val_low = *in_ptr++; in_val_high = *in_ptr++; - *out_ptr_low++ = in_val_low + in_val_high; - *--out_ptr_high = in_val_low - in_val_high; + out_ptr[i] = in_val_low + in_val_high; + out_ptr[set_span - 1 - i] = in_val_low - in_val_high; } - while (out_ptr_low < out_ptr_high); } /* Decide which buffers to use as input and output next time. Except for the first time (when the input buffer is the subroutine input) we just alternate the local buffers. */ in_buffer = out_buffer; - if (out_buffer == buffer_a) - out_buffer = buffer_b; - else - out_buffer = buffer_a; + out_buffer = (out_buffer == buffer_a) ? buffer_b : buffer_a; } /* Do dct_size/10 ten-point transforms */ @@ -153,11 +143,8 @@ void dct_type_iv(float input[], float output[], int dct_length) fptr2 = core_a; for (k = 0; k < CORE_SIZE; k++) { - sum = 0; - for (i = 0; i < CORE_SIZE; i++) - sum += fptr0[i]*fptr2[i]; + buffer_swap[k] = vec_dot_prodf(fptr0, fptr2, CORE_SIZE); fptr2 += CORE_SIZE; - buffer_swap[k] = sum; } fptr0 += CORE_SIZE; buffer_swap += CORE_SIZE; @@ -172,14 +159,10 @@ void dct_type_iv(float input[], float output[], int dct_length) { /* Initialization for the loop over sets at the current size */ set_span = dct_length >> set_count_log; - set_count = 1 << set_count_log; next_in_base = in_buffer; - if (set_count_log == 0) - next_out_base = output; - else - next_out_base = out_buffer; - ++table_ptr_ptr; + next_out_base = (set_count_log == 0) ? output : out_buffer; + table_ptr_ptr++; /* Loop over all the sets of this size */ for (sets_left = set_count; sets_left > 0; sets_left--) @@ -187,26 +170,23 @@ void dct_type_iv(float input[], float output[], int dct_length) /* Set up the pointers for the current set */ in_ptr_low = next_in_base; in_ptr_high = in_ptr_low + (set_span >> 1); - next_in_base += set_span; - out_ptr_low = next_out_base; - next_out_base += set_span; - out_ptr_high = next_out_base; + out_ptr = next_out_base; cos_msin_ptr = *table_ptr_ptr; /* Loop over all the butterfly pairs in the current set */ - do + for (i = 0; i < (set_span >> 1); i += 2) { - cos_even = (*cos_msin_ptr).cosine; - msin_even = (*cos_msin_ptr++).minus_sine; - *out_ptr_low++ = cos_even * *in_ptr_low - msin_even * *in_ptr_high; - *--out_ptr_high = msin_even * *in_ptr_low++ + cos_even * *in_ptr_high++; - - cos_odd = (*cos_msin_ptr).cosine; - msin_odd = (*cos_msin_ptr++).minus_sine; - *out_ptr_low++ = cos_odd * *in_ptr_low + msin_odd * *in_ptr_high; - *--out_ptr_high = msin_odd * *in_ptr_low++ - cos_odd * *in_ptr_high++; + cos_even = cos_msin_ptr[i].cosine; + msin_even = cos_msin_ptr[i].minus_sine; + cos_odd = cos_msin_ptr[i + 1].cosine; + msin_odd = cos_msin_ptr[i + 1].minus_sine; + out_ptr[i] = cos_even*in_ptr_low[i] - msin_even*in_ptr_high[i]; + out_ptr[set_span - 1 - i] = msin_even*in_ptr_low[i] + cos_even*in_ptr_high[i]; + out_ptr[i + 1] = cos_odd*in_ptr_low[i + 1] + msin_odd*in_ptr_high[i + 1]; + out_ptr[set_span - 2 - i] = msin_odd*in_ptr_low[i + 1] - cos_odd*in_ptr_high[i + 1]; } - while (out_ptr_low < out_ptr_high); + next_in_base += set_span; + next_out_base += set_span; } /* Swap input and output buffers for next time */ diff --git a/libs/libg722_1/src/dct4_a.c b/libs/libg722_1/src/dct4_a.c index 0f9c90eba0..d4ed1504e1 100644 --- a/libs/libg722_1/src/dct4_a.c +++ b/libs/libg722_1/src/dct4_a.c @@ -6,29 +6,23 @@ * Adapted by Steve Underwood from the reference * code supplied with ITU G.722.1, which is: * - * © 2004 Polycom, Inc. + * (C) 2004 Polycom, Inc. * All rights reserved. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: dct4_a.c,v 1.8 2008/09/30 14:06:39 steveu Exp $ */ -/********************************************************************************* -* Filename: dct_type_iv_a.c -* -* Purpose: Discrete Cosine Transform, Type IV used for MLT -* -* The basis functions are -* -* cos(PI*(t+0.5)*(k+0.5)/block_length) -* -* for time t and basis function number k. Due to the symmetry of the expression -* in t and k, it is clear that the forward and inverse transforms are the same. -* -*********************************************************************************/ +/* Discrete Cosine Transform, Type IV used for MLT + + The basis functions are + + cos(PI*(t+0.5)*(k+0.5)/block_length) + + for time t and basis function number k. Due to the symmetry of the + expression in t and k, it is clear that the forward and inverse transforms + are the same. */ /*! \file */ @@ -47,51 +41,31 @@ #include "dct4_a.h" -/********************************************************************************* - Function: dct_type_iv_a - - Syntax: void dct_type_iv_a (input, output, dct_length) - int16_t input[], output[], dct_length; - - Description: Discrete Cosine Transform, Type IV used for MLT -*********************************************************************************/ - +/* Discrete Cosine Transform, Type IV used for MLT */ void dct_type_iv_a(int16_t input[], int16_t output[], int dct_length) { int16_t buffer_a[MAX_DCT_LENGTH]; int16_t buffer_b[MAX_DCT_LENGTH]; int16_t buffer_c[MAX_DCT_LENGTH]; int16_t *in_ptr; - int16_t *in_ptr_low; - int16_t *in_ptr_high; - int16_t *next_in_base; - int16_t *out_ptr_low; - int16_t *out_ptr_high; - int16_t *next_out_base; - int16_t *out_buffer; + int16_t *out_ptr; int16_t *in_buffer; + int16_t *out_buffer; int16_t *buffer_swap; int16_t in_val_low; int16_t in_val_high; - int16_t out_val_low; - int16_t out_val_high; int16_t in_low_even; int16_t in_low_odd; int16_t in_high_even; int16_t in_high_odd; - int16_t out_low_even; - int16_t out_low_odd; - int16_t out_high_even; - int16_t out_high_odd; int16_t *pair_ptr; int16_t cos_even; int16_t cos_odd; int16_t msin_even; int16_t msin_odd; - int16_t neg_cos_odd; - int16_t neg_msin_even; int32_t sum; int16_t set_span; + int16_t half_span; int16_t set_count; int16_t set_count_log; int16_t pairs_left; @@ -99,15 +73,15 @@ void dct_type_iv_a(int16_t input[], int16_t output[], int dct_length) int16_t i; int16_t k; int16_t index; - const cos_msin_t **table_ptr_ptr; - const cos_msin_t *cos_msin_ptr; int16_t temp; int32_t acca; int16_t dct_length_log; + const cos_msin_t **table_ptr_ptr; + const cos_msin_t *cos_msin_ptr; - /* Do the sum/difference butterflies, the first part of */ - /* converting one N-point transform into N/2 two-point */ - /* transforms, where N = 1 << DCT_LENGTH_LOG. = 64/128 */ + /* Do the sum/difference butterflies, the first part of + converting one N-point transform into N/2 two-point + transforms, where N = 1 << DCT_LENGTH_LOG. = 64/128 */ if (dct_length == DCT_LENGTH) { dct_length_log = DCT_LENGTH_LOG; @@ -123,62 +97,45 @@ void dct_type_iv_a(int16_t input[], int16_t output[], int dct_length) index = 0L; in_buffer = input; out_buffer = buffer_a; - temp = sub(dct_length_log, 2); + temp = dct_length_log - 2; for (set_count_log = 0; set_count_log <= temp; set_count_log++) { - /* Initialization for the loop over sets at the current size */ - /* set_span = 1 << (DCT_LENGTH_LOG - set_count_log); */ - set_span = shr(dct_length, set_count_log); - - set_count = shl(1, set_count_log); + /* Loop over all the sets at the current size */ + set_span = dct_length >> set_count_log; + set_count = 1 << set_count_log; + half_span = set_span >> 1; in_ptr = in_buffer; - next_out_base = out_buffer; + out_ptr = out_buffer; - /* Loop over all the sets of this size */ for (sets_left = set_count; sets_left > 0; sets_left--) { - /* Set up output pointers for the current set */ - out_ptr_low = next_out_base; - next_out_base = next_out_base + set_span; - out_ptr_high = next_out_base; - /* Loop over all the butterflies in the current set */ - do + for (i = 0; i < half_span; i++) { - in_val_low = *in_ptr++; - in_val_high = *in_ptr++; - acca = L_add(in_val_low, in_val_high); - acca = L_shr(acca, 1); - out_val_low = (int16_t) acca; + in_val_low = *in_ptr++; + in_val_high = *in_ptr++; - acca = L_sub(in_val_low, in_val_high); - acca = L_shr(acca, 1); - out_val_high = (int16_t) acca; + acca = L_add(in_val_low, in_val_high); + out_ptr[i] = (int16_t) L_shr(acca, 1); - *out_ptr_low++ = out_val_low; - *--out_ptr_high = out_val_high; + acca = L_sub(in_val_low, in_val_high); + out_ptr[set_span - 1 - i] = (int16_t) L_shr(acca, 1); } - while (out_ptr_low < out_ptr_high); + out_ptr += set_span; } - /* Decide which buffers to use as input and output next time. */ - /* Except for the first time (when the input buffer is the */ - /* subroutine input) we just alternate the local buffers. */ + /* Decide which buffers to use as input and output next time. + Except for the first time (when the input buffer is the + subroutine input) we just alternate the local buffers. */ in_buffer = out_buffer; - if (out_buffer == buffer_a) - out_buffer = buffer_b; - else - out_buffer = buffer_a; + out_buffer = (out_buffer == buffer_a) ? buffer_b : buffer_a; index = add(index, 1); } - /* Do N/2 two-point transforms, */ - /* where N = 1 << DCT_LENGTH_LOG */ + /* Do N/2 two-point transforms, where N = 1 << DCT_LENGTH_LOG */ pair_ptr = in_buffer; buffer_swap = buffer_c; - temp = sub(dct_length_log, 1); - temp = shl(1, temp); - + temp = 1 << (dct_length_log - 1); for (pairs_left = temp; pairs_left > 0; pairs_left--) { for (k = 0; k < CORE_SIZE; k++) @@ -188,7 +145,6 @@ void dct_type_iv_a(int16_t input[], int16_t output[], int dct_length) sum = L_mac(sum, pair_ptr[i], dct_core_a[i][k]); buffer_swap[k] = xround(sum); } - /* Address arithmetic */ pair_ptr += CORE_SIZE; buffer_swap += CORE_SIZE; } @@ -202,77 +158,53 @@ void dct_type_iv_a(int16_t input[], int16_t output[], int dct_length) temp = sub(dct_length_log, 2); for (set_count_log = temp; set_count_log >= 0; set_count_log--) { - /* Initialization for the loop over sets at the current size */ - /* set_span = 1 << (DCT_LENGTH_LOG - set_count_log); */ - set_span = shr(dct_length, set_count_log); - set_count = shl(1, set_count_log); - next_in_base = in_buffer; - next_out_base = (set_count_log == 0) ? output : out_buffer; + /* Loop over all the sets at the current size */ + set_span = dct_length >> set_count_log; + set_count = 1 << set_count_log; + half_span = set_span >> 1; + in_ptr = in_buffer; + out_ptr = (set_count_log == 0) ? output : out_buffer; + cos_msin_ptr = *table_ptr_ptr++; - /* Loop over all the sets of this size */ for (sets_left = set_count; sets_left > 0; sets_left--) { - /* Set up the pointers for the current set */ - in_ptr_low = next_in_base; - temp = shr(set_span, 1); - - /* Address arithmetic */ - in_ptr_high = in_ptr_low + temp; - next_in_base += set_span; - out_ptr_low = next_out_base; - next_out_base += set_span; - out_ptr_high = next_out_base; - cos_msin_ptr = *table_ptr_ptr; - /* Loop over all the butterfly pairs in the current set */ - do + for (i = 0; i < half_span; i += 2) { - /* Address arithmetic */ - in_low_even = *in_ptr_low++; - in_low_odd = *in_ptr_low++; - in_high_even = *in_ptr_high++; - in_high_odd = *in_ptr_high++; - cos_even = cos_msin_ptr[0].cosine; - msin_even = cos_msin_ptr[0].minus_sine; - cos_odd = cos_msin_ptr[1].cosine; - msin_odd = cos_msin_ptr[1].minus_sine; - cos_msin_ptr += 2; + in_low_even = in_ptr[i]; + in_low_odd = in_ptr[i + 1]; + in_high_even = in_ptr[half_span + i]; + in_high_odd = in_ptr[half_span + i + 1]; - sum = 0L; - sum = L_mac(sum, cos_even, in_low_even); - neg_msin_even = negate(msin_even); - sum = L_mac(sum, neg_msin_even, in_high_even); - out_low_even = xround(sum); + cos_even = cos_msin_ptr[i].cosine; + msin_even = cos_msin_ptr[i].minus_sine; + cos_odd = cos_msin_ptr[i + 1].cosine; + msin_odd = cos_msin_ptr[i + 1].minus_sine; - sum = 0L; - sum = L_mac(sum, msin_even,in_low_even); + sum = L_mult(cos_even, in_low_even); + sum = L_mac(sum, -msin_even, in_high_even); + out_ptr[i] = xround(sum); + + sum = L_mult(msin_even,in_low_even); sum = L_mac(sum, cos_even, in_high_even); - out_high_even = xround(sum); + out_ptr[set_span - 1 - i] = xround(sum); - sum = 0L; - sum = L_mac(sum, cos_odd, in_low_odd); + sum = L_mult(cos_odd, in_low_odd); sum = L_mac(sum, msin_odd, in_high_odd); - out_low_odd = xround(sum); + out_ptr[i + 1] = xround(sum); - sum = 0L; - sum = L_mac(sum, msin_odd, in_low_odd); - neg_cos_odd = negate(cos_odd); - sum = L_mac(sum, neg_cos_odd, in_high_odd); - out_high_odd = xround(sum); - - *out_ptr_low++ = out_low_even; - *--out_ptr_high = out_high_even; - *out_ptr_low++ = out_low_odd; - *--out_ptr_high = out_high_odd; + sum = L_mult(msin_odd, in_low_odd); + sum = L_mac(sum, -cos_odd, in_high_odd); + out_ptr[set_span - 2 - i] = xround(sum); } - while (out_ptr_low < out_ptr_high); + in_ptr += set_span; + out_ptr += set_span; } /* Swap input and output buffers for next time */ buffer_swap = in_buffer; in_buffer = out_buffer; out_buffer = buffer_swap; - table_ptr_ptr++; } } /*- End of function --------------------------------------------------------*/ diff --git a/libs/libg722_1/src/dct4_a.h b/libs/libg722_1/src/dct4_a.h index bcc63bf29d..4d4b95c68e 100644 --- a/libs/libg722_1/src/dct4_a.h +++ b/libs/libg722_1/src/dct4_a.h @@ -6,14 +6,12 @@ * Adapted by Steve Underwood from the reference * code supplied with ITU G.722.1, which is: * - * © 2004 Polycom, Inc. + * (C) 2004 Polycom, Inc. * All rights reserved. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: dct4_a.h,v 1.4 2008/09/25 15:56:31 steveu Exp $ */ typedef struct diff --git a/libs/libg722_1/src/dct4_s.c b/libs/libg722_1/src/dct4_s.c index 71151b3f14..c195693cef 100644 --- a/libs/libg722_1/src/dct4_s.c +++ b/libs/libg722_1/src/dct4_s.c @@ -6,29 +6,23 @@ * Adapted by Steve Underwood from the reference * code supplied with ITU G.722.1, which is: * - * © 2004 Polycom, Inc. + * (C) 2004 Polycom, Inc. * All rights reserved. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: dct4_s.c,v 1.8 2008/09/30 14:06:39 steveu Exp $ */ -/******************************************************************************** -* Filename: dct_type_iv_s.c -* -* Purpose: Discrete Cosine Transform, Type IV used for inverse MLT -* -* The basis functions are -* -* cos(PI*(t+0.5)*(k+0.5)/block_length) -* -* for time t and basis function number k. Due to the symmetry of the expression -* in t and k, it is clear that the forward and inverse transforms are the same. -* -*********************************************************************************/ +/* Discrete Cosine Transform, Type IV used for inverse MLT + + The basis functions are + + cos(PI*(t+0.5)*(k+0.5)/block_length) + + for time t and basis function number k. Due to the symmetry of the + expression in t and k, it is clear that the forward and inverse transforms + are the same. */ /*! \file */ @@ -45,67 +39,51 @@ #if defined(G722_1_USE_FIXED_POINT) #include "dct4_s.h" +#include "utilities.h" -/******************************************************************************** - Function: dct_type_iv_s - - Syntax: void dct_type_iv_s (int16_t *input,int16_t *output,int16_t dct_length) - - - Description: Discrete Cosine Transform, Type IV used for inverse MLT -********************************************************************************/ +/* Discrete Cosine Transform, Type IV used for inverse MLT */ void dct_type_iv_s(int16_t input[], int16_t output[], int dct_length) { int16_t buffer_a[MAX_DCT_LENGTH]; int16_t buffer_b[MAX_DCT_LENGTH]; int16_t buffer_c[MAX_DCT_LENGTH]; int16_t *in_ptr; - int16_t *in_ptr_low; - int16_t *in_ptr_high; - int16_t *next_in_base; - int16_t *out_ptr_low; - int16_t *out_ptr_high; - int16_t *next_out_base; - int16_t *out_buffer; + int16_t *out_ptr; int16_t *in_buffer; + int16_t *out_buffer; int16_t *buffer_swap; int16_t in_val_low; int16_t in_val_high; - int16_t out_val_low; - int16_t out_val_high; int16_t in_low_even; int16_t in_low_odd; int16_t in_high_even; int16_t in_high_odd; - int16_t out_low_even; - int16_t out_low_odd; - int16_t out_high_even; - int16_t out_high_odd; int16_t *pair_ptr; int16_t cos_even; int16_t cos_odd; int16_t msin_even; int16_t msin_odd; int16_t set_span; + int16_t half_span; int16_t set_count; int16_t set_count_log; int16_t pairs_left; int16_t sets_left; int16_t i; + int16_t j; int16_t k; int16_t index; int16_t dummy; + int16_t dct_length_log; int32_t sum; + int32_t acca; const cos_msin_t **table_ptr_ptr; const cos_msin_t *cos_msin_ptr; - int32_t acca; - int16_t temp; - int16_t dct_length_log; const int16_t *dither_ptr; - /* Do the sum/difference butterflies, the first part of */ - /* converting one N-point transform into 32 - 10 point transforms */ - /* transforms, where N = 1 << DCT_LENGTH_LOG. */ + /* Do the sum/difference butterflies, the first part of + converting one N-point transform into 32 - 10 point transforms + transforms, where N = 1 << DCT_LENGTH_LOG. */ if (dct_length == DCT_LENGTH) { dct_length_log = DCT_LENGTH_LOG; @@ -122,92 +100,61 @@ void dct_type_iv_s(int16_t input[], int16_t output[], int dct_length) index = 0; i = 0; + j = 0; for (set_count_log = 0; set_count_log <= dct_length_log - 2; set_count_log++) { - /* Initialization for the loop over sets at the current size */ - /* set_span = 1 << (DCT_LENGTH_LOG - set_count_log); */ - set_span = shr(dct_length, set_count_log); - - set_count = shl(1, set_count_log); + /* Loop over all the sets at the current size */ + set_span = dct_length >> set_count_log; + set_count = 1 << set_count_log; + half_span = set_span >> 1; in_ptr = in_buffer; - next_out_base = out_buffer; + out_ptr = out_buffer; - /* Loop over all the sets of this size */ - temp = sub(index, 1); - if (temp < 0) + if (index < 1) { for (sets_left = set_count; sets_left > 0; sets_left--) { - /* Set up output pointers for the current set */ - /* pointer arithmetic */ - out_ptr_low = next_out_base; - next_out_base += set_span; - out_ptr_high = next_out_base; - /* Loop over all the butterflies in the current set */ - do + for (i = 0; i < half_span; i++) { in_val_low = *in_ptr++; in_val_high = *in_ptr++; - /* BEST METHOD OF GETTING RID OF BIAS, BUT COMPUTATIONALLY UNPLEASANT */ - /* ALTERNATIVE METHOD, SMEARS BIAS OVER THE ENTIRE FRAME, COMPUTATIONALLY SIMPLEST. */ - /* IF THIS WORKS, IT'S PREFERABLE */ - - dummy = add(in_val_low, dither_ptr[i++]); + dummy = add(in_val_low, dither_ptr[j++]); acca = L_add(dummy, in_val_high); - out_val_low = (int16_t) L_shr(acca, 1); + out_ptr[i] = (int16_t) L_shr(acca, 1); - dummy = add(in_val_low, dither_ptr[i++]); - acca = L_add(dummy, -in_val_high); - out_val_high = (int16_t) L_shr(acca, 1); - - *out_ptr_low++ = out_val_low; - *--out_ptr_high = out_val_high; - - /* this involves comparison of pointers */ - /* pointer arithmetic */ + dummy = add(in_val_low, dither_ptr[j++]); + acca = L_sub(dummy, in_val_high); + out_ptr[set_span - 1 - i] = (int16_t) L_shr(acca, 1); } - while (out_ptr_low < out_ptr_high); + out_ptr += set_span; } } else { for (sets_left = set_count; sets_left > 0; sets_left--) { - /* Set up output pointers for the current set */ - out_ptr_low = next_out_base; - next_out_base += set_span; - out_ptr_high = next_out_base; - /* Loop over all the butterflies in the current set */ - do + for (i = 0; i < half_span; i++) { in_val_low = *in_ptr++; in_val_high = *in_ptr++; - out_val_low = add(in_val_low, in_val_high); - out_val_high = add(in_val_low, negate(in_val_high)); - - *out_ptr_low++ = out_val_low; - *--out_ptr_high = out_val_high; + out_ptr[i] = add(in_val_low, in_val_high); + out_ptr[set_span - 1 - i] = sub(in_val_low, in_val_high); } - while (out_ptr_low < out_ptr_high); + out_ptr += set_span; } } - /* Decide which buffers to use as input and output next time. */ - /* Except for the first time (when the input buffer is the */ - /* subroutine input) we just alternate the local buffers. */ + /* Decide which buffers to use as input and output next time. + Except for the first time (when the input buffer is the + subroutine input) we just alternate the local buffers. */ in_buffer = out_buffer; - - if (out_buffer == buffer_a) - out_buffer = buffer_b; - else - out_buffer = buffer_a; - - index = add(index, 1); + out_buffer = (out_buffer == buffer_a) ? buffer_b : buffer_a; + index++; } /* Do 32 - 10 point transforms */ @@ -228,8 +175,7 @@ void dct_type_iv_s(int16_t input[], int16_t output[], int dct_length) buffer_swap += CORE_SIZE; } - for (i = 0; i < dct_length; i++) - in_buffer[i] = buffer_c[i]; + vec_copyi16(in_buffer, buffer_c, dct_length); table_ptr_ptr = s_cos_msin_table; @@ -238,90 +184,61 @@ void dct_type_iv_s(int16_t input[], int16_t output[], int dct_length) for (set_count_log = dct_length_log - 2; set_count_log >= 0; set_count_log--) { /* Initialization for the loop over sets at the current size */ - /* set_span = 1 << (DCT_LENGTH_LOG - set_count_log); */ - set_span = shr(dct_length, set_count_log); - - set_count = shl(1, set_count_log); - next_in_base = in_buffer; - if (set_count_log == 0) - next_out_base = output; - else - next_out_base = out_buffer; + set_span = dct_length >> set_count_log; + set_count = 1 << set_count_log; + half_span = set_span >> 1; + in_ptr = in_buffer; + out_ptr = (set_count_log == 0) ? output : out_buffer; + cos_msin_ptr = *table_ptr_ptr++; /* Loop over all the sets of this size */ for (sets_left = set_count; sets_left > 0; sets_left--) { - /* Set up the pointers for the current set */ - in_ptr_low = next_in_base; - temp = shr(set_span, 1); - in_ptr_high = in_ptr_low + temp; - next_in_base += set_span; - out_ptr_low = next_out_base; - next_out_base += set_span; - out_ptr_high = next_out_base; - cos_msin_ptr = *table_ptr_ptr; - /* Loop over all the butterfly pairs in the current set */ - do + for (i = 0; i < half_span; i += 2) { - in_low_even = *in_ptr_low++; - in_low_odd = *in_ptr_low++; - in_high_even = *in_ptr_high++; - in_high_odd = *in_ptr_high++; - cos_even = cos_msin_ptr[0].cosine; - msin_even = cos_msin_ptr[0].minus_sine; - cos_odd = cos_msin_ptr[1].cosine; - msin_odd = cos_msin_ptr[1].minus_sine; - cos_msin_ptr += 2; + in_low_even = in_ptr[i]; + in_low_odd = in_ptr[i + 1]; + in_high_even = in_ptr[half_span + i]; + in_high_odd = in_ptr[half_span + i + 1]; - sum = 0L; - sum = L_mac(sum, cos_even, in_low_even); - sum = L_mac(sum, negate(msin_even), in_high_even); - out_low_even = xround(L_shl(sum, 1)); + cos_even = cos_msin_ptr[i].cosine; + msin_even = cos_msin_ptr[i].minus_sine; + cos_odd = cos_msin_ptr[i + 1].cosine; + msin_odd = cos_msin_ptr[i + 1].minus_sine; - sum = 0L; - sum = L_mac(sum, msin_even, in_low_even); + sum = L_mult(cos_even, in_low_even); + sum = L_mac(sum, -msin_even, in_high_even); + out_ptr[i] = xround(L_shl(sum, 1)); + + sum = L_mult(msin_even, in_low_even); sum = L_mac(sum, cos_even, in_high_even); - out_high_even = xround(L_shl(sum, 1)); + out_ptr[set_span - 1 - i] = xround(L_shl(sum, 1)); - sum = 0L; - sum = L_mac(sum, cos_odd, in_low_odd); + sum = L_mult(cos_odd, in_low_odd); sum = L_mac(sum, msin_odd, in_high_odd); - out_low_odd = xround(L_shl(sum, 1)); + out_ptr[i + 1] = xround(L_shl(sum, 1)); - sum = 0L; - sum = L_mac(sum, msin_odd, in_low_odd); - sum = L_mac(sum, negate(cos_odd), in_high_odd); - out_high_odd = xround(L_shl(sum, 1)); - - *out_ptr_low++ = out_low_even; - *--out_ptr_high = out_high_even; - *out_ptr_low++ = out_low_odd; - *--out_ptr_high = out_high_odd; + sum = L_mult(msin_odd, in_low_odd); + sum = L_mac(sum, -cos_odd, in_high_odd); + out_ptr[set_span - 2 - i] = xround(L_shl(sum, 1)); } - while (out_ptr_low < out_ptr_high); + in_ptr += set_span; + out_ptr += set_span; } /* Swap input and output buffers for next time */ buffer_swap = in_buffer; in_buffer = out_buffer; out_buffer = buffer_swap; - - index = add(index, 1); - table_ptr_ptr++; + index++; } - /* ADD IN BIAS FOR OUTPUT */ + /* Add in bias for output */ if (dct_length == DCT_LENGTH) { - for (i = 0; i < 320; i++) + for (i = 0; i < DCT_LENGTH; i++) { sum = L_add(output[i], syn_bias_7khz[i]); - acca = L_sub(sum, 32767); - if (acca > 0) - sum = 32767L; - acca = L_add(sum, 32768L); - if (acca < 0) - sum = -32768L; - output[i] = (int16_t) sum; + output[i] = saturate(sum); } } } diff --git a/libs/libg722_1/src/dct4_s.h b/libs/libg722_1/src/dct4_s.h index 68040d0659..533be1c7b9 100644 --- a/libs/libg722_1/src/dct4_s.h +++ b/libs/libg722_1/src/dct4_s.h @@ -6,14 +6,12 @@ * Adapted by Steve Underwood from the reference * code supplied with ITU G.722.1, which is: * - * © 2004 Polycom, Inc. + * (C) 2004 Polycom, Inc. * All rights reserved. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: dct4_s.h,v 1.4 2008/09/25 15:56:31 steveu Exp $ */ typedef struct @@ -196,11 +194,9 @@ static const int16_t max_dither[MAX_DCT_LENGTH] = for (index = 0;index < length;index++) { angle = scale * ((double)index + 0.5); - table[index].cosine = (short) (FTOI((18427)* cos(angle))); - table[index].minus_sine = (short) (FTOI((18427)*(-sin(angle)))); + table[index].cosine = (int16_t) (FTOI((18427)* cos(angle))); + table[index].minus_sine = (int16_t) (FTOI((18427)*(-sin(angle)))); } - - ********************************************************************************/ static const cos_msin_t s_cos_msin_2[DCT_LENGTH_DIV_32] = diff --git a/libs/libg722_1/src/decoder.c b/libs/libg722_1/src/decoder.c index 80fcab4d5a..f1db32f282 100644 --- a/libs/libg722_1/src/decoder.c +++ b/libs/libg722_1/src/decoder.c @@ -6,14 +6,12 @@ * Adapted by Steve Underwood from the reference * code supplied with ITU G.722.1, which is: * - * © 2004 Polycom, Inc. + * (C)2004 Polycom, Inc. * All rights reserved. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: decoder.c,v 1.21 2008/11/21 15:30:22 steveu Exp $ */ /*! \file */ @@ -94,9 +92,7 @@ static void decoder(g722_1_decode_state_t *s, int16_t old_decoder_mlt_coefs[], int frame_error_flag); -/*************************************************************************** - Description: Decodes the out_words into mlt coefs using G.722.1 Annex C -***************************************************************************/ +/* Decodes the out_words into MLT coefs using G.722.1 Annex C */ void decoder(g722_1_decode_state_t *s, int16_t number_of_regions, int16_t decoder_mlt_coefs[], @@ -109,11 +105,11 @@ void decoder(g722_1_decode_state_t *s, int16_t absolute_region_power_index[MAX_NUMBER_OF_REGIONS]; int16_t decoder_power_categories[MAX_NUMBER_OF_REGIONS]; int16_t decoder_category_balances[MAX_NUM_CATEGORIZATION_CONTROL_POSSIBILITIES - 1]; - uint16_t categorization_control; int16_t num_categorization_control_bits; int16_t num_categorization_control_possibilities; int16_t number_of_coefs; int16_t number_of_valid_coefs; + uint16_t categorization_control; number_of_valid_coefs = number_of_regions*REGION_SIZE; @@ -184,9 +180,7 @@ void decoder(g722_1_decode_state_t *s, } /*- End of function --------------------------------------------------------*/ -/*************************************************************************** - Description: Recover differential_region_power_index from code bits -***************************************************************************/ +/* Recover differential_region_power_index from code bits */ static void decode_envelope(g722_1_decode_state_t *s, int16_t number_of_regions, int16_t *decoder_region_standard_deviation, @@ -262,7 +256,7 @@ static void decode_envelope(g722_1_decode_state_t *s, while ((i >= 0) && ((temp1 >= 0) || (temp2 > 0))) { i = sub(i, 1); - temp = shr(temp, 1); + temp >>= 1; max_index = sub(max_index, 2); temp1 = sub(temp, 8); temp2 = sub(max_index, 28); @@ -365,12 +359,12 @@ static void decode_vector_quantized_mlt_indices(g722_1_decode_state_t *s, if (g722_1_bitstream_get(&s->bitstream, &(s->code_ptr), 1) == 0) { temp = shl(index, 1); - index = (int16_t) *(decoder_table_ptr + temp); + index = decoder_table_ptr[temp]; } else { temp = shl(index, 1); - index = (int16_t) *(decoder_table_ptr + temp + 1); + index = decoder_table_ptr[temp + 1]; } s->number_of_bits_left--; } @@ -406,7 +400,7 @@ static void decode_vector_quantized_mlt_indices(g722_1_decode_state_t *s, { if ((signs_index & bit) == 0) decoder_mlt_value = negate(decoder_mlt_value); - bit = shr(bit, 1); + bit >>= 1; } *decoder_mlt_ptr++ = decoder_mlt_value; } @@ -440,7 +434,7 @@ static void decode_vector_quantized_mlt_indices(g722_1_decode_state_t *s, if (*decoder_mlt_ptr == 0) { *decoder_mlt_ptr = ((random_word & 1) == 0) ? noifillneg : noifillpos; - random_word = shr(random_word, 1); + random_word >>= 1; } /* pointer arithmetic */ decoder_mlt_ptr++; @@ -451,7 +445,7 @@ static void decode_vector_quantized_mlt_indices(g722_1_decode_state_t *s, if (*decoder_mlt_ptr == 0) { *decoder_mlt_ptr = ((random_word & 1) == 0) ? noifillneg : noifillpos; - random_word = shr(random_word,1); + random_word >>= 1; } /* pointer arithmetic */ decoder_mlt_ptr++; diff --git a/libs/libg722_1/src/decoderf.c b/libs/libg722_1/src/decoderf.c index 761a0cff30..e0e8e61743 100644 --- a/libs/libg722_1/src/decoderf.c +++ b/libs/libg722_1/src/decoderf.c @@ -6,14 +6,12 @@ * Adapted by Steve Underwood from the reference * code supplied with ITU G.722.1, which is: * - * © 2004 Polycom, Inc. + * (C) 2004 Polycom, Inc. * All rights reserved. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: decoderf.c,v 1.22 2008/11/21 15:30:22 steveu Exp $ */ /*! \file */ @@ -33,6 +31,7 @@ #include "huff_tab.h" #include "tables.h" #include "bitstream.h" +#include "utilities.h" #if !defined(G722_1_USE_FIXED_POINT) @@ -84,12 +83,12 @@ static void decoder(g722_1_decode_state_t *s, int absolute_region_power_index[MAX_NUMBER_OF_REGIONS]; int decoder_power_categories[MAX_NUMBER_OF_REGIONS]; int decoder_category_balances[MAX_NUM_CATEGORIZATION_CONTROL_POSSIBILITIES - 1]; - int rate_control; int num_categorization_control_bits; int num_categorization_control_possibilities; int number_of_coefs; int number_of_valid_coefs; int rmlt_scale_factor; + int rate_control; number_of_valid_coefs = s->number_of_regions*REGION_SIZE; @@ -451,7 +450,7 @@ static void decode_vector_quantized_mlt_indices(g722_1_decode_state_t *s, if (category == NUM_CATEGORIES - 1) { - noifillpos = standard_deviation*0.70711f; + noifillpos = standard_deviation*0.70711; noifillneg = -noifillpos; /* This assumes region_size = 20 */ @@ -555,27 +554,21 @@ static void error_handling(int number_of_coefs, float *decoder_mlt_coefs, float *old_decoder_mlt_coefs) { - int i; - /* If both the current and previous frames are errored, set the mlt coefficients to 0. If only the current frame is errored, repeat the previous frame's MLT coefficients. */ if (*frame_error_flag) { - for (i = 0; i < number_of_valid_coefs; i++) - decoder_mlt_coefs[i] = old_decoder_mlt_coefs[i]; - for (i = 0; i < number_of_valid_coefs; i++) - old_decoder_mlt_coefs[i] = 0.0f; + vec_copyf(decoder_mlt_coefs, old_decoder_mlt_coefs, number_of_valid_coefs); + vec_zerof(old_decoder_mlt_coefs, number_of_valid_coefs); } else { /* Store in case the next frame has errors. */ - for (i = 0; i < number_of_valid_coefs; i++) - old_decoder_mlt_coefs[i] = decoder_mlt_coefs[i]; + vec_copyf(old_decoder_mlt_coefs, decoder_mlt_coefs, number_of_valid_coefs); } /* Zero out the upper 1/8 of the spectrum. */ - for (i = number_of_valid_coefs; i < number_of_coefs; i++) - decoder_mlt_coefs[i] = 0.0f; + vec_zerof(&decoder_mlt_coefs[number_of_valid_coefs], number_of_coefs - number_of_valid_coefs); } /*- End of function --------------------------------------------------------*/ diff --git a/libs/libg722_1/src/defs.h b/libs/libg722_1/src/defs.h index 7a565d0565..9c2c83dd10 100644 --- a/libs/libg722_1/src/defs.h +++ b/libs/libg722_1/src/defs.h @@ -6,14 +6,12 @@ * Adapted by Steve Underwood from the reference * code supplied with ITU G.722.1, which is: * - * © 2004 Polycom, Inc. + * (C) 2004 Polycom, Inc. * All rights reserved. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: defs.h,v 1.16 2008/10/01 15:31:10 steveu Exp $ */ #define MAX(a,b) (a > b ? a : b) diff --git a/libs/libg722_1/src/encoder.c b/libs/libg722_1/src/encoder.c index fef4b44883..054d6b36bd 100644 --- a/libs/libg722_1/src/encoder.c +++ b/libs/libg722_1/src/encoder.c @@ -6,14 +6,12 @@ * Adapted by Steve Underwood from the reference * code supplied with ITU G.722.1, which is: * - * © 2004 Polycom, Inc. + * (C) 2004 Polycom, Inc. * All rights reserved. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: encoder.c,v 1.26 2008/11/21 15:30:22 steveu Exp $ */ /*! \file */ @@ -32,6 +30,7 @@ #include "huff_tab.h" #include "tables.h" #include "bitstream.h" +#include "utilities.h" #if defined(G722_1_USE_FIXED_POINT) @@ -99,9 +98,8 @@ static void bits_to_words(g722_1_encode_state_t *s, drp_num_bits[number_of_regions] = num_categorization_control_bits; drp_code_bits[number_of_regions] = categorization_control; - bit_count = 0; /* These code bits are right justified. */ - for (region = 0; region <= number_of_regions; region++) + for (bit_count = 0, region = 0; region <= number_of_regions; region++) { g722_1_bitstream_put(&s->bitstream, &out_code, drp_code_bits[region], drp_num_bits[region]); bit_count += drp_num_bits[region]; @@ -247,14 +245,11 @@ void adjust_abs_region_power_index(int16_t *absolute_region_power_index, for (region = 0; region < number_of_regions; region++) { - n = sub(absolute_region_power_index[region], 39); - n = shr(n, 1); + n = sub(absolute_region_power_index[region], 39) >> 1; if (n > 0) { temp = (int16_t) L_mult0(region, REGION_SIZE); - raw_mlt_ptr = &mlt_coefs[temp]; - for (i = 0; i < REGION_SIZE; i++) { acca = L_shl(*raw_mlt_ptr, 16); @@ -264,8 +259,7 @@ void adjust_abs_region_power_index(int16_t *absolute_region_power_index, *raw_mlt_ptr++ = (int16_t) acca; } - temp = sub(absolute_region_power_index[region], shl(n, 1)); - absolute_region_power_index[region] = temp; + absolute_region_power_index[region] = sub(absolute_region_power_index[region], shl(n, 1)); } } } @@ -281,7 +275,6 @@ static int16_t compute_region_powers(int16_t *mlt_coefs, { int16_t *input_ptr; int32_t long_accumulator; - int16_t itemp1; int16_t power_shift; int16_t region; int16_t j; @@ -295,12 +288,8 @@ static int16_t compute_region_powers(int16_t *mlt_coefs, input_ptr = mlt_coefs; for (region = 0; region < number_of_regions; region++) { - long_accumulator = 0; - for (j = 0; j < REGION_SIZE; j++) - { - itemp1 = *input_ptr++; - long_accumulator = L_mac0(long_accumulator, itemp1, itemp1); - } + long_accumulator = vec_dot_prodi16(input_ptr, input_ptr, REGION_SIZE); + input_ptr += REGION_SIZE; power_shift = 0; acca = long_accumulator & 0x7FFF0000L; @@ -348,7 +337,7 @@ static int16_t compute_region_powers(int16_t *mlt_coefs, } /* The MLT is currently scaled too low by the factor - ENCODER_SCALE_FACTOR(=18318)/32768 * (1./sqrt(160). + ENCODER_SCALE_FACTOR(=18318)/32768 * (1.0/sqrt(160). This is the ninth power of 1 over the square root of 2. So later we will add ESF_ADJUSTMENT_TO_RMS_INDEX (now 9) to drp_code_bits[0]. */ @@ -520,7 +509,8 @@ static int16_t vector_huffman(int16_t category, int16_t num_vecs; int16_t kmax; int16_t kmax_plus_one; - int16_t index,signs_index; + int16_t index; + int16_t signs_index; const int16_t *bitcount_table_ptr; const uint16_t *code_table_ptr; int32_t code_bits; diff --git a/libs/libg722_1/src/encoderf.c b/libs/libg722_1/src/encoderf.c index 36a52064f0..2589886aa3 100644 --- a/libs/libg722_1/src/encoderf.c +++ b/libs/libg722_1/src/encoderf.c @@ -6,14 +6,12 @@ * Adapted by Steve Underwood from the reference * code supplied with ITU G.722.1, which is: * - * © 2004 Polycom, Inc. + * (C) 2004 Polycom, Inc. * All rights reserved. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: encoderf.c,v 1.22 2008/11/21 15:30:22 steveu Exp $ */ /*! \file */ @@ -33,6 +31,7 @@ #include "huff_tab.h" #include "tables.h" #include "bitstream.h" +#include "utilities.h" #if !defined(G722_1_USE_FIXED_POINT) @@ -218,7 +217,6 @@ static int compute_region_powers(int number_of_regions, float *input_ptr; int iterations; float ftemp0; - float ftemp1; int index; int index_min; int index_max; @@ -230,13 +228,9 @@ static int compute_region_powers(int number_of_regions, input_ptr = mlt_coefs; for (region = 0; region < number_of_regions; region++) { - ftemp0 = 0.0f; - for (j = 0; j < REGION_SIZE; j++) - { - ftemp1 = *input_ptr++; - ftemp0 += ftemp1*ftemp1; - } + ftemp0 = vec_dot_prodf(input_ptr, input_ptr, REGION_SIZE); ftemp0 *= REGION_SIZE_INVERSE; + input_ptr += REGION_SIZE; index_min = 0; index_max = REGION_POWER_TABLE_SIZE; @@ -260,7 +254,7 @@ static int compute_region_powers(int number_of_regions, } /* The MLT is currently scaled too low by the factor - ENCODER_SCALE_FACTOR(=18318)/32768 * (1./sqrt(160). + ENCODER_SCALE_FACTOR(=18318)/32768 * (1.0/sqrt(160). This is the ninth power of 1 over the square root of 2. So later we will add ESF_ADJUSTMENT_TO_RMS_INDEX (now 9) to drp_code_bits[0]. */ @@ -448,7 +442,7 @@ static int vector_huffman(int category, number_of_non_zero = 0; for (j = 0; j < vec_dim; j++) { - k = (int) (fabs(*raw_mlt_ptr) * inv_of_step_size_times_std_dev + dead_zone[category]); + k = (int) (fabs(*raw_mlt_ptr)*inv_of_step_size_times_std_dev + dead_zone[category]); if (k != 0) { number_of_non_zero++; @@ -458,12 +452,12 @@ static int vector_huffman(int category, if (k > kmax) k = kmax; } - index = index*(kmax_plus_one) + k; + index = index*kmax_plus_one + k; raw_mlt_ptr++; } - code_bits = *(code_table_ptr + index); - number_of_code_bits = *(bitcount_table_ptr + index) + number_of_non_zero; + code_bits = code_table_ptr[index]; + number_of_code_bits = bitcount_table_ptr[index] + number_of_non_zero; number_of_region_bits += number_of_code_bits; code_bits = (code_bits << number_of_non_zero) + signs_index; diff --git a/libs/libg722_1/src/g722_1.h.in b/libs/libg722_1/src/g722_1.h.in index e4a1e415b1..86c0921a65 100644 --- a/libs/libg722_1/src/g722_1.h.in +++ b/libs/libg722_1/src/g722_1.h.in @@ -7,8 +7,6 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * $Id: g722_1.h.in,v 1.1.1.1 2008/09/20 09:47:17 steveu Exp $ */ /*! \file */ diff --git a/libs/libg722_1/src/g722_1/g722_1.h b/libs/libg722_1/src/g722_1/g722_1.h index 3408abbf31..6f2a497eb1 100644 --- a/libs/libg722_1/src/g722_1/g722_1.h +++ b/libs/libg722_1/src/g722_1/g722_1.h @@ -6,14 +6,12 @@ * Adapted by Steve Underwood from the reference * code supplied with ITU G.722.1, which is: * - * © 2004 Polycom, Inc. + * (C) 2004 Polycom, Inc. * All rights reserved. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: g722_1.h,v 1.14 2008/10/17 13:18:21 steveu Exp $ */ #if !defined(_G722_1_G722_1_H_) diff --git a/libs/libg722_1/src/g722_1/version.h.in b/libs/libg722_1/src/g722_1/version.h.in index f9c66d0745..e825425ce9 100644 --- a/libs/libg722_1/src/g722_1/version.h.in +++ b/libs/libg722_1/src/g722_1/version.h.in @@ -9,8 +9,6 @@ * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: version.h.in,v 1.2 2008/09/20 16:52:51 steveu Exp $ */ #if !defined(_G722_1_VERSION_H_) diff --git a/libs/libg722_1/src/huff_tab.c b/libs/libg722_1/src/huff_tab.c index 07f5085b35..3583ba30ff 100644 --- a/libs/libg722_1/src/huff_tab.c +++ b/libs/libg722_1/src/huff_tab.c @@ -6,14 +6,12 @@ * Adapted by Steve Underwood from the reference * code supplied with ITU G.722.1, which is: * - * © 2004 Polycom, Inc. + * (C) 2004 Polycom, Inc. * All rights reserved. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: huff_tab.c,v 1.7 2008/09/30 14:06:40 steveu Exp $ */ /*! \file */ diff --git a/libs/libg722_1/src/huff_tab.h b/libs/libg722_1/src/huff_tab.h index a58b843f5e..3d58962c83 100644 --- a/libs/libg722_1/src/huff_tab.h +++ b/libs/libg722_1/src/huff_tab.h @@ -6,14 +6,12 @@ * Adapted by Steve Underwood from the reference * code supplied with ITU G.722.1, which is: * - * © 2004 Polycom, Inc. + * (C) 2004 Polycom, Inc. * All rights reserved. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: huff_tab.h,v 1.4 2008/09/30 14:06:40 steveu Exp $ */ #define REGION_POWER_STEPSIZE_DB 3.010299957 diff --git a/libs/libg722_1/src/make_dct4_tables.c b/libs/libg722_1/src/make_dct4_tables.c index 015daf355a..ffb4a94063 100644 --- a/libs/libg722_1/src/make_dct4_tables.c +++ b/libs/libg722_1/src/make_dct4_tables.c @@ -6,14 +6,12 @@ * Adapted by Steve Underwood from the reference * code supplied with ITU G.722.1, which is: * - * © 2004 Polycom, Inc. + * (C) 2004 Polycom, Inc. * All rights reserved. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: make_dct4_tables.c,v 1.2 2008/10/02 11:43:54 steveu Exp $ */ /*! \file */ @@ -29,7 +27,11 @@ #include "g722_1/g722_1.h" +#if defined(PI) +#undef PI +#endif #define PI 3.141592653589793238462 + #include "defs.h" static void set_up_one_table(int length) @@ -99,6 +101,7 @@ int main(int argc, char *argv[]) for (i = 0; i <= length_log; i++) set_up_one_table(dct_size << i); + return 0; } /*- End of function --------------------------------------------------------*/ /*- End of file ------------------------------------------------------------*/ diff --git a/libs/libg722_1/src/make_tables.c b/libs/libg722_1/src/make_tables.c index d234d8a8a0..aa6d5cb748 100644 --- a/libs/libg722_1/src/make_tables.c +++ b/libs/libg722_1/src/make_tables.c @@ -6,14 +6,12 @@ * Adapted by Steve Underwood from the reference * code supplied with ITU G.722.1, which is: * - * © 2004 Polycom, Inc. + * (C) 2004 Polycom, Inc. * All rights reserved. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: make_tables.c,v 1.5 2008/11/21 15:30:22 steveu Exp $ */ /*! \file */ @@ -37,6 +35,7 @@ #undef PI #endif #define PI 3.141592653589793238462 + /* These may have been defined in the main header for the codec, so we clear out any pre-existing definitions here. */ #if defined(ENCODER_SCALE_FACTOR) @@ -124,7 +123,7 @@ static void generate_sam2coef_tables(void) for (i = 0; i < DCT_LENGTH; i++) { angle = (PI/2.0)*((double) i + 0.5)/(double) DCT_LENGTH; - printf(" %.15e,\n", sin(angle)); + printf(" %.15ef,\n", sin(angle)); } printf("};\n\n"); @@ -132,7 +131,7 @@ static void generate_sam2coef_tables(void) for (i = 0; i < MAX_DCT_LENGTH; i++) { angle = (PI/2.0)*((double) i + 0.5)/(double) MAX_DCT_LENGTH; - printf(" %.15le,\n", sin(angle)); + printf(" %.15ef,\n", sin(angle)); } printf("};\n\n"); @@ -180,7 +179,7 @@ static void generate_coef2sam_tables(void) for (i = 0; i < DCT_LENGTH; i++) { angle = (PI/2.0)*((double) i + 0.5)/(double) DCT_LENGTH; - printf(" %.15e,\n", sin(angle)); + printf(" %.15ef,\n", sin(angle)); } printf("};\n\n"); @@ -188,7 +187,7 @@ static void generate_coef2sam_tables(void) for (i = 0; i < MAX_DCT_LENGTH; i++) { angle = (PI/2.0)*((double) i + 0.5)/(double) MAX_DCT_LENGTH; - printf(" %.15e,\n", sin(angle)); + printf(" %.15ef,\n", sin(angle)); } printf("};\n\n"); @@ -218,7 +217,7 @@ int main(int argc, char *argv[]) for (i = 0; i < REGION_POWER_TABLE_SIZE; i++) { value = pow(10.0, 0.10*REGION_POWER_STEPSIZE_DB*(i - REGION_POWER_TABLE_NUM_NEGATIVES)); - printf(" %.15e,\n", sqrt(value)); + printf(" %.15ef,\n", sqrt(value)); } printf("};\n\n"); @@ -226,7 +225,7 @@ int main(int argc, char *argv[]) for (i = 0; i < REGION_POWER_TABLE_SIZE; i++) { value = pow(10.0, 0.10*REGION_POWER_STEPSIZE_DB*(i - REGION_POWER_TABLE_NUM_NEGATIVES)); - printf(" %.15e,\n", 1.0/sqrt(value)); + printf(" %.15ef,\n", 1.0/sqrt(value)); } printf("};\n\n"); @@ -259,14 +258,14 @@ int main(int argc, char *argv[]) printf("const float step_size[NUM_CATEGORIES] =\n{\n"); for (i = 0; i < NUM_CATEGORIES; i++) { - printf(" %.15e,\n", step_size[i]); + printf(" %.15ef,\n", step_size[i]); } printf("};\n\n"); printf("const float step_size_inverse_table[NUM_CATEGORIES] =\n{\n"); for (i = 0; i < NUM_CATEGORIES; i++) { - printf(" %.15e,\n", 1.0/step_size[i]); + printf(" %.15ef,\n", 1.0/step_size[i]); } printf("};\n\n"); @@ -275,7 +274,7 @@ int main(int argc, char *argv[]) for (i = 0; i < REGION_POWER_TABLE_SIZE; i++) { value = pow(10.0, 0.10*REGION_POWER_STEPSIZE_DB*(i - REGION_POWER_TABLE_NUM_NEGATIVES)); - printf(" %.15e,\n", value); + printf(" %.15ef,\n", value); } printf("};\n\n"); @@ -283,9 +282,10 @@ int main(int argc, char *argv[]) for (i = 0; i < REGION_POWER_TABLE_SIZE - 1; i++) { value = (float) pow(10.0, 0.10*REGION_POWER_STEPSIZE_DB*(0.5 + (i - REGION_POWER_TABLE_NUM_NEGATIVES))); - printf(" %.15e,\n", value); + printf(" %.15ef,\n", value); } printf("};\n\n"); + return 0; } /*- End of function --------------------------------------------------------*/ /*- End of file ------------------------------------------------------------*/ diff --git a/libs/libg722_1/src/sam2coef.c b/libs/libg722_1/src/sam2coef.c index 50f61d27ce..604c2874c8 100644 --- a/libs/libg722_1/src/sam2coef.c +++ b/libs/libg722_1/src/sam2coef.c @@ -6,14 +6,12 @@ * Adapted by Steve Underwood from the reference * code supplied with ITU G.722.1, which is: * - * © 2004 Polycom, Inc. + * (C) 2004 Polycom, Inc. * All rights reserved. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: sam2coef.c,v 1.12 2008/10/02 11:43:54 steveu Exp $ */ /*! \file */ @@ -29,17 +27,16 @@ #include "defs.h" #include "sam2coef.h" +#include "utilities.h" -/************************************************************************************ - Purpose: Convert Samples to Reversed MLT (Modulated Lapped Transform) Coefficients +/* Convert Samples to Reversed MLT (Modulated Lapped Transform) Coefficients - The "Reversed MLT" is an overlapped block transform which uses even symmetry - on the left, odd symmetry on the right and a Type IV DCT as the block transform. - It is thus similar to a MLT which uses odd symmetry on the left, even symmetry - on the right and a Type IV DST as the block transform. In fact, it is equivalent - to reversing the order of the samples, performing an MLT and then negating all - the even-numbered coefficients. -***************************************************************************/ + The "Reversed MLT" is an overlapped block transform which uses even symmetry + on the left, odd symmetry on the right and a Type IV DCT as the block transform. + It is thus similar to a MLT which uses odd symmetry on the left, even symmetry + on the right and a Type IV DST as the block transform. In fact, it is equivalent + to reversing the order of the samples, performing an MLT and then negating all + the even-numbered coefficients. */ #if defined(G722_1_USE_FIXED_POINT) int16_t samples_to_rmlt_coefs(const int16_t new_samples[], @@ -62,34 +59,26 @@ int16_t samples_to_rmlt_coefs(const int16_t new_samples[], half_dct_length = dct_length >> 1; - if (dct_length == DCT_LENGTH) - win = samples_to_rmlt_window; - else - win = max_samples_to_rmlt_window; + win = (dct_length == DCT_LENGTH) ? samples_to_rmlt_window : max_samples_to_rmlt_window; /* Get the first half of the windowed samples */ last = half_dct_length - 1; for (i = 0; i < half_dct_length; i++) { - acca = 0L; - acca = L_mac(acca, win[last - i], old_samples[last - i]); + acca = L_mult(win[last - i], old_samples[last - i]); acca = L_mac(acca, win[half_dct_length + i], old_samples[half_dct_length + i]); - temp = xround(acca); - windowed_data[i] = temp; + windowed_data[i] = xround(acca); } /* Get the second half of the windowed samples */ last = dct_length - 1; for (i = 0; i < half_dct_length; i++) { - acca = 0L; - acca = L_mac(acca, win[last - i], new_samples[i]); + acca = L_mult(win[last - i], new_samples[i]); acca = L_mac(acca, negate(win[i]), new_samples[last - i]); - temp = xround(acca); - windowed_data[half_dct_length + i] = temp; + windowed_data[half_dct_length + i] = xround(acca); } /* Save the new samples for next time, when they will be the old samples. */ - for (i = 0; i < dct_length; i++) - old_samples[i] = new_samples[i]; + vec_copyi16(old_samples, new_samples, dct_length); /* Calculate how many bits to shift up the input to the DCT. */ temp1 = 0; @@ -156,10 +145,7 @@ void samples_to_rmlt_coefs(const float new_samples[], half_dct_length = dct_length >> 1; - if (dct_length == DCT_LENGTH) - win = samples_to_rmlt_window; - else - win = max_samples_to_rmlt_window; + win = (dct_length == DCT_LENGTH) ? samples_to_rmlt_window : max_samples_to_rmlt_window; /* Get the first half of the windowed samples. */ last = half_dct_length - 1; for (i = 0; i < half_dct_length; i++) @@ -177,8 +163,7 @@ void samples_to_rmlt_coefs(const float new_samples[], windowed_data[half_dct_length + i] = sum; } /* Save the new samples for next time, when they will be the old samples. */ - for (i = 0; i < dct_length; i++) - old_samples[i] = new_samples[i]; + vec_copyf(old_samples, new_samples, dct_length); /* Perform a Type IV DCT on the windowed data to get the coefficients. */ dct_type_iv(windowed_data, coefs, dct_length); diff --git a/libs/libg722_1/src/sam2coef.h b/libs/libg722_1/src/sam2coef.h index 26f3cbaa02..1df19bb48f 100644 --- a/libs/libg722_1/src/sam2coef.h +++ b/libs/libg722_1/src/sam2coef.h @@ -6,14 +6,12 @@ * Adapted by Steve Underwood from the reference * code supplied with ITU G.722.1, which is: * - * © 2004 Polycom, Inc. + * (C) 2004 Polycom, Inc. * All rights reserved. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: sam2coef.h,v 1.2 2008/10/02 11:43:54 steveu Exp $ */ #if defined(G722_1_USE_FIXED_POINT) diff --git a/libs/libg722_1/src/tables.c b/libs/libg722_1/src/tables.c index 62a0e8d808..a0eed803bf 100644 --- a/libs/libg722_1/src/tables.c +++ b/libs/libg722_1/src/tables.c @@ -6,14 +6,12 @@ * Adapted by Steve Underwood from the reference * code supplied with ITU G.722.1, which is: * - * © 2004 Polycom, Inc. + * (C) 2004 Polycom, Inc. * All rights reserved. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: tables.c,v 1.11 2008/09/30 14:06:40 steveu Exp $ */ /*! \file */ @@ -65,70 +63,70 @@ const int16_t int_region_standard_deviation_table[REGION_POWER_TABLE_SIZE] = #else const float region_standard_deviation_table[REGION_POWER_TABLE_SIZE] = { - 2.441406247570224e-04f, - 3.452669826719395e-04f, - 4.882812495545411e-04f, - 6.905339654011486e-04f, - 9.765624991900746e-04f, - 1.381067930916839e-03f, - 1.953124998542134e-03f, - 2.762135862062757e-03f, - 3.906249997408239e-03f, - 5.524271724583683e-03f, - 7.812499995464418e-03f, - 1.104854345008369e-02f, - 1.562499999222472e-02f, - 2.209708690200003e-02f, - 3.124999998704119e-02f, - 4.419417380766535e-02f, - 6.249999997926591e-02f, - 8.838834762266132e-02f, - 1.249999999688989e-01f, - 1.767766952599839e-01f, - 2.499999999585318e-01f, - 3.535533905492901e-01f, - 4.999999999585318e-01f, - 7.071067811572251e-01f, - 1.000000000000000e+00f, - 1.414213562431740e+00f, - 2.000000000165873e+00f, - 2.828427125098059e+00f, - 4.000000000663491e+00f, - 5.656854250665278e+00f, - 8.000000001990472e+00f, - 1.131370850226887e+01f, - 1.600000000530792e+01f, - 2.262741700641438e+01f, - 3.200000001326981e+01f, - 4.525483401658204e+01f, - 6.400000003184756e+01f, - 9.050966804067060e+01f, - 1.280000000743110e+02f, - 1.810193360963542e+02f, - 2.560000001698536e+02f, - 3.620386722227349e+02f, - 5.120000003821707e+02f, - 7.240773445055215e+02f, - 1.024000000849268e+03f, - 1.448154689131149e+03f, - 2.048000001868390e+03f, - 2.896309378502505e+03f, - 4.096000004076487e+03f, - 5.792618757485434e+03f, - 8.192000008832390e+03f, - 1.158523751593169e+04f, - 1.638400001902361e+04f, - 2.317047503378509e+04f, - 3.276800004076484e+04f, - 4.634095007141347e+04f, - 6.553600008696507e+04f, - 9.268190015051374e+04f, - 1.310720001848009e+05f, - 1.853638003164007e+05f, - 2.621440003913428e+05f, - 3.707276006635486e+05f, - 5.242880008261676e+05f, - 7.414552013885899e+05f + 2.441406247570224e-04, + 3.452669826719395e-04, + 4.882812495545411e-04, + 6.905339654011486e-04, + 9.765624991900746e-04, + 1.381067930916839e-03, + 1.953124998542134e-03, + 2.762135862062757e-03, + 3.906249997408239e-03, + 5.524271724583683e-03, + 7.812499995464418e-03, + 1.104854345008369e-02, + 1.562499999222472e-02, + 2.209708690200003e-02, + 3.124999998704119e-02, + 4.419417380766535e-02, + 6.249999997926591e-02, + 8.838834762266132e-02, + 1.249999999688989e-01, + 1.767766952599839e-01, + 2.499999999585318e-01, + 3.535533905492901e-01, + 4.999999999585318e-01, + 7.071067811572251e-01, + 1.000000000000000e+00, + 1.414213562431740e+00, + 2.000000000165873e+00, + 2.828427125098059e+00, + 4.000000000663491e+00, + 5.656854250665278e+00, + 8.000000001990472e+00, + 1.131370850226887e+01, + 1.600000000530792e+01, + 2.262741700641438e+01, + 3.200000001326981e+01, + 4.525483401658204e+01, + 6.400000003184756e+01, + 9.050966804067060e+01, + 1.280000000743110e+02, + 1.810193360963542e+02, + 2.560000001698536e+02, + 3.620386722227349e+02, + 5.120000003821707e+02, + 7.240773445055215e+02, + 1.024000000849268e+03, + 1.448154689131149e+03, + 2.048000001868390e+03, + 2.896309378502505e+03, + 4.096000004076487e+03, + 5.792618757485434e+03, + 8.192000008832390e+03, + 1.158523751593169e+04, + 1.638400001902361e+04, + 2.317047503378509e+04, + 3.276800004076484e+04, + 4.634095007141347e+04, + 6.553600008696507e+04, + 9.268190015051374e+04, + 1.310720001848009e+05, + 1.853638003164007e+05, + 2.621440003913428e+05, + 3.707276006635486e+05, + 5.242880008261676e+05, + 7.414552013885899e+05 }; #endif @@ -146,70 +144,70 @@ const int16_t standard_deviation_inverse_table[REGION_POWER_TABLE_SIZE] = #else const float standard_deviation_inverse_table[REGION_POWER_TABLE_SIZE] = { - 4.096000004076488e+03f, - 2.896309378502504e+03f, - 2.048000001868390e+03f, - 1.448154689131149e+03f, - 1.024000000849268e+03f, - 7.240773445055215e+02f, - 5.120000003821708e+02f, - 3.620386722227349e+02f, - 2.560000001698537e+02f, - 1.810193360963542e+02f, - 1.280000000743110e+02f, - 9.050966804067060e+01f, - 6.400000003184756e+01f, - 4.525483401658203e+01f, - 3.200000001326982e+01f, - 2.262741700641438e+01f, - 1.600000000530793e+01f, - 1.131370850226887e+01f, - 8.000000001990474e+00f, - 5.656854250665277e+00f, - 4.000000000663491e+00f, - 2.828427125098059e+00f, - 2.000000000165873e+00f, - 1.414213562431740e+00f, - 1.000000000000000e+00f, - 7.071067811572251e-01f, - 4.999999999585318e-01f, - 3.535533905492901e-01f, - 2.499999999585318e-01f, - 1.767766952599838e-01f, - 1.249999999688989e-01f, - 8.838834762266132e-02f, - 6.249999997926592e-02f, - 4.419417380766535e-02f, - 3.124999998704120e-02f, - 2.209708690200002e-02f, - 1.562499999222472e-02f, - 1.104854345008369e-02f, - 7.812499995464418e-03f, - 5.524271724583683e-03f, - 3.906249997408239e-03f, - 2.762135862062757e-03f, - 1.953124998542134e-03f, - 1.381067930916839e-03f, - 9.765624991900747e-04f, - 6.905339654011486e-04f, - 4.882812495545411e-04f, - 3.452669826719394e-04f, - 2.441406247570224e-04f, - 1.726334913216520e-04f, - 1.220703123683871e-04f, - 8.631674565366727e-05f, - 6.103515617913153e-05f, - 4.315837282325419e-05f, - 3.051757808703478e-05f, - 2.157918640983742e-05f, - 1.525878904225187e-05f, - 1.078959320402385e-05f, - 7.629394520493171e-06f, - 5.394796601564505e-06f, - 3.814697259930213e-06f, - 2.697398300558537e-06f, - 1.907348629806920e-06f, - 1.348699150167414e-06f + 4.096000004076488e+03, + 2.896309378502504e+03, + 2.048000001868390e+03, + 1.448154689131149e+03, + 1.024000000849268e+03, + 7.240773445055215e+02, + 5.120000003821708e+02, + 3.620386722227349e+02, + 2.560000001698537e+02, + 1.810193360963542e+02, + 1.280000000743110e+02, + 9.050966804067060e+01, + 6.400000003184756e+01, + 4.525483401658203e+01, + 3.200000001326982e+01, + 2.262741700641438e+01, + 1.600000000530793e+01, + 1.131370850226887e+01, + 8.000000001990474e+00, + 5.656854250665277e+00, + 4.000000000663491e+00, + 2.828427125098059e+00, + 2.000000000165873e+00, + 1.414213562431740e+00, + 1.000000000000000e+00, + 7.071067811572251e-01, + 4.999999999585318e-01, + 3.535533905492901e-01, + 2.499999999585318e-01, + 1.767766952599838e-01, + 1.249999999688989e-01, + 8.838834762266132e-02, + 6.249999997926592e-02, + 4.419417380766535e-02, + 3.124999998704120e-02, + 2.209708690200002e-02, + 1.562499999222472e-02, + 1.104854345008369e-02, + 7.812499995464418e-03, + 5.524271724583683e-03, + 3.906249997408239e-03, + 2.762135862062757e-03, + 1.953124998542134e-03, + 1.381067930916839e-03, + 9.765624991900747e-04, + 6.905339654011486e-04, + 4.882812495545411e-04, + 3.452669826719394e-04, + 2.441406247570224e-04, + 1.726334913216520e-04, + 1.220703123683871e-04, + 8.631674565366727e-05, + 6.103515617913153e-05, + 4.315837282325419e-05, + 3.051757808703478e-05, + 2.157918640983742e-05, + 1.525878904225187e-05, + 1.078959320402385e-05, + 7.629394520493171e-06, + 5.394796601564505e-06, + 3.814697259930213e-06, + 2.697398300558537e-06, + 1.907348629806920e-06, + 1.348699150167414e-06 }; #endif @@ -241,14 +239,14 @@ const float step_size[NUM_CATEGORIES] = const float step_size_inverse_table[NUM_CATEGORIES] = { - 2.82805443e+00f, - 2.00000000e+00f, - 1.41422713e+00f, - 1.00000000e+00f, - 7.07113564e-01f, - 5.00000000e-01f, - 3.53556782e-01f, - 3.53556782e-01f + 2.82805443e+00, + 2.00000000e+00, + 1.41422713e+00, + 1.00000000e+00, + 7.07113564e-01, + 5.00000000e-01, + 3.53556782e-01, + 3.53556782e-01 }; #endif @@ -279,137 +277,137 @@ const float dead_zone[NUM_CATEGORIES] = #if !defined(G722_1_USE_FIXED_POINT) const float region_power_table[REGION_POWER_TABLE_SIZE] = { - 5.96046448e-08f, - 1.19209290e-07f, - 2.38418579e-07f, - 4.76837158e-07f, - 9.53674316e-07f, - 1.90734863e-06f, - 3.81469727e-06f, - 7.62939453e-06f, - 1.52587891e-05f, - 3.05175781e-05f, - 6.10351562e-05f, - 1.22070312e-04f, - 2.44140625e-04f, - 4.88281250e-04f, - 9.76562500e-04f, - 1.95312500e-03f, - 3.90625000e-03f, - 7.81250000e-03f, - 1.56250000e-02f, - 3.12500000e-02f, - 6.25000000e-02f, - 1.25000000e-01f, - 2.50000000e-01f, - 5.00000000e-01f, - 1.00000000e+00f, - 2.00000000e+00f, - 4.00000000e+00f, - 8.00000000e+00f, - 1.60000000e+01f, - 3.20000000e+01f, - 6.40000000e+01f, - 1.28000000e+02f, - 2.56000000e+02f, - 5.12000000e+02f, - 1.02400000e+03f, - 2.04800000e+03f, - 4.09600000e+03f, - 8.19200000e+03f, - 1.63840000e+04f, - 3.27680000e+04f, - 6.55360000e+04f, - 1.31072000e+05f, - 2.62144000e+05f, - 5.24288000e+05f, - 1.04857600e+06f, - 2.09715200e+06f, - 4.19430400e+06f, - 8.38860800e+06f, - 1.67772160e+07f, - 3.35544320e+07f, - 6.71088640e+07f, - 1.34217728e+08f, - 2.68435456e+08f, - 5.36870912e+08f, - 1.07374182e+09f, - 2.14748365e+09f, - 4.29496730e+09f, - 8.58993459e+09f, - 1.71798692e+10f, - 3.43597384e+10f, - 6.87194767e+10f, - 1.37438953e+11f, - 2.74877907e+11f, - 5.49755814e+11f + 5.96046448e-08, + 1.19209290e-07, + 2.38418579e-07, + 4.76837158e-07, + 9.53674316e-07, + 1.90734863e-06, + 3.81469727e-06, + 7.62939453e-06, + 1.52587891e-05, + 3.05175781e-05, + 6.10351562e-05, + 1.22070312e-04, + 2.44140625e-04, + 4.88281250e-04, + 9.76562500e-04, + 1.95312500e-03, + 3.90625000e-03, + 7.81250000e-03, + 1.56250000e-02, + 3.12500000e-02, + 6.25000000e-02, + 1.25000000e-01, + 2.50000000e-01, + 5.00000000e-01, + 1.00000000e+00, + 2.00000000e+00, + 4.00000000e+00, + 8.00000000e+00, + 1.60000000e+01, + 3.20000000e+01, + 6.40000000e+01, + 1.28000000e+02, + 2.56000000e+02, + 5.12000000e+02, + 1.02400000e+03, + 2.04800000e+03, + 4.09600000e+03, + 8.19200000e+03, + 1.63840000e+04, + 3.27680000e+04, + 6.55360000e+04, + 1.31072000e+05, + 2.62144000e+05, + 5.24288000e+05, + 1.04857600e+06, + 2.09715200e+06, + 4.19430400e+06, + 8.38860800e+06, + 1.67772160e+07, + 3.35544320e+07, + 6.71088640e+07, + 1.34217728e+08, + 2.68435456e+08, + 5.36870912e+08, + 1.07374182e+09, + 2.14748365e+09, + 4.29496730e+09, + 8.58993459e+09, + 1.71798692e+10, + 3.43597384e+10, + 6.87194767e+10, + 1.37438953e+11, + 2.74877907e+11, + 5.49755814e+11 }; const float region_power_table_boundary[REGION_POWER_TABLE_SIZE - 1] = { - 8.42936956e-08f, - 1.68587391e-07f, - 3.37174782e-07f, - 6.74349565e-07f, - 1.34869913e-06f, - 2.69739826e-06f, - 5.39479652e-06f, - 1.07895930e-05f, - 2.15791861e-05f, - 4.31583721e-05f, - 8.63167443e-05f, - 1.72633489e-04f, - 3.45266977e-04f, - 6.90533954e-04f, - 1.38106791e-03f, - 2.76213582e-03f, - 5.52427163e-03f, - 1.10485433e-02f, - 2.20970865e-02f, - 4.41941731e-02f, - 8.83883461e-02f, - 1.76776692e-01f, - 3.53553385e-01f, - 7.07106769e-01f, - 1.41421354e+00f, - 2.82842708e+00f, - 5.65685415e+00f, - 1.13137083e+01f, - 2.26274166e+01f, - 4.52548332e+01f, - 9.05096664e+01f, - 1.81019333e+02f, - 3.62038666e+02f, - 7.24077332e+02f, - 1.44815466e+03f, - 2.89630933e+03f, - 5.79261865e+03f, - 1.15852373e+04f, - 2.31704746e+04f, - 4.63409492e+04f, - 9.26818984e+04f, - 1.85363797e+05f, - 3.70727594e+05f, - 7.41455188e+05f, - 1.48291038e+06f, - 2.96582075e+06f, - 5.93164150e+06f, - 1.18632830e+07f, - 2.37265660e+07f, - 4.74531320e+07f, - 9.49062640e+07f, - 1.89812528e+08f, - 3.79625056e+08f, - 7.59250112e+08f, - 1.51850022e+09f, - 3.03700045e+09f, - 6.07400090e+09f, - 1.21480018e+10f, - 2.42960036e+10f, - 4.85920072e+10f, - 9.71840143e+10f, - 1.94368029e+11f, - 3.88736057e+11f + 8.42936956e-08, + 1.68587391e-07, + 3.37174782e-07, + 6.74349565e-07, + 1.34869913e-06, + 2.69739826e-06, + 5.39479652e-06, + 1.07895930e-05, + 2.15791861e-05, + 4.31583721e-05, + 8.63167443e-05, + 1.72633489e-04, + 3.45266977e-04, + 6.90533954e-04, + 1.38106791e-03, + 2.76213582e-03, + 5.52427163e-03, + 1.10485433e-02, + 2.20970865e-02, + 4.41941731e-02, + 8.83883461e-02, + 1.76776692e-01, + 3.53553385e-01, + 7.07106769e-01, + 1.41421354e+00, + 2.82842708e+00, + 5.65685415e+00, + 1.13137083e+01, + 2.26274166e+01, + 4.52548332e+01, + 9.05096664e+01, + 1.81019333e+02, + 3.62038666e+02, + 7.24077332e+02, + 1.44815466e+03, + 2.89630933e+03, + 5.79261865e+03, + 1.15852373e+04, + 2.31704746e+04, + 4.63409492e+04, + 9.26818984e+04, + 1.85363797e+05, + 3.70727594e+05, + 7.41455188e+05, + 1.48291038e+06, + 2.96582075e+06, + 5.93164150e+06, + 1.18632830e+07, + 2.37265660e+07, + 4.74531320e+07, + 9.49062640e+07, + 1.89812528e+08, + 3.79625056e+08, + 7.59250112e+08, + 1.51850022e+09, + 3.03700045e+09, + 6.07400090e+09, + 1.21480018e+10, + 2.42960036e+10, + 4.85920072e+10, + 9.71840143e+10, + 1.94368029e+11, + 3.88736057e+11 }; #endif diff --git a/libs/libg722_1/src/tables.h b/libs/libg722_1/src/tables.h index bf0aacba61..9b39979f18 100644 --- a/libs/libg722_1/src/tables.h +++ b/libs/libg722_1/src/tables.h @@ -6,14 +6,12 @@ * Adapted by Steve Underwood from the reference * code supplied with ITU G.722.1, which is: * - * © 2004 Polycom, Inc. + * (C) 2004 Polycom, Inc. * All rights reserved. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: tables.h,v 1.7 2008/09/26 17:37:31 steveu Exp $ */ #define REGION_POWER_TABLE_SIZE 64 diff --git a/libs/libg722_1/src/utilities.c b/libs/libg722_1/src/utilities.c new file mode 100644 index 0000000000..71cac6caf4 --- /dev/null +++ b/libs/libg722_1/src/utilities.c @@ -0,0 +1,467 @@ +/* + * g722_1 - a library for the G.722.1 and Annex C codecs + * + * utilities.c + * + * Copyright (C) 2006 Steve Underwood + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ + +#if defined(HAVE_CONFIG_H) +#include +#endif + +#include + +#if defined(G722_1_USE_MMX) +#include +#endif +#if defined(G722_1_USE_SSE) +#include +#endif +#if defined(G722_1_USE_SSE2) +#include +#endif +#if defined(G722_1_USE_SSE3) +#include +#include +#endif +#if defined(G722_1_USE_SSE4_1) +#include +#endif +#if defined(G722_1_USE_SSE4_2) +#include +#endif +#if defined(G722_1_USE_SSE4A) +#include +#endif +#if defined(G722_1_USE_SSE5) +#include +#endif + +#include "utilities.h" + +#if defined(G722_1_USE_FIXED_POINT) +void vec_copyi16(int16_t z[], const int16_t x[], int n) +{ + int i; + + for (i = 0; i < n; i++) + z[i] = x[i]; +} +/*- End of function --------------------------------------------------------*/ + +int32_t vec_dot_prodi16(const int16_t x[], const int16_t y[], int n) +{ + int32_t z; + +#if defined(__GNUC__) && defined(G722_1_USE_MMX) +#if defined(__x86_64__) + __asm__ __volatile__( + " emms;\n" + " pxor %%mm0,%%mm0;\n" + " leal -32(%%rsi,%%eax,2),%%edx;\n" /* edx = top - 32 */ + + " cmpl %%rdx,%%rsi;\n" + " ja 1f;\n" + + /* Work in blocks of 16 int16_t's until we are near the end */ + " .p2align 2;\n" + "2:\n" + " movq (%%rdi),%%mm1;\n" + " movq (%%rsi),%%mm2;\n" + " pmaddwd %%mm2,%%mm1;\n" + " paddd %%mm1,%%mm0;\n" + " movq 8(%%rdi),%%mm1;\n" + " movq 8(%%rsi),%%mm2;\n" + " pmaddwd %%mm2,%%mm1;\n" + " paddd %%mm1,%%mm0;\n" + " movq 16(%%rdi),%%mm1;\n" + " movq 16(%%rsi),%%mm2;\n" + " pmaddwd %%mm2,%%mm1;\n" + " paddd %%mm1,%%mm0;\n" + " movq 24(%%rdi),%%mm1;\n" + " movq 24(%%rsi),%%mm2;\n" + " pmaddwd %%mm2,%%mm1;\n" + " paddd %%mm1,%%mm0;\n" + + " addl $32,%%rsi;\n" + " addl $32,%%rdi;\n" + " cmpl %%rdx,%%rsi;\n" + " jbe 2b;\n" + + " .p2align 2;\n" + "1:\n" + " addl $24,%%rdx;\n" /* Now edx = top - 8 */ + " cmpl %%rdx,%%rsi;\n" + " ja 3f;\n" + + /* Work in blocks of 4 int16_t's until we are near the end */ + " .p2align 2;\n" + "4:\n" + " movq (%%rdi),%%mm1;\n" + " movq (%%rsi),%%mm2;\n" + " pmaddwd %%mm2,%%mm1;\n" + " paddd %%mm1,%%mm0;\n" + + " addl $8,%%rsi;\n" + " addl $8,%%rdi;\n" + " cmpl %%rdx,%%rsi;" + " jbe 4b;\n" + + " .p2align 2;\n" + "3:\n" + " addl $4,%%rdx;\n" /* Now edx = top - 4 */ + " cmpl %%rdx,%%rsi;\n" + " ja 5f;\n" + + /* Work in a block of 2 int16_t's */ + " movd (%%rdi),%%mm1;\n" + " movd (%%rsi),%%mm2;\n" + " pmaddwd %%mm2,%%mm1;\n" + " paddd %%mm1,%%mm0;\n" + + " addl $4,%%rsi;\n" + " addl $4,%%rdi;\n" + + " .p2align 2;\n" + "5:\n" + " addl $2,%%rdx;\n" /* Now edx = top - 2 */ + " cmpl %%rdx,%%rsi;\n" + " ja 6f;\n" + + /* Deal with the very last int16_t, when n is odd */ + " movswl (%%rdi),%%eax;\n" + " andl $65535,%%eax;\n" + " movd %%eax,%%mm1;\n" + " movswl (%%rsi),%%eax;\n" + " andl $65535,%%eax;\n" + " movd %%eax,%%mm2;\n" + " pmaddwd %%mm2,%%mm1;\n" + " paddd %%mm1,%%mm0;\n" + + " .p2align 2;\n" + "6:\n" + /* Merge the pieces of the answer */ + " movq %%mm0,%%mm1;\n" + " punpckhdq %%mm0,%%mm1;\n" + " paddd %%mm1,%%mm0;\n" + /* Et voila, eax has the final result */ + " movd %%mm0,%%eax;\n" + + " emms;\n" + : "=a" (z) + : "S" (x), "D" (y), "a" (n) + : "cc" + ); +#else + __asm__ __volatile__( + " emms;\n" + " pxor %%mm0,%%mm0;\n" + " leal -32(%%esi,%%eax,2),%%edx;\n" /* edx = top - 32 */ + + " cmpl %%edx,%%esi;\n" + " ja 1f;\n" + + /* Work in blocks of 16 int16_t's until we are near the end */ + " .p2align 2;\n" + "2:\n" + " movq (%%edi),%%mm1;\n" + " movq (%%esi),%%mm2;\n" + " pmaddwd %%mm2,%%mm1;\n" + " paddd %%mm1,%%mm0;\n" + " movq 8(%%edi),%%mm1;\n" + " movq 8(%%esi),%%mm2;\n" + " pmaddwd %%mm2,%%mm1;\n" + " paddd %%mm1,%%mm0;\n" + " movq 16(%%edi),%%mm1;\n" + " movq 16(%%esi),%%mm2;\n" + " pmaddwd %%mm2,%%mm1;\n" + " paddd %%mm1,%%mm0;\n" + " movq 24(%%edi),%%mm1;\n" + " movq 24(%%esi),%%mm2;\n" + " pmaddwd %%mm2,%%mm1;\n" + " paddd %%mm1,%%mm0;\n" + + " addl $32,%%esi;\n" + " addl $32,%%edi;\n" + " cmpl %%edx,%%esi;\n" + " jbe 2b;\n" + + " .p2align 2;\n" + "1:\n" + " addl $24,%%edx;\n" /* Now edx = top - 8 */ + " cmpl %%edx,%%esi;\n" + " ja 3f;\n" + + /* Work in blocks of 4 int16_t's until we are near the end */ + " .p2align 2;\n" + "4:\n" + " movq (%%edi),%%mm1;\n" + " movq (%%esi),%%mm2;\n" + " pmaddwd %%mm2,%%mm1;\n" + " paddd %%mm1,%%mm0;\n" + + " addl $8,%%esi;\n" + " addl $8,%%edi;\n" + " cmpl %%edx,%%esi;" + " jbe 4b;\n" + + " .p2align 2;\n" + "3:\n" + " addl $4,%%edx;\n" /* Now edx = top - 4 */ + " cmpl %%edx,%%esi;\n" + " ja 5f;\n" + + /* Work in a block of 2 int16_t's */ + " movd (%%edi),%%mm1;\n" + " movd (%%esi),%%mm2;\n" + " pmaddwd %%mm2,%%mm1;\n" + " paddd %%mm1,%%mm0;\n" + + " addl $4,%%esi;\n" + " addl $4,%%edi;\n" + + " .p2align 2;\n" + "5:\n" + " addl $2,%%edx;\n" /* Now edx = top - 2 */ + " cmpl %%edx,%%esi;\n" + " ja 6f;\n" + + /* Deal with the very last int16_t, when n is odd */ + " movswl (%%edi),%%eax;\n" + " andl $65535,%%eax;\n" + " movd %%eax,%%mm1;\n" + " movswl (%%esi),%%eax;\n" + " andl $65535,%%eax;\n" + " movd %%eax,%%mm2;\n" + " pmaddwd %%mm2,%%mm1;\n" + " paddd %%mm1,%%mm0;\n" + + " .p2align 2;\n" + "6:\n" + /* Merge the pieces of the answer */ + " movq %%mm0,%%mm1;\n" + " punpckhdq %%mm0,%%mm1;\n" + " paddd %%mm1,%%mm0;\n" + /* Et voila, eax has the final result */ + " movd %%mm0,%%eax;\n" + + " emms;\n" + : "=a" (z) + : "S" (x), "D" (y), "a" (n) + : "cc" + ); +#endif +#else + int i; + + z = 0; + for (i = 0; i < n; i++) + z += (int32_t) x[i]*(int32_t) y[i]; +#endif + return z; +} +/*- End of function --------------------------------------------------------*/ +#else +#if defined(__GNUC__) && defined(G722_1_USE_SSE2) +void vec_copyf(float z[], const float x[], int n) +{ + int i; + __m128 n1; + + if ((i = n & ~3)) + { + for (i -= 4; i >= 0; i -= 4) + { + n1 = _mm_loadu_ps(x + i); + _mm_storeu_ps(z + i, n1); + } + } + /* Now deal with the last 1 to 3 elements, which don't fill an SSE2 register */ + switch (n & 3) + { + case 3: + z[n - 3] = x[n - 3]; + case 2: + z[n - 2] = x[n - 2]; + case 1: + z[n - 1] = x[n - 1]; + } +} +#else +void vec_copyf(float z[], const float x[], int n) +{ + int i; + + for (i = 0; i < n; i++) + z[i] = x[i]; +} +#endif +/*- End of function --------------------------------------------------------*/ + +#if defined(__GNUC__) && defined(G722_1_USE_SSE2) +void vec_zerof(float z[], int n) +{ + int i; + __m128 n1; + + if ((i = n & ~3)) + { + n1 = _mm_setzero_ps(); + for (i -= 4; i >= 0; i -= 4) + _mm_storeu_ps(z + i, n1); + } + /* Now deal with the last 1 to 3 elements, which don't fill an SSE2 register */ + switch (n & 3) + { + case 3: + z[n - 3] = 0; + case 2: + z[n - 2] = 0; + case 1: + z[n - 1] = 0; + } +} +#else +void vec_zerof(float z[], int n) +{ + int i; + + for (i = 0; i < n; i++) + z[i] = 0.0f; +} +#endif +/*- End of function --------------------------------------------------------*/ + +void vec_subf(float z[], const float x[], const float y[], int n) +{ + int i; + + for (i = 0; i < n; i++) + z[i] = x[i] - y[i]; +} +/*- End of function --------------------------------------------------------*/ + +#if defined(__GNUC__) && defined(G722_1_USE_SSE2) +void vec_mulf(float z[], const float x[], const float y[], int n) +{ + int i; + __m128 n1; + __m128 n2; + __m128 n3; + + if ((i = n & ~3)) + { + for (i -= 4; i >= 0; i -= 4) + { + n1 = _mm_loadu_ps(x + i); + n2 = _mm_loadu_ps(y + i); + n3 = _mm_mul_ps(n1, n2); + _mm_storeu_ps(z + i, n3); + } + } + /* Now deal with the last 1 to 3 elements, which don't fill an SSE2 register */ + switch (n & 3) + { + case 3: + z[n - 3] = x[n - 3]*y[n - 3]; + case 2: + z[n - 2] = x[n - 2]*y[n - 2]; + case 1: + z[n - 1] = x[n - 1]*y[n - 1]; + } +} +#else +void vec_mulf(float z[], const float x[], const float y[], int n) +{ + int i; + + for (i = 0; i < n; i++) + z[i] = x[i]*y[i]; +} +#endif +/*- End of function --------------------------------------------------------*/ + +#if defined(__GNUC__) && defined(G722_1_USE_SSE2) +float vec_dot_prodf(const float x[], const float y[], int n) +{ + int i; + float z; + __m128 n1; + __m128 n2; + __m128 n3; + __m128 n4; + + z = 0.0f; + if ((i = n & ~3)) + { + n4 = _mm_setzero_ps(); //sets sum to zero + for (i -= 4; i >= 0; i -= 4) + { + n1 = _mm_loadu_ps(x + i); + n2 = _mm_loadu_ps(y + i); + n3 = _mm_mul_ps(n1, n2); + n4 = _mm_add_ps(n4, n3); + } + n4 = _mm_add_ps(_mm_movehl_ps(n4, n4), n4); + n4 = _mm_add_ss(_mm_shuffle_ps(n4, n4, 1), n4); + _mm_store_ss(&z, n4); + } + /* Now deal with the last 1 to 3 elements, which don't fill an SSE2 register */ + switch (n & 3) + { + case 3: + z += x[n - 3]*y[n - 3]; + case 2: + z += x[n - 2]*y[n - 2]; + case 1: + z += x[n - 1]*y[n - 1]; + } + return z; +} +#else +float vec_dot_prodf(const float x[], const float y[], int n) +{ + int i; + float z; + + z = 0.0f; + for (i = 0; i < n; i++) + z += x[i]*y[i]; + return z; +} +/*- End of function --------------------------------------------------------*/ +#endif + +void vec_scalar_mulf(float z[], const float x[], float y, int n) +{ + int i; + + for (i = 0; i < n; i++) + z[i] = x[i]*y; +} +/*- End of function --------------------------------------------------------*/ + +void vec_scaled_addf(float z[], const float x[], float x_scale, const float y[], float y_scale, int n) +{ + int i; + + for (i = 0; i < n; i++) + z[i] = x[i]*x_scale + y[i]*y_scale; +} +/*- End of function --------------------------------------------------------*/ + +void vec_scaled_subf(float z[], const float x[], float x_scale, const float y[], float y_scale, int n) +{ + int i; + + for (i = 0; i < n; i++) + z[i] = x[i]*x_scale - y[i]*y_scale; +} +/*- End of function --------------------------------------------------------*/ +#endif +/*- End of file ------------------------------------------------------------*/ diff --git a/libs/libg722_1/src/utilities.h b/libs/libg722_1/src/utilities.h new file mode 100644 index 0000000000..9d17103a16 --- /dev/null +++ b/libs/libg722_1/src/utilities.h @@ -0,0 +1,32 @@ +/* + * g722_1 - a library for the G.722.1 and Annex C codecs + * + * utilities.h + * + * Copyright (C) 2006 Steve Underwood + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ + +#if !defined(__UTILITIES_H__) +#define __UTILITIES_H__ + +/* Prototypes for some general purpose signal and vector functions */ +#if defined(G722_1_USE_FIXED_POINT) +void vec_copyi16(int16_t z[], const int16_t x[], int n); +int32_t vec_dot_prodi16(const int16_t x[], const int16_t y[], int n); +#else +void vec_copyf(float z[], const float x[], int n); +void vec_zerof(float z[], int n); +void vec_subf(float z[], const float x[], const float y[], int n); +void vec_scalar_mulf(float z[], const float x[], float y, int n); +void vec_mulf(float z[], const float x[], const float y[], int n); +float vec_dot_prodf(const float x[], const float y[], int n); +void vec_scaled_addf(float z[], const float x[], float x_scale, const float y[], float y_scale, int n); +void vec_scaled_subf(float z[], const float x[], float x_scale, const float y[], float y_scale, int n); +#endif + +#endif +/*- End of file ------------------------------------------------------------*/ diff --git a/libs/libg722_1/test-data/Makefile.am b/libs/libg722_1/test-data/Makefile.am index 83ddb94843..0b27a6830d 100644 --- a/libs/libg722_1/test-data/Makefile.am +++ b/libs/libg722_1/test-data/Makefile.am @@ -15,8 +15,6 @@ ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -## -## $Id: Makefile.am,v 1.2 2008/09/20 16:31:19 steveu Exp $ SUBDIRS = itu local diff --git a/libs/libg722_1/test-data/itu/Makefile.am b/libs/libg722_1/test-data/itu/Makefile.am index ae990154c0..df51ad0a07 100644 --- a/libs/libg722_1/test-data/itu/Makefile.am +++ b/libs/libg722_1/test-data/itu/Makefile.am @@ -15,8 +15,6 @@ ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -## -## $Id: Makefile.am,v 1.3 2008/09/23 16:03:04 steveu Exp $ SUBDIRS = diff --git a/libs/libg722_1/test-data/local/Makefile.am b/libs/libg722_1/test-data/local/Makefile.am index a7aca423c5..142fb4cc4e 100644 --- a/libs/libg722_1/test-data/local/Makefile.am +++ b/libs/libg722_1/test-data/local/Makefile.am @@ -15,8 +15,6 @@ ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -## -## $Id: Makefile.am,v 1.3 2008/09/24 16:12:52 steveu Exp $ SUBDIRS = diff --git a/libs/libg722_1/tests/Makefile.am b/libs/libg722_1/tests/Makefile.am index afad2f6433..aec0cecc29 100644 --- a/libs/libg722_1/tests/Makefile.am +++ b/libs/libg722_1/tests/Makefile.am @@ -15,8 +15,6 @@ ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -## -## $Id: Makefile.am,v 1.4 2008/10/19 04:05:02 steveu Exp $ AM_CFLAGS = $(COMP_VENDOR_CFLAGS) AM_LDFLAGS = $(COMP_VENDOR_LDFLAGS) @@ -33,8 +31,8 @@ LIBDIR = -L$(top_builddir)/src noinst_PROGRAMS = g722_1_tests -noinst_HEADERS = itu_bit_stream.c \ +noinst_HEADERS = g192_bit_stream.h \ timing.h -g722_1_tests_SOURCES = g722_1_tests.c itu_bit_stream.c +g722_1_tests_SOURCES = g722_1_tests.c g192_bit_stream.c g722_1_tests_LDADD = $(LIBDIR) -lg722_1 diff --git a/libs/libg722_1/tests/g192_bit_stream.c b/libs/libg722_1/tests/g192_bit_stream.c new file mode 100644 index 0000000000..36a853c6cc --- /dev/null +++ b/libs/libg722_1/tests/g192_bit_stream.c @@ -0,0 +1,177 @@ +/* + * broadvoice - a library for the BroadVoice 16 and 32 codecs + * + * g192_bit_stream.c + * + * Copyright 2008-2009 Steve Underwood + * + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 2.1, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/*! \file */ + +#if defined(HAVE_CONFIG_H) +#include "config.h" +#endif + +#include +#include +#include +#include + +#include "g192_bit_stream.h" + +#if !defined(FALSE) +#define FALSE 0 +#endif +#if !defined(TRUE) +#define TRUE (!FALSE) +#endif + +enum +{ + G192_FRAME_ERASURE = 0x6B20, + G192_FRAME_SYNC_1 = 0x6B21, + G192_FRAME_SYNC_2 = 0x6B22, + G192_FRAME_SYNC_3 = 0x6B23, + G192_FRAME_SYNC_4 = 0x6B24, + G192_FRAME_SYNC_5 = 0x6B25, + G192_FRAME_SYNC_6 = 0x6B26, + G192_FRAME_SYNC_7 = 0x6B27, + G192_FRAME_SYNC_8 = 0x6B28, + G192_FRAME_SYNC_9 = 0x6B29, + G192_FRAME_SYNC_10 = 0x6B2A, + G192_FRAME_SYNC_11 = 0x6B2B, + G192_FRAME_SYNC_12 = 0x6B2C, + G192_FRAME_SYNC_13 = 0x6B2D, + G192_FRAME_SYNC_14 = 0x6B2E, + G192_FRAME_SYNC_15 = 0x6B2F, + G192_HARD_ZERO = 0x7F, + G192_INDETERMINATE = 0x00, + G192_HARD_ONE = 0x81 +}; + +int itu_codec_bitstream_write(const uint8_t out_data[], + int number_of_bits, + int mode, + FILE *fp_bitstream) +{ + int i; + int j; + int bit_count; + int number_of_bytes; + uint8_t packed_word; + int16_t out_array[2 + number_of_bits + 7]; + + number_of_bytes = (number_of_bits + 7)/8; + if (mode == ITU_CODEC_BITSTREAM_PACKED) + { + return fwrite(out_data, 1, number_of_bytes, fp_bitstream); + } + j = 0; + out_array[j++] = G192_FRAME_SYNC_1; + out_array[j++] = number_of_bits; + for (i = 0; i < number_of_bytes; i++) + { + packed_word = out_data[i]; + for (bit_count = 7; bit_count >= 0; bit_count--) + out_array[j++] = ((packed_word >> bit_count) & 1) ? G192_HARD_ONE : G192_HARD_ZERO; + } + + return fwrite(out_array, sizeof(int16_t), number_of_bits + 2, fp_bitstream); +} +/*- End of function --------------------------------------------------------*/ + +int itu_codec_bitstream_read(uint8_t in_data[], + int16_t *erasure, + int number_of_bits, + int mode, + FILE *fp_bitstream) +{ + int i; + int j; + int bit_pos; + int nsamp; + int limit; + int rem; + int len; + int erased_frame; + int16_t packed_word; + int16_t bit; + int16_t in_array[2 + number_of_bits]; + + *erasure = FALSE; + if (mode == ITU_CODEC_BITSTREAM_PACKED) + { + nsamp = fread(in_data, 1, number_of_bits/8, fp_bitstream); + if (nsamp <= 0) + return -1; + return nsamp*8; + } + + nsamp = fread(in_array, sizeof(int16_t), 2, fp_bitstream); + if (nsamp < 2) + return -1; + if (in_array[0] < G192_FRAME_ERASURE || in_array[0] > G192_FRAME_SYNC_15) + { + *erasure = TRUE; + return 0; + } + erased_frame = (in_array[0] == G192_FRAME_ERASURE); + len = in_array[1]; + if (len > number_of_bits) + { + *erasure = TRUE; + return 0; + } + nsamp = fread(in_array, sizeof(int16_t), len, fp_bitstream); + if (nsamp != len) + { + *erasure = TRUE; + return nsamp; + } + + limit = (nsamp + 7)/8; + for (i = 0, j = 0; i < limit; i++) + { + packed_word = 0; + rem = (i == (limit - 1)) ? (limit*8 - nsamp) : 0; + for (bit_pos = 7; bit_pos >= rem; bit_pos--) + { + bit = in_array[j++]; + if (bit >= 0x0001 && bit <= G192_HARD_ZERO) + { + /* Its a zero */ + } + else if (bit >= G192_HARD_ONE && bit <= 0x00FF) + { + /* Its a one */ + packed_word |= (1 << bit_pos); + } + else + { + /* Bad bit */ + *erasure = 1; + } + } + in_data[i] = packed_word; + } + if (erased_frame) + *erasure = TRUE; + return nsamp; +} +/*- End of function --------------------------------------------------------*/ +/*- End of file ------------------------------------------------------------*/ diff --git a/libs/libg722_1/tests/g192_bit_stream.h b/libs/libg722_1/tests/g192_bit_stream.h new file mode 100644 index 0000000000..1948aa2e80 --- /dev/null +++ b/libs/libg722_1/tests/g192_bit_stream.h @@ -0,0 +1,75 @@ +/* + * broadvoice - a library for the BroadVoice 16 and 32 codecs + * + * g192_bit_stream.h + * + * Copyright 2008-2009 Steve Underwood + * + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 2.1, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/*! \file */ + +#if !defined(_G192_BIT_STREAM_H_) +#define _G192_BIT_STREAM_H_ + +/*! \page g192_bit_stream_page ITU G.192 codec bit stream handling +\section g192_bit_stream_page_sec_1 What does it do? + +\section g192_bit_stream_page_sec_2 How does it work? +*/ + +enum +{ + ITU_CODEC_BITSTREAM_PACKED = 0, + ITU_CODEC_BITSTREAM_G192 = 1 +}; + +#if defined(__cplusplus) +extern "C" +{ +#endif + +/*! \brief Write a frame of data to an output file. + \param out_data The buffer for the data to be written. + \param number_of_bits The number of bits to be written. + \param mode 0 = continuous, 1 = ITU G.192 codec bitstream format. + \param fp_bitstream The file context to be written to. + \return The number of words written. */ +int itu_codec_bitstream_write(const uint8_t out_data[], + int number_of_bits, + int mode, + FILE *fp_bitstream); + +/*! \brief Read a frame of data from an input file. + \param in_data The buffer for the data to be read. + \param p_erasure Set to TRUE if there is a frame erasure, else set to FALSE. + \param number_of_bits The number of bits to be read. + \param mode 0 = continuous, 1 = ITU G.192 codec bitstream format. + \param fp_bitstream The file context to be read from. + \return The number of words read. */ +int itu_codec_bitstream_read(uint8_t in_data[], + int16_t *p_erasure, + int number_of_bits, + int mode, + FILE *fp_bitstream); + +#if defined(__cplusplus) +} +#endif + +#endif +/*- End of file ------------------------------------------------------------*/ diff --git a/libs/libg722_1/tests/g722_1_tests.c b/libs/libg722_1/tests/g722_1_tests.c index 9f0b9519f9..7cc6befce1 100644 --- a/libs/libg722_1/tests/g722_1_tests.c +++ b/libs/libg722_1/tests/g722_1_tests.c @@ -6,14 +6,12 @@ * Adapted by Steve Underwood from the reference * code supplied with ITU G.722.1, which is: * - * © 2004 Polycom, Inc. + * (C) 2004 Polycom, Inc. * All rights reserved. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: g722_1_tests.c,v 1.14 2008/11/21 15:30:22 steveu Exp $ */ /*! \file */ @@ -36,7 +34,7 @@ #include #include "timing.h" -#include "itu_bit_stream.h" +#include "g192_bit_stream.h" typedef struct { @@ -227,7 +225,7 @@ static void parse_command_line(char *argv[], coder_control_t *control) } else if (strcasecmp(*argv, "i") == 0) { - control->encoded_format = ITU_CODEC_BITSTREAM_ITU; + control->encoded_format = ITU_CODEC_BITSTREAM_G192; printf("Encoding format = ITU-format bitstream\n"); } else diff --git a/libs/libg722_1/tests/itu_bit_stream.c b/libs/libg722_1/tests/itu_bit_stream.c deleted file mode 100644 index d07ef374eb..0000000000 --- a/libs/libg722_1/tests/itu_bit_stream.c +++ /dev/null @@ -1,139 +0,0 @@ -/* - * g722_1 - a library for the G.722.1 and Annex C codecs - * - * itu_bit_stream.c - * - * Adapted by Steve Underwood from the reference - * code supplied with ITU G.722.1, which is: - * - * © 2004 Polycom, Inc. - * All rights reserved. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: itu_bit_stream.c,v 1.6 2008/11/21 15:30:22 steveu Exp $ - */ - -/*! \file */ - -#if defined(HAVE_CONFIG_H) -#include "config.h" -#endif - -#include -#include -#include -#include - -#include "itu_bit_stream.h" - -static const int16_t frame_start = 0x6B21; -static const int16_t erased_frame_start = 0x6B20; -static const int16_t one = 0x0081; -static const int16_t zero = 0x007F; - -void itu_codec_bitstream_write(const uint8_t out_data[], - int number_of_bits, - int mode, - FILE *fp_bitstream) -{ - int i; - int j; - int bit_count; - int number_of_bytes; - uint8_t packed_word; - int16_t out_array[2 + number_of_bits + 7]; - - number_of_bytes = (number_of_bits + 7)/8; - if (mode == ITU_CODEC_BITSTREAM_PACKED) - { - fwrite(out_data, 1, number_of_bytes, fp_bitstream); - return; - } - j = 0; - out_array[j++] = frame_start; - out_array[j++] = number_of_bits; - for (i = 0; i < number_of_bytes; i++) - { - packed_word = out_data[i]; - for (bit_count = 7; bit_count >= 0; bit_count--) - out_array[j++] = ((packed_word >> bit_count) & 1) ? one : zero; - } - - fwrite(out_array, sizeof(int16_t), number_of_bits + 2, fp_bitstream); -} -/*- End of function --------------------------------------------------------*/ - -int itu_codec_bitstream_read(uint8_t in_data[], - int16_t *p_frame_error_flag, - int number_of_bits, - int mode, - FILE *fp_bitstream) -{ - int i; - int j; - int bit_count; - int nsamp; - int len; - int erased_frame; - int16_t packed_word; - int16_t bit; - int16_t in_array[2 + number_of_bits]; - - if (mode == ITU_CODEC_BITSTREAM_PACKED) - return fread(in_data, 1, number_of_bits/8, fp_bitstream)*8; - - nsamp = fread(in_array, sizeof(int16_t), 2, fp_bitstream); - if (nsamp < 2) - return -1; - if (in_array[0] != frame_start && in_array[0] != erased_frame_start) - { - *p_frame_error_flag = 1; - return 0; - } - erased_frame = (in_array[0] == erased_frame_start); - len = in_array[1]; - if (len > number_of_bits) - { - *p_frame_error_flag = 1; - return 0; - } - nsamp = fread(in_array, sizeof(int16_t), len, fp_bitstream); - if (nsamp != len) - { - *p_frame_error_flag = 1; - return nsamp; - } - *p_frame_error_flag = 0; - - for (i = 0, j = 0; i < nsamp/8; i++) - { - packed_word = 0; - bit_count = 7; - while (bit_count >= 0) - { - bit = in_array[j++]; - if (bit == zero) - bit = 0; - else if (bit == one) - bit = 1; - else - { - /* Bad bit */ - bit = 1; - *p_frame_error_flag = 1; - /* printf("read_ITU_format: bit not zero or one: %4x\n", bit); */ - } - packed_word = (packed_word << 1) | bit; - bit_count--; - } - in_data[i] = packed_word; - } - if (erased_frame) - *p_frame_error_flag = 1; - return nsamp; -} -/*- End of function --------------------------------------------------------*/ -/*- End of file ------------------------------------------------------------*/ diff --git a/libs/libg722_1/tests/regression_tests.sh.in b/libs/libg722_1/tests/regression_tests.sh.in index 6b52213b58..4be36b2008 100644 --- a/libs/libg722_1/tests/regression_tests.sh.in +++ b/libs/libg722_1/tests/regression_tests.sh.in @@ -16,9 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# $Id: regression_tests.sh.in,v 1.4 2008/11/21 15:30:22 steveu Exp $ -# STDOUT_DEST=xyzzy STDERR_DEST=xyzzy2 @@ -33,7 +30,7 @@ diff $TMP_FILE ../test-data/itu/g722_1/$VECTOR_CLASS/g722_1_enc_out_32000.itu RETVAL=$? if [ $RETVAL != 0 ] then - echo g722_1_tests E failed! + echo g722_1_tests encode failed! exit $RETVAL fi ./g722_1_tests E I 24000 16000 ../test-data/itu/g722_1/$VECTOR_CLASS/g722_1_enc_in.pcm $TMP_FILE @@ -41,17 +38,17 @@ diff $TMP_FILE ../test-data/itu/g722_1/$VECTOR_CLASS/g722_1_enc_out_24000.itu RETVAL=$? if [ $RETVAL != 0 ] then - echo g722_1_tests E failed! + echo g722_1_tests encode failed! exit $RETVAL fi -echo g722_1_tests E completed OK +echo g722_1_tests encode completed OK ./g722_1_tests D I 24000 16000 ../test-data/itu/g722_1/$VECTOR_CLASS/g722_1_enc_out_24000.itu $TMP_FILE diff $TMP_FILE ../test-data/itu/g722_1/$VECTOR_CLASS/g722_1_dec_out_24000.pcm RETVAL=$? if [ $RETVAL != 0 ] then - echo g722_1_tests D failed! + echo g722_1_tests decode failed! exit $RETVAL fi ./g722_1_tests D I 32000 16000 ../test-data/itu/g722_1/$VECTOR_CLASS/g722_1_enc_out_32000.itu $TMP_FILE @@ -59,7 +56,7 @@ diff $TMP_FILE ../test-data/itu/g722_1/$VECTOR_CLASS/g722_1_dec_out_32000.pcm RETVAL=$? if [ $RETVAL != 0 ] then - echo g722_1_tests D failed! + echo g722_1_tests decode failed! exit $RETVAL fi @@ -68,7 +65,7 @@ diff $TMP_FILE ../test-data/itu/g722_1/$VECTOR_CLASS/g722_1_dec_out_24000_fe.pcm RETVAL=$? if [ $RETVAL != 0 ] then - echo g722_1_tests D failed! + echo g722_1_tests decode failed! exit $RETVAL fi ./g722_1_tests D I 32000 16000 ../test-data/itu/g722_1/$VECTOR_CLASS/g722_1_dec_in_32000_fe.itu $TMP_FILE @@ -76,28 +73,28 @@ diff $TMP_FILE ../test-data/itu/g722_1/$VECTOR_CLASS/g722_1_dec_out_32000_fe.pcm RETVAL=$? if [ $RETVAL != 0 ] then - echo g722_1_tests D failed! + echo g722_1_tests decode failed! exit $RETVAL fi -echo g722_1_tests D completed OK +echo g722_1_tests decode completed OK ./g722_1_tests E I 32000 16000 ../test-data/local/short_wb_voice.wav $TMP_FILE RETVAL=$? if [ $RETVAL != 0 ] then - echo g722_1_tests E failed! + echo g722_1_tests encode failed! exit $RETVAL fi -echo g722_1_tests E completed OK +echo g722_1_tests encode completed OK ./g722_1_tests D I 32000 16000 $TMP_FILE test.au RETVAL=$? if [ $RETVAL != 0 ] then - echo g722_1_tests D failed! + echo g722_1_tests decode failed! exit $RETVAL fi -echo g722_1_tests D completed OK +echo g722_1_tests decode completed OK echo echo All regression tests successfully completed diff --git a/libs/libg722_1/tests/timing.h b/libs/libg722_1/tests/timing.h index 3fb1b3cc74..f95f3b8df1 100644 --- a/libs/libg722_1/tests/timing.h +++ b/libs/libg722_1/tests/timing.h @@ -1,5 +1,5 @@ /* - * SpanDSP - a series of DSP components for telephony + * g722_1 - a library for the G.722.1 and Annex C codecs * * timing.h - Provide access to the Pentium/Athlon TSC timer register * @@ -21,8 +21,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * $Id: timing.h,v 1.1 2008/10/17 15:17:39 steveu Exp $ */ #if !defined(_TIMING_H_) diff --git a/libs/libg722_1/unpack_g722_1_data.sh b/libs/libg722_1/unpack_g722_1_data.sh index 75741e0dd1..f8b85f4d30 100755 --- a/libs/libg722_1/unpack_g722_1_data.sh +++ b/libs/libg722_1/unpack_g722_1_data.sh @@ -16,9 +16,6 @@ # You should have received a copy of the GNU Lesser General Public # License along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# $Id: unpack_g722_1_data.sh,v 1.2 2008/09/26 12:09:29 steveu Exp $ -# ITUDATA="../../../T-REC-G.722.1-200505-I!!SOFT-ZST-E.zip" From 93630948e4efac18ad3f065365831a3cdb7407bd Mon Sep 17 00:00:00 2001 From: Steve Underwood Date: Sun, 26 Dec 2010 13:41:06 +0800 Subject: [PATCH 12/66] Missed a file in the previous update --- libs/libg722_1/g722_1.pc.in | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 libs/libg722_1/g722_1.pc.in diff --git a/libs/libg722_1/g722_1.pc.in b/libs/libg722_1/g722_1.pc.in new file mode 100644 index 0000000000..0fc01fbc73 --- /dev/null +++ b/libs/libg722_1/g722_1.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: spandsp +Description: A library for the ITU G.722.1 and G.722.1C audio codecs. +Requires: +Version: @VERSION@ +Libs: -L${libdir} -lg722_1 -lm +Cflags: -I${includedir} From 4e95227f39b3af92e03eab1e7808eb2d031dbdff Mon Sep 17 00:00:00 2001 From: Jeff Lenk Date: Sun, 26 Dec 2010 09:09:14 -0600 Subject: [PATCH 13/66] windows build fix for last commit --- libs/win32/libg722_1/libg722_1.vcproj | 8 ++++++++ libs/win32/libg722_1/libg722_1.vcxproj | 2 ++ libs/win32/libg722_1/libg722_1.vcxproj.filters | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/libs/win32/libg722_1/libg722_1.vcproj b/libs/win32/libg722_1/libg722_1.vcproj index e3101a22b9..a7a9530d05 100644 --- a/libs/win32/libg722_1/libg722_1.vcproj +++ b/libs/win32/libg722_1/libg722_1.vcproj @@ -342,6 +342,10 @@ RelativePath="..\..\libg722_1\src\tables.c" > + + + + + @@ -143,6 +144,7 @@ + diff --git a/libs/win32/libg722_1/libg722_1.vcxproj.filters b/libs/win32/libg722_1/libg722_1.vcxproj.filters index 855a60fae6..d54ad6e890 100644 --- a/libs/win32/libg722_1/libg722_1.vcxproj.filters +++ b/libs/win32/libg722_1/libg722_1.vcxproj.filters @@ -60,6 +60,9 @@ Source Files + + Source Files + @@ -92,5 +95,8 @@ Header Files + + Header Files + \ No newline at end of file From 7f81c3cc3c44ecba08bf58d219740190de3f55e9 Mon Sep 17 00:00:00 2001 From: Giovanni Maruzzelli Date: Mon, 27 Dec 2010 07:49:24 -0600 Subject: [PATCH 14/66] skypopen: OSS driver, added some code from /dev/zero to read(), and performances are better --- src/mod/endpoints/mod_skypopen/oss/main.c | 26 ++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/mod/endpoints/mod_skypopen/oss/main.c b/src/mod/endpoints/mod_skypopen/oss/main.c index a96e38d68a..10a210a574 100644 --- a/src/mod/endpoints/mod_skypopen/oss/main.c +++ b/src/mod/endpoints/mod_skypopen/oss/main.c @@ -249,6 +249,7 @@ static ssize_t skypopen_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos) { DEFINE_WAIT(wait); + size_t written; struct skypopen_dev *dev = filp->private_data; if(unload) @@ -273,8 +274,31 @@ static ssize_t skypopen_read(struct file *filp, char __user *buf, size_t count, prepare_to_wait(&dev->inq, &wait, TASK_INTERRUPTIBLE); schedule(); finish_wait(&dev->inq, &wait); - return count; + if (!count) + return 0; + + if (!access_ok(VERIFY_WRITE, buf, count)) + return -EFAULT; + + written = 0; + while (count) { + unsigned long unwritten; + size_t chunk = count; + + if (chunk > PAGE_SIZE) + chunk = PAGE_SIZE; /* Just for latency reasons */ + unwritten = __clear_user(buf, chunk); + written += chunk - unwritten; + if (unwritten) + break; + if (signal_pending(current)) + return written ? written : -ERESTARTSYS; + buf += chunk; + count -= chunk; + cond_resched(); + } + return written ? written : -EFAULT; } static ssize_t skypopen_write(struct file *filp, const char __user *buf, size_t count, From 430dfdacabcb07feb4f4c1aa6ad5a57e97a3e250 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 27 Dec 2010 09:27:21 -0600 Subject: [PATCH 15/66] revert change based on reports of bad audio --- src/mod/applications/mod_conference/mod_conference.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c index 2370e70ba1..fef64d50fc 100644 --- a/src/mod/applications/mod_conference/mod_conference.c +++ b/src/mod/applications/mod_conference/mod_conference.c @@ -2500,10 +2500,8 @@ static void conference_loop_output(conference_member_t *member) use_buffer = NULL; mux_used = (uint32_t) switch_buffer_inuse(member->mux_buffer); - if (mux_used < bytes * 2) { - use_timer = 1; - } - + use_timer = 1; + if (mux_used) { if (mux_used < bytes) { if (++low_count >= 5) { From 5eb951aa302676d2bebd74f630fece440db3b32f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 27 Dec 2010 14:55:55 -0600 Subject: [PATCH 16/66] fix partial match counting as exact match in dmachine --- src/switch_ivr_async.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index afd0fdbb70..0459f2b832 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -303,8 +303,6 @@ static dm_match_t switch_ivr_dmachine_check_match(switch_ivr_dmachine_t *dmachin if (is_timeout) { if (both_bp) { r_bp = exact_bp ? exact_bp : both_bp; - } else if (partial_bp) { - r_bp = partial_bp; } } From 903b2901dbd09e9ebbc6dffced4faa8cda166a11 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 27 Dec 2010 15:35:10 -0600 Subject: [PATCH 17/66] try to adjust the timer to be ok with the horrible 10000 microsecond kernel resolution on amazon ec3 but that doesn't mean it's not horribly wrong to run the kernel that slow --- src/switch_time.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/switch_time.c b/src/switch_time.c index 8465e5dcc0..ad721bee08 100644 --- a/src/switch_time.c +++ b/src/switch_time.c @@ -213,9 +213,13 @@ SWITCH_DECLARE(void) switch_time_calibrate_clock(void) } if (res > 1500) { + STEP_MS = res / 1000; + STEP_MIC = res; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Timer resolution of %ld microseconds detected!\n" - "Do you have your kernel timer frequency set to lower than 1,000Hz? You may experience audio problems.\n", ts.tv_nsec / 1000); + "Do you have your kernel timer frequency set to lower than 1,000Hz? " + "You may experience audio problems. Step MS %d\n", ts.tv_nsec / 1000, STEP_MS); do_sleep(5000000); switch_time_set_cond_yield(SWITCH_TRUE); return; From 27f5340d6ddda512f7d5d12b088f177e6aa38d28 Mon Sep 17 00:00:00 2001 From: Brian West Date: Mon, 27 Dec 2010 15:34:26 -0600 Subject: [PATCH 18/66] swigall --- src/mod/languages/mod_managed/managed/swig.cs | 2 ++ src/mod/languages/mod_perl/mod_perl_wrap.cpp | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/mod/languages/mod_managed/managed/swig.cs b/src/mod/languages/mod_managed/managed/swig.cs index bf328811dd..502ac01a65 100644 --- a/src/mod/languages/mod_managed/managed/swig.cs +++ b/src/mod/languages/mod_managed/managed/swig.cs @@ -21525,6 +21525,8 @@ public enum switch_channel_flag_t { CF_RECOVERED, CF_JITTERBUFFER, CF_DIALPLAN, + CF_BLOCK_BROADCAST_UNTIL_MEDIA, + CF_CNG_PLC, CF_FLAG_MAX } diff --git a/src/mod/languages/mod_perl/mod_perl_wrap.cpp b/src/mod/languages/mod_perl/mod_perl_wrap.cpp index 2efbdf1abc..370c88bc99 100644 --- a/src/mod/languages/mod_perl/mod_perl_wrap.cpp +++ b/src/mod/languages/mod_perl/mod_perl_wrap.cpp @@ -9732,17 +9732,17 @@ XS(SWIG_init) { SWIG_TypeClientData(SWIGTYPE_p_IVRMenu, (void*) "freeswitch::IVRMenu"); SWIG_TypeClientData(SWIGTYPE_p_API, (void*) "freeswitch::API"); SWIG_TypeClientData(SWIGTYPE_p_input_callback_state, (void*) "freeswitch::input_callback_state_t"); - /*@SWIG:/usr/local/share/swig/1.3.35/perl5/perltypemaps.swg,64,%set_constant@*/ do { + /*@SWIG:/usr/share/swig/1.3.35/perl5/perltypemaps.swg,64,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "S_HUP", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(S_HUP))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; - /*@SWIG:/usr/local/share/swig/1.3.35/perl5/perltypemaps.swg,64,%set_constant@*/ do { + /*@SWIG:/usr/share/swig/1.3.35/perl5/perltypemaps.swg,64,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "S_FREE", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(S_FREE))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; - /*@SWIG:/usr/local/share/swig/1.3.35/perl5/perltypemaps.swg,64,%set_constant@*/ do { + /*@SWIG:/usr/share/swig/1.3.35/perl5/perltypemaps.swg,64,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "S_RDLOCK", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(S_RDLOCK))); SvREADONLY_on(sv); From f6eab64c5c8eb76484f0502eb99c4dbefbbda7ef Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 27 Dec 2010 17:20:33 -0600 Subject: [PATCH 19/66] add uuid_buglist to fetch the current media-bugs attached to a given session uuid --- src/include/switch_core.h | 2 + .../applications/mod_commands/mod_commands.c | 47 ++++++++++++++++++- src/switch_core_media_bug.c | 26 ++++++++++ 3 files changed, 73 insertions(+), 2 deletions(-) diff --git a/src/include/switch_core.h b/src/include/switch_core.h index 840a06c204..bcd3c0aee2 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -246,6 +246,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_close(_Inout_ switch_media */ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_all(_In_ switch_core_session_t *session); +SWITCH_DECLARE(switch_status_t) switch_core_media_bug_enumerate(switch_core_session_t *session, switch_stream_handle_t *stream); + /*! \brief Read a frame from the bug \param bug the bug to read from diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 2deb437948..1c2e3ebfb9 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -2488,6 +2488,48 @@ SWITCH_STANDARD_API(uuid_display_function) return SWITCH_STATUS_SUCCESS; } +#define BUGLIST_SYNTAX "" +SWITCH_STANDARD_API(uuid_buglist_function) +{ + char *mydata = NULL, *argv[2] = { 0 }; + int argc = 0; + + switch_status_t status = SWITCH_STATUS_FALSE; + + if (zstr(cmd)) { + goto error; + } + + mydata = strdup(cmd); + switch_assert(mydata); + + argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); + + if (argc < 1) { + goto error; + } + if (argv[0]) { + switch_core_session_t *lsession = NULL; + + if ((lsession = switch_core_session_locate(argv[0]))) { + status = switch_core_media_bug_enumerate(lsession, stream); + switch_core_session_rwunlock(lsession); + } + goto ok; + } else { + goto error; + } + + error: + stream->write_function(stream, "-USAGE: %s\n", BUGLIST_SYNTAX); + switch_safe_free(mydata); + return SWITCH_STATUS_SUCCESS; + ok: + switch_safe_free(mydata); + + return SWITCH_STATUS_SUCCESS; +} + #define SIMPLIFY_SYNTAX "" SWITCH_STANDARD_API(uuid_simplify_function) { @@ -2541,7 +2583,6 @@ SWITCH_STANDARD_API(uuid_simplify_function) return SWITCH_STATUS_SUCCESS; } - #define JITTERBUFFER_SYNTAX " [0|[:]]" SWITCH_STANDARD_API(uuid_jitterbuffer_function) { @@ -4797,6 +4838,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load) SWITCH_ADD_API(commands_api_interface, "uuid_break", "Break", break_function, BREAK_SYNTAX); SWITCH_ADD_API(commands_api_interface, "uuid_bridge", "uuid_bridge", uuid_bridge_function, ""); SWITCH_ADD_API(commands_api_interface, "uuid_broadcast", "broadcast", uuid_broadcast_function, BROADCAST_SYNTAX); + SWITCH_ADD_API(commands_api_interface, "uuid_buglist", "List media bugs on a session", uuid_buglist_function, BUGLIST_SYNTAX); SWITCH_ADD_API(commands_api_interface, "uuid_chat", "Send a chat message", uuid_chat, UUID_CHAT_SYNTAX); SWITCH_ADD_API(commands_api_interface, "uuid_debug_audio", "debug audio", uuid_debug_audio_function, DEBUG_AUDIO_SYNTAX); SWITCH_ADD_API(commands_api_interface, "uuid_deflect", "Send a deflect", uuid_deflect, UUID_DEFLECT_SYNTAX); @@ -4911,6 +4953,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load) switch_console_set_complete("add uuid_break ::console::list_uuid both"); switch_console_set_complete("add uuid_bridge ::console::list_uuid ::console::list_uuid"); switch_console_set_complete("add uuid_broadcast ::console::list_uuid"); + switch_console_set_complete("add uuid_buglist ::console::list_uuid"); switch_console_set_complete("add uuid_chat ::console::list_uuid"); switch_console_set_complete("add uuid_debug_audio ::console::list_uuid"); switch_console_set_complete("add uuid_deflect ::console::list_uuid"); @@ -4939,7 +4982,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load) switch_console_set_complete("add uuid_phone_event ::console::list_uuid talk"); switch_console_set_complete("add uuid_phone_event ::console::list_uuid hold"); switch_console_set_complete("add uuid_preprocess ::console::list_uuid"); - switch_console_set_complete("add uuid_record ::console::list_uuid"); + switch_console_set_complete("add uuid_record ::console::list_uuid ::[start:stop"); switch_console_set_complete("add uuid_recv_dtmf ::console::list_uuid"); switch_console_set_complete("add uuid_send_dtmf ::console::list_uuid"); switch_console_set_complete("add uuid_session_heartbeat ::console::list_uuid"); diff --git a/src/switch_core_media_bug.c b/src/switch_core_media_bug.c index 7170969be2..21db3a9aff 100644 --- a/src/switch_core_media_bug.c +++ b/src/switch_core_media_bug.c @@ -392,6 +392,32 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_flush_all(switch_core_sess return SWITCH_STATUS_FALSE; } +SWITCH_DECLARE(switch_status_t) switch_core_media_bug_enumerate(switch_core_session_t *session, switch_stream_handle_t *stream) +{ + switch_media_bug_t *bp; + + stream->write_function(stream, "\n"); + + if (session->bugs) { + switch_thread_rwlock_wrlock(session->bug_rwlock); + for (bp = session->bugs; bp; bp = bp->next) { + int thread_locked = (bp->thread_id && bp->thread_id == switch_thread_self()); + stream->write_function(stream, + " \n" + " %s\n" + " %s\n" + " %d\n" + " \n", + bp->function, bp->target, thread_locked); + + } + switch_thread_rwlock_unlock(session->bug_rwlock); + } + + stream->write_function(stream, "\n"); + + return SWITCH_STATUS_SUCCESS; +} SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_all(switch_core_session_t *session) { From 844ac2201c4e98f19de695328334e7288197df65 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 27 Dec 2010 17:41:26 -0600 Subject: [PATCH 20/66] fix bad codepaths in mod_snapshot --- .../applications/mod_snapshot/mod_snapshot.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/mod/applications/mod_snapshot/mod_snapshot.c b/src/mod/applications/mod_snapshot/mod_snapshot.c index 2001ebdd38..20b311029b 100644 --- a/src/mod/applications/mod_snapshot/mod_snapshot.c +++ b/src/mod/applications/mod_snapshot/mod_snapshot.c @@ -188,10 +188,12 @@ static switch_status_t do_snap(switch_core_session_t *session) switch_core_file_close(&fh); switch_core_set_variable("file", file); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Wrote %s\n", file); + return SWITCH_STATUS_SUCCESS; } - return SWITCH_STATUS_SUCCESS; - + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "%s Bug is not attached.\n", switch_channel_get_name(channel)); + return SWITCH_STATUS_FALSE; + } #define SNAP_SYNTAX "start " @@ -249,7 +251,7 @@ SWITCH_STANDARD_APP(snapshot_app_function) } -#define SNAP_API_SYNTAX " " +#define SNAP_API_SYNTAX " snap|start [ read|write ]" SWITCH_STANDARD_API(snapshot_function) { char *mycmd = NULL, *argv[5] = { 0 }; @@ -260,7 +262,7 @@ SWITCH_STANDARD_API(snapshot_function) argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); } - if (zstr(cmd) || argc < 1 || zstr(argv[0])) { + if (zstr(cmd) || argc < 2 || zstr(argv[0])) { stream->write_function(stream, "-USAGE: %s\n", SNAP_API_SYNTAX); goto done; } else { @@ -270,9 +272,9 @@ SWITCH_STANDARD_API(snapshot_function) if (!strcasecmp(argv[1], "snap")) { status = do_snap(lsession); } else if (!strcasecmp(argv[1], "start")) { - char *sec = argv[1]; - char *fl = argv[2]; - const char *base = argv[3]; + char *sec = argv[2]; + char *fl = argv[3]; + const char *base = argv[4]; int seconds = 5; switch_media_bug_flag_t flags = SMBF_READ_STREAM | SMBF_WRITE_STREAM | SMBF_READ_PING; @@ -325,10 +327,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_snapshot_load) /* connect my internal structure to the blank pointer passed to me */ *module_interface = switch_loadable_module_create_module_interface(pool, modname); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hello World!\n"); - SWITCH_ADD_API(api_interface, "uuid_snapshot", "Snapshot API", snapshot_function, SNAP_API_SYNTAX); SWITCH_ADD_APP(app_interface, "snapshot", "", "", snapshot_app_function, SNAP_SYNTAX, SAF_SUPPORT_NOMEDIA); + switch_console_set_complete("add uuid_snapshot ::console::list_uuid"); /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_SUCCESS; From 0b8a9049f58bdb5ba224f74095fada7af4689ac6 Mon Sep 17 00:00:00 2001 From: Brian West Date: Mon, 27 Dec 2010 17:39:29 -0600 Subject: [PATCH 21/66] swigall --- src/mod/languages/mod_managed/freeswitch_wrap.cxx | 14 ++++++++++++++ src/mod/languages/mod_managed/managed/swig.cs | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/src/mod/languages/mod_managed/freeswitch_wrap.cxx b/src/mod/languages/mod_managed/freeswitch_wrap.cxx index 2c88f65ab6..b7187d4ef3 100644 --- a/src/mod/languages/mod_managed/freeswitch_wrap.cxx +++ b/src/mod/languages/mod_managed/freeswitch_wrap.cxx @@ -6588,6 +6588,20 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_media_bug_remove_all(void * jarg1) } +SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_media_bug_enumerate(void * jarg1, void * jarg2) { + int jresult ; + switch_core_session_t *arg1 = (switch_core_session_t *) 0 ; + switch_stream_handle_t *arg2 = (switch_stream_handle_t *) 0 ; + switch_status_t result; + + arg1 = (switch_core_session_t *)jarg1; + arg2 = (switch_stream_handle_t *)jarg2; + result = (switch_status_t)switch_core_media_bug_enumerate(arg1,arg2); + jresult = result; + return jresult; +} + + SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_media_bug_read(void * jarg1, void * jarg2, int jarg3) { int jresult ; switch_media_bug_t *arg1 = (switch_media_bug_t *) 0 ; diff --git a/src/mod/languages/mod_managed/managed/swig.cs b/src/mod/languages/mod_managed/managed/swig.cs index 502ac01a65..a79fde90e4 100644 --- a/src/mod/languages/mod_managed/managed/swig.cs +++ b/src/mod/languages/mod_managed/managed/swig.cs @@ -1045,6 +1045,11 @@ public class freeswitch { return ret; } + public static switch_status_t switch_core_media_bug_enumerate(SWIGTYPE_p_switch_core_session session, switch_stream_handle stream) { + switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_core_media_bug_enumerate(SWIGTYPE_p_switch_core_session.getCPtr(session), switch_stream_handle.getCPtr(stream)); + return ret; + } + public static switch_status_t switch_core_media_bug_read(SWIGTYPE_p_switch_media_bug bug, switch_frame frame, switch_bool_t fill) { switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_core_media_bug_read(SWIGTYPE_p_switch_media_bug.getCPtr(bug), switch_frame.getCPtr(frame), (int)fill); return ret; @@ -7269,6 +7274,9 @@ class freeswitchPINVOKE { [DllImport("mod_managed", EntryPoint="CSharp_switch_core_media_bug_remove_all")] public static extern int switch_core_media_bug_remove_all(HandleRef jarg1); + [DllImport("mod_managed", EntryPoint="CSharp_switch_core_media_bug_enumerate")] + public static extern int switch_core_media_bug_enumerate(HandleRef jarg1, HandleRef jarg2); + [DllImport("mod_managed", EntryPoint="CSharp_switch_core_media_bug_read")] public static extern int switch_core_media_bug_read(HandleRef jarg1, HandleRef jarg2, int jarg3); From 479f3de26be7267368a3ea912b0b52085884c55e Mon Sep 17 00:00:00 2001 From: Joao Mesquita Date: Mon, 27 Dec 2010 21:23:42 -0300 Subject: [PATCH 22/66] Add an unique id to the conference obj so that we can track conferences. --- .../mod_conference/mod_conference.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c index fa1f12c13f..c6a409e7ba 100644 --- a/src/mod/applications/mod_conference/mod_conference.c +++ b/src/mod/applications/mod_conference/mod_conference.c @@ -287,6 +287,7 @@ typedef struct conference_obj { uint32_t avg_itt; uint32_t avg_tally; switch_time_t run_time; + char *uuid_str; } conference_obj_t; /* Relationship with another member */ @@ -440,6 +441,7 @@ static switch_status_t conference_add_event_data(conference_obj_t *conference, s switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Conference-Name", conference->name); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Size", "%u", conference->count); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Conference-Profile-Name", conference->profile_name); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Conference-Unique-ID", conference->uuid_str); return status; } @@ -2779,6 +2781,12 @@ static void *SWITCH_THREAD_FUNC conference_record_thread_run(switch_thread_t *th switch_core_file_close(&fh); } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Recording of %s Stopped\n", rec->path); + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) { + conference_add_event_data(conference, event); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Action", "stop-recording"); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Path", rec->path); + switch_event_fire(&event); + } if (rec->pool) { switch_memory_pool_t *pool = rec->pool; @@ -5985,7 +5993,9 @@ static conference_obj_t *conference_new(char *name, conf_xml_cfg_t cfg, switch_m char *verbose_events = NULL; char *auto_record = NULL; char *terminate_on_silence = NULL; - + char uuid_str[SWITCH_UUID_FORMATTED_LENGTH+1]; + switch_uuid_t uuid; + /* Validate the conference name */ if (zstr(name)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Record! no name.\n"); @@ -6315,6 +6325,12 @@ static conference_obj_t *conference_new(char *name, conf_xml_cfg_t cfg, switch_m conference->verbose_events = 1; } + /* Create the conference unique identifier */ + switch_uuid_get(&uuid); + switch_uuid_format(uuid_str, &uuid); + conference->uuid_str = switch_core_strdup(conference->pool, uuid_str); + + /* Activate the conference mutex for exclusivity */ switch_mutex_init(&conference->mutex, SWITCH_MUTEX_NESTED, conference->pool); switch_mutex_init(&conference->flag_mutex, SWITCH_MUTEX_NESTED, conference->pool); From 86e7cdc5d1c6d8d8f173d4e5c921c9588f75679f Mon Sep 17 00:00:00 2001 From: Jeff Lenk Date: Tue, 28 Dec 2010 11:23:39 -0600 Subject: [PATCH 23/66] FS-2949 spelling error in -ERR return code encounterd -> encountered --- src/mod/languages/mod_lua/mod_lua.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/languages/mod_lua/mod_lua.cpp b/src/mod/languages/mod_lua/mod_lua.cpp index cf9b373ce0..b5a4999909 100644 --- a/src/mod/languages/mod_lua/mod_lua.cpp +++ b/src/mod/languages/mod_lua/mod_lua.cpp @@ -450,7 +450,7 @@ SWITCH_STANDARD_API(lua_api_function) if (switch_event_get_header(stream->param_event, "http-host")) { stream->write_function(stream, "Content-Type: text/html\n\n

Error Executing Script

"); } else { - stream->write_function(stream, "-ERR encounterd\n"); + stream->write_function(stream, "-ERR encountered\n"); } } lua_uninit(L); From 1d8a9297118f86ba40c0d2cc9f86b32552191acd Mon Sep 17 00:00:00 2001 From: Brian West Date: Tue, 28 Dec 2010 14:00:17 -0600 Subject: [PATCH 24/66] little note of warning for some folks just in case we had a question about the math lesson --- conf/autoload_configs/switch.conf.xml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/conf/autoload_configs/switch.conf.xml b/conf/autoload_configs/switch.conf.xml index 896dd0e712..fba809ba2c 100644 --- a/conf/autoload_configs/switch.conf.xml +++ b/conf/autoload_configs/switch.conf.xml @@ -23,7 +23,13 @@ - + From 81608da0067cb1bca2f718e4973e83af9371a659 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 29 Dec 2010 12:28:12 -0600 Subject: [PATCH 25/66] refactor sofia_contact to try the profile_name first then the domain to resolve the profile then fall back to querying every profile to reduce confusion with multi-homers (d'oh) also special profile name * will force a search-all situation --- src/mod/endpoints/mod_sofia/mod_sofia.c | 137 ++++++++++++++---------- 1 file changed, 81 insertions(+), 56 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 8aa37b95be..af7149b8c8 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -3395,6 +3395,36 @@ SWITCH_STANDARD_API(sofia_count_reg_function) return SWITCH_STATUS_SUCCESS; } +static void select_from_profile(sofia_profile_t *profile, + const char *user, + const char *domain, + const char *concat, + const char *exclude_contact, + switch_stream_handle_t *stream) +{ + struct cb_helper cb; + char *sql; + + cb.row_process = 0; + + cb.profile = profile; + cb.stream = stream; + + if (exclude_contact) { + sql = switch_mprintf("select contact, profile_name, '%q' " + "from sip_registrations where sip_user='%q' and (sip_host='%q' or presence_hosts like '%%%q%%') " + "and contact not like '%%%s%%'", (concat != NULL) ? concat : "", user, domain, domain, exclude_contact); + } else { + sql = switch_mprintf("select contact, profile_name, '%q' " + "from sip_registrations where sip_user='%q' and (sip_host='%q' or presence_hosts like '%%%q%%')", + (concat != NULL) ? concat : "", user, domain, domain); + } + + switch_assert(sql); + sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, contact_callback, &cb); + switch_safe_free(sql); +} + SWITCH_STANDARD_API(sofia_contact_function) { char *data; @@ -3406,6 +3436,7 @@ SWITCH_STANDARD_API(sofia_contact_function) sofia_profile_t *profile = NULL; const char *exclude_contact = NULL; char *reply = "error/facility_not_subscribed"; + switch_stream_handle_t mystream = { 0 }; if (!cmd) { stream->write_function(stream, "%s", ""); @@ -3440,76 +3471,70 @@ SWITCH_STANDARD_API(sofia_contact_function) } } - if (!profile_name && domain) { - profile_name = domain; + if (zstr(domain)) { + domain = switch_core_get_variable("domain"); } - if (user && profile_name) { - char *sql; + if (!user) goto end; - if (!(profile = sofia_glue_find_profile(profile_name))) { - profile_name = domain; - domain = NULL; - } - - if (!profile && profile_name) { + if (zstr(profile_name) || strcmp(profile_name, "*") || zstr(domain)) { + if (!zstr(profile_name)) { profile = sofia_glue_find_profile(profile_name); } - - if (profile) { - struct cb_helper cb; - switch_stream_handle_t mystream = { 0 }; - - cb.row_process = 0; - - if (!domain || (!strchr(domain, '.') && strcmp(profile_name, domain))) { - domain = profile->name; - } - - SWITCH_STANDARD_STREAM(mystream); - switch_assert(mystream.data); - cb.profile = profile; - cb.stream = &mystream; - - if (exclude_contact) { - sql = switch_mprintf("select contact, profile_name, '%q' " - "from sip_registrations where sip_user='%q' and (sip_host='%q' or presence_hosts like '%%%q%%') " - "and contact not like '%%%s%%'", (concat != NULL) ? concat : "", user, domain, domain, exclude_contact); - } else { - sql = switch_mprintf("select contact, profile_name, '%q' " - "from sip_registrations where sip_user='%q' and (sip_host='%q' or presence_hosts like '%%%q%%')", - (concat != NULL) ? concat : "", user, domain, domain); - } - - switch_assert(sql); - sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, contact_callback, &cb); - switch_safe_free(sql); - reply = (char *) mystream.data; - if (!zstr(reply) && end_of(reply) == ',') { - end_of(reply) = '\0'; - } - - if (zstr(reply)) { - reply = "error/user_not_registered"; - } - - stream->write_function(stream, "%s", reply); - reply = NULL; - - switch_safe_free(mystream.data); + + if (!profile) { + profile = sofia_glue_find_profile(domain); } } - if (reply) { - stream->write_function(stream, "%s", reply); + if (profile || !zstr(domain)) { + SWITCH_STANDARD_STREAM(mystream); + switch_assert(mystream.data); } - switch_safe_free(data); - if (profile) { + if (zstr(domain)) { + domain = profile->name; + } + + select_from_profile(profile, user, domain, concat, exclude_contact, &mystream); sofia_glue_release_profile(profile); + + } else if (!zstr(domain)) { + switch_mutex_lock(mod_sofia_globals.hash_mutex); + if (mod_sofia_globals.profile_hash) { + switch_hash_index_t *hi; + const void *var; + void *val; + + for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) { + switch_hash_this(hi, &var, NULL, &val); + if ((profile = (sofia_profile_t *) val) && !strcmp((char *)var, profile->name)) { + select_from_profile(profile, user, domain, concat, exclude_contact, &mystream); + profile = NULL; + } + } + } + switch_mutex_unlock(mod_sofia_globals.hash_mutex); + } + + reply = (char *) mystream.data; + + end: + + if (zstr(reply)) { + reply = "error/user_not_registered"; + } else if (end_of(reply) == ',') { + end_of(reply) = '\0'; } + stream->write_function(stream, "%s", reply); + reply = NULL; + + switch_safe_free(mystream.data); + + switch_safe_free(data); + return SWITCH_STATUS_SUCCESS; } From 650393fb90f79cfbbe9bc4b89f0d0dbdd9e9c3da Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 29 Dec 2010 13:15:14 -0600 Subject: [PATCH 26/66] add recovery_refresh app and api and use it in mod_conference to send a message to the channel telling it to sync its recovery snapshot --- src/include/switch_types.h | 1 + .../applications/mod_commands/mod_commands.c | 36 +++++++++++++++++++ .../mod_conference/mod_conference.c | 6 ++++ .../applications/mod_dptools/mod_dptools.c | 12 +++++++ src/mod/endpoints/mod_sofia/mod_sofia.c | 2 ++ 5 files changed, 57 insertions(+) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 830ea409e8..bb5f59865f 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -791,6 +791,7 @@ typedef enum { SWITCH_MESSAGE_INDICATE_UDPTL_MODE, SWITCH_MESSAGE_INDICATE_CLEAR_PROGRESS, SWITCH_MESSAGE_INDICATE_JITTER_BUFFER, + SWITCH_MESSAGE_INDICATE_RECOVERY_REFRESH, SWITCH_MESSAGE_INVALID } switch_core_session_message_types_t; diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 1c2e3ebfb9..8daaace7f3 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -2226,6 +2226,40 @@ SWITCH_STANDARD_API(uuid_deflect) return SWITCH_STATUS_SUCCESS; } +#define UUID_RECOVERY_REFRESH_SYNTAX " " +SWITCH_STANDARD_API(uuid_recovery_refresh) +{ + switch_core_session_t *tsession = NULL; + char *uuid = NULL, *text = NULL; + + if (!zstr(cmd) && (uuid = strdup(cmd))) { + if ((text = strchr(uuid, ' '))) { + *text++ = '\0'; + } + } + + if (zstr(uuid) || zstr(text)) { + stream->write_function(stream, "-USAGE: %s\n", UUID_RECOVERY_REFRESH_SYNTAX); + } else { + if ((tsession = switch_core_session_locate(uuid))) { + switch_core_session_message_t msg = { 0 }; + + /* Tell the channel to recovery_refresh the call */ + msg.from = __FILE__; + msg.string_arg = text; + msg.message_id = SWITCH_MESSAGE_INDICATE_RECOVERY_REFRESH; + switch_core_session_receive_message(tsession, &msg); + stream->write_function(stream, "+OK:%s\n", msg.string_reply); + switch_core_session_rwunlock(tsession); + } else { + stream->write_function(stream, "-ERR No Such Channel %s!\n", uuid); + } + } + + switch_safe_free(uuid); + return SWITCH_STATUS_SUCCESS; +} + #define SCHED_TRANSFER_SYNTAX "[+] - - - - diff --git a/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c b/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c index 3317436133..f145210e4f 100644 --- a/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c +++ b/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c @@ -52,8 +52,8 @@ typedef struct cdr_fd cdr_fd_t; const char *default_template = "\"${local_ip_v4}\",\"${caller_id_name}\",\"${caller_id_number}\",\"${destination_number}\",\"${context}\",\"${start_stamp}\"," - "\"${answer_stamp}\",\"${end_stamp}\",\"${duration}\",\"${billsec}\",\"${hangup_cause}\",\"${uuid}\",\"${bleg_uuid}\", \"${accountcode}\"," - "\"${read_codec}\", \"${write_codec}\"\n"; + "\"${answer_stamp}\",\"${end_stamp}\",\"${duration}\",\"${billsec}\",\"${hangup_cause}\",\"${uuid}\",\"${bleg_uuid}\",\"${accountcode}\"," + "\"${read_codec}\",\"${write_codec}\"\n"; static struct { switch_memory_pool_t *pool; @@ -65,9 +65,8 @@ static struct { int rotate; int debug; cdr_leg_t legs; - char *a_table; - char *g_table; char *db_info; + char *db_table; PGconn *db_connection; int db_online; switch_mutex_t *db_mutex; @@ -185,7 +184,7 @@ static void write_cdr(const char *path, const char *log_line) switch_mutex_unlock(fd->mutex); } -static int save_cdr(const char * const table, const char * const template, const char * const cdr) +static switch_status_t save_cdr(const char * const table, const char * const template, const char * const cdr) { char *columns, *values; char *p, *q; @@ -197,7 +196,7 @@ static int save_cdr(const char * const table, const char * const template, const if (!table || !*table || !template || !*template || !cdr || !*cdr) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Bad parameter\n"); - return 0; + return SWITCH_STATUS_FALSE; } /* Build comma-separated list of field names by dropping $ { } ; chars */ @@ -212,7 +211,8 @@ static int save_cdr(const char * const table, const char * const template, const } *q = '\0'; - /* In the expanded vars, replace double quotes (") with single quotes (') + /* + * In the expanded vars, replace double quotes (") with single quotes (') * for corect PostgreSQL syntax, and replace semi-colon with space to * prevent SQL injection attacks. */ @@ -248,7 +248,6 @@ static int save_cdr(const char * const table, const char * const template, const nullCounter++; } - charCounter = 0; nullCounter *= 4; vlen += nullCounter; nullValues = (char *) malloc(strlen(values) + nullCounter + 1); @@ -335,7 +334,7 @@ static int save_cdr(const char * const table, const char * const template, const globals.db_online = 0; switch_mutex_unlock(globals.db_mutex); free(query); - return 0; + return SWITCH_STATUS_FALSE; } res = PQexec(globals.db_connection, query); @@ -346,21 +345,21 @@ static int save_cdr(const char * const table, const char * const template, const globals.db_online = 0; switch_mutex_unlock(globals.db_mutex); free(query); - return 0; + return SWITCH_STATUS_FALSE; } PQclear(res); free(query); switch_mutex_unlock(globals.db_mutex); - return 1; + return SWITCH_STATUS_SUCCESS; } static switch_status_t my_on_reporting(switch_core_session_t *session) { switch_channel_t *channel = switch_core_session_get_channel(session); switch_status_t status = SWITCH_STATUS_SUCCESS; - const char *log_dir = NULL, *accountcode = NULL, *a_template_str = NULL, *g_template_str = NULL; + const char *log_dir = NULL, *template_str = NULL; char *log_line, *path = NULL; int saved = 0; @@ -402,44 +401,20 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) } } - g_template_str = (const char *) switch_core_hash_find(globals.template_hash, globals.default_template); + template_str = (const char *) switch_core_hash_find(globals.template_hash, globals.default_template); - if ((accountcode = switch_channel_get_variable(channel, "ACCOUNTCODE"))) { - a_template_str = (const char *) switch_core_hash_find(globals.template_hash, accountcode); + if (!template_str) { + template_str = default_template; } - if (!g_template_str) { - g_template_str = "\"${accountcode}\",\"${caller_id_number}\",\"${destination_number}\",\"${context}\",\"${caller_id}\",\"${channel_name}\",\"${bridge_channel}\",\"${last_app}\",\"${last_arg}\",\"${start_stamp}\",\"${answer_stamp}\",\"${end_stamp}\",\"${duration}\",\"${billsec}\",\"${hangup_cause}\",\"${amaflags}\",\"${uuid}\",\"${userfield}\";"; - } - - if (!a_template_str) { - a_template_str = g_template_str; - } - - log_line = switch_channel_expand_variables(channel, a_template_str); - - saved = 1; // save_cdr(globals.a_table, a_template_str, log_line); - - if (!saved && accountcode) { - path = switch_mprintf("%s%s%s.csv", log_dir, SWITCH_PATH_SEPARATOR, accountcode); - assert(path); - write_cdr(path, log_line); - free(path); - } - - if (g_template_str != a_template_str) { - if (log_line != a_template_str) { - switch_safe_free(log_line); - } - log_line = switch_channel_expand_variables(channel, g_template_str); - } + log_line = switch_channel_expand_variables(channel, template_str); if (!log_line) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating cdr\n"); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error expanding CDR variables.\n"); return SWITCH_STATUS_FALSE; } - saved = save_cdr(globals.g_table, g_template_str, log_line); + saved = save_cdr(globals.db_table, template_str, log_line); if (!saved) { path = switch_mprintf("%s%sMaster.csv", log_dir, SWITCH_PATH_SEPARATOR); @@ -448,7 +423,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) free(path); } - if (log_line != g_template_str) { + if (log_line != template_str) { free(log_line); } @@ -545,14 +520,12 @@ static switch_status_t load_config(switch_memory_pool_t *pool) globals.log_dir = switch_core_sprintf(pool, "%s%scdr-pg-csv", val, SWITCH_PATH_SEPARATOR); } else if (!strcasecmp(var, "rotate-on-hup")) { globals.rotate = switch_true(val); - } else if (!strcasecmp(var, "default-template")) { - globals.default_template = switch_core_strdup(pool, val); - } else if (!strcasecmp(var, "a-table")) { - globals.a_table = switch_core_strdup(pool, val); - } else if (!strcasecmp(var, "g-table")) { - globals.g_table = switch_core_strdup(pool, val); } else if (!strcasecmp(var, "db-info")) { globals.db_info = switch_core_strdup(pool, val); + } else if (!strcasecmp(var, "db-table") || !strcasecmp(var, "g-table")) { + globals.db_table = switch_core_strdup(pool, val); + } else if (!strcasecmp(var, "default-template")) { + globals.default_template = switch_core_strdup(pool, val); } } } @@ -578,26 +551,22 @@ static switch_status_t load_config(switch_memory_pool_t *pool) switch_xml_free(xml); } + if (!globals.log_dir) { + globals.log_dir = switch_core_sprintf(pool, "%s%scdr-pg-csv", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR); + } + + if (zstr(globals.db_info)) { + globals.db_info = switch_core_strdup(pool, "dbname=cdr"); + } + + if (zstr(globals.db_table)) { + globals.db_table = switch_core_strdup(pool, "cdr"); + } if (zstr(globals.default_template)) { globals.default_template = switch_core_strdup(pool, "default"); } - if (!globals.log_dir) { - globals.log_dir = switch_core_sprintf(pool, "%s%scdr-pg-csv", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR); - } - - if (zstr(globals.a_table)) { - globals.a_table = switch_core_strdup(pool, "a"); - } - - if (zstr(globals.g_table)) { - globals.g_table = switch_core_strdup(pool, "g"); - } - - if (zstr(globals.db_info)) { - globals.db_info = switch_core_strdup(pool, "dbname = cdr"); - } return status; } From 2be3175ae91924a3e7460f67f0aecd927d6f2661 Mon Sep 17 00:00:00 2001 From: Daniel Swarbrick Date: Fri, 31 Dec 2010 20:54:20 +0100 Subject: [PATCH 48/66] mod_cdr_pg_csv now spools the attempted SQL to disk if DB insert fails, instead of writing CSV. This should make it simpler to import any failed inserts. --- .../mod_cdr_pg_csv/mod_cdr_pg_csv.c | 79 +++++++++---------- .../mod_cdr_sqlite/mod_cdr_sqlite.c | 2 +- 2 files changed, 39 insertions(+), 42 deletions(-) diff --git a/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c b/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c index f145210e4f..275fec1396 100644 --- a/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c +++ b/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c @@ -53,7 +53,7 @@ typedef struct cdr_fd cdr_fd_t; const char *default_template = "\"${local_ip_v4}\",\"${caller_id_name}\",\"${caller_id_number}\",\"${destination_number}\",\"${context}\",\"${start_stamp}\"," "\"${answer_stamp}\",\"${end_stamp}\",\"${duration}\",\"${billsec}\",\"${hangup_cause}\",\"${uuid}\",\"${bleg_uuid}\",\"${accountcode}\"," - "\"${read_codec}\",\"${write_codec}\"\n"; + "\"${read_codec}\",\"${write_codec}\""; static struct { switch_memory_pool_t *pool; @@ -184,17 +184,17 @@ static void write_cdr(const char *path, const char *log_line) switch_mutex_unlock(fd->mutex); } -static switch_status_t save_cdr(const char * const table, const char * const template, const char * const cdr) +static switch_status_t save_cdr(const char * const template, const char * const cdr, const char * const log_dir) { char *columns, *values; char *p, *q; unsigned vlen; - char *query; - PGresult *res; char *nullValues, *temp, *tp; int nullCounter = 0, charCounter = 0; + char *sql = NULL, *path = NULL; + PGresult *res; - if (!table || !*table || !template || !*template || !cdr || !*cdr) { + if (!template || !*template || !cdr || !*cdr) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Bad parameter\n"); return SWITCH_STATUS_FALSE; } @@ -311,13 +311,13 @@ static switch_status_t save_cdr(const char * const table, const char * const tem //----------------------------- END_OF_PATCH ------------------------------- - query = switch_mprintf("INSERT INTO %s (%s) VALUES (%s);", table, columns, values); - assert(query); + sql = switch_mprintf("INSERT INTO %s (%s) VALUES (%s);\n", globals.db_table, columns, values); + assert(sql); free(columns); free(values); if (globals.debug) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Query: \"%s\"\n", query); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Query: \"%s\"\n", sql); } switch_mutex_lock(globals.db_mutex); @@ -330,29 +330,40 @@ static switch_status_t save_cdr(const char * const table, const char * const tem globals.db_online = 1; } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Connection to database failed: %s", PQerrorMessage(globals.db_connection)); - PQfinish(globals.db_connection); - globals.db_online = 0; - switch_mutex_unlock(globals.db_mutex); - free(query); - return SWITCH_STATUS_FALSE; + goto error; } - res = PQexec(globals.db_connection, query); + res = PQexec(globals.db_connection, sql); if (PQresultStatus(res) != PGRES_COMMAND_OK) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "INSERT command failed: %s", PQresultErrorMessage(res)); PQclear(res); - PQfinish(globals.db_connection); - globals.db_online = 0; - switch_mutex_unlock(globals.db_mutex); - free(query); - return SWITCH_STATUS_FALSE; + goto error; } + PQclear(res); - free(query); + free(sql); switch_mutex_unlock(globals.db_mutex); return SWITCH_STATUS_SUCCESS; + + + error: + + PQfinish(globals.db_connection); + globals.db_online = 0; + switch_mutex_unlock(globals.db_mutex); + + /* SQL INSERT failed for whatever reason. Spool the attempted query to disk */ + path = switch_mprintf("%s%scdr-spool.sql", log_dir, SWITCH_PATH_SEPARATOR); + assert(path); + write_cdr(path, sql); + + free(path); + free(sql); + + return SWITCH_STATUS_FALSE; + } static switch_status_t my_on_reporting(switch_core_session_t *session) @@ -360,8 +371,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) switch_channel_t *channel = switch_core_session_get_channel(session); switch_status_t status = SWITCH_STATUS_SUCCESS; const char *log_dir = NULL, *template_str = NULL; - char *log_line, *path = NULL; - int saved = 0; + char *expanded_vars = NULL; if (globals.shutdown) { return SWITCH_STATUS_SUCCESS; @@ -407,24 +417,17 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) template_str = default_template; } - log_line = switch_channel_expand_variables(channel, template_str); + expanded_vars = switch_channel_expand_variables(channel, template_str); - if (!log_line) { + if (!expanded_vars) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error expanding CDR variables.\n"); return SWITCH_STATUS_FALSE; } - saved = save_cdr(globals.db_table, template_str, log_line); + save_cdr(template_str, expanded_vars, log_dir); - if (!saved) { - path = switch_mprintf("%s%sMaster.csv", log_dir, SWITCH_PATH_SEPARATOR); - assert(path); - write_cdr(path, log_line); - free(path); - } - - if (log_line != template_str) { - free(log_line); + if (expanded_vars != template_str) { + free(expanded_vars); } return status; @@ -535,13 +538,7 @@ static switch_status_t load_config(switch_memory_pool_t *pool) char *var = (char *) switch_xml_attr(param, "name"); if (var) { char *tpl; - size_t len = strlen(param->txt) + 2; - if (end_of(param->txt) != '\n') { - tpl = switch_core_alloc(pool, len); - switch_snprintf(tpl, len, "%s\n", param->txt); - } else { - tpl = switch_core_strdup(pool, param->txt); - } + tpl = switch_core_strdup(pool, param->txt); switch_core_hash_insert(globals.template_hash, var, tpl); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Adding template %s.\n", var); diff --git a/src/mod/event_handlers/mod_cdr_sqlite/mod_cdr_sqlite.c b/src/mod/event_handlers/mod_cdr_sqlite/mod_cdr_sqlite.c index ca928182ba..534f18f2ca 100644 --- a/src/mod/event_handlers/mod_cdr_sqlite/mod_cdr_sqlite.c +++ b/src/mod/event_handlers/mod_cdr_sqlite/mod_cdr_sqlite.c @@ -113,7 +113,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) switch_channel_t *channel = switch_core_session_get_channel(session); switch_status_t status = SWITCH_STATUS_SUCCESS; const char *template_str = NULL; - char *expanded_vars, *sql = NULL; + char *expanded_vars = NULL, *sql = NULL; if (globals.shutdown) { return SWITCH_STATUS_SUCCESS; From ec57dc7ab76e5765bbd50905e47a1cac2aad38ba Mon Sep 17 00:00:00 2001 From: Steve Underwood Date: Sun, 2 Jan 2011 19:30:00 +0800 Subject: [PATCH 49/66] Added missing error codes when an ECM FAX is abandoned with the T30_ERR message --- libs/spandsp/src/t30.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/spandsp/src/t30.c b/libs/spandsp/src/t30.c index 45387b8585..aba4eef0eb 100644 --- a/libs/spandsp/src/t30.c +++ b/libs/spandsp/src/t30.c @@ -4275,6 +4275,7 @@ static void process_state_iv_eor(t30_state_t *s, const uint8_t *msg, int len) break; case T30_ERR: /* TODO: Continue with the next message if MPS or EOM? */ + s->current_status = T30_ERR_RETRYDCN; s->timer_t5 = 0; send_dcn(s); break; @@ -4319,6 +4320,7 @@ static void process_state_iv_eor_rnr(t30_state_t *s, const uint8_t *msg, int len break; case T30_ERR: /* TODO: Continue with the next message if MPS or EOM? */ + s->current_status = T30_ERR_RETRYDCN; s->timer_t5 = 0; send_dcn(s); break; From ced63c35167d5f6c52583b5e70da1b2cf669c8ef Mon Sep 17 00:00:00 2001 From: cypromis Date: Mon, 3 Jan 2011 11:40:49 +0100 Subject: [PATCH 50/66] added postgresql cdr module to modules.conf.in (commented out ) added sqlite cdr module to modules.conf.in (built by default) --- build/modules.conf.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build/modules.conf.in b/build/modules.conf.in index bd5d49a7ad..69d90a8dd4 100644 --- a/build/modules.conf.in +++ b/build/modules.conf.in @@ -73,6 +73,8 @@ endpoints/mod_loopback #event_handlers/mod_event_multicast event_handlers/mod_event_socket event_handlers/mod_cdr_csv +event_handlers/mod_cdr_sqlite +#event_handlers/mod_cdr_pg_csv #event_handlers/mod_radius_cdr #event_handlers/mod_erlang_event formats/mod_native_file From 45a32dda3d09878fe07659002fd192ed8dca3575 Mon Sep 17 00:00:00 2001 From: cypromis Date: Mon, 3 Jan 2011 11:58:15 +0100 Subject: [PATCH 51/66] added -lgpg-error to sun compiler CXXFLAGS for iksemel library and tools to be build corretly in libiksemel configure.ac --- libs/iksemel/configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/iksemel/configure.ac b/libs/iksemel/configure.ac index f7687922c2..1b8af13683 100644 --- a/libs/iksemel/configure.ac +++ b/libs/iksemel/configure.ac @@ -84,7 +84,7 @@ AC_ARG_ENABLE(64, if test "x${ax_cv_c_compiler_vendor}" = "xsun" ; then if test "${enable_64}" = "yes"; then CFLAGS="$CFLAGS -m64" - CXXFLAGS="$CXXFLAGS -m64" + CXXFLAGS="$CXXFLAGS -m64 -lgpg-error" fi fi From 09e6fd3f4ee5069491034fb150405fe7ad61fe3f Mon Sep 17 00:00:00 2001 From: Leon de Rooij Date: Mon, 3 Jan 2011 12:20:06 +0100 Subject: [PATCH 52/66] Make dbh:connected accessible from Lua - thanks Grmt --- src/mod/languages/mod_lua/freeswitch.i | 3 ++- src/mod/languages/mod_lua/freeswitch_lua.cpp | 15 +++++++---- src/mod/languages/mod_lua/freeswitch_lua.h | 3 ++- src/mod/languages/mod_lua/mod_lua_wrap.cpp | 26 ++++++++++++++++++++ 4 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/mod/languages/mod_lua/freeswitch.i b/src/mod/languages/mod_lua/freeswitch.i index 54bdb7bdc9..cea764d9d6 100644 --- a/src/mod/languages/mod_lua/freeswitch.i +++ b/src/mod/languages/mod_lua/freeswitch.i @@ -82,12 +82,13 @@ class Session : public CoreSession { class Dbh { private: switch_cache_db_handle_t *dbh; - bool connected; + bool m_connected; static int query_callback(void *pArg, int argc, char **argv, char **cargv); public: Dbh(char *dsn, char *user = NULL, char *pass = NULL); ~Dbh(); bool release(); + bool connected(); bool query(char *sql, SWIGLUA_FN lua_fun); }; diff --git a/src/mod/languages/mod_lua/freeswitch_lua.cpp b/src/mod/languages/mod_lua/freeswitch_lua.cpp index d60ae737a8..aad87fa6c1 100644 --- a/src/mod/languages/mod_lua/freeswitch_lua.cpp +++ b/src/mod/languages/mod_lua/freeswitch_lua.cpp @@ -318,9 +318,9 @@ Dbh::Dbh(char *dsn, char *user, char *pass) options.odbc_options.pass = pass; if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_ODBC, &options) == SWITCH_STATUS_SUCCESS) { - connected = true; + m_connected = true; } else { - connected = false; + m_connected = false; } } @@ -331,14 +331,19 @@ Dbh::~Dbh() bool Dbh::release() { - if (connected) { + if (m_connected) { switch_cache_db_release_db_handle(&dbh); - connected = false; + m_connected = false; return true; } return false; } +bool Dbh::connected() +{ + return m_connected; +} + int Dbh::query_callback(void *pArg, int argc, char **argv, char **cargv) { SWIGLUA_FN *lua_fun = (SWIGLUA_FN *)pArg; @@ -366,7 +371,7 @@ int Dbh::query_callback(void *pArg, int argc, char **argv, char **cargv) bool Dbh::query(char *sql, SWIGLUA_FN lua_fun) { - if (connected) { + if (m_connected) { if (lua_fun.L) { if (switch_cache_db_execute_sql_callback(dbh, sql, query_callback, &lua_fun, NULL) == SWITCH_STATUS_SUCCESS) { return true; diff --git a/src/mod/languages/mod_lua/freeswitch_lua.h b/src/mod/languages/mod_lua/freeswitch_lua.h index a0780b1537..3c43ebdd9f 100644 --- a/src/mod/languages/mod_lua/freeswitch_lua.h +++ b/src/mod/languages/mod_lua/freeswitch_lua.h @@ -55,12 +55,13 @@ namespace LUA { class Dbh { protected: switch_cache_db_handle_t *dbh; - bool connected; + bool m_connected; static int query_callback(void *pArg, int argc, char **argv, char **cargv); public: Dbh(char *dsn, char *user = NULL, char *pass = NULL); ~Dbh(); bool release(); + bool connected(); bool query(char *sql, SWIGLUA_FN lua_fun); }; } diff --git a/src/mod/languages/mod_lua/mod_lua_wrap.cpp b/src/mod/languages/mod_lua/mod_lua_wrap.cpp index d32646654c..4e2971098b 100644 --- a/src/mod/languages/mod_lua/mod_lua_wrap.cpp +++ b/src/mod/languages/mod_lua/mod_lua_wrap.cpp @@ -7229,6 +7229,31 @@ fail: } +static int _wrap_Dbh_connected(lua_State* L) { + int SWIG_arg = -1; + LUA::Dbh *arg1 = (LUA::Dbh *) 0 ; + bool result; + + SWIG_check_num_args("connected",1,1) + if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("connected",1,"LUA::Dbh *"); + + if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_LUA__Dbh,0))){ + SWIG_fail_ptr("Dbh_connected",1,SWIGTYPE_p_LUA__Dbh); + } + + result = (bool)(arg1)->connected(); + SWIG_arg=0; + lua_pushboolean(L,(int)(result==true)); SWIG_arg++; + return SWIG_arg; + + if(0) SWIG_fail; + +fail: + lua_error(L); + return SWIG_arg; +} + + static int _wrap_Dbh_query(lua_State* L) { int SWIG_arg = -1; LUA::Dbh *arg1 = (LUA::Dbh *) 0 ; @@ -7277,6 +7302,7 @@ delete arg1; } static swig_lua_method swig_LUA_Dbh_methods[] = { {"release", _wrap_Dbh_release}, + {"connected", _wrap_Dbh_connected}, {"query", _wrap_Dbh_query}, {0,0} }; From 2632af929d8c63447a482e16ca92f6d2c5dc1ebf Mon Sep 17 00:00:00 2001 From: Daniel Swarbrick Date: Mon, 3 Jan 2011 12:52:11 +0100 Subject: [PATCH 53/66] FS-2953 --- src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c b/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c index 275fec1396..45951f68bf 100644 --- a/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c +++ b/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c @@ -213,7 +213,7 @@ static switch_status_t save_cdr(const char * const template, const char * const /* * In the expanded vars, replace double quotes (") with single quotes (') - * for corect PostgreSQL syntax, and replace semi-colon with space to + * for correct PostgreSQL syntax, and replace semi-colon with space to * prevent SQL injection attacks. */ values = strdup(cdr); @@ -231,7 +231,7 @@ static switch_status_t save_cdr(const char * const template, const char * const /* * Patch for changing empty strings ('') in the expanded variables to - * Postgresql null + * PostgreSQL null */ for (p = values; *p; ++p) { if (*p == ',') { From 8ecf30807556ee3f614f4f2e5181dc5bbfbfdf81 Mon Sep 17 00:00:00 2001 From: cypromis Date: Mon, 3 Jan 2011 13:06:25 +0100 Subject: [PATCH 54/66] fix basops32.c make the file contain something even if ifdefs fail (which makes suncc fail) --- libs/libg722_1/src/basop32.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/libg722_1/src/basop32.c b/libs/libg722_1/src/basop32.c index 210e1296ec..3a51f45eee 100644 --- a/libs/libg722_1/src/basop32.c +++ b/libs/libg722_1/src/basop32.c @@ -17,9 +17,10 @@ #include #endif +#include + #if defined(G722_1_USE_FIXED_POINT) -#include #include #include From 935f2c42141eb78c3fd13ace50900bd99b905dd0 Mon Sep 17 00:00:00 2001 From: Daniel Swarbrick Date: Mon, 3 Jan 2011 13:25:46 +0100 Subject: [PATCH 55/66] mod_cdr_sqlite has no need for (yet) for SIGHUP --- src/mod/event_handlers/mod_cdr_sqlite/mod_cdr_sqlite.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/mod/event_handlers/mod_cdr_sqlite/mod_cdr_sqlite.c b/src/mod/event_handlers/mod_cdr_sqlite/mod_cdr_sqlite.c index 534f18f2ca..1eae1ab12f 100644 --- a/src/mod/event_handlers/mod_cdr_sqlite/mod_cdr_sqlite.c +++ b/src/mod/event_handlers/mod_cdr_sqlite/mod_cdr_sqlite.c @@ -173,10 +173,6 @@ static void event_handler(switch_event_t *event) if (globals.shutdown) { return; } - - if (sig && !strcmp(sig, "HUP")) { - /* Should we do something on SIG_HUP? */ - } } From 93bbbe96af98a6e4ab2ae5a48e68690b44bc103c Mon Sep 17 00:00:00 2001 From: Daniel Swarbrick Date: Mon, 3 Jan 2011 13:36:20 +0100 Subject: [PATCH 56/66] Remove event_handler() altogether, since it was doing nothing anyway --- .../mod_cdr_sqlite/mod_cdr_sqlite.c | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/mod/event_handlers/mod_cdr_sqlite/mod_cdr_sqlite.c b/src/mod/event_handlers/mod_cdr_sqlite/mod_cdr_sqlite.c index 1eae1ab12f..efb544e049 100644 --- a/src/mod/event_handlers/mod_cdr_sqlite/mod_cdr_sqlite.c +++ b/src/mod/event_handlers/mod_cdr_sqlite/mod_cdr_sqlite.c @@ -166,16 +166,6 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) } -static void event_handler(switch_event_t *event) -{ - const char *sig = switch_event_get_header(event, "Trapped-Signal"); - - if (globals.shutdown) { - return; - } -} - - static switch_state_handler_table_t state_handlers = { /*.on_init */ NULL, /*.on_routing */ NULL, @@ -290,11 +280,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_cdr_sqlite_load) load_config(pool); - if ((status = switch_event_bind(modname, SWITCH_EVENT_TRAP, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL)) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n"); - return status; - } - switch_core_add_state_handler(&state_handlers); *module_interface = switch_loadable_module_create_module_interface(pool, modname); @@ -305,7 +290,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_cdr_sqlite_load) SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cdr_sqlite_shutdown) { globals.shutdown = 1; - switch_event_unbind_callback(event_handler); switch_core_remove_state_handler(&state_handlers); return SWITCH_STATUS_SUCCESS; From aab453f52a37cfc43230e67c713ff7d605e7dd16 Mon Sep 17 00:00:00 2001 From: Daniel Swarbrick Date: Mon, 3 Jan 2011 14:01:08 +0100 Subject: [PATCH 57/66] tweak create.sql and config file --- conf/autoload_configs/cdr_pg_csv.conf.xml | 7 +++-- .../event_handlers/mod_cdr_pg_csv/create.sql | 26 ++----------------- .../mod_cdr_pg_csv/mod_cdr_pg_csv.c | 1 - 3 files changed, 5 insertions(+), 29 deletions(-) diff --git a/conf/autoload_configs/cdr_pg_csv.conf.xml b/conf/autoload_configs/cdr_pg_csv.conf.xml index bddd387b70..e17809780c 100644 --- a/conf/autoload_configs/cdr_pg_csv.conf.xml +++ b/conf/autoload_configs/cdr_pg_csv.conf.xml @@ -1,8 +1,5 @@ - - - @@ -10,6 +7,9 @@ + + + @@ -17,4 +17,3 @@ - diff --git a/src/mod/event_handlers/mod_cdr_pg_csv/create.sql b/src/mod/event_handlers/mod_cdr_pg_csv/create.sql index 83cfec1ec7..9a39b0b57f 100644 --- a/src/mod/event_handlers/mod_cdr_pg_csv/create.sql +++ b/src/mod/event_handlers/mod_cdr_pg_csv/create.sql @@ -1,5 +1,6 @@ +-- Sample CDR table schema -create table a ( +create table cdr ( id serial primary key, local_ip_v4 inet not null, caller_id_name varchar, @@ -20,26 +21,3 @@ create table a ( sip_hangup_disposition varchar, ani varchar ); - -create table g ( - id serial primary key, - local_ip_v4 inet not null, - caller_id_name varchar, - caller_id_number varchar, - destination_number varchar not null, - context varchar not null, - start_stamp timestamp with time zone not null, - answer_stamp timestamp with time zone, - end_stamp timestamp with time zone not null, - duration int not null, - billsec int not null, - hangup_cause varchar not null, - uuid uuid not null, - bleg_uuid uuid, - accountcode varchar, - read_codec varchar, - write_codec varchar, - sip_hangup_disposition varchar, - ani varchar -); - diff --git a/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c b/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c index 45951f68bf..9da7c9dfcb 100644 --- a/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c +++ b/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c @@ -457,7 +457,6 @@ static void event_handler(switch_event_t *event) PQfinish(globals.db_connection); globals.db_online = 0; } - } } From 80f3281c095f772b32eb1e042d267a089204b8e5 Mon Sep 17 00:00:00 2001 From: Daniel Swarbrick Date: Mon, 3 Jan 2011 15:05:24 +0100 Subject: [PATCH 58/66] whitespace fixups --- .../mod_cdr_sqlite/mod_cdr_sqlite.c | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/mod/event_handlers/mod_cdr_sqlite/mod_cdr_sqlite.c b/src/mod/event_handlers/mod_cdr_sqlite/mod_cdr_sqlite.c index efb544e049..b3334fea97 100644 --- a/src/mod/event_handlers/mod_cdr_sqlite/mod_cdr_sqlite.c +++ b/src/mod/event_handlers/mod_cdr_sqlite/mod_cdr_sqlite.c @@ -38,8 +38,8 @@ typedef enum { } cdr_leg_t; static char default_create_sql[] = - "CREATE TABLE %s (\n" - " caller_id_name VARCHAR,\n" + "CREATE TABLE %s (\n" + " caller_id_name VARCHAR,\n" " caller_id_number VARCHAR,\n" " destination_number VARCHAR,\n" " context VARCHAR,\n" @@ -77,8 +77,8 @@ SWITCH_MODULE_DEFINITION(mod_cdr_sqlite, mod_cdr_sqlite_load, mod_cdr_sqlite_shu switch_cache_db_handle_t *cdr_get_db_handle(void) { - switch_cache_db_connection_options_t options = { {0} }; - switch_cache_db_handle_t *dbh = NULL; + switch_cache_db_connection_options_t options = { {0} }; + switch_cache_db_handle_t *dbh = NULL; options.core_db_options.db_path = globals.db_name; if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_CORE_DB, &options) != SWITCH_STATUS_SUCCESS) @@ -89,22 +89,22 @@ switch_cache_db_handle_t *cdr_get_db_handle(void) static switch_status_t write_cdr(char *sql) { - switch_cache_db_handle_t *dbh = NULL; - switch_status_t status = SWITCH_STATUS_FALSE; + switch_cache_db_handle_t *dbh = NULL; + switch_status_t status = SWITCH_STATUS_FALSE; - if (!(dbh = cdr_get_db_handle())) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n"); - goto end; - } + if (!(dbh = cdr_get_db_handle())) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n"); + goto end; + } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Writing SQL to DB: %s\n", sql); - status = switch_cache_db_execute_sql(dbh, sql, NULL); + status = switch_cache_db_execute_sql(dbh, sql, NULL); end: - switch_cache_db_release_db_handle(&dbh); + switch_cache_db_release_db_handle(&dbh); - return status; + return status; } From 7b28994121b820e24c48e80c11ff5149f16245d3 Mon Sep 17 00:00:00 2001 From: Brian West Date: Mon, 3 Jan 2011 10:44:28 -0600 Subject: [PATCH 59/66] FS-502: gateway not identified when extension-in-contact is set --- src/mod/endpoints/mod_sofia/sofia.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 94eab68858..9e412bbbb7 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -6844,11 +6844,19 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ if (sip->sip_request->rq_url->url_params) { - gw_name = sofia_glue_find_parameter(sip->sip_request->rq_url->url_params, "gw="); + gw_name = sofia_glue_find_parameter_value(session, sip->sip_request->rq_url->url_params, "gw="); } if (strstr(destination_number, "gw+")) { - gw_name = destination_number + 3; + if (sofia_test_pflag(profile, PFLAG_FULL_ID)) { + char *tmp; + gw_name = switch_core_session_strdup(session, destination_number + 3); + if ((tmp = strchr(gw_name, '@'))) { + *tmp = '\0'; + } + } else { + gw_name = destination_number + 3; + } } if (gw_name) { From a3d66bb4f075cb8b073aac6a84f3651ebec9aadd Mon Sep 17 00:00:00 2001 From: Daniel Swarbrick Date: Mon, 3 Jan 2011 18:59:41 +0100 Subject: [PATCH 60/66] mod_cdr_pg_csv: make disk spool format user-selectable --- conf/autoload_configs/cdr_pg_csv.conf.xml | 2 + .../mod_cdr_pg_csv/mod_cdr_pg_csv.c | 53 ++++++++++++------- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/conf/autoload_configs/cdr_pg_csv.conf.xml b/conf/autoload_configs/cdr_pg_csv.conf.xml index e17809780c..2f2efa9b26 100644 --- a/conf/autoload_configs/cdr_pg_csv.conf.xml +++ b/conf/autoload_configs/cdr_pg_csv.conf.xml @@ -9,6 +9,8 @@ + + diff --git a/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c b/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c index 9da7c9dfcb..fba5f86728 100644 --- a/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c +++ b/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c @@ -67,6 +67,7 @@ static struct { cdr_leg_t legs; char *db_info; char *db_table; + char *spool_format; PGconn *db_connection; int db_online; switch_mutex_t *db_mutex; @@ -141,6 +142,7 @@ static void do_rotate(cdr_fd_t *fd) static void write_cdr(const char *path, const char *log_line) { cdr_fd_t *fd = NULL; + char *log_line_lf = NULL; unsigned int bytes_in, bytes_out; int loops = 0; @@ -154,8 +156,17 @@ static void write_cdr(const char *path, const char *log_line) switch_core_hash_insert(globals.fd_hash, path, fd); } + if (end_of(log_line) != '\n') { + size_t len = strlen(log_line) + 2; + log_line_lf = switch_core_alloc(globals.pool, len); + switch_snprintf(log_line_lf, len, "%s\n", log_line); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Adding LF to log_line.\n"); + } else { + log_line_lf = switch_core_strdup(globals.pool, log_line); + } + switch_mutex_lock(fd->mutex); - bytes_out = (unsigned) strlen(log_line); + bytes_out = (unsigned) strlen(log_line_lf); if (fd->fd < 0) { do_reopen(fd); @@ -169,7 +180,7 @@ static void write_cdr(const char *path, const char *log_line) do_rotate(fd); } - while ((bytes_in = write(fd->fd, log_line, bytes_out)) != bytes_out && ++loops < 10) { + while ((bytes_in = write(fd->fd, log_line_lf, bytes_out)) != bytes_out && ++loops < 10) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Write error to file %s %d/%d\n", path, (int) bytes_in, (int) bytes_out); do_rotate(fd); switch_yield(250000); @@ -184,7 +195,7 @@ static void write_cdr(const char *path, const char *log_line) switch_mutex_unlock(fd->mutex); } -static switch_status_t save_cdr(const char * const template, const char * const cdr, const char * const log_dir) +static switch_status_t save_cdr(const char * const template, const char * const cdr) { char *columns, *values; char *p, *q; @@ -214,7 +225,7 @@ static switch_status_t save_cdr(const char * const template, const char * const /* * In the expanded vars, replace double quotes (") with single quotes (') * for correct PostgreSQL syntax, and replace semi-colon with space to - * prevent SQL injection attacks. + * prevent SQL injection attacks */ values = strdup(cdr); for (p = values; *p; ++p) { @@ -309,9 +320,7 @@ static switch_status_t save_cdr(const char * const template, const char * const values = nullValues; free(tp); - //----------------------------- END_OF_PATCH ------------------------------- - - sql = switch_mprintf("INSERT INTO %s (%s) VALUES (%s);\n", globals.db_table, columns, values); + sql = switch_mprintf("INSERT INTO %s (%s) VALUES (%s);", globals.db_table, columns, values); assert(sql); free(columns); free(values); @@ -355,22 +364,27 @@ static switch_status_t save_cdr(const char * const template, const char * const switch_mutex_unlock(globals.db_mutex); /* SQL INSERT failed for whatever reason. Spool the attempted query to disk */ - path = switch_mprintf("%s%scdr-spool.sql", log_dir, SWITCH_PATH_SEPARATOR); - assert(path); - write_cdr(path, sql); + if (!strcasecmp(globals.spool_format, "sql")) { + path = switch_mprintf("%s%scdr-spool.sql", globals.log_dir, SWITCH_PATH_SEPARATOR); + assert(path); + write_cdr(path, sql); + } else { + path = switch_mprintf("%s%scdr-spool.csv", globals.log_dir, SWITCH_PATH_SEPARATOR); + assert(path); + write_cdr(path, cdr); + } free(path); free(sql); return SWITCH_STATUS_FALSE; - } static switch_status_t my_on_reporting(switch_core_session_t *session) { switch_channel_t *channel = switch_core_session_get_channel(session); switch_status_t status = SWITCH_STATUS_SUCCESS; - const char *log_dir = NULL, *template_str = NULL; + const char *template_str = NULL; char *expanded_vars = NULL; if (globals.shutdown) { @@ -389,12 +403,8 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) } } - if (!(log_dir = switch_channel_get_variable(channel, "cdr_pg_csv_base"))) { - log_dir = globals.log_dir; - } - - if (switch_dir_make_recursive(log_dir, SWITCH_DEFAULT_DIR_PERMS, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating %s\n", log_dir); + if (switch_dir_make_recursive(globals.log_dir, SWITCH_DEFAULT_DIR_PERMS, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating %s\n", globals.log_dir); return SWITCH_STATUS_FALSE; } @@ -424,7 +434,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) return SWITCH_STATUS_FALSE; } - save_cdr(template_str, expanded_vars, log_dir); + save_cdr(template_str, expanded_vars); if (expanded_vars != template_str) { free(expanded_vars); @@ -528,6 +538,8 @@ static switch_status_t load_config(switch_memory_pool_t *pool) globals.db_table = switch_core_strdup(pool, val); } else if (!strcasecmp(var, "default-template")) { globals.default_template = switch_core_strdup(pool, val); + } else if (!strcasecmp(var, "spool-format")) { + globals.spool_format = switch_core_strdup(pool, val); } } } @@ -563,6 +575,9 @@ static switch_status_t load_config(switch_memory_pool_t *pool) globals.default_template = switch_core_strdup(pool, "default"); } + if (zstr(globals.spool_format)) { + globals.spool_format = switch_core_strdup(pool, "csv"); + } return status; } From 66ce95a93049404324a382d307730c3aa4a1e443 Mon Sep 17 00:00:00 2001 From: Daniel Swarbrick Date: Mon, 3 Jan 2011 19:10:15 +0100 Subject: [PATCH 61/66] removing my debug :o --- src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c b/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c index fba5f86728..9f4260ddbb 100644 --- a/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c +++ b/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c @@ -160,7 +160,6 @@ static void write_cdr(const char *path, const char *log_line) size_t len = strlen(log_line) + 2; log_line_lf = switch_core_alloc(globals.pool, len); switch_snprintf(log_line_lf, len, "%s\n", log_line); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Adding LF to log_line.\n"); } else { log_line_lf = switch_core_strdup(globals.pool, log_line); } From df090a2a6b1042b8c575ecce241c021e16a792be Mon Sep 17 00:00:00 2001 From: Daniel Swarbrick Date: Mon, 3 Jan 2011 21:39:36 +0100 Subject: [PATCH 62/66] free() -> switch_safe_free() --- .../mod_cdr_pg_csv/mod_cdr_pg_csv.c | 18 +++++++++--------- .../mod_cdr_sqlite/mod_cdr_sqlite.c | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c b/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c index 9f4260ddbb..e515f8db19 100644 --- a/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c +++ b/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c @@ -121,7 +121,7 @@ static void do_rotate(cdr_fd_t *fd) p = switch_mprintf("%s.%s", fd->path, date); assert(p); switch_file_rename(fd->path, p, globals.pool); - free(p); + switch_safe_free(p); } do_reopen(fd); @@ -317,12 +317,12 @@ static switch_status_t save_cdr(const char * const template, const char * const *tp = 0; tp = values; values = nullValues; - free(tp); + switch_safe_free(tp); sql = switch_mprintf("INSERT INTO %s (%s) VALUES (%s);", globals.db_table, columns, values); assert(sql); - free(columns); - free(values); + switch_safe_free(columns); + switch_safe_free(values); if (globals.debug) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Query: \"%s\"\n", sql); @@ -349,7 +349,7 @@ static switch_status_t save_cdr(const char * const template, const char * const } PQclear(res); - free(sql); + switch_safe_free(sql); switch_mutex_unlock(globals.db_mutex); @@ -373,8 +373,8 @@ static switch_status_t save_cdr(const char * const template, const char * const write_cdr(path, cdr); } - free(path); - free(sql); + switch_safe_free(path); + switch_safe_free(sql); return SWITCH_STATUS_FALSE; } @@ -416,7 +416,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) switch_assert(buf); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "CHANNEL_DATA:\n%s\n", buf); switch_event_destroy(&event); - free(buf); + switch_safe_free(buf); } } @@ -436,7 +436,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) save_cdr(template_str, expanded_vars); if (expanded_vars != template_str) { - free(expanded_vars); + switch_safe_free(expanded_vars); } return status; diff --git a/src/mod/event_handlers/mod_cdr_sqlite/mod_cdr_sqlite.c b/src/mod/event_handlers/mod_cdr_sqlite/mod_cdr_sqlite.c index b3334fea97..1b91f1242a 100644 --- a/src/mod/event_handlers/mod_cdr_sqlite/mod_cdr_sqlite.c +++ b/src/mod/event_handlers/mod_cdr_sqlite/mod_cdr_sqlite.c @@ -140,7 +140,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) switch_assert(buf); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "CHANNEL_DATA:\n%s\n", buf); switch_event_destroy(&event); - free(buf); + switch_safe_free(buf); } } @@ -160,7 +160,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) sql = switch_mprintf("INSERT INTO %s VALUES (%s)", globals.db_table, expanded_vars); assert(sql); write_cdr(sql); - free(sql); + switch_safe_free(sql); return status; } @@ -264,8 +264,8 @@ static switch_status_t load_config(switch_memory_pool_t *pool) /* Check if table exists (try SELECT FROM ...) and create table if query fails */ switch_cache_db_test_reactive(dbh, select_sql, NULL, create_sql); - free(select_sql); - free(create_sql); + switch_safe_free(select_sql); + switch_safe_free(create_sql); switch_cache_db_release_db_handle(&dbh); } From 8b7fd76d3de084e581e994ffa171d1f6653a4d55 Mon Sep 17 00:00:00 2001 From: Daniel Swarbrick Date: Mon, 3 Jan 2011 22:09:46 +0100 Subject: [PATCH 63/66] use switch_zmalloc() instead of apr pools for short term storage, rename a couple of funcs to be clearer as to their purpose --- .../mod_cdr_pg_csv/mod_cdr_pg_csv.c | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c b/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c index e515f8db19..9cc1d8cf2c 100644 --- a/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c +++ b/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c @@ -139,7 +139,7 @@ static void do_rotate(cdr_fd_t *fd) } -static void write_cdr(const char *path, const char *log_line) +static void spool_cdr(const char *path, const char *log_line) { cdr_fd_t *fd = NULL; char *log_line_lf = NULL; @@ -157,12 +157,11 @@ static void write_cdr(const char *path, const char *log_line) } if (end_of(log_line) != '\n') { - size_t len = strlen(log_line) + 2; - log_line_lf = switch_core_alloc(globals.pool, len); - switch_snprintf(log_line_lf, len, "%s\n", log_line); + log_line_lf = switch_mprintf("%s\n", log_line); } else { - log_line_lf = switch_core_strdup(globals.pool, log_line); + switch_strdup(log_line_lf, log_line); } + assert(log_line_lf); switch_mutex_lock(fd->mutex); bytes_out = (unsigned) strlen(log_line_lf); @@ -192,9 +191,10 @@ static void write_cdr(const char *path, const char *log_line) end: switch_mutex_unlock(fd->mutex); + switch_safe_free(log_line_lf); } -static switch_status_t save_cdr(const char * const template, const char * const cdr) +static switch_status_t insert_cdr(const char * const template, const char * const cdr) { char *columns, *values; char *p, *q; @@ -210,7 +210,7 @@ static switch_status_t save_cdr(const char * const template, const char * const } /* Build comma-separated list of field names by dropping $ { } ; chars */ - columns = strdup(template); + switch_strdup(columns, template); for (p = columns, q = columns; *p; ++p) { switch (*p) { case '$': case '"': case '{': case '}': case ';': @@ -226,7 +226,7 @@ static switch_status_t save_cdr(const char * const template, const char * const * for correct PostgreSQL syntax, and replace semi-colon with space to * prevent SQL injection attacks */ - values = strdup(cdr); + switch_strdup(values, cdr); for (p = values; *p; ++p) { switch(*p) { case '"': @@ -260,7 +260,7 @@ static switch_status_t save_cdr(const char * const template, const char * const nullCounter *= 4; vlen += nullCounter; - nullValues = (char *) malloc(strlen(values) + nullCounter + 1); + switch_zmalloc(nullValues, strlen(values) + nullCounter + 1); charCounter = 0; temp = nullValues; tp = nullValues; @@ -366,11 +366,11 @@ static switch_status_t save_cdr(const char * const template, const char * const if (!strcasecmp(globals.spool_format, "sql")) { path = switch_mprintf("%s%scdr-spool.sql", globals.log_dir, SWITCH_PATH_SEPARATOR); assert(path); - write_cdr(path, sql); + spool_cdr(path, sql); } else { path = switch_mprintf("%s%scdr-spool.csv", globals.log_dir, SWITCH_PATH_SEPARATOR); assert(path); - write_cdr(path, cdr); + spool_cdr(path, cdr); } switch_safe_free(path); @@ -433,7 +433,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) return SWITCH_STATUS_FALSE; } - save_cdr(template_str, expanded_vars); + insert_cdr(template_str, expanded_vars); if (expanded_vars != template_str) { switch_safe_free(expanded_vars); From fc77d19b7bc6c64eadbd37f9715a79431f897379 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 3 Jan 2011 16:40:49 -0600 Subject: [PATCH 64/66] presence.... again.... --- src/mod/endpoints/mod_sofia/mod_sofia.h | 1 + src/mod/endpoints/mod_sofia/sofia_reg.c | 29 ++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 5fd6cd7963..8c6b1e0830 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -1035,6 +1035,7 @@ void sofia_profile_destroy(sofia_profile_t *profile); switch_status_t sip_dig_function(_In_opt_z_ const char *cmd, _In_opt_ switch_core_session_t *session, _In_ switch_stream_handle_t *stream); const char *sofia_gateway_status_name(sofia_gateway_status_t status); void sofia_reg_fire_custom_gateway_state_event(sofia_gateway_t *gateway, int status, const char *phrase); +uint32_t sofia_reg_reg_count(sofia_profile_t *profile, const char *user, const char *host); void sofia_glue_copy_t38_options(switch_t38_options_t *t38_options, switch_core_session_t *session); switch_t38_options_t *sofia_glue_extract_t38_options(switch_core_session_t *session, const char *r_sdp); char *sofia_glue_get_multipart(switch_core_session_t *session, const char *prefix, const char *sdp, char **mp_type); diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index 961eaa3ea0..1589eeb8e1 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -817,6 +817,19 @@ void sofia_reg_auth_challenge(nua_t *nua, sofia_profile_t *profile, nua_handle_t switch_safe_free(auth_str); } +uint32_t sofia_reg_reg_count(sofia_profile_t *profile, const char *user, const char *host) +{ + char buf[32] = ""; + char *sql; + + sql = switch_mprintf("select count(*) from sip_registrations where profile_name='%q' and " + "sip_user='%q' and (sip_host='%q' or presence_hosts like '%%%q%%')", profile->name, user, host, host); + + sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, buf, sizeof(buf)); + switch_safe_free(sql); + return atoi(buf); +} + uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sip_t const *sip, sofia_regtype_t regtype, char *key, uint32_t keylen, switch_event_t **v_event, const char *is_nat) { @@ -1298,6 +1311,12 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE); } + if (sofia_reg_reg_count(profile, to_user, reg_host) == 1) { + sql = switch_mprintf("delete from sip_presence where sip_user='%q' and sip_host='%q' and profile_name='%q' and open_closed='closed'", + to_user, reg_host, profile->name); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "DELETE PRESENCE SQL: %s\n", sql); + sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE); + } switch_mutex_unlock(profile->ireg_mutex); @@ -1361,8 +1380,16 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand } else { + int send = 1; - if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) { + if (multi_reg) { + if (sofia_reg_reg_count(profile, to_user, sub_host) > 0) { + send = 0; + } + } + + + if (send && switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", rpid); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", profile->url); From e6070feeab6940a3566a59a7802f003fa4181093 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 3 Jan 2011 16:48:10 -0600 Subject: [PATCH 65/66] cleanup --- src/mod/endpoints/mod_sofia/sofia_presence.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index 68296052e6..04d5b0142e 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -2645,14 +2645,7 @@ void sofia_presence_handle_sip_i_publish(nua_t *nua, sofia_profile_t *profile, n if (sofia_test_pflag(profile, PFLAG_MULTIREG) && !open) { - char buf[32] = ""; - - sql = switch_mprintf("select count(*) from sip_registrations where " - "sip_user='%q' and (sip_host='%q' or presence_hosts like '%%%q%%')", from_user, from_host, from_host); - - sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, buf, sizeof(buf)); - switch_safe_free(sql); - count = atoi(buf); + count = sofia_reg_reg_count(profile, from_user, from_host); } From 47c1b6d96ab853341efea272efe0ae5a60e97634 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 4 Jan 2011 14:23:25 -0500 Subject: [PATCH 66/66] freetdm: add validation to ftdm_span_start and ftdm_span_stop --- libs/freetdm/src/ftdm_io.c | 48 ++++++++++++++++--- libs/freetdm/src/include/private/ftdm_types.h | 2 +- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index efd52542a6..21354c4442 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -733,11 +733,28 @@ static void ftdm_span_add(ftdm_span_t *span) FT_DECLARE(ftdm_status_t) ftdm_span_stop(ftdm_span_t *span) { - ftdm_status_t status = FTDM_FAIL; - if (span->stop) { - status = span->stop(span); - span->stop = NULL; + ftdm_status_t status = FTDM_SUCCESS; + + ftdm_mutex_lock(span->mutex); + + if (!ftdm_test_flag(span, FTDM_SPAN_STARTED)) { + status = FTDM_EINVAL; + goto done; } + + if (!span->stop) { + status = FTDM_ENOSYS; + goto done; + } + + status = span->stop(span); + if (FTDM_SUCCESS == status) { + ftdm_clear_flag(span, FTDM_SPAN_STARTED); + } + +done: + ftdm_mutex_unlock(span->mutex); + return status; } @@ -5063,11 +5080,28 @@ FT_DECLARE(ftdm_status_t) ftdm_configure_span_signaling(ftdm_span_t *span, const FT_DECLARE(ftdm_status_t) ftdm_span_start(ftdm_span_t *span) { - if (span->start) { - return span->start(span); + ftdm_status_t status = FTDM_FAIL; + + ftdm_mutex_lock(span->mutex); + + if (ftdm_test_flag(span, FTDM_SPAN_STARTED)) { + status = FTDM_EINVAL; + goto done; } - return FTDM_FAIL; + if (!span->start) { + status = FTDM_ENOSYS; + goto done; + } + + status = span->start(span); + if (status == FTDM_SUCCESS) { + ftdm_set_flag_locked(span, FTDM_SPAN_STARTED); + } + +done: + ftdm_mutex_unlock(span->mutex); + return status; } FT_DECLARE(ftdm_status_t) ftdm_channel_add_to_group(const char* name, ftdm_channel_t* ftdmchan) diff --git a/libs/freetdm/src/include/private/ftdm_types.h b/libs/freetdm/src/include/private/ftdm_types.h index 2d683e3098..d79835733b 100644 --- a/libs/freetdm/src/include/private/ftdm_types.h +++ b/libs/freetdm/src/include/private/ftdm_types.h @@ -168,7 +168,7 @@ typedef enum { typedef enum { FTDM_SPAN_CONFIGURED = (1 << 0), - FTDM_SPAN_READY = (1 << 1), + FTDM_SPAN_STARTED = (1 << 1), FTDM_SPAN_STATE_CHANGE = (1 << 2), FTDM_SPAN_SUSPENDED = (1 << 3), FTDM_SPAN_IN_THREAD = (1 << 4),