提交 8e189ed2 authored 作者: Piotr Gregor's avatar Piotr Gregor

FS-9542 [avmd]: multithreaded

Now avmd detection is done in detector threads
processing audio frames with different resolution
and/or offsets. Detection decision is based on relative
standard deviation which dynamically adjusts to the signal.
Detection of amplitude, frequency and both simultaneously
is enabled and corresponding setting added to the configuration.
Frequency estimates are filtered with median filter.

This commit also resolves:
FS-9539 - Get estimates with different resolution
FS-9513 - Use adjustable thresholds
FS-9502 - Add detection mode setting
FS-9501 - Enable three modes of detection
FS-9407 - Add check of amplitude for NaN before appending to SMA buffer
FS-9139 - Unit test framework
上级 2b1f0da5
...@@ -37,13 +37,16 @@ ...@@ -37,13 +37,16 @@
<!-- required number of consecutive elements in the SMA buffer <!-- required number of consecutive elements in the SMA buffer
without reset. This parameter helps to avoid false beeps, bigger this value is without reset. This parameter helps to avoid false beeps, bigger this value is
smaller the probability of getting false detection --> smaller the probability of getting false detection -->
<param name="sample_n_continuous_streak" value="15"/> <param name="sample_n_continuous_streak" value="5"/>
<!-- define number of samples to skip starting from the beginning <!-- define number of samples to skip starting from the beginning
of the frame and/or after reset has happened. This serves the purpose of skipping first few of the frame and/or after reset has happened. This serves the purpose of skipping first few
estimations on each frame, as these estimations may be inaccurate. This parameter also helps estimations on each frame, as these estimations may be inaccurate. This parameter also helps
to give more robust detections when it's value is increased (up to scertain limit of about 60). --> to give more robust detections when it's value is increased (up to scertain limit of about 60). -->
<param name="sample_n_to_skip" value="15"/> <param name="sample_n_to_skip" value="0"/>
<param name="require_continuous_streak_amp" value="1"/>
<param name="sample_n_continuous_streak_amp" value="5"/>
<!-- define/undefine this to enable/disable simplified estimation <!-- define/undefine this to enable/disable simplified estimation
of frequency based on approximation of sin(x) with (x) of frequency based on approximation of sin(x) with (x)
...@@ -55,6 +58,10 @@ ...@@ -55,6 +58,10 @@
<!-- define/undefine to enable/disable avmd on external channel --> <!-- define/undefine to enable/disable avmd on external channel -->
<param name="outbound_channel" value="1"/> <param name="outbound_channel" value="1"/>
<!-- determines the mode of detection, default is both amplitude and frequency -->
<param name="detection_mode" value="2"/>
<!-- Per call settings end --> <!-- Per call settings end -->
</settings> </settings>
</configuration> </configuration>
......
...@@ -39,7 +39,7 @@ extern size_t next_power_of_2(size_t v); ...@@ -39,7 +39,7 @@ extern size_t next_power_of_2(size_t v);
{ \ { \
(b)->pos++; \ (b)->pos++; \
(b)->pos &= (b)->mask; \ (b)->pos &= (b)->mask; \
(b)->lpos++; \ (b)->lpos + 1 < 2 * (b)->buf_len ? (b)->lpos++ : (b)->lpos = (b)->buf_len; \
if ((b)->backlog < (b)->buf_len) (b)->backlog++; \ if ((b)->backlog < (b)->buf_len) (b)->backlog++; \
} }
......
...@@ -63,14 +63,14 @@ avmd_desa2_tweaked(circ_buffer_t *b, size_t i, double *amplitude) { ...@@ -63,14 +63,14 @@ avmd_desa2_tweaked(circ_buffer_t *b, size_t i, double *amplitude) {
we do simplified, modified for speed version : */ we do simplified, modified for speed version : */
result = n/d; result = n/d;
if (ISINF(result)) { /* if (ISINF(result)) {
*amplitude = 0.0; *amplitude = 0.0;
if (n < 0.0) { if (n < 0.0) {
return -10.0; return -10.0;
} else { } else {
return 10.0; return 10.0;
} }
} }*/
*amplitude = 2.0 * PSI_Xn / sqrt(PSI_Yn); *amplitude = 2.0 * PSI_Xn / sqrt(PSI_Yn);
return result; return result;
} }
...@@ -13,9 +13,9 @@ ...@@ -13,9 +13,9 @@
#define __AVMD_FIR_H__ #define __AVMD_FIR_H__
#define DESA_MAX(a, b) (a) > (b) ? (a) : (b) #define AVMD_MAX(a, b) (a) > (b) ? (a) : (b)
#define MEDIAN_FILTER(a, b, c) (a) > (b) ? ((a) > (c) ? \ #define AVMD_MEDIAN_FILTER(a, b, c) (a) > (b) ? ((a) > (c) ? \
DESA_MAX((b), (c)) : a) : ((b) > (c) ? DESA_MAX((a), (c)) : (b)) AVMD_MAX((b), (c)) : a) : ((b) > (c) ? AVMD_MAX((a), (c)) : (b))
#endif #endif
...@@ -46,7 +46,7 @@ typedef struct { ...@@ -46,7 +46,7 @@ typedef struct {
#define INC_SMA_POS(b) \ #define INC_SMA_POS(b) \
{ \ { \
(b)->lpos++; \ ((b)->lpos + 1 < 2 * (b)->len) ? ((b)->lpos++) : ((b)->lpos = (b)->len); \
(b)->pos = (b)->lpos % (b)->len; \ (b)->pos = (b)->lpos % (b)->len; \
} }
......
...@@ -37,13 +37,16 @@ ...@@ -37,13 +37,16 @@
<!-- required number of consecutive elements in the SMA buffer <!-- required number of consecutive elements in the SMA buffer
without reset. This parameter helps to avoid false beeps, bigger this value is without reset. This parameter helps to avoid false beeps, bigger this value is
smaller the probability of getting false detection --> smaller the probability of getting false detection -->
<param name="sample_n_continuous_streak" value="15"/> <param name="sample_n_continuous_streak" value="5"/>
<!-- define number of samples to skip starting from the beginning <!-- define number of samples to skip starting from the beginning
of the frame and/or after reset has happened. This serves the purpose of skipping first few of the frame and/or after reset has happened. This serves the purpose of skipping first few
estimations on each frame, as these estimations may be inaccurate. This parameter also helps estimations on each frame, as these estimations may be inaccurate. This parameter also helps
to give more robust detections when it's value is increased (up to scertain limit of about 60). --> to give more robust detections when it's value is increased (up to scertain limit of about 60). -->
<param name="sample_n_to_skip" value="15"/> <param name="sample_n_to_skip" value="0"/>
<param name="require_continuous_streak_amp" value="1"/>
<param name="sample_n_continuous_streak_amp" value="5"/>
<!-- define/undefine this to enable/disable simplified estimation <!-- define/undefine this to enable/disable simplified estimation
of frequency based on approximation of sin(x) with (x) of frequency based on approximation of sin(x) with (x)
...@@ -55,6 +58,10 @@ ...@@ -55,6 +58,10 @@
<!-- define/undefine to enable/disable avmd on external channel --> <!-- define/undefine to enable/disable avmd on external channel -->
<param name="outbound_channel" value="1"/> <param name="outbound_channel" value="1"/>
<!-- determines the mode of detection, default is both amplitude and frequency -->
<param name="detection_mode" value="2"/>
<!-- Per call settings end --> <!-- Per call settings end -->
</settings> </settings>
</configuration> </configuration>
......
#!/usr/bin/perl -w
#brief Subscribe to avmd events and print them to the console. #brief Subscribe to avmd events and print them to the console.
#author Piotr Gregor <piotrgregor@rsyncme.org> #author Piotr Gregor <piotrgregor@rsyncme.org>
#date 13 Sept 2016 09:44 PM #date 13 Sept 2016 09:44 PM
#!/usr/bin/perl $|++; # turn on autoflush
use strict; use strict;
use warnings; use warnings;
require ESL; require ESL;
my $host = "127.0.0.1"; my $host = "127.0.0.1";
my $port = "8021"; my $port = "8021";
my $pass = "ClueCon"; my $pass = "ClueCon";
......
#!/usr/bin/perl -w
#brief Call single voicemail available in default dialplan
# and print detection result to the console.
#author Piotr Gregor <piotrgregor@rsyncme.org>
#date 15 Sept 2016 02:44 PM
use strict;
use warnings;
require ESL;
use POSIX;
use Time::HiRes;
my $host = "127.0.0.1";
my $port = "8021";
my $pass = "ClueCon";
my $extension_base = "sofia/internal/1000\@192.168.1.60";
my $playback = 'local_stream://moh';
my $context = 'default';
my $endpoint;
my $dest;
my $callerid;
if ($#ARGV + 1 eq 2) {
$dest = $ARGV[0];
$callerid = $ARGV[1];
print "Dialing [" .$dest ."] as " .$callerid ."]\n";
} else {
die "Please specify destination number and caller id\n";
}
my $con = new ESL::ESLconnection($host, $port, $pass);
if (!$con) {
die "Unable to establish connection to $host:$port\n";
}
if ($con->connected()) {
print "OK, Connected.\n";
} else {
die "Connection failure.\n";
}
print "Subscribing to avmd events...\n";
$con->events("plain", "CUSTOM avmd::start");
$con->events("plain", "CUSTOM avmd::stop");
$con->events("plain", "CUSTOM avmd::beep");
while($con->connected()) {
test_once($dest, $callerid);
return 0;
}
print "Disconnected.\n\n";
sub test_once {
my ($dest, $callerid) = @_;
my $originate_string =
'originate ' .
'{ignore_early_media=true,' .
'origination_uuid=%s,' .
'originate_timeout=60,' .
'origination_caller_id_number=' . $callerid . ',' .
'origination_caller_id_name=' . $callerid . '}';
if(defined($endpoint)) {
$originate_string .= $endpoint;
} else {
$originate_string .= 'loopback/' . $dest . '/' . $context;
}
$originate_string .= ' ' . '&playback(' . $playback . ')';
my $uuid = $con->api('create_uuid')->getBody();
my ($time_epoch, $time_hires) = Time::HiRes::gettimeofday();
printf("Calling with uuid [%s] [%s]...\n", $uuid, POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime($time_epoch)), $time_hires);
$con->bgapi(sprintf($originate_string, $uuid));
print "Waiting for the events...\n\n";
while($con->connected()) {
my $e = $con->recvEvent();
if ($e) {
my $body = $e->serialize('plain');
print $body;
print "\n\n";
}
}
}
...@@ -4,8 +4,10 @@ ...@@ -4,8 +4,10 @@
#brief Test module avmd by calling all voicemails available #brief Test module avmd by calling all voicemails available
# in avmd test suite and print detection results to the console. # in avmd test suite and print detection results to the console.
#author Piotr Gregor <piotrgregor@rsyncme.org> #author Piotr Gregor <piotrgregor@rsyncme.org>
#details If you are testing locally - remember to set avmd to inbound mode, #details If you are testing serving voicemails from dialplan then avmd
# "avmd set inbound" in fs_cli. # must be set to inbound mode, either globally (by avmd set inbound
# in fs_cli) or in dialplan settings (<action application="avmd_start"
# data="inbound_channel=1,outbound_channel=0").
#date 15 Sept 2016 03:00 PM #date 15 Sept 2016 03:00 PM
...@@ -19,23 +21,99 @@ use Time::HiRes; ...@@ -19,23 +21,99 @@ use Time::HiRes;
# Hashtable of <destination number : test result expectation> pairs # Hashtable of <destination number : test result expectation> pairs
my %numbers = ( my %numbers = (
400 => "DETECTED", 503 => "NOTDETECTED", # dual frequency (similar to single freq with varying amplitude), mode [0] AVMD_DETECT_AMP
401 => "DETECTED", 504 => "NOTDETECTED",
402 => "DETECTED", 505 => "NOTDETECTED",
403 => "DETECTED", 506 => "NOTDETECTED",
404 => "DETECTED", 507 => "NOTDETECTED",
405 => "DETECTED", 508 => "NOTDETECTED",
406 => "DETECTED", 509 => "NOTDETECTED",
407 => "DETECTED", 510 => "NOTDETECTED",
408 => "DETECTED", 511 => "NOTDETECTED",
409 => "DETECTED", 512 => "NOTDETECTED",
410 => "DETECTED", 513 => "NOTDETECTED",
411 => "DETECTED", 514 => "NOTDETECTED",
412 => "DETECTED", 515 => "NOTDETECTED",
413 => "DETECTED", 516 => "NOTDETECTED",
414 => "DETECTED", 517 => "NOTDETECTED",
500 => "NOTDETECTED", 518 => "NOTDETECTED",
501 => "NOTDETECTED" 519 => "NOTDETECTED",
520 => "NOTDETECTED",
521 => "NOTDETECTED",
522 => "NOTDETECTED",
523 => "NOTDETECTED",
603 => "DETECTED", # dual frequency (similar to single freq with varying amplitude), mode [1] AVMD_DETECT_FREQ
604 => "DETECTED",
605 => "DETECTED",
606 => "DETECTED",
607 => "DETECTED",
608 => "DETECTED",
609 => "DETECTED",
610 => "DETECTED",
611 => "DETECTED",
612 => "DETECTED",
613 => "DETECTED",
614 => "DETECTED",
615 => "DETECTED",
616 => "DETECTED",
617 => "DETECTED",
618 => "DETECTED",
619 => "DETECTED",
620 => "DETECTED",
621 => "DETECTED",
622 => "DETECTED",
623 => "DETECTED",
703 => "NOTDETECTED", # dual frequency (similar to single freq with varying amplitude), mode [2] AVMD_DETECT_BOTH
704 => "NOTDETECTED",
705 => "NOTDETECTED",
706 => "NOTDETECTED",
707 => "NOTDETECTED",
708 => "NOTDETECTED",
709 => "NOTDETECTED",
710 => "NOTDETECTED",
711 => "NOTDETECTED",
712 => "NOTDETECTED",
713 => "NOTDETECTED",
714 => "NOTDETECTED",
715 => "NOTDETECTED",
716 => "NOTDETECTED",
717 => "NOTDETECTED",
718 => "NOTDETECTED",
719 => "NOTDETECTED",
720 => "NOTDETECTED",
721 => "NOTDETECTED",
722 => "NOTDETECTED",
723 => "NOTDETECTED",
840531000 => "DETECTED", # obscure voicemails, mode AVMD_DETECT_BOTH
840531001 => "DETECTED",
840531002 => "DETECTED",
840531003 => "DETECTED",
840531004 => "DETECTED",
840531005 => "DETECTED",
840531006 => "DETECTED",
840531007 => "DETECTED",
840531008 => "DETECTED",
840531009 => "DETECTED",
840531010 => "DETECTED",
840531011 => "DETECTED",
840531012 => "DETECTED",
840531013 => "DETECTED",
840531014 => "DETECTED",
840531200 => "DETECTED", # obscure voicemails, mode AVMD_DETECT_FREQ
840531201 => "DETECTED",
840531202 => "DETECTED",
840531203 => "DETECTED",
840531204 => "DETECTED",
840531205 => "DETECTED",
840531206 => "DETECTED",
840531207 => "DETECTED",
840531208 => "DETECTED",
840531209 => "DETECTED",
840531210 => "DETECTED",
840531211 => "DETECTED",
840531212 => "DETECTED",
840531213 => "DETECTED",
840531214 => "DETECTED",
); );
my $host = "127.0.0.1"; my $host = "127.0.0.1";
...@@ -72,7 +150,7 @@ if (!$con) { ...@@ -72,7 +150,7 @@ if (!$con) {
if ($con->connected()) { if ($con->connected()) {
print "OK.\n"; print "OK.\n";
} else { } else {
die "Conenction failure.\n"; die "Connection failure.\n";
} }
print "Subscribing to avmd events...\t"; print "Subscribing to avmd events...\t";
...@@ -108,10 +186,12 @@ sub test_once { ...@@ -108,10 +186,12 @@ sub test_once {
'originate_timeout=60,' . 'originate_timeout=60,' .
'origination_caller_id_number=' . $callerid . ',' . 'origination_caller_id_number=' . $callerid . ',' .
'origination_caller_id_name=' . $callerid . '}'; 'origination_caller_id_name=' . $callerid . '}';
my $outcome; my $outcome = "";
my $result; my $result = "";
my $event_uuid; my $event_uuid = "N/A";
my $uuid_in = ""; my $uuid_in = "";
my $freq = "N/A";
my $freq_var = "N/A";
if(defined($endpoint)) { if(defined($endpoint)) {
$originate_string .= $endpoint; $originate_string .= $endpoint;
...@@ -137,6 +217,10 @@ sub test_once { ...@@ -137,6 +217,10 @@ sub test_once {
} elsif (!($uuid_in eq "") && (($avmd_event_type eq 'avmd::beep') || ($avmd_event_type eq 'avmd::stop'))) { } elsif (!($uuid_in eq "") && (($avmd_event_type eq 'avmd::beep') || ($avmd_event_type eq 'avmd::stop'))) {
$event_uuid = $e->getHeader("Unique-ID"); $event_uuid = $e->getHeader("Unique-ID");
if ($event_uuid eq $uuid_in) { if ($event_uuid eq $uuid_in) {
if ($avmd_event_type eq 'avmd::beep') {
$freq = $e->getHeader("Frequency");
$freq_var = $e->getHeader("Frequency-variance");
}
$outcome = $e->getHeader("Beep-Status"); $outcome = $e->getHeader("Beep-Status");
if ($outcome eq $expectation) { if ($outcome eq $expectation) {
$result = "PASS"; $result = "PASS";
...@@ -150,7 +234,7 @@ sub test_once { ...@@ -150,7 +234,7 @@ sub test_once {
} }
} elsif ($event_name eq 'CHANNEL_HANGUP') { } elsif ($event_name eq 'CHANNEL_HANGUP') {
$event_uuid = $e->getHeader("variable_origination_uuid"); $event_uuid = $e->getHeader("variable_origination_uuid");
if ($event_uuid eq $uuid_out) { if ((defined $event_uuid) && ($event_uuid eq $uuid_out)) {
$outcome = "HANGUP"; $outcome = "HANGUP";
$result = "HANGUP"; $result = "HANGUP";
$hanguped++; $hanguped++;
...@@ -159,5 +243,6 @@ sub test_once { ...@@ -159,5 +243,6 @@ sub test_once {
} }
} }
} }
printf("\t[%s]\t[%s]\t\t[%s]\n", POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime($time_epoch)), $expectation, $result); printf("\t[%s]\t[%s]\t\t[%s]\t[%s]HZ\t[%s]\n", POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime($time_epoch)), $expectation, $result, $freq, $freq_var);
Time::HiRes::sleep(0.5); # avoid switch_core_session.c:2265 Throttle Error! 33, switch_time.c:1227 Over Session Rate of 30!
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论