[asterisk-commits] kharwell: branch kharwell/pimp_sip_video r383115 - in /team/kharwell/pimp_sip...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Mar 14 17:35:58 CDT 2013


Author: kharwell
Date: Thu Mar 14 17:35:55 2013
New Revision: 383115

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=383115
Log:
initial video implementation

Added:
    team/kharwell/pimp_sip_video/res/res_sip_sdp_video.c   (with props)
Modified:
    team/kharwell/pimp_sip_video/channels/chan_gulp.c

Modified: team/kharwell/pimp_sip_video/channels/chan_gulp.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_video/channels/chan_gulp.c?view=diff&rev=383115&r1=383114&r2=383115
==============================================================================
--- team/kharwell/pimp_sip_video/channels/chan_gulp.c (original)
+++ team/kharwell/pimp_sip_video/channels/chan_gulp.c Thu Mar 14 17:35:55 2013
@@ -151,6 +151,21 @@
 	return AST_RTP_GLUE_RESULT_LOCAL;
 }
 
+/*! \brief Function called by RTP engine to get local video RTP peer */
+static enum ast_rtp_glue_result gulp_get_vrtp_peer(struct ast_channel *chan, struct ast_rtp_instance **instance)
+{
+	struct gulp_pvt *pvt = ast_channel_tech_pvt(chan);
+
+	if (!pvt || !pvt->session || !pvt->media[SIP_MEDIA_VIDEO]->rtp) {
+		return AST_RTP_GLUE_RESULT_FORBID;
+	}
+
+	*instance = pvt->media[SIP_MEDIA_VIDEO]->rtp;
+	ao2_ref(*instance, +1);
+
+	return AST_RTP_GLUE_RESULT_LOCAL;
+}
+
 /*! \brief Function called by RTP engine to get peer capabilities */
 static void gulp_get_codec(struct ast_channel *chan, struct ast_format_cap *result)
 {
@@ -166,6 +181,7 @@
 static struct ast_rtp_glue gulp_rtp_glue = {
 	.type = "Gulp",
 	.get_rtp_info = gulp_get_rtp_peer,
+	.get_vrtp_info = gulp_get_vrtp_peer,
 	.get_codec = gulp_get_codec,
 	.update_peer = gulp_set_rtp_peer,
 };
@@ -259,17 +275,28 @@
 {
 	struct gulp_pvt *pvt = ast_channel_tech_pvt(ast);
 	struct ast_frame *f;
-	struct ast_sip_session_media *media = pvt->media[SIP_MEDIA_AUDIO];
-
-	if (!media) {
+	struct ast_sip_session_media *media;
+	int fdno = ast_channel_fdno(ast);
+
+	if (!(media = pvt->media[fdno / 2])) {
 		return &ast_null_frame;
 	}
 
-	switch (ast_channel_fdno(ast)) {
+	switch (fdno) {
 	case 0:
+		/* media = pvt->media[SIP_MEDIA_AUDIO]; */
 		f = ast_rtp_instance_read(media->rtp, 0);
 		break;
 	case 1:
+		/* media = pvt->media[SIP_MEDIA_AUDIO]; */
+		f = ast_rtp_instance_read(media->rtp, 1);
+		break;
+	case 2:
+		/* media = pvt->media[SIP_MEDIA_VIDEO]; */
+		f = ast_rtp_instance_read(media->rtp, 0);
+		break;
+	case 3:
+		/* media = pvt->media[SIP_MEDIA_VIDEO]; */
 		f = ast_rtp_instance_read(media->rtp, 1);
 		break;
 	default:
@@ -317,6 +344,11 @@
 			res = ast_rtp_instance_write(media->rtp, frame);
 		}
 		break;
+	case AST_FRAME_VIDEO:
+		if ((media = pvt->media[SIP_MEDIA_VIDEO]) && media->rtp) {
+			res = ast_rtp_instance_write(media->rtp, frame);
+		}
+		break;
 	default:
 		ast_log(LOG_WARNING, "Can't send %d type frames with Gulp\n", frame->frametype);
 		break;
@@ -409,12 +441,40 @@
 	return 0;
 }
 
+/*! \brief Send SIP INFO with video update request */
+static int transmit_info_with_vidupdate(struct ast_sip_session *session)
+{
+	pjsip_tx_data *packet;
+
+	const pj_str_t type = pj_str("application");
+	const pj_str_t subtype = pj_str("media_control+xml");
+
+	const pj_str_t xml = pj_str(
+		"<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n"
+		" <media_control>\r\n"
+		"  <vc_primitive>\r\n"
+		"   <to_encoder>\r\n"
+		"    <picture_fast_update/>\r\n"
+		"   </to_encoder>\r\n"
+		"  </vc_primitive>\r\n"
+		" </media_control>\r\n");
+
+	if (pjsip_inv_invite(session->inv_session, &packet) != PJ_SUCCESS) {
+		return -1;
+	}
+
+	packet->msg->body = pjsip_msg_body_create(packet->pool, &type, &subtype, &xml);
+        /* ast_sip_session_send_request(session, packet); */
+	return 0;
+}
+
 /*! \brief Function called by core to ask the channel to indicate some sort of condition */
 static int gulp_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen)
 {
 	int res = 0;
 	struct gulp_pvt *pvt = ast_channel_tech_pvt(ast);
 	struct ast_sip_session *session = pvt->session;
+	struct ast_sip_session_media *media;
 	int response_code = 0;
 
 	switch (condition) {
@@ -461,6 +521,13 @@
 		}
 		break;
 	case AST_CONTROL_VIDUPDATE:
+		media = pvt->media[SIP_MEDIA_VIDEO];
+		if (media && media->rtp) {
+			transmit_info_with_vidupdate(session);
+			response_code = 200;
+		} else
+			res = -1;
+		break;
 	case AST_CONTROL_UPDATE_RTP_PEER:
 	case AST_CONTROL_PVT_CAUSE_CODE:
 		break;
@@ -728,6 +795,9 @@
 	/* TODO: This needs to actually grab a proper endpoint and such */
 	ast_string_field_set(endpoint, context, "default");
 	ast_parse_allow_disallow(&endpoint->prefs, endpoint->codecs, "ulaw", 1);
+	ast_parse_allow_disallow(&endpoint->prefs, endpoint->codecs, "h261", 1);
+	ast_parse_allow_disallow(&endpoint->prefs, endpoint->codecs, "h263", 1);
+	ast_parse_allow_disallow(&endpoint->prefs, endpoint->codecs, "h264", 1);
 	endpoint->min_se = 90;
 	endpoint->sess_expires = 1800;
 

Added: team/kharwell/pimp_sip_video/res/res_sip_sdp_video.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_video/res/res_sip_sdp_video.c?view=auto&rev=383115
==============================================================================
--- team/kharwell/pimp_sip_video/res/res_sip_sdp_video.c (added)
+++ team/kharwell/pimp_sip_video/res/res_sip_sdp_video.c Thu Mar 14 17:35:55 2013
@@ -1,0 +1,452 @@
+/*
+ * 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 'video' 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/sched.h"
+
+#include "asterisk/res_sip.h"
+#include "asterisk/res_sip_session.h"
+
+/*! \brief Scheduler for RTCP purposes */
+static struct ast_sched_context *sched;
+
+/*! \brief Forward declarations for SDP handler functions */
+static int video_negotiate_incoming_sdp_stream(struct ast_sip_session *session, struct ast_sip_session_media *session_media, const struct pjmedia_sdp_session *sdp, const struct pjmedia_sdp_media *stream);
+static int video_create_outgoing_sdp_stream(struct ast_sip_session *session, struct ast_sip_session_media *session_media, struct pjmedia_sdp_session *sdp);
+static int video_apply_negotiated_sdp_stream(struct ast_sip_session *session, struct ast_sip_session_media *session_media, const struct pjmedia_sdp_session *local, const struct pjmedia_sdp_media *local_stream,
+	const struct pjmedia_sdp_session *remote, const struct pjmedia_sdp_media *remote_stream);
+
+/*! \brief Forward declaration for session supplement functions */
+static void video_stream_destroy(struct ast_sip_session_media *session_media);
+
+/*! \brief SDP handler for 'video' media stream */
+static struct ast_sip_session_sdp_handler video_sdp_handler = {
+	.id = "video",
+	.negotiate_incoming_sdp_stream = video_negotiate_incoming_sdp_stream,
+	.create_outgoing_sdp_stream = video_create_outgoing_sdp_stream,
+	.apply_negotiated_sdp_stream = video_apply_negotiated_sdp_stream,
+	.stream_destroy = video_stream_destroy,
+};
+
+/*! \brief Internal function which creates an RTP instance */
+static int video_create_rtp(struct ast_sip_session *session, struct ast_sip_session_media *session_media, unsigned int ipv6)
+{
+	pj_sockaddr addr;
+	char hostip[PJ_INET6_ADDRSTRLEN+2];
+	struct ast_sockaddr tmp;
+
+	if (pj_gethostip(ipv6 ? pj_AF_INET6() : pj_AF_INET(), &addr) != PJ_SUCCESS) {
+		return -1;
+	}
+
+	pj_sockaddr_print(&addr, hostip, sizeof(hostip), 2);
+
+	if (!ast_sockaddr_parse(&tmp, hostip, 0)) {
+		return -1;
+	}
+
+	if (!(session_media->rtp = ast_rtp_instance_new("asterisk", sched, &tmp, NULL))) {
+		return -1;
+	}
+
+	ast_rtp_instance_set_prop(session_media->rtp, AST_RTP_PROPERTY_RTCP, 1);
+	ast_rtp_instance_set_prop(session_media->rtp, AST_RTP_PROPERTY_NAT, session->endpoint->rtp_symmetric);
+
+	ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(session_media->rtp),
+					 session_media->rtp, &session->endpoint->prefs);
+
+	return 0;
+}
+
+/*! \brief Function which negotiates an incoming 'video' stream */
+static int video_negotiate_incoming_sdp_stream(struct ast_sip_session *session, struct ast_sip_session_media *session_media, const struct pjmedia_sdp_session *sdp, const struct pjmedia_sdp_media *stream)
+{
+	char host[NI_MAXHOST];
+	RAII_VAR(struct ast_sockaddr *, addrs, NULL, ast_free_ptr);
+
+	/* If no video formats have been configured reject this stream */
+	if (!ast_format_cap_has_type(session->endpoint->codecs, AST_FORMAT_TYPE_VIDEO)) {
+		return 0;
+	}
+
+	ast_copy_pj_str(host, stream->conn ? &stream->conn->addr : &sdp->conn->addr, sizeof(host));
+
+	/* Ensure that the address provided is valid */
+	if (ast_sockaddr_resolve(&addrs, host, PARSE_PORT_FORBID, AST_AF_UNSPEC) <= 0) {
+		/* The provided host was actually invalid so we error out this negotiation */
+		return -1;
+	}
+
+	/* Using the connection information create an appropriate RTP instance */
+	if (!session_media->rtp && video_create_rtp(session, session_media, ast_sockaddr_is_ipv6(addrs))) {
+		return -1;
+	}
+
+	/* pjmedia takes care of the formats and such */
+	return 1;
+}
+
+/*! \brief Function which creates an outgoing 'video' stream */
+static int video_create_outgoing_sdp_stream(struct ast_sip_session *session, struct ast_sip_session_media *session_media, struct pjmedia_sdp_session *sdp)
+{
+	static const pj_str_t STR_VIDEO = { "video", 5};
+	static const pj_str_t STR_IN = { "IN", 2 };
+	static const pj_str_t STR_IP4 = { "IP4", 3};
+	static const pj_str_t STR_IP6 = { "IP6", 3};
+	static const pj_str_t STR_RTP_AVP = { "RTP/AVP", 7 };
+	static const pj_str_t STR_SENDRECV = { "sendrecv", 8 };
+	pj_pool_t *pool = session->inv_session->pool_active;
+	pjmedia_sdp_media *media;
+	struct ast_sockaddr addr;
+	char tmp[32];
+	pj_str_t stmp;
+	pjmedia_sdp_attr *attr;
+	int index = 0, min_packet_size = 0, noncodec = (session->endpoint->dtmf == AST_SIP_DTMF_RFC_4733) ? AST_RTP_DTMF : 0;
+
+	if (!ast_format_cap_has_type(session->endpoint->codecs, AST_FORMAT_TYPE_VIDEO)) {
+		/* If no video formats are configured don't add a stream */
+		return 0;
+	} else if (!session_media->rtp && video_create_rtp(session, session_media, session->endpoint->rtp_ipv6)) {
+		return -1;
+	}
+
+	if (!(media = pj_pool_zalloc(pool, sizeof(struct pjmedia_sdp_media))) ||
+	    !(media->conn = pj_pool_zalloc(pool, sizeof(struct pjmedia_sdp_conn)))) {
+		return -1;
+	}
+
+	/* TODO: This should eventually support SRTP */
+	media->desc.media = STR_VIDEO;
+	media->desc.transport = STR_RTP_AVP;
+
+	/* Add connection level details */
+	ast_rtp_instance_get_local_address(session_media->rtp, &addr);
+	media->conn->net_type = STR_IN;
+	media->conn->addr_type = (ast_sockaddr_is_ipv6(&addr) && !ast_sockaddr_is_ipv4_mapped(&addr)) ? STR_IP6 : STR_IP4;
+	pj_strdup2(pool, &media->conn->addr, ast_sockaddr_stringify_addr_remote(&addr));
+	media->desc.port = (pj_uint16_t) ast_sockaddr_port(&addr);
+	media->desc.port_count = 1;
+
+	/* Add formats */
+	for (index = 0; (index < AST_CODEC_PREF_SIZE); index++) {
+		struct ast_format format;
+		int rtp_code;
+		pjmedia_sdp_rtpmap rtpmap;
+		struct ast_codec_pref *pref = &ast_rtp_instance_get_codecs(session_media->rtp)->pref;
+
+		if (!ast_codec_pref_index(&session->endpoint->prefs, index, &format)) {
+			break;
+		} else if (AST_FORMAT_GET_TYPE(format.id) != AST_FORMAT_TYPE_VIDEO) {
+			continue;
+		} else if ((rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(session_media->rtp),
+								   1, &format, 0)) == -1) {
+			return -1;
+		}
+
+		snprintf(tmp, sizeof(tmp), "%d", rtp_code);
+		pj_strdup2(pool, &media->desc.fmt[media->desc.fmt_count++], tmp);
+		rtpmap.pt = media->desc.fmt[media->desc.fmt_count - 1];
+		rtpmap.clock_rate = ast_rtp_lookup_sample_rate2(1, &format, 0);
+		pj_strdup2(pool, &rtpmap.enc_name, ast_rtp_lookup_mime_subtype2(1, &format, 0, 0));
+		rtpmap.param.slen = 0;
+
+		pjmedia_sdp_rtpmap_to_attr(pool, &rtpmap, &attr);
+		media->attr[media->attr_count++] = attr;
+
+		if (pref) {
+			struct ast_format_list fmt = ast_codec_pref_getsize(pref, &format);
+			if (fmt.cur_ms && ((fmt.cur_ms < min_packet_size) || !min_packet_size)) {
+				min_packet_size = fmt.cur_ms;
+			}
+		}
+	}
+
+	/* Add non-codec formats */
+	for (index = 1LL; index <= AST_RTP_MAX; index <<= 1) {
+		int rtp_code;
+		pjmedia_sdp_rtpmap rtpmap;
+
+		if (!(noncodec & index) || (rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(session_media->rtp),
+										   0, NULL, index)) == -1) {
+			continue;
+		}
+
+		snprintf(tmp, sizeof(tmp), "%d", rtp_code);
+		pj_strdup2(pool, &media->desc.fmt[media->desc.fmt_count++], tmp);
+		rtpmap.pt = media->desc.fmt[media->desc.fmt_count - 1];
+		rtpmap.clock_rate = ast_rtp_lookup_sample_rate2(0, NULL, index);
+		pj_strdup2(pool, &rtpmap.enc_name, ast_rtp_lookup_mime_subtype2(0, NULL, index, 0));
+		rtpmap.param.slen = 0;
+
+		pjmedia_sdp_rtpmap_to_attr(pool, &rtpmap, &attr);
+		media->attr[media->attr_count++] = attr;
+
+		if (index == AST_RTP_DTMF) {
+			snprintf(tmp, sizeof(tmp), "%d 0-16", rtp_code);
+			attr = pjmedia_sdp_attr_create(pool, "fmtp", pj_cstr(&stmp, tmp));
+			media->attr[media->attr_count++] = attr;
+		}
+	}
+
+	/* If ptime is set add it as an attribute */
+	if (min_packet_size) {
+		snprintf(tmp, sizeof(tmp), "%d", min_packet_size);
+		attr = pjmedia_sdp_attr_create(pool, "ptime", pj_cstr(&stmp, tmp));
+		media->attr[media->attr_count++] = attr;
+	}
+
+	/* Add the sendrecv attribute - we purposely don't keep track because pjmedia-sdp will automatically change our offer for us */
+	attr = PJ_POOL_ZALLOC_T(pool, pjmedia_sdp_attr);
+	attr->name = STR_SENDRECV;
+	media->attr[media->attr_count++] = attr;
+
+	/* Add the media stream to the SDP */
+	sdp->media[sdp->media_count++] = media;
+
+	return 1;
+}
+
+/*! \brief Function which applies a negotiated SDP stream */
+static int video_apply_negotiated_sdp_stream(struct ast_sip_session *session, struct ast_sip_session_media *session_media, const struct pjmedia_sdp_session *local, const struct pjmedia_sdp_media *local_stream,
+	const struct pjmedia_sdp_session *remote, const struct pjmedia_sdp_media *remote_stream)
+{
+	int format, othercapability = 0;
+	char host[NI_MAXHOST];
+	RAII_VAR(struct ast_sockaddr *, addrs, NULL, ast_free_ptr);
+	struct ast_rtp_codecs codecs;
+	const pjmedia_sdp_attr *attr;
+	RAII_VAR(struct ast_format_cap *, cap, NULL, ast_format_cap_destroy);
+	RAII_VAR(struct ast_format_cap *, jointcap, NULL, ast_format_cap_destroy);
+	RAII_VAR(struct ast_format_cap *, peercap, NULL, ast_format_cap_destroy);
+	struct ast_format fmt;
+
+	/* Create an RTP instance if need be */
+	if (!session_media->rtp && video_create_rtp(session, session_media, session->endpoint->rtp_ipv6)) {
+		return -1;
+	}
+
+	ast_copy_pj_str(host, remote_stream->conn ? &remote_stream->conn->addr : &remote->conn->addr, sizeof(host));
+
+	/* Ensure that the address provided is valid */
+	if (ast_sockaddr_resolve(&addrs, host, PARSE_PORT_FORBID, AST_AF_UNSPEC) <= 0) {
+		/* The provided host was actually invalid so we error out this negotiation */
+		return -1;
+	}
+
+	/* To properly apply formats to the channel we need to keep track of capabilities */
+	if (!(cap = ast_format_cap_alloc_nolock()) ||
+	    !(peercap = ast_format_cap_alloc_nolock())) {
+		ast_log(LOG_ERROR, "Failed to allocate video capabilities\n");
+		return -1;
+	}
+
+	/* Apply connection information to the RTP instance */
+	ast_sockaddr_set_port(addrs, remote_stream->desc.port);
+	ast_rtp_instance_set_remote_address(session_media->rtp, addrs);
+
+	ast_rtp_codecs_payloads_initialize(&codecs);
+
+	/* Iterate through provided formats */
+	for (format = 0; format < local_stream->desc.fmt_count; format++) {
+		/* The payload is kept as a string for things like t38 but for video it is always numerical */
+		ast_rtp_codecs_payloads_set_m_type(&codecs, NULL, pj_strtoul(&local_stream->desc.fmt[format]));
+
+		/* Look for the optional rtpmap attribute */
+		if ((attr = pjmedia_sdp_media_find_attr2(local_stream, "rtpmap", &local_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];
+
+				ast_copy_pj_str(name, &rtpmap->enc_name, sizeof(name));
+				ast_rtp_codecs_payloads_set_rtpmap_type_rate(&codecs, NULL, pj_strtoul(&local_stream->desc.fmt[format]),
+									     "video", name, 0, rtpmap->clock_rate);
+			}
+		}
+	}
+
+	ast_rtp_codecs_payload_formats(&codecs, peercap, &othercapability);
+
+	/* Apply packetization if available and configured to do so */
+	if (session->endpoint->use_ptime && (attr = pjmedia_sdp_media_find_attr2(remote_stream, "ptime", NULL))) {
+		pj_str_t value = attr->value;
+		unsigned long framing = pj_strtoul(pj_strltrim(&value));
+		int codec;
+		struct ast_codec_pref *pref = &ast_rtp_instance_get_codecs(session_media->rtp)->pref;
+
+		for (codec = 0; codec < AST_RTP_MAX_PT; codec++) {
+			struct ast_rtp_payload_type format = ast_rtp_codecs_payload_lookup(ast_rtp_instance_get_codecs(
+				session_media->rtp), codec);
+
+			if (!format.asterisk_format) {
+				continue;
+			}
+
+			ast_codec_pref_setsize(pref, &format.format, framing);
+		}
+
+		ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(session_media->rtp),
+			session_media->rtp, pref);
+	}
+
+	/* Using the configured codecs and the codecs in this SDP we determine the joint formats for *video only* */
+	ast_format_cap_copy(cap, session->endpoint->codecs);
+	ast_format_cap_remove_bytype(cap, AST_FORMAT_TYPE_AUDIO);
+
+	if (!(jointcap = ast_format_cap_joint(cap, peercap))) {
+		char usbuf[64], thembuf[64];
+
+		ast_channel_hangupcause_set(session->channel, AST_CAUSE_BEARERCAPABILITY_NOTAVAIL);
+		ast_getformatname_multiple(usbuf, sizeof(usbuf), cap);
+		ast_getformatname_multiple(thembuf, sizeof(thembuf), peercap);
+		ast_log(LOG_WARNING, "No joint capabilities between our configuration(%s) and incoming SDP(%s)\n", usbuf, thembuf);
+
+		ast_rtp_codecs_payloads_destroy(&codecs);
+		return -1;
+	}
+
+	ast_rtp_codecs_payloads_copy(&codecs, ast_rtp_instance_get_codecs(session_media->rtp),
+				     session_media->rtp);
+
+	/* Now that we have joint formats for video remove the existing ones from the channel and add the new ones */
+	ast_format_cap_copy(cap, ast_channel_nativeformats(session->channel));
+	ast_format_cap_remove_bytype(cap, AST_FORMAT_TYPE_AUDIO);
+	ast_format_cap_append(cap, jointcap);
+
+	/* Apply the new formats to the channel, potentially changing read/write formats while doing so */
+	ast_format_cap_append(ast_channel_nativeformats(session->channel), cap);
+	ast_codec_choose(&session->endpoint->prefs, cap, 0, &fmt);
+	ast_format_copy(ast_channel_rawwriteformat(session->channel), &fmt);
+	ast_format_copy(ast_channel_rawreadformat(session->channel), &fmt);
+	ast_set_read_format(session->channel, ast_channel_readformat(session->channel));
+	ast_set_write_format(session->channel, ast_channel_writeformat(session->channel));
+
+	ast_channel_set_fd(session->channel, 2, ast_rtp_instance_fd(session_media->rtp, 0));
+	ast_channel_set_fd(session->channel, 3, ast_rtp_instance_fd(session_media->rtp, 1));
+
+	if (session_media->held && (!ast_sockaddr_isnull(addrs) ||
+							  !pjmedia_sdp_media_find_attr2(remote_stream, "sendonly", NULL))) {
+		/* The remote side has taken us off hold */
+		ast_queue_control(session->channel, AST_CONTROL_UNHOLD);
+		ast_queue_frame(session->channel, &ast_null_frame);
+		session_media->held = 0;
+	} else if (ast_sockaddr_isnull(addrs) || ast_sockaddr_is_any(addrs) || pjmedia_sdp_media_find_attr2(remote_stream, "sendonly", NULL)) {
+		/* The remote side has put us on hold */
+		ast_queue_control_data(session->channel, AST_CONTROL_HOLD, S_OR(session->endpoint->mohsuggest, NULL),
+				       !ast_strlen_zero(session->endpoint->mohsuggest) ? strlen(session->endpoint->mohsuggest) + 1 : 0);
+		ast_rtp_instance_stop(session_media->rtp);
+		ast_queue_frame(session->channel, &ast_null_frame);
+		session_media->held = 1;
+	} else {
+		/* The remote side has not changed state, but make sure the instance is active */
+		ast_rtp_instance_activate(session_media->rtp);
+	}
+
+	ast_rtp_codecs_payloads_destroy(&codecs);
+	return 1;
+}
+
+/*! \brief Function which destroys the video RTP instance when session ends */
+static void video_stream_destroy(struct ast_sip_session_media *session_media)
+{
+	if (!session_media->rtp) {
+		return;
+	}
+
+	ast_rtp_instance_stop(session_media->rtp);
+	ast_rtp_instance_destroy(session_media->rtp);
+}
+
+/*!
+ * \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)
+{
+	if (!(sched = ast_sched_context_create())) {
+		ast_log(LOG_ERROR, "Unable to create scheduler context.\n");
+		goto end;
+	}
+
+	if (ast_sched_start_thread(sched)) {
+		ast_log(LOG_ERROR, "Unable to create scheduler context thread.\n");
+		goto end;
+	}
+
+	if (ast_sip_session_register_sdp_handler(&video_sdp_handler, "video")) {
+		ast_log(LOG_ERROR, "Unable to register SDP handler for 'video' stream type\n");
+		goto end;
+	}
+
+	return AST_MODULE_LOAD_SUCCESS;
+end:
+	if (sched) {
+		ast_sched_context_destroy(sched);
+	}
+
+	return AST_MODULE_LOAD_FAILURE;
+}
+
+/*! \brief Unload the Gulp channel from Asterisk */
+static int unload_module(void)
+{
+	ast_sip_session_unregister_sdp_handler(&video_sdp_handler, "video");
+	ast_sched_context_destroy(sched);
+	return 0;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "SIP SDP 'video' Media Stream Handler",
+		.load = load_module,
+		.unload = unload_module,
+		.load_pri = AST_MODPRI_CHANNEL_DRIVER,
+	       );

Propchange: team/kharwell/pimp_sip_video/res/res_sip_sdp_video.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/kharwell/pimp_sip_video/res/res_sip_sdp_video.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Rev URL

Propchange: team/kharwell/pimp_sip_video/res/res_sip_sdp_video.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list