codec_negotiation: Implement outgoing_call_offer_pref

Based on this new endpoint setting, a joint list of preferred codecs
between those received from the Asterisk core (remote), and those
specified in the endpoint's "allow" parameter (local) is created and
is used to create the outgoing SDP offer.

* Add outgoing_call_offer_pref to pjsip_configuration (endpoint)

* Add "call_direction" to res_pjsip_session.

* Update pjsip_session_caps.c to make the functions more generic
  so they could be used for both incoming and outgoing.

* Update ast_sip_session_create_outgoing to create the
  pending_media_state->topology with the results of
  ast_sip_session_create_joint_call_stream().

* The endpoint "preferred_codec_only" option now automatically sets
  AST_SIP_CALL_CODEC_PREF_FIRST in incoming_call_offer_pref.

* A helper function ast_stream_get_format_count() was added to
  streams to return the current count of formats.

ASTERISK-28777

Change-Id: Id4ec0b4a906c2ae5885bf947f101c59059935437
This commit is contained in:
George Joseph
2020-03-13 13:40:46 -06:00
committed by Friendly Automation
parent 57a457c26c
commit 2ee455958e
13 changed files with 408 additions and 297 deletions

View File

@@ -511,22 +511,40 @@ enum ast_sip_session_redirect {
/*!
* \brief Incoming/Outgoing call offer/answer joint codec preference.
*
* The default is INTERSECT ALL LOCAL.
*/
enum ast_sip_call_codec_pref {
/*! Two bits for merge */
/*! Intersection of local and remote */
AST_SIP_CALL_CODEC_PREF_INTERSECT = 1 << 0,
/*! Union of local and remote */
AST_SIP_CALL_CODEC_PREF_UNION = 1 << 1,
/*! Two bits for filter */
/*! No filter */
AST_SIP_CALL_CODEC_PREF_ALL = 1 << 2,
/*! Only the first */
AST_SIP_CALL_CODEC_PREF_FIRST = 1 << 3,
/*! Two bits for preference and sort */
/*! Prefer, and order by local values */
AST_SIP_CALL_CODEC_PREF_LOCAL,
/*! Prefer, and order by local values (intersection) */
AST_SIP_CALL_CODEC_PREF_LOCAL_LIMIT,
/*! Prefer, and order by local values (top/first only) */
AST_SIP_CALL_CODEC_PREF_LOCAL_SINGLE,
AST_SIP_CALL_CODEC_PREF_LOCAL = 1 << 4,
/*! Prefer, and order by remote values */
AST_SIP_CALL_CODEC_PREF_REMOTE,
/*! Prefer, and order by remote values (intersection) */
AST_SIP_CALL_CODEC_PREF_REMOTE_LIMIT,
/*! Prefer, and order by remote values (top/first only) */
AST_SIP_CALL_CODEC_PREF_REMOTE_SINGLE,
AST_SIP_CALL_CODEC_PREF_REMOTE = 1 << 5,
};
/*!
* \brief Returns true if the preference is set in the parameter
* \since 18.0.0
*
* \param param A ast_flags struct with one or more of enum ast_sip_call_codec_pref set
* \param codec_pref The last component of one of the enum values
* \retval 1 if the enum value is set
* \retval 0 if not
*/
#define ast_sip_call_codec_pref_test(__param, __codec_pref) (!!(ast_test_flag( &__param, AST_SIP_CALL_CODEC_PREF_ ## __codec_pref )))
/*!
* \brief Session timers options
*/
@@ -769,7 +787,9 @@ struct ast_sip_endpoint_media_configuration {
/*! Enable webrtc settings and defaults */
unsigned int webrtc;
/*! Codec preference for an incoming offer */
enum ast_sip_call_codec_pref incoming_call_offer_pref;
struct ast_flags incoming_call_offer_pref;
/*! Codec preference for an outgoing offer */
struct ast_flags outgoing_call_offer_pref;
};
/*!
@@ -3222,6 +3242,18 @@ int ast_sip_dtmf_to_str(const enum ast_sip_dtmf_mode dtmf,
*/
int ast_sip_str_to_dtmf(const char *dtmf_mode);
/*!
* \brief Convert the call codec preference flags to a string
* \since 18.0.0
*
* \param pref the call codec preference setting
*
* \returns a constant string with either the setting value or 'unknown'
* \note Don't try to free the string!
*
*/
const char *ast_sip_call_codec_pref_to_str(struct ast_flags pref);
/*!
* \brief Transport shutdown monitor callback.
* \since 13.18.0

View File

@@ -30,6 +30,9 @@
#include "asterisk/sdp_srtp.h"
/* Needed for ast_media_type */
#include "asterisk/codec.h"
/* Needed for pjmedia_sdp_session and pjsip_inv_session */
#include <pjsip_ua.h>
/* Forward declarations */
struct ast_sip_endpoint;
@@ -80,8 +83,6 @@ struct ast_sip_session_media {
struct ast_sip_session_sdp_handler *handler;
/*! \brief Holds SRTP information */
struct ast_sdp_srtp *srtp;
/*! \brief Media format capabilities */
struct ast_sip_session_caps *caps;
/*! \brief What type of encryption is in use on this stream */
enum ast_sip_session_media_encryption encryption;
/*! \brief The media transport in use for this stream */
@@ -157,6 +158,12 @@ struct ast_sip_session_delayed_request;
/*! \brief Opaque struct controlling the suspension of the session's serializer. */
struct ast_sip_session_suspender;
/*! \brief Indicates the call direction respective to Asterisk */
enum ast_sip_session_call_direction {
AST_SIP_SESSION_INCOMING_CALL = 0,
AST_SIP_SESSION_OUTGOING_CALL,
};
/*!
* \brief A structure describing a SIP session
*
@@ -222,8 +229,10 @@ struct ast_sip_session {
enum ast_sip_dtmf_mode dtmf;
/*! Initial incoming INVITE Request-URI. NULL otherwise. */
pjsip_uri *request_uri;
/* Media statistics for negotiated RTP streams */
/*! Media statistics for negotiated RTP streams */
AST_VECTOR(, struct ast_rtp_instance_stats *) media_stats;
/*! The direction of the call respective to Asterisk */
enum ast_sip_session_call_direction call_direction;
};
typedef int (*ast_sip_session_request_creation_cb)(struct ast_sip_session *session, pjsip_tx_data *tdata);

View File

@@ -20,63 +20,63 @@
struct ast_format_cap;
struct ast_sip_session;
struct ast_sip_session_media;
struct ast_sip_session_caps;
/*!
* \brief Allocate a SIP session capabilities object.
* \brief Create joint capabilities
* \since 18.0.0
*
* \retval An ao2 allocated SIP session capabilities object, or NULL on error
* Creates a list of joint capabilities between the given remote capabilities, and local ones.
* "local" and "remote" reference the values in ast_sip_call_codec_pref.
*
* \param remote The "remote" capabilities
* \param local The "local" capabilities
* \param media_type The media type
* \param codec_prefs One or more of enum ast_sip_call_codec_pref
*
* \retval A pointer to the joint capabilities (which may be empty).
* NULL will be returned only if no memory was available to allocate the structure.
* \note Returned object's reference must be released at some point,
*/
struct ast_sip_session_caps *ast_sip_session_caps_alloc(void);
struct ast_format_cap *ast_sip_create_joint_call_cap(const struct ast_format_cap *remote,
struct ast_format_cap *local, enum ast_media_type media_type,
struct ast_flags codec_pref);
/*!
* \brief Set the incoming call offer capabilities for a session.
* \brief Create a new stream of joint capabilities
* \since 18.0.0
*
* This will replace any capabilities already present.
*
* \param caps A session's capabilities object
* \param cap The capabilities to set it to
*/
void ast_sip_session_set_incoming_call_offer_cap(struct ast_sip_session_caps *caps,
struct ast_format_cap *cap);
/*!
* \brief Get the incoming call offer capabilities.
* \since 18.0.0
*
* \note Returned objects reference is not incremented.
*
* \param caps A session's capabilities object
*
* \retval An incoming call offer capabilities object
*/
const struct ast_format_cap *ast_sip_session_get_incoming_call_offer_cap(
const struct ast_sip_session_caps *caps);
/*!
* \brief Make the incoming call offer capabilities for a session.
* \since 18.0.0
*
* Creates and sets a list of joint capabilities between the given remote
* capabilities, and pre-configured ones. The resulting joint list is then
* stored, and 'owned' (reference held) by the session.
*
* If the incoming capabilities have been set elsewhere, this will not replace
* those. It will however, return a pointer to the current set.
*
* \note Returned object's reference is not incremented.
* Creates a new stream with capabilities between the given session's local capabilities,
* and the remote stream's. Codec selection is based on the session->endpoint's codecs, the
* session->endpoint's codec call preferences, and the stream passed by the core (for
* outgoing calls) or created by the incoming SDP (for incoming calls).
*
* \param session The session
* \param session_media An associated media session
* \param remote Capabilities of a device
* \param remote The remote stream
*
* \retval A pointer to the incoming call offer capabilities
* \retval A pointer to a new stream with the joint capabilities (which may be empty),
* NULL will be returned only if no memory was available to allocate the structure.
*/
const struct ast_format_cap *ast_sip_session_join_incoming_call_offer_cap(
const struct ast_sip_session *session, const struct ast_sip_session_media *session_media,
const struct ast_format_cap *remote);
struct ast_stream *ast_sip_session_create_joint_call_stream(const struct ast_sip_session *session,
struct ast_stream *remote);
/*!
* \brief Create joint capabilities
* \since 18.0.0
*
* Creates a list of joint capabilities between the given session's local capabilities,
* and the remote capabilities. Codec selection is based on the session->endpoint's codecs, the
* session->endpoint's codec call preferences, and the "remote" capabilities passed by the core (for
* outgoing calls) or created by the incoming SDP (for incoming calls).
*
* \param session The session
* \param media_type The media type
* \param remote Capabilities received in an SDP offer or from the core
*
* \retval A pointer to the joint capabilities (which may be empty).
* NULL will be returned only if no memory was available to allocate the structure.
* \note Returned object's reference must be released at some point,
*/
struct ast_format_cap *ast_sip_session_create_joint_call_cap(const struct ast_sip_session *session,
enum ast_media_type media_type, const struct ast_format_cap *remote);
#endif /* RES_PJSIP_SESSION_CAPS_H */

View File

@@ -166,6 +166,17 @@ void ast_stream_set_type(struct ast_stream *stream, enum ast_media_type type);
*/
struct ast_format_cap *ast_stream_get_formats(const struct ast_stream *stream);
/*!
* \brief Get the count of the current negotiated formats of a stream
*
* \param stream The media stream
*
* \return The count of negotiated formats
*
* \since 18
*/
int ast_stream_get_format_count(const struct ast_stream *stream);
/*!
* \brief Set the current negotiated formats of a stream
*