Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PISTON-1170: Sets prepend_on_forward media content_type correctly. #6674

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/kazoo_media/include/kz_media.hrl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-ifndef(KZ_MEDIA_HRL).

-define(CHUNKSIZE, 24576).
-define(NORMALIZATION_FORMAT, kapps_config:get_ne_binary(<<"crossbar.media">>, <<"normalization_format">>, <<"mp3">>)).

-record(media_file, {stream_url = <<>> :: binary()
,contents = <<>> :: binary()
Expand Down
2 changes: 0 additions & 2 deletions core/kazoo_media/src/kz_media_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
-define(NORMALIZE_SOURCE_ARGS, kapps_config:get_binary(?CONFIG_CAT, <<"normalize_source_args">>, <<>>)).
-define(NORMALIZE_DEST_ARGS, kapps_config:get_binary(?CONFIG_CAT, <<"normalize_destination_args">>, <<"-r 8000">>)).

-define(NORMALIZATION_FORMAT, kapps_config:get_ne_binary(<<"crossbar.media">>, <<"normalization_format">>, <<"mp3">>)).

-define(USE_ACCOUNT_OVERRIDES, kapps_config:get_is_true(?CONFIG_CAT, <<"support_account_overrides">>, 'true')).

-define(DEFAULT_MAX_RECORDING_LIMIT, 3*?SECONDS_IN_HOUR).
Expand Down
22 changes: 13 additions & 9 deletions core/kazoo_voicemail/src/kvm_message.erl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
]).

-include("kz_voicemail.hrl").
-include("kazoo_media/include/kz_media.hrl").

-export_type([vm_folder/0]).

Expand Down Expand Up @@ -785,32 +786,35 @@ prepend_forward_message(Call, ForwardId, Metadata, _SrcBoxId, Props) ->
{'ok', _} = kz_media_util:synthesize_tone(OrigSampleRate, <<"440">>, <<"0.5">>, TonePath),

lager:debug("joining prepend to original message"),
case kz_media_util:join_media_files([TmpPath, TonePath, OrigPath], [{sample_rate, OrigSampleRate}]) of
JoinFormat = ?NORMALIZATION_FORMAT,
JoinOptions = [{'sample_rate', OrigSampleRate}, {'to_format', JoinFormat}],
case kz_media_util:join_media_files([TmpPath, TonePath, OrigPath], JoinOptions) of
{'ok', FileContents} ->
JoinFilename = <<(kz_binary:rand_hex(16))/binary, ".mp3">>,
JoinFilename = <<(kz_binary:rand_hex(16))/binary, ".", JoinFormat/binary>>,
FileProps = [{'content_type', kz_mime:from_extension(JoinFormat)}],
_ = [kz_util:delete_file(F) || F <- [TmpPath, OrigPath, TonePath]],
%%TODO: update forwarded doc with length and media_filename
try_put_fwd_attachment(AccountId, ForwardId, JoinFilename, FileContents, 3);
try_put_fwd_attachment(AccountId, ForwardId, JoinFilename, FileContents, FileProps, 3);
{'error', _} ->
_ = [kz_util:delete_file(F) || F <- [TmpPath, OrigPath, TonePath]],
lager:warning("failed to join forward message media files"),
{'error', 'join_failed'}

end.

-spec try_put_fwd_attachment(kz_term:ne_binary(), kz_term:ne_binary(), kz_term:ne_binary(), iodata(), 1..3) -> db_ret().
try_put_fwd_attachment(AccountId, ForwardId, _JoinFilename, _FileContents, 0) ->
-spec try_put_fwd_attachment(kz_term:ne_binary(), kz_term:ne_binary(), kz_term:ne_binary(), iodata(), kz_term:proplist(), 1..3) -> db_ret().
try_put_fwd_attachment(AccountId, ForwardId, _JoinFilename, _FileContents, _FileProps, 0) ->
lager:error("max retries to save prepend forward voicemail attachment ~s in db ~s"
,[ForwardId, kvm_util:get_db(AccountId, ForwardId)]
),
{'error', 'max_save_retries'};
try_put_fwd_attachment(AccountId, ForwardId, JoinFilename, FileContents, Loop) ->
case kz_datamgr:put_attachment(kvm_util:get_db(AccountId, ForwardId), ForwardId, JoinFilename, FileContents) of
try_put_fwd_attachment(AccountId, ForwardId, JoinFilename, FileContents, FileProps, Loop) ->
case kz_datamgr:put_attachment(kvm_util:get_db(AccountId, ForwardId), ForwardId, JoinFilename, FileContents, FileProps) of
{'ok', _}=OK -> OK;
{'error', 'conflict'} ->
try_put_fwd_attachment(AccountId, ForwardId, JoinFilename, FileContents, Loop - 1);
try_put_fwd_attachment(AccountId, ForwardId, JoinFilename, FileContents, FileProps, Loop - 1);
{'error', 'timeout'} ->
try_put_fwd_attachment(AccountId, ForwardId, JoinFilename, FileContents, Loop - 1);
try_put_fwd_attachment(AccountId, ForwardId, JoinFilename, FileContents, FileProps, Loop - 1);
{'error', _Reason}=Error ->
lager:error("failed to save prepend forward voicemail message ~s in db ~s : ~p"
,[ForwardId, kvm_util:get_db(AccountId, ForwardId), _Reason]),
Expand Down