TT#22550 disable sound files transcoding

* NGCP sound files do not need transcoding anymore and
      it is disabled for the sound file upload/download logic
      (voicemail sound files transcoding is still required
       and retained)

Change-Id: I756c794ae614d3d85096936e217d83f3e0c6db44
changes/43/15743/6
Kirill Solomko 8 years ago
parent 8755043044
commit d419c49f76

@ -62,11 +62,6 @@ sub GET :Allow {
my $resource = $self->resource_from_item($c, $item);
$resource->{data} = $item->data;
if($item->codec eq "PCMA") {
$resource->{codec} = 'WAV';
$resource = $self->transcode_data($c, $item->codec, $resource);
last unless($resource);
}
$c->response->header ('Content-Disposition' => 'attachment; filename="' . $resource->{filename} . '"');
$c->response->content_type('audio/x-wav');

@ -562,12 +562,12 @@ sub handles_edit :Chained('handles_base') :PathPart('edit') {
fields => {},
back_uri => $c->req->uri,
);
if($posted && $form->validated) {
if (defined $upload) {
my $soundfile = eval { $upload->slurp };
my $filename = eval { $upload->filename };
my $ft = File::Type->new();
unless ($ft->checktype_contents($soundfile) eq 'audio/x-wav') {
NGCP::Panel::Utils::Message::error(
@ -577,7 +577,7 @@ sub handles_edit :Chained('handles_base') :PathPart('edit') {
);
NGCP::Panel::Utils::Navigation::back_or($c, $c->stash->{handles_base_uri});
}
my $target_codec = 'WAV';
# clear audio caches
@ -593,23 +593,6 @@ sub handles_edit :Chained('handles_base') :PathPart('edit') {
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 {
$soundfile = NGCP::Panel::Utils::Sounds::transcode_file(
$upload->tempname, 'WAV', $target_codec);
} catch ($e) {
NGCP::Panel::Utils::Message::error(
c => $c,
log => 'Transcoding audio file failed',
desc => $c->loc('Transcoding audio file failed'),
);
NGCP::Panel::Utils::Navigation::back_or($c, $c->stash->{handles_base_uri});
}
try {
$file_result->update({
loopplay => $form->values->{loopplay},
@ -686,28 +669,12 @@ sub handles_delete :Chained('handles_base') :PathPart('delete') {
sub handles_download :Chained('handles_base') :PathPart('download') :Args(0) {
my ($self, $c) = @_;
my $file = $c->stash->{file_result};
my $filename = $file->filename;
$filename =~ s/\.\w+$/.wav/;
my $data;
my $data = $file->data;
if($file->codec ne 'WAV') {
try {
$data = NGCP::Panel::Utils::Sounds::transcode_data(
$file->data, $file->codec, 'WAV');
} catch($e) {
NGCP::Panel::Utils::Message::error(
c => $c,
error => $e,
desc => $c->loc('Failed to transcode audio file'),
);
NGCP::Panel::Utils::Navigation::back_or($c, $c->stash->{handles_base_uri});
}
} else {
$data = $file->data;
}
$c->response->header ('Content-Disposition' => 'attachment; filename="' . $filename . '"');
$c->response->content_type('audio/x-wav');
$c->response->body($data);
@ -718,6 +685,7 @@ sub handles_load_default :Chained('handles_list') :PathPart('loaddefault') :Args
my ($self, $c) = @_;
my $posted = ($c->request->method eq 'POST');
my $form = NGCP::Panel::Form::get("NGCP::Panel::Form::Sound::LoadDefault", $c);
my $error;
$form->process(
posted => $posted,
params => $c->request->params,
@ -729,7 +697,7 @@ sub handles_load_default :Chained('handles_list') :PathPart('loaddefault') :Args
fields => {},
back_uri => $c->req->uri,
);
if($posted && $form->validated) {
my $lang = $form->params->{language};
my $base = "/var/lib/ngcp-soundsets";
@ -753,29 +721,30 @@ sub handles_load_default :Chained('handles_list') :PathPart('loaddefault') :Args
}
next unless(defined $path);
my $handle_id = $h->get_column("handleid");
my $data_ref;
my $codec = 'WAV';
my $file_id = $h->get_column("fileid");
my $fres;
my $fname = basename($path);
my $handle_id = $h->get_column("handleid");
my $loopplay = $form->params->{loopplay} ? 1 : 0;
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($form->params->{override}) {
$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->update({
filename => $fname,
data => $data,
loopplay => $form->params->{loopplay} ? 1 : 0,
data => ${data_ref},
loopplay => $loopplay,
});
} else {
$c->log->debug("skip $path as $hname exists via id $file_id and override is not set");
@ -783,26 +752,13 @@ sub handles_load_default :Chained('handles_list') :PathPart('loaddefault') :Args
} else {
$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')
->create({
filename => $fname,
data => $data,
data => ${data_ref},
handle_id => $handle_id,
set_id => $set_id,
loopplay => $form->params->{loopplay} ? 1 : 0,
loopplay => $loopplay,
codec => $codec,
});
}
@ -821,8 +777,10 @@ sub handles_load_default :Chained('handles_list') :PathPart('loaddefault') :Args
} catch($e) {
NGCP::Panel::Utils::Message::error(
c => $c,
error => $e,
desc => $c->loc('Failed to load default sound files.'),
$error
? (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});

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

Loading…
Cancel
Save