[asterisk-commits] file: branch group/pimp_my_sip r379273 - /team/group/pimp_my_sip/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jan 16 14:20:22 CST 2013


Author: file
Date: Wed Jan 16 14:20:18 2013
New Revision: 379273

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=379273
Log:
Construct an audio media stream when requested complete with connection details and formats!

Modified:
    team/group/pimp_my_sip/res/res_sip_sdp_audio.c

Modified: 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=diff&rev=379273&r1=379272&r2=379273
==============================================================================
--- team/group/pimp_my_sip/res/res_sip_sdp_audio.c (original)
+++ team/group/pimp_my_sip/res/res_sip_sdp_audio.c Wed Jan 16 14:20:18 2013
@@ -190,6 +190,11 @@
 /*! \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)
 {
+	pj_pool_t *pool = session->inv_session->pool_active;
+	pjmedia_sdp_media *media;
+	struct ast_sockaddr addr;
+	int index = 0;
+
 	if (!ast_format_cap_has_type(session->endpoint->codecs, AST_FORMAT_TYPE_AUDIO)) {
 		/* If no audio formats are configured don't add a stream */
 		return 0;
@@ -197,7 +202,54 @@
 		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 */
+	pj_strdup2(pool, &media->desc.media, "audio");
+	pj_strdup2(pool, &media->desc.transport, "RTP/AVP");
+
+	/* Add connection level details */
+	ast_rtp_instance_get_local_address(session->media.audio, &addr);
+	pj_strdup2(pool, &media->conn->net_type, "IN");
+	pj_strdup2(pool, &media->conn->addr_type, (ast_sockaddr_is_ipv6(&addr) && !ast_sockaddr_is_ipv4_mapped(&addr)) ? "IP6" : "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;
+		char tmp[32];
+		pjmedia_sdp_rtpmap rtpmap;
+		pjmedia_sdp_attr *attr;
+
+		if (!ast_codec_pref_index(&session->endpoint->prefs, index, &format)) {
+			break;
+		} else if (AST_FORMAT_GET_TYPE(format.id) != AST_FORMAT_TYPE_AUDIO) {
+			continue;
+		} else if ((rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(session->media.audio), 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;
+	}
+
+	/* TODO: Add noncodec formats */
+
+	/* Add the media stream to the SDP */
+	sdp->media[sdp->media_count++] = media;
 
 	return 1;
 }




More information about the asterisk-commits mailing list