[asterisk-commits] file: branch file/pimp_sip_media r380851 - in /team/file/pimp_sip_media: chan...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Feb 5 11:46:49 CST 2013


Author: file
Date: Tue Feb  5 11:46:45 2013
New Revision: 380851

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=380851
Log:
Clean stuff up to make it easier to read/understand/extend.

Modified:
    team/file/pimp_sip_media/channels/chan_gulp.c
    team/file/pimp_sip_media/include/asterisk/res_sip_session.h
    team/file/pimp_sip_media/res/res_sip_sdp_audio.c

Modified: team/file/pimp_sip_media/channels/chan_gulp.c
URL: http://svnview.digium.com/svn/asterisk/team/file/pimp_sip_media/channels/chan_gulp.c?view=diff&rev=380851&r1=380850&r2=380851
==============================================================================
--- team/file/pimp_sip_media/channels/chan_gulp.c (original)
+++ team/file/pimp_sip_media/channels/chan_gulp.c Tue Feb  5 11:46:45 2013
@@ -168,11 +168,6 @@
 	ast_format_copy(ast_channel_readformat(chan), &fmt);
 	ast_format_copy(ast_channel_rawreadformat(chan), &fmt);
 
-	if (session->media.audio) {
-		ast_channel_set_fd(chan, 0, ast_rtp_instance_fd(session->media.audio, 0));
-		ast_channel_set_fd(chan, 1, ast_rtp_instance_fd(session->media.audio, 1));
-	}
-
 	if (state == AST_STATE_RING) {
 		ast_channel_rings_set(chan, 1);
 	}
@@ -216,10 +211,10 @@
 
 	switch (ast_channel_fdno(ast)) {
 	case 0:
-		f = ast_rtp_instance_read(session->media.audio, 0);
+		f = ast_rtp_instance_read(session->media[AST_SIP_MEDIA_AUDIO].rtp, 0);
 		break;
 	case 1:
-		f = ast_rtp_instance_read(session->media.audio, 1);
+		f = ast_rtp_instance_read(session->media[AST_SIP_MEDIA_AUDIO].rtp, 1);
 		break;
 	default:
 		f = &ast_null_frame;
@@ -256,8 +251,8 @@
 				ast_getformatname(ast_channel_writeformat(ast)));
 			return 0;
 		}
-		if (session->media.audio) {
-			res = ast_rtp_instance_write(session->media.audio, frame);
+		if (session->media[AST_SIP_MEDIA_AUDIO].rtp) {
+			res = ast_rtp_instance_write(session->media[AST_SIP_MEDIA_AUDIO].rtp, frame);
 		}
 		break;
 	default:
@@ -373,7 +368,7 @@
 
 	switch (session->endpoint->dtmf) {
 	case AST_SIP_DTMF_RFC_4733:
-		ast_rtp_instance_dtmf_begin(session->media.audio, digit);
+		ast_rtp_instance_dtmf_begin(session->media[AST_SIP_MEDIA_AUDIO].rtp, digit);
 	case AST_SIP_DTMF_NONE:
 		break;
 	case AST_SIP_DTMF_INBAND:
@@ -397,7 +392,7 @@
 		/* TODO: Send INFO dtmf here */
 		break;
 	case AST_SIP_DTMF_RFC_4733:
-		ast_rtp_instance_dtmf_end_with_duration(session->media.audio, digit, duration);
+		ast_rtp_instance_dtmf_end_with_duration(session->media[AST_SIP_MEDIA_AUDIO].rtp, digit, duration);
 	case AST_SIP_DTMF_NONE:
 		break;
 	case AST_SIP_DTMF_INBAND:
@@ -699,11 +694,9 @@
 		}
 		break;
 	case 183:
-		ast_rtp_instance_activate(session->media.audio);
 		ast_queue_control(session->channel, AST_CONTROL_PROGRESS);
 		break;
 	case 200:
-		ast_rtp_instance_activate(session->media.audio);
 		ast_queue_control(session->channel, AST_CONTROL_ANSWER);
 		break;
 	default:

Modified: team/file/pimp_sip_media/include/asterisk/res_sip_session.h
URL: http://svnview.digium.com/svn/asterisk/team/file/pimp_sip_media/include/asterisk/res_sip_session.h?view=diff&rev=380851&r1=380850&r2=380851
==============================================================================
--- team/file/pimp_sip_media/include/asterisk/res_sip_session.h (original)
+++ team/file/pimp_sip_media/include/asterisk/res_sip_session.h Tue Feb  5 11:46:45 2013
@@ -38,11 +38,23 @@
 struct ast_rtp_instance;
 
 /*!
+ * \brief Positions of various media
+ */
+enum ast_sip_session_media_position {
+	/*! \brief First is audio */
+	AST_SIP_MEDIA_AUDIO = 0,
+	/*! \brief Second is video */
+	AST_SIP_MEDIA_VIDEO,
+	/*! \brief Last is the size for media details */
+	AST_SIP_MEDIA_SIZE,
+};
+
+/*!
  * \brief A structure containing SIP session media information
  */
 struct ast_sip_session_media {
-    /* RTP instance for audio */
-    struct ast_rtp_instance *audio;
+	/*! \brief RTP instance itself */
+	struct ast_rtp_instance *rtp;
 };
 
 /*!
@@ -56,18 +68,18 @@
 struct ast_sip_session {
 	/* Dialplan extension where incoming call is destined */
 	char exten[AST_MAX_EXTENSION];
-    /* The endpoint with which Asterisk is communicating */
-    struct ast_sip_endpoint *endpoint;
-    /* The PJSIP details of the session, which includes the dialog */
-    struct pjsip_inv_session *inv_session;
-    /* The Asterisk channel associated with the session */
-    struct ast_channel *channel;
+	/* The endpoint with which Asterisk is communicating */
+	struct ast_sip_endpoint *endpoint;
+	/* The PJSIP details of the session, which includes the dialog */
+	struct pjsip_inv_session *inv_session;
+	/* The Asterisk channel associated with the session */
+	struct ast_channel *channel;
 	/* Registered session supplements */
 	AST_LIST_HEAD(, ast_sip_session_supplement) supplements;
-    /* Datastores added to the session by supplements to the session */
+	/* Datastores added to the session by supplements to the session */
 	struct ao2_container *datastores;
-    /* Media information */
-    struct ast_sip_session_media media;
+	/* Media streams */
+	struct ast_sip_session_media media[AST_SIP_MEDIA_SIZE];
 	/* Workspace for tasks relating to this SIP session */
 	struct ast_sip_work *work;
 };

Modified: team/file/pimp_sip_media/res/res_sip_sdp_audio.c
URL: http://svnview.digium.com/svn/asterisk/team/file/pimp_sip_media/res/res_sip_sdp_audio.c?view=diff&rev=380851&r1=380850&r2=380851
==============================================================================
--- team/file/pimp_sip_media/res/res_sip_sdp_audio.c (original)
+++ team/file/pimp_sip_media/res/res_sip_sdp_audio.c Tue Feb  5 11:46:45 2013
@@ -83,13 +83,14 @@
 		return -1;
 	}
 
-	if (!(session->media.audio = ast_rtp_instance_new("asterisk", sched, &tmp, NULL))) {
-		return -1;
-	}
-
-	ast_rtp_instance_set_prop(session->media.audio, AST_RTP_PROPERTY_RTCP, 1);
-
-	ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(session->media.audio), session->media.audio, &session->endpoint->prefs);
+	if (!(session->media[AST_SIP_MEDIA_AUDIO].rtp = ast_rtp_instance_new("asterisk", sched, &tmp, NULL))) {
+		return -1;
+	}
+
+	ast_rtp_instance_set_prop(session->media[AST_SIP_MEDIA_AUDIO].rtp, AST_RTP_PROPERTY_RTCP, 1);
+
+	ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(session->media[AST_SIP_MEDIA_AUDIO].rtp),
+					 session->media[AST_SIP_MEDIA_AUDIO].rtp, &session->endpoint->prefs);
 	
 	return 0;
 }
@@ -136,7 +137,7 @@
 	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;
-	} else if (!session->media.audio && audio_create_rtp(session)) {
+	} else if (!session->media[AST_SIP_MEDIA_AUDIO].rtp && audio_create_rtp(session)) {
 		return -1;
 	}
 
@@ -150,7 +151,7 @@
 	pj_strdup2(pool, &media->desc.transport, "RTP/AVP");
 
 	/* Add connection level details */
-	ast_rtp_instance_get_local_address(session->media.audio, &addr);
+	ast_rtp_instance_get_local_address(session->media[AST_SIP_MEDIA_AUDIO].rtp, &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));
@@ -162,13 +163,14 @@
 		struct ast_format format;
 		int rtp_code;
 		pjmedia_sdp_rtpmap rtpmap;
-		struct ast_codec_pref *pref = &ast_rtp_instance_get_codecs(session->media.audio)->pref;
+		struct ast_codec_pref *pref = &ast_rtp_instance_get_codecs(session->media[AST_SIP_MEDIA_AUDIO].rtp)->pref;
 
 		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) {
+		} else if ((rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(session->media[AST_SIP_MEDIA_AUDIO].rtp),
+								   1, &format, 0)) == -1) {
 			return -1;
 		}
 
@@ -195,7 +197,8 @@
 		int rtp_code;
 		pjmedia_sdp_rtpmap rtpmap;
 
-		if (!(noncodec & index) || (rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(session->media.audio), 0, NULL, index)) == -1) {
+		if (!(noncodec & index) || (rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(session->media[AST_SIP_MEDIA_AUDIO].rtp),
+										   0, NULL, index)) == -1) {
 			continue;
 		}
 
@@ -241,7 +244,7 @@
 	struct ast_format fmt;
 
 	/* Create an RTP instance if need be */
-	if (!session->media.audio && audio_create_rtp(session)) {
+	if (!session->media[AST_SIP_MEDIA_AUDIO].rtp && audio_create_rtp(session)) {
 		return -1;
 	}
 
@@ -267,7 +270,7 @@
 
 	/* 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_rtp_instance_set_remote_address(session->media[AST_SIP_MEDIA_AUDIO].rtp, addrs);
 	ast_free(addrs);
 
 	ast_rtp_codecs_payloads_initialize(&codecs);
@@ -309,7 +312,8 @@
 		goto cleanup;
 	}
 
-	ast_rtp_codecs_payloads_copy(&codecs, ast_rtp_instance_get_codecs(session->media.audio), session->media.audio);
+	ast_rtp_codecs_payloads_copy(&codecs, ast_rtp_instance_get_codecs(session->media[AST_SIP_MEDIA_AUDIO].rtp),
+				     session->media[AST_SIP_MEDIA_AUDIO].rtp);
 
 	/* Now that we have joint formats for audio remove the existing ones from the channel and add the new ones */
 	ast_format_cap_copy(cap, ast_channel_nativeformats(session->channel));
@@ -321,6 +325,11 @@
 	ast_codec_choose(&session->endpoint->prefs, cap, 1, &fmt);
 	ast_set_read_format(session->channel, &fmt);
 	ast_set_write_format(session->channel, &fmt);
+
+	ast_channel_set_fd(session->channel, 0, ast_rtp_instance_fd(session->media[AST_SIP_MEDIA_AUDIO].rtp, 0));
+	ast_channel_set_fd(session->channel, 1, ast_rtp_instance_fd(session->media[AST_SIP_MEDIA_AUDIO].rtp, 1));
+
+	ast_rtp_instance_activate(session->media[AST_SIP_MEDIA_AUDIO].rtp);
 
 cleanup:
 	ast_format_cap_destroy(peercap);




More information about the asterisk-commits mailing list