[asterisk-commits] file: branch group/pimp_my_sip r379267 - /team/group/pimp_my_sip/res/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Jan 16 12:51:53 CST 2013
Author: file
Date: Wed Jan 16 12:51:50 2013
New Revision: 379267
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=379267
Log:
Add the beginnings of a module which does handling of 'audio' media streams in SIP SDP.
Added:
team/group/pimp_my_sip/res/res_sip_sdp_audio.c (with props)
Added: team/group/pimp_my_sip/res/res_sip_sdp_audio.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/res/res_sip_sdp_audio.c?view=auto&rev=379267
==============================================================================
--- team/group/pimp_my_sip/res/res_sip_sdp_audio.c (added)
+++ team/group/pimp_my_sip/res/res_sip_sdp_audio.c Wed Jan 16 12:51:50 2013
@@ -1,0 +1,174 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * Joshua Colp <jcolp at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \author Joshua Colp <jcolp at digium.com>
+ *
+ * \brief SIP SDP 'audio' media stream handling
+ */
+
+/*** MODULEINFO
+ <depend>res_sip</depend>
+ <depend>res_sip_session</depend>
+ <support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+
+#undef bzero
+#define bzero bzero
+#include "pjsip.h"
+#include "pjsip_ua.h"
+#include "pjmedia.h"
+#include "pjlib.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/module.h"
+#include "asterisk/rtp_engine.h"
+#include "asterisk/netsock2.h"
+#include "asterisk/channel.h"
+#include "asterisk/causes.h"
+
+#include "asterisk/res_sip_session.h"
+
+/*! \brief Forward declarations for SDP handler functions */
+static int audio_handle_incoming_sdp_stream_offer(struct ast_sip_session *session, struct pjmedia_sdp_media *stream);
+static int audio_create_outgoing_sdp_stream(struct ast_sip_session *session, struct pjmedia_sdp_session *sdp);
+
+/*! \brief SDP handler for 'audio' media stream */
+static struct ast_sip_session_sdp_handler audio_sdp_handler = {
+ .id = "audio",
+ .handle_incoming_sdp_stream_offer = audio_handle_incoming_sdp_stream_offer,
+ .create_outgoing_sdp_stream = audio_create_outgoing_sdp_stream,
+};
+
+/*! \brief Internal function which creates an RTP instance */
+static int audio_create_rtp(struct ast_sip_session *session)
+{
+ struct ast_sockaddr tmp;
+
+ /* TODO: Add support for IPv6 */
+ ast_sockaddr_parse(&tmp, "0.0.0.0", 0);
+
+ if (!(session->media.audio = ast_rtp_instance_new("asterisk", NULL, &tmp, NULL))) {
+ return -1;
+ }
+
+ /* TODO: Create scheduler so RTCP can function */
+ ast_rtp_instance_set_prop(session->media.audio, AST_RTP_PROPERTY_RTCP, 0);
+
+ ast_channel_set_fd(session->channel, 0, ast_rtp_instance_fd(session->media.audio, 0));
+
+ return 0;
+}
+
+/*! \brief Function which handles an incoming 'audio' stream */
+static int audio_handle_incoming_sdp_stream_offer(struct ast_sip_session *session, struct pjmedia_sdp_media *stream)
+{
+ char host[NI_MAXHOST];
+ int addrs_cnt, format;
+ struct ast_sockaddr *addrs;
+ struct ast_rtp_codecs codecs;
+ const pjmedia_sdp_attr *attr;
+
+ /* If the stream has been rejected stop media if active */
+ if (!stream->desc.port) {
+ if (session->media.audio) {
+ ast_rtp_instance_stop(session->media.audio);
+ }
+ return 1;
+ }
+
+ /* Create an RTP instance if need be */
+ if (!session->media.audio && audio_create_rtp(session)) {
+ return 1;
+ }
+
+ /* For now use stream level connection details - once the SDP itself is passed in we can use it if not present */
+ snprintf(host, sizeof(host), "%.*s", (int) pj_strlen(&stream->conn->addr), pj_strbuf(&stream->conn->addr));
+
+ /* Ensure that the address provided is valid */
+ if ((addrs_cnt = ast_sockaddr_resolve(&addrs, host, PARSE_PORT_FORBID, AST_AF_UNSPEC)) <= 0) {
+ /* The provided host was actually invalid so we kill the session as it would just end up being broken */
+ ast_channel_hangupcause_set(session->channel, AST_CAUSE_BEARERCAPABILITY_NOTAVAIL);
+ return -1;
+ }
+
+ /* Apply connection information to the RTP instance */
+ ast_sockaddr_set_port(addrs, stream->desc.port);
+ ast_rtp_instance_set_remote_address(session->media.audio, addrs);
+ ast_free(addrs);
+
+ /* Iterate through provided formats */
+ for (format = 0; format < stream->desc.fmt_count; format++) {
+ /* The payload is kept as a string for things like t38 but for audio it is always numerical */
+ ast_rtp_codecs_payloads_set_m_type(&codecs, NULL, pj_strtoul(&stream->desc.fmt[format]));
+
+ /* Look for the optional rtpmap attribute */
+ if ((attr = pjmedia_sdp_media_find_attr2(stream, "rtpmap", &stream->desc.fmt[format]))) {
+ pjmedia_sdp_rtpmap *rtpmap;
+
+ /* Interpret the attribute as an rtpmap */
+ if ((pjmedia_sdp_attr_to_rtpmap(session->inv_session->pool_active, attr, &rtpmap)) == PJ_SUCCESS) {
+ char name[32];
+
+ snprintf(name, sizeof(name), "%.*s", (int) pj_strlen(&rtpmap->enc_name), pj_strbuf(&rtpmap->enc_name));
+ ast_rtp_codecs_payloads_set_rtpmap_type_rate(&codecs, NULL, pj_strtoul(&stream->desc.fmt[format]),
+ "audio", name, 0, rtpmap->clock_rate);
+ }
+ }
+ }
+
+ return 0;
+}
+
+/*! \brief Function which creates an outgoing 'audio' stream */
+static int audio_create_outgoing_sdp_stream(struct ast_sip_session *session, struct pjmedia_sdp_session *sdp)
+{
+ return 0;
+}
+
+/*!
+ * \brief Load the module
+ *
+ * Module loading including tests for configuration or dependencies.
+ * This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE,
+ * or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails
+ * tests return AST_MODULE_LOAD_FAILURE. If the module can not load the
+ * configuration file or other non-critical problem return
+ * AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.
+ */
+static int load_module(void)
+{
+ return ast_sip_session_register_sdp_handler(&audio_sdp_handler, "audio") ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_SUCCESS;
+}
+
+/*! \brief Unload the Gulp channel from Asterisk */
+static int unload_module(void)
+{
+ ast_sip_session_unregister_sdp_handler(&audio_sdp_handler, "audio");
+ return 0;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "SIP SDP 'audio' Media Stream Handler",
+ .load = load_module,
+ .unload = unload_module,
+ .load_pri = AST_MODPRI_CHANNEL_DRIVER,
+ );
Propchange: team/group/pimp_my_sip/res/res_sip_sdp_audio.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/group/pimp_my_sip/res/res_sip_sdp_audio.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/group/pimp_my_sip/res/res_sip_sdp_audio.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the asterisk-commits
mailing list