diff --git a/src/channels/chan_voicemngr.c b/src/channels/chan_voicemngr.c index 10033cb9bc3709eb769775884f65034d6db40a56..e7ad983479c60fa38c4bf19aa6e7dadc128f33ee 100644 --- a/src/channels/chan_voicemngr.c +++ b/src/channels/chan_voicemngr.c @@ -767,11 +767,27 @@ static void chan_voicemngr_modify_codec(struct chan_voicemngr_subchannel *sub) { ast_channel_lock(sub->owner); if (bridged_chan) { - // for the internal call, bridged_chan is allocated but codec and ptime is not set so need to check it here and set default - // ptime and get codec from sub-owner in this case + // bridged_chan is allocated but codec and ptime is not set so need to check it here and set default ast_channel_ptime_set(sub->owner, ast_channel_ptime_get(bridged_chan) ? ast_channel_ptime_get(bridged_chan) : default_ptime); - ast_channel_codec_set(sub->owner, !ast_strlen_zero(ast_channel_codec_get(bridged_chan)) ? - ast_channel_codec_get(bridged_chan) : ast_format_get_name(ast_channel_writeformat(sub->owner))); + if (strncmp(ast_channel_name(bridged_chan), "TELCHAN", 5) == 0 ) { + // local chan, internal call, using alaw. + ast_log(LOG_NOTICE, "INTERNAL CALL, %s\n", ast_channel_name(bridged_chan)); + ast_channel_codec_set(sub->owner, "alaw"); + ast_channel_codec_set(bridged_chan, "alaw"); + struct ast_format_cap *caps; + caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT); + if (caps) { + ast_format_cap_append(caps, map_rtpname_to_format("alaw"), 0); + ast_channel_nativeformats_set(bridged_chan, caps); + ao2_ref(caps, -1); + } else { + ao2_cleanup(caps); + } + } else { + // get codec from bridged_chan's writeformat if not set + ast_channel_codec_set(sub->owner, !ast_strlen_zero(ast_channel_codec_get(bridged_chan)) ? + ast_channel_codec_get(bridged_chan) : ast_format_get_name(ast_channel_writeformat(bridged_chan))); + } // we need to set caps here from bridged_chan to avoid asterisk transcoding which break audio in some cases struct ast_format_cap *caps; caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT); @@ -1665,7 +1681,7 @@ static int chan_voicemngr_write(struct ast_channel *ast, struct ast_frame *frame int packet_size; audio_packet_t *ap; int sip_client_id = -1; - unsigned int rtp_timestamp = frame->ts * (ast_rtp_get_rate(frame->subclass.format)/1000); + unsigned int rtp_timestamp = frame->ts ? frame->ts * (ast_rtp_get_rate(frame->subclass.format)/1000) : 0; if (ast_channel_state(ast) != AST_STATE_UP && ast_channel_state(ast) != AST_STATE_RING) { /* Silently ignore packets until channel is up */