#!/usr/bin/perl # # Monitor Mux for Asterisk # Brian K. West # # Need to consider locking since res_monitor doesn't # We could mux a call in progress and i'm not sure # how * will react if we do so. I tried to flock the files # but didn't do anything... # # Update: If you mux a call inprogress. They will be out of sync # Also all monitoring stops. Wonder if we can get kram to do # an inprogress directory. Then move the files once the call is # hung up. # # Lets tell monitor-mux where everything is or should be. $destdir = "/var/spool/asterisk/monarc/"; $mondir = "/var/spool/asterisk/monitor/"; $soxmix = "/usr/local/bin/soxmix"; $sox = "/usr/local/bin/sox"; $rm = "/bin/rm"; # # Lets open the directory and read in all the files. # stripping out .. and . and stripping off the -in.wav # and -out.wav to get just the filenames. # opendir(DIR,$mondir) or die "can't opendir $mondir: $!\n"; while(defined($file = readdir(DIR))) { if($file eq ".") { next; } if($file eq "..") { next; } $file =~ s/\-in.gsm//g; $file =~ s/\-out.gsm//g; push(@files, $file); } # now get a unique array @files = unique(@files); # now lets do something with these files. foreach $file (@files) { # reverse in system("$sox $mondir$file-in.gsm $mondir$file-in-rev.gsm reverse"); # reverse out system("$sox $mondir$file-out.gsm $mondir$file-out-rev.gsm reverse"); # remove in and out files system("$rm $mondir$file-in.gsm $mondir$file-out.gsm"); # now lets mux the files system("$soxmix $mondir$file-in-rev.gsm $mondir$file-out-rev.gsm $mondir$file-rev.gsm"); # rm reverse old files system("$rm $mondir$file-in-rev.gsm $mondir$file-out-rev.gsm"); # now flip it back around and while we are at it.. archive it to a diff dir. system("$sox $mondir$file-rev.gsm $destdir$file.gsm reverse"); # remove the old muxed reverse file. system("$rm $mondir$file-rev.gsm"); } # used to unique the array of files. sub unique { my (%seen, $array); ($array)=@_; if(@$array){return grep{$seen{$_} ++} @$array;} else{return grep{ ! $seen{$_} ++} @_;} }