TT#23772 remove PCMA transcoding for music_on_hold sound files

* with the removal of PCMA transcoding for music_on_hold
      sound files, the transcoding only applies to convert
      any WAV -> expected WAV format by sems
    * adjust File::Slurp play_file() to use the buffer, to
      avoid possible issues with the stream data read
    * fail if the sound file to upload is empty or cannot be read

Change-Id: I527aadd279dfe7dee42593be89f65dedf65fd6dd
changes/64/16464/4
Kirill Solomko 8 years ago
parent b55cd64891
commit 5f29592e7a

@ -593,11 +593,6 @@ sub handles_edit :Chained('handles_base') :PathPart('edit') {
NGCP::Panel::Utils::Navigation::back_or($c, $c->stash->{handles_base_uri}); NGCP::Panel::Utils::Navigation::back_or($c, $c->stash->{handles_base_uri});
} }
if ($file_result->handle->name eq 'music_on_hold' && !$file_result->set->contract_id) {
$target_codec = 'PCMA';
$filename =~ s/\.[^.]+$/.pcma/;
}
try { try {
$soundfile = NGCP::Panel::Utils::Sounds::transcode_file( $soundfile = NGCP::Panel::Utils::Sounds::transcode_file(
$upload->tempname, 'WAV', $target_codec); $upload->tempname, 'WAV', $target_codec);
@ -718,6 +713,7 @@ sub handles_load_default :Chained('handles_list') :PathPart('loaddefault') :Args
my ($self, $c) = @_; my ($self, $c) = @_;
my $posted = ($c->request->method eq 'POST'); my $posted = ($c->request->method eq 'POST');
my $form = NGCP::Panel::Form::get("NGCP::Panel::Form::Sound::LoadDefault", $c); my $form = NGCP::Panel::Form::get("NGCP::Panel::Form::Sound::LoadDefault", $c);
my $error;
$form->process( $form->process(
posted => $posted, posted => $posted,
params => $c->request->params, params => $c->request->params,
@ -753,28 +749,27 @@ sub handles_load_default :Chained('handles_list') :PathPart('loaddefault') :Args
} }
next unless(defined $path); next unless(defined $path);
my $data_ref;
my $codec = 'WAV';
my $handle_id = $h->get_column("handleid"); my $handle_id = $h->get_column("handleid");
my $file_id = $h->get_column("fileid"); my $file_id = $h->get_column("fileid");
my $fres; my $fres;
my $fname = basename($path); my $fname = basename($path);
read_file($path, buf_ref => \$data_ref);
unless (${data_ref}) {
$error = "Cannot upload an empty sound file, $fname";
die $error;
}
if(defined $file_id) { if(defined $file_id) {
if($form->params->{override}) { if($form->params->{override}) {
$c->log->debug("override $path as $hname for existing id $file_id"); $c->log->debug("override $path as $hname for existing id $file_id");
my $data;
if(!$c->stash->{set_result}->contract_id &&
grep {/^$hname$/} (qw/music_on_hold/)) {
$fname =~ s/\.wav$/.pcma/;
$data = NGCP::Panel::Utils::Sounds::transcode_file(
$path, 'WAV', 'PCMA');
} else {
$data = read_file($path);
}
$fres = $schema->resultset('voip_sound_files')->find($file_id); $fres = $schema->resultset('voip_sound_files')->find($file_id);
$fres->update({ $fres->update({
filename => $fname, filename => $fname,
data => $data, data => ${data_ref},
loopplay => $form->params->{loopplay} ? 1 : 0, loopplay => $form->params->{loopplay} ? 1 : 0,
}); });
} else { } else {
@ -783,23 +778,10 @@ sub handles_load_default :Chained('handles_list') :PathPart('loaddefault') :Args
} else { } else {
$c->log->debug("inserting $path as $hname with new id"); $c->log->debug("inserting $path as $hname with new id");
my $codec = 'WAV';
my $data;
if(!$c->stash->{set_result}->contract_id &&
grep {/^$hname$/} (qw/music_on_hold/)) {
$fname =~ s/\.wav$/.pcma/;
$codec = 'PCMA';
$data = NGCP::Panel::Utils::Sounds::transcode_file(
$path, 'WAV', $codec);
} else {
$data = read_file($path);
}
$fres = $schema->resultset('voip_sound_files') $fres = $schema->resultset('voip_sound_files')
->create({ ->create({
filename => $fname, filename => $fname,
data => $data, data => ${data_ref},
handle_id => $handle_id, handle_id => $handle_id,
set_id => $set_id, set_id => $set_id,
loopplay => $form->params->{loopplay} ? 1 : 0, loopplay => $form->params->{loopplay} ? 1 : 0,
@ -821,8 +803,10 @@ sub handles_load_default :Chained('handles_list') :PathPart('loaddefault') :Args
} catch($e) { } catch($e) {
NGCP::Panel::Utils::Message::error( NGCP::Panel::Utils::Message::error(
c => $c, c => $c,
error => $e, $error
desc => $c->loc('Failed to load default sound files.'), ? (desc => $c->loc($error))
: (error => $e,
desc => $c->loc('Failed to load default sound files.')),
); );
} }
NGCP::Panel::Utils::Navigation::back_or($c, $c->stash->{handles_base_uri}); NGCP::Panel::Utils::Navigation::back_or($c, $c->stash->{handles_base_uri});

@ -191,12 +191,7 @@ sub update_item {
last; last;
} }
if($resource->{handle} eq 'music_on_hold' && !$set->contract_id) { $resource->{codec} = 'WAV';
$resource->{codec} = 'PCMA';
$resource->{filename} =~ s/\.[^.]+$/.pcma/;
} else {
$resource->{codec} = 'WAV';
}
$resource->{data} = $recording; $resource->{data} = $recording;
$resource = $self->transcode_data($c, 'WAV', $resource); $resource = $self->transcode_data($c, 'WAV', $resource);
last unless($resource); last unless($resource);

Loading…
Cancel
Save