[Asterisk-code-review] asymmetric_rtp_codec dialplan function (asterisk[13])
Salah Ahmed
asteriskteam at digium.com
Fri Dec 20 10:44:14 CST 2019
Salah Ahmed has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/13501 )
Change subject: asymmetric_rtp_codec dialplan function
......................................................................
asymmetric_rtp_codec dialplan function
Implement a dialplan function for asymmetric_rtp_codec. We
can change this flag on per call basis.
ASTERISK-28668
Change-Id: I600d5ac1c6c2b47a7a0da6425aea559f1aa61c7c
---
M channels/chan_pjsip.c
M channels/pjsip/dialplan_functions.c
M channels/pjsip/include/dialplan_functions.h
M include/asterisk/res_pjsip_session.h
M res/res_pjsip_sdp_rtp.c
M res/res_pjsip_session.c
6 files changed, 113 insertions(+), 4 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/01/13501/1
diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c
index 33abe03..422470c 100644
--- a/channels/chan_pjsip.c
+++ b/channels/chan_pjsip.c
@@ -770,7 +770,7 @@
* Therefore we need to update the native format to the current
* raw read format BEFORE the native format check
*/
- if (!session->endpoint->asymmetric_rtp_codec &&
+ if (!session->asymmetric_rtp_codec &&
ast_format_cmp(ast_channel_rawwriteformat(ast), f->subclass.format) == AST_FORMAT_CMP_NOT_EQUAL) {
struct ast_format_cap *caps;
@@ -2875,6 +2875,12 @@
.write = pjsip_acf_dtmf_mode_write
};
+static struct ast_custom_function asymmetric_rtp_codec_function = {
+ .name = "PJSIP_ASYMMETRIC_RTP_CODEC",
+ .read = pjsip_acf_asymmetric_rtp_codec_read,
+ .write = pjsip_acf_asymmetric_rtp_codec_write
+};
+
static struct ast_custom_function moh_passthrough_function = {
.name = "PJSIP_MOH_PASSTHROUGH",
.read = pjsip_acf_moh_passthrough_read,
@@ -2935,6 +2941,11 @@
goto end;
}
+ if (ast_custom_function_register(&asymmetric_rtp_codec_function)) {
+ ast_log(LOG_WARNING, "Unable to register PJSIP_ASYMMETRIC_RTP_CODEC dialplan function\n");
+ goto end;
+ }
+
if (ast_custom_function_register(&moh_passthrough_function)) {
ast_log(LOG_WARNING, "Unable to register PJSIP_MOH_PASSTHROUGH dialplan function\n");
goto end;
@@ -3000,6 +3011,7 @@
ast_sip_session_unregister_supplement(&chan_pjsip_supplement);
ast_sip_session_unregister_supplement(&call_pickup_supplement);
ast_custom_function_unregister(&dtmf_mode_function);
+ ast_custom_function_unregister(&asymmetric_rtp_codec_function);
ast_custom_function_unregister(&moh_passthrough_function);
ast_custom_function_unregister(&media_offer_function);
ast_custom_function_unregister(&chan_pjsip_dial_contacts_function);
@@ -3026,6 +3038,7 @@
ast_sip_session_unregister_supplement(&call_pickup_supplement);
ast_custom_function_unregister(&dtmf_mode_function);
+ ast_custom_function_unregister(&asymmetric_rtp_codec_function);
ast_custom_function_unregister(&moh_passthrough_function);
ast_custom_function_unregister(&media_offer_function);
ast_custom_function_unregister(&chan_pjsip_dial_contacts_function);
diff --git a/channels/pjsip/dialplan_functions.c b/channels/pjsip/dialplan_functions.c
index 3a6f0a4..74e7ace 100644
--- a/channels/pjsip/dialplan_functions.c
+++ b/channels/pjsip/dialplan_functions.c
@@ -80,6 +80,18 @@
<para>This function uses the same DTMF mode naming as the dtmf_mode configuration option</para>
</description>
</function>
+<function name="PJSIP_ASYMMETRIC_RTP_CODEC" language="en_US">
+ <synopsis>
+ Get or change the asymmethric rtp codec.
+ </synopsis>
+ <syntax>
+ </syntax>
+ <description>
+ <para>When read, returns the current asymmetric_rtp_codec mode</para>
+ <para>When written, sets the current asymmetric_rtp_codec mode</para>
+ <para>Allow the sending and receiving RTP codec to differ</para>
+ </description>
+</function>
<function name="PJSIP_MOH_PASSTHROUGH" language="en_US">
<synopsis>
Get or change the on-hold behavior for a SIP call.
@@ -1316,6 +1328,62 @@
return 0;
}
+int pjsip_acf_asymmetric_rtp_codec_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
+{
+ struct ast_sip_channel_pvt *channel;
+
+ if (!chan) {
+ ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
+ return -1;
+ }
+
+ ast_channel_lock(chan);
+ if (strcmp(ast_channel_tech(chan)->type, "PJSIP")) {
+ ast_log(LOG_WARNING, "Cannot call %s on a non-PJSIP channel\n", cmd);
+ ast_channel_unlock(chan);
+ return -1;
+ }
+
+ channel = ast_channel_tech_pvt(chan);
+
+ if (len < 3) {
+ ast_log(LOG_WARNING, "%s: buffer too small\n", cmd);
+ ast_channel_unlock(chan);
+ return -1;
+ }
+
+ channel = ast_channel_tech_pvt(chan);
+ strncpy(buf, AST_YESNO(channel->session->asymmetric_rtp_codec), len);
+
+ ast_channel_unlock(chan);
+ return 0;
+}
+
+int pjsip_acf_asymmetric_rtp_codec_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
+{
+ struct ast_sip_channel_pvt *channel;
+
+ if (!chan) {
+ ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
+ return -1;
+ }
+
+ ast_channel_lock(chan);
+ if (strcmp(ast_channel_tech(chan)->type, "PJSIP")) {
+ ast_log(LOG_WARNING, "Cannot call %s on a non-PJSIP channel\n", cmd);
+ ast_channel_unlock(chan);
+ return -1;
+ }
+
+ channel = ast_channel_tech_pvt(chan);
+ channel->session->asymmetric_rtp_codec = ast_true(value);
+
+ ast_channel_unlock(chan);
+
+ return 0;
+}
+
+
int pjsip_acf_moh_passthrough_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
{
struct ast_sip_channel_pvt *channel;
diff --git a/channels/pjsip/include/dialplan_functions.h b/channels/pjsip/include/dialplan_functions.h
index d0bf130..dd81055 100644
--- a/channels/pjsip/include/dialplan_functions.h
+++ b/channels/pjsip/include/dialplan_functions.h
@@ -73,6 +73,31 @@
int pjsip_acf_dtmf_mode_write(struct ast_channel *chan, const char *cmd, char *data, const char *value);
/*!
+ * \brief PJSIP_ASYMMETRIC_RTP_CODEC function read callback
+ * \param chan The channel the function is called on
+ * \param cmd The name of the function
+ * \param data Arguments passed to the function
+ * \param buf Out buffer that should be populated with the data
+ * \param len Size of the buffer
+ *
+ * \retval 0 on success
+ * \retval -1 on failure
+ */
+int pjsip_acf_asymmetric_rtp_codec_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len);
+
+/*!
+ * \brief PJSIP_ASYMMETRIC_RTP_CODEC function write callback
+ * \param chan The channel the function is called on
+ * \param cmd The name of the function
+ * \param data Arguments passed to the function
+ * \param value Value to be set by the function
+ *
+ * \retval 0 on success
+ * \retval -1 on failure
+ */
+int pjsip_acf_asymmetric_rtp_codec_write(struct ast_channel *chan, const char *cmd, char *data, const char *value);
+
+/*!
* \brief PJSIP_MOH_PASSTHROUGH function read callback
* \param chan The channel the function is called on
* \param cmd The name of the function
@@ -148,4 +173,4 @@
*/
int pjsip_acf_parse_uri_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len);
-#endif /* _PJSIP_DIALPLAN_FUNCTIONS */
\ No newline at end of file
+#endif /* _PJSIP_DIALPLAN_FUNCTIONS */
diff --git a/include/asterisk/res_pjsip_session.h b/include/asterisk/res_pjsip_session.h
index 9ae1883..ba017a6 100644
--- a/include/asterisk/res_pjsip_session.h
+++ b/include/asterisk/res_pjsip_session.h
@@ -161,6 +161,8 @@
unsigned int defer_end:1;
/*! Session end (remote hangup) requested while termination deferred */
unsigned int ended_while_deferred:1;
+ /*! asymmetric rtp codec */
+ unsigned int asymmetric_rtp_codec:1;
/*! Whether to pass through hold and unhold using re-invites with recvonly and sendrecv */
unsigned int moh_passthrough:1;
/*! DTMF mode to use with this session, from endpoint but can change */
diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c
index 98e9819..3baab40 100644
--- a/res/res_pjsip_sdp_rtp.c
+++ b/res/res_pjsip_sdp_rtp.c
@@ -241,7 +241,7 @@
}
ast_rtp_instance_set_prop(session_media->rtp, AST_RTP_PROPERTY_NAT, session->endpoint->media.rtp.symmetric);
- ast_rtp_instance_set_prop(session_media->rtp, AST_RTP_PROPERTY_ASYMMETRIC_CODEC, session->endpoint->asymmetric_rtp_codec);
+ ast_rtp_instance_set_prop(session_media->rtp, AST_RTP_PROPERTY_ASYMMETRIC_CODEC, session->asymmetric_rtp_codec);
if (!session->endpoint->media.rtp.ice_support && (ice = ast_rtp_instance_get_ice(session_media->rtp))) {
ice->stop(session_media->rtp);
@@ -419,7 +419,7 @@
* type and use only that. This ensures the core won't start sending
* out a format that we aren't currently sending.
*/
- if (!session->endpoint->asymmetric_rtp_codec) {
+ if (!session->asymmetric_rtp_codec) {
struct ast_format *best;
best = ast_format_cap_get_best_by_type(joint, media_type);
diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index bbdb8d1..8e629e5 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -1494,6 +1494,7 @@
session->dtmf = endpoint->dtmf;
session->moh_passthrough = endpoint->moh_passthrough;
+ session->asymmetric_rtp_codec = endpoint->asymmetric_rtp_codec;
if (ast_sip_session_add_supplements(session)) {
/* Release the ref held by session->inv_session */
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/13501
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: I600d5ac1c6c2b47a7a0da6425aea559f1aa61c7c
Gerrit-Change-Number: 13501
Gerrit-PatchSet: 1
Gerrit-Owner: Salah Ahmed <txrubel at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20191220/cd77fa76/attachment-0001.html>
More information about the asterisk-code-review
mailing list