diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c index eaeb9bc0a0..3cca9c6b6e 100644 --- a/channels/chan_pjsip.c +++ b/channels/chan_pjsip.c @@ -418,12 +418,13 @@ static struct ast_channel *chan_pjsip_new(struct ast_sip_session *session, int s ast_channel_nativeformats_set(chan, caps); if (!ast_format_cap_empty(caps)) { - /* - * XXX Probably should pick the first audio codec instead - * of simply the first codec. The first codec may be video. - */ - struct ast_format *fmt = ast_format_cap_get_format(caps, 0); + struct ast_format *fmt; + fmt = ast_format_cap_get_best_by_type(caps, AST_MEDIA_TYPE_AUDIO); + if (!fmt) { + /* Since our capabilities aren't empty, this will succeed */ + fmt = ast_format_cap_get_format(caps, 0); + } ast_channel_set_writeformat(chan, fmt); ast_channel_set_rawwriteformat(chan, fmt); ast_channel_set_readformat(chan, fmt); diff --git a/main/channel.c b/main/channel.c index f8ae442b93..b35a2fad43 100644 --- a/main/channel.c +++ b/main/channel.c @@ -5886,9 +5886,10 @@ struct ast_channel *ast_request(const char *type, struct ast_format_cap *request return NULL; /* XXX Only the audio format calculated as being the best for translation - * purposes is used for the request. This needs to be re-evaluated. It may be - * a better choice to send all the audio formats capable of being translated - * during the request and allow the channel drivers to pick the best one. */ + * purposes is used for the request. This is because we don't have the ability + * to signal to the initiator which one of their codecs that was offered is + * the one that was selected, particularly in a chain of Local channels. + */ joint_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT); if (!joint_cap) { return NULL; diff --git a/res/ari/resource_channels.c b/res/ari/resource_channels.c index edd319d371..693835129e 100644 --- a/res/ari/resource_channels.c +++ b/res/ari/resource_channels.c @@ -917,8 +917,6 @@ static void ari_channels_handle_originate_with_id(const char *args_endpoint, char *caller_id = NULL; char *cid_num = NULL; char *cid_name = NULL; - RAII_VAR(struct ast_format_cap *, cap, - ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT), ao2_cleanup); char *stuff; struct ast_channel *other = NULL; struct ast_channel *chan = NULL; @@ -930,12 +928,6 @@ static void ari_channels_handle_originate_with_id(const char *args_endpoint, struct ari_origination *origination; pthread_t thread; - if (!cap) { - ast_ari_response_alloc_failed(response); - return; - } - ast_format_cap_append(cap, ast_format_slin, 0); - if ((assignedids.uniqueid && AST_MAX_PUBLIC_UNIQUEID < strlen(assignedids.uniqueid)) || (assignedids.uniqueid2 && AST_MAX_PUBLIC_UNIQUEID < strlen(assignedids.uniqueid2))) { ast_ari_response_error(response, 400, "Bad Request", @@ -1071,7 +1063,7 @@ static void ari_channels_handle_originate_with_id(const char *args_endpoint, } } - if (ast_dial_prerun(dial, other, cap)) { + if (ast_dial_prerun(dial, other, NULL)) { ast_ari_response_alloc_failed(response); ast_dial_destroy(dial); ast_free(origination); diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c index a2550df9e0..3ec61e1e51 100644 --- a/res/res_pjsip_sdp_rtp.c +++ b/res/res_pjsip_sdp_rtp.c @@ -240,8 +240,8 @@ static int set_caps(struct ast_sip_session *session, struct ast_sip_session_medi /* get the joint capabilities between peer and endpoint */ ast_format_cap_get_compatible(caps, peer, joint); if (!ast_format_cap_count(joint)) { - struct ast_str *usbuf = ast_str_alloca(64); - struct ast_str *thembuf = ast_str_alloca(64); + struct ast_str *usbuf = ast_str_alloca(256); + struct ast_str *thembuf = ast_str_alloca(256); ast_rtp_codecs_payloads_destroy(&codecs); ast_log(LOG_NOTICE, "No joint capabilities for '%s' media stream between our configuration(%s) and incoming SDP(%s)\n", @@ -257,36 +257,17 @@ static int set_caps(struct ast_sip_session *session, struct ast_sip_session_medi ast_format_cap_append_from_cap(session->req_caps, joint, AST_MEDIA_TYPE_UNKNOWN); if (session->channel) { - struct ast_format *fmt; ast_channel_lock(session->channel); - ast_format_cap_remove_by_type(caps, AST_MEDIA_TYPE_UNKNOWN); - ast_format_cap_append_from_cap(caps, ast_channel_nativeformats(session->channel), AST_MEDIA_TYPE_UNKNOWN); - ast_format_cap_remove_by_type(caps, media_type); - - /* - * XXX Historically we picked the "best" joint format to use - * and stuck with it. It would be nice to just append the - * determined joint media capabilities to give translation - * more formats to choose from when necessary. Unfortunately, - * there are some areas of the system where this doesn't work - * very well. (The softmix bridge in particular is reluctant - * to pick higher fidelity formats and has a problem with - * asymmetric sample rates.) - */ - fmt = ast_format_cap_get_format(joint, 0); - ast_format_cap_append(caps, fmt, 0); /* * Apply the new formats to the channel, potentially changing * raw read/write formats and translation path while doing so. */ - ast_channel_nativeformats_set(session->channel, caps); + ast_channel_nativeformats_set(session->channel, joint); ast_set_read_format(session->channel, ast_channel_readformat(session->channel)); ast_set_write_format(session->channel, ast_channel_writeformat(session->channel)); ast_channel_unlock(session->channel); - - ao2_ref(fmt, -1); } ast_rtp_codecs_payloads_destroy(&codecs);